diff --git a/.eslintrc.yml b/.eslintrc.yml index 72cabe5b..41afe3ca 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -56,6 +56,9 @@ rules: - error - max: 1 no-trailing-spaces: error + no-param-reassign: + - error + - props: false object-curly-spacing: - error - always @@ -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 diff --git a/lib/calendar.ts b/lib/calendar.ts index 390d2cea..ee64c34b 100644 --- a/lib/calendar.ts +++ b/lib/calendar.ts @@ -36,14 +36,14 @@ const ReflectApply = Reflect.apply; const impl = {}; export class Calendar implements Temporal.Calendar { - constructor(id) { + constructor(idParam) { // Note: if the argument is not passed, IsBuiltinCalendar("undefined") will fail. This check // exists only to improve the error message. if (arguments.length < 1) { throw new RangeError('missing argument: id is required'); } - id = ES.ToString(id); + const id = ES.ToString(idParam); if (!IsBuiltinCalendar(id)) throw new RangeError(`invalid calendar identifier ${id}`); CreateSlots(this); SetSlot(this, CALENDAR_ID, id); @@ -60,22 +60,22 @@ export class Calendar implements Temporal.Calendar { get id() { return ES.ToString(this); } - dateFromFields(fields, options = undefined) { + dateFromFields(fields, optionsParam = undefined) { if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); if (!ES.IsObject(fields)) throw new TypeError('invalid fields'); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); return impl[GetSlot(this, CALENDAR_ID)].dateFromFields(fields, options, this); } - yearMonthFromFields(fields, options = undefined) { + yearMonthFromFields(fields, optionsParam = undefined) { if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); if (!ES.IsObject(fields)) throw new TypeError('invalid fields'); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); return impl[GetSlot(this, CALENDAR_ID)].yearMonthFromFields(fields, options, this); } - monthDayFromFields(fields, options = undefined) { + monthDayFromFields(fields, optionsParam = undefined) { if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); if (!ES.IsObject(fields)) throw new TypeError('invalid fields'); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); return impl[GetSlot(this, CALENDAR_ID)].monthDayFromFields(fields, options, this); } fields(fields) { @@ -105,11 +105,11 @@ export class Calendar implements Temporal.Calendar { if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); return impl[GetSlot(this, CALENDAR_ID)].mergeFields(fields, additionalFields); } - dateAdd(date, duration, options = undefined) { + dateAdd(dateParam, durationParam, optionsParam = undefined) { if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); - date = ES.ToTemporalDate(date); - duration = ES.ToTemporalDuration(duration); - options = ES.GetOptionsObject(options); + const date = ES.ToTemporalDate(dateParam); + const duration = ES.ToTemporalDuration(durationParam); + const options = ES.GetOptionsObject(optionsParam); const overflow = ES.ToTemporalOverflow(options); const { days } = ES.BalanceDuration( GetSlot(duration, DAYS), @@ -131,11 +131,11 @@ export class Calendar implements Temporal.Calendar { this ); } - dateUntil(one, two, options = undefined) { + dateUntil(oneParam, twoParam, optionsParam = undefined) { if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); - one = ES.ToTemporalDate(one); - two = ES.ToTemporalDate(two); - options = ES.GetOptionsObject(options); + const one = ES.ToTemporalDate(oneParam); + const two = ES.ToTemporalDate(twoParam); + const options = ES.GetOptionsObject(optionsParam); const largestUnit = ES.ToLargestTemporalUnit( options, 'auto', @@ -146,73 +146,83 @@ export class Calendar implements Temporal.Calendar { const Duration = GetIntrinsic('%Temporal.Duration%'); return new Duration(years, months, weeks, days, 0, 0, 0, 0, 0, 0); } - year(date) { + year(dateParam) { + let date = dateParam; if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date); return impl[GetSlot(this, CALENDAR_ID)].year(date); } - month(date) { + month(dateParam) { + let date = dateParam; if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); if (ES.IsTemporalMonthDay(date)) throw new TypeError('use monthCode on PlainMonthDay instead'); if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date); return impl[GetSlot(this, CALENDAR_ID)].month(date); } - monthCode(date) { + monthCode(dateParam) { + let date = dateParam; if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); if (!ES.IsTemporalYearMonth(date) && !ES.IsTemporalMonthDay(date)) date = ES.ToTemporalDate(date); return impl[GetSlot(this, CALENDAR_ID)].monthCode(date); } - day(date) { + day(dateParam) { + let date = dateParam; if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); if (!ES.IsTemporalMonthDay(date)) date = ES.ToTemporalDate(date); return impl[GetSlot(this, CALENDAR_ID)].day(date); } - era(date) { + era(dateParam) { + let date = dateParam; if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date); return impl[GetSlot(this, CALENDAR_ID)].era(date); } - eraYear(date) { + eraYear(dateParam) { + let date = dateParam; if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date); return impl[GetSlot(this, CALENDAR_ID)].eraYear(date); } - dayOfWeek(date) { + dayOfWeek(dateParam) { if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); - date = ES.ToTemporalDate(date); + const date = ES.ToTemporalDate(dateParam); return impl[GetSlot(this, CALENDAR_ID)].dayOfWeek(date); } - dayOfYear(date) { + dayOfYear(dateParam) { if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); - date = ES.ToTemporalDate(date); + const date = ES.ToTemporalDate(dateParam); return impl[GetSlot(this, CALENDAR_ID)].dayOfYear(date); } - weekOfYear(date) { + weekOfYear(dateParam) { if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); - date = ES.ToTemporalDate(date); + const date = ES.ToTemporalDate(dateParam); return impl[GetSlot(this, CALENDAR_ID)].weekOfYear(date); } - daysInWeek(date) { + daysInWeek(dateParam) { if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); - date = ES.ToTemporalDate(date); + const date = ES.ToTemporalDate(dateParam); return impl[GetSlot(this, CALENDAR_ID)].daysInWeek(date); } - daysInMonth(date) { + daysInMonth(dateParam) { + let date = dateParam; if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date); return impl[GetSlot(this, CALENDAR_ID)].daysInMonth(date); } - daysInYear(date) { + daysInYear(dateParam) { + let date = dateParam; if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date); return impl[GetSlot(this, CALENDAR_ID)].daysInYear(date); } - monthsInYear(date) { + monthsInYear(dateParam) { + let date = dateParam; if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date); return impl[GetSlot(this, CALENDAR_ID)].monthsInYear(date); } - inLeapYear(date) { + inLeapYear(dateParam) { + let date = dateParam; if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date); return impl[GetSlot(this, CALENDAR_ID)].inLeapYear(date); @@ -234,30 +244,39 @@ MakeIntrinsicClass(Calendar, 'Temporal.Calendar'); DefineIntrinsic('Temporal.Calendar.from', Calendar.from); impl['iso8601'] = { - dateFromFields(fields, options, calendar) { + dateFromFields(fieldsParam, options, calendar) { const overflow = ES.ToTemporalOverflow(options); - fields = ES.PrepareTemporalFields(fields, [['day'], ['month', undefined], ['monthCode', undefined], ['year']]); + let fields = ES.PrepareTemporalFields(fieldsParam, [ + ['day'], + ['month', undefined], + ['monthCode', undefined], + ['year'] + ]); fields = resolveNonLunisolarMonth(fields); - let { year, month, day } = fields; + let { year, month, day } = fields as any; ({ year, month, day } = ES.RegulateISODate(year, month, day, overflow)); return ES.CreateTemporalDate(year, month, day, calendar); }, - yearMonthFromFields(fields, options, calendar) { + yearMonthFromFields(fieldsParam, options, calendar) { const overflow = ES.ToTemporalOverflow(options); - fields = ES.PrepareTemporalFields(fields, [['month', undefined], ['monthCode', undefined], ['year']]); + let fields = ES.PrepareTemporalFields(fieldsParam, [ + ['month', undefined], + ['monthCode', undefined], + ['year'] + ]) as any; fields = resolveNonLunisolarMonth(fields); let { year, month } = fields; ({ year, month } = ES.RegulateISOYearMonth(year, month, overflow)); return ES.CreateTemporalYearMonth(year, month, calendar, /* referenceISODay = */ 1); }, - monthDayFromFields(fields, options, calendar) { + monthDayFromFields(fieldsParam, options, calendar) { const overflow = ES.ToTemporalOverflow(options); - fields = ES.PrepareTemporalFields(fields, [ + let fields = ES.PrepareTemporalFields(fieldsParam, [ ['day'], ['month', undefined], ['monthCode', undefined], ['year', undefined] - ]); + ]) as any; if (fields.month !== undefined && fields.year === undefined && fields.monthCode === undefined) { throw new TypeError('either year or monthCode required with month'); } @@ -339,14 +358,16 @@ impl['iso8601'] = { daysInMonth(date) { return ES.ISODaysInMonth(GetSlot(date, ISO_YEAR), GetSlot(date, ISO_MONTH)); }, - daysInYear(date) { + daysInYear(dateParam) { + let date = dateParam; if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date); return ES.LeapYear(GetSlot(date, ISO_YEAR)) ? 366 : 365; }, monthsInYear() { return 12; }, - inLeapYear(date) { + inLeapYear(dateParam) { + let date = dateParam; if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date); return ES.LeapYear(GetSlot(date, ISO_YEAR)); } @@ -682,8 +703,9 @@ const nonIsoHelperBase: NonIsoHelperBase = { * - no eras or a constant era defined in `.constantEra` * - non-lunisolar calendar (no leap months) * */ - adjustCalendarDate(calendarDate, cache, overflow /*, fromLegacyDate = false */) { + adjustCalendarDate(calendarDateParam, cache, overflow /*, fromLegacyDate = false */) { if (this.calendarType === 'lunisolar') throw new RangeError('Override required for lunisolar calendars'); + let calendarDate = calendarDateParam; this.validateCalendarDate(calendarDate); const largestMonth = this.monthsInYear(calendarDate, cache); let { month, year, eraYear, monthCode } = calendarDate; @@ -712,11 +734,11 @@ const nonIsoHelperBase: NonIsoHelperBase = { } return { ...calendarDate, month, day }; }, - calendarToIsoDate(date, overflow = 'constrain', cache) { - const originalDate = date; + calendarToIsoDate(dateParam, overflow = 'constrain', cache) { + const originalDate = dateParam; // First, normalize the calendar date to ensure that (year, month, day) // are all present, converting monthCode and eraYear if needed. - date = this.adjustCalendarDate(date, cache, overflow, false); + let date = this.adjustCalendarDate(dateParam, cache, overflow, false); // Fix obviously out-of-bounds values. Values that are valid generally, but // not in this particular year, may not be caught here for some calendars. @@ -863,11 +885,11 @@ const nonIsoHelperBase: NonIsoHelperBase = { const result = this.isoToCalendarDate(isoDate, cache); return result; }, - compareCalendarDates(date1, date2) { + compareCalendarDates(date1Param, date2Param) { // `date1` and `date2` are already records. The calls below simply validate // that all three required fields are present. - date1 = ES.PrepareTemporalFields(date1, [['day'], ['month'], ['year']]); - date2 = ES.PrepareTemporalFields(date2, [['day'], ['month'], ['year']]); + const date1 = ES.PrepareTemporalFields(date1Param, [['day'], ['month'], ['year']]) as any; + const date2 = ES.PrepareTemporalFields(date2Param, [['day'], ['month'], ['year']]) as any; if (date1.year !== date2.year) return ES.ComparisonResult(date1.year - date2.year); if (date1.month !== date2.month) return ES.ComparisonResult(date1.month - date2.month); if (date1.day !== date2.day) return ES.ComparisonResult(date1.day - date2.day); @@ -888,7 +910,8 @@ const nonIsoHelperBase: NonIsoHelperBase = { const addedCalendar = this.isoToCalendarDate(addedIso, cache); return addedCalendar; }, - addMonthsCalendar(calendarDate, months, overflow, cache) { + addMonthsCalendar(calendarDateParam, months, overflow, cache) { + let calendarDate = calendarDateParam; const { day } = calendarDate; for (let i = 0, absMonths = MathAbs(months); i < absMonths; i++) { const { month } = calendarDate; @@ -927,8 +950,8 @@ const nonIsoHelperBase: NonIsoHelperBase = { addCalendar(calendarDate, { years = 0, months = 0, weeks = 0, days = 0 }, overflow, cache) { const { year, month, day } = calendarDate; const addedMonths = this.addMonthsCalendar({ year: year + years, month, day }, months, overflow, cache); - days += weeks * 7; - const addedDays = this.addDaysCalendar(addedMonths, days, cache); + const initialDays = days + weeks * 7; + const addedDays = this.addDaysCalendar(addedMonths, initialDays, cache); return addedDays; }, untilCalendar(calendarOne, calendarTwo, largestUnit, cache) { @@ -1324,10 +1347,10 @@ const helperIndian = ObjectAssign({}, nonIsoHelperBase, { if (this.inLeapYear(calendarDate) && monthInfo.leap) monthInfo = monthInfo.leap; return monthInfo; }, - estimateIsoDate(this: typeof helperIndian & NonIsoHelperBase, calendarDate) { + estimateIsoDate(this: typeof helperIndian & NonIsoHelperBase, calendarDateParam) { // FYI, this "estimate" is always the exact ISO date, which makes the Indian // calendar fast! - calendarDate = this.adjustCalendarDate(calendarDate); + const calendarDate = this.adjustCalendarDate(calendarDateParam); const monthInfo = this.getMonthInfo(calendarDate); const isoYear = calendarDate.year + 78 + (monthInfo.nextYear ? 1 : 0); const isoMonth = monthInfo.month; @@ -1389,7 +1412,8 @@ const helperIndian = ObjectAssign({}, nonIsoHelperBase, { * } * ``` * */ -function adjustEras(eras) { +function adjustEras(erasParam) { + let eras = erasParam; if (eras.length === 0) { throw new RangeError('Invalid era data: eras are required'); } @@ -1558,10 +1582,11 @@ const makeHelperGregorian = (id, originalEras) => { }, adjustCalendarDate( this: typeof helperGregorian & NonIsoHelperBase, - calendarDate, + calendarDateParam, cache, overflow /*, fromLegacyDate = false */ ) { + let calendarDate = calendarDateParam; // Because this is not a lunisolar calendar, it's safe to convert monthCode to a number const { month, monthCode } = calendarDate; if (month === undefined) calendarDate = { ...calendarDate, month: monthCodeNumberPart(monthCode) }; @@ -1571,8 +1596,8 @@ const makeHelperGregorian = (id, originalEras) => { calendarDate = ReflectApply(nonIsoHelperBase.adjustCalendarDate, this, [calendarDate, cache, overflow]); return calendarDate; }, - estimateIsoDate(this: typeof helperGregorian & NonIsoHelperBase, calendarDate) { - calendarDate = this.adjustCalendarDate(calendarDate); + estimateIsoDate(this: typeof helperGregorian & NonIsoHelperBase, calendarDateParam) { + const calendarDate = this.adjustCalendarDate(calendarDateParam); const { year, month, day } = calendarDate; const { anchorEra } = this; const isoYearEstimate = year + anchorEra.isoEpoch.year - (anchorEra.hasYearZero ? 0 : 1); @@ -1931,11 +1956,11 @@ const helperDangi = ObjectAssign({}, { ...helperChinese, id: 'dangi' }); * ISO and non-ISO implementations vs. code that was very different. */ const nonIsoGeneralImpl = { - dateFromFields(this: typeof nonIsoGeneralImpl & { helper: NonIsoHelperBase }, fields, options, calendar) { + dateFromFields(this: typeof nonIsoGeneralImpl & { helper: NonIsoHelperBase }, fieldsParam, options, calendar) { const overflow = ES.ToTemporalOverflow(options); const cache = new OneObjectCache(); // Intentionally alphabetical - fields = ES.PrepareTemporalFields(fields, [ + const fields = ES.PrepareTemporalFields(fieldsParam, [ ['day'], ['era', undefined], ['eraYear', undefined], @@ -1948,11 +1973,11 @@ const nonIsoGeneralImpl = { cache.setObject(result); return result; }, - yearMonthFromFields(this: typeof nonIsoGeneralImpl & { helper: NonIsoHelperBase }, fields, options, calendar) { + yearMonthFromFields(this: typeof nonIsoGeneralImpl & { helper: NonIsoHelperBase }, fieldsParam, options, calendar) { const overflow = ES.ToTemporalOverflow(options); const cache = new OneObjectCache(); // Intentionally alphabetical - fields = ES.PrepareTemporalFields(fields, [ + const fields = ES.PrepareTemporalFields(fieldsParam, [ ['era', undefined], ['eraYear', undefined], ['month', undefined], @@ -1964,14 +1989,14 @@ const nonIsoGeneralImpl = { cache.setObject(result); return result; }, - monthDayFromFields(this: typeof nonIsoGeneralImpl & { helper: NonIsoHelperBase }, fields, options, calendar) { + monthDayFromFields(this: typeof nonIsoGeneralImpl & { helper: NonIsoHelperBase }, fieldsParam, options, calendar) { const overflow = ES.ToTemporalOverflow(options); // All built-in calendars require `day`, but some allow other fields to be // substituted for `month`. And for lunisolar calendars, either `monthCode` // or `year` must be provided because `month` is ambiguous without a year or // a code. const cache = new OneObjectCache(); - fields = ES.PrepareTemporalFields(fields, [ + const fields = ES.PrepareTemporalFields(fieldsParam, [ ['day'], ['era', undefined], ['eraYear', undefined], @@ -1985,7 +2010,8 @@ const nonIsoGeneralImpl = { cache.setObject(result); return result; }, - fields(fields) { + fields(fieldsParam) { + let fields = fieldsParam; if (fields.includes('year')) fields = [...fields, 'era', 'eraYear']; return fields; }, @@ -2108,7 +2134,8 @@ const nonIsoGeneralImpl = { const result = this.helper.calendarDaysUntil(startOfMonthCalendar, startOfNextMonthCalendar, cache); return result; }, - daysInYear(this: typeof nonIsoGeneralImpl & { helper: NonIsoHelperBase }, date) { + daysInYear(this: typeof nonIsoGeneralImpl & { helper: NonIsoHelperBase }, dateParam) { + let date = dateParam; if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date); const cache = OneObjectCache.getCacheForObject(date); const calendarDate = this.helper.temporalToCalendarDate(date, cache); @@ -2123,7 +2150,8 @@ const nonIsoGeneralImpl = { const result = this.helper.monthsInYear(calendarDate, cache); return result; }, - inLeapYear(this: typeof nonIsoGeneralImpl & { helper: NonIsoHelperBase }, date) { + inLeapYear(this: typeof nonIsoGeneralImpl & { helper: NonIsoHelperBase }, dateParam) { + let date = dateParam; if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date); const cache = OneObjectCache.getCacheForObject(date); const calendarDate = this.helper.temporalToCalendarDate(date, cache); diff --git a/lib/duration.ts b/lib/duration.ts index aff06c58..9e2c8216 100644 --- a/lib/duration.ts +++ b/lib/duration.ts @@ -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, @@ -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), @@ -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), @@ -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); @@ -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) { @@ -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); @@ -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); @@ -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'); @@ -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); diff --git a/lib/instant.ts b/lib/instant.ts index fc5562b2..8a76a336 100644 --- a/lib/instant.ts +++ b/lib/instant.ts @@ -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); @@ -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); @@ -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'); @@ -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); @@ -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; @@ -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); } @@ -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'; diff --git a/lib/intl.ts b/lib/intl.ts index 49f0c534..b49f26e2 100644 --- a/lib/intl.ts +++ b/lib/intl.ts @@ -69,11 +69,11 @@ function getResolvedTimeZoneLazy(obj) { export function DateTimeFormat( this: Intl.DateTimeFormat, locale = undefined, - options: Partial = {} + optionsParam: Partial = {} ): 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(); @@ -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', @@ -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, @@ -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, @@ -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, @@ -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, @@ -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', @@ -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', @@ -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', diff --git a/lib/plaindate.ts b/lib/plaindate.ts index 5457f333..efdd7ab8 100644 --- a/lib/plaindate.ts +++ b/lib/plaindate.ts @@ -22,11 +22,16 @@ import { Temporal } from '..'; const DISALLOWED_UNITS = ['hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond']; export class PlainDate implements Temporal.PlainDate { - constructor(isoYear, isoMonth, isoDay, calendar: Temporal.CalendarProtocol | string = ES.GetISO8601Calendar()) { - isoYear = ES.ToIntegerThrowOnInfinity(isoYear); - isoMonth = ES.ToIntegerThrowOnInfinity(isoMonth); - isoDay = ES.ToIntegerThrowOnInfinity(isoDay); - calendar = ES.ToTemporalCalendar(calendar); + constructor( + isoYearParam, + isoMonthParam, + isoDayParam, + calendarParam: Temporal.CalendarProtocol | string = ES.GetISO8601Calendar() + ) { + const isoYear = ES.ToIntegerThrowOnInfinity(isoYearParam); + const isoMonth = ES.ToIntegerThrowOnInfinity(isoMonthParam); + const isoDay = ES.ToIntegerThrowOnInfinity(isoDayParam); + const calendar = ES.ToTemporalCalendar(calendarParam); // Note: if the arguments are not passed, // ToIntegerThrowOnInfinity(undefined) will have returned 0, which will @@ -98,7 +103,7 @@ export class PlainDate implements Temporal.PlainDate { if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver'); return ES.CalendarInLeapYear(GetSlot(this, CALENDAR), this); } - with(temporalDateLike, options = undefined) { + with(temporalDateLike, optionsParam = undefined) { if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver'); if (!ES.IsObject(temporalDateLike)) { throw new TypeError('invalid argument'); @@ -123,34 +128,34 @@ export class PlainDate implements Temporal.PlainDate { fields = ES.CalendarMergeFields(calendar, fields, props); fields = ES.ToTemporalDateFields(fields, fieldNames); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); return ES.DateFromFields(calendar, fields, options); } - withCalendar(calendar) { + withCalendar(calendarParam) { if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver'); - calendar = ES.ToTemporalCalendar(calendar); + const calendar = ES.ToTemporalCalendar(calendarParam); return new PlainDate(GetSlot(this, ISO_YEAR), GetSlot(this, ISO_MONTH), GetSlot(this, ISO_DAY), calendar); } - add(temporalDurationLike, options = undefined) { + add(temporalDurationLike, optionsParam = undefined) { if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver'); const duration = ES.ToTemporalDuration(temporalDurationLike); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); return ES.CalendarDateAdd(GetSlot(this, CALENDAR), this, duration, options); } - subtract(temporalDurationLike, options = undefined) { + subtract(temporalDurationLike, optionsParam = undefined) { if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver'); const duration = ES.CreateNegatedTemporalDuration(ES.ToTemporalDuration(temporalDurationLike)); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); return ES.CalendarDateAdd(GetSlot(this, CALENDAR), this, duration, options); } - until(other, options = undefined) { + until(otherParam, optionsParam = undefined) { if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalDate(other); + const other = ES.ToTemporalDate(otherParam); const calendar = GetSlot(this, CALENDAR); const otherCalendar = GetSlot(other, CALENDAR); const calendarId = ES.ToString(calendar); @@ -159,7 +164,7 @@ export class PlainDate implements Temporal.PlainDate { throw new RangeError(`cannot compute difference between dates of ${calendarId} and ${otherCalendarId} calendars`); } - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const smallestUnit = ES.ToSmallestTemporalUnit(options, 'day', DISALLOWED_UNITS); const defaultLargestUnit = ES.LargerOfTwoTemporalUnits('day', smallestUnit); const largestUnit = ES.ToLargestTemporalUnit(options, 'auto', DISALLOWED_UNITS, defaultLargestUnit); @@ -204,9 +209,9 @@ export class PlainDate implements Temporal.PlainDate { const Duration = GetIntrinsic('%Temporal.Duration%'); return new Duration(years, months, weeks, days, 0, 0, 0, 0, 0, 0); } - since(other, options = undefined) { + since(otherParam, optionsParam = undefined) { if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalDate(other); + const other = ES.ToTemporalDate(otherParam); const calendar = GetSlot(this, CALENDAR); const otherCalendar = GetSlot(other, CALENDAR); const calendarId = ES.ToString(calendar); @@ -215,7 +220,7 @@ export class PlainDate implements Temporal.PlainDate { throw new RangeError(`cannot compute difference between dates of ${calendarId} and ${otherCalendarId} calendars`); } - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const smallestUnit = ES.ToSmallestTemporalUnit(options, 'day', DISALLOWED_UNITS); const defaultLargestUnit = ES.LargerOfTwoTemporalUnits('day', smallestUnit); const largestUnit = ES.ToLargestTemporalUnit(options, 'auto', DISALLOWED_UNITS, defaultLargestUnit); @@ -260,9 +265,9 @@ export class PlainDate implements Temporal.PlainDate { return new Duration(-years, -months, -weeks, -days, 0, 0, 0, 0, 0, 0); } - equals(other) { + equals(otherParam) { if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalDate(other); + const other = ES.ToTemporalDate(otherParam); for (const slot of [ISO_YEAR, ISO_MONTH, ISO_DAY]) { const val1 = GetSlot(this, slot); const val2 = GetSlot(other, slot); @@ -270,9 +275,9 @@ export class PlainDate implements Temporal.PlainDate { } return ES.CalendarEquals(GetSlot(this, CALENDAR), GetSlot(other, CALENDAR)); } - toString(options = undefined) { + toString(optionsParam = undefined) { if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver'); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const showCalendar = ES.ToShowCalendarOption(options); return ES.TemporalDateToString(this, showCalendar); } @@ -287,16 +292,16 @@ export class PlainDate implements Temporal.PlainDate { valueOf(): never { throw new TypeError('use compare() or equals() to compare Temporal.PlainDate'); } - toPlainDateTime(temporalTime = undefined) { + toPlainDateTime(temporalTimeParam = undefined) { if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver'); const year = GetSlot(this, ISO_YEAR); const month = GetSlot(this, ISO_MONTH); const day = GetSlot(this, ISO_DAY); const calendar = GetSlot(this, CALENDAR); - if (temporalTime === undefined) return ES.CreateTemporalDateTime(year, month, day, 0, 0, 0, 0, 0, 0, calendar); + if (temporalTimeParam === undefined) return ES.CreateTemporalDateTime(year, month, day, 0, 0, 0, 0, 0, 0, calendar); - temporalTime = ES.ToTemporalTime(temporalTime); + const temporalTime = ES.ToTemporalTime(temporalTimeParam); const hour = GetSlot(temporalTime, ISO_HOUR); const minute = GetSlot(temporalTime, ISO_MINUTE); const second = GetSlot(temporalTime, ISO_SECOND); @@ -392,8 +397,8 @@ export class PlainDate implements Temporal.PlainDate { isoYear: GetSlot(this, ISO_YEAR) }; } - static from(item, options = undefined) { - options = ES.GetOptionsObject(options); + static from(item, optionsParam = undefined) { + const options = ES.GetOptionsObject(optionsParam); if (ES.IsTemporalDate(item)) { ES.ToTemporalOverflow(options); // validate and ignore return ES.CreateTemporalDate( @@ -405,9 +410,9 @@ export class PlainDate implements Temporal.PlainDate { } return ES.ToTemporalDate(item, options); } - static compare(one, two) { - one = ES.ToTemporalDate(one); - two = ES.ToTemporalDate(two); + static compare(oneParam, twoParam) { + const one = ES.ToTemporalDate(oneParam); + const two = ES.ToTemporalDate(twoParam); return ES.CompareISODate( GetSlot(one, ISO_YEAR), GetSlot(one, ISO_MONTH), diff --git a/lib/plaindatetime.ts b/lib/plaindatetime.ts index 78418360..8523d00f 100644 --- a/lib/plaindatetime.ts +++ b/lib/plaindatetime.ts @@ -22,27 +22,27 @@ import { Temporal } from '..'; export class PlainDateTime implements Temporal.PlainDateTime { constructor( - isoYear, - isoMonth, - isoDay, - hour = 0, - minute = 0, - second = 0, - millisecond = 0, - microsecond = 0, - nanosecond = 0, - calendar: Temporal.CalendarProtocol | string = ES.GetISO8601Calendar() + isoYearParam, + isoMonthParam, + isoDayParam, + hourParam = 0, + minuteParam = 0, + secondParam = 0, + millisecondParam = 0, + microsecondParam = 0, + nanosecondParam = 0, + calendarParam: Temporal.CalendarProtocol | string = ES.GetISO8601Calendar() ) { - isoYear = ES.ToIntegerThrowOnInfinity(isoYear); - isoMonth = ES.ToIntegerThrowOnInfinity(isoMonth); - isoDay = ES.ToIntegerThrowOnInfinity(isoDay); - hour = ES.ToIntegerThrowOnInfinity(hour); - minute = ES.ToIntegerThrowOnInfinity(minute); - second = ES.ToIntegerThrowOnInfinity(second); - millisecond = ES.ToIntegerThrowOnInfinity(millisecond); - microsecond = ES.ToIntegerThrowOnInfinity(microsecond); - nanosecond = ES.ToIntegerThrowOnInfinity(nanosecond); - calendar = ES.ToTemporalCalendar(calendar); + const isoYear = ES.ToIntegerThrowOnInfinity(isoYearParam); + const isoMonth = ES.ToIntegerThrowOnInfinity(isoMonthParam); + const isoDay = ES.ToIntegerThrowOnInfinity(isoDayParam); + const hour = ES.ToIntegerThrowOnInfinity(hourParam); + const minute = ES.ToIntegerThrowOnInfinity(minuteParam); + const second = ES.ToIntegerThrowOnInfinity(secondParam); + const millisecond = ES.ToIntegerThrowOnInfinity(millisecondParam); + const microsecond = ES.ToIntegerThrowOnInfinity(microsecondParam); + const nanosecond = ES.ToIntegerThrowOnInfinity(nanosecondParam); + const calendar = ES.ToTemporalCalendar(calendarParam); // Note: if the arguments are not passed, // ToIntegerThrowOnInfinity(undefined) will have returned 0, which will @@ -150,7 +150,7 @@ export class PlainDateTime implements Temporal.PlainDateTime { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); return ES.CalendarInLeapYear(GetSlot(this, CALENDAR), this); } - with(temporalDateTimeLike, options = undefined) { + with(temporalDateTimeLike, optionsParam = undefined) { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); if (!ES.IsObject(temporalDateTimeLike)) { throw new TypeError('invalid argument'); @@ -165,7 +165,7 @@ export class PlainDateTime implements Temporal.PlainDateTime { throw new TypeError('with() does not support a timeZone property'); } - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const calendar = GetSlot(this, CALENDAR); const fieldNames = ES.CalendarFields(calendar, [ 'day', @@ -202,16 +202,16 @@ export class PlainDateTime implements Temporal.PlainDateTime { calendar ); } - withPlainTime(temporalTime = undefined) { + withPlainTime(temporalTimeParam = undefined) { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); const year = GetSlot(this, ISO_YEAR); const month = GetSlot(this, ISO_MONTH); const day = GetSlot(this, ISO_DAY); const calendar = GetSlot(this, CALENDAR); - if (temporalTime === undefined) return ES.CreateTemporalDateTime(year, month, day, 0, 0, 0, 0, 0, 0, calendar); + if (temporalTimeParam === undefined) return ES.CreateTemporalDateTime(year, month, day, 0, 0, 0, 0, 0, 0, calendar); - temporalTime = ES.ToTemporalTime(temporalTime); + const temporalTime = ES.ToTemporalTime(temporalTimeParam); const hour = GetSlot(temporalTime, ISO_HOUR); const minute = GetSlot(temporalTime, ISO_MINUTE); const second = GetSlot(temporalTime, ISO_SECOND); @@ -232,10 +232,10 @@ export class PlainDateTime implements Temporal.PlainDateTime { calendar ); } - withPlainDate(temporalDate) { + withPlainDate(temporalDateParam) { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); - temporalDate = ES.ToTemporalDate(temporalDate); + const temporalDate = ES.ToTemporalDate(temporalDateParam); const year = GetSlot(temporalDate, ISO_YEAR); const month = GetSlot(temporalDate, ISO_MONTH); const day = GetSlot(temporalDate, ISO_DAY); @@ -262,9 +262,9 @@ export class PlainDateTime implements Temporal.PlainDateTime { calendar ); } - withCalendar(calendar) { + withCalendar(calendarParam) { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); - calendar = ES.ToTemporalCalendar(calendar); + const calendar = ES.ToTemporalCalendar(calendarParam); return new PlainDateTime( GetSlot(this, ISO_YEAR), GetSlot(this, ISO_MONTH), @@ -278,11 +278,11 @@ export class PlainDateTime implements Temporal.PlainDateTime { calendar ); } - add(temporalDurationLike, options = undefined) { + add(temporalDurationLike, optionsParam = undefined) { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); const duration = ES.ToLimitedTemporalDuration(temporalDurationLike); const { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = duration; - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const calendar = GetSlot(this, CALENDAR); const { year, month, day, hour, minute, second, millisecond, microsecond, nanosecond } = ES.AddDateTime( GetSlot(this, ISO_YEAR), @@ -320,11 +320,11 @@ export class PlainDateTime implements Temporal.PlainDateTime { calendar ); } - subtract(temporalDurationLike, options = undefined) { + subtract(temporalDurationLike, optionsParam = undefined) { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); const duration = ES.ToLimitedTemporalDuration(temporalDurationLike); const { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = duration; - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const calendar = GetSlot(this, CALENDAR); const { year, month, day, hour, minute, second, millisecond, microsecond, nanosecond } = ES.AddDateTime( GetSlot(this, ISO_YEAR), @@ -362,9 +362,9 @@ export class PlainDateTime implements Temporal.PlainDateTime { calendar ); } - until(other, options = undefined) { + until(otherParam, optionsParam = undefined) { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalDateTime(other); + const other = ES.ToTemporalDateTime(otherParam); const calendar = GetSlot(this, CALENDAR); const otherCalendar = GetSlot(other, CALENDAR); const calendarId = ES.ToString(calendar); @@ -372,7 +372,7 @@ export class PlainDateTime implements Temporal.PlainDateTime { if (calendarId !== otherCalendarId) { throw new RangeError(`cannot compute difference between dates of ${calendarId} and ${otherCalendarId} calendars`); } - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const smallestUnit = ES.ToSmallestTemporalUnit(options, 'nanosecond'); const defaultLargestUnit = ES.LargerOfTwoTemporalUnits('day', smallestUnit); const largestUnit = ES.ToLargestTemporalUnit(options, 'auto', [], defaultLargestUnit); @@ -436,9 +436,9 @@ export class PlainDateTime implements Temporal.PlainDateTime { const Duration = GetIntrinsic('%Temporal.Duration%'); return new Duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds); } - since(other, options = undefined) { + since(otherParam, optionsParam = undefined) { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalDateTime(other); + const other = ES.ToTemporalDateTime(otherParam); const calendar = GetSlot(this, CALENDAR); const otherCalendar = GetSlot(other, CALENDAR); const calendarId = ES.ToString(calendar); @@ -446,7 +446,7 @@ export class PlainDateTime implements Temporal.PlainDateTime { if (calendarId !== otherCalendarId) { throw new RangeError(`cannot compute difference between dates of ${calendarId} and ${otherCalendarId} calendars`); } - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const smallestUnit = ES.ToSmallestTemporalUnit(options, 'nanosecond'); const defaultLargestUnit = ES.LargerOfTwoTemporalUnits('day', smallestUnit); const largestUnit = ES.ToLargestTemporalUnit(options, 'auto', [], defaultLargestUnit); @@ -521,10 +521,10 @@ export class PlainDateTime implements Temporal.PlainDateTime { -nanoseconds ); } - round(options) { + round(optionsParam) { if (!ES.IsTemporalDateTime(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, ['year', 'month', 'week']); if (smallestUnit === undefined) throw new RangeError('smallestUnit is required'); const roundingMode = ES.ToTemporalRoundingMode(options, 'halfExpand'); @@ -576,9 +576,9 @@ export class PlainDateTime implements Temporal.PlainDateTime { GetSlot(this, CALENDAR) ); } - equals(other) { + equals(otherParam) { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalDateTime(other); + const other = ES.ToTemporalDateTime(otherParam); for (const slot of [ ISO_YEAR, ISO_MONTH, @@ -596,9 +596,9 @@ export class PlainDateTime implements Temporal.PlainDateTime { } return ES.CalendarEquals(GetSlot(this, CALENDAR), GetSlot(other, CALENDAR)); } - toString(options = undefined) { + toString(optionsParam = undefined) { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const { precision, unit, increment } = ES.ToSecondsStringPrecision(options); const showCalendar = ES.ToShowCalendarOption(options); const roundingMode = ES.ToTemporalRoundingMode(options, 'trunc'); @@ -616,10 +616,10 @@ export class PlainDateTime implements Temporal.PlainDateTime { throw new TypeError('use compare() or equals() to compare Temporal.PlainDateTime'); } - toZonedDateTime(temporalTimeZoneLike, options = undefined) { + toZonedDateTime(temporalTimeZoneLike, optionsParam = undefined) { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); const timeZone = ES.ToTemporalTimeZone(temporalTimeZoneLike); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const disambiguation = ES.ToTemporalDisambiguation(options); const instant = ES.BuiltinTimeZoneGetInstantFor(timeZone, this, disambiguation); return ES.CreateTemporalZonedDateTime(GetSlot(instant, EPOCHNANOSECONDS), timeZone, GetSlot(this, CALENDAR)); @@ -662,8 +662,8 @@ export class PlainDateTime implements Temporal.PlainDateTime { }; } - static from(item, options = undefined) { - options = ES.GetOptionsObject(options); + static from(item, optionsParam = undefined) { + const options = ES.GetOptionsObject(optionsParam); if (ES.IsTemporalDateTime(item)) { ES.ToTemporalOverflow(options); // validate and ignore return ES.CreateTemporalDateTime( @@ -681,9 +681,9 @@ export class PlainDateTime implements Temporal.PlainDateTime { } return ES.ToTemporalDateTime(item, options); } - static compare(one, two) { - one = ES.ToTemporalDateTime(one); - two = ES.ToTemporalDateTime(two); + static compare(oneParam, twoParam) { + const one = ES.ToTemporalDateTime(oneParam); + const two = ES.ToTemporalDateTime(twoParam); for (const slot of [ ISO_YEAR, ISO_MONTH, diff --git a/lib/plainmonthday.ts b/lib/plainmonthday.ts index 30db84ad..bfa77ad6 100644 --- a/lib/plainmonthday.ts +++ b/lib/plainmonthday.ts @@ -7,11 +7,11 @@ import { Temporal } from '..'; const ObjectCreate = Object.create; export class PlainMonthDay implements Temporal.PlainMonthDay { - constructor(isoMonth, isoDay, calendar = ES.GetISO8601Calendar(), referenceISOYear = 1972) { - isoMonth = ES.ToIntegerThrowOnInfinity(isoMonth); - isoDay = ES.ToIntegerThrowOnInfinity(isoDay); - calendar = ES.ToTemporalCalendar(calendar); - referenceISOYear = ES.ToIntegerThrowOnInfinity(referenceISOYear); + constructor(isoMonthParam, isoDayParam, calendarParam = ES.GetISO8601Calendar(), referenceISOYearParam = 1972) { + const isoMonth = ES.ToIntegerThrowOnInfinity(isoMonthParam); + const isoDay = ES.ToIntegerThrowOnInfinity(isoDayParam); + const calendar = ES.ToTemporalCalendar(calendarParam); + const referenceISOYear = ES.ToIntegerThrowOnInfinity(referenceISOYearParam); // Note: if the arguments are not passed, // ToIntegerThrowOnInfinity(undefined) will have returned 0, which will @@ -37,7 +37,7 @@ export class PlainMonthDay implements Temporal.PlainMonthDay { return GetSlot(this, CALENDAR); } - with(temporalMonthDayLike, options = undefined) { + with(temporalMonthDayLike, optionsParam = undefined) { if (!ES.IsTemporalMonthDay(this)) throw new TypeError('invalid receiver'); if (!ES.IsObject(temporalMonthDayLike)) { throw new TypeError('invalid argument'); @@ -62,12 +62,12 @@ export class PlainMonthDay implements Temporal.PlainMonthDay { fields = ES.CalendarMergeFields(calendar, fields, props); fields = ES.ToTemporalMonthDayFields(fields, fieldNames); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); return ES.MonthDayFromFields(calendar, fields, options); } - equals(other) { + equals(otherParam) { if (!ES.IsTemporalMonthDay(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalMonthDay(other); + const other = ES.ToTemporalMonthDay(otherParam); for (const slot of [ISO_MONTH, ISO_DAY, ISO_YEAR]) { const val1 = GetSlot(this, slot); const val2 = GetSlot(other, slot); @@ -75,9 +75,9 @@ export class PlainMonthDay implements Temporal.PlainMonthDay { } return ES.CalendarEquals(GetSlot(this, CALENDAR), GetSlot(other, CALENDAR)); } - toString(options = undefined) { + toString(optionsParam = undefined) { if (!ES.IsTemporalMonthDay(this)) throw new TypeError('invalid receiver'); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const showCalendar = ES.ToShowCalendarOption(options); return ES.TemporalMonthDayToString(this, showCalendar); } @@ -131,8 +131,8 @@ export class PlainMonthDay implements Temporal.PlainMonthDay { isoYear: GetSlot(this, ISO_YEAR) }; } - static from(item, options = undefined) { - options = ES.GetOptionsObject(options); + static from(item, optionsParam = undefined) { + const options = ES.GetOptionsObject(optionsParam); if (ES.IsTemporalMonthDay(item)) { ES.ToTemporalOverflow(options); // validate and ignore return ES.CreateTemporalMonthDay( diff --git a/lib/plaintime.ts b/lib/plaintime.ts index 678d4ebf..53c757c7 100644 --- a/lib/plaintime.ts +++ b/lib/plaintime.ts @@ -65,13 +65,20 @@ function TemporalTimeToString(time, precision, options = undefined) { } export class PlainTime implements Temporal.PlainTime { - constructor(isoHour = 0, isoMinute = 0, isoSecond = 0, isoMillisecond = 0, isoMicrosecond = 0, isoNanosecond = 0) { - isoHour = ES.ToIntegerThrowOnInfinity(isoHour); - isoMinute = ES.ToIntegerThrowOnInfinity(isoMinute); - isoSecond = ES.ToIntegerThrowOnInfinity(isoSecond); - isoMillisecond = ES.ToIntegerThrowOnInfinity(isoMillisecond); - isoMicrosecond = ES.ToIntegerThrowOnInfinity(isoMicrosecond); - isoNanosecond = ES.ToIntegerThrowOnInfinity(isoNanosecond); + constructor( + isoHourParam = 0, + isoMinuteParam = 0, + isoSecondParam = 0, + isoMillisecondParam = 0, + isoMicrosecondParam = 0, + isoNanosecondParam = 0 + ) { + const isoHour = ES.ToIntegerThrowOnInfinity(isoHourParam); + const isoMinute = ES.ToIntegerThrowOnInfinity(isoMinuteParam); + const isoSecond = ES.ToIntegerThrowOnInfinity(isoSecondParam); + const isoMillisecond = ES.ToIntegerThrowOnInfinity(isoMillisecondParam); + const isoMicrosecond = ES.ToIntegerThrowOnInfinity(isoMicrosecondParam); + const isoNanosecond = ES.ToIntegerThrowOnInfinity(isoNanosecondParam); ES.RejectTime(isoHour, isoMinute, isoSecond, isoMillisecond, isoMicrosecond, isoNanosecond); CreateSlots(this); @@ -122,7 +129,7 @@ export class PlainTime implements Temporal.PlainTime { return GetSlot(this, ISO_NANOSECOND); } - with(temporalTimeLike, options = undefined) { + with(temporalTimeLike, optionsParam = undefined) { if (!ES.IsTemporalTime(this)) throw new TypeError('invalid receiver'); if (!ES.IsObject(temporalTimeLike)) { throw new TypeError('invalid argument'); @@ -137,7 +144,7 @@ export class PlainTime implements Temporal.PlainTime { throw new TypeError('with() does not support a timeZone property'); } - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const overflow = ES.ToTemporalOverflow(options); const props = ES.ToPartialRecord(temporalTimeLike, [ @@ -234,10 +241,10 @@ export class PlainTime implements Temporal.PlainTime { )); return new PlainTime(hour, minute, second, millisecond, microsecond, nanosecond); } - until(other, options = undefined) { + until(otherParam, optionsParam = undefined) { if (!ES.IsTemporalTime(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalTime(other); - options = ES.GetOptionsObject(options); + const other = ES.ToTemporalTime(otherParam); + const options = ES.GetOptionsObject(optionsParam); const largestUnit = ES.ToLargestTemporalUnit(options, 'auto', DISALLOWED_UNITS, 'hour'); const smallestUnit = ES.ToSmallestTemporalUnit(options, 'nanosecond', DISALLOWED_UNITS); ES.ValidateTemporalUnitRange(largestUnit, smallestUnit); @@ -285,10 +292,10 @@ export class PlainTime implements Temporal.PlainTime { 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.IsTemporalTime(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalTime(other); - options = ES.GetOptionsObject(options); + const other = ES.ToTemporalTime(otherParam); + const options = ES.GetOptionsObject(optionsParam); const largestUnit = ES.ToLargestTemporalUnit(options, 'auto', DISALLOWED_UNITS, 'hour'); const smallestUnit = ES.ToSmallestTemporalUnit(options, 'nanosecond', DISALLOWED_UNITS); ES.ValidateTemporalUnitRange(largestUnit, smallestUnit); @@ -342,10 +349,10 @@ export class PlainTime implements Temporal.PlainTime { const Duration = GetIntrinsic('%Temporal.Duration%'); return new Duration(0, 0, 0, 0, hours, minutes, seconds, milliseconds, microseconds, nanoseconds); } - round(options) { + round(optionsParam) { if (!ES.IsTemporalTime(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'); @@ -371,9 +378,9 @@ export class PlainTime implements Temporal.PlainTime { return new PlainTime(hour, minute, second, millisecond, microsecond, nanosecond); } - equals(other) { + equals(otherParam) { if (!ES.IsTemporalTime(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalTime(other); + const other = ES.ToTemporalTime(otherParam); for (const slot of [ISO_HOUR, ISO_MINUTE, ISO_SECOND, ISO_MILLISECOND, ISO_MICROSECOND, ISO_NANOSECOND]) { const val1 = GetSlot(this, slot); const val2 = GetSlot(other, slot); @@ -382,9 +389,9 @@ export class PlainTime implements Temporal.PlainTime { return true; } - toString(options = undefined) { + toString(optionsParam = undefined) { if (!ES.IsTemporalTime(this)) throw new TypeError('invalid receiver'); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const { precision, unit, increment } = ES.ToSecondsStringPrecision(options); const roundingMode = ES.ToTemporalRoundingMode(options, 'trunc'); return TemporalTimeToString(this, precision, { unit, increment, roundingMode }); @@ -401,10 +408,10 @@ export class PlainTime implements Temporal.PlainTime { throw new TypeError('use compare() or equals() to compare Temporal.PlainTime'); } - toPlainDateTime(temporalDate) { + toPlainDateTime(temporalDateParam) { if (!ES.IsTemporalTime(this)) throw new TypeError('invalid receiver'); - temporalDate = ES.ToTemporalDate(temporalDate); + const temporalDate = ES.ToTemporalDate(temporalDateParam); const year = GetSlot(temporalDate, ISO_YEAR); const month = GetSlot(temporalDate, ISO_MONTH); const day = GetSlot(temporalDate, ISO_DAY); @@ -489,8 +496,8 @@ export class PlainTime implements Temporal.PlainTime { }; } - static from(item, options = undefined) { - options = ES.GetOptionsObject(options); + static from(item, optionsParam = undefined) { + const options = ES.GetOptionsObject(optionsParam); const overflow = ES.ToTemporalOverflow(options); if (ES.IsTemporalTime(item)) { return new PlainTime( @@ -504,9 +511,9 @@ export class PlainTime implements Temporal.PlainTime { } return ES.ToTemporalTime(item, overflow); } - static compare(one, two) { - one = ES.ToTemporalTime(one); - two = ES.ToTemporalTime(two); + static compare(oneParam, twoParam) { + const one = ES.ToTemporalTime(oneParam); + const two = ES.ToTemporalTime(twoParam); for (const slot of [ISO_HOUR, ISO_MINUTE, ISO_SECOND, ISO_MILLISECOND, ISO_MICROSECOND, ISO_NANOSECOND]) { const val1 = GetSlot(one, slot); const val2 = GetSlot(two, slot); diff --git a/lib/plainyearmonth.ts b/lib/plainyearmonth.ts index 5fdc4120..b278c42f 100644 --- a/lib/plainyearmonth.ts +++ b/lib/plainyearmonth.ts @@ -9,11 +9,11 @@ const ObjectCreate = Object.create; const DISALLOWED_UNITS = ['week', 'day', 'hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond']; export class PlainYearMonth implements Temporal.PlainYearMonth { - constructor(isoYear, isoMonth, calendar = ES.GetISO8601Calendar(), referenceISODay = 1) { - isoYear = ES.ToIntegerThrowOnInfinity(isoYear); - isoMonth = ES.ToIntegerThrowOnInfinity(isoMonth); - calendar = ES.ToTemporalCalendar(calendar); - referenceISODay = ES.ToIntegerThrowOnInfinity(referenceISODay); + constructor(isoYearParam, isoMonthParam, calendarParam = ES.GetISO8601Calendar(), referenceISODayParam = 1) { + const isoYear = ES.ToIntegerThrowOnInfinity(isoYearParam); + const isoMonth = ES.ToIntegerThrowOnInfinity(isoMonthParam); + const calendar = ES.ToTemporalCalendar(calendarParam); + const referenceISODay = ES.ToIntegerThrowOnInfinity(referenceISODayParam); // Note: if the arguments are not passed, // ToIntegerThrowOnInfinity(undefined) will have returned 0, which will @@ -65,7 +65,7 @@ export class PlainYearMonth implements Temporal.PlainYearMonth { if (!ES.IsTemporalYearMonth(this)) throw new TypeError('invalid receiver'); return ES.CalendarInLeapYear(GetSlot(this, CALENDAR), this); } - with(temporalYearMonthLike, options = undefined) { + with(temporalYearMonthLike, optionsParam = undefined) { if (!ES.IsTemporalYearMonth(this)) throw new TypeError('invalid receiver'); if (!ES.IsObject(temporalYearMonthLike)) { throw new TypeError('invalid argument'); @@ -90,17 +90,17 @@ export class PlainYearMonth implements Temporal.PlainYearMonth { fields = ES.CalendarMergeFields(calendar, fields, props); fields = ES.ToTemporalYearMonthFields(fields, fieldNames); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); return ES.YearMonthFromFields(calendar, fields, options); } - add(temporalDurationLike, options = undefined) { + add(temporalDurationLike, optionsParam = undefined) { if (!ES.IsTemporalYearMonth(this)) throw new TypeError('invalid receiver'); const duration = ES.ToLimitedTemporalDuration(temporalDurationLike); let { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = duration; ({ days } = ES.BalanceDuration(days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds, 'day')); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const calendar = GetSlot(this, CALENDAR); const fieldNames = ES.CalendarFields(calendar, ['monthCode', 'year']); @@ -114,7 +114,7 @@ export class PlainYearMonth implements Temporal.PlainYearMonth { return ES.YearMonthFromFields(calendar, addedDateFields, optionsCopy); } - subtract(temporalDurationLike, options = undefined) { + subtract(temporalDurationLike, optionsParam = undefined) { if (!ES.IsTemporalYearMonth(this)) throw new TypeError('invalid receiver'); let duration = ES.ToLimitedTemporalDuration(temporalDurationLike); duration = { @@ -132,7 +132,7 @@ export class PlainYearMonth implements Temporal.PlainYearMonth { let { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = duration; ({ days } = ES.BalanceDuration(days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds, 'day')); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const calendar = GetSlot(this, CALENDAR); const fieldNames = ES.CalendarFields(calendar, ['monthCode', 'year']); @@ -146,9 +146,9 @@ export class PlainYearMonth implements Temporal.PlainYearMonth { return ES.YearMonthFromFields(calendar, addedDateFields, optionsCopy); } - until(other, options = undefined) { + until(otherParam, optionsParam = undefined) { if (!ES.IsTemporalYearMonth(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalYearMonth(other); + const other = ES.ToTemporalYearMonth(otherParam); const calendar = GetSlot(this, CALENDAR); const otherCalendar = GetSlot(other, CALENDAR); const calendarID = ES.ToString(calendar); @@ -158,7 +158,7 @@ export class PlainYearMonth implements Temporal.PlainYearMonth { `cannot compute difference between months of ${calendarID} and ${otherCalendarID} calendars` ); } - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const smallestUnit = ES.ToSmallestTemporalUnit(options, 'month', DISALLOWED_UNITS); const largestUnit = ES.ToLargestTemporalUnit(options, 'auto', DISALLOWED_UNITS, 'year'); ES.ValidateTemporalUnitRange(largestUnit, smallestUnit); @@ -208,9 +208,9 @@ export class PlainYearMonth implements Temporal.PlainYearMonth { const Duration = GetIntrinsic('%Temporal.Duration%'); return new Duration(years, months, 0, 0, 0, 0, 0, 0, 0, 0); } - since(other, options = undefined) { + since(otherParam, optionsParam = undefined) { if (!ES.IsTemporalYearMonth(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalYearMonth(other); + const other = ES.ToTemporalYearMonth(otherParam); const calendar = GetSlot(this, CALENDAR); const otherCalendar = GetSlot(other, CALENDAR); const calendarID = ES.ToString(calendar); @@ -220,7 +220,7 @@ export class PlainYearMonth implements Temporal.PlainYearMonth { `cannot compute difference between months of ${calendarID} and ${otherCalendarID} calendars` ); } - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const smallestUnit = ES.ToSmallestTemporalUnit(options, 'month', DISALLOWED_UNITS); const largestUnit = ES.ToLargestTemporalUnit(options, 'auto', DISALLOWED_UNITS, 'year'); ES.ValidateTemporalUnitRange(largestUnit, smallestUnit); @@ -270,9 +270,9 @@ export class PlainYearMonth implements Temporal.PlainYearMonth { return new Duration(-years, -months, 0, 0, 0, 0, 0, 0, 0, 0); } - equals(other) { + equals(otherParam) { if (!ES.IsTemporalYearMonth(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalYearMonth(other); + const other = ES.ToTemporalYearMonth(otherParam); for (const slot of [ISO_YEAR, ISO_MONTH, ISO_DAY]) { const val1 = GetSlot(this, slot); const val2 = GetSlot(other, slot); @@ -280,9 +280,9 @@ export class PlainYearMonth implements Temporal.PlainYearMonth { } return ES.CalendarEquals(GetSlot(this, CALENDAR), GetSlot(other, CALENDAR)); } - toString(options = undefined) { + toString(optionsParam = undefined) { if (!ES.IsTemporalYearMonth(this)) throw new TypeError('invalid receiver'); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const showCalendar = ES.ToShowCalendarOption(options); return ES.TemporalYearMonthToString(this, showCalendar); } @@ -337,8 +337,8 @@ export class PlainYearMonth implements Temporal.PlainYearMonth { isoYear: GetSlot(this, ISO_YEAR) }; } - static from(item, options = undefined) { - options = ES.GetOptionsObject(options); + static from(item, optionsParam = undefined) { + const options = ES.GetOptionsObject(optionsParam); if (ES.IsTemporalYearMonth(item)) { ES.ToTemporalOverflow(options); // validate and ignore return ES.CreateTemporalYearMonth( @@ -350,9 +350,9 @@ export class PlainYearMonth implements Temporal.PlainYearMonth { } return ES.ToTemporalYearMonth(item, options); } - static compare(one, two) { - one = ES.ToTemporalYearMonth(one); - two = ES.ToTemporalYearMonth(two); + static compare(oneParam, twoParam) { + const one = ES.ToTemporalYearMonth(oneParam); + const two = ES.ToTemporalYearMonth(twoParam); return ES.CompareISODate( GetSlot(one, ISO_YEAR), GetSlot(one, ISO_MONTH), diff --git a/lib/timezone.ts b/lib/timezone.ts index 6ebf55b8..a59d9abe 100644 --- a/lib/timezone.ts +++ b/lib/timezone.ts @@ -20,14 +20,14 @@ import { import { Temporal } from '..'; export class TimeZone implements Temporal.TimeZone { - constructor(timeZoneIdentifier) { + constructor(timeZoneIdentifierParam) { // Note: if the argument is not passed, GetCanonicalTimeZoneIdentifier(undefined) will throw. // This check exists only to improve the error message. if (arguments.length < 1) { throw new RangeError('missing argument: identifier is required'); } - timeZoneIdentifier = ES.GetCanonicalTimeZoneIdentifier(timeZoneIdentifier); + const timeZoneIdentifier = ES.GetCanonicalTimeZoneIdentifier(timeZoneIdentifierParam); CreateSlots(this); SetSlot(this, TIMEZONE_ID, timeZoneIdentifier); @@ -43,9 +43,9 @@ export class TimeZone implements Temporal.TimeZone { get id() { return ES.ToString(this); } - getOffsetNanosecondsFor(instant) { + getOffsetNanosecondsFor(instantParam) { if (!ES.IsTemporalTimeZone(this)) throw new TypeError('invalid receiver'); - instant = ES.ToTemporalInstant(instant); + const instant = ES.ToTemporalInstant(instantParam); const id = GetSlot(this, TIMEZONE_ID); const offsetNs = ES.ParseOffsetString(id); @@ -53,26 +53,26 @@ export class TimeZone implements Temporal.TimeZone { return ES.GetIANATimeZoneOffsetNanoseconds(GetSlot(instant, EPOCHNANOSECONDS), id); } - getOffsetStringFor(instant) { + getOffsetStringFor(instantParam) { if (!ES.IsTemporalTimeZone(this)) throw new TypeError('invalid receiver'); - instant = ES.ToTemporalInstant(instant); + const instant = ES.ToTemporalInstant(instantParam); return ES.BuiltinTimeZoneGetOffsetStringFor(this, instant); } - getPlainDateTimeFor(instant, calendar = ES.GetISO8601Calendar()) { - instant = ES.ToTemporalInstant(instant); - calendar = ES.ToTemporalCalendar(calendar); + getPlainDateTimeFor(instantParam, calendarParam = ES.GetISO8601Calendar()) { + const instant = ES.ToTemporalInstant(instantParam); + const calendar = ES.ToTemporalCalendar(calendarParam); return ES.BuiltinTimeZoneGetPlainDateTimeFor(this, instant, calendar); } - getInstantFor(dateTime, options = undefined) { + getInstantFor(dateTimeParam, optionsParam = undefined) { if (!ES.IsTemporalTimeZone(this)) throw new TypeError('invalid receiver'); - dateTime = ES.ToTemporalDateTime(dateTime); - options = ES.GetOptionsObject(options); + const dateTime = ES.ToTemporalDateTime(dateTimeParam); + const options = ES.GetOptionsObject(optionsParam); const disambiguation = ES.ToTemporalDisambiguation(options); return ES.BuiltinTimeZoneGetInstantFor(this, dateTime, disambiguation); } - getPossibleInstantsFor(dateTime) { + getPossibleInstantsFor(dateTimeParam) { if (!ES.IsTemporalTimeZone(this)) throw new TypeError('invalid receiver'); - dateTime = ES.ToTemporalDateTime(dateTime); + const dateTime = ES.ToTemporalDateTime(dateTimeParam); const Instant = GetIntrinsic('%Temporal.Instant%'); const id = GetSlot(this, TIMEZONE_ID); @@ -107,9 +107,9 @@ export class TimeZone implements Temporal.TimeZone { ); return possibleEpochNs.map((ns) => new Instant(ns)); } - getNextTransition(startingPoint) { + getNextTransition(startingPointParam) { if (!ES.IsTemporalTimeZone(this)) throw new TypeError('invalid receiver'); - startingPoint = ES.ToTemporalInstant(startingPoint); + const startingPoint = ES.ToTemporalInstant(startingPointParam); const id = GetSlot(this, TIMEZONE_ID); // Offset time zones or UTC have no transitions @@ -122,9 +122,9 @@ export class TimeZone implements Temporal.TimeZone { epochNanoseconds = ES.GetIANATimeZoneNextTransition(epochNanoseconds, id); return epochNanoseconds === null ? null : new Instant(epochNanoseconds); } - getPreviousTransition(startingPoint) { + getPreviousTransition(startingPointParam) { if (!ES.IsTemporalTimeZone(this)) throw new TypeError('invalid receiver'); - startingPoint = ES.ToTemporalInstant(startingPoint); + const startingPoint = ES.ToTemporalInstant(startingPointParam); const id = GetSlot(this, TIMEZONE_ID); // Offset time zones or UTC have no transitions diff --git a/lib/zoneddatetime.ts b/lib/zoneddatetime.ts index 4e5a5305..18963bb0 100644 --- a/lib/zoneddatetime.ts +++ b/lib/zoneddatetime.ts @@ -25,7 +25,7 @@ import bigInt from 'big-integer'; const ArrayPrototypePush = Array.prototype.push; export class ZonedDateTime implements Temporal.ZonedDateTime { - constructor(epochNanoseconds, timeZone, calendar = ES.GetISO8601Calendar()) { + constructor(epochNanosecondsParam, timeZoneParam, calendarParam = ES.GetISO8601Calendar()) { // Note: if the argument is not passed, ToBigInt(undefined) will throw. This check exists only // to improve the error message. // ToTemporalTimeZone(undefined) will end up calling TimeZone.from("undefined"), which @@ -33,9 +33,9 @@ export class ZonedDateTime implements Temporal.ZonedDateTime { if (arguments.length < 1) { throw new TypeError('missing argument: epochNanoseconds is required'); } - epochNanoseconds = ES.ToBigInt(epochNanoseconds); - timeZone = ES.ToTemporalTimeZone(timeZone); - calendar = ES.ToTemporalCalendar(calendar); + const epochNanoseconds = ES.ToBigInt(epochNanosecondsParam); + const timeZone = ES.ToTemporalTimeZone(timeZoneParam); + const calendar = ES.ToTemporalCalendar(calendarParam); ES.CreateTemporalZonedDateTimeSlots(this, epochNanoseconds, timeZone, calendar); } @@ -169,7 +169,7 @@ export class ZonedDateTime implements Temporal.ZonedDateTime { if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver'); return ES.GetOffsetNanosecondsFor(GetSlot(this, TIME_ZONE), GetSlot(this, INSTANT)); } - with(temporalZonedDateTimeLike, options = undefined) { + with(temporalZonedDateTimeLike, optionsParam = undefined) { if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver'); if (!ES.IsObject(temporalZonedDateTimeLike)) { throw new TypeError('invalid zoned-date-time-like'); @@ -184,7 +184,7 @@ export class ZonedDateTime implements Temporal.ZonedDateTime { throw new TypeError('timeZone invalid for with(). use withTimeZone()'); } - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const disambiguation = ES.ToTemporalDisambiguation(options); const offset = ES.ToTemporalOffset(options, 'prefer'); @@ -232,10 +232,10 @@ export class ZonedDateTime implements Temporal.ZonedDateTime { return ES.CreateTemporalZonedDateTime(epochNanoseconds, GetSlot(this, TIME_ZONE), calendar); } - withPlainDate(temporalDate) { + withPlainDate(temporalDateParam) { if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver'); - temporalDate = ES.ToTemporalDate(temporalDate); + const temporalDate = ES.ToTemporalDate(temporalDateParam); const year = GetSlot(temporalDate, ISO_YEAR); const month = GetSlot(temporalDate, ISO_MONTH); @@ -267,11 +267,11 @@ export class ZonedDateTime implements Temporal.ZonedDateTime { const instant = ES.BuiltinTimeZoneGetInstantFor(timeZone, dt, 'compatible'); return ES.CreateTemporalZonedDateTime(GetSlot(instant, EPOCHNANOSECONDS), timeZone, calendar); } - withPlainTime(temporalTime = undefined) { + withPlainTime(temporalTimeParam = undefined) { if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver'); const PlainTime = GetIntrinsic('%Temporal.PlainTime%'); - temporalTime = temporalTime == undefined ? new PlainTime() : ES.ToTemporalTime(temporalTime); + const temporalTime = temporalTimeParam == undefined ? new PlainTime() : ES.ToTemporalTime(temporalTimeParam); const thisDt = dateTime(this); const year = GetSlot(thisDt, ISO_YEAR); @@ -302,21 +302,21 @@ export class ZonedDateTime implements Temporal.ZonedDateTime { const instant = ES.BuiltinTimeZoneGetInstantFor(timeZone, dt, 'compatible'); return ES.CreateTemporalZonedDateTime(GetSlot(instant, EPOCHNANOSECONDS), timeZone, calendar); } - withTimeZone(timeZone) { + withTimeZone(timeZoneParam) { if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver'); - timeZone = ES.ToTemporalTimeZone(timeZone); + const timeZone = ES.ToTemporalTimeZone(timeZoneParam); return ES.CreateTemporalZonedDateTime(GetSlot(this, EPOCHNANOSECONDS), timeZone, GetSlot(this, CALENDAR)); } - withCalendar(calendar) { + withCalendar(calendarParam) { if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver'); - calendar = ES.ToTemporalCalendar(calendar); + const calendar = ES.ToTemporalCalendar(calendarParam); return ES.CreateTemporalZonedDateTime(GetSlot(this, EPOCHNANOSECONDS), GetSlot(this, TIME_ZONE), calendar); } - add(temporalDurationLike, options = undefined) { + add(temporalDurationLike, optionsParam = undefined) { if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver'); const duration = ES.ToLimitedTemporalDuration(temporalDurationLike); const { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = duration; - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const timeZone = GetSlot(this, TIME_ZONE); const calendar = GetSlot(this, CALENDAR); const epochNanoseconds = ES.AddZonedDateTime( @@ -337,11 +337,11 @@ export class ZonedDateTime implements Temporal.ZonedDateTime { ); return ES.CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar); } - subtract(temporalDurationLike, options = undefined) { + subtract(temporalDurationLike, optionsParam = undefined) { if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver'); const duration = ES.ToLimitedTemporalDuration(temporalDurationLike); const { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = duration; - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const timeZone = GetSlot(this, TIME_ZONE); const calendar = GetSlot(this, CALENDAR); const epochNanoseconds = ES.AddZonedDateTime( @@ -362,9 +362,9 @@ export class ZonedDateTime implements Temporal.ZonedDateTime { ); return ES.CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar); } - until(other, options = undefined) { + until(otherParam, optionsParam = undefined) { if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalZonedDateTime(other); + const other = ES.ToTemporalZonedDateTime(otherParam); const calendar = GetSlot(this, CALENDAR); const otherCalendar = GetSlot(other, CALENDAR); const calendarId = ES.ToString(calendar); @@ -372,7 +372,7 @@ export class ZonedDateTime implements Temporal.ZonedDateTime { if (calendarId !== otherCalendarId) { throw new RangeError(`cannot compute difference between dates of ${calendarId} and ${otherCalendarId} calendars`); } - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const smallestUnit = ES.ToSmallestTemporalUnit(options, 'nanosecond'); const defaultLargestUnit = ES.LargerOfTwoTemporalUnits('hour', smallestUnit); const largestUnit = ES.ToLargestTemporalUnit(options, 'auto', [], defaultLargestUnit); @@ -456,9 +456,9 @@ export class ZonedDateTime implements Temporal.ZonedDateTime { const Duration = GetIntrinsic('%Temporal.Duration%'); return new Duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds); } - since(other, options = undefined) { + since(otherParam, optionsParam = undefined) { if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalZonedDateTime(other); + const other = ES.ToTemporalZonedDateTime(otherParam); const calendar = GetSlot(this, CALENDAR); const otherCalendar = GetSlot(other, CALENDAR); const calendarId = ES.ToString(calendar); @@ -466,7 +466,7 @@ export class ZonedDateTime implements Temporal.ZonedDateTime { if (calendarId !== otherCalendarId) { throw new RangeError(`cannot compute difference between dates of ${calendarId} and ${otherCalendarId} calendars`); } - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const smallestUnit = ES.ToSmallestTemporalUnit(options, 'nanosecond'); const defaultLargestUnit = ES.LargerOfTwoTemporalUnits('hour', smallestUnit); const largestUnit = ES.ToLargestTemporalUnit(options, 'auto', [], defaultLargestUnit); @@ -562,10 +562,10 @@ export class ZonedDateTime implements Temporal.ZonedDateTime { -nanoseconds ); } - round(options) { + round(optionsParam) { if (!ES.IsTemporalZonedDateTime(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, ['year', 'month', 'week']); if (smallestUnit === undefined) throw new RangeError('smallestUnit is required'); const roundingMode = ES.ToTemporalRoundingMode(options, 'halfExpand'); @@ -645,18 +645,18 @@ export class ZonedDateTime implements Temporal.ZonedDateTime { return ES.CreateTemporalZonedDateTime(epochNanoseconds, timeZone, GetSlot(this, CALENDAR)); } - equals(other) { + equals(otherParam) { if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver'); - other = ES.ToTemporalZonedDateTime(other); + const other = ES.ToTemporalZonedDateTime(otherParam); const one = GetSlot(this, EPOCHNANOSECONDS); const two = GetSlot(other, EPOCHNANOSECONDS); if (!bigInt(one).equals(two)) return false; if (!ES.TimeZoneEquals(GetSlot(this, TIME_ZONE), GetSlot(other, TIME_ZONE))) return false; return ES.CalendarEquals(GetSlot(this, CALENDAR), GetSlot(other, CALENDAR)); } - toString(options = undefined) { + toString(optionsParam = undefined) { if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver'); - options = ES.GetOptionsObject(options); + const options = ES.GetOptionsObject(optionsParam); const { precision, unit, increment } = ES.ToSecondsStringPrecision(options); const roundingMode = ES.ToTemporalRoundingMode(options, 'trunc'); const showCalendar = ES.ToShowCalendarOption(options); @@ -750,8 +750,8 @@ export class ZonedDateTime implements Temporal.ZonedDateTime { timeZone: tz }; } - static from(item, options = undefined) { - options = ES.GetOptionsObject(options); + static from(item, optionsParam = undefined) { + const options = ES.GetOptionsObject(optionsParam); if (ES.IsTemporalZonedDateTime(item)) { ES.ToTemporalOverflow(options); // validate and ignore ES.ToTemporalDisambiguation(options); @@ -764,9 +764,9 @@ export class ZonedDateTime implements Temporal.ZonedDateTime { } return ES.ToTemporalZonedDateTime(item, options); } - static compare(one, two) { - one = ES.ToTemporalZonedDateTime(one); - two = ES.ToTemporalZonedDateTime(two); + static compare(oneParam, twoParam) { + const one = ES.ToTemporalZonedDateTime(oneParam); + const two = ES.ToTemporalZonedDateTime(twoParam); const ns1 = GetSlot(one, EPOCHNANOSECONDS); const ns2 = GetSlot(two, EPOCHNANOSECONDS); if (bigInt(ns1).lesser(ns2)) return -1;