Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ rules:
- error
- max: 1
no-trailing-spaces: error
no-param-reassign:
- error
- props: false
object-curly-spacing:
- error
- always
Expand Down Expand Up @@ -88,3 +91,10 @@ overrides:
- test/validStrings.mjs
rules:
no-console: off
- files:
- test/*.mjs
- test/**/*
# TODO Fix these files!
- lib/ecmascript.ts
rules:
no-param-reassign: off
166 changes: 97 additions & 69 deletions lib/calendar.ts

Large diffs are not rendered by default.

72 changes: 36 additions & 36 deletions lib/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ import { Temporal } from '..';

export class Duration implements Temporal.Duration {
constructor(
years = 0,
months = 0,
weeks = 0,
days = 0,
hours = 0,
minutes = 0,
seconds = 0,
milliseconds = 0,
microseconds = 0,
nanoseconds = 0
yearsParam = 0,
monthsParam = 0,
weeksParam = 0,
daysParam = 0,
hoursParam = 0,
minutesParam = 0,
secondsParam = 0,
millisecondsParam = 0,
microsecondsParam = 0,
nanosecondsParam = 0
) {
years = ES.ToIntegerThrowOnInfinity(years);
months = ES.ToIntegerThrowOnInfinity(months);
weeks = ES.ToIntegerThrowOnInfinity(weeks);
days = ES.ToIntegerThrowOnInfinity(days);
hours = ES.ToIntegerThrowOnInfinity(hours);
minutes = ES.ToIntegerThrowOnInfinity(minutes);
seconds = ES.ToIntegerThrowOnInfinity(seconds);
milliseconds = ES.ToIntegerThrowOnInfinity(milliseconds);
microseconds = ES.ToIntegerThrowOnInfinity(microseconds);
nanoseconds = ES.ToIntegerThrowOnInfinity(nanoseconds);
const years = ES.ToIntegerThrowOnInfinity(yearsParam);
const months = ES.ToIntegerThrowOnInfinity(monthsParam);
const weeks = ES.ToIntegerThrowOnInfinity(weeksParam);
const days = ES.ToIntegerThrowOnInfinity(daysParam);
const hours = ES.ToIntegerThrowOnInfinity(hoursParam);
const minutes = ES.ToIntegerThrowOnInfinity(minutesParam);
const seconds = ES.ToIntegerThrowOnInfinity(secondsParam);
const milliseconds = ES.ToIntegerThrowOnInfinity(millisecondsParam);
const microseconds = ES.ToIntegerThrowOnInfinity(microsecondsParam);
const nanoseconds = ES.ToIntegerThrowOnInfinity(nanosecondsParam);

const sign = ES.DurationSign(
years,
Expand Down Expand Up @@ -203,11 +203,11 @@ export class Duration implements Temporal.Duration {
Math.abs(GetSlot(this, NANOSECONDS))
);
}
add(other, options = undefined) {
add(other, optionsParam = undefined) {
if (!ES.IsTemporalDuration(this)) throw new TypeError('invalid receiver');
let { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } =
ES.ToLimitedTemporalDuration(other);
options = ES.GetOptionsObject(options);
const options = ES.GetOptionsObject(optionsParam);
const relativeTo = ES.ToRelativeTemporalObject(options);
({ years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = ES.AddDuration(
GetSlot(this, YEARS),
Expand All @@ -234,11 +234,11 @@ export class Duration implements Temporal.Duration {
));
return new Duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
}
subtract(other, options = undefined) {
subtract(other, optionsParam = undefined) {
if (!ES.IsTemporalDuration(this)) throw new TypeError('invalid receiver');
let { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } =
ES.ToLimitedTemporalDuration(other);
options = ES.GetOptionsObject(options);
const options = ES.GetOptionsObject(optionsParam);
const relativeTo = ES.ToRelativeTemporalObject(options);
({ years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = ES.AddDuration(
GetSlot(this, YEARS),
Expand All @@ -265,9 +265,9 @@ export class Duration implements Temporal.Duration {
));
return new Duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
}
round(options) {
round(optionsParam) {
if (!ES.IsTemporalDuration(this)) throw new TypeError('invalid receiver');
if (options === undefined) throw new TypeError('options parameter is required');
if (optionsParam === undefined) throw new TypeError('options parameter is required');
let years = GetSlot(this, YEARS);
let months = GetSlot(this, MONTHS);
let weeks = GetSlot(this, WEEKS);
Expand All @@ -291,7 +291,7 @@ export class Duration implements Temporal.Duration {
microseconds,
nanoseconds
);
options = ES.GetOptionsObject(options);
const options = ES.GetOptionsObject(optionsParam);
let smallestUnit = ES.ToSmallestTemporalUnit(options, undefined);
let smallestUnitPresent = true;
if (!smallestUnit) {
Expand Down Expand Up @@ -374,7 +374,7 @@ export class Duration implements Temporal.Duration {

return new Duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
}
total(options) {
total(optionsParam) {
if (!ES.IsTemporalDuration(this)) throw new TypeError('invalid receiver');
let years = GetSlot(this, YEARS);
let months = GetSlot(this, MONTHS);
Expand All @@ -387,8 +387,8 @@ export class Duration implements Temporal.Duration {
let microseconds = GetSlot(this, MICROSECONDS);
let nanoseconds = GetSlot(this, NANOSECONDS);

if (options === undefined) throw new TypeError('options argument is required');
options = ES.GetOptionsObject(options);
if (optionsParam === undefined) throw new TypeError('options argument is required');
const options = ES.GetOptionsObject(optionsParam);
const unit = ES.ToTemporalDurationTotalUnit(options);
if (unit === undefined) throw new RangeError('unit option is required');
const relativeTo = ES.ToRelativeTemporalObject(options);
Expand Down Expand Up @@ -430,9 +430,9 @@ export class Duration implements Temporal.Duration {
);
return total;
}
toString(options = undefined) {
toString(optionsParam = undefined) {
if (!ES.IsTemporalDuration(this)) throw new TypeError('invalid receiver');
options = ES.GetOptionsObject(options);
const options = ES.GetOptionsObject(optionsParam);
const { precision, unit, increment } = ES.ToSecondsStringPrecision(options);
if (precision === 'minute') throw new RangeError('smallestUnit must not be "minute"');
const roundingMode = ES.ToTemporalRoundingMode(options, 'trunc');
Expand Down Expand Up @@ -470,10 +470,10 @@ export class Duration implements Temporal.Duration {
}
return ES.ToTemporalDuration(item);
}
static compare(one, two, options = undefined) {
one = ES.ToTemporalDuration(one);
two = ES.ToTemporalDuration(two);
options = ES.GetOptionsObject(options);
static compare(oneParam, twoParam, optionsParam = undefined) {
const one = ES.ToTemporalDuration(oneParam);
const two = ES.ToTemporalDuration(twoParam);
const options = ES.GetOptionsObject(optionsParam);
const relativeTo = ES.ToRelativeTemporalObject(options);
const y1 = GetSlot(one, YEARS);
const mon1 = GetSlot(one, MONTHS);
Expand Down
59 changes: 30 additions & 29 deletions lib/instant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ export class Instant implements Temporal.Instant {
);
return new Instant(ns);
}
until(other, options = undefined) {
until(otherParam, optionsParam = undefined) {
if (!ES.IsTemporalInstant(this)) throw new TypeError('invalid receiver');
other = ES.ToTemporalInstant(other);
options = ES.GetOptionsObject(options);
const other = ES.ToTemporalInstant(otherParam);
const options = ES.GetOptionsObject(optionsParam);
const smallestUnit = ES.ToSmallestTemporalUnit(options, 'nanosecond', DISALLOWED_UNITS);
const defaultLargestUnit = ES.LargerOfTwoTemporalUnits('second', smallestUnit);
const largestUnit = ES.ToLargestTemporalUnit(options, 'auto', DISALLOWED_UNITS, defaultLargestUnit);
Expand Down Expand Up @@ -128,10 +128,10 @@ export class Instant implements Temporal.Instant {
const Duration = GetIntrinsic('%Temporal.Duration%');
return new Duration(0, 0, 0, 0, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
}
since(other, options = undefined) {
since(otherParam, optionsParam = undefined) {
if (!ES.IsTemporalInstant(this)) throw new TypeError('invalid receiver');
other = ES.ToTemporalInstant(other);
options = ES.GetOptionsObject(options);
const other = ES.ToTemporalInstant(otherParam);
const options = ES.GetOptionsObject(optionsParam);
const smallestUnit = ES.ToSmallestTemporalUnit(options, 'nanosecond', DISALLOWED_UNITS);
const defaultLargestUnit = ES.LargerOfTwoTemporalUnits('second', smallestUnit);
const largestUnit = ES.ToLargestTemporalUnit(options, 'auto', DISALLOWED_UNITS, defaultLargestUnit);
Expand Down Expand Up @@ -161,10 +161,10 @@ export class Instant implements Temporal.Instant {
const Duration = GetIntrinsic('%Temporal.Duration%');
return new Duration(0, 0, 0, 0, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
}
round(options) {
round(optionsParam) {
if (!ES.IsTemporalInstant(this)) throw new TypeError('invalid receiver');
if (options === undefined) throw new TypeError('options parameter is required');
options = ES.GetOptionsObject(options);
if (optionsParam === undefined) throw new TypeError('options parameter is required');
const options = ES.GetOptionsObject(optionsParam);
const smallestUnit = ES.ToSmallestTemporalUnit(options, undefined, DISALLOWED_UNITS);
if (smallestUnit === undefined) throw new RangeError('smallestUnit is required');
const roundingMode = ES.ToTemporalRoundingMode(options, 'halfExpand');
Expand All @@ -181,16 +181,16 @@ export class Instant implements Temporal.Instant {
const roundedNs = ES.RoundInstant(ns, roundingIncrement, smallestUnit, roundingMode);
return new Instant(roundedNs);
}
equals(other) {
equals(otherParam) {
if (!ES.IsTemporalInstant(this)) throw new TypeError('invalid receiver');
other = ES.ToTemporalInstant(other);
const other = ES.ToTemporalInstant(otherParam);
const one = GetSlot(this, EPOCHNANOSECONDS);
const two = GetSlot(other, EPOCHNANOSECONDS);
return bigInt(one).equals(two);
}
toString(options = undefined) {
toString(optionsParam = undefined) {
if (!ES.IsTemporalInstant(this)) throw new TypeError('invalid receiver');
options = ES.GetOptionsObject(options);
const options = ES.GetOptionsObject(optionsParam);
let timeZone = options.timeZone;
if (timeZone !== undefined) timeZone = ES.ToTemporalTimeZone(timeZone);
const { precision, unit, increment } = ES.ToSecondsStringPrecision(options);
Expand Down Expand Up @@ -228,7 +228,8 @@ export class Instant implements Temporal.Instant {
const timeZone = ES.ToTemporalTimeZone(temporalTimeZoneLike);
return ES.CreateTemporalZonedDateTime(GetSlot(this, EPOCHNANOSECONDS), timeZone, calendar);
}
toZonedDateTimeISO(item) {
toZonedDateTimeISO(itemParam) {
let item = itemParam;
if (!ES.IsTemporalInstant(this)) throw new TypeError('invalid receiver');
if (ES.IsObject(item)) {
const timeZoneProperty = item.timeZone;
Expand All @@ -241,26 +242,26 @@ export class Instant implements Temporal.Instant {
return ES.CreateTemporalZonedDateTime(GetSlot(this, EPOCHNANOSECONDS), timeZone, calendar);
}

static fromEpochSeconds(epochSeconds) {
epochSeconds = ES.ToNumber(epochSeconds);
static fromEpochSeconds(epochSecondsParam) {
const epochSeconds = ES.ToNumber(epochSecondsParam);
const epochNanoseconds = bigInt(epochSeconds).multiply(1e9);
ES.ValidateEpochNanoseconds(epochNanoseconds);
return new Instant(epochNanoseconds);
}
static fromEpochMilliseconds(epochMilliseconds) {
epochMilliseconds = ES.ToNumber(epochMilliseconds);
static fromEpochMilliseconds(epochMillisecondsParam) {
const epochMilliseconds = ES.ToNumber(epochMillisecondsParam);
const epochNanoseconds = bigInt(epochMilliseconds).multiply(1e6);
ES.ValidateEpochNanoseconds(epochNanoseconds);
return new Instant(epochNanoseconds);
}
static fromEpochMicroseconds(epochMicroseconds) {
epochMicroseconds = ES.ToBigInt(epochMicroseconds);
static fromEpochMicroseconds(epochMicrosecondsParam) {
const epochMicroseconds = ES.ToBigInt(epochMicrosecondsParam);
const epochNanoseconds = epochMicroseconds.multiply(1e3);
ES.ValidateEpochNanoseconds(epochNanoseconds);
return new Instant(epochNanoseconds);
}
static fromEpochNanoseconds(epochNanoseconds) {
epochNanoseconds = ES.ToBigInt(epochNanoseconds);
static fromEpochNanoseconds(epochNanosecondsParam) {
const epochNanoseconds = ES.ToBigInt(epochNanosecondsParam);
ES.ValidateEpochNanoseconds(epochNanoseconds);
return new Instant(epochNanoseconds);
}
Expand All @@ -270,13 +271,13 @@ export class Instant implements Temporal.Instant {
}
return ES.ToTemporalInstant(item);
}
static compare(one, two) {
one = ES.ToTemporalInstant(one);
two = ES.ToTemporalInstant(two);
one = GetSlot(one, EPOCHNANOSECONDS);
two = GetSlot(two, EPOCHNANOSECONDS);
if (bigInt(one).lesser(two)) return -1;
if (bigInt(one).greater(two)) return 1;
static compare(oneParam, twoParam) {
const one = ES.ToTemporalInstant(oneParam);
const two = ES.ToTemporalInstant(twoParam);
const oneNs = GetSlot(one, EPOCHNANOSECONDS);
const twoNs = GetSlot(two, EPOCHNANOSECONDS);
if (bigInt(oneNs).lesser(twoNs)) return -1;
if (bigInt(oneNs).greater(twoNs)) return 1;
return 0;
}
[Symbol.toStringTag]!: 'Temporal.Instant';
Expand Down
38 changes: 20 additions & 18 deletions lib/intl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ function getResolvedTimeZoneLazy(obj) {
export function DateTimeFormat(
this: Intl.DateTimeFormat,
locale = undefined,
options: Partial<Intl.DateTimeFormatOptions> = {}
optionsParam: Partial<Intl.DateTimeFormatOptions> = {}
): void {
if (!(this instanceof DateTimeFormat)) return new DateTimeFormat(locale, options);
const hasOptions = typeof options !== 'undefined';
options = hasOptions ? ObjectAssign({}, options) : {};
if (!(this instanceof DateTimeFormat)) return new DateTimeFormat(locale, optionsParam);
const hasOptions = typeof optionsParam !== 'undefined';
const options = hasOptions ? ObjectAssign({}, optionsParam) : {};
const original = new IntlDateTimeFormat(locale, options);
const ro = original.resolvedOptions();

Expand Down Expand Up @@ -200,8 +200,8 @@ function formatRangeToParts(this: typeof DateTimeFormat, a, b) {
return this[ORIGINAL].formatRangeToParts(a, b);
}

function amend(options = {}, amended = {}) {
options = ObjectAssign({}, options);
function amend(optionsParam = {}, amended = {}) {
const options = ObjectAssign({}, optionsParam);
for (const opt of [
'year',
'month',
Expand All @@ -221,8 +221,8 @@ function amend(options = {}, amended = {}) {
return options;
}

function timeAmend(options) {
options = amend(options, {
function timeAmend(optionsParam) {
let options = amend(optionsParam, {
year: false,
month: false,
day: false,
Expand All @@ -240,8 +240,8 @@ function timeAmend(options) {
return options;
}

function yearMonthAmend(options) {
options = amend(options, {
function yearMonthAmend(optionsParam) {
let options = amend(optionsParam, {
day: false,
hour: false,
minute: false,
Expand All @@ -258,8 +258,8 @@ function yearMonthAmend(options) {
return options;
}

function monthDayAmend(options) {
options = amend(options, {
function monthDayAmend(optionsParam) {
let options = amend(optionsParam, {
year: false,
hour: false,
minute: false,
Expand All @@ -276,8 +276,8 @@ function monthDayAmend(options) {
return options;
}

function dateAmend(options) {
options = amend(options, {
function dateAmend(optionsParam) {
let options = amend(optionsParam, {
hour: false,
minute: false,
second: false,
Expand All @@ -295,8 +295,8 @@ function dateAmend(options) {
return options;
}

function datetimeAmend(options) {
options = amend(options, { timeZoneName: false });
function datetimeAmend(optionsParam) {
let options = amend(optionsParam, { timeZoneName: false });
if (!hasTimeOptions(options) && !hasDateOptions(options)) {
options = ObjectAssign({}, options, {
year: 'numeric',
Expand All @@ -310,7 +310,8 @@ function datetimeAmend(options) {
return options;
}

function zonedDateTimeAmend(options) {
function zonedDateTimeAmend(optionsParam) {
let options = optionsParam;
if (!hasTimeOptions(options) && !hasDateOptions(options)) {
options = ObjectAssign({}, options, {
year: 'numeric',
Expand All @@ -325,7 +326,8 @@ function zonedDateTimeAmend(options) {
return options;
}

function instantAmend(options) {
function instantAmend(optionsParam) {
let options = optionsParam;
if (!hasTimeOptions(options) && !hasDateOptions(options)) {
options = ObjectAssign({}, options, {
year: 'numeric',
Expand Down
Loading