diff --git a/harness/temporalHelpers.js b/harness/temporalHelpers.js index 1c3b7227b0..39017c84f8 100644 --- a/harness/temporalHelpers.js +++ b/harness/temporalHelpers.js @@ -282,48 +282,6 @@ var TemporalHelpers = { throw new Test262Error(message); }, - /* - * checkCalendarDateUntilLargestUnitSingular(func, expectedLargestUnitCalls): - * - * When an options object with a largestUnit property is synthesized inside - * Temporal and passed to user code such as calendar.dateUntil(), the value of - * the largestUnit property should be in the singular form, even if the input - * was given in the plural form. - * (This doesn't apply when the options object is passed through verbatim.) - * - * func(calendar, largestUnit, index) is the operation under test. It's called - * with an instance of a calendar that keeps track of which largestUnit is - * passed to dateUntil(), each key of expectedLargestUnitCalls in turn, and - * the key's numerical index in case the function needs to generate test data - * based on the index. At the end, the actual values passed to dateUntil() are - * compared with the array values of expectedLargestUnitCalls. - */ - checkCalendarDateUntilLargestUnitSingular(func, expectedLargestUnitCalls) { - const actual = []; - - class DateUntilOptionsCalendar extends Temporal.Calendar { - constructor() { - super("iso8601"); - } - - dateUntil(earlier, later, options) { - actual.push(options.largestUnit); - return super.dateUntil(earlier, later, options); - } - - toString() { - return "date-until-options"; - } - } - - const calendar = new DateUntilOptionsCalendar(); - Object.entries(expectedLargestUnitCalls).forEach(([largestUnit, expected], index) => { - func(calendar, largestUnit, index); - assert.compareArray(actual, expected, `largestUnit passed to calendar.dateUntil() for largestUnit ${largestUnit}`); - actual.splice(0); // empty it for the next check - }); - }, - /* * checkPlainDateTimeConversionFastPath(func): * @@ -808,79 +766,6 @@ var TemporalHelpers = { resultAssertions(result); }, - /* - * Check that any iterable returned from a custom time zone's - * getPossibleInstantsFor() method is exhausted. - * The custom time zone object is passed in to func(). - * expected is an array of strings representing the expected calls to the - * getPossibleInstantsFor() method. The PlainDateTimes that it is called with, - * are compared (using their toString() results) with the array. - */ - checkTimeZonePossibleInstantsIterable(func, expected) { - // A custom time zone that returns an iterable instead of an array from its - // getPossibleInstantsFor() method, and for testing purposes skips - // 00:00-01:00 UTC on January 1, 2030, and repeats 00:00-01:00 UTC+1 on - // January 3, 2030. Otherwise identical to the UTC time zone. - class TimeZonePossibleInstantsIterable extends Temporal.TimeZone { - constructor() { - super("UTC"); - this.getPossibleInstantsForCallCount = 0; - this.getPossibleInstantsForCalledWith = []; - this.getPossibleInstantsForReturns = []; - this.iteratorExhausted = []; - } - - toString() { - return "Custom/Iterable"; - } - - getOffsetNanosecondsFor(instant) { - if (Temporal.Instant.compare(instant, "2030-01-01T00:00Z") >= 0 && - Temporal.Instant.compare(instant, "2030-01-03T01:00Z") < 0) { - return 3600_000_000_000; - } else { - return 0; - } - } - - getPossibleInstantsFor(dateTime) { - this.getPossibleInstantsForCallCount++; - this.getPossibleInstantsForCalledWith.push(dateTime); - - // Fake DST transition - let retval = super.getPossibleInstantsFor(dateTime); - if (dateTime.toPlainDate().equals("2030-01-01") && dateTime.hour === 0) { - retval = []; - } else if (dateTime.toPlainDate().equals("2030-01-03") && dateTime.hour === 0) { - retval.push(retval[0].subtract({ hours: 1 })); - } else if (dateTime.year === 2030 && dateTime.month === 1 && dateTime.day >= 1 && dateTime.day <= 2) { - retval[0] = retval[0].subtract({ hours: 1 }); - } - - this.getPossibleInstantsForReturns.push(retval); - this.iteratorExhausted.push(false); - return { - callIndex: this.getPossibleInstantsForCallCount - 1, - timeZone: this, - *[Symbol.iterator]() { - yield* this.timeZone.getPossibleInstantsForReturns[this.callIndex]; - this.timeZone.iteratorExhausted[this.callIndex] = true; - }, - }; - } - } - - const timeZone = new TimeZonePossibleInstantsIterable(); - func(timeZone); - - assert.sameValue(timeZone.getPossibleInstantsForCallCount, expected.length, "getPossibleInstantsFor() method called correct number of times"); - - for (let index = 0; index < expected.length; index++) { - assert.sameValue(timeZone.getPossibleInstantsForCalledWith[index].toString(), expected[index], "getPossibleInstantsFor() called with expected PlainDateTime"); - assert(timeZone.iteratorExhausted[index], "iterated through the whole iterable"); - } - }, - /* * Check that any calendar-carrying Temporal object has its [[Calendar]] * internal slot read by ToTemporalCalendar, and does not fetch the calendar @@ -962,401 +847,6 @@ var TemporalHelpers = { assert.compareArray(actual, expected, "property getters not called"); }, - /* - * A custom calendar used in prototype pollution checks. Verifies that the - * fromFields methods are always called with a null-prototype fields object. - */ - calendarCheckFieldsPrototypePollution() { - class CalendarCheckFieldsPrototypePollution extends Temporal.Calendar { - constructor() { - super("iso8601"); - this.dateFromFieldsCallCount = 0; - this.yearMonthFromFieldsCallCount = 0; - this.monthDayFromFieldsCallCount = 0; - } - - // toString must remain "iso8601", so that some methods don't throw due to - // incompatible calendars - - dateFromFields(fields, options = {}) { - this.dateFromFieldsCallCount++; - assert.sameValue(Object.getPrototypeOf(fields), null, "dateFromFields should be called with null-prototype fields object"); - return super.dateFromFields(fields, options); - } - - yearMonthFromFields(fields, options = {}) { - this.yearMonthFromFieldsCallCount++; - assert.sameValue(Object.getPrototypeOf(fields), null, "yearMonthFromFields should be called with null-prototype fields object"); - return super.yearMonthFromFields(fields, options); - } - - monthDayFromFields(fields, options = {}) { - this.monthDayFromFieldsCallCount++; - assert.sameValue(Object.getPrototypeOf(fields), null, "monthDayFromFields should be called with null-prototype fields object"); - return super.monthDayFromFields(fields, options); - } - } - - return new CalendarCheckFieldsPrototypePollution(); - }, - - /* - * A custom calendar used in prototype pollution checks. Verifies that the - * mergeFields() method is always called with null-prototype fields objects. - */ - calendarCheckMergeFieldsPrototypePollution() { - class CalendarCheckMergeFieldsPrototypePollution extends Temporal.Calendar { - constructor() { - super("iso8601"); - this.mergeFieldsCallCount = 0; - } - - toString() { - return "merge-fields-null-proto"; - } - - mergeFields(fields, additionalFields) { - this.mergeFieldsCallCount++; - assert.sameValue(Object.getPrototypeOf(fields), null, "mergeFields should be called with null-prototype fields object (first argument)"); - assert.sameValue(Object.getPrototypeOf(additionalFields), null, "mergeFields should be called with null-prototype fields object (second argument)"); - return super.mergeFields(fields, additionalFields); - } - } - - return new CalendarCheckMergeFieldsPrototypePollution(); - }, - - /* - * A custom calendar used in prototype pollution checks. Verifies that methods - * are always called with a null-prototype options object. - */ - calendarCheckOptionsPrototypePollution() { - class CalendarCheckOptionsPrototypePollution extends Temporal.Calendar { - constructor() { - super("iso8601"); - this.yearMonthFromFieldsCallCount = 0; - this.dateUntilCallCount = 0; - } - - toString() { - return "options-null-proto"; - } - - yearMonthFromFields(fields, options) { - this.yearMonthFromFieldsCallCount++; - assert.sameValue(Object.getPrototypeOf(options), null, "yearMonthFromFields should be called with null-prototype options"); - return super.yearMonthFromFields(fields, options); - } - - dateUntil(one, two, options) { - this.dateUntilCallCount++; - assert.sameValue(Object.getPrototypeOf(options), null, "dateUntil should be called with null-prototype options"); - return super.dateUntil(one, two, options); - } - } - - return new CalendarCheckOptionsPrototypePollution(); - }, - - /* - * A custom calendar that asserts its dateAdd() method is called with the - * options parameter having the value undefined. - */ - calendarDateAddUndefinedOptions() { - class CalendarDateAddUndefinedOptions extends Temporal.Calendar { - constructor() { - super("iso8601"); - this.dateAddCallCount = 0; - } - - toString() { - return "dateadd-undef-options"; - } - - dateAdd(date, duration, options) { - this.dateAddCallCount++; - assert.sameValue(options, undefined, "dateAdd shouldn't be called with options"); - return super.dateAdd(date, duration, options); - } - } - return new CalendarDateAddUndefinedOptions(); - }, - - /* - * A custom calendar that asserts its dateAdd() method is called with a - * PlainDate instance. Optionally, it also asserts that the PlainDate instance - * is the specific object `this.specificPlainDate`, if it is set by the - * calling code. - */ - calendarDateAddPlainDateInstance() { - class CalendarDateAddPlainDateInstance extends Temporal.Calendar { - constructor() { - super("iso8601"); - this.dateAddCallCount = 0; - this.specificPlainDate = undefined; - } - - toString() { - return "dateadd-plain-date-instance"; - } - - dateFromFields(...args) { - return super.dateFromFields(...args).withCalendar(this); - } - - dateAdd(date, duration, options) { - this.dateAddCallCount++; - assert(date instanceof Temporal.PlainDate, "dateAdd() should be called with a PlainDate instance"); - if (this.dateAddCallCount === 1 && this.specificPlainDate) { - assert.sameValue(date, this.specificPlainDate, `dateAdd() should be called first with the specific PlainDate instance ${this.specificPlainDate}`); - } - return super.dateAdd(date, duration, options).withCalendar(this); - } - } - return new CalendarDateAddPlainDateInstance(); - }, - - /* - * A custom calendar that returns an iterable instead of an array from its - * fields() method, otherwise identical to the ISO calendar. - */ - calendarFieldsIterable() { - class CalendarFieldsIterable extends Temporal.Calendar { - constructor() { - super("iso8601"); - this.fieldsCallCount = 0; - this.fieldsCalledWith = []; - this.iteratorExhausted = []; - } - - toString() { - return "fields-iterable"; - } - - fields(fieldNames) { - this.fieldsCallCount++; - this.fieldsCalledWith.push(fieldNames.slice()); - this.iteratorExhausted.push(false); - return { - callIndex: this.fieldsCallCount - 1, - calendar: this, - *[Symbol.iterator]() { - yield* this.calendar.fieldsCalledWith[this.callIndex]; - this.calendar.iteratorExhausted[this.callIndex] = true; - }, - }; - } - } - return new CalendarFieldsIterable(); - }, - - /* - * A custom calendar that asserts its ...FromFields() methods are called with - * the options parameter having the value undefined. - */ - calendarFromFieldsUndefinedOptions() { - class CalendarFromFieldsUndefinedOptions extends Temporal.Calendar { - constructor() { - super("iso8601"); - this.dateFromFieldsCallCount = 0; - this.monthDayFromFieldsCallCount = 0; - this.yearMonthFromFieldsCallCount = 0; - } - - toString() { - return "from-fields-undef-options"; - } - - dateFromFields(fields, options) { - this.dateFromFieldsCallCount++; - assert.sameValue(options, undefined, "dateFromFields shouldn't be called with options"); - return super.dateFromFields(fields, options); - } - - yearMonthFromFields(fields, options) { - this.yearMonthFromFieldsCallCount++; - assert.sameValue(options, undefined, "yearMonthFromFields shouldn't be called with options"); - return super.yearMonthFromFields(fields, options); - } - - monthDayFromFields(fields, options) { - this.monthDayFromFieldsCallCount++; - assert.sameValue(options, undefined, "monthDayFromFields shouldn't be called with options"); - return super.monthDayFromFields(fields, options); - } - } - return new CalendarFromFieldsUndefinedOptions(); - }, - - /* - * A custom calendar that modifies the fields object passed in to - * dateFromFields, sabotaging its time properties. - */ - calendarMakeInfinityTime() { - class CalendarMakeInfinityTime extends Temporal.Calendar { - constructor() { - super("iso8601"); - } - - dateFromFields(fields, options) { - const retval = super.dateFromFields(fields, options); - fields.hour = Infinity; - fields.minute = Infinity; - fields.second = Infinity; - fields.millisecond = Infinity; - fields.microsecond = Infinity; - fields.nanosecond = Infinity; - return retval; - } - } - return new CalendarMakeInfinityTime(); - }, - - /* - * A custom calendar that defines getters on the fields object passed into - * dateFromFields that throw, sabotaging its time properties. - */ - calendarMakeInvalidGettersTime() { - class CalendarMakeInvalidGettersTime extends Temporal.Calendar { - constructor() { - super("iso8601"); - } - - dateFromFields(fields, options) { - const retval = super.dateFromFields(fields, options); - const throwingDescriptor = { - get() { - throw new Test262Error("reading a sabotaged time field"); - }, - }; - Object.defineProperties(fields, { - hour: throwingDescriptor, - minute: throwingDescriptor, - second: throwingDescriptor, - millisecond: throwingDescriptor, - microsecond: throwingDescriptor, - nanosecond: throwingDescriptor, - }); - return retval; - } - } - return new CalendarMakeInvalidGettersTime(); - }, - - /* - * A custom calendar whose mergeFields() method returns a proxy object with - * all of its Get and HasProperty operations observable, as well as adding a - * "shouldNotBeCopied": true property. - */ - calendarMergeFieldsGetters() { - class CalendarMergeFieldsGetters extends Temporal.Calendar { - constructor() { - super("iso8601"); - this.mergeFieldsReturnOperations = []; - } - - toString() { - return "merge-fields-getters"; - } - - dateFromFields(fields, options) { - assert.sameValue(fields.shouldNotBeCopied, undefined, "extra fields should not be copied"); - return super.dateFromFields(fields, options); - } - - yearMonthFromFields(fields, options) { - assert.sameValue(fields.shouldNotBeCopied, undefined, "extra fields should not be copied"); - return super.yearMonthFromFields(fields, options); - } - - monthDayFromFields(fields, options) { - assert.sameValue(fields.shouldNotBeCopied, undefined, "extra fields should not be copied"); - return super.monthDayFromFields(fields, options); - } - - mergeFields(fields, additionalFields) { - const retval = super.mergeFields(fields, additionalFields); - retval._calendar = this; - retval.shouldNotBeCopied = true; - return new Proxy(retval, { - get(target, key) { - target._calendar.mergeFieldsReturnOperations.push(`get ${key}`); - const result = target[key]; - if (result === undefined) { - return undefined; - } - return TemporalHelpers.toPrimitiveObserver(target._calendar.mergeFieldsReturnOperations, result, key); - }, - has(target, key) { - target._calendar.mergeFieldsReturnOperations.push(`has ${key}`); - return key in target; - }, - }); - } - } - return new CalendarMergeFieldsGetters(); - }, - - /* - * A custom calendar whose mergeFields() method returns a primitive value, - * given by @primitive, and which records the number of calls made to its - * dateFromFields(), yearMonthFromFields(), and monthDayFromFields() methods. - */ - calendarMergeFieldsReturnsPrimitive(primitive) { - class CalendarMergeFieldsPrimitive extends Temporal.Calendar { - constructor(mergeFieldsReturnValue) { - super("iso8601"); - this._mergeFieldsReturnValue = mergeFieldsReturnValue; - this.dateFromFieldsCallCount = 0; - this.monthDayFromFieldsCallCount = 0; - this.yearMonthFromFieldsCallCount = 0; - } - - toString() { - return "merge-fields-primitive"; - } - - dateFromFields(fields, options) { - this.dateFromFieldsCallCount++; - return super.dateFromFields(fields, options); - } - - yearMonthFromFields(fields, options) { - this.yearMonthFromFieldsCallCount++; - return super.yearMonthFromFields(fields, options); - } - - monthDayFromFields(fields, options) { - this.monthDayFromFieldsCallCount++; - return super.monthDayFromFields(fields, options); - } - - mergeFields() { - return this._mergeFieldsReturnValue; - } - } - return new CalendarMergeFieldsPrimitive(primitive); - }, - - /* - * A custom calendar whose fields() method returns the same value as the - * iso8601 calendar, with the addition of extraFields provided as parameter. - */ - calendarWithExtraFields(fields) { - class CalendarWithExtraFields extends Temporal.Calendar { - constructor(extraFields) { - super("iso8601"); - this._extraFields = extraFields; - } - - fields(fieldNames) { - return super.fields(fieldNames).concat(this._extraFields); - } - } - - return new CalendarWithExtraFields(fields); - }, - /* * observeProperty(calls, object, propertyName, value): * @@ -1421,72 +911,6 @@ var TemporalHelpers = { }; }, - /* - * oneShiftTimeZone(shiftInstant, shiftNanoseconds): - * - * In the case of a spring-forward time zone offset transition (skipped time), - * and disambiguation === 'earlier', BuiltinTimeZoneGetInstantFor subtracts a - * negative number of nanoseconds from a PlainDateTime, which should balance - * with the microseconds field. - * - * This returns an instance of a custom time zone class which skips a length - * of time equal to shiftNanoseconds (a number), at the Temporal.Instant - * shiftInstant. Before shiftInstant, it's identical to UTC, and after - * shiftInstant it's a constant-offset time zone. - * - * It provides a getPossibleInstantsForCalledWith member which is an array - * with the result of calling toString() on any PlainDateTimes passed to - * getPossibleInstantsFor(). - */ - oneShiftTimeZone(shiftInstant, shiftNanoseconds) { - class OneShiftTimeZone extends Temporal.TimeZone { - constructor(shiftInstant, shiftNanoseconds) { - super("+00:00"); - this._shiftInstant = shiftInstant; - this._epoch1 = shiftInstant.epochNanoseconds; - this._epoch2 = this._epoch1 + BigInt(shiftNanoseconds); - this._shiftNanoseconds = shiftNanoseconds; - this._shift = new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, this._shiftNanoseconds); - this.getPossibleInstantsForCalledWith = []; - } - - _isBeforeShift(instant) { - return instant.epochNanoseconds < this._epoch1; - } - - getOffsetNanosecondsFor(instant) { - return this._isBeforeShift(instant) ? 0 : this._shiftNanoseconds; - } - - getPossibleInstantsFor(plainDateTime) { - this.getPossibleInstantsForCalledWith.push(plainDateTime.toString({ calendarName: "never" })); - const [instant] = super.getPossibleInstantsFor(plainDateTime); - if (this._shiftNanoseconds > 0) { - if (this._isBeforeShift(instant)) return [instant]; - if (instant.epochNanoseconds < this._epoch2) return []; - return [instant.subtract(this._shift)]; - } - if (instant.epochNanoseconds < this._epoch2) return [instant]; - const shifted = instant.subtract(this._shift); - if (this._isBeforeShift(instant)) return [instant, shifted]; - return [shifted]; - } - - getNextTransition(instant) { - return this._isBeforeShift(instant) ? this._shiftInstant : null; - } - - getPreviousTransition(instant) { - return this._isBeforeShift(instant) ? null : this._shiftInstant; - } - - toString() { - return "Custom/One_Shift"; - } - } - return new OneShiftTimeZone(shiftInstant, shiftNanoseconds); - }, - /* * propertyBagObserver(): * Returns an object that behaves like the given propertyBag but tracks Get diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/basic.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/basic.js deleted file mode 100644 index c1f8ad510c..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/basic.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.dateadd -description: Basic tests for dateAdd(). -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const iso = Temporal.Calendar.from("iso8601"); -const date = Temporal.PlainDate.from("1994-11-06"); -const positiveDuration = Temporal.Duration.from({ months: 1, weeks: 1 }); -const negativeDuration = Temporal.Duration.from({ months: -1, weeks: -1 }); - -TemporalHelpers.assertPlainDate( - iso.dateAdd(Temporal.PlainDateTime.from("1994-11-06T08:15:30"), positiveDuration, {}), - 1994, 12, "M12", 13, "date: PlainDateTime"); - -TemporalHelpers.assertPlainDate( - iso.dateAdd({ year: 1994, month: 11, day: 6 }, positiveDuration, {}), - 1994, 12, "M12", 13, "date: property bag"); - -TemporalHelpers.assertPlainDate( - iso.dateAdd("1994-11-06", positiveDuration, {}), - 1994, 12, "M12", 13, "date: string"); - -assert.throws(TypeError, () => iso.dateAdd({ month: 11 }, positiveDuration, {}), "date: missing property"); - -TemporalHelpers.assertPlainDate( - iso.dateAdd(date, { months: 1, weeks: 1 }, {}), - 1994, 12, "M12", 13, "duration: property bag"); - -TemporalHelpers.assertPlainDate( - iso.dateAdd(date, "P1M1W", {}), - 1994, 12, "M12", 13, "duration: string"); - -assert.throws(TypeError, () => iso.dateAdd(date, { month: 1 }, {}), "duration: missing property"); - -TemporalHelpers.assertPlainDate( - iso.dateAdd(Temporal.PlainDateTime.from("1994-11-06T08:15:30"), negativeDuration, {}), - 1994, 9, "M09", 29, "date: PlainDateTime, negative duration"); - -TemporalHelpers.assertPlainDate( - iso.dateAdd({ year: 1994, month: 11, day: 6 }, negativeDuration, {}), - 1994, 9, "M09", 29, "date: property bag, negative duration"); - -TemporalHelpers.assertPlainDate( - iso.dateAdd("1994-11-06", negativeDuration, {}), - 1994, 9, "M09", 29, "date: string, negative duration"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/duration-argument-string-negative-fractional-units.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/duration-argument-string-negative-fractional-units.js deleted file mode 100644 index 7fb804b0a6..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/duration-argument-string-negative-fractional-units.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.dateadd -description: Strings with fractional duration units are treated with the correct sign -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const calendar = new Temporal.Calendar("iso8601"); -const instance = new Temporal.PlainDate(2000, 5, 2, calendar); - -const resultHours = calendar.dateAdd(instance, "-PT24.567890123H"); -TemporalHelpers.assertPlainDate(resultHours, 2000, 5, "M05", 1, "negative fractional hours"); - -const resultMinutes = calendar.dateAdd(instance, "-PT1440.567890123M"); -TemporalHelpers.assertPlainDate(resultMinutes, 2000, 5, "M05", 1, "negative fractional minutes"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDate.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDate.js deleted file mode 100644 index f48f6bba5a..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDate.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.dateadd -description: Temporal.Calendar.prototype.dateAdd should throw from ToTemporalDate. -info: | - ... - 4. Set date to ? ToTemporalDate(date). -features: [Temporal, arrow-function] ----*/ -let cal = new Temporal.Calendar("iso8601"); - -assert.throws(RangeError, - () => cal.dateAdd("invalid date string", new Temporal.Duration(1)), - 'cal.dateAdd("invalid date string", new Temporal.Duration(1)) throws a RangeError exception'); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDuration.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDuration.js deleted file mode 100644 index 82402427ae..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDuration.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.dateadd -description: Temporal.Calendar.prototype.dateAdd should throw from ToTemporalDuration. -info: | - ... - 5. Set duration to ? ToTemporalDuration(duration). -features: [Temporal, arrow-function] ----*/ -let cal = new Temporal.Calendar("iso8601"); - -assert.throws(RangeError, - () => cal.dateAdd("2020-02-03", "invalid duration string"), - 'cal.dateAdd("2020-02-03", "invalid duration string") throws a RangeError exception'); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-type-error-from-GetOptionsObject.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-type-error-from-GetOptionsObject.js deleted file mode 100644 index ced9209a48..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-type-error-from-GetOptionsObject.js +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: sec-temporal.calendar.prototype.dateadd -description: Temporal.Calendar.prototype.dateAdd should throw from GetOptionsObject. -info: | - ... - 6. Set options to ? GetOptionsObject(options). -features: [BigInt, Symbol, Temporal, arrow-function] ----*/ -let cal = new Temporal.Calendar('iso8601'); -let invalidOptionsList = [null, 'invalid option', 234, 23n, Symbol('foo'), true, false, Infinity]; - -invalidOptionsList.forEach(function(invalidOptions) { - assert.throws( - TypeError, - () => cal.dateAdd('2020-02-03', 'P1Y', invalidOptions), - 'cal.dateAdd("2020-02-03", "P1Y", invalidOptions) throws a TypeError exception' - ); -}); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/missing-properties.js b/test/built-ins/Temporal/Calendar/prototype/dateFromFields/missing-properties.js deleted file mode 100644 index e1694ccf10..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/missing-properties.js +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.datefromfields -description: Errors due to missing properties on fields object are thrown in the correct order -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Calendar("iso8601"); - -const missingDay = { - get year() { - TemporalHelpers.assertUnreachable("day should be checked first"); - }, - get month() { - TemporalHelpers.assertUnreachable("day should be checked first"); - }, - get monthCode() { - TemporalHelpers.assertUnreachable("day should be checked first"); - }, -}; -assert.throws(TypeError, () => instance.dateFromFields(missingDay), "day should be checked before year and month"); - -let getMonth = false; -let getMonthCode = false; -const missingYearAndMonth = { - day: 1, - get month() { - getMonth = true; - }, - get monthCode() { - getMonthCode = true; - }, -}; -assert.throws(TypeError, () => instance.dateFromFields(missingYearAndMonth), "year should be checked after fetching but before resolving the month"); -assert(getMonth, "year is fetched after month"); -assert(getMonthCode, "year is fetched after monthCode"); - -const missingMonth = { - day: 1, - year: 2000, -}; -assert.throws(TypeError, () => instance.dateFromFields(missingMonth), "month should be resolved last"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/throw-type-error-from-GetOptionsObject.js b/test/built-ins/Temporal/Calendar/prototype/dateFromFields/throw-type-error-from-GetOptionsObject.js deleted file mode 100644 index 5ec1e2c75a..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/throw-type-error-from-GetOptionsObject.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: sec-temporal.calendar.prototype.datefromfields -description: Temporal.Calendar.prototype.dateFromFields should throw TypeError from GetOptionsObject. -info: | - 4. If Type(fields) is not Object, throw a TypeError exception. -features: [BigInt, Symbol, Temporal, arrow-function] ----*/ -let cal = new Temporal.Calendar('iso8601'); - -let fields = { - year: 2021, - month: 7, - day: 20 -}; - -let notObjectList = [null, 'string', Symbol('efg'), true, false, Infinity, NaN, 123, 456n]; - -notObjectList.forEach(function(options) { - assert.throws( - TypeError, - () => cal.dateFromFields(fields, options), - 'cal.dateFromFields(fields, options) throws a TypeError exception' - ); -}); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/throws-range-error.js b/test/built-ins/Temporal/Calendar/prototype/dateFromFields/throws-range-error.js deleted file mode 100644 index 7f433249a8..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/throws-range-error.js +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: sec-temporal.calendar.prototype.datefromfields -description: > - Temporal.Calendar.prototype.dateFromFields should throw RangeError for - input not in valid range. -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. If Type(fields) is not Object, throw a TypeError exception. - 5. Set options to ? GetOptionsObject(options). - 6. Let result be ? ISODateFromFields(fields, options). - 7. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], calendar). -features: [Temporal, arrow-function] ----*/ -let cal = new Temporal.Calendar("iso8601") - -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, monthCode: "m1", day: 17}), - 'cal.dateFromFields({year: 2021, monthCode: "m1", day: 17}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, monthCode: "M1", day: 17}), - 'cal.dateFromFields({year: 2021, monthCode: "M1", day: 17}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, monthCode: "m01", day: 17}), - 'cal.dateFromFields({year: 2021, monthCode: "m01", day: 17}) throws a RangeError exception'); - -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, month: 12, monthCode: "M11", day: 17}), - 'cal.dateFromFields({year: 2021, month: 12, monthCode: "M11", day: 17}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, monthCode: "M00", day: 17}), - 'cal.dateFromFields({year: 2021, monthCode: "M00", day: 17}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, monthCode: "M19", day: 17}), - 'cal.dateFromFields({year: 2021, monthCode: "M19", day: 17}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, monthCode: "M99", day: 17}), - 'cal.dateFromFields({year: 2021, monthCode: "M99", day: 17}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, monthCode: "M13", day: 17}), - 'cal.dateFromFields({year: 2021, monthCode: "M13", day: 17}) throws a RangeError exception'); - -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, month: -1, day: 17}), - 'cal.dateFromFields({year: 2021, month: -1, day: 17}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, month: -Infinity, day: 17}), - 'cal.dateFromFields({year: 2021, month: -Infinity, day: 17}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, month: 7, day: -17}), - 'cal.dateFromFields({year: 2021, month: 7, day: -17}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, month: 7, day: -Infinity}), - 'cal.dateFromFields({year: 2021, month: 7, day: -Infinity}) throws a RangeError exception'); - -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, month: 12, day: 0}, {overflow: "reject"}), - 'cal.dateFromFields({year: 2021, month: 12, day: 0}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, month: 12, day: 32}, {overflow: "reject"}), - 'cal.dateFromFields({year: 2021, month: 12, day: 32}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, month: 1, day: 32}, {overflow: "reject"}), - 'cal.dateFromFields({year: 2021, month: 1, day: 32}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, month: 2, day: 29}, {overflow: "reject"}), - 'cal.dateFromFields({year: 2021, month: 2, day: 29}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, month: 6, day: 31}, {overflow: "reject"}), - 'cal.dateFromFields({year: 2021, month: 6, day: 31}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, month: 9, day: 31}, {overflow: "reject"}), - 'cal.dateFromFields({year: 2021, month: 9, day: 31}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, month: 0, day: 5}, {overflow: "reject"}), - 'cal.dateFromFields({year: 2021, month: 0, day: 5}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields({year: 2021, month: 13, day: 5}, {overflow: "reject"}), - 'cal.dateFromFields({year: 2021, month: 13, day: 5}, {overflow: "reject"}) throws a RangeError exception'); - -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, monthCode: "M12", day: 0}, {overflow: "reject"}), - 'cal.dateFromFields( {year: 2021, monthCode: "M12", day: 0}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, monthCode: "M12", day: 32}, {overflow: "reject"}), - 'cal.dateFromFields( {year: 2021, monthCode: "M12", day: 32}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, monthCode: "M01", day: 32}, {overflow: "reject"}), - 'cal.dateFromFields( {year: 2021, monthCode: "M01", day: 32}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, monthCode: "M02", day: 29}, {overflow: "reject"}), - 'cal.dateFromFields( {year: 2021, monthCode: "M02", day: 29}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, monthCode: "M06", day: 31}, {overflow: "reject"}), - 'cal.dateFromFields( {year: 2021, monthCode: "M06", day: 31}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, monthCode: "M09", day: 31}, {overflow: "reject"}), - 'cal.dateFromFields( {year: 2021, monthCode: "M09", day: 31}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, monthCode: "M00", day: 5}, {overflow: "reject"}), - 'cal.dateFromFields( {year: 2021, monthCode: "M00", day: 5}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, monthCode: "M13", day: 5}, {overflow: "reject"}), - 'cal.dateFromFields( {year: 2021, monthCode: "M13", day: 5}, {overflow: "reject"}) throws a RangeError exception'); - -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 12, day: 0}), 'cal.dateFromFields( {year: 2021, month: 12, day: 0}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 0, day: 3}), 'cal.dateFromFields( {year: 2021, month: 0, day: 3}) throws a RangeError exception'); - -// Check throw for the second arg -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 7, day: 13}, {overflow: "invalid"}), 'cal.dateFromFields( {year: 2021, month: 7, day: 13}, {overflow: "invalid"}) throws a RangeError exception'); - -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 1, day: 32}, {overflow: "reject"}), 'cal.dateFromFields( {year: 2021, month: 1, day: 32}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 2, day: 29}, {overflow: "reject"}), 'cal.dateFromFields( {year: 2021, month: 2, day: 29}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 3, day: 32}, {overflow: "reject"}), 'cal.dateFromFields( {year: 2021, month: 3, day: 32}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 4, day: 31}, {overflow: "reject"}), 'cal.dateFromFields( {year: 2021, month: 4, day: 31}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 5, day: 32}, {overflow: "reject"}), 'cal.dateFromFields( {year: 2021, month: 5, day: 32}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 6, day: 31}, {overflow: "reject"}), 'cal.dateFromFields( {year: 2021, month: 6, day: 31}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 7, day: 32}, {overflow: "reject"}), 'cal.dateFromFields( {year: 2021, month: 7, day: 32}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 8, day: 32}, {overflow: "reject"}), 'cal.dateFromFields( {year: 2021, month: 8, day: 32}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 9, day: 31}, {overflow: "reject"}), 'cal.dateFromFields( {year: 2021, month: 9, day: 31}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 10, day: 32}, {overflow: "reject"}), 'cal.dateFromFields( {year: 2021, month: 10, day: 32}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 11, day: 31}, {overflow: "reject"}), 'cal.dateFromFields( {year: 2021, month: 11, day: 31}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 12, day: 32}, {overflow: "reject"}), 'cal.dateFromFields( {year: 2021, month: 12, day: 32}, {overflow: "reject"}) throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateFromFields( - {year: 2021, month: 13, day: 5}, {overflow: "reject"}), 'cal.dateFromFields( {year: 2021, month: 13, day: 5}, {overflow: "reject"}) throws a RangeError exception'); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/throws-type-error.js b/test/built-ins/Temporal/Calendar/prototype/dateFromFields/throws-type-error.js deleted file mode 100644 index b970735574..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/throws-type-error.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: sec-temporal.calendar.prototype.datefromfields -description: Temporal.Calendar.prototype.dateFromFields should throw TypeError with wrong type. -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. If Type(fields) is not Object, throw a TypeError exception. - 5. Set options to ? GetOptionsObject(options). - 6. Let result be ? ISODateFromFields(fields, options). - 7. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], calendar). -features: [BigInt, Symbol, Temporal, arrow-function] ----*/ -// Check throw for first arg -let cal = new Temporal.Calendar('iso8601'); -assert.throws(TypeError, () => cal.dateFromFields(), 'cal.dateFromFields() throws a TypeError exception'); - -[undefined, true, false, 123, 456n, Symbol(), 'string'].forEach(function(fields) { - assert.throws( - TypeError, - () => cal.dateFromFields(fields), - 'cal.dateFromFields(fields) throws a TypeError exception' - ); - - assert.throws( - TypeError, - () => cal.dateFromFields(fields, undefined), - 'cal.dateFromFields(fields, undefined) throws a TypeError exception' - ); - - assert.throws(TypeError, () => cal.dateFromFields(fields, { - overflow: 'constrain' - }), 'cal.dateFromFields(fields, {overflow: "constrain"}) throws a TypeError exception'); - - assert.throws(TypeError, () => cal.dateFromFields(fields, { - overflow: 'reject' - }), 'cal.dateFromFields(fields, {overflow: "reject"}) throws a TypeError exception'); -}); - -assert.throws(TypeError, () => cal.dateFromFields({ - month: 1, - day: 17 -}), 'cal.dateFromFields({month: 1, day: 17}) throws a TypeError exception'); - -assert.throws(TypeError, () => cal.dateFromFields({ - year: 2021, - day: 17 -}), 'cal.dateFromFields({year: 2021, day: 17}) throws a TypeError exception'); - -assert.throws(TypeError, () => cal.dateFromFields({ - year: 2021, - month: 12 -}), 'cal.dateFromFields({year: 2021, month: 12}) throws a TypeError exception'); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/basic.js b/test/built-ins/Temporal/Calendar/prototype/dateUntil/basic.js deleted file mode 100644 index c7d4d4b49f..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/dateUntil/basic.js +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.dateuntil -description: Basic tests for dateUntil(). -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const iso = Temporal.Calendar.from("iso8601"); -const date1 = Temporal.PlainDate.from("1999-09-03"); -const date2 = Temporal.PlainDate.from("2000-01-01"); - -TemporalHelpers.assertDuration( - iso.dateUntil(date1, date2, {}), - 0, 0, 0, 120, 0, 0, 0, 0, 0, 0, "two PlainDates"); - -TemporalHelpers.assertDuration( - iso.dateUntil(Temporal.PlainDateTime.from("1999-09-03T08:15:30"), date2, {}), - 0, 0, 0, 120, 0, 0, 0, 0, 0, 0, "first argument: PlainDateTime"); - -TemporalHelpers.assertDuration( - iso.dateUntil({ year: 1999, month: 9, day: 3 }, date2, {}), - 0, 0, 0, 120, 0, 0, 0, 0, 0, 0, "first argument: property bag"); - -TemporalHelpers.assertDuration( - iso.dateUntil("1999-09-03", date2, {}), - 0, 0, 0, 120, 0, 0, 0, 0, 0, 0, "first argument: string"); - -assert.throws(TypeError, () => iso.dateUntil({ month: 11 }, date2, {}), "first argument: missing property"); - -TemporalHelpers.assertDuration( - iso.dateUntil(date1, Temporal.PlainDateTime.from("2000-01-01T08:15:30"), {}), - 0, 0, 0, 120, 0, 0, 0, 0, 0, 0, "second argument: PlainDateTime"); - -TemporalHelpers.assertDuration( - iso.dateUntil(date1, { year: 2000, month: 1, day: 1 }, {}), - 0, 0, 0, 120, 0, 0, 0, 0, 0, 0, "second argument: property bag"); - -TemporalHelpers.assertDuration( - iso.dateUntil(date1, "2000-01-01", {}), - 0, 0, 0, 120, 0, 0, 0, 0, 0, 0, "second argument: string"); - -assert.throws(TypeError, () => iso.dateUntil(date1, { month: 11 }, {}), "second argument: missing property"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/largest-unit-day.js b/test/built-ins/Temporal/Calendar/prototype/dateUntil/largest-unit-day.js deleted file mode 100644 index 530d104afa..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/dateUntil/largest-unit-day.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.dateuntil -description: Temporal.Calendar.prototype.dateUntil with largestUnit is "day" -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. Set one to ? ToTemporalDate(one). - 5. Set two to ? ToTemporalDate(two). - 6. Set options to ? GetOptionsObject(options). - 7. Let largestUnit be ? ToLargestTemporalUnit(options, « "hour", "minute", "second", "millisecond", "microsecond", "nanosecond" », "auto", "day"). - 8. Let result be ! DifferenceISODate(one.[[ISOYear]], one.[[ISOMonth]], one.[[ISODay]], two.[[ISOYear]], two.[[ISOMonth]], two.[[ISODay]], largestUnit). - 9. Return ? CreateTemporalDuration(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], 0, 0, 0, 0, 0, 0). -features: [Temporal] -includes: [temporalHelpers.js] ----*/ -let cal = new Temporal.Calendar("iso8601"); - -["day", "days"].forEach(function(largestUnit) { - let opt = {largestUnit}; - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-07-16", opt), - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "same day"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-07-17", opt), - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "one day"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-08-17", opt), - 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, "32 days"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-09-16", opt), - 0, 0, 0, 62, 0, 0, 0, 0, 0, 0, "62 days"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2022-07-16", opt), - 0, 0, 0, 365, 0, 0, 0, 0, 0, 0, "365 days"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2031-07-16", opt), - 0, 0, 0, 3652, 0, 0, 0, 0, 0, 0, "3652 days"); - - - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-17", "2021-07-16", opt), - 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "negative one day"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-08-17", "2021-07-16", opt), - 0, 0, 0, -32, 0, 0, 0, 0, 0, 0, "negative 32 days"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-09-16", "2021-07-16", opt), - 0, 0, 0, -62, 0, 0, 0, 0, 0, 0, "negative 62 days"); - TemporalHelpers.assertDuration( - cal.dateUntil("2022-07-16", "2021-07-16", opt), - 0, 0, 0, -365, 0, 0, 0, 0, 0, 0, "negative 365 days"); - TemporalHelpers.assertDuration( - cal.dateUntil("2031-07-16", "2021-07-16", opt), - 0, 0, 0, -3652, 0, 0, 0, 0, 0, 0, "negative 3652 days"); -}); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/largest-unit-week.js b/test/built-ins/Temporal/Calendar/prototype/dateUntil/largest-unit-week.js deleted file mode 100644 index 757794631b..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/dateUntil/largest-unit-week.js +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.dateuntil -description: Temporal.Calendar.prototype.dateUntil with largestUnit is "week" -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. Set one to ? ToTemporalDate(one). - 5. Set two to ? ToTemporalDate(two). - 6. Set options to ? GetOptionsObject(options). - 7. Let largestUnit be ? ToLargestTemporalUnit(options, « "hour", "minute", "second", "millisecond", "microsecond", "nanosecond" », "auto", "day"). - 8. Let result be ! DifferenceISODate(one.[[ISOYear]], one.[[ISOMonth]], one.[[ISODay]], two.[[ISOYear]], two.[[ISOMonth]], two.[[ISODay]], largestUnit). - 9. Return ? CreateTemporalDuration(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], 0, 0, 0, 0, 0, 0). -features: [Temporal] -includes: [temporalHelpers.js] ----*/ -let cal = new Temporal.Calendar("iso8601"); - -["week", "weeks"].forEach(function(largestUnit) { - let opt = {largestUnit}; - - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-07-16", opt), - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "same day"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-07-17", opt), - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "one day"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-07-23", opt), - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "7 days"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-08-16", opt), - 0, 0, 4, 3, 0, 0, 0, 0, 0, 0, "4 weeks and 3 days"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-08-13", opt), - 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, "4 weeks"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-09-16", opt), - 0, 0, 8, 6, 0, 0, 0, 0, 0, 0, "8 weeks and 6 days"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2022-07-16", opt), - 0, 0, 52, 1, 0, 0, 0, 0, 0, 0, "52 weeks and 1 day"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2031-07-16", opt), - 0, 0, 521, 5, 0, 0, 0, 0, 0, 0, "521 weeks and 5 days"); - - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-17", "2021-07-16", opt), - 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "negative one day"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-23", "2021-07-16", opt), - 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, "negative 7 days"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-08-16", "2021-07-16", opt), - 0, 0, -4, -3, 0, 0, 0, 0, 0, 0, "negative 4 weeks and 3 days"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-08-13", "2021-07-16", opt), - 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, "negative 4 weeks"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-09-16", "2021-07-16", opt), - 0, 0, -8, -6, 0, 0, 0, 0, 0, 0, "negative 8 weeks and 6 days"); - TemporalHelpers.assertDuration( - cal.dateUntil("2022-07-16", "2021-07-16", opt), - 0, 0, -52, -1, 0, 0, 0, 0, 0, 0, "negative 52 weeks and 1 day"); - TemporalHelpers.assertDuration( - cal.dateUntil("2031-07-16", "2021-07-16", opt), - 0, 0, -521, -5, 0, 0, 0, 0, 0, 0, "negative 521 weeks and 5 days"); -}); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/throws-range-error-ToLargestTemporalUnit.js b/test/built-ins/Temporal/Calendar/prototype/dateUntil/throws-range-error-ToLargestTemporalUnit.js deleted file mode 100644 index eda0c7b458..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/dateUntil/throws-range-error-ToLargestTemporalUnit.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.dateuntil -description: Temporal.Calendar.prototype.dateUntil throw RangeError on ToLargestTemporalUnit with invalide or disallowed unit -info: | - 7. Let largestUnit be ? ToLargestTemporalUnit(options, « "hour", "minute", "second", "millisecond", "microsecond", "nanosecond" », "auto", "day"). -features: [Temporal, arrow-function] ----*/ -let cal = new Temporal.Calendar("iso8601"); - -["invalid", "hour", "minute", "second", "millisecond", "microsecond", - "nanosecond"].forEach(function(largestUnit) { - assert.throws(RangeError, () => cal.dateUntil("2021-07-16", "2022-03-04", {largestUnit}), - 'cal.dateUntil("2021-07-16", "2022-03-04", {largestUnit}) throws a RangeError exception'); -}); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/throws-range-error-ToTemporalDate.js b/test/built-ins/Temporal/Calendar/prototype/dateUntil/throws-range-error-ToTemporalDate.js deleted file mode 100644 index 75384d627e..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/dateUntil/throws-range-error-ToTemporalDate.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.dateuntil -description: Temporal.Calendar.prototype.dateUntil throw RangeError on ToTemporalDate -info: | - 1. Let calendar be the this value. - 4. Set one to ? ToTemporalDate(one). - 5. Set two to ? ToTemporalDate(two). -features: [Temporal, arrow-function] ----*/ -let cal = new Temporal.Calendar("iso8601"); - -assert.throws(RangeError, () => cal.dateUntil("2021-07-16", "invalide date"), - 'cal.dateUntil("2021-07-16", "invalide date") throws a RangeError exception'); -assert.throws(RangeError, () => cal.dateUntil("invalide date", "2021-07-16"), - 'cal.dateUntil("invalide date", "2021-07-16") throws a RangeError exception'); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/throws-type-error-GetOptionsObject.js b/test/built-ins/Temporal/Calendar/prototype/dateUntil/throws-type-error-GetOptionsObject.js deleted file mode 100644 index 3cce0671f0..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/dateUntil/throws-type-error-GetOptionsObject.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: sec-temporal.calendar.prototype.dateuntil -description: Temporal.Calendar.prototype.dateUntil throw TypeError on GetOptionsObject -info: | - 6. Set options to ? GetOptionsObject(options). -features: [BigInt, Symbol, Temporal, arrow-function] ----*/ -let cal = new Temporal.Calendar('iso8601'); - -['string', null, true, false, 123, 456n, Symbol(), Infinity, NaN].forEach(function(opt) { - assert.throws( - TypeError, - () => cal.dateUntil('2021-07-16', '2021-08-11', opt), - 'cal.dateUntil("2021-07-16", "2021-08-11", opt) throws a TypeError exception' - ); -}); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/basic.js b/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/basic.js deleted file mode 100644 index 28aa00db18..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/basic.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.monthdayfromfields -description: Temporal.Calendar.prototype.monthDayFromFields will return correctly with valid data. -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. If Type(fields) is not Object, throw a TypeError exception. - 5. Set options to ? GetOptionsObject(options). - 6. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "day" »). - 7. Let overflow be ? ToTemporalOverflow(options). - 8. Perform ? ISOResolveMonth(fields). - 9. Let result be ? ISOMonthDayFromFields(fields, overflow). - 10. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], "iso8601", result.[[ReferenceISOYear]]). -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const cal = new Temporal.Calendar("iso8601"); - -const options = [ - { overflow: "constrain" }, - { overflow: "reject" }, - {}, - undefined, -]; -options.forEach((opt) => { - const optionsDesc = opt && JSON.stringify(opt); - let result = cal.monthDayFromFields({ year: 2021, month: 7, day: 3 }, opt); - TemporalHelpers.assertPlainMonthDay(result, "M07", 3, `month 7, day 3, with year, options = ${optionsDesc}`); - result = cal.monthDayFromFields({ year: 2021, month: 12, day: 31 }, opt); - TemporalHelpers.assertPlainMonthDay(result, "M12", 31, `month 12, day 31, with year, options = ${optionsDesc}`); - result = cal.monthDayFromFields({ monthCode: "M07", day: 3 }, opt); - TemporalHelpers.assertPlainMonthDay(result, "M07", 3, `monthCode M07, day 3, options = ${optionsDesc}`); - result = cal.monthDayFromFields({ monthCode: "M12", day: 31 }, opt); - TemporalHelpers.assertPlainMonthDay(result, "M12", 31, `monthCode M12, day 31, options = ${optionsDesc}`); -}); - -TemporalHelpers.ISOMonths.forEach(({ month, monthCode, daysInMonth }) => { - let result = cal.monthDayFromFields({ month, day: daysInMonth }); - TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth, `month ${month}, day ${daysInMonth}`); - - result = cal.monthDayFromFields({ monthCode, day: daysInMonth }); - TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth, `monthCode ${monthCode}, day ${daysInMonth}`); -}); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/fields-missing-properties.js b/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/fields-missing-properties.js deleted file mode 100644 index 6a3d30d439..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/fields-missing-properties.js +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.monthdayfromfields -description: Temporal.Calendar.prototype.monthDayFromFields will throw TypeError with incorrect input data type. -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. If Type(fields) is not Object, throw a TypeError exception. - 5. Set options to ? GetOptionsObject(options). - 6. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "day" »). - 7. Let overflow be ? ToTemporalOverflow(options). - 8. Perform ? ISOResolveMonth(fields). - 9. Let result be ? ISOMonthDayFromFields(fields, overflow). - 10. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], "iso8601", result.[[ReferenceISOYear]]). -features: [Temporal] ----*/ - -let cal = new Temporal.Calendar("iso8601") - -assert.throws(TypeError, () => cal.monthDayFromFields({}), "at least one correctly spelled property is required"); -assert.throws(TypeError, () => cal.monthDayFromFields({ month: 12 }), "day is required with month"); -assert.throws(TypeError, () => cal.monthDayFromFields({ monthCode: "M12" }), "day is required with monthCode"); -assert.throws(TypeError, () => cal.monthDayFromFields({ year: 2021, month: 12 }), "day is required with year and month"); -assert.throws(TypeError, () => cal.monthDayFromFields({ year: 2021, monthCode: "M12" }), "day is required with year and monthCode"); -assert.throws(TypeError, () => cal.monthDayFromFields({ year: 2021, day: 17 }), "either month or monthCode is required"); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/missing-properties.js b/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/missing-properties.js deleted file mode 100644 index 0c426af686..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/missing-properties.js +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.monthdayfromfields -description: Errors due to missing properties on fields object are thrown in the correct order -includes: [compareArray.js, temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Calendar("iso8601"); - -const missingDay = { - get year() { - TemporalHelpers.assertUnreachable("day should be checked first"); - }, - get month() { - TemporalHelpers.assertUnreachable("day should be checked first"); - }, - get monthCode() { - TemporalHelpers.assertUnreachable("day should be checked first"); - }, -}; -assert.throws(TypeError, () => instance.monthDayFromFields(missingDay), "day should be checked before year and month"); - -let got = []; -const fieldsSpy = TemporalHelpers.propertyBagObserver(got, { day: 1 }); -assert.throws(TypeError, () => instance.monthDayFromFields(fieldsSpy), "incomplete fields should be rejected (but after reading all non-required fields)"); -assert.compareArray(got, [ - "get day", - "get day.valueOf", - "call day.valueOf", - "get month", - "get monthCode", - "get year", -], "fields should be read in alphabetical order"); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/monthcode-invalid.js b/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/monthcode-invalid.js deleted file mode 100644 index 29e5c4f098..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/monthcode-invalid.js +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.monthdayfromfields -description: Throw RangeError for an out-of-range, conflicting, or ill-formed monthCode -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. If Type(fields) is not Object, throw a TypeError exception. - 5. Set options to ? GetOptionsObject(options). - 6. Let result be ? ISOMonthDayFromFields(fields, options). - 7. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], calendar, result.[[ReferenceISOYear]]). -features: [Temporal] ----*/ - -const cal = new Temporal.Calendar("iso8601"); - -["m1", "M1", "m01"].forEach((monthCode) => { - assert.throws(RangeError, () => cal.monthDayFromFields({ monthCode, day: 17 }), - `monthCode '${monthCode}' is not well-formed`); -}); - -assert.throws(RangeError, () => cal.monthDayFromFields({ year: 2021, month: 12, monthCode: "M11", day: 17 }), - "monthCode and month conflict"); - -["M00", "M19", "M99", "M13"].forEach((monthCode) => { - assert.throws(RangeError, () => cal.monthDayFromFields({ monthCode, day: 17 }), - `monthCode '${monthCode}' is not valid for ISO 8601 calendar`); -}); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/overflow-constrain.js b/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/overflow-constrain.js deleted file mode 100644 index 4388661217..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/overflow-constrain.js +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.monthdayfromfields -description: Temporal.Calendar.prototype.monthDayFromFields will return correctly with data and overflow set to 'constrain'. -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. If Type(fields) is not Object, throw a TypeError exception. - 5. Set options to ? GetOptionsObject(options). - 6. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "day" »). - 7. Let overflow be ? ToTemporalOverflow(options). - 8. Perform ? ISOResolveMonth(fields). - 9. Let result be ? ISOMonthDayFromFields(fields, overflow). - 10. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], "iso8601", result.[[ReferenceISOYear]]). -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const cal = new Temporal.Calendar("iso8601"); -const opt = { overflow: "constrain" }; - -let result = cal.monthDayFromFields({ year: 2021, month: 13, day: 1 }, opt); -TemporalHelpers.assertPlainMonthDay(result, "M12", 1, "month 13 is constrained to 12"); - -result = cal.monthDayFromFields({ year: 2021, month: 999999, day: 500 }, opt); -TemporalHelpers.assertPlainMonthDay(result, "M12", 31, "month 999999 is constrained to 12 and day 500 is constrained to 31"); - -[-99999, -1, 0].forEach((month) => { - assert.throws( - RangeError, - () => cal.monthDayFromFields({ year: 2021, month, day: 1 }, opt), - `Month ${month} is out of range for 2021 even with overflow: constrain` - ); -}); - -TemporalHelpers.ISOMonths.forEach(({ month, monthCode, daysInMonth }) => { - const day = daysInMonth + 1; - - result = cal.monthDayFromFields({ month, day }, opt); - TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth, - `day is constrained from ${day} to ${daysInMonth} in month ${month}`); - - result = cal.monthDayFromFields({ month, day: 9001 }, opt); - TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth, - `day is constrained to ${daysInMonth} in month ${month}`); - - result = cal.monthDayFromFields({ monthCode, day }, opt); - TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth, - `day is constrained from ${day} to ${daysInMonth} in monthCode ${monthCode}`); - - result = cal.monthDayFromFields({ monthCode, day: 9001 }, opt); - TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth, - `day is constrained to ${daysInMonth} in monthCode ${monthCode}`); -}); - -[ ["month", 2], ["monthCode", "M02"] ].forEach(([ name, value ]) => { - result = cal.monthDayFromFields({ year: 2020, [name]: value, day: 30 }, opt); - TemporalHelpers.assertPlainMonthDay(result, "M02", 29, `${name} ${value} is constrained to 29 in leap year 2020`); - - result = cal.monthDayFromFields({ year: 2021, [name]: value, day: 29 }, opt); - TemporalHelpers.assertPlainMonthDay(result, "M02", 28, `${name} ${value} is constrained to 28 in common year 2021`); -}); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/overflow-reject.js b/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/overflow-reject.js deleted file mode 100644 index 6fe0227ff3..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/overflow-reject.js +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.monthdayfromfields -description: Throw RangeError for input data out of range with overflow reject -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. If Type(fields) is not Object, throw a TypeError exception. - 5. Set options to ? GetOptionsObject(options). - 6. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "day" »). - 7. Let overflow be ? ToTemporalOverflow(options). - 8. Perform ? ISOResolveMonth(fields). - 9. Let result be ? ISOMonthDayFromFields(fields, overflow). - 10. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], "iso8601", result.[[ReferenceISOYear]]). -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const cal = new Temporal.Calendar("iso8601"); - -[-1, 0, 13, 9995].forEach((month) => { - assert.throws( - RangeError, - () => cal.monthDayFromFields({year: 2021, month, day: 5}, { overflow: "reject" }), - `Month ${month} is out of range for 2021 with overflow: reject` - ); -}); - -[-1, 0, 32, 999].forEach((day) => { - assert.throws( - RangeError, - () => cal.monthDayFromFields({ year: 2021, month: 12, day }, { overflow: "reject" }), - `Day ${day} is out of range for 2021-12 with overflow: reject` - ); - assert.throws( - RangeError, - () => cal.monthDayFromFields({ monthCode: "M12", day }, { overflow: "reject" }), - `Day ${day} is out of range for 2021-M12 with overflow: reject` - ); -}); - -TemporalHelpers.ISOMonths.forEach(({ month, monthCode, daysInMonth }) => { - const day = daysInMonth + 1; - assert.throws(RangeError, - () => cal.monthDayFromFields({ month, day }, { overflow: "reject" }), - `Day ${day} is out of range for month ${month} with overflow: reject`); - assert.throws(RangeError, - () => cal.monthDayFromFields({ monthCode, day }, { overflow: "reject" }), - `Day ${day} is out of range for monthCode ${monthCode} with overflow: reject`); -}); - -[ ["month", 2], ["monthCode", "M02"] ].forEach(([ name, value ]) => { - assert.throws(RangeError, - () => cal.monthDayFromFields({ year: 2020, [name]: value, day: 30 }, { overflow: "reject" }), - `Day 30 is out of range for ${name} ${value} in leap year 2020 with overflow: reject`); - assert.throws(RangeError, - () => cal.monthDayFromFields({ year: 2021, [name]: value, day: 29 }, { overflow: "reject" }), - `Day 29 is out of range for ${name} ${value} in common year 2021 with overflow: reject`); -}); diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/basic.js b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/basic.js deleted file mode 100644 index 2624bc7b65..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/basic.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.yearmonthfromfields -description: Temporal.Calendar.prototype.yearMonthFromFields return correctly with valid data. -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. If Type(fields) is not Object, throw a TypeError exception. - 5. Set options to ? GetOptionsObject(options). - 6. Let result be ? ISOYearMonthFromFields(fields, options). - 7. Return ? CreateTemporalYearMonth(result.[[Year]], result.[[Month]], calendar, result.[[ReferenceISODay]]). -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const cal = new Temporal.Calendar("iso8601") - -let result = cal.yearMonthFromFields({ year: 2021, month: 7 }); -TemporalHelpers.assertPlainYearMonth(result, 2021, 7, "M07", "year 2021, month 7"); -result = cal.yearMonthFromFields({ year: 2021, month: 12 }); -TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "year 2021, month 12"); -result = cal.yearMonthFromFields({ year: 2021, monthCode: "M07" }); -TemporalHelpers.assertPlainYearMonth(result, 2021, 7, "M07", "year 2021, monthCode M07"); -result = cal.yearMonthFromFields({ year: 2021, monthCode: "M12" }); -TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "year 2021, monthCode M12"); - -["constrain", "reject"].forEach((overflow) => { - const opt = { overflow }; - result = cal.yearMonthFromFields({ year: 2021, month: 7 }, opt); - TemporalHelpers.assertPlainYearMonth(result, 2021, 7, "M07", `year 2021, month 7, overflow ${overflow}`); - result = cal.yearMonthFromFields({ year: 2021, month: 12 }, opt); - TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", `year 2021, month 12, overflow ${overflow}`); - result = cal.yearMonthFromFields({ year: 2021, monthCode: "M07" }, opt); - TemporalHelpers.assertPlainYearMonth(result, 2021, 7, "M07", `year 2021, monthCode M07, overflow ${overflow}`); - result = cal.yearMonthFromFields({ year: 2021, monthCode: "M12" }, opt); - TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", `year 2021, monthCode M12, overflow ${overflow}`); -}); diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/fields-missing-properties.js b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/fields-missing-properties.js deleted file mode 100644 index c63d8f39e6..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/fields-missing-properties.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.yearmonthfromfields -description: Temporal.Calendar.prototype.yearMonthFromFields will throw TypeError with incorrect input data type. -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. If Type(fields) is not Object, throw a TypeError exception. - 5. Set options to ? GetOptionsObject(options). - 6. Let result be ? ISOYearMonthFromFields(fields, options). - 7. Return ? CreateTemporalYearMonth(result.[[Year]], result.[[Month]], calendar, result.[[ReferenceISODay]]). -features: [Temporal] ----*/ - -const cal = new Temporal.Calendar("iso8601") - -assert.throws(TypeError, () => cal.yearMonthFromFields({}), "at least one correctly spelled property is required"); -assert.throws(TypeError, () => cal.yearMonthFromFields({ month: 1 }), "year is required"); -assert.throws(TypeError, () => cal.yearMonthFromFields({ year: 2021 }), "month or monthCode is required"); diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/monthcode-invalid.js b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/monthcode-invalid.js deleted file mode 100644 index 0b01bf85a7..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/monthcode-invalid.js +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.yearmonthfromfields -description: Throw RangeError for an out-of-range, conflicting, or ill-formed monthCode -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. If Type(fields) is not Object, throw a TypeError exception. - 5. Set options to ? GetOptionsObject(options). - 6. Let result be ? ISOYearMonthFromFields(fields, options). - 7. Return ? CreateTemporalYearMonth(result.[[Year]], result.[[Month]], calendar, result.[[ReferenceISODay]]). -features: [Temporal] ----*/ - -const cal = new Temporal.Calendar("iso8601"); - -["m1", "M1", "m01"].forEach((monthCode) => { - assert.throws(RangeError, () => cal.yearMonthFromFields({ year: 2021, monthCode }), - `monthCode '${monthCode}' is not well-formed`); -}); - -assert.throws(RangeError, () => cal.yearMonthFromFields({ year: 2021, month: 12, monthCode: "M11" }), - "monthCode and month conflict"); - -["M00", "M19", "M99", "M13"].forEach((monthCode) => { - assert.throws(RangeError, () => cal.yearMonthFromFields({ year: 2021, monthCode }), - `monthCode '${monthCode}' is not valid for year 2021`); -}); diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-constrain.js b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-constrain.js deleted file mode 100644 index 6384d42a28..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-constrain.js +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.yearmonthfromfields -description: Temporal.Calendar.prototype.yearMonthFromFields will return correctly with data and overflow set to 'constrain'. -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. If Type(fields) is not Object, throw a TypeError exception. - 5. Set options to ? GetOptionsObject(options). - 6. Let result be ? ISOYearMonthFromFields(fields, options). - 7. Return ? CreateTemporalYearMonth(result.[[Year]], result.[[Month]], calendar, result.[[ReferenceISODay]]). -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const cal = new Temporal.Calendar("iso8601") -const opt = { overflow: "constrain" }; - -let result = cal.yearMonthFromFields({ year: 2021, month: 1 }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 1, "M01", "month 1 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, month: 2 }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 2, "M02", "month 2 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, month: 3 }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 3, "M03", "month 3 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, month: 4 }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 4, "M04", "month 4 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, month: 5 }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 5, "M05", "month 5 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, month: 6 }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 6, "M06", "month 6 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, month: 7 }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 7, "M07", "month 7 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, month: 8 }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 8, "M08", "month 8 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, month: 9 }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 9, "M09", "month 9 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, month: 10 }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 10, "M10", "month 10 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, month: 11 }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 11, "M11", "month 11 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, month: 12 }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "month 12 with overflow constrain"); - -assert.throws( - RangeError, - () => cal.yearMonthFromFields({ year: 2021, month: -99999 }, opt), - "negative month -99999 is out of range even with overflow constrain" -) -assert.throws( - RangeError, - () => cal.yearMonthFromFields({ year: 2021, month: -1 }, opt), - "negative month -1 is out of range even with overflow constrain" -) -assert.throws( - RangeError, - () => cal.yearMonthFromFields({ year: 2021, month: 0 }, opt), - "month zero is out of range even with overflow constrain" -) - -result = cal.yearMonthFromFields({ year: 2021, month: 13 }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "month 13 is constrained to 12"); -result = cal.yearMonthFromFields({ year: 2021, month: 99999 }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "month 99999 is constrained to 12"); - -result = cal.yearMonthFromFields({ year: 2021, monthCode: "M01" }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 1, "M01", "monthCode M01 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, monthCode: "M02" }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 2, "M02", "monthCode M02 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, monthCode: "M03" }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 3, "M03", "monthCode M03 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, monthCode: "M04" }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 4, "M04", "monthCode M04 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, monthCode: "M05" }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 5, "M05", "monthCode M05 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, monthCode: "M06" }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 6, "M06", "monthCode M06 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, monthCode: "M07" }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 7, "M07", "monthCode M07 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, monthCode: "M08" }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 8, "M08", "monthCode M08 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, monthCode: "M09" }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 9, "M09", "monthCode M09 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, monthCode: "M10" }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 10, "M10", "monthCode M10 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, monthCode: "M11" }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 11, "M11", "monthCode M11 with overflow constrain"); -result = cal.yearMonthFromFields({ year: 2021, monthCode: "M12" }, opt); -TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "monthCode M12 with overflow constrain"); diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-reject.js b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-reject.js deleted file mode 100644 index d0d475d9e7..0000000000 --- a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-reject.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.yearmonthfromfields -description: Throw RangeError for input data out of range with overflow reject -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. If Type(fields) is not Object, throw a TypeError exception. - 5. Set options to ? GetOptionsObject(options). - 6. Let result be ? ISOYearMonthFromFields(fields, options). - 7. Return ? CreateTemporalYearMonth(result.[[Year]], result.[[Month]], calendar, result.[[ReferenceISODay]]). -features: [Temporal] ----*/ - -const cal = new Temporal.Calendar("iso8601"); - -[-1, 0, 13, 9995].forEach((month) => { - assert.throws( - RangeError, - () => cal.yearMonthFromFields({year: 2021, month, day: 5}, { overflow: "reject" }), - `Month ${month} is out of range for 2021 with overflow: reject` - ); -}); diff --git a/test/built-ins/Temporal/Duration/compare/order-of-operations.js b/test/built-ins/Temporal/Duration/compare/order-of-operations.js index 7a1c9ac9f4..ada4887dd7 100644 --- a/test/built-ins/Temporal/Duration/compare/order-of-operations.js +++ b/test/built-ins/Temporal/Duration/compare/order-of-operations.js @@ -88,30 +88,6 @@ actual.splice(0); // clear const baseExpectedOpsWithRelativeTo = expected.concat([ // ToRelativeTemporalObject "get options.relativeTo.calendar", - "has options.relativeTo.calendar.dateAdd", - "has options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.calendar.dateUntil", - "has options.relativeTo.calendar.day", - "has options.relativeTo.calendar.dayOfWeek", - "has options.relativeTo.calendar.dayOfYear", - "has options.relativeTo.calendar.daysInMonth", - "has options.relativeTo.calendar.daysInWeek", - "has options.relativeTo.calendar.daysInYear", - "has options.relativeTo.calendar.fields", - "has options.relativeTo.calendar.id", - "has options.relativeTo.calendar.inLeapYear", - "has options.relativeTo.calendar.mergeFields", - "has options.relativeTo.calendar.month", - "has options.relativeTo.calendar.monthCode", - "has options.relativeTo.calendar.monthDayFromFields", - "has options.relativeTo.calendar.monthsInYear", - "has options.relativeTo.calendar.weekOfYear", - "has options.relativeTo.calendar.year", - "has options.relativeTo.calendar.yearMonthFromFields", - "has options.relativeTo.calendar.yearOfWeek", - "get options.relativeTo.calendar.dateFromFields", - "get options.relativeTo.calendar.fields", - "call options.relativeTo.calendar.fields", "get options.relativeTo.day", "get options.relativeTo.day.valueOf", "call options.relativeTo.day.valueOf", @@ -136,9 +112,6 @@ const expectedOpsForPlainRelativeTo = baseExpectedOpsWithRelativeTo.concat([ "get options.relativeTo.year", "get options.relativeTo.year.valueOf", "call options.relativeTo.year.valueOf", - "call options.relativeTo.calendar.dateFromFields", - // lookup in Duration.compare - "get options.relativeTo.calendar.dateAdd", ]); const plainRelativeTo = TemporalHelpers.propertyBagObserver(actual, { @@ -177,22 +150,6 @@ Temporal.Duration.compare( assert.compareArray(actual, expectedOpsForPlainRelativeTo, "order of operations with PlainDate relativeTo and no calendar units"); actual.splice(0); // clear -// code path through UnbalanceDurationRelative that balances higher units down -// to days: -const expectedOpsForPlainDayBalancing = expectedOpsForPlainRelativeTo.concat( - [ - "call options.relativeTo.calendar.dateAdd", // UnbalanceDateDurationRelative on 1st argument - "call options.relativeTo.calendar.dateAdd", // UnbalanceDateDurationRelative on 2nd argument - ] -); -Temporal.Duration.compare( - createDurationPropertyBagObserver("one", 1, 1, 1), - createDurationPropertyBagObserver("two", 1, 1, 1, 1), - createOptionsObserver(plainRelativeTo) -); -assert.compareArray(actual, expectedOpsForPlainDayBalancing, "order of operations with PlainDate relativeTo and calendar units"); -actual.splice(0); // clear - const expectedOpsForZonedRelativeTo = baseExpectedOpsWithRelativeTo.concat([ // ToRelativeTemporalObject, continued "get options.relativeTo.hour.valueOf", @@ -225,16 +182,6 @@ const expectedOpsForZonedRelativeTo = baseExpectedOpsWithRelativeTo.concat([ "get options.relativeTo.year", "get options.relativeTo.year.valueOf", "call options.relativeTo.year.valueOf", - "call options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.timeZone.getOffsetNanosecondsFor", - "has options.relativeTo.timeZone.getPossibleInstantsFor", - "has options.relativeTo.timeZone.id", - "get options.relativeTo.timeZone.getOffsetNanosecondsFor", - "get options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // lookup in Duration.compare - "get options.relativeTo.calendar.dateAdd", ]); const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, { @@ -261,13 +208,7 @@ Temporal.Duration.compare( ); assert.compareArray( actual, - expectedOpsForZonedRelativeTo.concat([ - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // AddDaysToZonedDateTime on first argument - "call options.relativeTo.timeZone.getPossibleInstantsFor", - // AddDaysToZonedDateTime on second argument - "call options.relativeTo.timeZone.getPossibleInstantsFor", - ]), + expectedOpsForZonedRelativeTo, "order of operations with ZonedDateTime relativeTo and no calendar units except days" ); actual.splice(0); // clear @@ -293,15 +234,7 @@ Temporal.Duration.compare( ); assert.compareArray( actual, - expectedOpsForZonedRelativeTo.concat([ - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // AddZonedDateTime on first argument - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - // AddZonedDateTime on second argument - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - ]), + expectedOpsForZonedRelativeTo, "order of operations with ZonedDateTime relativeTo and calendar units" ); actual.splice(0); // clear diff --git a/test/built-ins/Temporal/Duration/prototype/round/order-of-operations.js b/test/built-ins/Temporal/Duration/prototype/round/order-of-operations.js index 306656758d..8bfcb7393a 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/order-of-operations.js +++ b/test/built-ins/Temporal/Duration/prototype/round/order-of-operations.js @@ -48,30 +48,6 @@ const expectedOpsForPlainRelativeTo = [ "call options.largestUnit.toString", "get options.relativeTo", "get options.relativeTo.calendar", - "has options.relativeTo.calendar.dateAdd", - "has options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.calendar.dateUntil", - "has options.relativeTo.calendar.day", - "has options.relativeTo.calendar.dayOfWeek", - "has options.relativeTo.calendar.dayOfYear", - "has options.relativeTo.calendar.daysInMonth", - "has options.relativeTo.calendar.daysInWeek", - "has options.relativeTo.calendar.daysInYear", - "has options.relativeTo.calendar.fields", - "has options.relativeTo.calendar.id", - "has options.relativeTo.calendar.inLeapYear", - "has options.relativeTo.calendar.mergeFields", - "has options.relativeTo.calendar.month", - "has options.relativeTo.calendar.monthCode", - "has options.relativeTo.calendar.monthDayFromFields", - "has options.relativeTo.calendar.monthsInYear", - "has options.relativeTo.calendar.weekOfYear", - "has options.relativeTo.calendar.year", - "has options.relativeTo.calendar.yearMonthFromFields", - "has options.relativeTo.calendar.yearOfWeek", - "get options.relativeTo.calendar.dateFromFields", - "get options.relativeTo.calendar.fields", - "call options.relativeTo.calendar.fields", "get options.relativeTo.day", "get options.relativeTo.day.valueOf", "call options.relativeTo.day.valueOf", @@ -92,7 +68,6 @@ const expectedOpsForPlainRelativeTo = [ "get options.relativeTo.year", "get options.relativeTo.year.valueOf", "call options.relativeTo.year.valueOf", - "call options.relativeTo.calendar.dateFromFields", "get options.roundingIncrement", "get options.roundingIncrement.valueOf", "call options.roundingIncrement.valueOf", @@ -102,9 +77,6 @@ const expectedOpsForPlainRelativeTo = [ "get options.smallestUnit", "get options.smallestUnit.toString", "call options.smallestUnit.toString", - // lookup in Duration.p.round - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", ]; const plainRelativeTo = TemporalHelpers.propertyBagObserver(actual, { @@ -120,135 +92,12 @@ instance.round(createOptionsObserver({ relativeTo: plainRelativeTo })); assert.compareArray(actual, expectedOpsForPlainRelativeTo, "order of operations for PlainDate relativeTo"); actual.splice(0); // clear -// code path through RoundDuration that rounds to the nearest year, with minimal calendar calls: -const expectedMinimalOpsForYearRounding = expectedOpsForPlainRelativeTo.concat([ - // initial AddDate in Duration.p.round 39.c not called because no calendar units - "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime - "call options.relativeTo.calendar.dateAdd", -]); -const instanceMinimal = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 100); -instanceMinimal.round(createOptionsObserver({ smallestUnit: "years", relativeTo: plainRelativeTo })); -assert.compareArray(actual, expectedMinimalOpsForYearRounding, "order of operations with years = 0 and smallestUnit = years"); -actual.splice(0); // clear - -// code path through Duration.prototype.round that rounds to the nearest year: -const expectedOpsForYearRounding = expectedOpsForPlainRelativeTo.concat([ - "call options.relativeTo.calendar.dateAdd", // 39.c - "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime - // RoundRelativeDuration - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateAdd", -]); -const instanceYears = new Temporal.Duration(1, 12, 0, 0, /* hours = */ 2400); -instanceYears.round(createOptionsObserver({ smallestUnit: "years", relativeTo: plainRelativeTo })); -assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years"); -actual.splice(0); // clear - -// code path through Duration.prototype.round that rounds to the nearest month: -const expectedOpsForMonthRounding = expectedOpsForPlainRelativeTo.concat([ - "call options.relativeTo.calendar.dateAdd", // 39.c - "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime - // RoundRelativeDuration - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateAdd", -]); -const instance2 = new Temporal.Duration(1, 0, 0, 62); -instance2.round(createOptionsObserver({ largestUnit: "months", smallestUnit: "months", relativeTo: plainRelativeTo })); -assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with largestUnit = smallestUnit = months"); -actual.splice(0); // clear - -// code path through Duration.prototype.round that rounds to the nearest week: -const expectedOpsForWeekRounding = expectedOpsForPlainRelativeTo.concat([ - "call options.relativeTo.calendar.dateAdd", // 39.c - "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime - // RoundRelativeDuration - "call options.relativeTo.calendar.dateUntil", - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateAdd", -]); -const instance3 = new Temporal.Duration(1, 1, 0, 15); -instance3.round(createOptionsObserver({ largestUnit: "weeks", smallestUnit: "weeks", relativeTo: plainRelativeTo })); -assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with largestUnit = smallestUnit = weeks"); -actual.splice(0); // clear - -// code path through Duration.prototype.round that rounds to the nearest day: -const expectedOpsForDayRounding = expectedOpsForPlainRelativeTo.concat([ - "call options.relativeTo.calendar.dateAdd", // 39.c -]); -const instance4 = new Temporal.Duration(1, 1, 1) -instance4.round(createOptionsObserver({ largestUnit: "days", smallestUnit: "days", relativeTo: plainRelativeTo })); -assert.compareArray(actual, expectedOpsForDayRounding, "order of operations with largestUnit = smallestUnit = days"); -actual.splice(0); // clear - -// code path through BalanceDateDurationRelative balancing from days up to years: -const expectedOpsForDayToYearBalancing = expectedOpsForPlainRelativeTo.concat([ - "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime - "call options.relativeTo.calendar.dateAdd", -]); -const instance5 = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 396 * 24); -instance5.round(createOptionsObserver({ largestUnit: "years", smallestUnit: "days", relativeTo: plainRelativeTo })); -assert.compareArray(actual, expectedOpsForDayToYearBalancing, "order of operations with largestUnit = years, smallestUnit = days"); -actual.splice(0); // clear - -// code path through Duration.prototype.round balancing from months up to years: -const expectedOpsForMonthToYearBalancing = expectedOpsForPlainRelativeTo.concat([ - "call options.relativeTo.calendar.dateAdd", // 39.c - "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime - // RoundRelativeDuration - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateAdd", -]); -const instance6 = new Temporal.Duration(0, 12); -instance6.round(createOptionsObserver({ largestUnit: "years", smallestUnit: "months", relativeTo: plainRelativeTo })); -assert.compareArray(actual, expectedOpsForMonthToYearBalancing, "order of operations with largestUnit = years, smallestUnit = months"); -actual.splice(0); // clear - -const expectedOpsForDayToMonthBalancing = expectedOpsForPlainRelativeTo.concat([ - "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime -]); -const instance7 = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 32 * 24); -instance7.round(createOptionsObserver({ largestUnit: "months", smallestUnit: "days", relativeTo: plainRelativeTo })); -assert.compareArray(actual, expectedOpsForDayToMonthBalancing, "order of operations with largestUnit = months, smallestUnit = days"); -actual.splice(0); // clear - -const expectedOpsForDayToWeekBalancing = expectedOpsForPlainRelativeTo.concat([ - "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime -]); -const instance8 = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 8 * 24); -instance8.round(createOptionsObserver({ largestUnit: "weeks", smallestUnit: "days", relativeTo: plainRelativeTo })); -assert.compareArray(actual, expectedOpsForDayToWeekBalancing, "order of operations with largestUnit = weeks, smallestUnit = days"); -actual.splice(0); // clear - const expectedOpsForZonedRelativeTo = [ "get options.largestUnit", "get options.largestUnit.toString", "call options.largestUnit.toString", "get options.relativeTo", "get options.relativeTo.calendar", - "has options.relativeTo.calendar.dateAdd", - "has options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.calendar.dateUntil", - "has options.relativeTo.calendar.day", - "has options.relativeTo.calendar.dayOfWeek", - "has options.relativeTo.calendar.dayOfYear", - "has options.relativeTo.calendar.daysInMonth", - "has options.relativeTo.calendar.daysInWeek", - "has options.relativeTo.calendar.daysInYear", - "has options.relativeTo.calendar.fields", - "has options.relativeTo.calendar.id", - "has options.relativeTo.calendar.inLeapYear", - "has options.relativeTo.calendar.mergeFields", - "has options.relativeTo.calendar.month", - "has options.relativeTo.calendar.monthCode", - "has options.relativeTo.calendar.monthDayFromFields", - "has options.relativeTo.calendar.monthsInYear", - "has options.relativeTo.calendar.weekOfYear", - "has options.relativeTo.calendar.year", - "has options.relativeTo.calendar.yearMonthFromFields", - "has options.relativeTo.calendar.yearOfWeek", - "get options.relativeTo.calendar.dateFromFields", - "get options.relativeTo.calendar.fields", - "call options.relativeTo.calendar.fields", "get options.relativeTo.day", "get options.relativeTo.day.valueOf", "call options.relativeTo.day.valueOf", @@ -283,15 +132,6 @@ const expectedOpsForZonedRelativeTo = [ "get options.relativeTo.year", "get options.relativeTo.year.valueOf", "call options.relativeTo.year.valueOf", - "call options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.timeZone.getOffsetNanosecondsFor", - "has options.relativeTo.timeZone.getPossibleInstantsFor", - "has options.relativeTo.timeZone.id", - "get options.relativeTo.timeZone.getOffsetNanosecondsFor", - "get options.relativeTo.timeZone.getPossibleInstantsFor", - // InterpretISODateTimeOffset - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", "get options.roundingIncrement", "get options.roundingIncrement.valueOf", "call options.roundingIncrement.valueOf", @@ -321,120 +161,5 @@ const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, { // basic order of operations with ZonedDateTime relativeTo: instance.round(createOptionsObserver({ relativeTo: zonedRelativeTo })); -assert.compareArray(actual, expectedOpsForZonedRelativeTo.concat([ - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", -]), "order of operations for ZonedDateTime relativeTo"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest year with minimal calendar operations: -const expectedOpsForMinimalYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([ - // ToTemporalDate - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // lookup in Duration.p.round - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", - // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 - "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c - "call options.relativeTo.calendar.dateUntil", // 13.f - // RoundRelativeDuration - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getPossibleInstantsFor", -]); -instance.round(createOptionsObserver({ smallestUnit: "years", relativeTo: zonedRelativeTo })); -assert.compareArray( - actual, - expectedOpsForMinimalYearRoundingZoned, - "order of operations with years = 0, smallestUnit = years and ZonedDateTime relativeTo" -); -actual.splice(0); // clear - -// code path through Duration.p.round that rounds to the nearest year: -const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([ - // ToTemporalDate - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // lookup in Duration.p.round - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", - // AddZonedDateTime - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 - "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c - "call options.relativeTo.calendar.dateUntil", // 13.f - // RoundRelativeDuration - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getPossibleInstantsFor", -]); -instanceYears.round(createOptionsObserver({ smallestUnit: "years", relativeTo: zonedRelativeTo })); -assert.compareArray( - actual, - expectedOpsForYearRoundingZoned, - "order of operations with smallestUnit = years and ZonedDateTime relativeTo" -); -actual.splice(0); // clear - -// code path that hits the special weeks/years case in BalanceDateDurationRelative -const expectedOpsForYearsWeeksSpecialCase = expectedOpsForZonedRelativeTo.concat([ - // ToTemporalDate - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // lookup in Duration.p.round - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", - // No user code calls in UnbalanceDateDurationRelative - // RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor - // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 - "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c - "call options.relativeTo.calendar.dateUntil", // 13.f - // RoundRelativeDuration - "call options.relativeTo.calendar.dateUntil", - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getPossibleInstantsFor", -]); -new Temporal.Duration(0, 1, 1).round(createOptionsObserver({ largestUnit: "years", smallestUnit: "weeks", relativeTo: zonedRelativeTo })); -assert.compareArray( - actual, - expectedOpsForYearsWeeksSpecialCase, - "order of operations with largestUnit = years, smallestUnit = weeks, and ZonedDateTime relativeTo" -); -actual.splice(0); // clear - -// code path that skips user code calls in BalanceDateDurationRelative due to -// special case for largestUnit months and smallestUnit weeks -const expectedOpsForMonthsWeeksSpecialCase = expectedOpsForZonedRelativeTo.concat([ - // ToTemporalDate - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // lookup in Duration.p.round - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", - // RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor - // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 - "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c - "call options.relativeTo.calendar.dateUntil", // 13.f - // RoundRelativeDuration - "call options.relativeTo.calendar.dateUntil", - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getPossibleInstantsFor", -]); -new Temporal.Duration(0, 1, 1).round(createOptionsObserver({ largestUnit: "months", smallestUnit: "weeks", relativeTo: zonedRelativeTo })); -assert.compareArray( - actual, - expectedOpsForMonthsWeeksSpecialCase, - "order of operations with largestUnit = months, smallestUnit = weeks, and ZonedDateTime relativeTo" -); +assert.compareArray(actual, expectedOpsForZonedRelativeTo, "order of operations for ZonedDateTime relativeTo"); actual.splice(0); // clear diff --git a/test/built-ins/Temporal/Duration/prototype/total/order-of-operations.js b/test/built-ins/Temporal/Duration/prototype/total/order-of-operations.js index f4bb5d120b..dca60bca6a 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/order-of-operations.js +++ b/test/built-ins/Temporal/Duration/prototype/total/order-of-operations.js @@ -36,30 +36,6 @@ const expectedOpsForPlainRelativeTo = [ // ToRelativeTemporalObject "get options.relativeTo", "get options.relativeTo.calendar", - "has options.relativeTo.calendar.dateAdd", - "has options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.calendar.dateUntil", - "has options.relativeTo.calendar.day", - "has options.relativeTo.calendar.dayOfWeek", - "has options.relativeTo.calendar.dayOfYear", - "has options.relativeTo.calendar.daysInMonth", - "has options.relativeTo.calendar.daysInWeek", - "has options.relativeTo.calendar.daysInYear", - "has options.relativeTo.calendar.fields", - "has options.relativeTo.calendar.id", - "has options.relativeTo.calendar.inLeapYear", - "has options.relativeTo.calendar.mergeFields", - "has options.relativeTo.calendar.month", - "has options.relativeTo.calendar.monthCode", - "has options.relativeTo.calendar.monthDayFromFields", - "has options.relativeTo.calendar.monthsInYear", - "has options.relativeTo.calendar.weekOfYear", - "has options.relativeTo.calendar.year", - "has options.relativeTo.calendar.yearMonthFromFields", - "has options.relativeTo.calendar.yearOfWeek", - "get options.relativeTo.calendar.dateFromFields", - "get options.relativeTo.calendar.fields", - "call options.relativeTo.calendar.fields", "get options.relativeTo.day", "get options.relativeTo.day.valueOf", "call options.relativeTo.day.valueOf", @@ -80,14 +56,10 @@ const expectedOpsForPlainRelativeTo = [ "get options.relativeTo.year", "get options.relativeTo.year.valueOf", "call options.relativeTo.year.valueOf", - "call options.relativeTo.calendar.dateFromFields", // GetTemporalUnit "get options.unit", "get options.unit.toString", "call options.unit.toString", - // lookup in Duration.p.total - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", ]; const plainRelativeTo = TemporalHelpers.propertyBagObserver(actual, { @@ -103,96 +75,10 @@ instance.total(createOptionsObserver({ unit: "nanoseconds", relativeTo: plainRel assert.compareArray(actual, expectedOpsForPlainRelativeTo, "order of operations for PlainDate relativeTo"); actual.splice(0); // clear -// code path through RoundDuration that rounds to the nearest year with minimal calendar calls: -const expectedOpsForMinimalYearRounding = expectedOpsForPlainRelativeTo.concat([ - // DifferencePlainDateTimeWithRounding -> DifferenceISODateTime - "call options.relativeTo.calendar.dateUntil", - "call options.relativeTo.calendar.dateAdd", -]); -instance.total(createOptionsObserver({ unit: "years", relativeTo: plainRelativeTo })); -assert.compareArray(actual, expectedOpsForMinimalYearRounding, "order of operations with years = 0 and unit = years"); -actual.splice(0); // clear - -// code path through Duration.p.total that rounds to the nearest year: -const expectedOpsForYearRounding = expectedOpsForPlainRelativeTo.concat([ - "call options.relativeTo.calendar.dateAdd", // Duration.p.total 19.c - // DifferencePlainDateTimeWithRounding - "call options.relativeTo.calendar.dateUntil", // 5 - // RoundRelativeDuration - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateAdd", -]); -const instanceYears = new Temporal.Duration(1, 12, 0, 0, /* hours = */ 2400); -instanceYears.total(createOptionsObserver({ unit: "years", relativeTo: plainRelativeTo })); -assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with unit = years"); -actual.splice(0); // clear - -// code path through Duration.prototype.total that rounds to the nearest month: -const expectedOpsForMonthRounding = expectedOpsForPlainRelativeTo.concat([ - "call options.relativeTo.calendar.dateAdd", // Duration.p.total 19.c - // DifferencePlainDateTimeWithRounding - "call options.relativeTo.calendar.dateUntil", // 5 - // RoundRelativeDuration - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateAdd", -]); -const instance2 = new Temporal.Duration(1, 0, 0, 62); -instance2.total(createOptionsObserver({ unit: "months", relativeTo: plainRelativeTo })); -assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with unit = months"); -actual.splice(0); // clear - -// code path through Duration.prototype.total that rounds to the nearest week: -const expectedOpsForWeekRounding = expectedOpsForPlainRelativeTo.concat([ - "call options.relativeTo.calendar.dateAdd", // Duration.p.total 19.c - // DifferencePlainDateTimeWithRounding - "call options.relativeTo.calendar.dateUntil", // 5 - // RoundRelativeDuration - "call options.relativeTo.calendar.dateUntil", - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateAdd", -]); -const instance3 = new Temporal.Duration(1, 1, 0, 15); -instance3.total(createOptionsObserver({ unit: "weeks", relativeTo: plainRelativeTo })); -assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with unit = weeks"); -actual.splice(0); // clear - -// code path through UnbalanceDateDurationRelative that rounds to the nearest day: -const expectedOpsForDayRounding = expectedOpsForPlainRelativeTo.concat([ - "call options.relativeTo.calendar.dateAdd", // 10 -]); -const instance4 = new Temporal.Duration(1, 1, 1) -instance4.total(createOptionsObserver({ unit: "days", relativeTo: plainRelativeTo })); -assert.compareArray(actual, expectedOpsForDayRounding, "order of operations with unit = days"); -actual.splice(0); // clear - const expectedOpsForZonedRelativeTo = [ // ToRelativeTemporalObject "get options.relativeTo", "get options.relativeTo.calendar", - "has options.relativeTo.calendar.dateAdd", - "has options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.calendar.dateUntil", - "has options.relativeTo.calendar.day", - "has options.relativeTo.calendar.dayOfWeek", - "has options.relativeTo.calendar.dayOfYear", - "has options.relativeTo.calendar.daysInMonth", - "has options.relativeTo.calendar.daysInWeek", - "has options.relativeTo.calendar.daysInYear", - "has options.relativeTo.calendar.fields", - "has options.relativeTo.calendar.id", - "has options.relativeTo.calendar.inLeapYear", - "has options.relativeTo.calendar.mergeFields", - "has options.relativeTo.calendar.month", - "has options.relativeTo.calendar.monthCode", - "has options.relativeTo.calendar.monthDayFromFields", - "has options.relativeTo.calendar.monthsInYear", - "has options.relativeTo.calendar.weekOfYear", - "has options.relativeTo.calendar.year", - "has options.relativeTo.calendar.yearMonthFromFields", - "has options.relativeTo.calendar.yearOfWeek", - "get options.relativeTo.calendar.dateFromFields", - "get options.relativeTo.calendar.fields", - "call options.relativeTo.calendar.fields", "get options.relativeTo.day", "get options.relativeTo.day.valueOf", "call options.relativeTo.day.valueOf", @@ -227,15 +113,6 @@ const expectedOpsForZonedRelativeTo = [ "get options.relativeTo.year", "get options.relativeTo.year.valueOf", "call options.relativeTo.year.valueOf", - "call options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.timeZone.getOffsetNanosecondsFor", - "has options.relativeTo.timeZone.getPossibleInstantsFor", - "has options.relativeTo.timeZone.id", - "get options.relativeTo.timeZone.getOffsetNanosecondsFor", - "get options.relativeTo.timeZone.getPossibleInstantsFor", - // InterpretISODateTimeOffset - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // GetTemporalUnit "get options.unit", "get options.unit.toString", @@ -260,117 +137,5 @@ const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, { // basic order of observable operations, without rounding: instance.total(createOptionsObserver({ unit: "nanoseconds", relativeTo: zonedRelativeTo })); -assert.compareArray(actual, expectedOpsForZonedRelativeTo.concat([ - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", -]), "order of operations for ZonedDateTime relativeTo"); +assert.compareArray(actual, expectedOpsForZonedRelativeTo, "order of operations for ZonedDateTime relativeTo"); actual.splice(0); // clear - -// code path through Duration.p.total that rounds to the nearest year with -// minimal calendar operations: -const expectedOpsForMinimalYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([ - // ToTemporalDate - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // lookup in Duration.p.total - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", - // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 - "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c - "call options.relativeTo.calendar.dateUntil", // 13.f - // RoundRelativeDuration - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getPossibleInstantsFor", -]); -instance.total(createOptionsObserver({ unit: "years", relativeTo: zonedRelativeTo })); -assert.compareArray( - actual, - expectedOpsForMinimalYearRoundingZoned, - "order of operations with years = 0, unit = years and ZonedDateTime relativeTo" -); -actual.splice(0); // clear - -// code path through Duration.p.total that rounds to years: -const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([ - // ToTemporalDate - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // lookup in Duration.p.total - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", - // 18.c AddZonedDateTime - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor - // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 - "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c - "call options.relativeTo.calendar.dateUntil", // 13.f - // RoundRelativeDuration - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getPossibleInstantsFor", -]); -instanceYears.total(createOptionsObserver({ unit: "years", relativeTo: zonedRelativeTo })); -assert.compareArray( - actual, - expectedOpsForYearRoundingZoned, - "order of operations with unit = years and ZonedDateTime relativeTo" -); -actual.splice(0); // clear - -// code path through Duration.p.total that rounds to months: -const expectedOpsForMonthsRoundingZoned = expectedOpsForZonedRelativeTo.concat([ - // ToTemporalDate - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // lookup in Duration.p.total - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", - // 18.c AddZonedDateTime - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor - // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 - "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c - "call options.relativeTo.calendar.dateUntil", // 13.f - // RoundRelativeDuration - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getPossibleInstantsFor", -]); -new Temporal.Duration(0, 1, 1).total(createOptionsObserver({ unit: "months", relativeTo: zonedRelativeTo })); -assert.compareArray( - actual, - expectedOpsForMonthsRoundingZoned, - "order of operations with unit = months and ZonedDateTime relativeTo" -); -actual.splice(0); // clear - -// code path through Duration.p.total that rounds to weeks: -const expectedOpsForWeeksRoundingZoned = expectedOpsForZonedRelativeTo.concat([ - // ToTemporalDate - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // lookup in Duration.p.total - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", - // 18.c AddZonedDateTime - "call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor - // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 - "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c - "call options.relativeTo.calendar.dateUntil", // 13.f - // RoundRelativeDuration - "call options.relativeTo.calendar.dateUntil", - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getPossibleInstantsFor", -]); -new Temporal.Duration(0, 0, 0, 1, 240).total(createOptionsObserver({ unit: "weeks", relativeTo: zonedRelativeTo })); -assert.compareArray( - actual, - expectedOpsForWeeksRoundingZoned, - "order of operations with unit = weeks and no calendar units" -); -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/Instant/prototype/since/order-of-operations.js b/test/built-ins/Temporal/Instant/prototype/since/order-of-operations.js index ab293f45f2..6065fa9a3c 100644 --- a/test/built-ins/Temporal/Instant/prototype/since/order-of-operations.js +++ b/test/built-ins/Temporal/Instant/prototype/since/order-of-operations.js @@ -11,23 +11,16 @@ features: [Temporal] const expected = [ "get other.toString", "call other.toString", - "ownKeys options", - "getOwnPropertyDescriptor options.roundingIncrement", - "get options.roundingIncrement", - "getOwnPropertyDescriptor options.roundingMode", - "get options.roundingMode", - "getOwnPropertyDescriptor options.largestUnit", "get options.largestUnit", - "getOwnPropertyDescriptor options.smallestUnit", - "get options.smallestUnit", - "getOwnPropertyDescriptor options.additional", - "get options.additional", "get options.largestUnit.toString", "call options.largestUnit.toString", + "get options.roundingIncrement", "get options.roundingIncrement.valueOf", "call options.roundingIncrement.valueOf", + "get options.roundingMode", "get options.roundingMode.toString", "call options.roundingMode.toString", + "get options.smallestUnit", "get options.smallestUnit.toString", "call options.smallestUnit.toString", ]; diff --git a/test/built-ins/Temporal/Instant/prototype/toString/order-of-operations.js b/test/built-ins/Temporal/Instant/prototype/toString/order-of-operations.js index 9eef8b2ca8..7c64f8cb48 100644 --- a/test/built-ins/Temporal/Instant/prototype/toString/order-of-operations.js +++ b/test/built-ins/Temporal/Instant/prototype/toString/order-of-operations.js @@ -19,11 +19,6 @@ const expected = [ "get options.smallestUnit.toString", "call options.smallestUnit.toString", "get options.timeZone", - "has options.timeZone.getOffsetNanosecondsFor", - "has options.timeZone.getPossibleInstantsFor", - "has options.timeZone.id", - "get options.timeZone.getOffsetNanosecondsFor", - "call options.timeZone.getOffsetNanosecondsFor", ]; const actual = []; diff --git a/test/built-ins/Temporal/Instant/prototype/until/order-of-operations.js b/test/built-ins/Temporal/Instant/prototype/until/order-of-operations.js index 61b77fbcbb..152672007b 100644 --- a/test/built-ins/Temporal/Instant/prototype/until/order-of-operations.js +++ b/test/built-ins/Temporal/Instant/prototype/until/order-of-operations.js @@ -11,23 +11,16 @@ features: [Temporal] const expected = [ "get other.toString", "call other.toString", - "ownKeys options", - "getOwnPropertyDescriptor options.roundingIncrement", - "get options.roundingIncrement", - "getOwnPropertyDescriptor options.roundingMode", - "get options.roundingMode", - "getOwnPropertyDescriptor options.largestUnit", "get options.largestUnit", - "getOwnPropertyDescriptor options.smallestUnit", - "get options.smallestUnit", - "getOwnPropertyDescriptor options.additional", - "get options.additional", "get options.largestUnit.toString", "call options.largestUnit.toString", + "get options.roundingIncrement", "get options.roundingIncrement.valueOf", "call options.roundingIncrement.valueOf", + "get options.roundingMode", "get options.roundingMode.toString", "call options.roundingMode.toString", + "get options.smallestUnit", "get options.smallestUnit.toString", "call options.smallestUnit.toString", ]; diff --git a/test/built-ins/Temporal/Now/plainTimeISO/toPlainTime-override.js b/test/built-ins/Temporal/Now/plainTimeISO/toPlainTime-override.js index 7411562060..22a0390df2 100644 --- a/test/built-ins/Temporal/Now/plainTimeISO/toPlainTime-override.js +++ b/test/built-ins/Temporal/Now/plainTimeISO/toPlainTime-override.js @@ -4,18 +4,12 @@ /*--- esid: sec-temporal.now.plaintimeiso description: PlainDateTime.toPlainTime is not observably called -includes: [compareArray.js, temporalHelpers.js] +includes: [compareArray.js] features: [Temporal] ---*/ const actual = []; -const expected = [ - "has timeZone.getOffsetNanosecondsFor", - "has timeZone.getPossibleInstantsFor", - "has timeZone.id", - "get timeZone.getOffsetNanosecondsFor", - "call timeZone.getOffsetNanosecondsFor", -]; +const expected = []; Object.defineProperty(Temporal.PlainDateTime.prototype, "toPlainTime", { get() { @@ -26,17 +20,7 @@ Object.defineProperty(Temporal.PlainDateTime.prototype, "toPlainTime", { }, }); -const timeZone = TemporalHelpers.timeZoneObserver(actual, "timeZone", { - getOffsetNanosecondsFor(instant) { - assert.sameValue(instant instanceof Temporal.Instant, true, "Instant"); - return -Number(instant.epochNanoseconds % 86400_000_000_000n); - }, -}); - -const result = Temporal.Now.plainTimeISO(timeZone); +const result = Temporal.Now.plainTimeISO("UTC"); assert.sameValue(result instanceof Temporal.PlainTime, true); -for (const property of ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"]) { - assert.sameValue(result[property], 0, property); -} assert.compareArray(actual, expected); diff --git a/test/built-ins/Temporal/PlainDate/compare/calendar.js b/test/built-ins/Temporal/PlainDate/compare/calendar.js deleted file mode 100644 index 250bffa98c..0000000000 --- a/test/built-ins/Temporal/PlainDate/compare/calendar.js +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.plaindate.compare -description: basic tests -features: [Temporal] ----*/ - -class CalendarTraceToString extends Temporal.Calendar { - constructor(id) { - super("iso8601"); - this.id_ = id; - this.calls = 0; - } - toString() { - ++this.calls; - return this.id_; - } -}; - -const calendar1 = new CalendarTraceToString("a"); -const date1 = new Temporal.PlainDate(1914, 2, 23, calendar1); - -const calendar2 = new CalendarTraceToString("a"); -const date2 = new Temporal.PlainDate(1914, 2, 23, calendar2); - -const calendar3 = new CalendarTraceToString("b"); -const date3 = new Temporal.PlainDate(1914, 2, 23, calendar3); - -assert.sameValue(Temporal.PlainDate.compare(date1, date1), 0, "same object"); -assert.sameValue(Temporal.PlainDate.compare(date1, date2), 0, "same date"); -assert.sameValue(Temporal.PlainDate.compare(date1, date3), 0, "same date, different calendar"); - -assert.sameValue(calendar1.calls, 0, "calendar1 toString() calls"); -assert.sameValue(calendar2.calls, 0, "calendar2 toString() calls"); -assert.sameValue(calendar3.calls, 0, "calendar3 toString() calls"); diff --git a/test/built-ins/Temporal/PlainDate/compare/exhaustive.js b/test/built-ins/Temporal/PlainDate/compare/exhaustive.js index acce9f7169..9a0eab177a 100644 --- a/test/built-ins/Temporal/PlainDate/compare/exhaustive.js +++ b/test/built-ins/Temporal/PlainDate/compare/exhaustive.js @@ -8,7 +8,7 @@ features: [Temporal] ---*/ const cal1 = "iso8601"; -const cal2 = new (class extends Temporal.Calendar { id = "custom"; })("iso8601"); +const cal2 = "gregory"; assert.sameValue( Temporal.PlainDate.compare( diff --git a/test/built-ins/Temporal/PlainDate/compare/not-same-object.js b/test/built-ins/Temporal/PlainDate/compare/not-same-object.js new file mode 100644 index 0000000000..0ddb8b98c6 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/compare/not-same-object.js @@ -0,0 +1,14 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.compare +description: Dates are equal even if they are not the same object +features: [Temporal] +---*/ + +const date1 = new Temporal.PlainDate(1914, 2, 23); +const date2 = new Temporal.PlainDate(1914, 2, 23); + +assert.sameValue(Temporal.PlainDate.compare(date1, date1), 0, "same object"); +assert.sameValue(Temporal.PlainDate.compare(date1, date2), 0, "same date"); diff --git a/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-primitive.js b/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-primitive.js index e1dcc6795f..d17e3269ed 100644 --- a/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-primitive.js +++ b/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-primitive.js @@ -9,8 +9,6 @@ features: [Temporal] ---*/ const expected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", @@ -25,9 +23,9 @@ TemporalHelpers.assertPlainDate(result, 2021, 5, "M05", 17); actual.splice(0); // empty it for the next check const failureExpected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", + "get options.overflow.toString", + "call options.overflow.toString", ]; assert.throws(TypeError, () => Temporal.PlainDate.from(7, options)); diff --git a/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string-invalid.js b/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string-invalid.js index f3789e814d..b5fc45c02a 100644 --- a/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string-invalid.js +++ b/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string-invalid.js @@ -9,9 +9,9 @@ features: [Temporal] ---*/ const expected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", + "get options.overflow.toString", + "call options.overflow.toString", ]; let actual = []; diff --git a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/one-of-era-erayear-undefined.js b/test/built-ins/Temporal/PlainDate/from/one-of-era-erayear-undefined.js similarity index 58% rename from test/built-ins/Temporal/Calendar/prototype/dateFromFields/one-of-era-erayear-undefined.js rename to test/built-ins/Temporal/PlainDate/from/one-of-era-erayear-undefined.js index 4d36b89c81..1ce0e936a3 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/one-of-era-erayear-undefined.js +++ b/test/built-ins/Temporal/PlainDate/from/one-of-era-erayear-undefined.js @@ -2,15 +2,14 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.datefromfields +esid: sec-temporal.plaindate.from description: Does not throw a RangeError if only one of era/eraYear fields is present features: [Temporal] includes: [temporalHelpers.js] ---*/ const base = { year: 2000, month: 5, day: 2, era: 'ce' }; -const instance = new Temporal.Calendar('iso8601'); -TemporalHelpers.assertPlainDate(instance.dateFromFields({ ...base }), 2000, 5, 'M05', 2); +TemporalHelpers.assertPlainDate(Temporal.PlainDate.from(base), 2000, 5, 'M05', 2); const base2 = { year: 2000, month: 5, day: 2, eraYear: 1 }; -TemporalHelpers.assertPlainDate(instance.dateFromFields({ ...base }), 2000, 5, 'M05', 2); +TemporalHelpers.assertPlainDate(Temporal.PlainDate.from(base2), 2000, 5, 'M05', 2); diff --git a/test/built-ins/Temporal/PlainDate/from/order-of-operations.js b/test/built-ins/Temporal/PlainDate/from/order-of-operations.js index 1c85479d04..257bfda34a 100644 --- a/test/built-ins/Temporal/PlainDate/from/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDate/from/order-of-operations.js @@ -9,36 +9,10 @@ features: [Temporal] ---*/ const expected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", - "getOwnPropertyDescriptor options.extra", - "get options.extra", + "get options.overflow.toString", + "call options.overflow.toString", "get fields.calendar", - "has fields.calendar.dateAdd", - "has fields.calendar.dateFromFields", - "has fields.calendar.dateUntil", - "has fields.calendar.day", - "has fields.calendar.dayOfWeek", - "has fields.calendar.dayOfYear", - "has fields.calendar.daysInMonth", - "has fields.calendar.daysInWeek", - "has fields.calendar.daysInYear", - "has fields.calendar.fields", - "has fields.calendar.id", - "has fields.calendar.inLeapYear", - "has fields.calendar.mergeFields", - "has fields.calendar.month", - "has fields.calendar.monthCode", - "has fields.calendar.monthDayFromFields", - "has fields.calendar.monthsInYear", - "has fields.calendar.weekOfYear", - "has fields.calendar.year", - "has fields.calendar.yearMonthFromFields", - "has fields.calendar.yearOfWeek", - "get fields.calendar.dateFromFields", - "get fields.calendar.fields", - "call fields.calendar.fields", "get fields.day", "get fields.day.valueOf", "call fields.day.valueOf", @@ -51,10 +25,6 @@ const expected = [ "get fields.year", "get fields.year.valueOf", "call fields.year.valueOf", - "call fields.calendar.dateFromFields", - // inside Calendar.p.dateFromFields - "get options.overflow.toString", - "call options.overflow.toString", ]; const actual = []; diff --git a/test/built-ins/Temporal/PlainDate/from/out-of-range.js b/test/built-ins/Temporal/PlainDate/from/out-of-range.js new file mode 100644 index 0000000000..e15d330cf7 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/from/out-of-range.js @@ -0,0 +1,88 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.plaindate.from +description: Should throw RangeError for input not in valid range. +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 3. Assert: calendar.[[Identifier]] is "iso8601". + 4. If Type(fields) is not Object, throw a TypeError exception. + 5. Set options to ? GetOptionsObject(options). + 6. Let result be ? ISODateFromFields(fields, options). + 7. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], calendar). +features: [Temporal, arrow-function] +---*/ + +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, monthCode: "m1", day: 17})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, monthCode: "M1", day: 17})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, monthCode: "m01", day: 17})); + +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, month: 12, monthCode: "M11", day: 17})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, monthCode: "M00", day: 17})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, monthCode: "M19", day: 17})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, monthCode: "M99", day: 17})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, monthCode: "M13", day: 17})); + +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, month: -1, day: 17})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, month: -Infinity, day: 17})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, month: 7, day: -17})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, month: 7, day: -Infinity})); + +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, month: 12, day: 0}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, month: 12, day: 32}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, month: 1, day: 32}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, month: 2, day: 29}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, month: 6, day: 31}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, month: 9, day: 31}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, month: 0, day: 5}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from({year: 2021, month: 13, day: 5}, {overflow: "reject"})); + +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, monthCode: "M12", day: 0}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, monthCode: "M12", day: 32}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, monthCode: "M01", day: 32}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, monthCode: "M02", day: 29}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, monthCode: "M06", day: 31}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, monthCode: "M09", day: 31}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, monthCode: "M00", day: 5}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, monthCode: "M13", day: 5}, {overflow: "reject"})); + +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, month: 12, day: 0})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, month: 0, day: 3})); + +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, month: 1, day: 32}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, month: 2, day: 29}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, month: 3, day: 32}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, month: 4, day: 31}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, month: 5, day: 32}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, month: 6, day: 31}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, month: 7, day: 32}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, month: 8, day: 32}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, month: 9, day: 31}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, month: 10, day: 32}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, month: 11, day: 31}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, month: 12, day: 32}, {overflow: "reject"})); +assert.throws(RangeError, () => Temporal.PlainDate.from( + {year: 2021, month: 13, day: 5}, {overflow: "reject"})); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-month-day-need-constrain.js b/test/built-ins/Temporal/PlainDate/from/with-year-month-day-need-constrain.js similarity index 69% rename from test/built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-month-day-need-constrain.js rename to test/built-ins/Temporal/PlainDate/from/with-year-month-day-need-constrain.js index 223c9f42f2..320e96e52c 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-month-day-need-constrain.js +++ b/test/built-ins/Temporal/PlainDate/from/with-year-month-day-need-constrain.js @@ -1,8 +1,8 @@ // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.datefromfields -description: Temporal.Calendar.prototype.dateFromFields with year/month/day and need constrain +esid: sec-temporal.plaindate.from +description: Property bag with year/month/day and need constrain info: | 1. Let calendar be the this value. 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). @@ -14,74 +14,73 @@ info: | features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601") TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, month: 1, day: 133}), + Temporal.PlainDate.from({year: 2021, month: 1, day: 133}), 2021, 1, "M01", 31, "year/month/day with day need to be constrained in Jan"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, month: 2, day: 133}), + Temporal.PlainDate.from({year: 2021, month: 2, day: 133}), 2021, 2, "M02", 28, "year/month/day with day need to be constrained in Feb"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, month: 3, day: 133}), + Temporal.PlainDate.from({year: 2021, month: 3, day: 133}), 2021, 3, "M03", 31, "year/month/day with day need to be constrained in March"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, month: 4, day: 133}), + Temporal.PlainDate.from({year: 2021, month: 4, day: 133}), 2021, 4, "M04", 30, "year/month/day with day need to be constrained in April"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, month: 5, day: 133}), + Temporal.PlainDate.from({year: 2021, month: 5, day: 133}), 2021, 5, "M05", 31, "year/month/day with day need to be constrained in May"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, month: 6, day: 133}), + Temporal.PlainDate.from({year: 2021, month: 6, day: 133}), 2021, 6, "M06", 30, "year/month/day with day need to be constrained in Jun"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, month: 7, day: 133}), + Temporal.PlainDate.from({year: 2021, month: 7, day: 133}), 2021, 7, "M07", 31, "year/month/day with day need to be constrained in July"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, month: 8, day: 133}), + Temporal.PlainDate.from({year: 2021, month: 8, day: 133}), 2021, 8, "M08", 31, "year/month/day with day need to be constrained in Aug"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, month: 9, day: 133}), + Temporal.PlainDate.from({year: 2021, month: 9, day: 133}), 2021, 9, "M09", 30, "year/month/day with day need to be constrained in Sept."); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, month: 10, day: 133}), + Temporal.PlainDate.from({year: 2021, month: 10, day: 133}), 2021, 10, "M10", 31, "year/month/day with day need to be constrained in Oct."); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, month: 11, day: 133}), + Temporal.PlainDate.from({year: 2021, month: 11, day: 133}), 2021, 11, "M11", 30, "year/month/day with day need to be constrained in Nov."); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, month: 12, day: 133}), + Temporal.PlainDate.from({year: 2021, month: 12, day: 133}), 2021, 12, "M12", 31, "year/month/day with day need to be constrained in Dec."); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, month: 13, day: 500}), + Temporal.PlainDate.from({year: 2021, month: 13, day: 500}), 2021, 12, "M12", 31, "year/month/day with month and day need to be constrained"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, month: 999999, day: 500}), + Temporal.PlainDate.from({year: 2021, month: 999999, day: 500}), 2021, 12, "M12", 31, "year/month/day with month and day need to be constrained"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-month-day.js b/test/built-ins/Temporal/PlainDate/from/with-year-month-day.js similarity index 75% rename from test/built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-month-day.js rename to test/built-ins/Temporal/PlainDate/from/with-year-month-day.js index cc7bdad2ea..87068fd4ed 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-month-day.js +++ b/test/built-ins/Temporal/PlainDate/from/with-year-month-day.js @@ -1,8 +1,8 @@ // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.datefromfields -description: Temporal.Calendar.prototype.dateFromFields with year/month/day +esid: sec-temporal.plaindate.from +description: With year/month/day info: | 1. Let calendar be the this value. 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). @@ -14,9 +14,8 @@ info: | features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601") TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, month: 7, day: 15}), + Temporal.PlainDate.from({year: 2021, month: 7, day: 15}), 2021, 7, "M07", 15, "year/month/day"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-monthCode-day-need-constrain.js b/test/built-ins/Temporal/PlainDate/from/with-year-monthCode-day-need-constrain.js similarity index 68% rename from test/built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-monthCode-day-need-constrain.js rename to test/built-ins/Temporal/PlainDate/from/with-year-monthCode-day-need-constrain.js index 7a021938a0..07378b4063 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-monthCode-day-need-constrain.js +++ b/test/built-ins/Temporal/PlainDate/from/with-year-monthCode-day-need-constrain.js @@ -1,8 +1,8 @@ // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.datefromfields -description: Temporal.Calendar.prototype.dateFromFields with year, monthCode and day and need constrain +esid: sec-temporal.plaindate.from +description: With year, monthCode and day and need constrain info: | 1. Let calendar be the this value. 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). @@ -14,64 +14,63 @@ info: | features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601") TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, monthCode: "M01", day: 133}), + Temporal.PlainDate.from({year: 2021, monthCode: "M01", day: 133}), 2021, 1, "M01", 31, "year/monthCode/day with day need to be constrained in Jan"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, monthCode: "M02", day: 133}), + Temporal.PlainDate.from({year: 2021, monthCode: "M02", day: 133}), 2021, 2, "M02", 28, "year/monthCode/day with day need to be constrained in Feb"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, monthCode: "M03", day: 133}), + Temporal.PlainDate.from({year: 2021, monthCode: "M03", day: 133}), 2021, 3, "M03", 31, "year/monthCode/day with day need to be constrained in March"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, monthCode: "M04", day: 133}), + Temporal.PlainDate.from({year: 2021, monthCode: "M04", day: 133}), 2021, 4, "M04", 30, "year/monthCode/day with day need to be constrained in April"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, monthCode: "M05", day: 133}), + Temporal.PlainDate.from({year: 2021, monthCode: "M05", day: 133}), 2021, 5, "M05", 31, "year/monthCode/day with day need to be constrained in May"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, monthCode: "M06", day: 133}), + Temporal.PlainDate.from({year: 2021, monthCode: "M06", day: 133}), 2021, 6, "M06", 30, "year/monthCode/day with day need to be constrained in Jun"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, monthCode: "M07", day: 133}), + Temporal.PlainDate.from({year: 2021, monthCode: "M07", day: 133}), 2021, 7, "M07", 31, "year/monthCode/day with day need to be constrained in July"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, monthCode: "M08", day: 133}), + Temporal.PlainDate.from({year: 2021, monthCode: "M08", day: 133}), 2021, 8, "M08", 31, "year/monthCode/day with day need to be constrained in Aug"); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, monthCode: "M09", day: 133}), + Temporal.PlainDate.from({year: 2021, monthCode: "M09", day: 133}), 2021, 9, "M09", 30, "year/monthCode/day with day need to be constrained in Sept."); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, monthCode: "M10", day: 133}), + Temporal.PlainDate.from({year: 2021, monthCode: "M10", day: 133}), 2021, 10, "M10", 31, "year/monthCode/day with day need to be constrained in Oct."); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, monthCode: "M11", day: 133}), + Temporal.PlainDate.from({year: 2021, monthCode: "M11", day: 133}), 2021, 11, "M11", 30, "year/monthCode/day with day need to be constrained in Nov."); TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, monthCode: "M12", day: 133}), + Temporal.PlainDate.from({year: 2021, monthCode: "M12", day: 133}), 2021, 12, "M12", 31, "year/monthCode/day with day need to be constrained in Dec."); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-monthCode-day.js b/test/built-ins/Temporal/PlainDate/from/with-year-monthCode-day.js similarity index 74% rename from test/built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-monthCode-day.js rename to test/built-ins/Temporal/PlainDate/from/with-year-monthCode-day.js index 8b27f81026..2bb09d1dfb 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateFromFields/with-year-monthCode-day.js +++ b/test/built-ins/Temporal/PlainDate/from/with-year-monthCode-day.js @@ -1,8 +1,8 @@ // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.datefromfields -description: Temporal.Calendar.prototype.dateFromFields with year, monthCode and day. +esid: sec-temporal.plaindate.from +description: Property bag with year, monthCode and day info: | 1. Let calendar be the this value. 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). @@ -14,9 +14,8 @@ info: | features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601") TemporalHelpers.assertPlainDate( - cal.dateFromFields({year: 2021, monthCode: "M07", day: 15}), + Temporal.PlainDate.from({year: 2021, monthCode: "M07", day: 15}), 2021, 7, "M07", 15, "year/monthCode/day"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-days.js b/test/built-ins/Temporal/PlainDate/prototype/add/add-days.js similarity index 64% rename from test/built-ins/Temporal/Calendar/prototype/dateAdd/add-days.js rename to test/built-ins/Temporal/PlainDate/prototype/add/add-days.js index 2577b67362..f629e91924 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-days.js +++ b/test/built-ins/Temporal/PlainDate/prototype/add/add-days.js @@ -2,35 +2,34 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.dateadd -description: Temporal.Calendar.prototype.dateAdd add duration with days and calculate correctly.. +esid: sec-temporal.plaindate.prototype.add +description: Add duration with days and calculate correctly info: | 8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow). features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601"); let p10d = new Temporal.Duration(0,0,0,10); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-07-16", p10d), 2021, 7, "M07", 26, + Temporal.PlainDate.from("2021-07-16").add(p10d), 2021, 7, "M07", 26, "add 10 days and result into the same month"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-07-26", p10d), 2021, 8, "M08", 5, + Temporal.PlainDate.from("2021-07-26").add(p10d), 2021, 8, "M08", 5, "add 10 days and result into next month"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-12-26", p10d), 2022, 1, "M01", 5, + Temporal.PlainDate.from("2021-12-26").add(p10d), 2022, 1, "M01", 5, "add 10 days and result into next year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-02-26", p10d), 2020, 3, "M03", 7, + Temporal.PlainDate.from("2020-02-26").add(p10d), 2020, 3, "M03", 7, "add 10 days from a leap year in Feb and result into March"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-02-26", p10d), 2021, 3, "M03", 8, + Temporal.PlainDate.from("2021-02-26").add(p10d), 2021, 3, "M03", 8, "add 10 days from a non leap year in Feb and result into March"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-02-19", p10d), 2020, 2, "M02", 29, + Temporal.PlainDate.from("2020-02-19").add(p10d), 2020, 2, "M02", 29, "add 10 days from a leap year in Feb 19 and result into Feb 29"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-02-19", p10d), 2021, 3, "M03", 1, + Temporal.PlainDate.from("2021-02-19").add(p10d), 2021, 3, "M03", 1, "add 10 days from a non leap year in Feb 19 and result into March 1"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-months-weeks.js b/test/built-ins/Temporal/PlainDate/prototype/add/add-months-weeks.js similarity index 63% rename from test/built-ins/Temporal/Calendar/prototype/dateAdd/add-months-weeks.js rename to test/built-ins/Temporal/PlainDate/prototype/add/add-months-weeks.js index 6f54afa275..c9ba250f33 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-months-weeks.js +++ b/test/built-ins/Temporal/PlainDate/prototype/add/add-months-weeks.js @@ -2,35 +2,34 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.dateadd -description: Temporal.Calendar.prototype.dateAdd add duration with months and weeks and calculate correctly. +esid: sec-temporal.plaindate.prototype.add +description: Add duration with months and weeks and calculate correctly info: | 8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow). features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601"); let p2m3w = new Temporal.Duration(0,2,3); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-02-29", p2m3w), 2020, 5, "M05", 20, + Temporal.PlainDate.from("2020-02-29").add(p2m3w), 2020, 5, "M05", 20, "add two months 3 weeks from Feb 29 of a leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-02-28", p2m3w), 2020, 5, "M05", 19, + Temporal.PlainDate.from("2020-02-28").add(p2m3w), 2020, 5, "M05", 19, "add two months 3 weeks from Feb 28 of a leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-02-28", p2m3w), 2021, 5, "M05", 19, + Temporal.PlainDate.from("2021-02-28").add(p2m3w), 2021, 5, "M05", 19, "add two months 3 weeks from Feb 28 of a non leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-12-28", p2m3w), 2021, 3, "M03", 21, + Temporal.PlainDate.from("2020-12-28").add(p2m3w), 2021, 3, "M03", 21, "add two months 3 weeks from end of year to non leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2019-12-28", p2m3w), 2020, 3, "M03", 20, + Temporal.PlainDate.from("2019-12-28").add(p2m3w), 2020, 3, "M03", 20, "add two months 3 weeks from end of year to leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2019-10-28", p2m3w), 2020, 1, "M01", 18, + Temporal.PlainDate.from("2019-10-28").add(p2m3w), 2020, 1, "M01", 18, "add two months 3 weeks and cause roll into a new year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2019-10-31", p2m3w), 2020, 1, "M01", 21, + Temporal.PlainDate.from("2019-10-31").add(p2m3w), 2020, 1, "M01", 21, "add two months 3 weeks and cause roll into a new year"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-months.js b/test/built-ins/Temporal/PlainDate/prototype/add/add-months.js similarity index 66% rename from test/built-ins/Temporal/Calendar/prototype/dateAdd/add-months.js rename to test/built-ins/Temporal/PlainDate/prototype/add/add-months.js index 8c765d6456..ff6c6fc87b 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-months.js +++ b/test/built-ins/Temporal/PlainDate/prototype/add/add-months.js @@ -2,32 +2,31 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.dateadd -description: Temporal.Calendar.prototype.dateAdd add duration with months and calculate correctly +esid: sec-temporal.plaindate.prototype.add +description: Add duration with months and calculate correctly info: | 8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow). features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601"); let p5m = new Temporal.Duration(0, 5); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-07-16", p5m), 2021, 12, "M12", 16, + Temporal.PlainDate.from("2021-07-16").add(p5m), 2021, 12, "M12", 16, "add five months and result in the same year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-08-16", p5m), 2022, 1, "M01", 16, + Temporal.PlainDate.from("2021-08-16").add(p5m), 2022, 1, "M01", 16, "add five months and result in the next year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-10-31", p5m), 2022, 3, "M03", 31, + Temporal.PlainDate.from("2021-10-31").add(p5m), 2022, 3, "M03", 31, "add five months and result in the next year in end of month"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2019-10-01", p5m), 2020, 3, "M03", 1, + Temporal.PlainDate.from("2019-10-01").add(p5m), 2020, 3, "M03", 1, "add five months and result in the next year in end of month on leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-09-30", p5m), 2022, 2, "M02", 28, + Temporal.PlainDate.from("2021-09-30").add(p5m), 2022, 2, "M02", 28, "add five months and result in the nexdt year and constrain to Feb 28"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2019-09-30", p5m), 2020, 2, "M02", 29, + Temporal.PlainDate.from("2019-09-30").add(p5m), 2020, 2, "M02", 29, "add five months and result in the nexdt year and constrain to Feb 29 on leap year"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-weeks-days.js b/test/built-ins/Temporal/PlainDate/prototype/add/add-weeks-days.js similarity index 68% rename from test/built-ins/Temporal/Calendar/prototype/dateAdd/add-weeks-days.js rename to test/built-ins/Temporal/PlainDate/prototype/add/add-weeks-days.js index 1af689ec74..bd5209697e 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-weeks-days.js +++ b/test/built-ins/Temporal/PlainDate/prototype/add/add-weeks-days.js @@ -2,25 +2,24 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.dateadd -description: Temporal.Calendar.prototype.dateAdd add duration with weeks and days and calculate correctly. +esid: sec-temporal.plaindate.prototype.add +description: Add duration with weeks and days and calculate correctly info: | 8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow). features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601"); let p2w3d = new Temporal.Duration(0,0,2,3); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-02-29", p2w3d), 2020, 3, "M03", 17, + Temporal.PlainDate.from("2020-02-29").add(p2w3d), 2020, 3, "M03", 17, "add 2 weeks and 3 days (17 days) from Feb 29 in a leap year and cause rolling into March"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-02-28", p2w3d), 2021, 3, "M03", 17, + Temporal.PlainDate.from("2021-02-28").add(p2w3d), 2021, 3, "M03", 17, "add 2 weeks and 3 days (17 days) from Feb and cause rolling into March in a non leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-02-28", p2w3d), 2020, 3, "M03", 16, + Temporal.PlainDate.from("2020-02-28").add(p2w3d), 2020, 3, "M03", 16, "add 2 weeks and 3 days (17 days) from Feb and cause rolling into March in a leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-12-28", p2w3d), 2021, 1, "M01", 14, + Temporal.PlainDate.from("2020-12-28").add(p2w3d), 2021, 1, "M01", 14, "add 2 weeks and 3 days (17 days) and cause rolling into a new year"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-weeks.js b/test/built-ins/Temporal/PlainDate/prototype/add/add-weeks.js similarity index 61% rename from test/built-ins/Temporal/Calendar/prototype/dateAdd/add-weeks.js rename to test/built-ins/Temporal/PlainDate/prototype/add/add-weeks.js index 797778e098..edcc3adb7b 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-weeks.js +++ b/test/built-ins/Temporal/PlainDate/prototype/add/add-weeks.js @@ -2,62 +2,61 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.dateadd -description: Temporal.Calendar.prototype.dateAdd add duration with weeks and calculate correctly. +esid: sec-temporal.plaindate.prototype.add +description: Add duration with weeks and calculate correctly info: | 8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow). features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601"); let p1w = new Temporal.Duration(0,0,1); let p6w = new Temporal.Duration(0,0,6); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-02-19", p1w), 2021, 2, "M02", 26, + Temporal.PlainDate.from("2021-02-19").add(p1w), 2021, 2, "M02", 26, "add one week in Feb"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-02-27", p1w), 2021, 3, "M03", 6, + Temporal.PlainDate.from("2021-02-27").add(p1w), 2021, 3, "M03", 6, "add one week in Feb and result in March"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-02-27", p1w), 2020, 3, "M03", 5, + Temporal.PlainDate.from("2020-02-27").add(p1w), 2020, 3, "M03", 5, "add one week in Feb and result in March in a leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-12-24", p1w), 2021, 12, "M12", 31, + Temporal.PlainDate.from("2021-12-24").add(p1w), 2021, 12, "M12", 31, "add one week and result in the last day of a year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-12-25", p1w), 2022, 1, "M01", 1, + Temporal.PlainDate.from("2021-12-25").add(p1w), 2022, 1, "M01", 1, "add one week and result in the first day of next year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-01-27", p1w), 2021, 2, "M02", 3, + Temporal.PlainDate.from("2021-01-27").add(p1w), 2021, 2, "M02", 3, "add one week and result in next month from a month with 31 days"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-06-27", p1w), 2021, 7, "M07", 4, + Temporal.PlainDate.from("2021-06-27").add(p1w), 2021, 7, "M07", 4, "add one week and result in next month from a month with 30 days"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-07-27", p1w), 2021, 8, "M08", 3, + Temporal.PlainDate.from("2021-07-27").add(p1w), 2021, 8, "M08", 3, "add one week and result in next month from a month with 31 days"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-02-19", p6w), 2021, 4, "M04", 2, + Temporal.PlainDate.from("2021-02-19").add(p6w), 2021, 4, "M04", 2, "add six weeks and result in next month from Feb in a non leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-02-19", p6w), 2020, 4, "M04", 1, + Temporal.PlainDate.from("2020-02-19").add(p6w), 2020, 4, "M04", 1, "add six weeks and result in next month from Feb in a leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-12-24", p6w), 2022, 2, "M02", 4, + Temporal.PlainDate.from("2021-12-24").add(p6w), 2022, 2, "M02", 4, "add six weeks and result in the next year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-01-27", p6w), 2021, 3, "M03", 10, + Temporal.PlainDate.from("2021-01-27").add(p6w), 2021, 3, "M03", 10, "add six weeks and result in the same year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-01-27", p6w), 2020, 3, "M03", 9, + Temporal.PlainDate.from("2020-01-27").add(p6w), 2020, 3, "M03", 9, "add six weeks and result in the same year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-06-27", p6w), 2021, 8, "M08", 8, + Temporal.PlainDate.from("2021-06-27").add(p6w), 2021, 8, "M08", 8, "add six weeks and result in the same year crossing month of 30 and 31 days"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-07-27", p6w), 2021, 9, "M09", 7, + Temporal.PlainDate.from("2021-07-27").add(p6w), 2021, 9, "M09", 7, "add six weeks and result in the same year crossing month of 31 and 31 days"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-years-months-days.js b/test/built-ins/Temporal/PlainDate/prototype/add/add-years-months-days.js similarity index 66% rename from test/built-ins/Temporal/Calendar/prototype/dateAdd/add-years-months-days.js rename to test/built-ins/Temporal/PlainDate/prototype/add/add-years-months-days.js index a8c2e5cb38..58d41e76db 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-years-months-days.js +++ b/test/built-ins/Temporal/PlainDate/prototype/add/add-years-months-days.js @@ -2,44 +2,43 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.dateadd -description: Temporal.Calendar.prototype.dateAdd add duration with years, months and days and calculate correctly. +esid: sec-temporal.plaindate.prototype.add +description: Add duration with years, months and days and calculate correctly info: | 8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow). features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601"); let p1y2m4d = new Temporal.Duration(1,2,0,4); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-07-16", p1y2m4d), 2022, 9, "M09", 20, + Temporal.PlainDate.from("2021-07-16").add(p1y2m4d), 2022, 9, "M09", 20, "add one year two months and 4 days"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-02-27", p1y2m4d), 2022, 5, "M05", 1, + Temporal.PlainDate.from("2021-02-27").add(p1y2m4d), 2022, 5, "M05", 1, "add one year two months and 4 days and roll into new month from a month of 30 days"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-01-28", p1y2m4d), 2022, 4, "M04", 1, + Temporal.PlainDate.from("2021-01-28").add(p1y2m4d), 2022, 4, "M04", 1, "add one year two months and 4 days and roll into new month from a month of 31 days"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-02-26", p1y2m4d), 2022, 4, "M04", 30, + Temporal.PlainDate.from("2021-02-26").add(p1y2m4d), 2022, 4, "M04", 30, "add one year two months and 4 days which roll from March to April in a non leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2023-02-26", p1y2m4d), 2024, 4, "M04", 30, + Temporal.PlainDate.from("2023-02-26").add(p1y2m4d), 2024, 4, "M04", 30, "add one year two months and 4 days which roll from March to April in a leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-12-30", p1y2m4d), 2023, 3, "M03", 4, + Temporal.PlainDate.from("2021-12-30").add(p1y2m4d), 2023, 3, "M03", 4, "add one year two months and 4 days which roll month into new year and roll day into March in non leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2022-12-30", p1y2m4d), 2024, 3, "M03", 4, + Temporal.PlainDate.from("2022-12-30").add(p1y2m4d), 2024, 3, "M03", 4, "add one year two months and 4 days which roll month into new year and roll day into March in leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2022-12-29", p1y2m4d), 2024, 3, "M03", 4, + Temporal.PlainDate.from("2022-12-29").add(p1y2m4d), 2024, 3, "M03", 4, "add one year two months and 4 days which roll month into new year and roll day into March in leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-07-30", p1y2m4d), 2022, 10, "M10", 4, + Temporal.PlainDate.from("2021-07-30").add(p1y2m4d), 2022, 10, "M10", 4, "add one year two months and 4 days which roll into a new month from a month with 30 days"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-06-30", p1y2m4d), 2022, 9, "M09", 3, + Temporal.PlainDate.from("2021-06-30").add(p1y2m4d), 2022, 9, "M09", 3, "add one year two months and 4 days which roll into a new month from a month with 31 days"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-years-months.js b/test/built-ins/Temporal/PlainDate/prototype/add/add-years-months.js similarity index 66% rename from test/built-ins/Temporal/Calendar/prototype/dateAdd/add-years-months.js rename to test/built-ins/Temporal/PlainDate/prototype/add/add-years-months.js index e7b4499550..2e9e5c4685 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-years-months.js +++ b/test/built-ins/Temporal/PlainDate/prototype/add/add-years-months.js @@ -2,26 +2,25 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.dateadd -description: Temporal.Calendar.prototype.dateAdd add duration with years and months and calculate correctly. +esid: sec-temporal.plaindate.prototype.add +description: Add duration with years and months and calculate correctly info: | 8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow). features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601"); let p1y2m = new Temporal.Duration(1,2); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-07-16", p1y2m), 2022, 9, "M09", 16, + Temporal.PlainDate.from("2021-07-16").add(p1y2m), 2022, 9, "M09", 16, "add one year and 2 months"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-11-30", p1y2m), 2023, 1, "M01", 30, + Temporal.PlainDate.from("2021-11-30").add(p1y2m), 2023, 1, "M01", 30, "add one year and 2 months roll into a new year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-12-31", p1y2m), 2023, 2, "M02", 28, + Temporal.PlainDate.from("2021-12-31").add(p1y2m), 2023, 2, "M02", 28, "add one year and 2 months roll into a new year and constrain in Feb 28 of a non leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2022-12-31", p1y2m), 2024, 2, "M02", 29, + Temporal.PlainDate.from("2022-12-31").add(p1y2m), 2024, 2, "M02", 29, "add one year and 2 months roll into a new year and constrain in Feb 29 of a leap year"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-years-weeks.js b/test/built-ins/Temporal/PlainDate/prototype/add/add-years-weeks.js similarity index 67% rename from test/built-ins/Temporal/Calendar/prototype/dateAdd/add-years-weeks.js rename to test/built-ins/Temporal/PlainDate/prototype/add/add-years-weeks.js index 5152a1c3c2..81288ff491 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-years-weeks.js +++ b/test/built-ins/Temporal/PlainDate/prototype/add/add-years-weeks.js @@ -2,29 +2,28 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.dateadd -description: Temporal.Calendar.prototype.dateAdd add duration with years and weeks and calculate correctly. +esid: sec-temporal.plaindate.prototype.add +description: Add duration with years and weeks and calculate correctly info: | 8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow). features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601"); let p1y2w = new Temporal.Duration(1,0,2); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-02-28", p1y2w), 2021, 3, "M03", 14, + Temporal.PlainDate.from("2020-02-28").add(p1y2w), 2021, 3, "M03", 14, "add 1 year and 2 weeks to Feb 28 and cause roll into March in a non leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-02-29", p1y2w), 2021, 3, "M03", 14, + Temporal.PlainDate.from("2020-02-29").add(p1y2w), 2021, 3, "M03", 14, "add 1 year and 2 weeks to Feb 29 and cause roll into March in a non leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2019-02-28", p1y2w), 2020, 3, "M03", 13, + Temporal.PlainDate.from("2019-02-28").add(p1y2w), 2020, 3, "M03", 13, "add 1 year and 2 weeks to Feb 28 and cause roll into March in a leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-02-28", p1y2w), 2022, 3, "M03", 14, + Temporal.PlainDate.from("2021-02-28").add(p1y2w), 2022, 3, "M03", 14, "add 1 year and 2 weeks to Feb 28 and cause roll into March in a non leap year"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-12-28", p1y2w), 2022, 1, "M01", 11, + Temporal.PlainDate.from("2020-12-28").add(p1y2w), 2022, 1, "M01", 11, "add 1 year and 2 weeks and cause roll into a new year"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-years.js b/test/built-ins/Temporal/PlainDate/prototype/add/add-years.js similarity index 64% rename from test/built-ins/Temporal/Calendar/prototype/dateAdd/add-years.js rename to test/built-ins/Temporal/PlainDate/prototype/add/add-years.js index c9c44246da..f414dda2d8 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/add-years.js +++ b/test/built-ins/Temporal/PlainDate/prototype/add/add-years.js @@ -2,24 +2,23 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.dateadd -description: Temporal.Calendar.prototype.dateAdd add duration with years only calculate correctly. +esid: sec-temporal.plaindate.prototype.add +description: Add duration with years only calculate correctly info: | 8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow). features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601"); let p1y = new Temporal.Duration(1); let p4y = new Temporal.Duration(4); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-02-29", p1y), 2021, 2, "M02", 28, + Temporal.PlainDate.from("2020-02-29").add(p1y), 2021, 2, "M02", 28, "add one year on Feb 29"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2020-02-29", p4y), 2024, 2, "M02", 29, + Temporal.PlainDate.from("2020-02-29").add(p4y), 2024, 2, "M02", 29, "add four years on Feb 29"); TemporalHelpers.assertPlainDate( - cal.dateAdd("2021-07-16", p1y), 2022, 7, "M07", 16, + Temporal.PlainDate.from("2021-07-16").add(p1y), 2022, 7, "M07", 16, "add one year on other date"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/add/argument-string-invalid.js b/test/built-ins/Temporal/PlainDate/prototype/add/argument-string-invalid.js new file mode 100644 index 0000000000..abe66bf8f1 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/add/argument-string-invalid.js @@ -0,0 +1,16 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.add +description: Throws RangeError when duration string is invalid +info: | + ... + 5. Set duration to ? ToTemporalDuration(duration). +features: [Temporal, arrow-function] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); +assert.throws(RangeError, + () => instance.add("invalid duration string"), + "invalid duration string causes a RangeError"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/add/argument-string.js b/test/built-ins/Temporal/PlainDate/prototype/add/argument-string.js index 5abb43791b..7f9a284af9 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/add/argument-string.js +++ b/test/built-ins/Temporal/PlainDate/prototype/add/argument-string.js @@ -11,3 +11,5 @@ features: [Temporal] const instance = Temporal.PlainDate.from({ year: 2000, month: 5, day: 2 }); const result = instance.add("P3D"); TemporalHelpers.assertPlainDate(result, 2000, 5, "M05", 5); + +TemporalHelpers.assertPlainDate(instance.add("P1M1W"), 2000, 6, "M06", 9, "calendar units"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/add/order-of-operations.js b/test/built-ins/Temporal/PlainDate/prototype/add/order-of-operations.js index d2df806807..605a2760c9 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/add/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDate/prototype/add/order-of-operations.js @@ -40,10 +40,6 @@ const expected = [ "get fields.years", "get fields.years.valueOf", "call fields.years.valueOf", - // AddDate - "get this.calendar.dateAdd", - "call this.calendar.dateAdd", - // inside Calendar.p.dateAdd "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", @@ -51,8 +47,6 @@ const expected = [ const actual = []; const instance = new Temporal.PlainDate(2000, 5, 2, "iso8601"); -// clear observable operations that occurred during the constructor call -actual.splice(0); const fields = TemporalHelpers.propertyBagObserver(actual, { years: 1, @@ -75,51 +69,3 @@ instance.add(fields, options); assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -const noCalendarExpected = [ - // ToTemporalDurationRecord - "get fields.days", - "get fields.days.valueOf", - "call fields.days.valueOf", - "get fields.hours", - "get fields.hours.valueOf", - "call fields.hours.valueOf", - "get fields.microseconds", - "get fields.microseconds.valueOf", - "call fields.microseconds.valueOf", - "get fields.milliseconds", - "get fields.milliseconds.valueOf", - "call fields.milliseconds.valueOf", - "get fields.minutes", - "get fields.minutes.valueOf", - "call fields.minutes.valueOf", - "get fields.months", - "get fields.nanoseconds", - "get fields.nanoseconds.valueOf", - "call fields.nanoseconds.valueOf", - "get fields.seconds", - "get fields.seconds.valueOf", - "call fields.seconds.valueOf", - "get fields.weeks", - "get fields.years", - "get this.calendar.dateAdd", - // AddDate - "get options.overflow", - "get options.overflow.toString", - "call options.overflow.toString", -]; - -const noCalendarFields = TemporalHelpers.propertyBagObserver(actual, { - days: 1, - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1, - nanoseconds: 1, -}, "fields"); - -instance.add(noCalendarFields, options); -assert.compareArray(actual, noCalendarExpected, "order of operations with no calendar operation"); - -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-object-valid.js b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-object-valid.js index a20357f64d..d60ace9d2e 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-object-valid.js +++ b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-object-valid.js @@ -10,29 +10,5 @@ features: [Temporal] const instance = new Temporal.PlainDate(2000, 5, 2); assert.sameValue(instance.equals({ year: 2000, month: 5, day: 2 }), true, "same date"); assert.sameValue(instance.equals({ year: 2000, month: 5, day: 4 }), false, "different date"); - -const calendar = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "a", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -assert.sameValue(instance.withCalendar(calendar).equals({ year: 2000, month: 5, day: 2 }), +assert.sameValue(instance.equals({ year: 2000, month: 5, day: 2, calendar: "gregory" }), false, "different calendar"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-string.js b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-string.js index 9919d17563..329bf5572e 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-string.js +++ b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-string.js @@ -10,28 +10,4 @@ features: [Temporal] const instance = new Temporal.PlainDate(2000, 5, 2); assert.sameValue(instance.equals("2000-05-02"), true, "same date"); assert.sameValue(instance.equals("2000-05-04"), false, "different date"); - -const calendar = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "a", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -assert.sameValue(instance.withCalendar(calendar).equals("2000-05-02"), false, "different calendar"); +assert.sameValue(instance.equals("2000-05-02[u-ca=gregory]"), false, "different calendar"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/equals/calendar-is-compared.js b/test/built-ins/Temporal/PlainDate/prototype/equals/calendar-is-compared.js new file mode 100644 index 0000000000..03525b7cd4 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/equals/calendar-is-compared.js @@ -0,0 +1,12 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.protoype.equals +description: test if the calendar is compared +features: [Temporal] +---*/ + +const date1 = new Temporal.PlainDate(1914, 2, 23, "iso8601"); +const date2 = new Temporal.PlainDate(1914, 2, 22, "gregory"); +assert.sameValue(date1.equals(date2), false, "different ISO dates"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/equals/calendar-no-call.js b/test/built-ins/Temporal/PlainDate/prototype/equals/calendar-no-call.js deleted file mode 100644 index 95f485fa49..0000000000 --- a/test/built-ins/Temporal/PlainDate/prototype/equals/calendar-no-call.js +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.plaindate.protoype.equals -description: test if the calendar is compared -features: [Temporal] ----*/ - -class CalendarTraceToString extends Temporal.Calendar { - constructor(id) { - super("iso8601"); - this.id_ = id; - this.calls = 0; - } - toString() { - ++this.calls; - return this.id_; - } -}; - -const calendar1 = new CalendarTraceToString("a"); -const date1 = new Temporal.PlainDate(1914, 2, 23, calendar1); - -const calendar2 = new CalendarTraceToString("b"); -const date2 = new Temporal.PlainDate(1914, 2, 22, calendar2); - -assert.sameValue(date1.equals(date2), false, "different ISO dates"); -assert.sameValue(calendar1.calls, 0, "calendar1 toString() calls"); -assert.sameValue(calendar2.calls, 0, "calendar2 toString() calls"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/calendar-id-match.js b/test/built-ins/Temporal/PlainDate/prototype/since/calendar-id-match.js index 0c2953910c..aa20863c44 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/calendar-id-match.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/calendar-id-match.js @@ -3,28 +3,11 @@ /*--- esid: sec-temporal.plaindate.prototype.since -description: Calculation is performed if calendars' toString results match +description: Calculation is performed if calendars' IDs match includes: [compareArray.js, temporalHelpers.js] features: [Temporal] ---*/ -class Calendar1 extends Temporal.Calendar { - constructor() { - super("iso8601"); - } - toString() { - return "A"; - } -} -class Calendar2 extends Temporal.Calendar { - constructor() { - super("iso8601"); - } - toString() { - return "A"; - } -} - -const plainDate1 = new Temporal.PlainDate(2000, 1, 1, new Calendar1()); -const plainDate2 = new Temporal.PlainDate(2000, 1, 2, new Calendar2()); +const plainDate1 = new Temporal.PlainDate(2000, 1, 1, "iso8601"); +const plainDate2 = Temporal.PlainDate.from({ year: 2000, month: 1, day: 2, calendar: "2024-05-16[u-ca=iso8601]" }); TemporalHelpers.assertDuration(plainDate2.since(plainDate1), 0, 0, 0, /* days = */ 1, 0, 0, 0, 0, 0, 0); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/calendar-mismatch.js b/test/built-ins/Temporal/PlainDate/prototype/since/calendar-mismatch.js index f8226f5f9c..f0291e45ea 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/calendar-mismatch.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/calendar-mismatch.js @@ -3,57 +3,10 @@ /*--- esid: sec-temporal.plaindate.prototype.since -description: RangeError thrown if calendars' id properties do not match +description: RangeError thrown if calendars' IDs do not match features: [Temporal] ---*/ -const calendar1 = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "A", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -const calendar2 = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "B", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const plainDate1 = new Temporal.PlainDate(2000, 1, 1, calendar1); -const plainDate2 = new Temporal.PlainDate(2000, 1, 1, calendar2); +const plainDate1 = new Temporal.PlainDate(2000, 1, 1, "gregory"); +const plainDate2 = new Temporal.PlainDate(2000, 1, 1, "japanese"); assert.throws(RangeError, () => plainDate1.since(plainDate2)); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/order-of-operations.js b/test/built-ins/Temporal/PlainDate/prototype/since/order-of-operations.js index 5d78ded207..ef1541e552 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/order-of-operations.js @@ -11,30 +11,6 @@ features: [Temporal] const expected = [ // ToTemporalDate "get other.calendar", - "has other.calendar.dateAdd", - "has other.calendar.dateFromFields", - "has other.calendar.dateUntil", - "has other.calendar.day", - "has other.calendar.dayOfWeek", - "has other.calendar.dayOfYear", - "has other.calendar.daysInMonth", - "has other.calendar.daysInWeek", - "has other.calendar.daysInYear", - "has other.calendar.fields", - "has other.calendar.id", - "has other.calendar.inLeapYear", - "has other.calendar.mergeFields", - "has other.calendar.month", - "has other.calendar.monthCode", - "has other.calendar.monthDayFromFields", - "has other.calendar.monthsInYear", - "has other.calendar.weekOfYear", - "has other.calendar.year", - "has other.calendar.yearMonthFromFields", - "has other.calendar.yearOfWeek", - "get other.calendar.dateFromFields", - "get other.calendar.fields", - "call other.calendar.fields", "get other.day", "get other.day.valueOf", "call other.day.valueOf", @@ -47,29 +23,17 @@ const expected = [ "get other.year", "get other.year.valueOf", "call other.year.valueOf", - "call other.calendar.dateFromFields", - // CalendarEquals - "get this.calendar.id", - "get other.calendar.id", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.roundingIncrement", - "get options.roundingIncrement", - "getOwnPropertyDescriptor options.roundingMode", - "get options.roundingMode", - "getOwnPropertyDescriptor options.largestUnit", - "get options.largestUnit", - "getOwnPropertyDescriptor options.smallestUnit", - "get options.smallestUnit", - "getOwnPropertyDescriptor options.additional", - "get options.additional", // GetDifferenceSettings + "get options.largestUnit", "get options.largestUnit.toString", "call options.largestUnit.toString", + "get options.roundingIncrement", "get options.roundingIncrement.valueOf", "call options.roundingIncrement.valueOf", + "get options.roundingMode", "get options.roundingMode.toString", "call options.roundingMode.toString", + "get options.smallestUnit", "get options.smallestUnit.toString", "call options.smallestUnit.toString", ]; @@ -97,96 +61,7 @@ function createOptionsObserver({ smallestUnit = "days", largestUnit = "auto", ro }, "options"); } -// clear any observable things that happened while constructing the objects -actual.splice(0); - // basic order of observable operations with calendar call, without rounding: instance.since(otherDatePropertyBag, createOptionsObserver({ largestUnit: "years" })); -assert.compareArray(actual, expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", -]), "order of operations"); +assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -// short-circuit for identical objects: -const identicalPropertyBag = TemporalHelpers.propertyBagObserver(actual, { - year: 2000, - month: 5, - monthCode: "M05", - day: 2, - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), -}, "other"); - -instance.since(identicalPropertyBag, createOptionsObserver()); -assert.compareArray(actual, expected, "order of operations with identical dates"); -actual.splice(0); // clear - -// code path through RoundRelativeDuration that rounds to the nearest year: -const expectedOpsForYearRounding = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.since(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "years" })); -assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest year and skips a DateUntil call: -const otherDatePropertyBagSameMonth = TemporalHelpers.propertyBagObserver(actual, { - year: 2001, - month: 5, - monthCode: "M05", - day: 2, - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), -}, "other"); -const expectedOpsForYearRoundingSameMonth = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.since(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" })); -assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest month: -const expectedOpsForMonthRounding = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.since(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "months" })); -assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest week: -const expectedOpsForWeekRounding = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateUntil", - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.since(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "weeks" })); -assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/subtract/order-of-operations.js b/test/built-ins/Temporal/PlainDate/prototype/subtract/order-of-operations.js index e33a0fdf8f..477fc58ec7 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/subtract/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDate/prototype/subtract/order-of-operations.js @@ -40,10 +40,6 @@ const expected = [ "get fields.years", "get fields.years.valueOf", "call fields.years.valueOf", - // AddDate - "get this.calendar.dateAdd", - "call this.calendar.dateAdd", - // inside Calendar.p.dateAdd "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", @@ -73,51 +69,3 @@ instance.subtract(fields, options); assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -const noCalendarExpected = [ - // ToTemporalDurationRecord - "get fields.days", - "get fields.days.valueOf", - "call fields.days.valueOf", - "get fields.hours", - "get fields.hours.valueOf", - "call fields.hours.valueOf", - "get fields.microseconds", - "get fields.microseconds.valueOf", - "call fields.microseconds.valueOf", - "get fields.milliseconds", - "get fields.milliseconds.valueOf", - "call fields.milliseconds.valueOf", - "get fields.minutes", - "get fields.minutes.valueOf", - "call fields.minutes.valueOf", - "get fields.months", - "get fields.nanoseconds", - "get fields.nanoseconds.valueOf", - "call fields.nanoseconds.valueOf", - "get fields.seconds", - "get fields.seconds.valueOf", - "call fields.seconds.valueOf", - "get fields.weeks", - "get fields.years", - "get this.calendar.dateAdd", - // AddDate - "get options.overflow", - "get options.overflow.toString", - "call options.overflow.toString", -]; - -const noCalendarFields = TemporalHelpers.propertyBagObserver(actual, { - days: 1, - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1, - nanoseconds: 1, -}, "fields"); - -instance.subtract(noCalendarFields, options); -assert.compareArray(actual, noCalendarExpected, "order of operations with no calendar operation"); - -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-always.js b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-always.js index a5621276a5..fd4646053d 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-always.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-always.js @@ -7,39 +7,6 @@ description: If calendarName is "always", the calendar ID should be included. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "2000-05-02[u-ca=iso8601]", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "2000-05-02[u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "2000-05-02[u-ca=iso8601]", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "2000-05-02[u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "2000-05-02[u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const date = new Temporal.PlainDate(2000, 5, 2, ...args); - const result = date.toString({ calendarName: "always" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = always`); -} +const date = new Temporal.PlainDate(2000, 5, 2); +const result = date.toString({ calendarName: "always" }); +assert.sameValue(result, "2000-05-02[u-ca=iso8601]", `built-in ISO calendar for calendarName = always`); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-auto.js b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-auto.js index 77e8c5dd4d..dfac7a06f3 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-auto.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-auto.js @@ -7,39 +7,6 @@ description: If calendarName is "auto", "iso8601" should be omitted. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "2000-05-02", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "2000-05-02[u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "2000-05-02", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "2000-05-02[u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "2000-05-02[u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const date = new Temporal.PlainDate(2000, 5, 2, ...args); - const result = date.toString({ calendarName: "auto" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = auto`); -} +const date = new Temporal.PlainDate(2000, 5, 2); +const result = date.toString({ calendarName: "auto" }); +assert.sameValue(result, "2000-05-02", `built-in ISO calendar for calendarName = auto`); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-critical.js b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-critical.js index dc3d37b756..2af44b82ab 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-critical.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-critical.js @@ -9,39 +9,6 @@ description: > features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "2000-05-02[!u-ca=iso8601]", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "2000-05-02[!u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "2000-05-02[!u-ca=iso8601]", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "2000-05-02[!u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "2000-05-02[!u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const date = new Temporal.PlainDate(2000, 5, 2, ...args); - const result = date.toString({ calendarName: "critical" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = critical`); -} +const date = new Temporal.PlainDate(2000, 5, 2); +const result = date.toString({ calendarName: "critical" }); +assert.sameValue(result, "2000-05-02[!u-ca=iso8601]", `built-in ISO calendar for calendarName = critical`); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-never.js b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-never.js index 1d25028717..00207ee3e3 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-never.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-never.js @@ -7,39 +7,6 @@ description: If calendarName is "never", the calendar ID should be omitted. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "2000-05-02", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "2000-05-02", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "2000-05-02", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "2000-05-02", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "2000-05-02", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const date = new Temporal.PlainDate(2000, 5, 2, ...args); - const result = date.toString({ calendarName: "never" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = never`); -} +const date = new Temporal.PlainDate(2000, 5, 2); +const result = date.toString({ calendarName: "never" }); +assert.sameValue(result, "2000-05-02", `built-in ISO calendar for calendarName = never`); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-undefined.js b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-undefined.js index fac29dcf86..e1c5052a01 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-undefined.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-undefined.js @@ -14,40 +14,7 @@ info: | features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "2000-05-02", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "2000-05-02[u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "2000-05-02", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "2000-05-02[u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "2000-05-02[u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const date = new Temporal.PlainDate(2000, 5, 2, ...args); - const result = date.toString({ calendarName: undefined }); - assert.sameValue(result, expected, `default calendarName option is auto with ${description} calendar`); - // See options-object.js for {} and options-undefined.js for absent options arg -} +const date = new Temporal.PlainDate(2000, 5, 2); +const result = date.toString({ calendarName: undefined }); +assert.sameValue(result, "2000-05-02", `default calendarName option is auto with built-in ISO calendar`); +// See options-object.js for {} and options-undefined.js for absent options arg diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-wrong-type.js index d3718951bf..80c0b3c6c8 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-wrong-type.js @@ -15,32 +15,9 @@ includes: [compareArray.js, temporalHelpers.js] features: [Temporal] ---*/ -const calendar = { - id: "custom", - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -const date = new Temporal.PlainDate(2000, 5, 2, calendar); +const date = new Temporal.PlainDate(2000, 5, 2, "iso8601"); TemporalHelpers.checkStringOptionWrongType("calendarName", "auto", (calendarName) => date.toString({ calendarName }), - (result, descr) => assert.sameValue(result, "2000-05-02[u-ca=custom]", descr), + (result, descr) => assert.sameValue(result, "2000-05-02", descr), ); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/options-undefined.js b/test/built-ins/Temporal/PlainDate/prototype/toString/options-undefined.js index 416b42fc2b..a311d02267 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/options-undefined.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/options-undefined.js @@ -7,35 +7,12 @@ description: Verify that undefined options are handled correctly. features: [Temporal] ---*/ -const calendar = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "custom", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; const date1 = new Temporal.PlainDate(2000, 5, 2); -const date2 = new Temporal.PlainDate(2000, 5, 2, calendar); +const date2 = new Temporal.PlainDate(2000, 5, 2, "gregory"); [ [date1, "2000-05-02"], - [date2, "2000-05-02[u-ca=custom]"], + [date2, "2000-05-02[u-ca=gregory]"], ].forEach(([date, expected]) => { const explicit = date.toString(undefined); assert.sameValue(explicit, expected, "default calendarName option is auto"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/order-of-operations.js b/test/built-ins/Temporal/PlainDate/prototype/toString/order-of-operations.js index a773a9a792..a53a018d3c 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/order-of-operations.js @@ -12,14 +12,10 @@ const expected = [ "get options.calendarName", "get options.calendarName.toString", "call options.calendarName.toString", - "get this.calendar.id", ]; const actual = []; -const calendar = TemporalHelpers.calendarObserver(actual, "this.calendar"); -const instance = new Temporal.PlainDate(2000, 5, 2, calendar); -// clear observable operations that occurred during the constructor call -actual.splice(0); +const instance = new Temporal.PlainDate(2000, 5, 2, "iso8601"); const options = TemporalHelpers.propertyBagObserver(actual, { calendarName: "auto", diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/order-of-operations.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/order-of-operations.js index 9c00c83da6..d293691aef 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/order-of-operations.js @@ -11,9 +11,6 @@ features: [Temporal] const actual = []; const expected = [ "get item.timeZone", - "has item.timeZone.getOffsetNanosecondsFor", - "has item.timeZone.getPossibleInstantsFor", - "has item.timeZone.id", "get item.plainTime", // ToTemporalTime "get item.plainTime.hour", @@ -34,18 +31,9 @@ const expected = [ "get item.plainTime.second", "get item.plainTime.second.valueOf", "call item.plainTime.second.valueOf", - // lookup in PlainDate.p.toZonedDateTime - "get item.timeZone.getOffsetNanosecondsFor", - "get item.timeZone.getPossibleInstantsFor", - // GetInstantFor - "call item.timeZone.getPossibleInstantsFor", ]; -const calendar = TemporalHelpers.calendarObserver(actual, "this.calendar"); -const instance = new Temporal.PlainDate(2000, 1, 1, calendar); -const springForwardInstance = new Temporal.PlainDate(2000, 4, 2, calendar); -const fallBackInstance = new Temporal.PlainDate(2000, 10, 29, calendar); -actual.splice(0); // clear calendar calls that happened in constructors +const instance = new Temporal.PlainDate(2000, 1, 1, "iso8601"); const plainTime = TemporalHelpers.propertyBagObserver(actual, { hour: 2, @@ -55,41 +43,11 @@ const plainTime = TemporalHelpers.propertyBagObserver(actual, { microsecond: 0, nanosecond: 0, }, "item.plainTime"); -const dstTimeZone = TemporalHelpers.springForwardFallBackTimeZone(); -const timeZone = TemporalHelpers.timeZoneObserver(actual, "item.timeZone", { - getOffsetNanosecondsFor: dstTimeZone.getOffsetNanosecondsFor, - getPossibleInstantsFor: dstTimeZone.getPossibleInstantsFor, -}); const item = TemporalHelpers.propertyBagObserver(actual, { plainTime, - timeZone, -}, "item"); + timeZone: "UTC" +}, "item", ["timeZone"]); instance.toZonedDateTime(item); -assert.compareArray(actual, expected, "order of operations at normal wall-clock time"); -actual.splice(0); // clear - -const plainTime130 = TemporalHelpers.propertyBagObserver(actual, { - hour: 1, - minute: 30, - second: 0, - millisecond: 0, - microsecond: 0, - nanosecond: 0, -}, "item.plainTime"); -const item130 = TemporalHelpers.propertyBagObserver(actual, { - plainTime: plainTime130, - timeZone, -}, "item"); - -fallBackInstance.toZonedDateTime(item130); -assert.compareArray(actual, expected, "order of operations at repeated wall-clock time"); -actual.splice(0); // clear - -springForwardInstance.toZonedDateTime(item); -assert.compareArray(actual, expected.concat([ - "call item.timeZone.getOffsetNanosecondsFor", - "call item.timeZone.getOffsetNanosecondsFor", - "call item.timeZone.getPossibleInstantsFor", -]), "order of operations at skipped wall-clock time"); +assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/calendar-id-match.js b/test/built-ins/Temporal/PlainDate/prototype/until/calendar-id-match.js index 9eb1c08578..514860154d 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/calendar-id-match.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/calendar-id-match.js @@ -3,28 +3,11 @@ /*--- esid: sec-temporal.plaindate.prototype.until -description: Calculation is performed if calendars' toString results match +description: Calculation is performed if calendars' IDs match includes: [compareArray.js, temporalHelpers.js] features: [Temporal] ---*/ -class Calendar1 extends Temporal.Calendar { - constructor() { - super("iso8601"); - } - toString() { - return "A"; - } -} -class Calendar2 extends Temporal.Calendar { - constructor() { - super("iso8601"); - } - toString() { - return "A"; - } -} - -const plainDate1 = new Temporal.PlainDate(2000, 1, 1, new Calendar1()); -const plainDate2 = new Temporal.PlainDate(2000, 1, 2, new Calendar2()); +const plainDate1 = new Temporal.PlainDate(2000, 1, 1, "iso8601"); +const plainDate2 = Temporal.PlainDate.from({ year: 2000, month: 1, day: 2, calendar: "2024-05-16[u-ca=iso8601]" }); TemporalHelpers.assertDuration(plainDate1.until(plainDate2), 0, 0, 0, /* days = */ 1, 0, 0, 0, 0, 0, 0); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/calendar-mismatch.js b/test/built-ins/Temporal/PlainDate/prototype/until/calendar-mismatch.js index 05c96de8c9..dfd871d8d1 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/calendar-mismatch.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/calendar-mismatch.js @@ -3,57 +3,10 @@ /*--- esid: sec-temporal.plaindate.prototype.until -description: RangeError thrown if calendars' id properties do not match +description: RangeError thrown if calendars' IDs do not match features: [Temporal] ---*/ -const calendar1 = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "A", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -const calendar2 = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "B", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const plainDate1 = new Temporal.PlainDate(2000, 1, 1, calendar1); -const plainDate2 = new Temporal.PlainDate(2000, 1, 1, calendar2); +const plainDate1 = new Temporal.PlainDate(2000, 1, 1, "gregory"); +const plainDate2 = new Temporal.PlainDate(2000, 1, 1, "japanese"); assert.throws(RangeError, () => plainDate1.until(plainDate2)); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/largestunit-day.js b/test/built-ins/Temporal/PlainDate/prototype/until/largestunit-day.js new file mode 100644 index 0000000000..e8d6f2f671 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/largestunit-day.js @@ -0,0 +1,47 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.until +description: Date arithmetic with largestUnit "day" +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +["day", "days"].forEach(function(largestUnit) { + let opt = {largestUnit}; + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-16").until("2021-07-16", opt), + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "same day"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-16").until("2021-07-17", opt), + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "one day"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-16").until("2021-08-17", opt), + 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, "32 days"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-16").until("2021-09-16", opt), + 0, 0, 0, 62, 0, 0, 0, 0, 0, 0, "62 days"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-16").until("2022-07-16", opt), + 0, 0, 0, 365, 0, 0, 0, 0, 0, 0, "365 days"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-16").until("2031-07-16", opt), + 0, 0, 0, 3652, 0, 0, 0, 0, 0, 0, "3652 days"); + + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-17").until("2021-07-16", opt), + 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "negative one day"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-08-17").until("2021-07-16", opt), + 0, 0, 0, -32, 0, 0, 0, 0, 0, 0, "negative 32 days"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-09-16").until("2021-07-16", opt), + 0, 0, 0, -62, 0, 0, 0, 0, 0, 0, "negative 62 days"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2022-07-16").until("2021-07-16", opt), + 0, 0, 0, -365, 0, 0, 0, 0, 0, 0, "negative 365 days"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2031-07-16").until("2021-07-16", opt), + 0, 0, 0, -3652, 0, 0, 0, 0, 0, 0, "negative 3652 days"); +}); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/largest-unit-month.js b/test/built-ins/Temporal/PlainDate/prototype/until/largestunit-month.js similarity index 55% rename from test/built-ins/Temporal/Calendar/prototype/dateUntil/largest-unit-month.js rename to test/built-ins/Temporal/PlainDate/prototype/until/largestunit-month.js index 5953c7886a..d79d82a524 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateUntil/largest-unit-month.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/largestunit-month.js @@ -2,93 +2,82 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.dateuntil -description: Temporal.Calendar.prototype.dateUntil with largestUnit is "month" -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. Set one to ? ToTemporalDate(one). - 5. Set two to ? ToTemporalDate(two). - 6. Set options to ? GetOptionsObject(options). - 7. Let largestUnit be ? ToLargestTemporalUnit(options, « "hour", "minute", "second", "millisecond", "microsecond", "nanosecond" », "auto", "day"). - 8. Let result be ! DifferenceISODate(one.[[ISOYear]], one.[[ISOMonth]], one.[[ISODay]], two.[[ISOYear]], two.[[ISOMonth]], two.[[ISODay]], largestUnit). - 9. Return ? CreateTemporalDuration(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], 0, 0, 0, 0, 0, 0). +esid: sec-temporal.plaindate.prototype.until +description: Date arithmetic with largestUnit "month" features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601"); ["month", "months"].forEach(function(largestUnit) { let opt = {largestUnit}; TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-07-16", opt), + Temporal.PlainDate.from("2021-07-16").until("2021-07-16", opt), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "same day"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-07-17", opt), + Temporal.PlainDate.from("2021-07-16").until("2021-07-17", opt), 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "one day"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-07-23", opt), + Temporal.PlainDate.from("2021-07-16").until("2021-07-23", opt), 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, "7 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-08-16", opt), + Temporal.PlainDate.from("2021-07-16").until("2021-08-16", opt), 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "1 month in same year"); TemporalHelpers.assertDuration( - cal.dateUntil("2020-12-16", "2021-01-16", opt), + Temporal.PlainDate.from("2020-12-16").until("2021-01-16", opt), 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "1 month in different year"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-01-05", "2021-02-05", opt), + Temporal.PlainDate.from("2021-01-05").until("2021-02-05", opt), 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "1 month in same year"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-01-07", "2021-03-07", opt), + Temporal.PlainDate.from("2021-01-07").until("2021-03-07", opt), 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, "2 month in same year across Feb 28"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-08-17", opt), + Temporal.PlainDate.from("2021-07-16").until("2021-08-17", opt), 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, "1 month and 1 day in a month with 31 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-08-13", opt), + Temporal.PlainDate.from("2021-07-16").until("2021-08-13", opt), 0, 0, 0, 28, 0, 0, 0, 0, 0, 0, "28 days roll across a month which has 31 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-09-16", opt), + Temporal.PlainDate.from("2021-07-16").until("2021-09-16", opt), 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, "2 months with both months which have 31 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2022-07-16", opt), + Temporal.PlainDate.from("2021-07-16").until("2022-07-16", opt), 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, "12 months"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2031-07-16", opt), + Temporal.PlainDate.from("2021-07-16").until("2031-07-16", opt), 0, 120, 0, 0, 0, 0, 0, 0, 0, 0, "120 months"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-17", "2021-07-16", opt), + Temporal.PlainDate.from("2021-07-17").until("2021-07-16", opt), 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "negative one day"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-23", "2021-07-16", opt), + Temporal.PlainDate.from("2021-07-23").until("2021-07-16", opt), 0, 0, 0, -7, 0, 0, 0, 0, 0, 0, "negative 7 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-08-16", "2021-07-16", opt), + Temporal.PlainDate.from("2021-08-16").until("2021-07-16", opt), 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, "negative 1 month in same year"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-01-16", "2020-12-16", opt), + Temporal.PlainDate.from("2021-01-16").until("2020-12-16", opt), 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, "negative 1 month in different year"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-02-05", "2021-01-05", opt), + Temporal.PlainDate.from("2021-02-05").until("2021-01-05", opt), 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, "negative 1 month in same year"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-03-07", "2021-01-07", opt), + Temporal.PlainDate.from("2021-03-07").until("2021-01-07", opt), 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, "negative 2 month in same year across Feb 28"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-08-17", "2021-07-16", opt), + Temporal.PlainDate.from("2021-08-17").until("2021-07-16", opt), 0, -1, 0, -1, 0, 0, 0, 0, 0, 0, "negative 1 month and 1 day in a month with 31 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-08-13", "2021-07-16", opt), + Temporal.PlainDate.from("2021-08-13").until("2021-07-16", opt), 0, 0, 0, -28, 0, 0, 0, 0, 0, 0, "negative 28 days roll across a month which has 31 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-09-16", "2021-07-16", opt), + Temporal.PlainDate.from("2021-09-16").until("2021-07-16", opt), 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, "negative 2 months with both months which have 31 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2022-07-16", "2021-07-16", opt), + Temporal.PlainDate.from("2022-07-16").until("2021-07-16", opt), 0, -12, 0, 0, 0, 0, 0, 0, 0, 0, "negative 12 months"); TemporalHelpers.assertDuration( - cal.dateUntil("2031-07-16", "2021-07-16", opt), + Temporal.PlainDate.from("2031-07-16").until("2021-07-16", opt), 0, -120, 0, 0, 0, 0, 0, 0, 0, 0, "negative 120 months"); }); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/largestunit-week.js b/test/built-ins/Temporal/PlainDate/prototype/until/largestunit-week.js new file mode 100644 index 0000000000..44e44dfab4 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/largestunit-week.js @@ -0,0 +1,60 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.until +description: Date arithmetic with largestUnit "week" +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +["week", "weeks"].forEach(function(largestUnit) { + let opt = {largestUnit}; + + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-16").until("2021-07-16", opt), + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "same day"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-16").until("2021-07-17", opt), + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "one day"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-16").until("2021-07-23", opt), + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "7 days"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-16").until("2021-08-16", opt), + 0, 0, 4, 3, 0, 0, 0, 0, 0, 0, "4 weeks and 3 days"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-16").until("2021-08-13", opt), + 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, "4 weeks"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-16").until("2021-09-16", opt), + 0, 0, 8, 6, 0, 0, 0, 0, 0, 0, "8 weeks and 6 days"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-16").until("2022-07-16", opt), + 0, 0, 52, 1, 0, 0, 0, 0, 0, 0, "52 weeks and 1 day"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-16").until("2031-07-16", opt), + 0, 0, 521, 5, 0, 0, 0, 0, 0, 0, "521 weeks and 5 days"); + + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-17").until("2021-07-16", opt), + 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "negative one day"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-07-23").until("2021-07-16", opt), + 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, "negative 7 days"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-08-16").until("2021-07-16", opt), + 0, 0, -4, -3, 0, 0, 0, 0, 0, 0, "negative 4 weeks and 3 days"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-08-13").until("2021-07-16", opt), + 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, "negative 4 weeks"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2021-09-16").until("2021-07-16", opt), + 0, 0, -8, -6, 0, 0, 0, 0, 0, 0, "negative 8 weeks and 6 days"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2022-07-16").until("2021-07-16", opt), + 0, 0, -52, -1, 0, 0, 0, 0, 0, 0, "negative 52 weeks and 1 day"); + TemporalHelpers.assertDuration( + Temporal.PlainDate.from("2031-07-16").until("2021-07-16", opt), + 0, 0, -521, -5, 0, 0, 0, 0, 0, 0, "negative 521 weeks and 5 days"); +}); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/largest-unit-year.js b/test/built-ins/Temporal/PlainDate/prototype/until/largestunit-year.js similarity index 60% rename from test/built-ins/Temporal/Calendar/prototype/dateUntil/largest-unit-year.js rename to test/built-ins/Temporal/PlainDate/prototype/until/largestunit-year.js index 03773ec893..850c8de676 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateUntil/largest-unit-year.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/largestunit-year.js @@ -2,203 +2,192 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.dateuntil -description: Temporal.Calendar.prototype.dateUntil with largestUnit is "year" -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. Set one to ? ToTemporalDate(one). - 5. Set two to ? ToTemporalDate(two). - 6. Set options to ? GetOptionsObject(options). - 7. Let largestUnit be ? ToLargestTemporalUnit(options, « "hour", "minute", "second", "millisecond", "microsecond", "nanosecond" », "auto", "day"). - 8. Let result be ! DifferenceISODate(one.[[ISOYear]], one.[[ISOMonth]], one.[[ISODay]], two.[[ISOYear]], two.[[ISOMonth]], two.[[ISODay]], largestUnit). - 9. Return ? CreateTemporalDuration(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], 0, 0, 0, 0, 0, 0). +esid: sec-temporal.plaindate.prototype.until +description: Date arithmetic with largestUnit "year" features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601"); ["year", "years"].forEach(function(largestUnit) { let opt = {largestUnit}; TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-07-16", opt), + Temporal.PlainDate.from("2021-07-16").until("2021-07-16", opt), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "same day"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-07-17", opt), + Temporal.PlainDate.from("2021-07-16").until("2021-07-17", opt), 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "one day"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-07-23", opt), + Temporal.PlainDate.from("2021-07-16").until("2021-07-23", opt), 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, "7 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-08-16", opt), + Temporal.PlainDate.from("2021-07-16").until("2021-08-16", opt), 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "1 month in same year"); TemporalHelpers.assertDuration( - cal.dateUntil("2020-12-16", "2021-01-16", opt), + Temporal.PlainDate.from("2020-12-16").until("2021-01-16", opt), 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "1 month in different year"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-01-05", "2021-02-05", opt), + Temporal.PlainDate.from("2021-01-05").until("2021-02-05", opt), 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "1 month in same year"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-01-07", "2021-03-07", opt), + Temporal.PlainDate.from("2021-01-07").until("2021-03-07", opt), 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, "2 month in same year across Feb 28"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-08-17", opt), + Temporal.PlainDate.from("2021-07-16").until("2021-08-17", opt), 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, "1 month and 1 day in a month with 31 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-08-13", opt), + Temporal.PlainDate.from("2021-07-16").until("2021-08-13", opt), 0, 0, 0, 28, 0, 0, 0, 0, 0, 0, "28 days roll across a month which has 31 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-09-16", opt), + Temporal.PlainDate.from("2021-07-16").until("2021-09-16", opt), 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, "2 months with both months which have 31 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2022-07-16", opt), + Temporal.PlainDate.from("2021-07-16").until("2022-07-16", opt), 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "1 year"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2031-07-16", opt), + Temporal.PlainDate.from("2021-07-16").until("2031-07-16", opt), 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, "10 years"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2022-07-19", opt), + Temporal.PlainDate.from("2021-07-16").until("2022-07-19", opt), 1, 0, 0, 3, 0, 0, 0, 0, 0, 0, "1 year and 3 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2022-09-19", opt), + Temporal.PlainDate.from("2021-07-16").until("2022-09-19", opt), 1, 2, 0, 3, 0, 0, 0, 0, 0, 0, "1 year 2 months and 3 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2031-12-16", opt), + Temporal.PlainDate.from("2021-07-16").until("2031-12-16", opt), 10, 5, 0, 0, 0, 0, 0, 0, 0, 0, "10 years and 5 months"); TemporalHelpers.assertDuration( - cal.dateUntil("1997-12-16", "2021-07-16", opt), + Temporal.PlainDate.from("1997-12-16").until("2021-07-16", opt), 23, 7, 0, 0, 0, 0, 0, 0, 0, 0, "23 years and 7 months"); TemporalHelpers.assertDuration( - cal.dateUntil("1997-07-16", "2021-07-16", opt), + Temporal.PlainDate.from("1997-07-16").until("2021-07-16", opt), 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, "24 years"); TemporalHelpers.assertDuration( - cal.dateUntil("1997-07-16", "2021-07-15", opt), + Temporal.PlainDate.from("1997-07-16").until("2021-07-15", opt), 23, 11, 0, 29, 0, 0, 0, 0, 0, 0, "23 years, 11 months and 29 days"); TemporalHelpers.assertDuration( - cal.dateUntil("1997-06-16", "2021-06-15", opt), + Temporal.PlainDate.from("1997-06-16").until("2021-06-15", opt), 23, 11, 0, 30, 0, 0, 0, 0, 0, 0, "23 years, 11 months and 30 days"); TemporalHelpers.assertDuration( - cal.dateUntil("1960-02-16", "2020-03-16", opt), + Temporal.PlainDate.from("1960-02-16").until("2020-03-16", opt), 60, 1, 0, 0, 0, 0, 0, 0, 0, 0, "60 years, 1 month"); TemporalHelpers.assertDuration( - cal.dateUntil("1960-02-16", "2021-03-15", opt), + Temporal.PlainDate.from("1960-02-16").until("2021-03-15", opt), 61, 0, 0, 27, 0, 0, 0, 0, 0, 0, "61 years, 27 days in non leap year"); TemporalHelpers.assertDuration( - cal.dateUntil("1960-02-16", "2020-03-15", opt), + Temporal.PlainDate.from("1960-02-16").until("2020-03-15", opt), 60, 0, 0, 28, 0, 0, 0, 0, 0, 0, "60 years, 28 days in leap year"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-03-30", "2021-07-16", opt), + Temporal.PlainDate.from("2021-03-30").until("2021-07-16", opt), 0, 3, 0, 16, 0, 0, 0, 0, 0, 0, "3 months and 16 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2020-03-30", "2021-07-16", opt), + Temporal.PlainDate.from("2020-03-30").until("2021-07-16", opt), 1, 3, 0, 16, 0, 0, 0, 0, 0, 0, "1 year, 3 months and 16 days"); TemporalHelpers.assertDuration( - cal.dateUntil("1960-03-30", "2021-07-16", opt), + Temporal.PlainDate.from("1960-03-30").until("2021-07-16", opt), 61, 3, 0, 16, 0, 0, 0, 0, 0, 0, "61 years, 3 months and 16 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2019-12-30", "2021-07-16", opt), + Temporal.PlainDate.from("2019-12-30").until("2021-07-16", opt), 1, 6, 0, 16, 0, 0, 0, 0, 0, 0, "1 year, 6 months and 16 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2020-12-30", "2021-07-16", opt), + Temporal.PlainDate.from("2020-12-30").until("2021-07-16", opt), 0, 6, 0, 16, 0, 0, 0, 0, 0, 0, "6 months and 16 days"); TemporalHelpers.assertDuration( - cal.dateUntil("1997-12-30", "2021-07-16", opt), + Temporal.PlainDate.from("1997-12-30").until("2021-07-16", opt), 23, 6, 0, 16, 0, 0, 0, 0, 0, 0, "23 years, 6 months and 16 days"); TemporalHelpers.assertDuration( - cal.dateUntil("0001-12-25", "2021-07-16", opt), + Temporal.PlainDate.from("0001-12-25").until("2021-07-16", opt), 2019, 6, 0, 21, 0, 0, 0, 0, 0, 0, "2019 years, 6 months and 21 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2019-12-30", "2021-03-05", opt), + Temporal.PlainDate.from("2019-12-30").until("2021-03-05", opt), 1, 2, 0, 5, 0, 0, 0, 0, 0, 0, "1 year, 2 months and 5 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-17", "2021-07-16", opt), + Temporal.PlainDate.from("2021-07-17").until("2021-07-16", opt), 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "negative one day"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-23", "2021-07-16", opt), + Temporal.PlainDate.from("2021-07-23").until("2021-07-16", opt), 0, 0, 0, -7, 0, 0, 0, 0, 0, 0, "negative 7 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-08-16", "2021-07-16", opt), + Temporal.PlainDate.from("2021-08-16").until("2021-07-16", opt), 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, "negative 1 month in same year"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-01-16", "2020-12-16", opt), + Temporal.PlainDate.from("2021-01-16").until("2020-12-16", opt), 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, "negative 1 month in different year"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-02-05", "2021-01-05", opt), + Temporal.PlainDate.from("2021-02-05").until("2021-01-05", opt), 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, "negative 1 month in same year"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-03-07", "2021-01-07", opt), + Temporal.PlainDate.from("2021-03-07").until("2021-01-07", opt), 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, "negative 2 month in same year across Feb 28"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-08-17", "2021-07-16", opt), + Temporal.PlainDate.from("2021-08-17").until("2021-07-16", opt), 0, -1, 0, -1, 0, 0, 0, 0, 0, 0, "negative 1 month and 1 day in a month with 31 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-08-13", "2021-07-16", opt), + Temporal.PlainDate.from("2021-08-13").until("2021-07-16", opt), 0, 0, 0, -28, 0, 0, 0, 0, 0, 0, "negative 28 days roll across a month which has 31 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-09-16", "2021-07-16", opt), + Temporal.PlainDate.from("2021-09-16").until("2021-07-16", opt), 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, "negative 2 months with both months which have 31 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2022-07-16", "2021-07-16", opt), + Temporal.PlainDate.from("2022-07-16").until("2021-07-16", opt), -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "negative 1 year"); TemporalHelpers.assertDuration( - cal.dateUntil("2031-07-16", "2021-07-16", opt), + Temporal.PlainDate.from("2031-07-16").until("2021-07-16", opt), -10, 0, 0, 0, 0, 0, 0, 0, 0, 0, "negative 10 years"); TemporalHelpers.assertDuration( - cal.dateUntil("2022-07-19", "2021-07-16", opt), + Temporal.PlainDate.from("2022-07-19").until("2021-07-16", opt), -1, 0, 0, -3, 0, 0, 0, 0, 0, 0, "negative 1 year and 3 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2022-09-19", "2021-07-16", opt), + Temporal.PlainDate.from("2022-09-19").until("2021-07-16", opt), -1, -2, 0, -3, 0, 0, 0, 0, 0, 0, "negative 1 year 2 months and 3 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2031-12-16", "2021-07-16", opt), + Temporal.PlainDate.from("2031-12-16").until("2021-07-16", opt), -10, -5, 0, 0, 0, 0, 0, 0, 0, 0, "negative 10 years and 5 months"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "1997-12-16", opt), + Temporal.PlainDate.from("2021-07-16").until("1997-12-16", opt), -23, -7, 0, 0, 0, 0, 0, 0, 0, 0, "negative 23 years and 7 months"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "1997-07-16", opt), + Temporal.PlainDate.from("2021-07-16").until("1997-07-16", opt), -24, 0, 0, 0, 0, 0, 0, 0, 0, 0, "negative 24 years"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-15", "1997-07-16", opt), + Temporal.PlainDate.from("2021-07-15").until("1997-07-16", opt), -23, -11, 0, -30, 0, 0, 0, 0, 0, 0, "negative 23 years, 11 months and 30 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-06-15", "1997-06-16", opt), + Temporal.PlainDate.from("2021-06-15").until("1997-06-16", opt), -23, -11, 0, -29, 0, 0, 0, 0, 0, 0, "negative 23 years, 11 months and 29 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2020-03-16", "1960-02-16", opt), + Temporal.PlainDate.from("2020-03-16").until("1960-02-16", opt), -60, -1, 0, 0, 0, 0, 0, 0, 0, 0, "negative 60 years, 1 month"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-03-15", "1960-02-16", opt), + Temporal.PlainDate.from("2021-03-15").until("1960-02-16", opt), -61, 0, 0, -28, 0, 0, 0, 0, 0, 0, "negative 61 years, 28 days in non leap year"); TemporalHelpers.assertDuration( - cal.dateUntil("2020-03-15", "1960-02-16", opt), + Temporal.PlainDate.from("2020-03-15").until("1960-02-16", opt), -60, 0, 0, -28, 0, 0, 0, 0, 0, 0, "negative 60 years, 28 days in leap year"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-03-30", opt), + Temporal.PlainDate.from("2021-07-16").until("2021-03-30", opt), 0, -3, 0, -17, 0, 0, 0, 0, 0, 0, "negative 3 months and 17 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2020-03-30", opt), + Temporal.PlainDate.from("2021-07-16").until("2020-03-30", opt), -1, -3, 0, -17, 0, 0, 0, 0, 0, 0, "negative 1 year, 3 months and 17 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "1960-03-30", opt), + Temporal.PlainDate.from("2021-07-16").until("1960-03-30", opt), -61, -3, 0, -17, 0, 0, 0, 0, 0, 0, "negative 61 years, 3 months and 17 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2019-12-30", opt), + Temporal.PlainDate.from("2021-07-16").until("2019-12-30", opt), -1, -6, 0, -17, 0, 0, 0, 0, 0, 0, "negative 1 year, 6 months and 17 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2020-12-30", opt), + Temporal.PlainDate.from("2021-07-16").until("2020-12-30", opt), 0, -6, 0, -17, 0, 0, 0, 0, 0, 0, "negative 6 months and 17 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "1997-12-30", opt), + Temporal.PlainDate.from("2021-07-16").until("1997-12-30", opt), -23, -6, 0, -17, 0, 0, 0, 0, 0, 0, "negative 23 years, 6 months and 17 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "0001-12-25", opt), + Temporal.PlainDate.from("2021-07-16").until("0001-12-25", opt), -2019, -6, 0, -22, 0, 0, 0, 0, 0, 0, "negative 2019 years, 6 months and 22 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-03-05", "2019-12-30", opt), + Temporal.PlainDate.from("2021-03-05").until("2019-12-30", opt), -1, -2, 0, -6, 0, 0, 0, 0, 0, 0, "negative 1 year, 2 months and 6 days"); }); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/no-options.js b/test/built-ins/Temporal/PlainDate/prototype/until/no-options.js similarity index 70% rename from test/built-ins/Temporal/Calendar/prototype/dateUntil/no-options.js rename to test/built-ins/Temporal/PlainDate/prototype/until/no-options.js index 962400e354..dc686e63c1 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateUntil/no-options.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/no-options.js @@ -2,8 +2,8 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.dateuntil -description: Temporal.Calendar.prototype.dateUntil with no options +esid: sec-temporal.plaindate.prototype.until +description: With no options info: | 1. Let calendar be the this value. 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). @@ -17,40 +17,38 @@ info: | features: [Temporal] includes: [temporalHelpers.js] ---*/ -let cal = new Temporal.Calendar("iso8601"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-07-16"), + Temporal.PlainDate.from("2021-07-16").until("2021-07-16"), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "same day"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-07-17"), + Temporal.PlainDate.from("2021-07-16").until("2021-07-17"), 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "one day"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-08-17"), + Temporal.PlainDate.from("2021-07-16").until("2021-08-17"), 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, "32 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2021-09-16"), + Temporal.PlainDate.from("2021-07-16").until("2021-09-16"), 0, 0, 0, 62, 0, 0, 0, 0, 0, 0, "62 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2022-07-16"), + Temporal.PlainDate.from("2021-07-16").until("2022-07-16"), 0, 0, 0, 365, 0, 0, 0, 0, 0, 0, "365 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-16", "2031-07-16"), + Temporal.PlainDate.from("2021-07-16").until("2031-07-16"), 0, 0, 0, 3652, 0, 0, 0, 0, 0, 0, "3652 days"); - TemporalHelpers.assertDuration( - cal.dateUntil("2021-07-17", "2021-07-16"), + Temporal.PlainDate.from("2021-07-17").until("2021-07-16"), 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "negative one day"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-08-17", "2021-07-16"), + Temporal.PlainDate.from("2021-08-17").until("2021-07-16"), 0, 0, 0, -32, 0, 0, 0, 0, 0, 0, "negative 32 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2021-09-16", "2021-07-16"), + Temporal.PlainDate.from("2021-09-16").until("2021-07-16"), 0, 0, 0, -62, 0, 0, 0, 0, 0, 0, "negative 62 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2022-07-16", "2021-07-16"), + Temporal.PlainDate.from("2022-07-16").until("2021-07-16"), 0, 0, 0, -365, 0, 0, 0, 0, 0, 0, "negative 365 days"); TemporalHelpers.assertDuration( - cal.dateUntil("2031-07-16", "2021-07-16"), + Temporal.PlainDate.from("2031-07-16").until("2021-07-16"), 0, 0, 0, -3652, 0, 0, 0, 0, 0, 0, "negative 3652 days"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/order-of-operations.js b/test/built-ins/Temporal/PlainDate/prototype/until/order-of-operations.js index 6061d392f6..adce3da784 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/order-of-operations.js @@ -11,30 +11,6 @@ features: [Temporal] const expected = [ // ToTemporalDate "get other.calendar", - "has other.calendar.dateAdd", - "has other.calendar.dateFromFields", - "has other.calendar.dateUntil", - "has other.calendar.day", - "has other.calendar.dayOfWeek", - "has other.calendar.dayOfYear", - "has other.calendar.daysInMonth", - "has other.calendar.daysInWeek", - "has other.calendar.daysInYear", - "has other.calendar.fields", - "has other.calendar.id", - "has other.calendar.inLeapYear", - "has other.calendar.mergeFields", - "has other.calendar.month", - "has other.calendar.monthCode", - "has other.calendar.monthDayFromFields", - "has other.calendar.monthsInYear", - "has other.calendar.weekOfYear", - "has other.calendar.year", - "has other.calendar.yearMonthFromFields", - "has other.calendar.yearOfWeek", - "get other.calendar.dateFromFields", - "get other.calendar.fields", - "call other.calendar.fields", "get other.day", "get other.day.valueOf", "call other.day.valueOf", @@ -47,29 +23,17 @@ const expected = [ "get other.year", "get other.year.valueOf", "call other.year.valueOf", - "call other.calendar.dateFromFields", - // CalendarEquals - "get this.calendar.id", - "get other.calendar.id", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.roundingIncrement", - "get options.roundingIncrement", - "getOwnPropertyDescriptor options.roundingMode", - "get options.roundingMode", - "getOwnPropertyDescriptor options.largestUnit", - "get options.largestUnit", - "getOwnPropertyDescriptor options.smallestUnit", - "get options.smallestUnit", - "getOwnPropertyDescriptor options.additional", - "get options.additional", // GetDifferenceSettings + "get options.largestUnit", "get options.largestUnit.toString", "call options.largestUnit.toString", + "get options.roundingIncrement", "get options.roundingIncrement.valueOf", "call options.roundingIncrement.valueOf", + "get options.roundingMode", "get options.roundingMode.toString", "call options.roundingMode.toString", + "get options.smallestUnit", "get options.smallestUnit.toString", "call options.smallestUnit.toString", ]; @@ -97,97 +61,7 @@ function createOptionsObserver({ smallestUnit = "days", largestUnit = "auto", ro }, "options"); } -// clear any observable things that happened while constructing the objects -actual.splice(0); - // basic order of observable operations with calendar call, without rounding: instance.until(otherDatePropertyBag, createOptionsObserver({ largestUnit: "years" })); -assert.compareArray(actual, expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", -]), "order of operations"); +assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -// short-circuit for identical objects: - -const identicalPropertyBag = TemporalHelpers.propertyBagObserver(actual, { - year: 2000, - month: 5, - monthCode: "M05", - day: 2, - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), -}, "other"); - -instance.since(identicalPropertyBag, createOptionsObserver()); -assert.compareArray(actual, expected, "order of operations with identical dates"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest year: -const expectedOpsForYearRounding = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.until(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "years" })); -assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest year and skips a DateUntil call: -const otherDatePropertyBagSameMonth = TemporalHelpers.propertyBagObserver(actual, { - year: 2001, - month: 5, - monthCode: "M05", - day: 2, - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), -}, "other"); -const expectedOpsForYearRoundingSameMonth = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.until(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" })); -assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest month: -const expectedOpsForMonthRounding = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.until(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "months" })); -assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest week: -const expectedOpsForWeekRounding = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateUntil", - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.until(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "weeks" })); -assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks"); diff --git a/test/intl402/Temporal/Calendar/prototype/dateUntil/zero-length-duration-result.js b/test/built-ins/Temporal/PlainDate/prototype/until/zero-length-duration-result.js similarity index 58% rename from test/intl402/Temporal/Calendar/prototype/dateUntil/zero-length-duration-result.js rename to test/built-ins/Temporal/PlainDate/prototype/until/zero-length-duration-result.js index e852a60f4b..58fdbc6c4e 100644 --- a/test/intl402/Temporal/Calendar/prototype/dateUntil/zero-length-duration-result.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/zero-length-duration-result.js @@ -3,14 +3,14 @@ /*--- description: The duration from a date to itself is a zero duration (PT0S) -esid: sec-temporal.calendar.prototype.dateuntil +esid: sec-temporal.plaindate.prototype.until features: [Temporal] +includes: [temporalHelpers.js] ---*/ -const instance = new Temporal.Calendar("gregory"); const date = new Temporal.PlainDate(2001, 6, 3); ['year', 'month', 'week', 'day'].forEach((largestUnit) => { - const result = instance.dateUntil(date, date, { largestUnit }); - assert.sameValue(result.toString(), 'PT0S'); + const result = date.until(date, { largestUnit }); + TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "The duration from a date to itself is zero") }); diff --git a/test/built-ins/Temporal/PlainDate/prototype/with/order-of-operations.js b/test/built-ins/Temporal/PlainDate/prototype/with/order-of-operations.js index 65da7f52d2..3e3d1b1df5 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/with/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDate/prototype/with/order-of-operations.js @@ -12,27 +12,10 @@ const expected = [ // RejectObjectWithCalendarOrTimeZone "get fields.calendar", "get fields.timeZone", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", + // GetTemporalOverflowOption "get options.overflow", - "getOwnPropertyDescriptor options.extra", - "get options.extra", - // lookup - "get this.calendar.dateFromFields", - "get this.calendar.fields", - "get this.calendar.mergeFields", - // CalendarFields - "call this.calendar.fields", - // PrepareTemporalFields on receiver - "get this.calendar.day", - "call this.calendar.day", - "get this.calendar.month", - "call this.calendar.month", - "get this.calendar.monthCode", - "call this.calendar.monthCode", - "get this.calendar.year", - "call this.calendar.year", + "get options.overflow.toString", + "call options.overflow.toString", // PrepareTemporalFields on argument "get fields.day", "get fields.day.valueOf", @@ -46,13 +29,6 @@ const expected = [ "get fields.year", "get fields.year.valueOf", "call fields.year.valueOf", - // CalendarMergeFields - "call this.calendar.mergeFields", - // CalendarDateFromFields - "call this.calendar.dateFromFields", - // inside Calendar.p.dateFromFields - "get options.overflow.toString", - "call options.overflow.toString", ]; const actual = []; diff --git a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-case-insensitive.js b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-case-insensitive.js index 6a0ce65d69..db18d84e8a 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-case-insensitive.js +++ b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-case-insensitive.js @@ -7,29 +7,7 @@ description: Calendar names are case-insensitive features: [Temporal] ---*/ -const instance = new Temporal.PlainDate(1976, 11, 18, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.PlainDate(1976, 11, 18, "iso8601"); let arg = "iSo8601"; const result = instance.withCalendar(arg); diff --git a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-iso-string.js b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-iso-string.js index aa99e6cae0..c9afdf80c9 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-iso-string.js +++ b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-iso-string.js @@ -7,29 +7,7 @@ description: An ISO 8601 string can be converted to a calendar ID in Calendar features: [Temporal] ---*/ -const instance = new Temporal.PlainDate(1976, 11, 18, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.PlainDate(1976, 11, 18, "iso8601"); for (const arg of [ "2020-01-01", diff --git a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js index 370ebb6af8..e0cfb96795 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js +++ b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js @@ -7,29 +7,7 @@ description: A number is not allowed to be a calendar features: [Temporal] ---*/ -const instance = new Temporal.PlainDate(1976, 11, 18, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.PlainDate(1976, 11, 18, "iso8601"); const numbers = [ 1, diff --git a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-string-leap-second.js b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-string-leap-second.js index 604f608538..c73c5449dc 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-string-leap-second.js +++ b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-string-leap-second.js @@ -7,29 +7,7 @@ description: Leap second is a valid ISO string for Calendar features: [Temporal] ---*/ -const instance = new Temporal.PlainDate(1976, 11, 18, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.PlainDate(1976, 11, 18, "iso8601"); const arg = "2016-12-31T23:59:60"; const result = instance.withCalendar(arg); diff --git a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-string.js b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-string.js index 90a2149df6..a252f2ebc3 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-string.js +++ b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-string.js @@ -7,29 +7,7 @@ description: A calendar ID is valid input for Calendar features: [Temporal] ---*/ -const instance = new Temporal.PlainDate(1976, 11, 18, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.PlainDate(1976, 11, 18, "iso8601"); const arg = "iso8601"; diff --git a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-temporal-object.js b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-temporal-object.js index 24ba4c7d1e..4cb7bd1e99 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-temporal-object.js +++ b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-temporal-object.js @@ -3,7 +3,9 @@ /*--- esid: sec-temporal.plaindate.prototype.withcalendar -description: Fast path for converting other Temporal objects to Temporal.Calendar by reading internal slots +description: > + Fast path for converting other Temporal objects to calendar ID by reading + internal slots info: | sec-temporal-totemporalcalendar step 1.b: b. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then @@ -31,29 +33,7 @@ const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UT }, }); - const instance = new Temporal.PlainDate(1976, 11, 18, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); + const instance = new Temporal.PlainDate(1976, 11, 18, "iso8601"); const result = instance.withCalendar(arg); assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-wrong-type.js index b0c2796a33..944eec4a60 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-wrong-type.js @@ -5,33 +5,11 @@ esid: sec-temporal.plaindate.prototype.withcalendar description: > Appropriate error thrown when argument cannot be converted to a valid string - or object for Calendar + for Calendar features: [BigInt, Symbol, Temporal] ---*/ -const instance = new Temporal.PlainDate(1976, 11, 18, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.PlainDate(1976, 11, 18, "iso8601"); const primitiveTests = [ [null, "null"], diff --git a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/subclassing-ignored.js b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/subclassing-ignored.js index 2762a40ed8..e237dcbb98 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/subclassing-ignored.js +++ b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/subclassing-ignored.js @@ -8,40 +8,13 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const customCalendar = { - era() { return undefined; }, - eraYear() { return undefined; }, - year() { return 1900; }, - month() { return 2; }, - monthCode() { return "M02"; }, - day() { return 5; }, - id: "custom-calendar", - toString() { return "custom-calendar"; }, - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - TemporalHelpers.checkSubclassingIgnored( Temporal.PlainDate, [2000, 5, 2], "withCalendar", - [customCalendar], + ["iso8601"], (result) => { - TemporalHelpers.assertPlainDate(result, 1900, 2, "M02", 5); - assert.sameValue(result.getISOFields().calendar, customCalendar, "calendar result"); + TemporalHelpers.assertPlainDate(result, 2000, 5, "M05", 2); + assert.sameValue(result.getISOFields().calendar, "iso8601", "calendar result"); }, ); diff --git a/test/built-ins/Temporal/PlainDateTime/compare/exhaustive.js b/test/built-ins/Temporal/PlainDateTime/compare/exhaustive.js index ae19ccbf27..d1043059e3 100644 --- a/test/built-ins/Temporal/PlainDateTime/compare/exhaustive.js +++ b/test/built-ins/Temporal/PlainDateTime/compare/exhaustive.js @@ -7,157 +7,154 @@ description: Tests for compare() with each possible outcome features: [Temporal] ---*/ -const cal1 = "iso8601"; -const cal2 = new (class extends Temporal.Calendar { id = "custom"; })("iso8601"); - assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111, cal1), - new Temporal.PlainDateTime(1987, 5, 31, 12, 15, 45, 333, 777, 111, cal2) + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111), + new Temporal.PlainDateTime(1987, 5, 31, 12, 15, 45, 333, 777, 111) ), 1, "year >" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(1981, 12, 15, 6, 30, 15, 222, 444, 6, cal1), - new Temporal.PlainDateTime(2048, 12, 15, 6, 30, 15, 222, 444, 6, cal2) + new Temporal.PlainDateTime(1981, 12, 15, 6, 30, 15, 222, 444, 6), + new Temporal.PlainDateTime(2048, 12, 15, 6, 30, 15, 222, 444, 6) ), -1, "year <" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111, cal1), - new Temporal.PlainDateTime(2000, 3, 31, 12, 15, 45, 333, 777, 111, cal2) + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111), + new Temporal.PlainDateTime(2000, 3, 31, 12, 15, 45, 333, 777, 111) ), 1, "month >" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 444, 6, cal1), - new Temporal.PlainDateTime(1981, 12, 15, 6, 30, 15, 222, 444, 6, cal2) + new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 444, 6), + new Temporal.PlainDateTime(1981, 12, 15, 6, 30, 15, 222, 444, 6) ), -1, "month <" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111, cal1), - new Temporal.PlainDateTime(2000, 5, 14, 12, 15, 45, 333, 777, 111, cal2) + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111), + new Temporal.PlainDateTime(2000, 5, 14, 12, 15, 45, 333, 777, 111) ), 1, "day >" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 444, 6, cal1), - new Temporal.PlainDateTime(1981, 4, 21, 6, 30, 15, 222, 444, 6, cal2) + new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 444, 6), + new Temporal.PlainDateTime(1981, 4, 21, 6, 30, 15, 222, 444, 6) ), -1, "day <" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111, cal1), - new Temporal.PlainDateTime(2000, 5, 31, 6, 15, 45, 333, 777, 111, cal2) + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111), + new Temporal.PlainDateTime(2000, 5, 31, 6, 15, 45, 333, 777, 111) ), 1, "hour >" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 444, 6, cal1), - new Temporal.PlainDateTime(1981, 4, 15, 22, 30, 15, 222, 444, 6, cal2) + new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 444, 6), + new Temporal.PlainDateTime(1981, 4, 15, 22, 30, 15, 222, 444, 6) ), -1, "hour <" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111, cal1), - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 22, 333, 777, 111, cal2) + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111), + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 22, 333, 777, 111) ), 1, "minute >" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 444, 6, cal1), - new Temporal.PlainDateTime(1981, 4, 15, 6, 57, 15, 222, 444, 6, cal2) + new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 444, 6), + new Temporal.PlainDateTime(1981, 4, 15, 6, 57, 15, 222, 444, 6) ), -1, "minute <" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 6, 333, 777, 111, cal1), - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 5, 333, 777, 111, cal2) + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 6, 333, 777, 111), + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 5, 333, 777, 111) ), 1, "second >" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 3, 222, 444, 6, cal1), - new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 4, 222, 444, 6, cal2) + new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 3, 222, 444, 6), + new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 4, 222, 444, 6) ), -1, "second <" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 6, 777, 111, cal1), - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 5, 777, 111, cal2) + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 6, 777, 111), + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 5, 777, 111) ), 1, "millisecond >" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 3, 444, 6, cal1), - new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 4, 444, 6, cal2) + new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 3, 444, 6), + new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 4, 444, 6) ), -1, "millisecond <" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 6, 111, cal1), - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 5, 111, cal2) + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 6, 111), + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 5, 111) ), 1, "microsecond >" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 3, 6, cal1), - new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 4, 6, cal2) + new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 3, 6), + new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 4, 6) ), -1, "microsecond <" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 999, cal1), - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111, cal2) + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 999), + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111) ), 1, "nanosecond >" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 444, 0, cal1), - new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 444, 6, cal2) + new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 444, 0), + new Temporal.PlainDateTime(1981, 4, 15, 6, 30, 15, 222, 444, 6) ), -1, "nanosecond <" ); assert.sameValue( Temporal.PlainDateTime.compare( - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111, cal1), - new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111, cal2) + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111), + new Temporal.PlainDateTime(2000, 5, 31, 12, 15, 45, 333, 777, 111) ), 0, "=" diff --git a/test/built-ins/Temporal/PlainDateTime/from/observable-get-overflow-argument-primitive.js b/test/built-ins/Temporal/PlainDateTime/from/observable-get-overflow-argument-primitive.js index babe403a9c..252511ed7a 100644 --- a/test/built-ins/Temporal/PlainDateTime/from/observable-get-overflow-argument-primitive.js +++ b/test/built-ins/Temporal/PlainDateTime/from/observable-get-overflow-argument-primitive.js @@ -9,8 +9,6 @@ features: [Temporal] ---*/ const expected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", @@ -24,11 +22,6 @@ assert.compareArray(actual, expected, "Successful call"); TemporalHelpers.assertPlainDateTime(result, 2021, 5, "M05", 17, 12, 34, 56, 0, 0, 0); actual.splice(0); // empty it for the next check -const failureExpected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", - "get options.overflow", -]; assert.throws(TypeError, () => Temporal.PlainDateTime.from(7, options)); -assert.compareArray(actual, failureExpected, "Failing call"); +assert.compareArray(actual, expected, "Failing call"); diff --git a/test/built-ins/Temporal/PlainDateTime/from/observable-get-overflow-argument-string-invalid.js b/test/built-ins/Temporal/PlainDateTime/from/observable-get-overflow-argument-string-invalid.js index 9eff4e745b..1fd76087a5 100644 --- a/test/built-ins/Temporal/PlainDateTime/from/observable-get-overflow-argument-string-invalid.js +++ b/test/built-ins/Temporal/PlainDateTime/from/observable-get-overflow-argument-string-invalid.js @@ -9,9 +9,9 @@ features: [Temporal] ---*/ const expected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", + "get options.overflow.toString", + "call options.overflow.toString", ]; let actual = []; diff --git a/test/built-ins/Temporal/PlainDateTime/from/order-of-operations.js b/test/built-ins/Temporal/PlainDateTime/from/order-of-operations.js index 973fea62d1..f19ffb3522 100644 --- a/test/built-ins/Temporal/PlainDateTime/from/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDateTime/from/order-of-operations.js @@ -9,40 +9,12 @@ features: [Temporal] ---*/ const expected = [ - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", + // GetTemporalOverflowOption "get options.overflow", - "getOwnPropertyDescriptor options.extra", - "get options.extra", + "get options.overflow.toString", + "call options.overflow.toString", // GetTemporalCalendarSlotValueWithISODefault "get fields.calendar", - "has fields.calendar.dateAdd", - "has fields.calendar.dateFromFields", - "has fields.calendar.dateUntil", - "has fields.calendar.day", - "has fields.calendar.dayOfWeek", - "has fields.calendar.dayOfYear", - "has fields.calendar.daysInMonth", - "has fields.calendar.daysInWeek", - "has fields.calendar.daysInYear", - "has fields.calendar.fields", - "has fields.calendar.id", - "has fields.calendar.inLeapYear", - "has fields.calendar.mergeFields", - "has fields.calendar.month", - "has fields.calendar.monthCode", - "has fields.calendar.monthDayFromFields", - "has fields.calendar.monthsInYear", - "has fields.calendar.weekOfYear", - "has fields.calendar.year", - "has fields.calendar.yearMonthFromFields", - "has fields.calendar.yearOfWeek", - // lookup - "get fields.calendar.dateFromFields", - "get fields.calendar.fields", - // CalendarFields - "call fields.calendar.fields", // PrepareTemporalFields "get fields.day", "get fields.day.valueOf", @@ -74,10 +46,6 @@ const expected = [ "get fields.year", "get fields.year.valueOf", "call fields.year.valueOf", - // InterpretTemporalDateTimeFields - "get options.overflow.toString", - "call options.overflow.toString", - "call fields.calendar.dateFromFields", ]; const actual = []; diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/add/order-of-operations.js b/test/built-ins/Temporal/PlainDateTime/prototype/add/order-of-operations.js index 978a940f9e..10a5c9e45d 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/add/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/add/order-of-operations.js @@ -40,10 +40,6 @@ const expected = [ "get fields.years", "get fields.years.valueOf", "call fields.years.valueOf", - // AddDateTime -> AddDate - "get this.calendar.dateAdd", - "call this.calendar.dateAdd", - // inside Calendar.p.dateAdd "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", @@ -73,51 +69,3 @@ instance.add(fields, options); assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -const noCalendarExpected = [ - // ToTemporalDurationRecord - "get fields.days", - "get fields.days.valueOf", - "call fields.days.valueOf", - "get fields.hours", - "get fields.hours.valueOf", - "call fields.hours.valueOf", - "get fields.microseconds", - "get fields.microseconds.valueOf", - "call fields.microseconds.valueOf", - "get fields.milliseconds", - "get fields.milliseconds.valueOf", - "call fields.milliseconds.valueOf", - "get fields.minutes", - "get fields.minutes.valueOf", - "call fields.minutes.valueOf", - "get fields.months", - "get fields.nanoseconds", - "get fields.nanoseconds.valueOf", - "call fields.nanoseconds.valueOf", - "get fields.seconds", - "get fields.seconds.valueOf", - "call fields.seconds.valueOf", - "get fields.weeks", - "get fields.years", - "get this.calendar.dateAdd", - // AddDateTime -> AddDate - "get options.overflow", - "get options.overflow.toString", - "call options.overflow.toString", -]; - -const noCalendarFields = TemporalHelpers.propertyBagObserver(actual, { - days: 1, - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1, - nanoseconds: 1, -}, "fields"); - -instance.add(noCalendarFields, options); -assert.compareArray(actual, noCalendarExpected, "order of operations with no calendar operation"); - -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/equals/calendar-checked.js b/test/built-ins/Temporal/PlainDateTime/prototype/equals/calendar-checked.js index bd13a76186..8f569cda59 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/equals/calendar-checked.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/equals/calendar-checked.js @@ -8,102 +8,15 @@ includes: [compareArray.js,temporalHelpers.js] features: [Temporal] ---*/ -const actual = []; - -function makeCalendar(id, objectName) { - const calendar = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, - }; - TemporalHelpers.observeProperty(actual, calendar, "id", id, objectName); - return calendar; -} - -const calendar1 = makeCalendar("A", "calendar1"); -const calendar2 = makeCalendar("A", "calendar2"); -const calendar3 = makeCalendar("B", "calendar3"); -const dt1 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, calendar1); -const dt1b = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, calendar1); -const dt2 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, calendar2); -const dt3 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, calendar3); -actual.splice(0); // disregard the HasProperty checks done in the constructor - -assert.sameValue(dt1.equals(dt1b), true, "same calendar object"); -assert.compareArray(actual, []); +const dt1 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "iso8601"); +const dt2 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "iso8601"); +const dt3 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "gregory"); assert.sameValue(dt1.equals(dt2), true, "same calendar string"); -assert.compareArray(actual, ["get calendar1.id", "get calendar2.id"]); - -actual.splice(0); // empty it for the next check assert.sameValue(dt1.equals(dt3), false, "different calendar string"); -assert.compareArray(actual, ["get calendar1.id", "get calendar3.id"]); -const calendar4 = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - get id() { TemporalHelpers.assertUnreachable('should not get calendar4.id'); }, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -const calendar5 = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - get id() { TemporalHelpers.assertUnreachable('should not get calendar5.id'); }, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -const dt4 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, calendar4); -const dt5 = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102, calendar4); -const dt6 = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102, calendar5); +const dt4 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "iso8601"); +const dt5 = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102, "iso8601"); +const dt6 = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102, "gregory"); assert.sameValue(dt4.equals(dt5), false, "not equal same calendar"); assert.sameValue(dt4.equals(dt6), false, "not equal different calendar"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/different-calendars-throws.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/different-calendars-throws.js index 19c34416c2..837da7f242 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/since/different-calendars-throws.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/different-calendars-throws.js @@ -8,29 +8,7 @@ features: [Temporal] ---*/ const dt1 = new Temporal.PlainDateTime(2000, 1, 1, 0, 0, 0, 0, 0, 0); -const dt2 = new Temporal.PlainDateTime(2000, 1, 1, 0, 0, 0, 0, 0, 0, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "custom", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const dt2 = new Temporal.PlainDateTime(2000, 1, 1, 0, 0, 0, 0, 0, 0, "gregory"); assert.throws( RangeError, diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/order-of-operations.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/order-of-operations.js index c076a0e6fa..8fdccbdf0b 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/since/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/order-of-operations.js @@ -11,30 +11,6 @@ features: [Temporal] const expected = [ // ToTemporalDateTime "get other.calendar", - "has other.calendar.dateAdd", - "has other.calendar.dateFromFields", - "has other.calendar.dateUntil", - "has other.calendar.day", - "has other.calendar.dayOfWeek", - "has other.calendar.dayOfYear", - "has other.calendar.daysInMonth", - "has other.calendar.daysInWeek", - "has other.calendar.daysInYear", - "has other.calendar.fields", - "has other.calendar.id", - "has other.calendar.inLeapYear", - "has other.calendar.mergeFields", - "has other.calendar.month", - "has other.calendar.monthCode", - "has other.calendar.monthDayFromFields", - "has other.calendar.monthsInYear", - "has other.calendar.weekOfYear", - "has other.calendar.year", - "has other.calendar.yearMonthFromFields", - "has other.calendar.yearOfWeek", - "get other.calendar.dateFromFields", - "get other.calendar.fields", - "call other.calendar.fields", "get other.day", "get other.day.valueOf", "call other.day.valueOf", @@ -65,29 +41,17 @@ const expected = [ "get other.year", "get other.year.valueOf", "call other.year.valueOf", - "call other.calendar.dateFromFields", - // CalendarEquals - "get this.calendar.id", - "get other.calendar.id", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.roundingIncrement", - "get options.roundingIncrement", - "getOwnPropertyDescriptor options.roundingMode", - "get options.roundingMode", - "getOwnPropertyDescriptor options.largestUnit", - "get options.largestUnit", - "getOwnPropertyDescriptor options.smallestUnit", - "get options.smallestUnit", - "getOwnPropertyDescriptor options.additional", - "get options.additional", // GetDifferenceSettings + "get options.largestUnit", "get options.largestUnit.toString", "call options.largestUnit.toString", + "get options.roundingIncrement", "get options.roundingIncrement.valueOf", "call options.roundingIncrement.valueOf", + "get options.roundingMode", "get options.roundingMode.toString", "call options.roundingMode.toString", + "get options.smallestUnit", "get options.smallestUnit.toString", "call options.smallestUnit.toString", ]; @@ -111,8 +75,6 @@ const otherDateTimePropertyBag = TemporalHelpers.propertyBagObserver(actual, { function createOptionsObserver({ smallestUnit = "nanoseconds", largestUnit = "auto", roundingMode = "halfExpand", roundingIncrement = 1 } = {}) { return TemporalHelpers.propertyBagObserver(actual, { - // order is significant, due to iterating through properties in order to - // copy them to an internal null-prototype object: roundingIncrement, roundingMode, largestUnit, @@ -121,108 +83,7 @@ function createOptionsObserver({ smallestUnit = "nanoseconds", largestUnit = "au }, "options"); } -// clear any observable things that happened while constructing the objects -actual.splice(0); - // basic order of observable operations with calendar call, without rounding: instance.since(otherDateTimePropertyBag, createOptionsObserver({ largestUnit: "years" })); -assert.compareArray(actual, expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", -]), "order of operations"); +assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -// short-circuit for identical objects: -const identicalPropertyBag = TemporalHelpers.propertyBagObserver(actual, { - year: 2000, - month: 5, - monthCode: "M05", - day: 2, - hour: 12, - minute: 34, - second: 56, - millisecond: 987, - microsecond: 654, - nanosecond: 321, - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), -}, "other"); - -instance.since(identicalPropertyBag, createOptionsObserver()); -assert.compareArray(actual, expected, "order of operations with identical datetimes"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest year: -const expectedOpsForYearRounding = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" })); -assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest year and skips a DateUntil call: -const otherDatePropertyBagSameMonth = TemporalHelpers.propertyBagObserver(actual, { - year: 2001, - month: 5, - monthCode: "M05", - day: 2, - hour: 12, - minute: 34, - second: 56, - millisecond: 987, - microsecond: 654, - nanosecond: 321, - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), -}, "other"); -const expectedOpsForYearRoundingSameMonth = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.until(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" })); -assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest month: -const expectedOpsForMonthRounding = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" })); -assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest week: -const expectedOpsForWeekRounding = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateUntil", - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" })); -assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/subtract/order-of-operations.js b/test/built-ins/Temporal/PlainDateTime/prototype/subtract/order-of-operations.js index 34cb0acde0..153d4b9a9f 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/subtract/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/subtract/order-of-operations.js @@ -40,10 +40,6 @@ const expected = [ "get fields.years", "get fields.years.valueOf", "call fields.years.valueOf", - // AddDateTime -> AddDate - "get this.calendar.dateAdd", - "call this.calendar.dateAdd", - // inside Calendar.p.dateAdd "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", @@ -71,51 +67,3 @@ instance.subtract(fields, options); assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -const noCalendarExpected = [ - // ToTemporalDurationRecord - "get fields.days", - "get fields.days.valueOf", - "call fields.days.valueOf", - "get fields.hours", - "get fields.hours.valueOf", - "call fields.hours.valueOf", - "get fields.microseconds", - "get fields.microseconds.valueOf", - "call fields.microseconds.valueOf", - "get fields.milliseconds", - "get fields.milliseconds.valueOf", - "call fields.milliseconds.valueOf", - "get fields.minutes", - "get fields.minutes.valueOf", - "call fields.minutes.valueOf", - "get fields.months", - "get fields.nanoseconds", - "get fields.nanoseconds.valueOf", - "call fields.nanoseconds.valueOf", - "get fields.seconds", - "get fields.seconds.valueOf", - "call fields.seconds.valueOf", - "get fields.weeks", - "get fields.years", - "get this.calendar.dateAdd", - // AddDateTime -> AddDate - "get options.overflow", - "get options.overflow.toString", - "call options.overflow.toString", -]; - -const noCalendarFields = TemporalHelpers.propertyBagObserver(actual, { - days: 1, - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1, - nanoseconds: 1, -}, "fields"); - -instance.subtract(noCalendarFields, options); -assert.compareArray(actual, noCalendarExpected, "order of operations with no calendar operation"); - -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-always.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-always.js index 53659c4644..e6faea1ea9 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-always.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-always.js @@ -7,39 +7,6 @@ description: If calendarName is "always", the calendar ID should be included. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "1976-11-18T15:23:00[u-ca=iso8601]", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "1976-11-18T15:23:00[u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "1976-11-18T15:23:00[u-ca=iso8601]", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "1976-11-18T15:23:00[u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1976-11-18T15:23:00[u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, ...args); - const result = date.toString({ calendarName: "always" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = always`); -} +const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0); +const result = date.toString({ calendarName: "always" }); +assert.sameValue(result, "1976-11-18T15:23:00[u-ca=iso8601]", `built-in ISO calendar for calendarName = always`); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js index 31f669617c..80809b5b2f 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js @@ -7,39 +7,6 @@ description: If calendarName is "auto", "iso8601" should be omitted. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "1976-11-18T15:23:00", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "1976-11-18T15:23:00[u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "1976-11-18T15:23:00", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "1976-11-18T15:23:00[u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1976-11-18T15:23:00[u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, ...args); - const result = date.toString({ calendarName: "auto" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = auto`); -} +const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0); +const result = date.toString({ calendarName: "auto" }); +assert.sameValue(result, "1976-11-18T15:23:00", `built-in ISO calendar for calendarName = auto`); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-critical.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-critical.js index e3face2fc1..506bf6aa00 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-critical.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-critical.js @@ -9,39 +9,6 @@ description: > features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "1976-11-18T15:23:00[!u-ca=iso8601]", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "1976-11-18T15:23:00[!u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "1976-11-18T15:23:00[!u-ca=iso8601]", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "1976-11-18T15:23:00[!u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1976-11-18T15:23:00[!u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, ...args); - const result = date.toString({ calendarName: "critical" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = critical`); -} +const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0); +const result = date.toString({ calendarName: "critical" }); +assert.sameValue(result, "1976-11-18T15:23:00[!u-ca=iso8601]", `built-in ISO calendar for calendarName = critical`); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-never.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-never.js index 5cc5a4d24b..7c3aa902cc 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-never.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-never.js @@ -7,39 +7,6 @@ description: If calendarName is "never", the calendar ID should be omitted. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "1976-11-18T15:23:00", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "1976-11-18T15:23:00", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "1976-11-18T15:23:00", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "1976-11-18T15:23:00", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1976-11-18T15:23:00", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, ...args); - const result = date.toString({ calendarName: "never" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = never`); -} +const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0); +const result = date.toString({ calendarName: "never" }); +assert.sameValue(result, "1976-11-18T15:23:00", `built-in ISO calendar for calendarName = never`); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-undefined.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-undefined.js index fee3b92005..9687ce048b 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-undefined.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-undefined.js @@ -14,40 +14,7 @@ info: | features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "1976-11-18T15:23:00", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "1976-11-18T15:23:00[u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "1976-11-18T15:23:00", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "1976-11-18T15:23:00[u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1976-11-18T15:23:00[u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const datetime = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, ...args); - const result = datetime.toString({ calendarName: undefined }); - assert.sameValue(result, expected, `default calendarName option is auto with ${description} calendar`); - // See options-object.js for {} and options-undefined.js for absent options arg -} +const datetime = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0); +const result = datetime.toString({ calendarName: undefined }); +assert.sameValue(result, "1976-11-18T15:23:00", `default calendarName option is auto with built-in ISO calendar`); +// See options-object.js for {} and options-undefined.js for absent options arg diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-wrong-type.js index 2786a47bb4..ee4e68ec50 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-wrong-type.js @@ -15,32 +15,9 @@ includes: [compareArray.js, temporalHelpers.js] features: [Temporal] ---*/ -const calendar = { - id: "custom", - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar); +const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, "iso8601"); TemporalHelpers.checkStringOptionWrongType("calendarName", "auto", (calendarName) => datetime.toString({ calendarName }), - (result, descr) => assert.sameValue(result, "2000-05-02T12:34:56.987654321[u-ca=custom]", descr), + (result, descr) => assert.sameValue(result, "2000-05-02T12:34:56.987654321", descr), ); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/options-undefined.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/options-undefined.js index daa6083232..5f78ee5cfe 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toString/options-undefined.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/options-undefined.js @@ -7,35 +7,12 @@ description: Verify that undefined options are handled correctly. features: [Temporal] ---*/ -const calendar = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "custom", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; const datetime1 = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 650, 0); -const datetime2 = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 650, 0, calendar); +const datetime2 = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 650, 0, "gregory"); [ [datetime1, "2000-05-02T12:34:56.98765"], - [datetime2, "2000-05-02T12:34:56.98765[u-ca=custom]"], + [datetime2, "2000-05-02T12:34:56.98765[u-ca=gregory]"], ].forEach(([datetime, expected]) => { const explicit = datetime.toString(undefined); assert.sameValue(explicit, expected, "default calendarName option is auto, precision is auto, and no rounding"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/order-of-operations.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/order-of-operations.js index 76f5446f7a..bc97b6884a 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toString/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/order-of-operations.js @@ -21,7 +21,6 @@ const expected = [ "get options.smallestUnit", "get options.smallestUnit.toString", "call options.smallestUnit.toString", - "get this.calendar.id", ]; const actual = []; @@ -52,7 +51,6 @@ const expectedForFractionalSecondDigits = [ "get options.roundingMode.toString", "call options.roundingMode.toString", "get options.smallestUnit", - "get this.calendar.id", ]; instance.toString( diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/balance-negative-time-units.js b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/balance-negative-time-units.js deleted file mode 100644 index 2a0427c9c9..0000000000 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/balance-negative-time-units.js +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.plaindatetime.prototype.tozoneddatetime -description: Negative time fields are balanced upwards -info: | - sec-temporal-balancetime steps 3–14: - 3. Set _microsecond_ to _microsecond_ + floor(_nanosecond_ / 1000). - 4. Set _nanosecond_ to _nanosecond_ modulo 1000. - 5. Set _millisecond_ to _millisecond_ + floor(_microsecond_ / 1000). - 6. Set _microsecond_ to _microsecond_ modulo 1000. - 7. Set _second_ to _second_ + floor(_millisecond_ / 1000). - 8. Set _millisecond_ to _millisecond_ modulo 1000. - 9. Set _minute_ to _minute_ + floor(_second_ / 60). - 10. Set _second_ to _second_ modulo 60. - 11. Set _hour_ to _hour_ + floor(_minute_ / 60). - 12. Set _minute_ to _minute_ modulo 60. - 13. Let _days_ be floor(_hour_ / 24). - 14. Set _hour_ to _hour_ modulo 24. - sec-temporal-addtime step 8: - 8. Return ? BalanceTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_). - sec-temporal-adddatetime step 1: - 1. Let _timeResult_ be ? AddTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_). - sec-temporal-builtintimezonegetinstantfor step 13.a: - a. Let _earlier_ be ? AddDateTime(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], 0, 0, 0, 0, 0, 0, 0, 0, 0, −_nanoseconds_, *"constrain"*). - sec-temporal.plaindatetime.prototype.tozoneddatetime step 6: - 6. Let _instant_ be BuiltinTimeZoneGetInstantFor(_timeZone_, _dateTime_, _disambiguation_). -includes: [compareArray.js, temporalHelpers.js] -features: [Temporal] ----*/ - -const shiftInstant = new Temporal.Instant(3661_001_001_001n); -const tz = TemporalHelpers.oneShiftTimeZone(shiftInstant, 2); -const datetime = new Temporal.PlainDateTime(1970, 1, 1, 1, 1, 1, 1, 1, 1); - -// This code path is encountered if disambiguation is `earlier` and the shift is -// a spring-forward change -datetime.toZonedDateTime(tz, { disambiguation: "earlier" }); - -const expected = [ - "1970-01-01T01:01:01.001001001", - "1970-01-01T01:01:01.001000999", -]; -assert.compareArray(tz.getPossibleInstantsForCalledWith, expected); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/constant-offset.js b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/constant-offset.js new file mode 100644 index 0000000000..0f2fc19194 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/constant-offset.js @@ -0,0 +1,14 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.tozoneddatetime +description: Result in time zone with constant UTC offset +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(2019, 2, 16, 23, 45); +["earlier", "later", "compatible", "reject"].forEach((disambiguation) => { + const result = instance.toZonedDateTime("+03:30", { disambiguation }); + assert.sameValue(result.epochNanoseconds, 1550348100_000_000_000n, "Result is 2019-02-16T20:15Z regardless of disambiguation"); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/disambiguation.js b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/disambiguation.js new file mode 100644 index 0000000000..de60676a8f --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/disambiguation.js @@ -0,0 +1,22 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.tozoneddatetime +description: Basic tests for disambiguation option +features: [Temporal] +---*/ + +const dtm = new Temporal.PlainDateTime(2000, 10, 29, 1, 45); + +for (const disambiguation of ["compatible", "earlier", "later", "reject"]) { + const result = dtm.toZonedDateTime("UTC", { disambiguation }); + assert.sameValue(result.epochNanoseconds, 972783900_000_000_000n, "epoch nanoseconds remains constant"); + assert.sameValue(result.timeZoneId, "UTC", "time zone is adopted"); +} + +for (const disambiguation of ["compatible", "earlier", "later", "reject"]) { + const result = dtm.toZonedDateTime("+03:30", { disambiguation }); + assert.sameValue(result.epochNanoseconds, 972771300_000_000_000n, "epoch nanoseconds remains constant"); + assert.sameValue(result.timeZoneId, "+03:30", "time zone is adopted"); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/fixed-offset-near-date-time-limits.js b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/fixed-offset-near-date-time-limits.js new file mode 100644 index 0000000000..0bc7c7eb34 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/fixed-offset-near-date-time-limits.js @@ -0,0 +1,45 @@ +// Copyright (C) 2022 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.tozoneddatetime +description: Values near the date/time limit and a fixed offset. +features: [Temporal, exponentiation] +---*/ + +const oneHour = 1n * 60n * 60n * 1000n**3n; + +const minDt = new Temporal.PlainDateTime(-271821, 4, 19, 1, 0, 0, 0, 0, 0); +const minValidDt = new Temporal.PlainDateTime(-271821, 4, 20, 0, 0, 0, 0, 0, 0); +const maxDt = new Temporal.PlainDateTime(275760, 9, 13, 0, 0, 0, 0, 0, 0); + +// Try the minimum date-time. +assert.throws(RangeError, () => minDt.toZonedDateTime("+00")); +assert.throws(RangeError, () => minDt.toZonedDateTime("+01")); +assert.throws(RangeError, () => minDt.toZonedDateTime("-01")); + +// Try the minimum valid date-time. +["earlier", "later"].forEach((disambiguation) => { + const zdt = minValidDt.toZonedDateTime("+00", { disambiguation }); + assert.sameValue(zdt.epochNanoseconds, -86_40000_00000_00000_00000n); +}); + +["earlier", "later"].forEach((disambiguation) => { + const zdt = minValidDt.toZonedDateTime("-01", { disambiguation }); + assert.sameValue(zdt.epochNanoseconds, -86_40000_00000_00000_00000n + oneHour); +}); + +assert.throws(RangeError, () => minValidDt.toZonedDateTime("+01")); + +// Try the maximum valid date-time. +["earlier", "later"].forEach((disambiguation) => { + const zdt = maxDt.toZonedDateTime("+00"); + assert.sameValue(zdt.epochNanoseconds, 86_40000_00000_00000_00000n); +}); + +["earlier", "later"].forEach((disambiguation) => { + const zdt = maxDt.toZonedDateTime("+01"); + assert.sameValue(zdt.epochNanoseconds, 86_40000_00000_00000_00000n - oneHour); +}); + +assert.throws(RangeError, () => maxDt.toZonedDateTime("-01")); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/negative-year.js b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/negative-year.js new file mode 100644 index 0000000000..bc2a6d1e90 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/negative-year.js @@ -0,0 +1,14 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.tozoneddatetime +description: Check result when Gregorian year is negative +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(-1000, 10, 29, 10, 46, 38, 271, 986, 102); +["earlier", "later", "compatible", "reject"].forEach((disambiguation) => { + const result = instance.toZonedDateTime("+06:00", { disambiguation }); + assert.sameValue(result.epochNanoseconds, -93698104401_728_013_898n, "Result is -001000-10-29T04:46:38.271986102Z regardless of disambiguation"); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/order-of-operations.js b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/order-of-operations.js index 18c7b8fdd0..2336d61f3f 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/order-of-operations.js @@ -9,54 +9,23 @@ features: [Temporal] ---*/ const expected = [ - // ToTemporalTimeZoneSlotValue - "has timeZone.getOffsetNanosecondsFor", - "has timeZone.getPossibleInstantsFor", - "has timeZone.id", // ToTemporalDisambiguation "get options.disambiguation", "get options.disambiguation.toString", "call options.disambiguation.toString", - // lookup in PlainDateTime.p.toZonedDateTime - "get timeZone.getOffsetNanosecondsFor", - "get timeZone.getPossibleInstantsFor", - // GetInstantFor - "call timeZone.getPossibleInstantsFor", ]; const actual = []; -const calendar = TemporalHelpers.calendarObserver(actual, "this.calendar"); -const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar); -const fallBackInstance = new Temporal.PlainDateTime(2000, 10, 29, 1, 30, 0, 0, 0, 0, calendar); -const springForwardInstance = new Temporal.PlainDateTime(2000, 4, 2, 2, 30, 0, 0, 0, 0, calendar); -// clear observable operations that occurred during the constructor calls -actual.splice(0); - -const dstTimeZone = TemporalHelpers.springForwardFallBackTimeZone(); -const timeZone = TemporalHelpers.timeZoneObserver(actual, "timeZone", { - getOffsetNanosecondsFor: dstTimeZone.getOffsetNanosecondsFor, - getPossibleInstantsFor: dstTimeZone.getPossibleInstantsFor, -}); +const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, "iso8601"); const options = TemporalHelpers.propertyBagObserver(actual, { disambiguation: "compatible" }, "options"); -instance.toZonedDateTime(timeZone, options); -assert.compareArray(actual, expected, "order of operations at normal wall-clock time"); -actual.splice(0); // clear - -fallBackInstance.toZonedDateTime(timeZone, options); -assert.compareArray(actual, expected, "order of operations at repeated wall-clock time"); -actual.splice(0); // clear - -springForwardInstance.toZonedDateTime(timeZone, options); -assert.compareArray(actual, expected.concat([ - "call timeZone.getOffsetNanosecondsFor", - "call timeZone.getOffsetNanosecondsFor", - "call timeZone.getPossibleInstantsFor", -]), "order of operations at skipped wall-clock time"); +instance.toZonedDateTime("UTC", options); +assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear +const rejectInstance = new Temporal.PlainDateTime(2000, 4, 2, 2, 30); const rejectOptions = TemporalHelpers.propertyBagObserver(actual, { disambiguation: "reject" }, "options"); -assert.throws(RangeError, () => springForwardInstance.toZonedDateTime(timeZone, rejectOptions)); -assert.compareArray(actual, expected, "order of operations at skipped wall-clock time with disambiguation: reject"); +assert.throws(RangeError, () => rejectInstance.toZonedDateTime("America/Vancouver", rejectOptions)); +assert.compareArray(actual, expected, "order of operations with disambiguation: reject"); actual.splice(0); // clear diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/two-digit-year.js b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/two-digit-year.js new file mode 100644 index 0000000000..13b6f2bc4f --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/two-digit-year.js @@ -0,0 +1,16 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.tozoneddatetime +description: > + Check result when Gregorian year is two digits (in case underlying + implementation uses Date and forgets to use setFullYear) +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(98, 10, 29, 10, 46, 38, 271, 986, 102); +["earlier", "later", "compatible", "reject"].forEach((disambiguation) => { + const result = instance.toZonedDateTime("+06:00", { disambiguation }); + assert.sameValue(result.epochNanoseconds, -59048507601_728_013_898n, "Result is 0098-10-29T04:46:38.271986102Z regardless of disambiguation"); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/year-zero.js b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/year-zero.js new file mode 100644 index 0000000000..afcc99c42a --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/year-zero.js @@ -0,0 +1,23 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.tozoneddatetime +description: > + Check result in Gregorian year zero (in case underlying + implementation uses Date and calls setFullYear on a non-leap year) +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(0, 10, 29, 10, 46, 38, 271, 986, 102); +["earlier", "later", "compatible", "reject"].forEach((disambiguation) => { + const result = instance.toZonedDateTime("+06:00", { disambiguation }); + assert.sameValue(result.epochNanoseconds, -62141109201_728_013_898n, "Result is 0000-10-29T04:46:38.271986102Z regardless of disambiguation"); +}); + +// leap day +const instanceLeap = new Temporal.PlainDateTime(0, 2, 29); +["earlier", "later", "compatible", "reject"].forEach((disambiguation) => { + const result = instanceLeap.toZonedDateTime("-00:01", { disambiguation }); + assert.sameValue(result.epochNanoseconds, -62162121540_000_000_000n, "Result is 0000-02-29T00:01Z regardless of disambiguation"); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/different-calendars-throws.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/different-calendars-throws.js index a644ccbd65..9dc2968540 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/until/different-calendars-throws.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/different-calendars-throws.js @@ -8,29 +8,7 @@ features: [Temporal] ---*/ const dt1 = new Temporal.PlainDateTime(2000, 1, 1, 0, 0, 0, 0, 0, 0); -const dt2 = new Temporal.PlainDateTime(2000, 1, 1, 0, 0, 0, 0, 0, 0, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "custom", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const dt2 = new Temporal.PlainDateTime(2000, 1, 1, 0, 0, 0, 0, 0, 0, "gregory"); assert.throws( RangeError, diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/order-of-operations.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/order-of-operations.js index de054949f7..84d734ed5a 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/until/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/order-of-operations.js @@ -11,30 +11,6 @@ features: [Temporal] const expected = [ // ToTemporalDateTime "get other.calendar", - "has other.calendar.dateAdd", - "has other.calendar.dateFromFields", - "has other.calendar.dateUntil", - "has other.calendar.day", - "has other.calendar.dayOfWeek", - "has other.calendar.dayOfYear", - "has other.calendar.daysInMonth", - "has other.calendar.daysInWeek", - "has other.calendar.daysInYear", - "has other.calendar.fields", - "has other.calendar.id", - "has other.calendar.inLeapYear", - "has other.calendar.mergeFields", - "has other.calendar.month", - "has other.calendar.monthCode", - "has other.calendar.monthDayFromFields", - "has other.calendar.monthsInYear", - "has other.calendar.weekOfYear", - "has other.calendar.year", - "has other.calendar.yearMonthFromFields", - "has other.calendar.yearOfWeek", - "get other.calendar.dateFromFields", - "get other.calendar.fields", - "call other.calendar.fields", "get other.day", "get other.day.valueOf", "call other.day.valueOf", @@ -65,29 +41,17 @@ const expected = [ "get other.year", "get other.year.valueOf", "call other.year.valueOf", - "call other.calendar.dateFromFields", - // CalendarEquals - "get this.calendar.id", - "get other.calendar.id", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.roundingIncrement", - "get options.roundingIncrement", - "getOwnPropertyDescriptor options.roundingMode", - "get options.roundingMode", - "getOwnPropertyDescriptor options.largestUnit", - "get options.largestUnit", - "getOwnPropertyDescriptor options.smallestUnit", - "get options.smallestUnit", - "getOwnPropertyDescriptor options.additional", - "get options.additional", // GetDifferenceSettings + "get options.largestUnit", "get options.largestUnit.toString", "call options.largestUnit.toString", + "get options.roundingIncrement", "get options.roundingIncrement.valueOf", "call options.roundingIncrement.valueOf", + "get options.roundingMode", "get options.roundingMode.toString", "call options.roundingMode.toString", + "get options.smallestUnit", "get options.smallestUnit.toString", "call options.smallestUnit.toString", ]; @@ -121,108 +85,7 @@ function createOptionsObserver({ smallestUnit = "nanoseconds", largestUnit = "au }, "options"); } -// clear any observable things that happened while constructing the objects -actual.splice(0); - // basic order of observable operations with calendar call, without rounding: instance.until(otherDateTimePropertyBag, createOptionsObserver({ largestUnit: "years" })); -assert.compareArray(actual, expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", -]), "order of operations"); +assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -// short-circuit for identical objects: -const identicalPropertyBag = TemporalHelpers.propertyBagObserver(actual, { - year: 2000, - month: 5, - monthCode: "M05", - day: 2, - hour: 12, - minute: 34, - second: 56, - millisecond: 987, - microsecond: 654, - nanosecond: 321, - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), -}, "other"); - -instance.until(identicalPropertyBag, createOptionsObserver()); -assert.compareArray(actual, expected, "order of operations with identical datetimes"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest year: -const expectedOpsForYearRounding = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" })); -assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest year and skips a DateUntil call: -const otherDatePropertyBagSameMonth = TemporalHelpers.propertyBagObserver(actual, { - year: 2001, - month: 5, - monthCode: "M05", - day: 2, - hour: 12, - minute: 34, - second: 56, - millisecond: 987, - microsecond: 654, - nanosecond: 321, - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), -}, "other"); -const expectedOpsForYearRoundingSameMonth = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.until(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" })); -assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest month: -const expectedOpsForMonthRounding = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" })); -assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = years"); -actual.splice(0); // clear - -// code path through RoundDuration that rounds to the nearest week: -const expectedOpsForWeekRounding = expected.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // CalendarDateUntil - "call this.calendar.dateUntil", - // RoundRelativeDuration - "call this.calendar.dateUntil", - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" })); -assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/with/order-of-operations.js b/test/built-ins/Temporal/PlainDateTime/prototype/with/order-of-operations.js index c7e6b2a6c7..9cf38b9cda 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/with/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/with/order-of-operations.js @@ -13,26 +13,9 @@ const expected = [ "get fields.calendar", "get fields.timeZone", // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", - "getOwnPropertyDescriptor options.extra", - "get options.extra", - // lookup - "get this.calendar.dateFromFields", - "get this.calendar.fields", - "get this.calendar.mergeFields", - // CalendarFields - "call this.calendar.fields", - // PrepareTemporalFields on receiver - "get this.calendar.day", - "call this.calendar.day", - "get this.calendar.month", - "call this.calendar.month", - "get this.calendar.monthCode", - "call this.calendar.monthCode", - "get this.calendar.year", - "call this.calendar.year", + "get options.overflow.toString", + "call options.overflow.toString", // PrepareTemporalFields on argument "get fields.day", "get fields.day.valueOf", @@ -64,12 +47,6 @@ const expected = [ "get fields.year", "get fields.year.valueOf", "call fields.year.valueOf", - // CalendarMergeFields - "call this.calendar.mergeFields", - // InterpretTemporalDateTimeFields - "get options.overflow.toString", - "call options.overflow.toString", - "call this.calendar.dateFromFields", ]; const actual = []; diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/argument-string.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/argument-string.js index 249c69712f..652a668b0a 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/argument-string.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/argument-string.js @@ -8,31 +8,7 @@ features: [Temporal] includes: [temporalHelpers.js] ---*/ -const calendar = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "something special", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - toString() { return "something special"; }, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, calendar); +const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "gregory"); const result = dt.withCalendar("iso8601"); TemporalHelpers.assertPlainDateTime( diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-case-insensitive.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-case-insensitive.js index 7545f4af25..2f7251ff8b 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-case-insensitive.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-case-insensitive.js @@ -7,29 +7,7 @@ description: Calendar names are case-insensitive features: [Temporal] ---*/ -const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "iso8601"); let arg = "iSo8601"; const result = instance.withCalendar(arg); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-iso-string.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-iso-string.js index b6f4899488..a77767ec39 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-iso-string.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-iso-string.js @@ -7,29 +7,7 @@ description: An ISO 8601 string can be converted to a calendar ID in Calendar features: [Temporal] ---*/ -const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "iso8601"); for (const arg of [ "2020-01-01", diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number.js index 6b333b4642..2ea1291174 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number.js @@ -7,29 +7,7 @@ description: A number is not allowed to be a calendar features: [Temporal] ---*/ -const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "iso8601"); const numbers = [ 1, diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-string-leap-second.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-string-leap-second.js index e6f877f4ab..40b465ab20 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-string-leap-second.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-string-leap-second.js @@ -7,29 +7,7 @@ description: Leap second is a valid ISO string for Calendar features: [Temporal] ---*/ -const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "iso8601"); const arg = "2016-12-31T23:59:60"; const result = instance.withCalendar(arg); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-string.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-string.js index 6f570a53b7..60d17cda7c 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-string.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-string.js @@ -7,29 +7,7 @@ description: A calendar ID is valid input for Calendar features: [Temporal] ---*/ -const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "iso8601"); const arg = "iso8601"; diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-temporal-object.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-temporal-object.js index d7dc089866..baae132bb8 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-temporal-object.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-temporal-object.js @@ -3,7 +3,9 @@ /*--- esid: sec-temporal.plaindatetime.prototype.withcalendar -description: Fast path for converting other Temporal objects to Temporal.Calendar by reading internal slots +description: > + Fast path for converting other Temporal objects to calendar ID by reading + internal slots info: | sec-temporal-totemporalcalendar step 1.b: b. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then @@ -31,29 +33,7 @@ const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UT }, }); - const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); + const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "iso8601"); const result = instance.withCalendar(arg); assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-wrong-type.js index fd75835dee..14aad0c975 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-wrong-type.js @@ -5,33 +5,11 @@ esid: sec-temporal.plaindatetime.prototype.withcalendar description: > Appropriate error thrown when argument cannot be converted to a valid string - or object for Calendar + for Calendar features: [BigInt, Symbol, Temporal] ---*/ -const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "iso8601"); const primitiveTests = [ [null, "null"], diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/subclassing-ignored.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/subclassing-ignored.js index 4a600e52c8..23998a2390 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/subclassing-ignored.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/subclassing-ignored.js @@ -8,40 +8,12 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const customCalendar = { - era() { return undefined; }, - eraYear() { return undefined; }, - year() { return 1900; }, - month() { return 2; }, - monthCode() { return "M02"; }, - day() { return 5; }, - id: "custom-calendar", - toString() { return "custom-calendar"; }, - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - TemporalHelpers.checkSubclassingIgnored( Temporal.PlainDateTime, [2000, 5, 2, 12, 34, 56, 987, 654, 321], "withCalendar", - [customCalendar], + ["iso8601"], (result) => { - TemporalHelpers.assertPlainDateTime(result, 1900, 2, "M02", 5, 12, 34, 56, 987, 654, 321); - assert.sameValue(result.getISOFields().calendar, customCalendar, "calendar result"); + TemporalHelpers.assertPlainDateTime(result, 2000, 5, "M05", 2, 12, 34, 56, 987, 654, 321); }, ); diff --git a/test/built-ins/Temporal/PlainMonthDay/from/basic.js b/test/built-ins/Temporal/PlainMonthDay/from/basic.js new file mode 100644 index 0000000000..77e4edec71 --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/from/basic.js @@ -0,0 +1,35 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.from +description: Returns correctly with valid data. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const options = [ + { overflow: "constrain" }, + { overflow: "reject" }, + {}, + undefined, +]; +options.forEach((opt) => { + const optionsDesc = opt && JSON.stringify(opt); + result = Temporal.PlainMonthDay.from({ year: 2021, month: 7, day: 3 }, opt); + TemporalHelpers.assertPlainMonthDay(result, "M07", 3, `month 7, day 3, with year, options = ${optionsDesc}`); + result = Temporal.PlainMonthDay.from({ year: 2021, month: 12, day: 31 }, opt); + TemporalHelpers.assertPlainMonthDay(result, "M12", 31, `month 12, day 31, with year, options = ${optionsDesc}`); + result = Temporal.PlainMonthDay.from({ monthCode: "M07", day: 3 }, opt); + TemporalHelpers.assertPlainMonthDay(result, "M07", 3, `monthCode M07, day 3, options = ${optionsDesc}`); + result = Temporal.PlainMonthDay.from({ monthCode: "M12", day: 31 }, opt); + TemporalHelpers.assertPlainMonthDay(result, "M12", 31, `monthCode M12, day 31, options = ${optionsDesc}`); +}); + +TemporalHelpers.ISOMonths.forEach(({ month, monthCode, daysInMonth }) => { + result = Temporal.PlainMonthDay.from({ month, day: daysInMonth }); + TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth, `month ${month}, day ${daysInMonth}`); + + result = Temporal.PlainMonthDay.from({ monthCode, day: daysInMonth }); + TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth, `monthCode ${monthCode}, day ${daysInMonth}`); +}); diff --git a/test/built-ins/Temporal/PlainMonthDay/from/fields-missing-properties.js b/test/built-ins/Temporal/PlainMonthDay/from/fields-missing-properties.js index 1b932bc599..c268ccd012 100644 --- a/test/built-ins/Temporal/PlainMonthDay/from/fields-missing-properties.js +++ b/test/built-ins/Temporal/PlainMonthDay/from/fields-missing-properties.js @@ -9,6 +9,10 @@ features: [Temporal] assert.throws(TypeError, () => Temporal.PlainMonthDay.from({}), "No properties"); assert.throws(TypeError, () => Temporal.PlainMonthDay.from({ day: 15 }), "Only day"); +assert.throws(TypeError, () => Temporal.PlainMonthDay.from({ month: 12 }), "day is required with month"); assert.throws(TypeError, () => Temporal.PlainMonthDay.from({ monthCode: 'M12' }), "Only monthCode"); assert.throws(TypeError, () => Temporal.PlainMonthDay.from({ monthCode: undefined, day: 15 }), "monthCode undefined"); assert.throws(TypeError, () => Temporal.PlainMonthDay.from({ months: 12, day: 31 }), "months plural"); +assert.throws(TypeError, () => Temporal.PlainMonthDay.from({ year: 2021, month: 12 }), "day is required with year and month"); +assert.throws(TypeError, () => Temporal.PlainMonthDay.from({ year: 2021, monthCode: "M12" }), "day is required with year and monthCode"); +assert.throws(TypeError, () => Temporal.PlainMonthDay.from({ year: 2021, day: 17 }), "either month or monthCode is required"); diff --git a/test/built-ins/Temporal/PlainMonthDay/from/fields-object.js b/test/built-ins/Temporal/PlainMonthDay/from/fields-object.js index 000ad58b1d..20e4e1d353 100644 --- a/test/built-ins/Temporal/PlainMonthDay/from/fields-object.js +++ b/test/built-ins/Temporal/PlainMonthDay/from/fields-object.js @@ -18,8 +18,6 @@ const tests = [ [Temporal.PlainDate.from("2019-10-01"), "PlainDate object"], [{ monthCode: "M10", day: 1, calendar: "iso8601" }, "option bag with monthCode and explicit ISO calendar"], [{ month: 10, day: 1, calendar: "iso8601" }, "option bag with month and explicit ISO calendar"], - [{ monthCode: "M10", day: 1, calendar: Temporal.Calendar.from("iso8601") }, "option bag with monthCode and object ISO calendar"], - [{ month: 10, day: 1, calendar: Temporal.Calendar.from("iso8601") }, "option bag with month and object ISO calendar"], ]; for (const [argument, description = argument] of tests) { diff --git a/test/built-ins/Temporal/PlainMonthDay/from/monthcode-invalid.js b/test/built-ins/Temporal/PlainMonthDay/from/monthcode-invalid.js new file mode 100644 index 0000000000..4957e52178 --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/from/monthcode-invalid.js @@ -0,0 +1,21 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.from +description: Throw RangeError for an out-of-range, conflicting, or ill-formed monthCode +features: [Temporal] +---*/ + +["m1", "M1", "m01"].forEach((monthCode) => { + assert.throws(RangeError, () => Temporal.PlainMonthDay.from({ monthCode, day: 17 }), + `monthCode '${monthCode}' is not well-formed`); +}); + +assert.throws(RangeError, () => Temporal.PlainMonthDay.from({ year: 2021, month: 12, monthCode: "M11", day: 17 }), + "monthCode and month conflict"); + +["M00", "M19", "M99", "M13"].forEach((monthCode) => { + assert.throws(RangeError, () => Temporal.PlainMonthDay.from({ monthCode, day: 17 }), + `monthCode '${monthCode}' is not valid for ISO 8601 calendar`); +}); diff --git a/test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-primitive.js b/test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-primitive.js index 2dedb669b4..281311983d 100644 --- a/test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-primitive.js +++ b/test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-primitive.js @@ -11,8 +11,6 @@ features: [Temporal] ---*/ const expected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", @@ -26,11 +24,6 @@ assert.compareArray(actual, expected, "Successful call"); TemporalHelpers.assertPlainMonthDay(result, "M05", 17); actual.splice(0); // empty it for the next check -const failureExpected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", - "get options.overflow", -]; assert.throws(TypeError, () => Temporal.PlainMonthDay.from(7, options)); -assert.compareArray(actual, failureExpected, "Failing call"); +assert.compareArray(actual, expected, "Failing call"); diff --git a/test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-string-invalid.js b/test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-string-invalid.js index 297ea0dfd3..fa3f1256b5 100644 --- a/test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-string-invalid.js +++ b/test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-string-invalid.js @@ -9,9 +9,9 @@ features: [Temporal] ---*/ const expected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", + "get options.overflow.toString", + "call options.overflow.toString", ]; let actual = []; diff --git a/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/one-of-era-erayear-undefined.js b/test/built-ins/Temporal/PlainMonthDay/from/one-of-era-erayear-undefined.js similarity index 58% rename from test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/one-of-era-erayear-undefined.js rename to test/built-ins/Temporal/PlainMonthDay/from/one-of-era-erayear-undefined.js index 4b7f40e22a..46fcbe0b91 100644 --- a/test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/one-of-era-erayear-undefined.js +++ b/test/built-ins/Temporal/PlainMonthDay/from/one-of-era-erayear-undefined.js @@ -2,15 +2,14 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.monthDayFromFields +esid: sec-temporal.plainmonthday.from description: Does not throw a RangeError if only one of era/eraYear fields is present features: [Temporal] includes: [temporalHelpers.js] ---*/ const base = { year: 2000, month: 5, day: 2, era: 'ce' }; -const instance = new Temporal.Calendar('iso8601'); -TemporalHelpers.assertPlainMonthDay(instance.monthDayFromFields({ ...base }), 'M05', 2); +TemporalHelpers.assertPlainMonthDay(Temporal.PlainMonthDay.from(base), 'M05', 2); const base2 = { year: 2000, month: 5, day: 2, eraYear: 1 }; -TemporalHelpers.assertPlainMonthDay(instance.monthDayFromFields({ ...base }), 'M05', 2); +TemporalHelpers.assertPlainMonthDay(Temporal.PlainMonthDay.from(base2), 'M05', 2); diff --git a/test/built-ins/Temporal/PlainMonthDay/from/order-of-operations.js b/test/built-ins/Temporal/PlainMonthDay/from/order-of-operations.js index 9c7b01073f..8bea4600cb 100644 --- a/test/built-ins/Temporal/PlainMonthDay/from/order-of-operations.js +++ b/test/built-ins/Temporal/PlainMonthDay/from/order-of-operations.js @@ -9,39 +9,10 @@ features: [Temporal] ---*/ const expected = [ - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", - "getOwnPropertyDescriptor options.extra", - "get options.extra", + "get options.overflow.toString", + "call options.overflow.toString", "get fields.calendar", - "has fields.calendar.dateAdd", - "has fields.calendar.dateFromFields", - "has fields.calendar.dateUntil", - "has fields.calendar.day", - "has fields.calendar.dayOfWeek", - "has fields.calendar.dayOfYear", - "has fields.calendar.daysInMonth", - "has fields.calendar.daysInWeek", - "has fields.calendar.daysInYear", - "has fields.calendar.fields", - "has fields.calendar.id", - "has fields.calendar.inLeapYear", - "has fields.calendar.mergeFields", - "has fields.calendar.month", - "has fields.calendar.monthCode", - "has fields.calendar.monthDayFromFields", - "has fields.calendar.monthsInYear", - "has fields.calendar.weekOfYear", - "has fields.calendar.year", - "has fields.calendar.yearMonthFromFields", - "has fields.calendar.yearOfWeek", - // lookup - "get fields.calendar.fields", - "get fields.calendar.monthDayFromFields", - // CalendarFields - "call fields.calendar.fields", // PrepareTemporalFields "get fields.day", "get fields.day.valueOf", @@ -55,11 +26,6 @@ const expected = [ "get fields.year", "get fields.year.valueOf", "call fields.year.valueOf", - // CalendarMonthDayFromFields - "call fields.calendar.monthDayFromFields", - // inside Calendar.p.monthDayFromFields - "get options.overflow.toString", - "call options.overflow.toString", ]; const actual = []; diff --git a/test/built-ins/Temporal/PlainMonthDay/from/overflow.js b/test/built-ins/Temporal/PlainMonthDay/from/overflow.js index 0db03be79a..c0d2432deb 100644 --- a/test/built-ins/Temporal/PlainMonthDay/from/overflow.js +++ b/test/built-ins/Temporal/PlainMonthDay/from/overflow.js @@ -36,3 +36,87 @@ assert.throws(RangeError, () => Temporal.PlainMonthDay.from("13-34", { overflow: "invalid ISO string: constrain"); assert.throws(RangeError, () => Temporal.PlainMonthDay.from("13-34", { overflow: "reject" }), "invalid ISO string: reject"); + +const opt = { overflow: "constrain" }; + +let result = Temporal.PlainMonthDay.from({ year: 2021, month: 13, day: 1 }, opt); +TemporalHelpers.assertPlainMonthDay(result, "M12", 1, "month 13 is constrained to 12"); + +result = Temporal.PlainMonthDay.from({ year: 2021, month: 999999, day: 500 }, opt); +TemporalHelpers.assertPlainMonthDay(result, "M12", 31, "month 999999 is constrained to 12 and day 500 is constrained to 31"); + +[-99999, -1, 0].forEach((month) => { + assert.throws( + RangeError, + () => Temporal.PlainMonthDay.from({ year: 2021, month, day: 1 }, opt), + `Month ${month} is out of range for 2021 even with overflow: constrain` + ); +}); + +TemporalHelpers.ISOMonths.forEach(({ month, monthCode, daysInMonth }) => { + const day = daysInMonth + 1; + + result = Temporal.PlainMonthDay.from({ month, day }, opt); + TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth, + `day is constrained from ${day} to ${daysInMonth} in month ${month}`); + + result = Temporal.PlainMonthDay.from({ month, day: 9001 }, opt); + TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth, + `day is constrained to ${daysInMonth} in month ${month}`); + + result = Temporal.PlainMonthDay.from({ monthCode, day }, opt); + TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth, + `day is constrained from ${day} to ${daysInMonth} in monthCode ${monthCode}`); + + result = Temporal.PlainMonthDay.from({ monthCode, day: 9001 }, opt); + TemporalHelpers.assertPlainMonthDay(result, monthCode, daysInMonth, + `day is constrained to ${daysInMonth} in monthCode ${monthCode}`); +}); + +[ ["month", 2], ["monthCode", "M02"] ].forEach(([ name, value ]) => { + result = Temporal.PlainMonthDay.from({ year: 2020, [name]: value, day: 30 }, opt); + TemporalHelpers.assertPlainMonthDay(result, "M02", 29, `${name} ${value} is constrained to 29 in leap year 2020`); + + result = Temporal.PlainMonthDay.from({ year: 2021, [name]: value, day: 29 }, opt); + TemporalHelpers.assertPlainMonthDay(result, "M02", 28, `${name} ${value} is constrained to 28 in common year 2021`); +}); + +[-1, 0, 13, 9995].forEach((month) => { + assert.throws( + RangeError, + () => Temporal.PlainMonthDay.from({year: 2021, month, day: 5}, { overflow: "reject" }), + `Month ${month} is out of range for 2021 with overflow: reject` + ); +}); + +[-1, 0, 32, 999].forEach((day) => { + assert.throws( + RangeError, + () => Temporal.PlainMonthDay.from({ year: 2021, month: 12, day }, { overflow: "reject" }), + `Day ${day} is out of range for 2021-12 with overflow: reject` + ); + assert.throws( + RangeError, + () => Temporal.PlainMonthDay.from({ monthCode: "M12", day }, { overflow: "reject" }), + `Day ${day} is out of range for 2021-M12 with overflow: reject` + ); +}); + +TemporalHelpers.ISOMonths.forEach(({ month, monthCode, daysInMonth }) => { + const day = daysInMonth + 1; + assert.throws(RangeError, + () => Temporal.PlainMonthDay.from({ month, day }, { overflow: "reject" }), + `Day ${day} is out of range for month ${month} with overflow: reject`); + assert.throws(RangeError, + () => Temporal.PlainMonthDay.from({ monthCode, day }, { overflow: "reject" }), + `Day ${day} is out of range for monthCode ${monthCode} with overflow: reject`); +}); + +[ ["month", 2], ["monthCode", "M02"] ].forEach(([ name, value ]) => { + assert.throws(RangeError, + () => Temporal.PlainMonthDay.from({ year: 2020, [name]: value, day: 30 }, { overflow: "reject" }), + `Day 30 is out of range for ${name} ${value} in leap year 2020 with overflow: reject`); + assert.throws(RangeError, + () => Temporal.PlainMonthDay.from({ year: 2021, [name]: value, day: 29 }, { overflow: "reject" }), + `Day 29 is out of range for ${name} ${value} in common year 2021 with overflow: reject`); +}); diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/calendars.js b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/calendars.js index 33ea114706..a8664ee185 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/calendars.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/calendars.js @@ -8,45 +8,8 @@ includes: [compareArray.js, temporalHelpers.js] features: [Temporal] ---*/ -const expected = [ - "get calendar a.id", - "get calendar b.id", -]; -const actual = []; -const calendar = (id) => { - const c = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, - }; - TemporalHelpers.observeProperty(actual, c, "id", id, `calendar ${id}`); - return c; -}; - -const mdA = new Temporal.PlainMonthDay(2, 7, calendar("a")); -const mdB = new Temporal.PlainMonthDay(2, 7, calendar("b")); -const mdC = new Temporal.PlainMonthDay(2, 7, calendar("c"), 1974); -actual.splice(0); // disregard the HasProperty checks done in the constructor - +const mdA = new Temporal.PlainMonthDay(2, 7, "iso8601"); +const mdB = new Temporal.PlainMonthDay(2, 7, "gregory"); +const mdC = new Temporal.PlainMonthDay(2, 7, "iso8601", 1974); assert.sameValue(mdA.equals(mdC), false, "different year"); -assert.compareArray(actual, [], "Should not check calendar"); - assert.sameValue(mdA.equals(mdB), false, "different calendar"); -assert.compareArray(actual, expected, "Should check calendar"); diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toJSON/calendarname.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toJSON/calendarname.js index d5606782a7..27e70db292 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toJSON/calendarname.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toJSON/calendarname.js @@ -7,35 +7,9 @@ description: toJSON doesn't take calendarName into account. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - const tests = [ [[], "05-02"], - [[{ id: "custom", ...calendarMethods }], "1972-05-02[u-ca=custom]"], - [[{ id: "iso8601", ...calendarMethods }], "05-02"], - [[{ id: "ISO8601", ...calendarMethods }], "1972-05-02[u-ca=ISO8601]"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1972-05-02[u-ca=\u0131so8601]"], // dotless i + [["gregory"], "1972-05-02[u-ca=gregory]"], ]; const options = { get calendarName() { diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toJSON/year-format.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toJSON/year-format.js index ebe40ba173..6ac57221df 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toJSON/year-format.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toJSON/year-format.js @@ -9,47 +9,43 @@ features: [Temporal] // For PlainMonthDay, the ISO reference year is only present in the string if // the calendar is not ISO 8601 -class NotISO extends Temporal.Calendar { - constructor() { super("iso8601"); } - get id() { return "not-iso"; } -} -const calendar = new NotISO(); +const calendar = "gregory"; let instance = new Temporal.PlainMonthDay(12, 3, calendar, -100000); -assert.sameValue(instance.toJSON(), "-100000-12-03[u-ca=not-iso]", "large negative year formatted as 6-digit"); +assert.sameValue(instance.toJSON(), "-100000-12-03[u-ca=gregory]", "large negative year formatted as 6-digit"); instance = new Temporal.PlainMonthDay(4, 5, calendar, -10000); -assert.sameValue(instance.toJSON(), "-010000-04-05[u-ca=not-iso]", "smallest 5-digit negative year formatted as 6-digit"); +assert.sameValue(instance.toJSON(), "-010000-04-05[u-ca=gregory]", "smallest 5-digit negative year formatted as 6-digit"); instance = new Temporal.PlainMonthDay(6, 7, calendar, -9999); -assert.sameValue(instance.toJSON(), "-009999-06-07[u-ca=not-iso]", "largest 4-digit negative year formatted as 6-digit"); +assert.sameValue(instance.toJSON(), "-009999-06-07[u-ca=gregory]", "largest 4-digit negative year formatted as 6-digit"); instance = new Temporal.PlainMonthDay(8, 9, calendar, -1000); -assert.sameValue(instance.toJSON(), "-001000-08-09[u-ca=not-iso]", "smallest 4-digit negative year formatted as 6-digit"); +assert.sameValue(instance.toJSON(), "-001000-08-09[u-ca=gregory]", "smallest 4-digit negative year formatted as 6-digit"); instance = new Temporal.PlainMonthDay(10, 9, calendar, -999); -assert.sameValue(instance.toJSON(), "-000999-10-09[u-ca=not-iso]", "largest 3-digit negative year formatted as 6-digit"); +assert.sameValue(instance.toJSON(), "-000999-10-09[u-ca=gregory]", "largest 3-digit negative year formatted as 6-digit"); instance = new Temporal.PlainMonthDay(8, 7, calendar, -1); -assert.sameValue(instance.toJSON(), "-000001-08-07[u-ca=not-iso]", "year -1 formatted as 6-digit"); +assert.sameValue(instance.toJSON(), "-000001-08-07[u-ca=gregory]", "year -1 formatted as 6-digit"); instance = new Temporal.PlainMonthDay(6, 5, calendar, 0); -assert.sameValue(instance.toJSON(), "0000-06-05[u-ca=not-iso]", "year 0 formatted as 4-digit"); +assert.sameValue(instance.toJSON(), "0000-06-05[u-ca=gregory]", "year 0 formatted as 4-digit"); instance = new Temporal.PlainMonthDay(4, 3, calendar, 1); -assert.sameValue(instance.toJSON(), "0001-04-03[u-ca=not-iso]", "year 1 formatted as 4-digit"); +assert.sameValue(instance.toJSON(), "0001-04-03[u-ca=gregory]", "year 1 formatted as 4-digit"); instance = new Temporal.PlainMonthDay(2, 10, calendar, 999); -assert.sameValue(instance.toJSON(), "0999-02-10[u-ca=not-iso]", "largest 3-digit positive year formatted as 4-digit"); +assert.sameValue(instance.toJSON(), "0999-02-10[u-ca=gregory]", "largest 3-digit positive year formatted as 4-digit"); instance = new Temporal.PlainMonthDay(1, 23, calendar, 1000); -assert.sameValue(instance.toJSON(), "1000-01-23[u-ca=not-iso]", "smallest 4-digit positive year formatted as 4-digit"); +assert.sameValue(instance.toJSON(), "1000-01-23[u-ca=gregory]", "smallest 4-digit positive year formatted as 4-digit"); instance = new Temporal.PlainMonthDay(4, 5, calendar, 9999); -assert.sameValue(instance.toJSON(), "9999-04-05[u-ca=not-iso]", "largest 4-digit positive year formatted as 4-digit"); +assert.sameValue(instance.toJSON(), "9999-04-05[u-ca=gregory]", "largest 4-digit positive year formatted as 4-digit"); instance = new Temporal.PlainMonthDay(6, 7, calendar, 10000); -assert.sameValue(instance.toJSON(), "+010000-06-07[u-ca=not-iso]", "smallest 5-digit positive year formatted as 6-digit"); +assert.sameValue(instance.toJSON(), "+010000-06-07[u-ca=gregory]", "smallest 5-digit positive year formatted as 6-digit"); instance = new Temporal.PlainMonthDay(8, 9, calendar, 100000); -assert.sameValue(instance.toJSON(), "+100000-08-09[u-ca=not-iso]", "large positive year formatted as 6-digit"); +assert.sameValue(instance.toJSON(), "+100000-08-09[u-ca=gregory]", "large positive year formatted as 6-digit"); diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-always.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-always.js index c5a3fe2d16..e3e8affe44 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-always.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-always.js @@ -7,39 +7,6 @@ description: If calendarName is "always", the calendar ID should be included. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "1972-05-02[u-ca=iso8601]", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "1972-05-02[u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "1972-05-02[u-ca=iso8601]", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "1972-05-02[u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1972-05-02[u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const monthday = new Temporal.PlainMonthDay(5, 2, ...args); - const result = monthday.toString({ calendarName: "always" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = always`); -} +const monthday = new Temporal.PlainMonthDay(5, 2); +const result = monthday.toString({ calendarName: "always" }); +assert.sameValue(result, "1972-05-02[u-ca=iso8601]", `built-in ISO calendar for calendarName = always`); diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-auto.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-auto.js index 7ab7659c84..7d9266b3d5 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-auto.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-auto.js @@ -7,39 +7,6 @@ description: If calendarName is "auto", "iso8601" should be omitted. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "05-02", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "1972-05-02[u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "05-02", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "1972-05-02[u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1972-05-02[u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const monthday = new Temporal.PlainMonthDay(5, 2, ...args); - const result = monthday.toString({ calendarName: "auto" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = auto`); -} +const monthday = new Temporal.PlainMonthDay(5, 2); +const result = monthday.toString({ calendarName: "auto" }); +assert.sameValue(result, "05-02", `built-in ISO calendar for calendarName = auto`); diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-critical.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-critical.js index 60d26a57d0..a446d581b5 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-critical.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-critical.js @@ -9,39 +9,6 @@ description: > features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "1972-05-02[!u-ca=iso8601]", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "1972-05-02[!u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "1972-05-02[!u-ca=iso8601]", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "1972-05-02[!u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1972-05-02[!u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const monthday = new Temporal.PlainMonthDay(5, 2, ...args); - const result = monthday.toString({ calendarName: "critical" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = critical`); -} +const monthday = new Temporal.PlainMonthDay(5, 2); +const result = monthday.toString({ calendarName: "critical" }); +assert.sameValue(result, "1972-05-02[!u-ca=iso8601]", `built-in ISO calendar for calendarName = critical`); diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-never.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-never.js index 50e0459576..09eb10f169 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-never.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-never.js @@ -7,39 +7,6 @@ description: If calendarName is "never", the calendar ID should be omitted. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "05-02", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "1972-05-02", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "05-02", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "1972-05-02", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1972-05-02", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const monthday = new Temporal.PlainMonthDay(5, 2, ...args); - const result = monthday.toString({ calendarName: "never" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = never`); -} +const monthday = new Temporal.PlainMonthDay(5, 2); +const result = monthday.toString({ calendarName: "never" }); +assert.sameValue(result, "05-02", `built-in ISO calendar for calendarName = never`); diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-undefined.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-undefined.js index 67c1d3a628..7d963de36b 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-undefined.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-undefined.js @@ -14,40 +14,7 @@ info: | features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "05-02", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "1972-05-02[u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "05-02", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "1972-05-02[u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1972-05-02[u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const monthday = new Temporal.PlainMonthDay(5, 2, ...args); - const result = monthday.toString({ calendarName: undefined }); - assert.sameValue(result, expected, `default calendarName option is auto with ${description} calendar`); - // See options-object.js for {} and options-undefined.js for absent options arg -} +const monthday = new Temporal.PlainMonthDay(5, 2); +const result = monthday.toString({ calendarName: undefined }); +assert.sameValue(result, "05-02", `default calendarName option is auto with built-in ISO calendar`); +// See options-object.js for {} and options-undefined.js for absent options arg diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-wrong-type.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-wrong-type.js index efbc3a6138..03f8f6b2fb 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-wrong-type.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-wrong-type.js @@ -15,32 +15,9 @@ includes: [compareArray.js, temporalHelpers.js] features: [Temporal] ---*/ -const calendar = { - id: "custom", - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -const monthday = new Temporal.PlainMonthDay(5, 2, calendar); +const monthday = new Temporal.PlainMonthDay(5, 2, "iso8601"); TemporalHelpers.checkStringOptionWrongType("calendarName", "auto", (calendarName) => monthday.toString({ calendarName }), - (result, descr) => assert.sameValue(result, "1972-05-02[u-ca=custom]", descr), + (result, descr) => assert.sameValue(result, "05-02", descr), ); diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/options-undefined.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/options-undefined.js index 73b5c8361b..906740b3c5 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/options-undefined.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/options-undefined.js @@ -7,35 +7,9 @@ description: Verify that undefined options are handled correctly. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - const tests = [ [[], "05-02"], - [[{ id: "custom", ...calendarMethods }], "1972-05-02[u-ca=custom]"], - [[{ id: "iso8601", ...calendarMethods }], "05-02"], - [[{ id: "ISO8601", ...calendarMethods }], "1972-05-02[u-ca=ISO8601]"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1972-05-02[u-ca=\u0131so8601]"], // dotless i + [["gregory"], "1972-05-02[u-ca=gregory]"], ]; for (const [args, expected] of tests) { diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/order-of-operations.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/order-of-operations.js index 36819f6838..cb6957378b 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/order-of-operations.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/order-of-operations.js @@ -12,7 +12,6 @@ const expected = [ "get options.calendarName", "get options.calendarName.toString", "call options.calendarName.toString", - "get this.calendar.id", ]; const actual = []; diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/year-format.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/year-format.js index da4aaeb7cb..ae3f43542d 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/year-format.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/year-format.js @@ -9,47 +9,43 @@ features: [Temporal] // For PlainMonthDay, the ISO reference year is only present in the string if // the calendar is not ISO 8601 -class NotISO extends Temporal.Calendar { - constructor() { super("iso8601"); } - get id() { return "not-iso"; } -} -const calendar = new NotISO(); +const calendar = "gregory"; let instance = new Temporal.PlainMonthDay(12, 3, calendar, -100000); -assert.sameValue(instance.toString(), "-100000-12-03[u-ca=not-iso]", "large negative year formatted as 6-digit"); +assert.sameValue(instance.toString(), "-100000-12-03[u-ca=gregory]", "large negative year formatted as 6-digit"); instance = new Temporal.PlainMonthDay(4, 5, calendar, -10000); -assert.sameValue(instance.toString(), "-010000-04-05[u-ca=not-iso]", "smallest 5-digit negative year formatted as 6-digit"); +assert.sameValue(instance.toString(), "-010000-04-05[u-ca=gregory]", "smallest 5-digit negative year formatted as 6-digit"); instance = new Temporal.PlainMonthDay(6, 7, calendar, -9999); -assert.sameValue(instance.toString(), "-009999-06-07[u-ca=not-iso]", "largest 4-digit negative year formatted as 6-digit"); +assert.sameValue(instance.toString(), "-009999-06-07[u-ca=gregory]", "largest 4-digit negative year formatted as 6-digit"); instance = new Temporal.PlainMonthDay(8, 9, calendar, -1000); -assert.sameValue(instance.toString(), "-001000-08-09[u-ca=not-iso]", "smallest 4-digit negative year formatted as 6-digit"); +assert.sameValue(instance.toString(), "-001000-08-09[u-ca=gregory]", "smallest 4-digit negative year formatted as 6-digit"); instance = new Temporal.PlainMonthDay(10, 9, calendar, -999); -assert.sameValue(instance.toString(), "-000999-10-09[u-ca=not-iso]", "largest 3-digit negative year formatted as 6-digit"); +assert.sameValue(instance.toString(), "-000999-10-09[u-ca=gregory]", "largest 3-digit negative year formatted as 6-digit"); instance = new Temporal.PlainMonthDay(8, 7, calendar, -1); -assert.sameValue(instance.toString(), "-000001-08-07[u-ca=not-iso]", "year -1 formatted as 6-digit"); +assert.sameValue(instance.toString(), "-000001-08-07[u-ca=gregory]", "year -1 formatted as 6-digit"); instance = new Temporal.PlainMonthDay(6, 5, calendar, 0); -assert.sameValue(instance.toString(), "0000-06-05[u-ca=not-iso]", "year 0 formatted as 4-digit"); +assert.sameValue(instance.toString(), "0000-06-05[u-ca=gregory]", "year 0 formatted as 4-digit"); instance = new Temporal.PlainMonthDay(4, 3, calendar, 1); -assert.sameValue(instance.toString(), "0001-04-03[u-ca=not-iso]", "year 1 formatted as 4-digit"); +assert.sameValue(instance.toString(), "0001-04-03[u-ca=gregory]", "year 1 formatted as 4-digit"); instance = new Temporal.PlainMonthDay(2, 10, calendar, 999); -assert.sameValue(instance.toString(), "0999-02-10[u-ca=not-iso]", "largest 3-digit positive year formatted as 4-digit"); +assert.sameValue(instance.toString(), "0999-02-10[u-ca=gregory]", "largest 3-digit positive year formatted as 4-digit"); instance = new Temporal.PlainMonthDay(1, 23, calendar, 1000); -assert.sameValue(instance.toString(), "1000-01-23[u-ca=not-iso]", "smallest 4-digit positive year formatted as 4-digit"); +assert.sameValue(instance.toString(), "1000-01-23[u-ca=gregory]", "smallest 4-digit positive year formatted as 4-digit"); instance = new Temporal.PlainMonthDay(4, 5, calendar, 9999); -assert.sameValue(instance.toString(), "9999-04-05[u-ca=not-iso]", "largest 4-digit positive year formatted as 4-digit"); +assert.sameValue(instance.toString(), "9999-04-05[u-ca=gregory]", "largest 4-digit positive year formatted as 4-digit"); instance = new Temporal.PlainMonthDay(6, 7, calendar, 10000); -assert.sameValue(instance.toString(), "+010000-06-07[u-ca=not-iso]", "smallest 5-digit positive year formatted as 6-digit"); +assert.sameValue(instance.toString(), "+010000-06-07[u-ca=gregory]", "smallest 5-digit positive year formatted as 6-digit"); instance = new Temporal.PlainMonthDay(8, 9, calendar, 100000); -assert.sameValue(instance.toString(), "+100000-08-09[u-ca=not-iso]", "large positive year formatted as 6-digit"); +assert.sameValue(instance.toString(), "+100000-08-09[u-ca=gregory]", "large positive year formatted as 6-digit"); diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/with/order-of-operations.js b/test/built-ins/Temporal/PlainMonthDay/prototype/with/order-of-operations.js index d01ce31c21..d133168362 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/with/order-of-operations.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/with/order-of-operations.js @@ -12,23 +12,10 @@ const expected = [ // RejectObjectWithCalendarOrTimeZone "get fields.calendar", "get fields.timeZone", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", + // GetTemporalOverflowOption "get options.overflow", - "getOwnPropertyDescriptor options.extra", - "get options.extra", - // lookup - "get this.calendar.fields", - "get this.calendar.mergeFields", - "get this.calendar.monthDayFromFields", - // CalendarFields - "call this.calendar.fields", - // PrepareTemporalFields on receiver - "get this.calendar.day", - "call this.calendar.day", - "get this.calendar.monthCode", - "call this.calendar.monthCode", + "get options.overflow.toString", + "call options.overflow.toString", // PrepareTemporalFields on argument "get fields.day", "get fields.day.valueOf", @@ -42,13 +29,6 @@ const expected = [ "get fields.year", "get fields.year.valueOf", "call fields.year.valueOf", - // CalendarMergeFields - "call this.calendar.mergeFields", - // CalendarMonthDayFromFields - "call this.calendar.monthDayFromFields", - // inside Calendar.p.monthDayFromFields - "get options.overflow.toString", - "call options.overflow.toString", ]; const actual = []; diff --git a/test/built-ins/Temporal/PlainTime/compare/exhaustive.js b/test/built-ins/Temporal/PlainTime/compare/exhaustive.js index 05d3688121..1112f1c488 100644 --- a/test/built-ins/Temporal/PlainTime/compare/exhaustive.js +++ b/test/built-ins/Temporal/PlainTime/compare/exhaustive.js @@ -7,109 +7,106 @@ description: Tests for compare() with each possible outcome features: [Temporal] ---*/ -const cal1 = "iso8601"; -const cal2 = new (class extends Temporal.Calendar { id = "custom"; })("iso8601"); - assert.sameValue( Temporal.PlainTime.compare( - new Temporal.PlainTime(12, 15, 45, 333, 777, 111, cal1), - new Temporal.PlainTime(6, 15, 45, 333, 777, 111, cal2) + new Temporal.PlainTime(12, 15, 45, 333, 777, 111), + new Temporal.PlainTime(6, 15, 45, 333, 777, 111) ), 1, "hour >" ); assert.sameValue( Temporal.PlainTime.compare( - new Temporal.PlainTime(6, 30, 15, 222, 444, 6, cal1), - new Temporal.PlainTime(22, 30, 15, 222, 444, 6, cal2) + new Temporal.PlainTime(6, 30, 15, 222, 444, 6), + new Temporal.PlainTime(22, 30, 15, 222, 444, 6) ), -1, "hour <" ); assert.sameValue( Temporal.PlainTime.compare( - new Temporal.PlainTime(12, 45, 15, 333, 777, 111, cal1), - new Temporal.PlainTime(12, 15, 22, 333, 777, 111, cal2) + new Temporal.PlainTime(12, 45, 15, 333, 777, 111), + new Temporal.PlainTime(12, 15, 22, 333, 777, 111) ), 1, "minute >" ); assert.sameValue( Temporal.PlainTime.compare( - new Temporal.PlainTime(6, 30, 15, 222, 444, 6, cal1), - new Temporal.PlainTime(6, 57, 15, 222, 444, 6, cal2) + new Temporal.PlainTime(6, 30, 15, 222, 444, 6), + new Temporal.PlainTime(6, 57, 15, 222, 444, 6) ), -1, "minute <" ); assert.sameValue( Temporal.PlainTime.compare( - new Temporal.PlainTime(12, 15, 6, 333, 777, 111, cal1), - new Temporal.PlainTime(12, 15, 5, 333, 777, 111, cal2) + new Temporal.PlainTime(12, 15, 6, 333, 777, 111), + new Temporal.PlainTime(12, 15, 5, 333, 777, 111) ), 1, "second >" ); assert.sameValue( Temporal.PlainTime.compare( - new Temporal.PlainTime(6, 30, 3, 222, 444, 6, cal1), - new Temporal.PlainTime(6, 30, 4, 222, 444, 6, cal2) + new Temporal.PlainTime(6, 30, 3, 222, 444, 6), + new Temporal.PlainTime(6, 30, 4, 222, 444, 6) ), -1, "second <" ); assert.sameValue( Temporal.PlainTime.compare( - new Temporal.PlainTime(12, 15, 45, 6, 777, 111, cal1), - new Temporal.PlainTime(12, 15, 45, 5, 777, 111, cal2) + new Temporal.PlainTime(12, 15, 45, 6, 777, 111), + new Temporal.PlainTime(12, 15, 45, 5, 777, 111) ), 1, "millisecond >" ); assert.sameValue( Temporal.PlainTime.compare( - new Temporal.PlainTime(6, 30, 15, 3, 444, 6, cal1), - new Temporal.PlainTime(6, 30, 15, 4, 444, 6, cal2) + new Temporal.PlainTime(6, 30, 15, 3, 444, 6), + new Temporal.PlainTime(6, 30, 15, 4, 444, 6) ), -1, "millisecond <" ); assert.sameValue( Temporal.PlainTime.compare( - new Temporal.PlainTime(12, 15, 45, 333, 6, 111, cal1), - new Temporal.PlainTime(12, 15, 45, 333, 5, 111, cal2) + new Temporal.PlainTime(12, 15, 45, 333, 6, 111), + new Temporal.PlainTime(12, 15, 45, 333, 5, 111) ), 1, "microsecond >" ); assert.sameValue( Temporal.PlainTime.compare( - new Temporal.PlainTime(6, 30, 15, 222, 3, 6, cal1), - new Temporal.PlainTime(6, 30, 15, 222, 4, 6, cal2) + new Temporal.PlainTime(6, 30, 15, 222, 3, 6), + new Temporal.PlainTime(6, 30, 15, 222, 4, 6) ), -1, "microsecond <" ); assert.sameValue( Temporal.PlainTime.compare( - new Temporal.PlainTime(12, 15, 45, 333, 777, 999, cal1), - new Temporal.PlainTime(12, 15, 45, 333, 777, 111, cal2) + new Temporal.PlainTime(12, 15, 45, 333, 777, 999), + new Temporal.PlainTime(12, 15, 45, 333, 777, 111) ), 1, "nanosecond >" ); assert.sameValue( Temporal.PlainTime.compare( - new Temporal.PlainTime(6, 30, 15, 222, 444, 0, cal1), - new Temporal.PlainTime(6, 30, 15, 222, 444, 6, cal2) + new Temporal.PlainTime(6, 30, 15, 222, 444, 0), + new Temporal.PlainTime(6, 30, 15, 222, 444, 6) ), -1, "nanosecond <" ); assert.sameValue( Temporal.PlainTime.compare( - new Temporal.PlainTime(12, 15, 45, 333, 777, 111, cal1), - new Temporal.PlainTime(12, 15, 45, 333, 777, 111, cal2) + new Temporal.PlainTime(12, 15, 45, 333, 777, 111), + new Temporal.PlainTime(12, 15, 45, 333, 777, 111) ), 0, "=" diff --git a/test/built-ins/Temporal/PlainTime/prototype/since/order-of-operations.js b/test/built-ins/Temporal/PlainTime/prototype/since/order-of-operations.js index 2397853675..a84c7670d5 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/since/order-of-operations.js +++ b/test/built-ins/Temporal/PlainTime/prototype/since/order-of-operations.js @@ -28,25 +28,17 @@ const expected = [ "get other.second", "get other.second.valueOf", "call other.second.valueOf", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.roundingIncrement", - "get options.roundingIncrement", - "getOwnPropertyDescriptor options.roundingMode", - "get options.roundingMode", - "getOwnPropertyDescriptor options.largestUnit", - "get options.largestUnit", - "getOwnPropertyDescriptor options.smallestUnit", - "get options.smallestUnit", - "getOwnPropertyDescriptor options.additional", - "get options.additional", // GetDifferenceSettings + "get options.largestUnit", "get options.largestUnit.toString", "call options.largestUnit.toString", + "get options.roundingIncrement", "get options.roundingIncrement.valueOf", "call options.roundingIncrement.valueOf", + "get options.roundingMode", "get options.roundingMode.toString", "call options.roundingMode.toString", + "get options.smallestUnit", "get options.smallestUnit.toString", "call options.smallestUnit.toString", ]; @@ -76,17 +68,3 @@ const result = instance.since(other, options); assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -// short-circuit does not skip reading options -const identicalPropertyBag = TemporalHelpers.propertyBagObserver(actual, { - hour: 12, - minute: 34, - second: 56, - millisecond: 987, - microsecond: 654, - nanosecond: 321, -}, "other"); -instance.since(identicalPropertyBag, options); -assert.compareArray(actual, expected, "order of operations with identical times"); - -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/PlainTime/prototype/until/order-of-operations.js b/test/built-ins/Temporal/PlainTime/prototype/until/order-of-operations.js index 76f5670cc0..31de91d60b 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/until/order-of-operations.js +++ b/test/built-ins/Temporal/PlainTime/prototype/until/order-of-operations.js @@ -28,25 +28,17 @@ const expected = [ "get other.second", "get other.second.valueOf", "call other.second.valueOf", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.roundingIncrement", - "get options.roundingIncrement", - "getOwnPropertyDescriptor options.roundingMode", - "get options.roundingMode", - "getOwnPropertyDescriptor options.largestUnit", - "get options.largestUnit", - "getOwnPropertyDescriptor options.smallestUnit", - "get options.smallestUnit", - "getOwnPropertyDescriptor options.additional", - "get options.additional", // GetDifferenceSettings + "get options.largestUnit", "get options.largestUnit.toString", "call options.largestUnit.toString", + "get options.roundingIncrement", "get options.roundingIncrement.valueOf", "call options.roundingIncrement.valueOf", + "get options.roundingMode", "get options.roundingMode.toString", "call options.roundingMode.toString", + "get options.smallestUnit", "get options.smallestUnit.toString", "call options.smallestUnit.toString", ]; diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/compare-calendar.js b/test/built-ins/Temporal/PlainYearMonth/compare/compare-calendar.js index a3b9185118..90eac9a39d 100644 --- a/test/built-ins/Temporal/PlainYearMonth/compare/compare-calendar.js +++ b/test/built-ins/Temporal/PlainYearMonth/compare/compare-calendar.js @@ -7,16 +7,6 @@ description: compare() does not take the calendar into account features: [Temporal] ---*/ -class CustomCalendar extends Temporal.Calendar { - constructor(id) { - super("iso8601"); - this._id = id; - } - toString() { - return this._id; - } -} - -const ym1 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("a"), 1); -const ym2 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("b"), 1); +const ym1 = new Temporal.PlainYearMonth(2000, 1, "iso8601", 1); +const ym2 = new Temporal.PlainYearMonth(2000, 1, "gregory", 1); assert.sameValue(Temporal.PlainYearMonth.compare(ym1, ym2), 0); diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/exhaustive.js b/test/built-ins/Temporal/PlainYearMonth/compare/exhaustive.js index 99ad5ca200..ee203d1afd 100644 --- a/test/built-ins/Temporal/PlainYearMonth/compare/exhaustive.js +++ b/test/built-ins/Temporal/PlainYearMonth/compare/exhaustive.js @@ -8,7 +8,7 @@ features: [Temporal] ---*/ const cal1 = "iso8601"; -const cal2 = new (class extends Temporal.Calendar { id = "custom"; })("iso8601"); +const cal2 = "gregory"; assert.sameValue( Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2000, 5, cal1), new Temporal.PlainYearMonth(1987, 5, cal2)), diff --git a/test/built-ins/Temporal/PlainYearMonth/from/basic.js b/test/built-ins/Temporal/PlainYearMonth/from/basic.js new file mode 100644 index 0000000000..12b56cd953 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/basic.js @@ -0,0 +1,30 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: Returns correctly with valid data +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +let result = Temporal.PlainYearMonth.from({ year: 2021, month: 7 }); +TemporalHelpers.assertPlainYearMonth(result, 2021, 7, "M07", "year 2021, month 7"); +result = Temporal.PlainYearMonth.from({ year: 2021, month: 12 }); +TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "year 2021, month 12"); +result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M07" }); +TemporalHelpers.assertPlainYearMonth(result, 2021, 7, "M07", "year 2021, monthCode M07"); +result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M12" }); +TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "year 2021, monthCode M12"); + +["constrain", "reject"].forEach((overflow) => { + const opt = { overflow }; + result = Temporal.PlainYearMonth.from({ year: 2021, month: 7 }, opt); + TemporalHelpers.assertPlainYearMonth(result, 2021, 7, "M07", `year 2021, month 7, overflow ${overflow}`); + result = Temporal.PlainYearMonth.from({ year: 2021, month: 12 }, opt); + TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", `year 2021, month 12, overflow ${overflow}`); + result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M07" }, opt); + TemporalHelpers.assertPlainYearMonth(result, 2021, 7, "M07", `year 2021, monthCode M07, overflow ${overflow}`); + result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M12" }, opt); + TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", `year 2021, monthCode M12, overflow ${overflow}`); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/fields-missing-properties.js b/test/built-ins/Temporal/PlainYearMonth/from/fields-missing-properties.js new file mode 100644 index 0000000000..fbb68678d2 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/fields-missing-properties.js @@ -0,0 +1,12 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: Throws TypeError with incorrect input data type +features: [Temporal] +---*/ + +assert.throws(TypeError, () => Temporal.PlainYearMonth.from({}), "at least one correctly spelled property is required"); +assert.throws(TypeError, () => Temporal.PlainYearMonth.from({ month: 1 }), "year is required"); +assert.throws(TypeError, () => Temporal.PlainYearMonth.from({ year: 2021 }), "month or monthCode is required"); diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/missing-properties.js b/test/built-ins/Temporal/PlainYearMonth/from/missing-properties.js similarity index 73% rename from test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/missing-properties.js rename to test/built-ins/Temporal/PlainYearMonth/from/missing-properties.js index d8fb8e2b9e..8ca897742c 100644 --- a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/missing-properties.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/missing-properties.js @@ -2,13 +2,11 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.yearmonthfromfields +esid: sec-temporal.plainyearmonth.from description: Errors due to missing properties on fields object are thrown in the correct order features: [Temporal] ---*/ -const instance = new Temporal.Calendar("iso8601"); - let getMonth = false; let getMonthCode = false; const missingYearAndMonth = { @@ -19,8 +17,8 @@ const missingYearAndMonth = { getMonthCode = true; }, }; -assert.throws(TypeError, () => instance.yearMonthFromFields(missingYearAndMonth), "year should be checked after fetching but before resolving the month"); +assert.throws(TypeError, () => Temporal.PlainYearMonth.from(missingYearAndMonth), "year should be checked after fetching but before resolving the month"); assert(getMonth, "year is fetched after month"); assert(getMonthCode, "year is fetched after monthCode"); -assert.throws(TypeError, () => instance.yearMonthFromFields({ year: 2000 }), "month should be resolved last"); +assert.throws(TypeError, () => Temporal.PlainYearMonth.from({ year: 2000 }), "month should be resolved last"); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/monthcode-invalid.js b/test/built-ins/Temporal/PlainYearMonth/from/monthcode-invalid.js new file mode 100644 index 0000000000..84357f8890 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/monthcode-invalid.js @@ -0,0 +1,21 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: Throw RangeError for an out-of-range, conflicting, or ill-formed monthCode +features: [Temporal] +---*/ + +["m1", "M1", "m01"].forEach((monthCode) => { + assert.throws(RangeError, () => Temporal.PlainYearMonth.from({ year: 2021, monthCode }), + `monthCode '${monthCode}' is not well-formed`); +}); + +assert.throws(RangeError, () => Temporal.PlainYearMonth.from({ year: 2021, month: 12, monthCode: "M11" }), + "monthCode and month conflict"); + +["M00", "M19", "M99", "M13"].forEach((monthCode) => { + assert.throws(RangeError, () => Temporal.PlainYearMonth.from({ year: 2021, monthCode }), + `monthCode '${monthCode}' is not valid for year 2021`); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-primitive.js b/test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-primitive.js index 66eeb90b34..1714a0a460 100644 --- a/test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-primitive.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-primitive.js @@ -9,8 +9,6 @@ features: [Temporal] ---*/ const expected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", @@ -25,9 +23,9 @@ TemporalHelpers.assertPlainYearMonth(result, 2021, 5, "M05"); actual.splice(0); // empty it for the next check const failureExpected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", + "get options.overflow.toString", + "call options.overflow.toString", ]; assert.throws(TypeError, () => Temporal.PlainYearMonth.from(7, options)); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-string-invalid.js b/test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-string-invalid.js index 7fa6807b3e..774824f76b 100644 --- a/test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-string-invalid.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-string-invalid.js @@ -9,9 +9,9 @@ features: [Temporal] ---*/ const expected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", + "get options.overflow.toString", + "call options.overflow.toString", ]; let actual = []; diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/one-of-era-erayear-undefined.js b/test/built-ins/Temporal/PlainYearMonth/from/one-of-era-erayear-undefined.js similarity index 56% rename from test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/one-of-era-erayear-undefined.js rename to test/built-ins/Temporal/PlainYearMonth/from/one-of-era-erayear-undefined.js index 9cb06acd19..524b01f9ec 100644 --- a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/one-of-era-erayear-undefined.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/one-of-era-erayear-undefined.js @@ -2,15 +2,14 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.yearMonthFromFields +esid: sec-temporal.plainyearmonth.from description: Does not throw a RangeError if only one of era/eraYear fields is present features: [Temporal] includes: [temporalHelpers.js] ---*/ const base = { year: 2000, month: 5, day: 2, era: 'ce' }; -const instance = new Temporal.Calendar('iso8601'); -TemporalHelpers.assertPlainYearMonth(instance.yearMonthFromFields({ ...base }), 2000, 5, 'M05'); +TemporalHelpers.assertPlainYearMonth(Temporal.PlainYearMonth.from(base), 2000, 5, 'M05'); const base2 = { year: 2000, month: 5, day: 2, eraYear: 1 }; -TemporalHelpers.assertPlainYearMonth(instance.yearMonthFromFields({ ...base }), 2000, 5, 'M05'); +TemporalHelpers.assertPlainYearMonth(Temporal.PlainYearMonth.from(base2), 2000, 5, 'M05'); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/order-of-operations.js b/test/built-ins/Temporal/PlainYearMonth/from/order-of-operations.js index df023ba824..92451a2f5a 100644 --- a/test/built-ins/Temporal/PlainYearMonth/from/order-of-operations.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/order-of-operations.js @@ -10,39 +10,11 @@ features: [Temporal] const expected = [ // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", - "getOwnPropertyDescriptor options.extra", - "get options.extra", + "get options.overflow.toString", + "call options.overflow.toString", // GetTemporalCalendarSlotValueWithISODefault "get fields.calendar", - "has fields.calendar.dateAdd", - "has fields.calendar.dateFromFields", - "has fields.calendar.dateUntil", - "has fields.calendar.day", - "has fields.calendar.dayOfWeek", - "has fields.calendar.dayOfYear", - "has fields.calendar.daysInMonth", - "has fields.calendar.daysInWeek", - "has fields.calendar.daysInYear", - "has fields.calendar.fields", - "has fields.calendar.id", - "has fields.calendar.inLeapYear", - "has fields.calendar.mergeFields", - "has fields.calendar.month", - "has fields.calendar.monthCode", - "has fields.calendar.monthDayFromFields", - "has fields.calendar.monthsInYear", - "has fields.calendar.weekOfYear", - "has fields.calendar.year", - "has fields.calendar.yearMonthFromFields", - "has fields.calendar.yearOfWeek", - // lookup - "get fields.calendar.fields", - "get fields.calendar.yearMonthFromFields", - // CalendarFields - "call fields.calendar.fields", // PrepareTemporalFields "get fields.month", "get fields.month.valueOf", @@ -53,11 +25,6 @@ const expected = [ "get fields.year", "get fields.year.valueOf", "call fields.year.valueOf", - // CalendarYearMonthFromFields - "call fields.calendar.yearMonthFromFields", - // inside Calendar.p.yearMonthFromFields - "get options.overflow.toString", - "call options.overflow.toString", ]; const actual = []; diff --git a/test/built-ins/Temporal/PlainYearMonth/from/overflow-constrain.js b/test/built-ins/Temporal/PlainYearMonth/from/overflow-constrain.js index c1cacdf619..5bda3f57b6 100644 --- a/test/built-ins/Temporal/PlainYearMonth/from/overflow-constrain.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/overflow-constrain.js @@ -12,3 +12,75 @@ const propertyBag = { year: 2000, month: 13 }; const plainYearMonth = Temporal.PlainYearMonth.from(propertyBag, { overflow: "constrain" }); TemporalHelpers.assertPlainYearMonth(plainYearMonth, 2000, 12, "M12", "default overflow is constrain"); +const opt = { overflow: "constrain" }; + +let result = Temporal.PlainYearMonth.from({ year: 2021, month: 1 }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 1, "M01", "month 1 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, month: 2 }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 2, "M02", "month 2 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, month: 3 }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 3, "M03", "month 3 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, month: 4 }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 4, "M04", "month 4 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, month: 5 }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 5, "M05", "month 5 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, month: 6 }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 6, "M06", "month 6 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, month: 7 }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 7, "M07", "month 7 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, month: 8 }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 8, "M08", "month 8 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, month: 9 }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 9, "M09", "month 9 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, month: 10 }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 10, "M10", "month 10 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, month: 11 }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 11, "M11", "month 11 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, month: 12 }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "month 12 with overflow constrain"); + +assert.throws( + RangeError, + () => Temporal.PlainYearMonth.from({ year: 2021, month: -99999 }, opt), + "negative month -99999 is out of range even with overflow constrain" +) +assert.throws( + RangeError, + () => Temporal.PlainYearMonth.from({ year: 2021, month: -1 }, opt), + "negative month -1 is out of range even with overflow constrain" +) +assert.throws( + RangeError, + () => Temporal.PlainYearMonth.from({ year: 2021, month: 0 }, opt), + "month zero is out of range even with overflow constrain" +) + +result = Temporal.PlainYearMonth.from({ year: 2021, month: 13 }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "month 13 is constrained to 12"); +result = Temporal.PlainYearMonth.from({ year: 2021, month: 99999 }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "month 99999 is constrained to 12"); + +result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M01" }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 1, "M01", "monthCode M01 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M02" }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 2, "M02", "monthCode M02 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M03" }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 3, "M03", "monthCode M03 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M04" }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 4, "M04", "monthCode M04 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M05" }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 5, "M05", "monthCode M05 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M06" }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 6, "M06", "monthCode M06 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M07" }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 7, "M07", "monthCode M07 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M08" }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 8, "M08", "monthCode M08 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M09" }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 9, "M09", "monthCode M09 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M10" }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 10, "M10", "monthCode M10 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M11" }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 11, "M11", "monthCode M11 with overflow constrain"); +result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M12" }, opt); +TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "monthCode M12 with overflow constrain"); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/overflow-reject.js b/test/built-ins/Temporal/PlainYearMonth/from/overflow-reject.js index 86e4151cd5..64d6d082d1 100644 --- a/test/built-ins/Temporal/PlainYearMonth/from/overflow-reject.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/overflow-reject.js @@ -9,3 +9,11 @@ features: [Temporal] const bad = { year: 2019, month: 13 }; assert.throws(RangeError, () => Temporal.PlainYearMonth.from(bad, { overflow: "reject" })); + +[-1, 0, 13, 9995].forEach((month) => { + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.from({year: 2021, month, day: 5}, { overflow: "reject" }), + `Month ${month} is out of range for 2021 with overflow: reject` + ); +}); diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/reference-day.js b/test/built-ins/Temporal/PlainYearMonth/from/reference-day.js similarity index 72% rename from test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/reference-day.js rename to test/built-ins/Temporal/PlainYearMonth/from/reference-day.js index 2d6fca7269..d8500272c4 100644 --- a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/reference-day.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/reference-day.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.yearmonthfromfields +esid: sec-temporal.plainyearmonth.from description: Reference ISO day is chosen to be the first of the calendar month info: | 6.d. Perform ! CreateDataPropertyOrThrow(_fields_, *"day"*, *1*𝔽). @@ -11,9 +11,7 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const cal = new Temporal.Calendar("iso8601"); - -const result1 = cal.yearMonthFromFields({ year: 2023, monthCode: "M01", day: 13 }); +const result1 = Temporal.PlainYearMonth.from({ year: 2023, monthCode: "M01", day: 13 }); TemporalHelpers.assertPlainYearMonth( result1, 2023, 1, "M01", @@ -21,7 +19,7 @@ TemporalHelpers.assertPlainYearMonth( /* era = */ undefined, /* era year = */ undefined, /* reference day = */ 1 ); -const result2 = cal.yearMonthFromFields({ year: 2021, monthCode: "M02", day: 50 }, { overflow: "constrain" }); +const result2 = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M02", day: 50 }, { overflow: "constrain" }); TemporalHelpers.assertPlainYearMonth( result2, 2021, 2, "M02", @@ -29,7 +27,7 @@ TemporalHelpers.assertPlainYearMonth( /* era = */ undefined, /* era year = */ undefined, /* reference day = */ 1 ); -const result3 = cal.yearMonthFromFields({ year: 2021, monthCode: "M02", day: 50 }, { overflow: "reject" }); +const result3 = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M02", day: 50 }, { overflow: "reject" }); TemporalHelpers.assertPlainYearMonth( result3, 2021, 2, "M02", diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/end-of-month-out-of-range.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/end-of-month-out-of-range.js index bdae83c18b..af1dbfc2b0 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/add/end-of-month-out-of-range.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/add/end-of-month-out-of-range.js @@ -20,11 +20,3 @@ const duration = new Temporal.Duration(0, 0, 0, -1); // Calendar addition result is out of range assert.throws(RangeError, () => new Temporal.PlainYearMonth(275760, 9).add(duration), "Addition of 1 month to receiver out of range"); - -// Calendar addition succeeds, but subtracting 1 day gives out of range result -const cal = new class extends Temporal.Calendar { - dateAdd() { - return new Temporal.PlainDate(-271821, 4, 19); - } -}("iso8601"); -assert.throws(RangeError, () => new Temporal.PlainYearMonth(2000, 1, cal).add(duration), "Subtraction of 1 day from next month out of range"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/options-undefined.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/options-undefined.js index c13d1ca842..999aaaef7c 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/add/options-undefined.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/add/options-undefined.js @@ -8,23 +8,16 @@ features: [Temporal] ---*/ // overflow option has no effect on addition in the ISO calendar, so verify this -// with a custom calendar -class CheckedAdd extends Temporal.Calendar { - constructor() { - super("iso8601"); - } - dateAdd(date, duration, options, constructor) { - this.called = true; - assert.notSameValue(options, undefined, "options not undefined"); - return super.dateAdd(date, duration, options, constructor); - } -} -const calendar = new CheckedAdd(); +// with a lunisolar calendar. Default overflow is "constrain" so this should not +// throw. -const yearmonth = new Temporal.PlainYearMonth(2000, 1, calendar); -const duration = { months: 1 }; +const yearmonth = Temporal.PlainYearMonth.from({ + year: 5779, + monthCode: "M05L", + calendar: "hebrew" +}); +const duration = { years: 1 }; yearmonth.add(duration, undefined); -yearmonth.add(duration); -assert(calendar.called); +yearmonth.add(duration); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/order-of-operations.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/order-of-operations.js index d7f3e65ba8..0045f2fb5c 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/add/order-of-operations.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/add/order-of-operations.js @@ -40,39 +40,8 @@ const expected = [ "get fields.years", "get fields.years.valueOf", "call fields.years.valueOf", - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateFromFields", - "get this.calendar.day", - "get this.calendar.fields", - "get this.calendar.yearMonthFromFields", - // CalendarFields - "call this.calendar.fields", - // PrepareTemporalFields on receiver - "get this.calendar.monthCode", - "call this.calendar.monthCode", - "get this.calendar.year", - "call this.calendar.year", - // CalendarDateFromFields - "call this.calendar.dateFromFields", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", + // GetTemporalOverflowOption "get options.overflow", - // CalendarDateAdd - "call this.calendar.dateAdd", - // inside Calendar.p.dateAdd - "get options.overflow", - "get options.overflow.toString", - "call options.overflow.toString", - // PrepareTemporalFields on added date - "get this.calendar.monthCode", - "call this.calendar.monthCode", - "get this.calendar.year", - "call this.calendar.year", - // CalendarYearMonthFromFields - "call this.calendar.yearMonthFromFields", - // inside Calendar.p.yearMonthFromFields "get options.overflow.toString", "call options.overflow.toString", ]; @@ -99,79 +68,3 @@ instance.add(fields, options); assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -const noCalendarExpected = [ - // ToTemporalDuration - "get fields.days", - "get fields.days.valueOf", - "call fields.days.valueOf", - "get fields.hours", - "get fields.hours.valueOf", - "call fields.hours.valueOf", - "get fields.microseconds", - "get fields.microseconds.valueOf", - "call fields.microseconds.valueOf", - "get fields.milliseconds", - "get fields.milliseconds.valueOf", - "call fields.milliseconds.valueOf", - "get fields.minutes", - "get fields.minutes.valueOf", - "call fields.minutes.valueOf", - "get fields.months", - "get fields.nanoseconds", - "get fields.nanoseconds.valueOf", - "call fields.nanoseconds.valueOf", - "get fields.seconds", - "get fields.seconds.valueOf", - "call fields.seconds.valueOf", - "get fields.weeks", - "get fields.years", - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateFromFields", - "get this.calendar.day", - "get this.calendar.fields", - "get this.calendar.yearMonthFromFields", - // CalendarFields - "call this.calendar.fields", - // PrepareTemporalFields on receiver - "get this.calendar.monthCode", - "call this.calendar.monthCode", - "get this.calendar.year", - "call this.calendar.year", - // CalendarDateFromFields - "call this.calendar.dateFromFields", - // SnapshotOwnProperties - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", - "get options.overflow", - // AddDate - "get options.overflow", - "get options.overflow.toString", - "call options.overflow.toString", - // PrepareTemporalFields on added date - "get this.calendar.monthCode", - "call this.calendar.monthCode", - "get this.calendar.year", - "call this.calendar.year", - // CalendarYearMonthFromFields - "call this.calendar.yearMonthFromFields", - // inside Calendar.p.yearMonthFromFields - "get options.overflow.toString", - "call options.overflow.toString", -]; - -const noCalendarFields = TemporalHelpers.propertyBagObserver(actual, { - days: 1, - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1, - nanoseconds: 1, -}, "fields"); - -instance.add(noCalendarFields, options); -assert.compareArray(actual, noCalendarExpected, "order of operations with no calendar units"); - -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/overflow-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/overflow-wrong-type.js index 41937f230c..6bc39ff5b7 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/add/overflow-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/add/overflow-wrong-type.js @@ -33,13 +33,9 @@ assert.throws(RangeError, () => yearmonth.add(duration, { overflow: 2 }), "numbe assert.throws(RangeError, () => yearmonth.add(duration, { overflow: 2n }), "bigint"); assert.throws(RangeError, () => yearmonth.add(duration, { overflow: {} }), "plain object"); -// toString property is read once by Calendar.dateAdd() and then once again by -// calendar.yearMonthFromFields(). const expected = [ "get overflow.toString", "call overflow.toString", - "get overflow.toString", - "call overflow.toString", ]; const actual = []; const observer = TemporalHelpers.toPrimitiveObserver(actual, "constrain", "overflow"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/compare-calendar.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/compare-calendar.js index 90244edaca..9eda0a510e 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/compare-calendar.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/compare-calendar.js @@ -8,39 +8,10 @@ includes: [compareArray.js, temporalHelpers.js] features: [Temporal] ---*/ -const actual = []; -class CustomCalendar extends Temporal.Calendar { - constructor(id) { - super("iso8601"); - this._id = id; - } - get id() { - actual.push(this._id); - return this._id; - } - toString() { - TemporalHelpers.assertUnreachable("should not call toString"); - } -} +const ym1 = new Temporal.PlainYearMonth(2000, 1, "iso8601", 1); +const ym2 = new Temporal.PlainYearMonth(2000, 1, "iso8601", 1); +assert(ym1.equals(ym2), "Equal if calendars and ISO dates are equal"); -const sharedCalendar = new CustomCalendar("a"); -const ym1 = new Temporal.PlainYearMonth(2000, 1, sharedCalendar, 1); -const ym2 = new Temporal.PlainYearMonth(2000, 1, sharedCalendar, 1); -assert.sameValue(ym1.equals(ym2), true); -assert.compareArray(actual, [], "should not call toString if objects are equal"); - -const ym3 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("b"), 1); -const ym4 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("c"), 2); -assert.sameValue(ym3.equals(ym4), false); -assert.compareArray(actual, [], "should not call toString if ISO dates differ"); - -const ym5 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("d"), 1); -const ym6 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("e"), 1); -assert.sameValue(ym5.equals(ym6), false); -assert.compareArray(actual, ["d", "e"], "order of operations"); - -actual.splice(0); // empty it for the next check -const ym7 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("f"), 1); -const ym8 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("f"), 1); -assert.sameValue(ym7.equals(ym8), true); -assert.compareArray(actual, ["f", "f"], "order of operations"); +const ym3 = new Temporal.PlainYearMonth(2000, 1, "iso8601", 1); +const ym4 = new Temporal.PlainYearMonth(2000, 1, "gregory", 1); +assert(!ym3.equals(ym4), "Unequal if ISO dates are equal but calendars are not"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/mixed-calendar-invalid.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/mixed-calendar-invalid.js index 8dfa5fb139..614f38cb2b 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/mixed-calendar-invalid.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/mixed-calendar-invalid.js @@ -7,17 +7,7 @@ description: Mixed calendars throw as invalid features: [Temporal] ---*/ -class customCal extends Temporal.Calendar { - constructor () { - super('iso8601'); - } - - get id() { - return "I am a secret cal."; - } -} - const ym1 = new Temporal.PlainYearMonth(2000, 1); -const ym2 = new Temporal.PlainYearMonth(2000, 1, new customCal()); +const ym2 = new Temporal.PlainYearMonth(2000, 1, "gregory"); assert.throws(RangeError, () => ym1.since(ym2), 'since throws with different calendars'); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/order-of-operations.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/order-of-operations.js index 8799ab6c44..84d3bfd6ce 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/order-of-operations.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/order-of-operations.js @@ -8,33 +8,9 @@ includes: [compareArray.js, temporalHelpers.js] features: [Temporal] ---*/ -const expectedMinimal = [ +const expected = [ // ToTemporalYearMonth "get other.calendar", - "has other.calendar.dateAdd", - "has other.calendar.dateFromFields", - "has other.calendar.dateUntil", - "has other.calendar.day", - "has other.calendar.dayOfWeek", - "has other.calendar.dayOfYear", - "has other.calendar.daysInMonth", - "has other.calendar.daysInWeek", - "has other.calendar.daysInYear", - "has other.calendar.fields", - "has other.calendar.id", - "has other.calendar.inLeapYear", - "has other.calendar.mergeFields", - "has other.calendar.month", - "has other.calendar.monthCode", - "has other.calendar.monthDayFromFields", - "has other.calendar.monthsInYear", - "has other.calendar.weekOfYear", - "has other.calendar.year", - "has other.calendar.yearMonthFromFields", - "has other.calendar.yearOfWeek", - "get other.calendar.fields", - "get other.calendar.yearMonthFromFields", - "call other.calendar.fields", "get other.month", "get other.month.valueOf", "call other.month.valueOf", @@ -44,56 +20,20 @@ const expectedMinimal = [ "get other.year", "get other.year.valueOf", "call other.year.valueOf", - "call other.calendar.yearMonthFromFields", - // CalendarEquals - "get this.calendar.id", - "get other.calendar.id", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.roundingIncrement", - "get options.roundingIncrement", - "getOwnPropertyDescriptor options.roundingMode", - "get options.roundingMode", - "getOwnPropertyDescriptor options.largestUnit", - "get options.largestUnit", - "getOwnPropertyDescriptor options.smallestUnit", - "get options.smallestUnit", - "getOwnPropertyDescriptor options.additional", - "get options.additional", // GetDifferenceSettings + "get options.largestUnit", "get options.largestUnit.toString", "call options.largestUnit.toString", + "get options.roundingIncrement", "get options.roundingIncrement.valueOf", "call options.roundingIncrement.valueOf", + "get options.roundingMode", "get options.roundingMode.toString", "call options.roundingMode.toString", + "get options.smallestUnit", "get options.smallestUnit.toString", "call options.smallestUnit.toString", ]; - -const expected = expectedMinimal.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateFromFields", - "get this.calendar.dateUntil", - "get this.calendar.fields", - // CalendarFields - "call this.calendar.fields", - // PrepareTemporalFields / CalendarDateFromFields (receiver) - "get this.calendar.monthCode", - "call this.calendar.monthCode", - "get this.calendar.year", - "call this.calendar.year", - "call this.calendar.dateFromFields", - // PrepareTemporalFields / CalendarDateFromFields (argument) - "get other.calendar.monthCode", - "call other.calendar.monthCode", - "get other.calendar.year", - "call other.calendar.year", - "call this.calendar.dateFromFields", - // CalendarDateUntil - "call this.calendar.dateUntil", -]); const actual = []; const instance = new Temporal.PlainYearMonth(2000, 5, "iso8601", 1); @@ -107,8 +47,6 @@ const otherYearMonthPropertyBag = TemporalHelpers.propertyBagObserver(actual, { function createOptionsObserver({ smallestUnit = "months", largestUnit = "auto", roundingMode = "halfExpand", roundingIncrement = 1 } = {}) { return TemporalHelpers.propertyBagObserver(actual, { - // order is significant, due to iterating through properties in order to - // copy them to an internal null-prototype object: roundingIncrement, roundingMode, largestUnit, @@ -117,55 +55,6 @@ function createOptionsObserver({ smallestUnit = "months", largestUnit = "auto", }, "options"); } -// clear any observable things that happened while constructing the objects -actual.splice(0); - -// code path that skips RoundDuration: instance.since(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "months", roundingIncrement: 1 })); assert.compareArray(actual, expected, "order of operations with no rounding"); actual.splice(0); // clear - -// short-circuit for identical objects: -const identicalPropertyBag = TemporalHelpers.propertyBagObserver(actual, { - year: 2000, - month: 5, - monthCode: "M05", - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), -}, "other"); - -instance.since(identicalPropertyBag, createOptionsObserver()); -assert.compareArray(actual, expectedMinimal, "order of operations with identical year-months"); -actual.splice(0); // clear - -// code path through RoundRelativeDuration that rounds to the nearest year: -const expectedOpsForYearRounding = expected.concat([ - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.since(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "years" })); -assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years"); -actual.splice(0); // clear - -// code path through RoundRelativeDuration that rounds to the nearest year and skips a DateUntil call -const otherYearMonthPropertyBagSameMonth = TemporalHelpers.propertyBagObserver(actual, { - year: 2001, - month: 5, - monthCode: "M05", - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), -}, "other"); -const expectedOpsForYearRoundingSameMonth = expected.concat([ - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.since(otherYearMonthPropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" })); -assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months"); -actual.splice(0); // clear - -// code path through RoundRelativeDuration that rounds to the nearest month: -const expectedOpsForMonthRounding = expected.concat([ - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", // BubbleRelativeDuration -]); -instance.since(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "months", roundingIncrement: 2 })); -assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/end-of-month-out-of-range.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/end-of-month-out-of-range.js index 36117a5b45..935ee2efd4 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/end-of-month-out-of-range.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/end-of-month-out-of-range.js @@ -20,11 +20,3 @@ const duration = new Temporal.Duration(0, 0, 0, 1); // Calendar addition result is out of range assert.throws(RangeError, () => new Temporal.PlainYearMonth(275760, 9).subtract(duration), "Addition of 1 month to receiver out of range"); - -// Calendar addition succeeds, but subtracting 1 day gives out of range result -const cal = new class extends Temporal.Calendar { - dateAdd() { - return new Temporal.PlainDate(-271821, 4, 19); - } -}("iso8601"); -assert.throws(RangeError, () => new Temporal.PlainYearMonth(2000, 1, cal).subtract(duration), "Subtraction of 1 day from next month out of range"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/options-undefined.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/options-undefined.js index b0cf9bd9d4..0e17b53178 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/options-undefined.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/options-undefined.js @@ -8,27 +8,16 @@ features: [Temporal] ---*/ // overflow option has no effect on addition in the ISO calendar, so verify this -// with a custom calendar -class CheckedAdd extends Temporal.Calendar { - constructor() { - super("iso8601"); - this.called = 0; - } - dateAdd(date, duration, options, constructor) { - this.called += 1; - if (this.called == 2) - assert.notSameValue(options, undefined, "options not undefined"); - return super.dateAdd(date, duration, options, constructor); - } -} -const calendar = new CheckedAdd(); +// with a lunisolar calendar. Default overflow is "constrain" so this should not +// throw. -const yearmonth = new Temporal.PlainYearMonth(2000, 3, calendar); -const duration = { months: 1 }; +const yearmonth = Temporal.PlainYearMonth.from({ + year: 5779, + monthCode: "M05L", + calendar: "hebrew" +}); +const duration = { years: 1 }; yearmonth.subtract(duration, undefined); -assert.sameValue(calendar.called, 2, "dateAdd should have been called twice"); -calendar.called = 0; yearmonth.subtract(duration); -assert.sameValue(calendar.called, 2, "dateAdd should have been called twice"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/order-of-operations.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/order-of-operations.js index ea8caa0933..b376925ae6 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/order-of-operations.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/order-of-operations.js @@ -40,42 +40,7 @@ const expected = [ "get fields.years", "get fields.years.valueOf", "call fields.years.valueOf", - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateFromFields", - "get this.calendar.day", - "get this.calendar.fields", - "get this.calendar.yearMonthFromFields", - // CalendarFields - "call this.calendar.fields", - // PrepareTemporalFields on receiver - "get this.calendar.monthCode", - "call this.calendar.monthCode", - "get this.calendar.year", - "call this.calendar.year", - // calculate last day of month - "call this.calendar.dateFromFields", - "call this.calendar.dateAdd", - "call this.calendar.day", - "call this.calendar.dateFromFields", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", - // CalendarDateAdd - "call this.calendar.dateAdd", - // inside Calendar.p.dateAdd - "get options.overflow", - "get options.overflow.toString", - "call options.overflow.toString", - // PrepareTemporalFields on added date - "get this.calendar.monthCode", - "call this.calendar.monthCode", - "get this.calendar.year", - "call this.calendar.year", - // CalendarYearMonthFromFields - "call this.calendar.yearMonthFromFields", - // inside Calendar.p.yearMonthFromFields "get options.overflow.toString", "call options.overflow.toString", ]; @@ -102,83 +67,3 @@ instance.subtract(fields, options); assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -const noCalendarExpected = [ - // ToTemporalDuration - "get fields.days", - "get fields.days.valueOf", - "call fields.days.valueOf", - "get fields.hours", - "get fields.hours.valueOf", - "call fields.hours.valueOf", - "get fields.microseconds", - "get fields.microseconds.valueOf", - "call fields.microseconds.valueOf", - "get fields.milliseconds", - "get fields.milliseconds.valueOf", - "call fields.milliseconds.valueOf", - "get fields.minutes", - "get fields.minutes.valueOf", - "call fields.minutes.valueOf", - "get fields.months", - "get fields.nanoseconds", - "get fields.nanoseconds.valueOf", - "call fields.nanoseconds.valueOf", - "get fields.seconds", - "get fields.seconds.valueOf", - "call fields.seconds.valueOf", - "get fields.weeks", - "get fields.years", - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateFromFields", - "get this.calendar.day", - "get this.calendar.fields", - "get this.calendar.yearMonthFromFields", - // CalendarFields - "call this.calendar.fields", - // PrepareTemporalFields on receiver - "get this.calendar.monthCode", - "call this.calendar.monthCode", - "get this.calendar.year", - "call this.calendar.year", - // CalendarDateFromFields - "call this.calendar.dateFromFields", - // calculate last day of month - "call this.calendar.dateAdd", - "call this.calendar.day", - "call this.calendar.dateFromFields", - // SnapshotOwnProperties - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", - "get options.overflow", - // AddDate - "get options.overflow", - "get options.overflow.toString", - "call options.overflow.toString", - // PrepareTemporalFields on added date - "get this.calendar.monthCode", - "call this.calendar.monthCode", - "get this.calendar.year", - "call this.calendar.year", - // CalendarYearMonthFromFields - "call this.calendar.yearMonthFromFields", - // inside Calendar.p.yearMonthFromFields - "get options.overflow.toString", - "call options.overflow.toString", -]; - -const noCalendarFields = TemporalHelpers.propertyBagObserver(actual, { - days: 1, - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1, - nanoseconds: 1, -}, "fields"); - -instance.subtract(noCalendarFields, options); -assert.compareArray(actual, noCalendarExpected, "order of operations with no calendar units"); - -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/overflow-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/overflow-wrong-type.js index f683dfbd4c..1d0bfdc326 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/overflow-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/overflow-wrong-type.js @@ -33,13 +33,9 @@ assert.throws(RangeError, () => yearmonth.subtract(duration, { overflow: 2 }), " assert.throws(RangeError, () => yearmonth.subtract(duration, { overflow: 2n }), "bigint"); assert.throws(RangeError, () => yearmonth.subtract(duration, { overflow: {} }), "plain object"); -// toString property is read once by Calendar.dateAdd() and then once again by -// calendar.yearMonthFromFields(). const expected = [ "get overflow.toString", "call overflow.toString", - "get overflow.toString", - "call overflow.toString", ]; const actual = []; const observer = TemporalHelpers.toPrimitiveObserver(actual, "constrain", "overflow"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-always.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-always.js index 9aaf7f0d76..e9fb1a7a1f 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-always.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-always.js @@ -7,39 +7,6 @@ description: If calendarName is "always", the calendar ID should be included. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "2000-05-01[u-ca=iso8601]", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "2000-05-01[u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "2000-05-01[u-ca=iso8601]", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "2000-05-01[u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "2000-05-01[u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const yearmonth = new Temporal.PlainYearMonth(2000, 5, ...args); - const result = yearmonth.toString({ calendarName: "always" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = always`); -} +const yearmonth = new Temporal.PlainYearMonth(2000, 5); +const result = yearmonth.toString({ calendarName: "always" }); +assert.sameValue(result, "2000-05-01[u-ca=iso8601]", `built-in ISO calendar for calendarName = always`); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-auto.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-auto.js index c940f67815..a26310c764 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-auto.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-auto.js @@ -7,39 +7,6 @@ description: If calendarName is "auto", "iso8601" should be omitted. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "2000-05", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "2000-05-01[u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "2000-05", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "2000-05-01[u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "2000-05-01[u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const yearmonth = new Temporal.PlainYearMonth(2000, 5, ...args); - const result = yearmonth.toString({ calendarName: "auto" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = auto`); -} +const yearmonth = new Temporal.PlainYearMonth(2000, 5); +const result = yearmonth.toString({ calendarName: "auto" }); +assert.sameValue(result, "2000-05", `built-in ISO calendar for calendarName = auto`); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-critical.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-critical.js index cc4aeaea3a..864845d745 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-critical.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-critical.js @@ -9,39 +9,6 @@ description: > features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "2000-05-01[!u-ca=iso8601]", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "2000-05-01[!u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "2000-05-01[!u-ca=iso8601]", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "2000-05-01[!u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "2000-05-01[!u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const yearmonth = new Temporal.PlainYearMonth(2000, 5, ...args); - const result = yearmonth.toString({ calendarName: "critical" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = critical`); -} +const yearmonth = new Temporal.PlainYearMonth(2000, 5); +const result = yearmonth.toString({ calendarName: "critical" }); +assert.sameValue(result, "2000-05-01[!u-ca=iso8601]", `built-in ISO calendar for calendarName = critical`); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-never.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-never.js index 9bfe45ec12..57f8b5c0f5 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-never.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-never.js @@ -7,39 +7,6 @@ description: If calendarName is "never", the calendar ID should be omitted. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "2000-05", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "2000-05-01", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "2000-05", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "2000-05-01", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "2000-05-01", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const yearmonth = new Temporal.PlainYearMonth(2000, 5, ...args); - const result = yearmonth.toString({ calendarName: "never" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = never`); -} +const yearmonth = new Temporal.PlainYearMonth(2000, 5); +const result = yearmonth.toString({ calendarName: "never" }); +assert.sameValue(result, "2000-05", `built-in ISO calendar for calendarName = never`); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-undefined.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-undefined.js index a8d9717ead..33886ab4be 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-undefined.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-undefined.js @@ -14,40 +14,7 @@ info: | features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "2000-05", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "2000-05-01[u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "2000-05", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "2000-05-01[u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "2000-05-01[u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const yearmonth = new Temporal.PlainYearMonth(2000, 5, ...args); - const result = yearmonth.toString({ calendarName: undefined }); - assert.sameValue(result, expected, `default calendarName option is auto with ${description} calendar`); - // See options-object.js for {} and options-undefined.js for absent options arg -} +const yearmonth = new Temporal.PlainYearMonth(2000, 5); +const result = yearmonth.toString({ calendarName: undefined }); +assert.sameValue(result, "2000-05", `default calendarName option is auto with built-in ISO calendar`); +// See options-object.js for {} and options-undefined.js for absent options arg diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-wrong-type.js index df91dd657c..e72752f4fc 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-wrong-type.js @@ -15,32 +15,9 @@ includes: [compareArray.js, temporalHelpers.js] features: [Temporal] ---*/ -const calendar = { - id: "custom", - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -const yearmonth = new Temporal.PlainYearMonth(2000, 5, calendar); +const yearmonth = new Temporal.PlainYearMonth(2000, 5, "iso8601"); TemporalHelpers.checkStringOptionWrongType("calendarName", "auto", (calendarName) => yearmonth.toString({ calendarName }), - (result, descr) => assert.sameValue(result, "2000-05-01[u-ca=custom]", descr), + (result, descr) => assert.sameValue(result, "2000-05", descr), ); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/options-undefined.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/options-undefined.js index c84712f2e6..59ccdc737d 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/options-undefined.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/options-undefined.js @@ -7,35 +7,12 @@ description: Verify that undefined options are handled correctly. features: [Temporal] ---*/ -const calendar = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "custom", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; const yearmonth1 = new Temporal.PlainYearMonth(2000, 5); -const yearmonth2 = new Temporal.PlainYearMonth(2000, 5, calendar); +const yearmonth2 = new Temporal.PlainYearMonth(2000, 5, "gregory", 1); [ [yearmonth1, "2000-05"], - [yearmonth2, "2000-05-01[u-ca=custom]"], + [yearmonth2, "2000-05-01[u-ca=gregory]"], ].forEach(([yearmonth, expected]) => { const explicit = yearmonth.toString(undefined); assert.sameValue(explicit, expected, "default calendarName option is auto"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/order-of-operations.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/order-of-operations.js index dfcdb76f89..46d68db910 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/order-of-operations.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/order-of-operations.js @@ -12,7 +12,6 @@ const expected = [ "get options.calendarName", "get options.calendarName.toString", "call options.calendarName.toString", - "get this.calendar.id", ]; const actual = []; diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/mixed-calendar-invalid.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/mixed-calendar-invalid.js index 653542e781..3341fab43d 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/mixed-calendar-invalid.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/mixed-calendar-invalid.js @@ -7,17 +7,7 @@ description: Mixed calendars throw as invalid features: [Temporal] ---*/ -class customCal extends Temporal.Calendar { - constructor () { - super('iso8601'); - } - - get id() { - return "I am a secret cal."; - } -} - const ym1 = new Temporal.PlainYearMonth(2000, 1); -const ym2 = new Temporal.PlainYearMonth(2000, 1, new customCal()); +const ym2 = new Temporal.PlainYearMonth(2000, 1, "gregory"); assert.throws(RangeError, () => ym1.until(ym2), 'until throws with different calendars'); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/order-of-operations.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/order-of-operations.js index c7fa8d06df..fc2859e16a 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/order-of-operations.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/order-of-operations.js @@ -8,33 +8,9 @@ includes: [compareArray.js, temporalHelpers.js] features: [Temporal] ---*/ -const expectedMinimal = [ +const expected = [ // ToTemporalYearMonth "get other.calendar", - "has other.calendar.dateAdd", - "has other.calendar.dateFromFields", - "has other.calendar.dateUntil", - "has other.calendar.day", - "has other.calendar.dayOfWeek", - "has other.calendar.dayOfYear", - "has other.calendar.daysInMonth", - "has other.calendar.daysInWeek", - "has other.calendar.daysInYear", - "has other.calendar.fields", - "has other.calendar.id", - "has other.calendar.inLeapYear", - "has other.calendar.mergeFields", - "has other.calendar.month", - "has other.calendar.monthCode", - "has other.calendar.monthDayFromFields", - "has other.calendar.monthsInYear", - "has other.calendar.weekOfYear", - "has other.calendar.year", - "has other.calendar.yearMonthFromFields", - "has other.calendar.yearOfWeek", - "get other.calendar.fields", - "get other.calendar.yearMonthFromFields", - "call other.calendar.fields", "get other.month", "get other.month.valueOf", "call other.month.valueOf", @@ -44,56 +20,20 @@ const expectedMinimal = [ "get other.year", "get other.year.valueOf", "call other.year.valueOf", - "call other.calendar.yearMonthFromFields", - // CalendarEquals - "get this.calendar.id", - "get other.calendar.id", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.roundingIncrement", - "get options.roundingIncrement", - "getOwnPropertyDescriptor options.roundingMode", - "get options.roundingMode", - "getOwnPropertyDescriptor options.largestUnit", - "get options.largestUnit", - "getOwnPropertyDescriptor options.smallestUnit", - "get options.smallestUnit", - "getOwnPropertyDescriptor options.additional", - "get options.additional", // GetDifferenceSettings + "get options.largestUnit", "get options.largestUnit.toString", "call options.largestUnit.toString", + "get options.roundingIncrement", "get options.roundingIncrement.valueOf", "call options.roundingIncrement.valueOf", + "get options.roundingMode", "get options.roundingMode.toString", "call options.roundingMode.toString", + "get options.smallestUnit", "get options.smallestUnit.toString", "call options.smallestUnit.toString", ]; - -const expected = expectedMinimal.concat([ - // lookup - "get this.calendar.dateAdd", - "get this.calendar.dateFromFields", - "get this.calendar.dateUntil", - "get this.calendar.fields", - // CalendarFields - "call this.calendar.fields", - // PrepareTemporalFields / CalendarDateFromFields (receiver) - "get this.calendar.monthCode", - "call this.calendar.monthCode", - "get this.calendar.year", - "call this.calendar.year", - "call this.calendar.dateFromFields", - // PrepareTemporalFields / CalendarDateFromFields (argument) - "get other.calendar.monthCode", - "call other.calendar.monthCode", - "get other.calendar.year", - "call other.calendar.year", - "call this.calendar.dateFromFields", - // CalendarDateUntil - "call this.calendar.dateUntil", -]); const actual = []; const instance = new Temporal.PlainYearMonth(2000, 5, "iso8601", 1); @@ -107,8 +47,6 @@ const otherYearMonthPropertyBag = TemporalHelpers.propertyBagObserver(actual, { function createOptionsObserver({ smallestUnit = "months", largestUnit = "auto", roundingMode = "halfExpand", roundingIncrement = 1 } = {}) { return TemporalHelpers.propertyBagObserver(actual, { - // order is significant, due to iterating through properties in order to - // copy them to an internal null-prototype object: roundingIncrement, roundingMode, largestUnit, @@ -117,56 +55,5 @@ function createOptionsObserver({ smallestUnit = "months", largestUnit = "auto", }, "options"); } -// clear any observable things that happened while constructing the objects -actual.splice(0); - -// code path that skips RoundDuration: -instance.since(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "months", roundingIncrement: 1 })); -assert.compareArray(actual, expected, "order of operations with no rounding"); -actual.splice(0); // clear - -// short-circuit for identical objects: -const identicalPropertyBag = TemporalHelpers.propertyBagObserver(actual, { - year: 2000, - month: 5, - monthCode: "M05", - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), -}, "other"); - -instance.until(identicalPropertyBag, createOptionsObserver()); -assert.compareArray(actual, expectedMinimal, "order of operations with identical year-months"); -actual.splice(0); // clear - -// code path through RoundRelativeDuration that rounds to the nearest year: -const expectedOpsForYearRounding = expected.concat([ - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.until(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "years" })); -assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years"); -actual.splice(0); // clear - -// code path through RoundRelativeDuration that rounds to the nearest year and skips a DateUntil call -const otherYearMonthPropertyBagSameMonth = TemporalHelpers.propertyBagObserver(actual, { - year: 2001, - month: 5, - monthCode: "M05", - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), -}, "other"); -const expectedOpsForYearRoundingSameMonth = expected.concat([ - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", -]); -instance.until(otherYearMonthPropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" })); -assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months"); -actual.splice(0); // clear - -// code path through RoundRelativeDuration that rounds to the nearest month: -const expectedOpsForMonthRounding = expected.concat([ - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", // BubbleRelativeDuration -]); -instance.until(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "months", roundingIncrement: 2 })); -assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months"); -actual.splice(0); // clear +instance.until(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "months", roundingIncrement: 1 })); +assert.compareArray(actual, expected, "order of operations"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/with/order-of-operations.js b/test/built-ins/Temporal/PlainYearMonth/prototype/with/order-of-operations.js index 33a9914715..cc8c6b6e61 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/with/order-of-operations.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/with/order-of-operations.js @@ -13,24 +13,9 @@ const expected = [ "get fields.calendar", "get fields.timeZone", // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", "get options.overflow", - "getOwnPropertyDescriptor options.extra", - "get options.extra", - // lookup - "get this.calendar.fields", - "get this.calendar.mergeFields", - "get this.calendar.yearMonthFromFields", - // CalendarFields - "call this.calendar.fields", - // PrepareTemporalFields on receiver - "get this.calendar.month", - "call this.calendar.month", - "get this.calendar.monthCode", - "call this.calendar.monthCode", - "get this.calendar.year", - "call this.calendar.year", + "get options.overflow.toString", + "call options.overflow.toString", // PrepareTemporalFields on argument "get fields.month", "get fields.month.valueOf", @@ -41,13 +26,6 @@ const expected = [ "get fields.year", "get fields.year.valueOf", "call fields.year.valueOf", - // CalendarMergeFields - "call this.calendar.mergeFields", - // CalendarYearMonthFromFields - "call this.calendar.yearMonthFromFields", - // inside Calendar.p.yearMonthFromFields - "get options.overflow.toString", - "call options.overflow.toString", ]; const actual = []; diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/exhaustive.js b/test/built-ins/Temporal/ZonedDateTime/compare/exhaustive.js index 655868266c..7120b92a84 100644 --- a/test/built-ins/Temporal/ZonedDateTime/compare/exhaustive.js +++ b/test/built-ins/Temporal/ZonedDateTime/compare/exhaustive.js @@ -10,7 +10,7 @@ features: [Temporal] const tz1 = "UTC"; const tz2 = "-00:30"; const cal1 = "iso8601"; -const cal2 = new (class extends Temporal.Calendar { id = "custom"; })("iso8601"); +const cal2 = "gregory"; assert.sameValue( Temporal.ZonedDateTime.compare(new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, tz1, cal1), new Temporal.ZonedDateTime(500_000_000_000_000_000n, tz2, cal2)), diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/compare/order-of-operations.js index fc19a1055c..f7a0b7f3be 100644 --- a/test/built-ins/Temporal/ZonedDateTime/compare/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/compare/order-of-operations.js @@ -10,30 +10,6 @@ features: [Temporal] const expected = [ "get one.calendar", - "has one.calendar.dateAdd", - "has one.calendar.dateFromFields", - "has one.calendar.dateUntil", - "has one.calendar.day", - "has one.calendar.dayOfWeek", - "has one.calendar.dayOfYear", - "has one.calendar.daysInMonth", - "has one.calendar.daysInWeek", - "has one.calendar.daysInYear", - "has one.calendar.fields", - "has one.calendar.id", - "has one.calendar.inLeapYear", - "has one.calendar.mergeFields", - "has one.calendar.month", - "has one.calendar.monthCode", - "has one.calendar.monthDayFromFields", - "has one.calendar.monthsInYear", - "has one.calendar.weekOfYear", - "has one.calendar.year", - "has one.calendar.yearMonthFromFields", - "has one.calendar.yearOfWeek", - "get one.calendar.dateFromFields", - "get one.calendar.fields", - "call one.calendar.fields", // PrepareTemporalFields "get one.day", "get one.day.valueOf", @@ -69,42 +45,8 @@ const expected = [ "get one.year", "get one.year.valueOf", "call one.year.valueOf", - "has one.timeZone.getOffsetNanosecondsFor", - "has one.timeZone.getPossibleInstantsFor", - "has one.timeZone.id", - // InterpretTemporalDateTimeFields - "call one.calendar.dateFromFields", - // InterpretISODateTimeOffset - "get one.timeZone.getOffsetNanosecondsFor", - "get one.timeZone.getPossibleInstantsFor", - "call one.timeZone.getPossibleInstantsFor", - "call one.timeZone.getOffsetNanosecondsFor", // Same set of operations, for the other argument: "get two.calendar", - "has two.calendar.dateAdd", - "has two.calendar.dateFromFields", - "has two.calendar.dateUntil", - "has two.calendar.day", - "has two.calendar.dayOfWeek", - "has two.calendar.dayOfYear", - "has two.calendar.daysInMonth", - "has two.calendar.daysInWeek", - "has two.calendar.daysInYear", - "has two.calendar.fields", - "has two.calendar.id", - "has two.calendar.inLeapYear", - "has two.calendar.mergeFields", - "has two.calendar.month", - "has two.calendar.monthCode", - "has two.calendar.monthDayFromFields", - "has two.calendar.monthsInYear", - "has two.calendar.weekOfYear", - "has two.calendar.year", - "has two.calendar.yearMonthFromFields", - "has two.calendar.yearOfWeek", - "get two.calendar.dateFromFields", - "get two.calendar.fields", - "call two.calendar.fields", // PrepareTemporalFields "get two.day", "get two.day.valueOf", @@ -140,16 +82,6 @@ const expected = [ "get two.year", "get two.year.valueOf", "call two.year.valueOf", - "has two.timeZone.getOffsetNanosecondsFor", - "has two.timeZone.getPossibleInstantsFor", - "has two.timeZone.id", - // InterpretTemporalDateTimeFields - "call two.calendar.dateFromFields", - // InterpretISODateTimeOffset - "get two.timeZone.getOffsetNanosecondsFor", - "get two.timeZone.getPossibleInstantsFor", - "call two.timeZone.getPossibleInstantsFor", - "call two.timeZone.getOffsetNanosecondsFor", ]; const actual = []; diff --git a/test/built-ins/Temporal/ZonedDateTime/from/balance-negative-time-units.js b/test/built-ins/Temporal/ZonedDateTime/from/balance-negative-time-units.js deleted file mode 100644 index 80eb5903e6..0000000000 --- a/test/built-ins/Temporal/ZonedDateTime/from/balance-negative-time-units.js +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.zoneddatetime.from -description: Negative time fields are balanced upwards -info: | - sec-temporal-balancetime steps 3–14: - 3. Set _microsecond_ to _microsecond_ + floor(_nanosecond_ / 1000). - 4. Set _nanosecond_ to _nanosecond_ modulo 1000. - 5. Set _millisecond_ to _millisecond_ + floor(_microsecond_ / 1000). - 6. Set _microsecond_ to _microsecond_ modulo 1000. - 7. Set _second_ to _second_ + floor(_millisecond_ / 1000). - 8. Set _millisecond_ to _millisecond_ modulo 1000. - 9. Set _minute_ to _minute_ + floor(_second_ / 60). - 10. Set _second_ to _second_ modulo 60. - 11. Set _hour_ to _hour_ + floor(_minute_ / 60). - 12. Set _minute_ to _minute_ modulo 60. - 13. Let _days_ be floor(_hour_ / 24). - 14. Set _hour_ to _hour_ modulo 24. - sec-temporal-addtime step 8: - 8. Return ? BalanceTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_). - sec-temporal-adddatetime step 1: - 1. Let _timeResult_ be ? AddTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_). - sec-temporal-builtintimezonegetinstantfor step 13.a: - a. Let _earlier_ be ? AddDateTime(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], 0, 0, 0, 0, 0, 0, 0, 0, 0, −_nanoseconds_, *"constrain"*). - sec-temporal-interpretisodatetimeoffset steps 4–10: - 4. If _offsetNanoseconds_ is *null*, or _offset_ is *"ignore"*, then - a. Let _instant_ be ? BuiltinTimeZoneGetInstantFor(_timeZone_, _dateTime_, _disambiguation_). - ... - ... - 6. Assert: _offset_ is *"prefer"* or *"reject"*. - 7. Let _possibleInstants_ be ? GetPossibleInstantsFor(_timeZone_, _dateTime_). - ... - 9. If _offset_ is *"reject"*, throw a *RangeError* exception. - 10. Let _instant_ be ? DisambiguatePossibleInstants(_possibleInstants_, _timeZone_, _dateTime_, _disambiguation_). - sec-temporal-totemporalzoneddatetime step 7: - 7. Let _epochNanoseconds_ be ? InterpretISODateTimeOffset(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]], _offsetNanoseconds_, _timeZone_, _disambiguation_, _offset_). - sec-temporal.zoneddatetime.from step 3: - 3. Return ? ToTemporalZonedDateTime(_item_, _options_). -includes: [compareArray.js, temporalHelpers.js] -features: [Temporal] ----*/ - -const shiftInstant = new Temporal.Instant(3661_001_001_001n); -const tz1 = TemporalHelpers.oneShiftTimeZone(shiftInstant, 2); - -// This code path is encountered if offset is `ignore` or `prefer`, -// disambiguation is `earlier` and the shift is a spring-forward change -Temporal.ZonedDateTime.from({ - year: 1970, - month: 1, - day: 1, - hour: 1, - minute: 1, - second: 1, - millisecond: 1, - microsecond: 1, - nanosecond: 1, - timeZone: tz1, -}, { offset: "ignore", disambiguation: "earlier" }); - -const expected1 = [ - "1970-01-01T01:01:01.001001001", - "1970-01-01T01:01:01.001000999", -]; -assert.compareArray(tz1.getPossibleInstantsForCalledWith, expected1); - -const tz2 = TemporalHelpers.oneShiftTimeZone(shiftInstant, 2); - -Temporal.ZonedDateTime.from({ - year: 1970, - month: 1, - day: 1, - hour: 1, - minute: 1, - second: 1, - millisecond: 1, - microsecond: 1, - nanosecond: 1, - timeZone: tz2, -}, { offset: "prefer", disambiguation: "earlier" }); - -const expected2 = [ - "1970-01-01T01:01:01.001001001", - "1970-01-01T01:01:01.001000999", -]; -assert.compareArray(tz2.getPossibleInstantsForCalledWith, expected2); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/observable-get-overflow-argument-primitive.js b/test/built-ins/Temporal/ZonedDateTime/from/observable-get-overflow-argument-primitive.js index 6d3724cfab..bbce75342f 100644 --- a/test/built-ins/Temporal/ZonedDateTime/from/observable-get-overflow-argument-primitive.js +++ b/test/built-ins/Temporal/ZonedDateTime/from/observable-get-overflow-argument-primitive.js @@ -9,17 +9,13 @@ features: [Temporal] ---*/ const expected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.disambiguation", "get options.disambiguation", - "getOwnPropertyDescriptor options.offset", - "get options.offset", - "getOwnPropertyDescriptor options.overflow", - "get options.overflow", "get options.disambiguation.toString", "call options.disambiguation.toString", + "get options.offset", "get options.offset.toString", "call options.offset.toString", + "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", ]; @@ -36,14 +32,6 @@ assert.compareArray(actual, expected, "Successful call"); assert.sameValue(result.epochNanoseconds, 1_000_000_000_000_000_000n); actual.splice(0); // empty it for the next check -const failureExpected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.disambiguation", - "get options.disambiguation", - "getOwnPropertyDescriptor options.offset", - "get options.offset", - "getOwnPropertyDescriptor options.overflow", - "get options.overflow", -]; + assert.throws(TypeError, () => Temporal.ZonedDateTime.from(7, options)); -assert.compareArray(actual, failureExpected, "Failing call"); +assert.compareArray(actual, expected, "Failing call"); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/observable-get-overflow-argument-string-invalid.js b/test/built-ins/Temporal/ZonedDateTime/from/observable-get-overflow-argument-string-invalid.js index c7ab1200a3..2b395b1890 100644 --- a/test/built-ins/Temporal/ZonedDateTime/from/observable-get-overflow-argument-string-invalid.js +++ b/test/built-ins/Temporal/ZonedDateTime/from/observable-get-overflow-argument-string-invalid.js @@ -9,13 +9,15 @@ features: [Temporal] ---*/ const expected = [ - "ownKeys options", - "getOwnPropertyDescriptor options.disambiguation", "get options.disambiguation", - "getOwnPropertyDescriptor options.offset", + "get options.disambiguation.toString", + "call options.disambiguation.toString", "get options.offset", - "getOwnPropertyDescriptor options.overflow", + "get options.offset.toString", + "call options.offset.toString", "get options.overflow", + "get options.overflow.toString", + "call options.overflow.toString", ]; let actual = []; diff --git a/test/built-ins/Temporal/ZonedDateTime/from/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/from/order-of-operations.js index e82e491dba..ae18e7d83c 100644 --- a/test/built-ins/Temporal/ZonedDateTime/from/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/from/order-of-operations.js @@ -9,42 +9,20 @@ features: [Temporal] ---*/ const expected = [ - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", - "get options.overflow", - "getOwnPropertyDescriptor options.disambiguation", + // GetTemporalDisambiguationOption "get options.disambiguation", - "getOwnPropertyDescriptor options.offset", + "get options.disambiguation.toString", + "call options.disambiguation.toString", + // GetTemporalOffsetOption "get options.offset", - "getOwnPropertyDescriptor options.extra", - "get options.extra", + "get options.offset.toString", + "call options.offset.toString", + // GetTemporalOverflowOption + "get options.overflow", + "get options.overflow.toString", + "call options.overflow.toString", // ToTemporalCalendar "get item.calendar", - "has item.calendar.dateAdd", - "has item.calendar.dateFromFields", - "has item.calendar.dateUntil", - "has item.calendar.day", - "has item.calendar.dayOfWeek", - "has item.calendar.dayOfYear", - "has item.calendar.daysInMonth", - "has item.calendar.daysInWeek", - "has item.calendar.daysInYear", - "has item.calendar.fields", - "has item.calendar.id", - "has item.calendar.inLeapYear", - "has item.calendar.mergeFields", - "has item.calendar.month", - "has item.calendar.monthCode", - "has item.calendar.monthDayFromFields", - "has item.calendar.monthsInYear", - "has item.calendar.weekOfYear", - "has item.calendar.year", - "has item.calendar.yearMonthFromFields", - "has item.calendar.yearOfWeek", - "get item.calendar.dateFromFields", - "get item.calendar.fields", - "call item.calendar.fields", // PrepareTemporalFields "get item.day", "get item.day.valueOf", @@ -80,23 +58,6 @@ const expected = [ "get item.year", "get item.year.valueOf", "call item.year.valueOf", - "has item.timeZone.getOffsetNanosecondsFor", - "has item.timeZone.getPossibleInstantsFor", - "has item.timeZone.id", - // InterpretTemporalDateTimeFields - "get options.disambiguation.toString", - "call options.disambiguation.toString", - "get options.offset.toString", - "call options.offset.toString", - "get options.overflow.toString", - "call options.overflow.toString", - "call item.calendar.dateFromFields", - // lookup in ToTemporalZonedDateTime - "get item.timeZone.getOffsetNanosecondsFor", - "get item.timeZone.getPossibleInstantsFor", - // InterpretISODateTimeOffset - "call item.timeZone.getPossibleInstantsFor", - "call item.timeZone.getOffsetNanosecondsFor", ]; const actual = []; diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/add/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/prototype/add/order-of-operations.js index e8fa4d55f2..b58ab68826 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/add/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/add/order-of-operations.js @@ -40,19 +40,10 @@ const expected = [ "get duration.years", "get duration.years.valueOf", "call duration.years.valueOf", - // lookup - "get this.timeZone.getOffsetNanosecondsFor", - "get this.timeZone.getPossibleInstantsFor", - "get this.calendar.dateAdd", - // AddZonedDateTime - "call this.timeZone.getOffsetNanosecondsFor", - "call this.calendar.dateAdd", - // ... inside Calendar.p.dateAdd + // GetTemporalOverflowOption "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", - // AddZonedDateTime again - "call this.timeZone.getPossibleInstantsFor", ]; const actual = []; diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-object.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-object.js index 0342912721..27fe0e8c8f 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-object.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-object.js @@ -9,97 +9,15 @@ features: [Temporal] const instance = new Temporal.ZonedDateTime(0n, "UTC"); -class CustomTimeZone extends Temporal.TimeZone { - constructor(id) { - super("UTC"); - this._id = id; - } - get id() { - return this._id; - } -} - -const objectsEqualUTC = [ - new Temporal.TimeZone("UTC"), - new CustomTimeZone("UTC"), - { id: "UTC", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }, - new Temporal.ZonedDateTime(0n, "UTC") -]; - -const tzUTC = new Temporal.TimeZone("UTC"); - -for (const object of objectsEqualUTC) { - const result = instance.withTimeZone(tzUTC).equals(instance.withTimeZone(object)); - assert.sameValue(result, true, `Receiver ${tzUTC.id} should equal argument ${object.id}`); -} - -const objectsEqual0000 = [ - new Temporal.TimeZone("+00:00"), - new Temporal.TimeZone("+0000"), - new Temporal.TimeZone("+00"), - new CustomTimeZone("+00:00"), - new CustomTimeZone("+0000"), - new CustomTimeZone("+00"), - { id: "+00:00", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }, - { id: "+0000", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }, - { id: "+00", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }, - new Temporal.ZonedDateTime(0n, "+00:00"), - new Temporal.ZonedDateTime(0n, "+0000"), - new Temporal.ZonedDateTime(0n, "+00"), +const idsEqual0000 = [ "+00:00", "+0000", "+00" ]; -const tz0000ToTest = [ - new Temporal.TimeZone("+00:00"), - new Temporal.TimeZone("+0000"), - new Temporal.TimeZone("+00"), - new CustomTimeZone("+00:00"), - new CustomTimeZone("+0000"), - new CustomTimeZone("+00") -]; - -for (const arg of objectsEqual0000) { - for (const receiver of tz0000ToTest) { +for (const arg of idsEqual0000) { + for (const receiver of idsEqual0000) { const result = instance.withTimeZone(receiver).equals(instance.withTimeZone(arg)); - assert.sameValue(result, true, `Receiver ${receiver.id} should equal argument ${arg.id ?? arg}`); + assert.sameValue(result, true, `Receiver ${receiver} should equal argument ${arg}`); } } - -const objectsNotEqual = [ - new Temporal.TimeZone("+00:00"), - new CustomTimeZone("+00:00"), - new CustomTimeZone("Etc/Custom"), - { id: "+00:00", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }, - { id: "Etc/Custom", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }, - new Temporal.ZonedDateTime(0n, "+00:00"), - "UTC" -]; - -const customObjectsToTest = [tzUTC, new CustomTimeZone("YouTeeSee"), new CustomTimeZone("+01:00")]; - -for (const arg of objectsNotEqual) { - for (const receiver of customObjectsToTest) { - if (arg === "UTC" && receiver === tzUTC) continue; - const result = instance.withTimeZone(receiver).equals(instance.withTimeZone(arg)); - assert.sameValue(result, false, `Receiver ${receiver.id} should not equal argument ${arg.id ?? arg}`); - } -} - -// Custom object IDs are compared case-sensitively -const classInstanceCustomId = new CustomTimeZone("Moon/Cheese"); -const classInstanceSameCaseCustomId = new CustomTimeZone("Moon/Cheese"); -const classInstanceDifferentCaseCustomId = new CustomTimeZone("MoOn/CHEESe"); - -const plainObjectSameCaseCustomId = { id: "Moon/Cheese", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }; -const plainObjectDifferentCaseCustomId = { - id: "MoOn/CHEESe", - getPossibleInstantsFor: null, - getOffsetNanosecondsFor: null -}; - -assert.sameValue(instance.withTimeZone(classInstanceCustomId).equals(instance.withTimeZone(classInstanceSameCaseCustomId)), true); -assert.sameValue(instance.withTimeZone(classInstanceCustomId).equals(instance.withTimeZone(classInstanceDifferentCaseCustomId)), false); -assert.sameValue(instance.withTimeZone(classInstanceCustomId).equals(instance.withTimeZone(plainObjectSameCaseCustomId)), true); -assert.sameValue(instance.withTimeZone(classInstanceCustomId).equals(instance.withTimeZone(plainObjectDifferentCaseCustomId)), false); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-normalize-offset-strings.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-normalize-offset-strings.js index 5785d96a02..b66dc8e873 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-normalize-offset-strings.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-normalize-offset-strings.js @@ -16,25 +16,9 @@ for (const test of tests) { const {idToTest, description} = test; const instance = new Temporal.ZonedDateTime(0n, "+00:00"); - const bag1 = { year: 1970, monthCode: "M01", day: 1, timeZone: idToTest }; - assert.sameValue(instance.equals(bag1), true, `Offset time zones are equal despite ${description} syntax in property bag argument`); + const bag = { year: 1970, monthCode: "M01", day: 1, timeZone: idToTest }; + assert.sameValue(instance.equals(bag), true, `Offset time zones are equal despite ${description} syntax in property bag argument`); const str = "1970-01-01[+00:00]"; assert.sameValue(instance.equals(str), true, `Offset time zones are equal despite ${description} syntax in ISO string argument`); - - const getPossibleInstantsFor = (pdt) => [Temporal.Instant.from(`${pdt.toString()}Z`)] - const plainObj = { id: idToTest, getPossibleInstantsFor, getOffsetNanosecondsFor: () => 0 }; - const bag2 = { year: 1970, monthCode: "M01", day: 1, timeZone: plainObj }; - assert.sameValue(instance.equals(bag2), true, `Offset time zones are equal despite ${description} syntax in plain object time zone ID`); - - class CustomTimeZone extends Temporal.TimeZone { - constructor() { - super(idToTest); - } - get id() { return idToTest; } - } - const customTimeZoneInstance = new CustomTimeZone(); - assert.sameValue(customTimeZoneInstance.id, idToTest); - const bag3 = { year: 1970, monthCode: "M01", day: 1, timeZone: customTimeZoneInstance }; - assert.sameValue(instance.equals(bag3), true, `Offset time zones are equal despite ${description} syntax in custom object time zone ID`); } diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-string-datetime.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-string-datetime.js index e39e593354..516c2bbbd4 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-string-datetime.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-string-datetime.js @@ -13,6 +13,35 @@ const instance1 = new Temporal.ZonedDateTime(0n, expectedTimeZone); let timeZone = "2021-02-19T17:30"; assert.throws(RangeError, () => instance1.equals({ year: 1970, month: 1, day: 1, timeZone }), "bare date-time string is not a time zone"); +[ + "2021-08-19T17:30-07:00:01", + "2021-08-19T17:30-07:00:00", + "2021-08-19T17:30-07:00:00.1", + "2021-08-19T17:30-07:00:00.0", + "2021-08-19T17:30-07:00:00.01", + "2021-08-19T17:30-07:00:00.00", + "2021-08-19T17:30-07:00:00.001", + "2021-08-19T17:30-07:00:00.000", + "2021-08-19T17:30-07:00:00.0001", + "2021-08-19T17:30-07:00:00.0000", + "2021-08-19T17:30-07:00:00.00001", + "2021-08-19T17:30-07:00:00.00000", + "2021-08-19T17:30-07:00:00.000001", + "2021-08-19T17:30-07:00:00.000000", + "2021-08-19T17:30-07:00:00.0000001", + "2021-08-19T17:30-07:00:00.0000000", + "2021-08-19T17:30-07:00:00.00000001", + "2021-08-19T17:30-07:00:00.00000000", + "2021-08-19T17:30-07:00:00.000000001", + "2021-08-19T17:30-07:00:00.000000000", +].forEach((timeZone) => { + assert.throws( + RangeError, + () => instance1.equals({ year: 2020, month: 5, day: 2, timeZone }), + `ISO string ${timeZone} with a sub-minute offset is not a valid time zone` + ); +}); + // The following are all valid strings so should not throw. They should produce // expectedTimeZone, so additionally the operation should return true, because // the property bag will produce an instance that's equal to the receiver. diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/order-of-operations.js index c6d65698cf..b1497c8e51 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/order-of-operations.js @@ -10,30 +10,6 @@ features: [Temporal] const expected = [ "get other.calendar", - "has other.calendar.dateAdd", - "has other.calendar.dateFromFields", - "has other.calendar.dateUntil", - "has other.calendar.day", - "has other.calendar.dayOfWeek", - "has other.calendar.dayOfYear", - "has other.calendar.daysInMonth", - "has other.calendar.daysInWeek", - "has other.calendar.daysInYear", - "has other.calendar.fields", - "has other.calendar.id", - "has other.calendar.inLeapYear", - "has other.calendar.mergeFields", - "has other.calendar.month", - "has other.calendar.monthCode", - "has other.calendar.monthDayFromFields", - "has other.calendar.monthsInYear", - "has other.calendar.weekOfYear", - "has other.calendar.year", - "has other.calendar.yearMonthFromFields", - "has other.calendar.yearOfWeek", - "get other.calendar.dateFromFields", - "get other.calendar.fields", - "call other.calendar.fields", // PrepareTemporalFields "get other.day", "get other.day.valueOf", @@ -69,23 +45,6 @@ const expected = [ "get other.year", "get other.year.valueOf", "call other.year.valueOf", - "has other.timeZone.getOffsetNanosecondsFor", - "has other.timeZone.getPossibleInstantsFor", - "has other.timeZone.id", - // InterpretTemporalDateTimeFields - "call other.calendar.dateFromFields", - // lookup in ToTemporalZonedDateTime - "get other.timeZone.getOffsetNanosecondsFor", - "get other.timeZone.getPossibleInstantsFor", - // InterpretISODateTimeOffset - "call other.timeZone.getPossibleInstantsFor", - "call other.timeZone.getOffsetNanosecondsFor", - // TimeZoneEquals - "get this.timeZone.id", - "get other.timeZone.id", - // CalendarEquals - "get this.calendar.id", - "get other.calendar.id", ]; const actual = []; diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/round/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/prototype/round/order-of-operations.js index 9f6ddf1295..679327d750 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/round/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/round/order-of-operations.js @@ -18,14 +18,6 @@ const expected = [ "get options.smallestUnit", "get options.smallestUnit.toString", "call options.smallestUnit.toString", - // lookup - "get this.timeZone.getOffsetNanosecondsFor", - "get this.timeZone.getPossibleInstantsFor", - // GetPlainDateTimeFor on receiver's instant - "call this.timeZone.getOffsetNanosecondsFor", - // InterpretISODateTimeOffset - "call this.timeZone.getPossibleInstantsFor", - "call this.timeZone.getOffsetNanosecondsFor", ]; const actual = []; @@ -41,75 +33,8 @@ const nextHourOptions = TemporalHelpers.propertyBagObserver(actual, { roundingIncrement: 1, }, "options"); -const calendar = TemporalHelpers.calendarObserver(actual, "this.calendar"); -const instance = new Temporal.ZonedDateTime( - 988786472_987_654_321n, /* 2001-05-02T06:54:32.987654321Z */ - TemporalHelpers.timeZoneObserver(actual, "this.timeZone"), - calendar, -); - -const fallBackTimeZone = TemporalHelpers.oneShiftTimeZone(Temporal.Instant.fromEpochMilliseconds(1800_000), -3600_000_000_000); -const fallBackTimeZoneObserver = TemporalHelpers.timeZoneObserver(actual, "this.timeZone", { - getOffsetNanosecondsFor: fallBackTimeZone.getOffsetNanosecondsFor.bind(fallBackTimeZone), - getPossibleInstantsFor: fallBackTimeZone.getPossibleInstantsFor.bind(fallBackTimeZone), -}); -const fallBackInstance = new Temporal.ZonedDateTime(0n, fallBackTimeZoneObserver, calendar); -const beforeFallBackInstance = new Temporal.ZonedDateTime(-3599_000_000_000n, fallBackTimeZoneObserver, calendar); - -const springForwardTimeZone = TemporalHelpers.oneShiftTimeZone(Temporal.Instant.fromEpochMilliseconds(-1800_000), 3600_000_000_000); -const springForwardTimeZoneObserver = TemporalHelpers.timeZoneObserver(actual, "this.timeZone", { - getOffsetNanosecondsFor: springForwardTimeZone.getOffsetNanosecondsFor.bind(springForwardTimeZone), - getPossibleInstantsFor: springForwardTimeZone.getPossibleInstantsFor.bind(springForwardTimeZone), -}); -const springForwardInstance = new Temporal.ZonedDateTime(0n, springForwardTimeZoneObserver, calendar); -const beforeSpringForwardInstance = new Temporal.ZonedDateTime(-3599_000_000_000n, springForwardTimeZoneObserver, calendar); -// clear any observable operations that happen due to time zone or calendar -// calls in the constructors -actual.splice(0); +const instance = new Temporal.ZonedDateTime(988786472_987_654_321n, /* 2001-05-02T06:54:32.987654321Z */ "UTC"); instance.round(options); assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -fallBackInstance.round(options); -assert.compareArray(actual, expected, "order of operations with preceding midnight at repeated wall-clock time"); -actual.splice(0); // clear - -beforeFallBackInstance.round(nextHourOptions); -assert.compareArray(actual, expected, "order of operations with rounding result at repeated wall-clock time"); -actual.splice(0); // clear - -springForwardInstance.round(options); -assert.compareArray(actual, expected, "order of operations with preceding midnight at skipped wall-clock time"); -actual.splice(0); // clear - -const expectedSkippedResult = [ - "get options.roundingIncrement", - "get options.roundingIncrement.valueOf", - "call options.roundingIncrement.valueOf", - "get options.roundingMode", - "get options.roundingMode.toString", - "call options.roundingMode.toString", - "get options.smallestUnit", - "get options.smallestUnit.toString", - "call options.smallestUnit.toString", - // lookup - "get this.timeZone.getOffsetNanosecondsFor", - "get this.timeZone.getPossibleInstantsFor", - // GetPlainDateTimeFor on receiver's instant - "call this.timeZone.getOffsetNanosecondsFor", - // InterpretISODateTimeOffset - "call this.timeZone.getPossibleInstantsFor", - // DisambiguatePossibleInstants - "call this.timeZone.getOffsetNanosecondsFor", - "call this.timeZone.getOffsetNanosecondsFor", - "call this.timeZone.getPossibleInstantsFor", -]; - -beforeSpringForwardInstance.round(nextHourOptions); -assert.compareArray( - actual, - expectedSkippedResult, - "order of operations with following midnight and rounding result at skipped wall-clock time" -); -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-timezone-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-timezone-string.js index bc33b46d39..468686541c 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-timezone-string.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-timezone-string.js @@ -4,32 +4,11 @@ /*--- esid: sec-temporal.zoneddatetime.prototype.since description: Time zone IDs are valid input for a time zone -includes: [temporalHelpers.js] features: [Temporal] ---*/ -const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor"); -Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", { - configurable: true, - enumerable: false, - get() { - TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up"); - }, -}); -const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor"); -Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", { - configurable: true, - enumerable: false, - get() { - TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up"); - }, -}); - -const instance1 = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("UTC")); +const instance1 = new Temporal.ZonedDateTime(0n, "UTC"); assert(instance1.since({ year: 1970, month: 1, day: 1, timeZone: "UTC" }).blank, "Time zone created from string 'UTC'"); -const instance2 = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("-01:30")); +const instance2 = new Temporal.ZonedDateTime(0n, "-01:30"); assert(instance2.since({ year: 1969, month: 12, day: 31, hour: 22, minute: 30, timeZone: "-01:30" }).blank, "Time zone created from string '-01:30'"); - -Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal); -Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/order-of-operations.js index a4c47635e7..9c83ff6f07 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/order-of-operations.js @@ -11,30 +11,6 @@ features: [Temporal] const expected = [ // ToTemporalZonedDateTime "get other.calendar", - "has other.calendar.dateAdd", - "has other.calendar.dateFromFields", - "has other.calendar.dateUntil", - "has other.calendar.day", - "has other.calendar.dayOfWeek", - "has other.calendar.dayOfYear", - "has other.calendar.daysInMonth", - "has other.calendar.daysInWeek", - "has other.calendar.daysInYear", - "has other.calendar.fields", - "has other.calendar.id", - "has other.calendar.inLeapYear", - "has other.calendar.mergeFields", - "has other.calendar.month", - "has other.calendar.monthCode", - "has other.calendar.monthDayFromFields", - "has other.calendar.monthsInYear", - "has other.calendar.weekOfYear", - "has other.calendar.year", - "has other.calendar.yearMonthFromFields", - "has other.calendar.yearOfWeek", - "get other.calendar.dateFromFields", - "get other.calendar.fields", - "call other.calendar.fields", "get other.day", "get other.day.valueOf", "call other.day.valueOf", @@ -69,54 +45,23 @@ const expected = [ "get other.year", "get other.year.valueOf", "call other.year.valueOf", - "has other.timeZone.getOffsetNanosecondsFor", - "has other.timeZone.getPossibleInstantsFor", - "has other.timeZone.id", - "call other.calendar.dateFromFields", - "get other.timeZone.getOffsetNanosecondsFor", - "get other.timeZone.getPossibleInstantsFor", - "call other.timeZone.getPossibleInstantsFor", - "call other.timeZone.getOffsetNanosecondsFor", - // CalendarEquals - "get this.calendar.id", - "get other.calendar.id", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.roundingIncrement", - "get options.roundingIncrement", - "getOwnPropertyDescriptor options.roundingMode", - "get options.roundingMode", - "getOwnPropertyDescriptor options.largestUnit", - "get options.largestUnit", - "getOwnPropertyDescriptor options.smallestUnit", - "get options.smallestUnit", - "getOwnPropertyDescriptor options.additional", - "get options.additional", // GetDifferenceSettings + "get options.largestUnit", "get options.largestUnit.toString", "call options.largestUnit.toString", + "get options.roundingIncrement", "get options.roundingIncrement.valueOf", "call options.roundingIncrement.valueOf", + "get options.roundingMode", "get options.roundingMode.toString", "call options.roundingMode.toString", + "get options.smallestUnit", "get options.smallestUnit.toString", "call options.smallestUnit.toString", ]; const actual = []; -const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, ownTimeZone, ownCalendar); - -const dstTimeZone = TemporalHelpers.springForwardFallBackTimeZone(); -const ownDstTimeZone = TemporalHelpers.timeZoneObserver(actual, "this.timeZone", { - getOffsetNanosecondsFor: dstTimeZone.getOffsetNanosecondsFor, - getPossibleInstantsFor: dstTimeZone.getPossibleInstantsFor, -}); -const otherDstTimeZone = TemporalHelpers.timeZoneObserver(actual, "other.timeZone", { - getOffsetNanosecondsFor: dstTimeZone.getOffsetNanosecondsFor, - getPossibleInstantsFor: dstTimeZone.getPossibleInstantsFor, -}); -/* 2000-10-29T01:30-07:00, in the middle of the first repeated hour: */ -const fallBackInstance = new Temporal.ZonedDateTime(972808200_000_000_000n, ownDstTimeZone, ownCalendar); +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601"); const otherDateTimePropertyBag = TemporalHelpers.propertyBagObserver(actual, { year: 2004, @@ -136,8 +81,6 @@ const otherDateTimePropertyBag = TemporalHelpers.propertyBagObserver(actual, { function createOptionsObserver({ smallestUnit = "nanoseconds", largestUnit = "auto", roundingMode = "halfExpand", roundingIncrement = 1 } = {}) { return TemporalHelpers.propertyBagObserver(actual, { - // order is significant, due to iterating through properties in order to - // copy them to an internal null-prototype object: roundingIncrement, roundingMode, largestUnit, @@ -146,220 +89,7 @@ function createOptionsObserver({ smallestUnit = "nanoseconds", largestUnit = "au }, "options"); } -// clear any observable things that happened while constructing the objects -actual.splice(0); - // basic order of observable operations, without rounding: instance.since(otherDateTimePropertyBag, createOptionsObserver()); assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -// short-circuit for identical objects will still test TimeZoneEquals if -// largestUnit is a calendar unit: -const identicalPropertyBag = TemporalHelpers.propertyBagObserver(actual, { - year: 2001, - month: 9, - monthCode: "M09", - day: 9, - hour: 1, - minute: 46, - second: 40, - millisecond: 0, - microsecond: 0, - nanosecond: 0, - offset: "+00:00", - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), - timeZone: TemporalHelpers.timeZoneObserver(actual, "other.timeZone"), -}, "other"); - -instance.since(identicalPropertyBag, createOptionsObserver({ largestUnit: "years" })); -assert.compareArray(actual, expected.concat([ - "get this.timeZone.id", - "get other.timeZone.id", -]), "order of operations with identical dates and largestUnit a calendar unit"); -actual.splice(0); // clear - -// two ZonedDateTimes that denote the same wall-clock time in the time zone can -// avoid calling some calendar methods: -const fallBackPropertyBag = TemporalHelpers.propertyBagObserver(actual, { - year: 2000, - month: 10, - monthCode: "M10", - day: 29, - hour: 1, - minute: 30, - second: 0, - millisecond: 0, - microsecond: 0, - nanosecond: 0, - offset: "-08:00", - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), - timeZone: otherDstTimeZone, -}, "other"); -fallBackInstance.since(fallBackPropertyBag, createOptionsObserver({ largestUnit: "days" })); -assert.compareArray(actual, [ - // ToTemporalZonedDateTime - "get other.calendar", - "has other.calendar.dateAdd", - "has other.calendar.dateFromFields", - "has other.calendar.dateUntil", - "has other.calendar.day", - "has other.calendar.dayOfWeek", - "has other.calendar.dayOfYear", - "has other.calendar.daysInMonth", - "has other.calendar.daysInWeek", - "has other.calendar.daysInYear", - "has other.calendar.fields", - "has other.calendar.id", - "has other.calendar.inLeapYear", - "has other.calendar.mergeFields", - "has other.calendar.month", - "has other.calendar.monthCode", - "has other.calendar.monthDayFromFields", - "has other.calendar.monthsInYear", - "has other.calendar.weekOfYear", - "has other.calendar.year", - "has other.calendar.yearMonthFromFields", - "has other.calendar.yearOfWeek", - "get other.calendar.dateFromFields", - "get other.calendar.fields", - "call other.calendar.fields", - "get other.day", - "get other.day.valueOf", - "call other.day.valueOf", - "get other.hour", - "get other.hour.valueOf", - "call other.hour.valueOf", - "get other.microsecond", - "get other.microsecond.valueOf", - "call other.microsecond.valueOf", - "get other.millisecond", - "get other.millisecond.valueOf", - "call other.millisecond.valueOf", - "get other.minute", - "get other.minute.valueOf", - "call other.minute.valueOf", - "get other.month", - "get other.month.valueOf", - "call other.month.valueOf", - "get other.monthCode", - "get other.monthCode.toString", - "call other.monthCode.toString", - "get other.nanosecond", - "get other.nanosecond.valueOf", - "call other.nanosecond.valueOf", - "get other.offset", - "get other.offset.toString", - "call other.offset.toString", - "get other.second", - "get other.second.valueOf", - "call other.second.valueOf", - "get other.timeZone", - "get other.year", - "get other.year.valueOf", - "call other.year.valueOf", - "has other.timeZone.getOffsetNanosecondsFor", - "has other.timeZone.getPossibleInstantsFor", - "has other.timeZone.id", - "call other.calendar.dateFromFields", - "get other.timeZone.getOffsetNanosecondsFor", - "get other.timeZone.getPossibleInstantsFor", - "call other.timeZone.getPossibleInstantsFor", - "call other.timeZone.getOffsetNanosecondsFor", - // NOTE: extra because of wall-clock time ambiguity: - "call other.timeZone.getOffsetNanosecondsFor", - // CalendarEquals - "get this.calendar.id", - "get other.calendar.id", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.roundingIncrement", - "get options.roundingIncrement", - "getOwnPropertyDescriptor options.roundingMode", - "get options.roundingMode", - "getOwnPropertyDescriptor options.largestUnit", - "get options.largestUnit", - "getOwnPropertyDescriptor options.smallestUnit", - "get options.smallestUnit", - "getOwnPropertyDescriptor options.additional", - "get options.additional", - // GetDifferenceSettings - "get options.largestUnit.toString", - "call options.largestUnit.toString", - "get options.roundingIncrement.valueOf", - "call options.roundingIncrement.valueOf", - "get options.roundingMode.toString", - "call options.roundingMode.toString", - "get options.smallestUnit.toString", - "call options.smallestUnit.toString", - // TimeZoneEquals - "get this.timeZone.id", - "get other.timeZone.id", - // lookup - "get this.timeZone.getOffsetNanosecondsFor", - "get this.timeZone.getPossibleInstantsFor", - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // DifferenceZonedDateTime - "call this.timeZone.getOffsetNanosecondsFor", - "call this.timeZone.getOffsetNanosecondsFor", - "call this.timeZone.getPossibleInstantsFor", -], "order of operations with identical wall-clock times and largestUnit a calendar unit"); -actual.splice(0); // clear - -// Making largestUnit a calendar unit adds the following observable operations: -const expectedOpsForCalendarDifference = [ - // TimeZoneEquals - "get this.timeZone.id", - "get other.timeZone.id", - // lookup - "get this.timeZone.getOffsetNanosecondsFor", - "get this.timeZone.getPossibleInstantsFor", - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // precalculate PlainDateTime - "call this.timeZone.getOffsetNanosecondsFor", - // DifferenceZonedDateTime - "call this.timeZone.getOffsetNanosecondsFor", - "call this.timeZone.getPossibleInstantsFor", - "call this.calendar.dateUntil", -]; - -const expectedOpsForCalendarRounding = expected.concat(expectedOpsForCalendarDifference, [ - // RoundRelativeDuration - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", - "call this.timeZone.getPossibleInstantsFor", - "call this.timeZone.getPossibleInstantsFor", -]); - -// code path that skips RoundRelativeDuration: -instance.since(otherDateTimePropertyBag, createOptionsObserver({ largestUnit: "years", smallestUnit: "nanoseconds", roundingIncrement: 1 })); -assert.compareArray(actual, expected.concat(expectedOpsForCalendarDifference), "order of operations with largestUnit years and no rounding"); -actual.splice(0); // clear - -// code path through RoundRelativeDuration that rounds to the nearest year: -instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" })); -assert.compareArray(actual, expectedOpsForCalendarRounding, "order of operations with smallestUnit = years"); -actual.splice(0); // clear - -// code path through RoundRelativeDuration that rounds to the nearest month: -instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" })); -assert.compareArray(actual, expectedOpsForCalendarRounding, "order of operations with smallestUnit = months"); -actual.splice(0); // clear - -// code path through RoundRelativeDuration that rounds to the nearest week: -instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" })); -assert.compareArray(actual, expected.concat(expectedOpsForCalendarDifference, [ - // RoundRelativeDuration - "call this.calendar.dateUntil", - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", - "call this.timeZone.getPossibleInstantsFor", - "call this.timeZone.getPossibleInstantsFor", -]), "order of operations with smallestUnit = weeks"); -actual.splice(0); // clear - -instance.since(otherDateTimePropertyBag, createOptionsObserver({ largestUnit: "hours" })); -assert.compareArray(actual, expected, "order of operations with largestUnit being a time unit"); -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/order-of-operations.js index a5aabf8570..dc7a1c24d5 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/order-of-operations.js @@ -40,19 +40,9 @@ const expected = [ "get duration.years", "get duration.years.valueOf", "call duration.years.valueOf", - // lookup - "get this.timeZone.getOffsetNanosecondsFor", - "get this.timeZone.getPossibleInstantsFor", - "get this.calendar.dateAdd", - // AddZonedDateTime - "call this.timeZone.getOffsetNanosecondsFor", - "call this.calendar.dateAdd", - // ... inside Calendar.p.dateAdd "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", - // AddZonedDateTime again - "call this.timeZone.getPossibleInstantsFor", ]; const actual = []; diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/limits.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/limits.js new file mode 100644 index 0000000000..57f06adced --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/limits.js @@ -0,0 +1,24 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.toplaindatetime +description: Checking limits of representable PlainDateTime +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const min = new Temporal.ZonedDateTime(-8_640_000_000_000_000_000_000n, "-23:59"); +const max = new Temporal.ZonedDateTime(8_640_000_000_000_000_000_000n, "+23:59"); + +TemporalHelpers.assertPlainDateTime( + min.toPlainDateTime(), + -271821, 4, "M04", 19, 0, 1, 0, 0, 0, 0, + "minimum" +); + +TemporalHelpers.assertPlainDateTime( + max.toPlainDateTime(), + 275760, 9, "M09", 13, 23, 59, 0, 0, 0, 0, + "maximum" +); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/pre-epoch.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/pre-epoch.js new file mode 100644 index 0000000000..520f57dac5 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/pre-epoch.js @@ -0,0 +1,13 @@ +// Copyright (C) 2020 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.toplaindatetime +description: Test of basic functionality for an exact time earlier than the Unix epoch +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const zdt = Temporal.ZonedDateTime.from("1969-07-16T13:32:01.234567891Z[-04:00]"); +const dateTime = zdt.toPlainDateTime(); +TemporalHelpers.assertPlainDateTime(dateTime, 1969, 7, "M07", 16, 9, 32, 1, 234, 567, 891); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-always.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-always.js index 08d3803acd..7ace486c45 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-always.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-always.js @@ -7,39 +7,6 @@ description: If calendarName is "always", the calendar ID should be included. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=iso8601]", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=iso8601]", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", ...args); - const result = date.toString({ calendarName: "always" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = always`); -} +const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC"); +const result = date.toString({ calendarName: "always" }); +assert.sameValue(result, "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=iso8601]", `built-in ISO calendar for calendarName = always`); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-auto.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-auto.js index 5685d98990..996cfe4bd0 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-auto.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-auto.js @@ -7,39 +7,6 @@ description: If calendarName is "auto", "iso8601" should be omitted. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "1970-01-01T01:01:01.987654321+00:00[UTC]", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", ...args); - const result = date.toString({ calendarName: "auto" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = auto`); -} +const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC"); +const result = date.toString({ calendarName: "auto" }); +assert.sameValue(result, "1970-01-01T01:01:01.987654321+00:00[UTC]", `built-in ISO calendar for calendarName = auto`); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-critical.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-critical.js index 4cd5f7bcde..5f9c83f66b 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-critical.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-critical.js @@ -9,39 +9,6 @@ description: > features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=iso8601]", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=iso8601]", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", ...args); - const result = date.toString({ calendarName: "critical" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = critical`); -} +const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC"); +const result = date.toString({ calendarName: "critical" }); +assert.sameValue(result, "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=iso8601]", `built-in ISO calendar for calendarName = critical`); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-never.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-never.js index 23d81baa91..aaec4137a2 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-never.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-never.js @@ -7,39 +7,6 @@ description: If calendarName is "never", the calendar ID should be omitted. features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "1970-01-01T01:01:01.987654321+00:00[UTC]", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", ...args); - const result = date.toString({ calendarName: "never" }); - assert.sameValue(result, expected, `${description} calendar for calendarName = never`); -} +const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC"); +const result = date.toString({ calendarName: "never" }); +assert.sameValue(result, "1970-01-01T01:01:01.987654321+00:00[UTC]", `built-in ISO calendar for calendarName = never`); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-undefined.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-undefined.js index 245597ed63..13a21aaa1c 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-undefined.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-undefined.js @@ -14,40 +14,7 @@ info: | features: [Temporal] ---*/ -const calendarMethods = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - -const tests = [ - [[], "1970-01-01T01:01:01.987654321+00:00[UTC]", "built-in ISO"], - [[{ id: "custom", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", "custom"], - [[{ id: "iso8601", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with iso8601 id"], - [[{ id: "ISO8601", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=ISO8601]", "custom with caps id"], - [[{ id: "\u0131so8601", ...calendarMethods }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=\u0131so8601]", "custom with dotless i id"], -]; - -for (const [args, expected, description] of tests) { - const datetime = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", ...args); - const result = datetime.toString({ calendarName: undefined }); - assert.sameValue(result, expected, `default calendarName option is auto with ${description} calendar`); - // See options-object.js for {} and options-undefined.js for absent options arg -} +const datetime = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC"); +const result = datetime.toString({ calendarName: undefined }); +assert.sameValue(result, "1970-01-01T01:01:01.987654321+00:00[UTC]", `default calendarName option is auto with built-in ISO calendar`); +// See options-object.js for {} and options-undefined.js for absent options arg diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-wrong-type.js index 21bca7e70e..039906e795 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-wrong-type.js @@ -15,32 +15,9 @@ includes: [compareArray.js, temporalHelpers.js] features: [Temporal] ---*/ -const calendar = { - id: "custom", - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC", calendar); +const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC", "iso8601"); TemporalHelpers.checkStringOptionWrongType("calendarName", "auto", (calendarName) => datetime.toString({ calendarName }), - (result, descr) => assert.sameValue(result, "2001-09-09T01:46:40.987654321+00:00[UTC][u-ca=custom]", descr), + (result, descr) => assert.sameValue(result, "2001-09-09T01:46:40.987654321+00:00[UTC]", descr), ); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/options-undefined.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/options-undefined.js index c8ba5fce0f..1e54c3e4f1 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/options-undefined.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/options-undefined.js @@ -7,35 +7,12 @@ description: Verify that undefined options are handled correctly. features: [Temporal] ---*/ -const calendar = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "custom", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; const datetime1 = new Temporal.ZonedDateTime(957270896_987_650_000n, "UTC"); -const datetime2 = new Temporal.ZonedDateTime(957270896_987_650_000n, "UTC", calendar); +const datetime2 = new Temporal.ZonedDateTime(957270896_987_650_000n, "UTC", "gregory"); [ [datetime1, "2000-05-02T12:34:56.98765+00:00[UTC]"], - [datetime2, "2000-05-02T12:34:56.98765+00:00[UTC][u-ca=custom]"], + [datetime2, "2000-05-02T12:34:56.98765+00:00[UTC][u-ca=gregory]"], ].forEach(([datetime, expected]) => { const explicit = datetime.toString(undefined); assert.sameValue(explicit, expected, "default show options are auto, precision is auto, and no rounding"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/order-of-operations.js index fff53abf3f..23b27b58ae 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/order-of-operations.js @@ -27,10 +27,6 @@ const expected = [ "get options.timeZoneName", "get options.timeZoneName.toString", "call options.timeZoneName.toString", - "get this.timeZone.getOffsetNanosecondsFor", - "call this.timeZone.getOffsetNanosecondsFor", - "get this.timeZone.id", - "get this.calendar.id", ]; const actual = []; @@ -67,10 +63,6 @@ const expectedForFractionalSecondDigits = [ "get options.timeZoneName", "get options.timeZoneName.toString", "call options.timeZoneName.toString", - "get this.timeZone.getOffsetNanosecondsFor", - "call this.timeZone.getOffsetNanosecondsFor", - "get this.timeZone.id", - "get this.calendar.id", ]; instance.toString( diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-auto.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-auto.js index 46f1b57c3b..7a1c8079fe 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-auto.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-auto.js @@ -10,11 +10,6 @@ features: [Temporal] const tests = [ ["UTC", "1970-01-01T01:01:01.987654321+00:00[UTC]", "built-in UTC"], ["+01:00", "1970-01-01T02:01:01.987654321+01:00[+01:00]", "built-in offset"], - [{ - getOffsetNanosecondsFor() { return 0; }, - getPossibleInstantsFor() { return []; }, - id: "Etc/Custom", - }, "1970-01-01T01:01:01.987654321+00:00[Etc/Custom]", "custom"], ]; for (const [timeZone, expected, description] of tests) { diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-critical.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-critical.js index b20ebe5d7a..7b277350c9 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-critical.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-critical.js @@ -12,11 +12,6 @@ features: [Temporal] const tests = [ ["UTC", "1970-01-01T01:01:01.987654321+00:00[!UTC]", "built-in UTC"], ["+01:00", "1970-01-01T02:01:01.987654321+01:00[!+01:00]", "built-in offset"], - [{ - getOffsetNanosecondsFor() { return 0; }, - getPossibleInstantsFor() { return []; }, - id: "Etc/Custom", - }, "1970-01-01T01:01:01.987654321+00:00[!Etc/Custom]", "custom"], ]; for (const [timeZone, expected, description] of tests) { diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-never.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-never.js index 5f87ca06bb..a460457038 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-never.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-never.js @@ -10,11 +10,6 @@ features: [Temporal] const tests = [ ["UTC", "1970-01-01T01:01:01.987654321+00:00", "built-in UTC"], ["+01:00", "1970-01-01T02:01:01.987654321+01:00", "built-in offset"], - [{ - getOffsetNanosecondsFor() { return 0; }, - getPossibleInstantsFor() { return []; }, - id: "Etc/Custom", - }, "1970-01-01T01:01:01.987654321+00:00", "custom"], ]; for (const [timeZone, expected, description] of tests) { diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/order-of-operations.js index fed80a80ac..2000935c74 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/until/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/order-of-operations.js @@ -11,30 +11,6 @@ features: [Temporal] const expected = [ // ToTemporalZonedDateTime "get other.calendar", - "has other.calendar.dateAdd", - "has other.calendar.dateFromFields", - "has other.calendar.dateUntil", - "has other.calendar.day", - "has other.calendar.dayOfWeek", - "has other.calendar.dayOfYear", - "has other.calendar.daysInMonth", - "has other.calendar.daysInWeek", - "has other.calendar.daysInYear", - "has other.calendar.fields", - "has other.calendar.id", - "has other.calendar.inLeapYear", - "has other.calendar.mergeFields", - "has other.calendar.month", - "has other.calendar.monthCode", - "has other.calendar.monthDayFromFields", - "has other.calendar.monthsInYear", - "has other.calendar.weekOfYear", - "has other.calendar.year", - "has other.calendar.yearMonthFromFields", - "has other.calendar.yearOfWeek", - "get other.calendar.dateFromFields", - "get other.calendar.fields", - "call other.calendar.fields", "get other.day", "get other.day.valueOf", "call other.day.valueOf", @@ -69,56 +45,23 @@ const expected = [ "get other.year", "get other.year.valueOf", "call other.year.valueOf", - "has other.timeZone.getOffsetNanosecondsFor", - "has other.timeZone.getPossibleInstantsFor", - "has other.timeZone.id", - "call other.calendar.dateFromFields", - "get other.timeZone.getOffsetNanosecondsFor", - "get other.timeZone.getPossibleInstantsFor", - "call other.timeZone.getPossibleInstantsFor", - "call other.timeZone.getOffsetNanosecondsFor", - // CalendarEquals - "get this.calendar.id", - "get other.calendar.id", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.roundingIncrement", - "get options.roundingIncrement", - "getOwnPropertyDescriptor options.roundingMode", - "get options.roundingMode", - "getOwnPropertyDescriptor options.largestUnit", - "get options.largestUnit", - "getOwnPropertyDescriptor options.smallestUnit", - "get options.smallestUnit", - "getOwnPropertyDescriptor options.additional", - "get options.additional", // GetDifferenceSettings + "get options.largestUnit", "get options.largestUnit.toString", "call options.largestUnit.toString", + "get options.roundingIncrement", "get options.roundingIncrement.valueOf", "call options.roundingIncrement.valueOf", + "get options.roundingMode", "get options.roundingMode.toString", "call options.roundingMode.toString", + "get options.smallestUnit", "get options.smallestUnit.toString", "call options.smallestUnit.toString", ]; const actual = []; -const ownTimeZone = TemporalHelpers.timeZoneObserver(actual, "this.timeZone"); -const ownCalendar = TemporalHelpers.calendarObserver(actual, "this.calendar"); -const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, ownTimeZone, ownCalendar); - -const dstTimeZone = TemporalHelpers.springForwardFallBackTimeZone(); -const ownDstTimeZone = TemporalHelpers.timeZoneObserver(actual, "this.timeZone", { - getOffsetNanosecondsFor: dstTimeZone.getOffsetNanosecondsFor, - getPossibleInstantsFor: dstTimeZone.getPossibleInstantsFor, -}); -const otherDstTimeZone = TemporalHelpers.timeZoneObserver(actual, "other.timeZone", { - getOffsetNanosecondsFor: dstTimeZone.getOffsetNanosecondsFor, - getPossibleInstantsFor: dstTimeZone.getPossibleInstantsFor, -}); -/* 2000-10-29T01:30-07:00, in the middle of the first repeated hour: */ -const fallBackInstance = new Temporal.ZonedDateTime(972808200_000_000_000n, ownDstTimeZone, ownCalendar); +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); const otherDateTimePropertyBag = TemporalHelpers.propertyBagObserver(actual, { year: 2004, @@ -138,8 +81,6 @@ const otherDateTimePropertyBag = TemporalHelpers.propertyBagObserver(actual, { function createOptionsObserver({ smallestUnit = "nanoseconds", largestUnit = "auto", roundingMode = "halfExpand", roundingIncrement = 1 } = {}) { return TemporalHelpers.propertyBagObserver(actual, { - // order is significant, due to iterating through properties in order to - // copy them to an internal null-prototype object: roundingIncrement, roundingMode, largestUnit, @@ -148,220 +89,7 @@ function createOptionsObserver({ smallestUnit = "nanoseconds", largestUnit = "au }, "options"); } -// clear any observable things that happened while constructing the objects -actual.splice(0); - // basic order of observable operations, without rounding: instance.until(otherDateTimePropertyBag, createOptionsObserver()); assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -// short-circuit for identical objects will still test TimeZoneEquals if -// largestUnit is a calendar unit: -const identicalPropertyBag = TemporalHelpers.propertyBagObserver(actual, { - year: 2001, - month: 9, - monthCode: "M09", - day: 9, - hour: 1, - minute: 46, - second: 40, - millisecond: 0, - microsecond: 0, - nanosecond: 0, - offset: "+00:00", - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), - timeZone: TemporalHelpers.timeZoneObserver(actual, "other.timeZone"), -}, "other"); - -instance.until(identicalPropertyBag, createOptionsObserver({ largestUnit: "years" })); -assert.compareArray(actual, expected.concat([ - "get this.timeZone.id", - "get other.timeZone.id", -]), "order of operations with identical dates and largestUnit a calendar unit"); -actual.splice(0); // clear - -// two ZonedDateTimes that denote the same wall-clock time in the time zone can -// avoid calling some calendar methods: -const fallBackPropertyBag = TemporalHelpers.propertyBagObserver(actual, { - year: 2000, - month: 10, - monthCode: "M10", - day: 29, - hour: 1, - minute: 30, - second: 0, - millisecond: 0, - microsecond: 0, - nanosecond: 0, - offset: "-08:00", - calendar: TemporalHelpers.calendarObserver(actual, "other.calendar"), - timeZone: otherDstTimeZone, -}, "other"); -fallBackInstance.until(fallBackPropertyBag, createOptionsObserver({ largestUnit: "days" })); -assert.compareArray(actual, [ - // ToTemporalZonedDateTime - "get other.calendar", - "has other.calendar.dateAdd", - "has other.calendar.dateFromFields", - "has other.calendar.dateUntil", - "has other.calendar.day", - "has other.calendar.dayOfWeek", - "has other.calendar.dayOfYear", - "has other.calendar.daysInMonth", - "has other.calendar.daysInWeek", - "has other.calendar.daysInYear", - "has other.calendar.fields", - "has other.calendar.id", - "has other.calendar.inLeapYear", - "has other.calendar.mergeFields", - "has other.calendar.month", - "has other.calendar.monthCode", - "has other.calendar.monthDayFromFields", - "has other.calendar.monthsInYear", - "has other.calendar.weekOfYear", - "has other.calendar.year", - "has other.calendar.yearMonthFromFields", - "has other.calendar.yearOfWeek", - "get other.calendar.dateFromFields", - "get other.calendar.fields", - "call other.calendar.fields", - "get other.day", - "get other.day.valueOf", - "call other.day.valueOf", - "get other.hour", - "get other.hour.valueOf", - "call other.hour.valueOf", - "get other.microsecond", - "get other.microsecond.valueOf", - "call other.microsecond.valueOf", - "get other.millisecond", - "get other.millisecond.valueOf", - "call other.millisecond.valueOf", - "get other.minute", - "get other.minute.valueOf", - "call other.minute.valueOf", - "get other.month", - "get other.month.valueOf", - "call other.month.valueOf", - "get other.monthCode", - "get other.monthCode.toString", - "call other.monthCode.toString", - "get other.nanosecond", - "get other.nanosecond.valueOf", - "call other.nanosecond.valueOf", - "get other.offset", - "get other.offset.toString", - "call other.offset.toString", - "get other.second", - "get other.second.valueOf", - "call other.second.valueOf", - "get other.timeZone", - "get other.year", - "get other.year.valueOf", - "call other.year.valueOf", - "has other.timeZone.getOffsetNanosecondsFor", - "has other.timeZone.getPossibleInstantsFor", - "has other.timeZone.id", - "call other.calendar.dateFromFields", - "get other.timeZone.getOffsetNanosecondsFor", - "get other.timeZone.getPossibleInstantsFor", - "call other.timeZone.getPossibleInstantsFor", - "call other.timeZone.getOffsetNanosecondsFor", - // NOTE: extra because of wall-clock time ambiguity: - "call other.timeZone.getOffsetNanosecondsFor", - // CalendarEquals - "get this.calendar.id", - "get other.calendar.id", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.roundingIncrement", - "get options.roundingIncrement", - "getOwnPropertyDescriptor options.roundingMode", - "get options.roundingMode", - "getOwnPropertyDescriptor options.largestUnit", - "get options.largestUnit", - "getOwnPropertyDescriptor options.smallestUnit", - "get options.smallestUnit", - "getOwnPropertyDescriptor options.additional", - "get options.additional", - // GetDifferenceSettings - "get options.largestUnit.toString", - "call options.largestUnit.toString", - "get options.roundingIncrement.valueOf", - "call options.roundingIncrement.valueOf", - "get options.roundingMode.toString", - "call options.roundingMode.toString", - "get options.smallestUnit.toString", - "call options.smallestUnit.toString", - // TimeZoneEquals - "get this.timeZone.id", - "get other.timeZone.id", - // lookup - "get this.timeZone.getOffsetNanosecondsFor", - "get this.timeZone.getPossibleInstantsFor", - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // DifferenceZonedDateTime - "call this.timeZone.getOffsetNanosecondsFor", - "call this.timeZone.getOffsetNanosecondsFor", - "call this.timeZone.getPossibleInstantsFor", -], "order of operations with identical wall-clock times and largestUnit a calendar unit"); -actual.splice(0); // clear - -// Making largestUnit a calendar unit adds the following observable operations: -const expectedOpsForCalendarDifference = [ - // TimeZoneEquals - "get this.timeZone.id", - "get other.timeZone.id", - // lookup - "get this.timeZone.getOffsetNanosecondsFor", - "get this.timeZone.getPossibleInstantsFor", - "get this.calendar.dateAdd", - "get this.calendar.dateUntil", - // precalculate PlainDateTime - "call this.timeZone.getOffsetNanosecondsFor", - // DifferenceZonedDateTime - "call this.timeZone.getOffsetNanosecondsFor", - "call this.timeZone.getPossibleInstantsFor", - "call this.calendar.dateUntil", -]; - -const expectedOpsForCalendarRounding = expected.concat(expectedOpsForCalendarDifference, [ - // RoundRelativeDuration - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", - "call this.timeZone.getPossibleInstantsFor", - "call this.timeZone.getPossibleInstantsFor", -]); - -// code path that skips RoundRelativeDuration: -instance.until(otherDateTimePropertyBag, createOptionsObserver({ largestUnit: "years", smallestUnit: "nanoseconds", roundingIncrement: 1 })); -assert.compareArray(actual, expected.concat(expectedOpsForCalendarDifference), "order of operations with largestUnit years and no rounding"); -actual.splice(0); // clear - -// code path through RoundRelativeDuration that rounds to the nearest year: -instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" })); -assert.compareArray(actual, expectedOpsForCalendarRounding, "order of operations with smallestUnit = years"); -actual.splice(0); // clear - -// code path through RoundRelativeDuration that rounds to the nearest month: -instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" })); -assert.compareArray(actual, expectedOpsForCalendarRounding, "order of operations with smallestUnit = months"); -actual.splice(0); // clear - -// code path through RoundRelativeDuration that rounds to the nearest week: -instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" })); -assert.compareArray(actual, expected.concat(expectedOpsForCalendarDifference, [ - // RoundRelativeDuration - "call this.calendar.dateUntil", - "call this.calendar.dateAdd", - "call this.calendar.dateAdd", - "call this.timeZone.getPossibleInstantsFor", - "call this.timeZone.getPossibleInstantsFor", -]), "order of operations with smallestUnit = weeks"); -actual.splice(0); // clear - -instance.until(otherDateTimePropertyBag, createOptionsObserver({ largestUnit: "hours" })); -assert.compareArray(actual, expected, "order of operations with largestUnit being a time unit"); -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/with/balance-negative-time-units.js b/test/built-ins/Temporal/ZonedDateTime/prototype/with/balance-negative-time-units.js deleted file mode 100644 index 7903a25e68..0000000000 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/with/balance-negative-time-units.js +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.zoneddatetime.prototype.with -description: Negative time fields are balanced upwards -info: | - sec-temporal-balancetime steps 3–14: - 3. Set _microsecond_ to _microsecond_ + floor(_nanosecond_ / 1000). - 4. Set _nanosecond_ to _nanosecond_ modulo 1000. - 5. Set _millisecond_ to _millisecond_ + floor(_microsecond_ / 1000). - 6. Set _microsecond_ to _microsecond_ modulo 1000. - 7. Set _second_ to _second_ + floor(_millisecond_ / 1000). - 8. Set _millisecond_ to _millisecond_ modulo 1000. - 9. Set _minute_ to _minute_ + floor(_second_ / 60). - 10. Set _second_ to _second_ modulo 60. - 11. Set _hour_ to _hour_ + floor(_minute_ / 60). - 12. Set _minute_ to _minute_ modulo 60. - 13. Let _days_ be floor(_hour_ / 24). - 14. Set _hour_ to _hour_ modulo 24. - sec-temporal-addtime step 8: - 8. Return ? BalanceTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_). - sec-temporal-adddatetime step 1: - 1. Let _timeResult_ be ? AddTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_). - sec-temporal-builtintimezonegetinstantfor step 13.a: - a. Let _earlier_ be ? AddDateTime(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], 0, 0, 0, 0, 0, 0, 0, 0, 0, −_nanoseconds_, *"constrain"*). - sec-temporal-interpretisodatetimeoffset steps 4–10: - 4. If _offsetNanoseconds_ is *null*, or _offset_ is *"ignore"*, then - a. Let _instant_ be ? BuiltinTimeZoneGetInstantFor(_timeZone_, _dateTime_, _disambiguation_). - ... - ... - 6. Assert: _offset_ is *"prefer"* or *"reject"*. - 7. Let _possibleInstants_ be ? GetPossibleInstantsFor(_timeZone_, _dateTime_). - ... - 9. If _offset_ is *"reject"*, throw a *RangeError* exception. - 10. Let _instant_ be ? DisambiguatePossibleInstants(_possibleInstants_, _timeZone_, _dateTime_, _disambiguation_). - sec-temporal.zoneddatetime.prototype.with step 26: - 26. Let _epochNanoseconds_ be ? InterpretISODateTimeOffset(_dateTimeResult_.[[Year]], _dateTimeResult_.[[Month]], _dateTimeResult_.[[Day]], _dateTimeResult_.[[Hour]], _dateTimeResult_.[[Minute]], _dateTimeResult_.[[Second]], _dateTimeResult_.[[Millisecond]], _dateTimeResult_.[[Microsecond]], _dateTimeResult_.[[Nanosecond]], _offsetNanoseconds_, _timeZone_, _disambiguation_, _offset_). -includes: [compareArray.js, temporalHelpers.js] -features: [Temporal] ----*/ - -const shiftInstant = new Temporal.Instant(3661_001_001_001n); -const tz1 = TemporalHelpers.oneShiftTimeZone(shiftInstant, 2); -const datetime1 = new Temporal.ZonedDateTime(3661_001_001_000n, tz1); - -// This code path is encountered if offset is `ignore` or `prefer`, -// disambiguation is `earlier` and the shift is a spring-forward change -datetime1.with({ nanosecond: 1 }, { offset: "ignore", disambiguation: "earlier" }); - -const expected = [ - "1970-01-01T01:01:01.001001001", - "1970-01-01T01:01:01.001000999", -]; -assert.compareArray(tz1.getPossibleInstantsForCalledWith, expected); - -const tz2 = TemporalHelpers.oneShiftTimeZone(shiftInstant, 2); -const datetime2 = new Temporal.ZonedDateTime(3661_001_001_000n, tz2); - -datetime2.with({ nanosecond: 1 }, { offset: "prefer", disambiguation: "earlier" }); - -assert.compareArray(tz2.getPossibleInstantsForCalledWith, expected); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/with/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/prototype/with/order-of-operations.js index 488f10454f..cdf1f5dda2 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/with/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/with/order-of-operations.js @@ -12,36 +12,6 @@ const expected = [ // RejectObjectWithCalendarOrTimeZone "get fields.calendar", "get fields.timeZone", - // CopyDataProperties - "ownKeys options", - "getOwnPropertyDescriptor options.overflow", - "get options.overflow", - "getOwnPropertyDescriptor options.disambiguation", - "get options.disambiguation", - "getOwnPropertyDescriptor options.offset", - "get options.offset", - "getOwnPropertyDescriptor options.extra", - "get options.extra", - // lookup - "get this.calendar.dateFromFields", - "get this.calendar.fields", - "get this.calendar.mergeFields", - // lookup - "get this.timeZone.getOffsetNanosecondsFor", - "get this.timeZone.getPossibleInstantsFor", - // GetOffsetNanosecondsFor on receiver - "call this.timeZone.getOffsetNanosecondsFor", - // CalendarFields - "call this.calendar.fields", - // PrepareTemporalFields on receiver - "get this.calendar.day", - "call this.calendar.day", - "get this.calendar.month", - "call this.calendar.month", - "get this.calendar.monthCode", - "call this.calendar.monthCode", - "get this.calendar.year", - "call this.calendar.year", // PrepareTemporalFields on argument "get fields.day", "get fields.day.valueOf", @@ -76,19 +46,18 @@ const expected = [ "get fields.year", "get fields.year.valueOf", "call fields.year.valueOf", - // CalendarMergeFields - "call this.calendar.mergeFields", - // InterpretTemporalDateTimeFields + // GetTemporalDisambiguationOption + "get options.disambiguation", "get options.disambiguation.toString", "call options.disambiguation.toString", + // GetTemporalOffsetOption + "get options.offset", "get options.offset.toString", "call options.offset.toString", + // GetTemporalOverflowOption + "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", - "call this.calendar.dateFromFields", - // InterpretISODateTimeOffset - "call this.timeZone.getPossibleInstantsFor", - "call this.timeZone.getOffsetNanosecondsFor", ]; const actual = []; @@ -118,53 +87,3 @@ const options = TemporalHelpers.propertyBagObserver(actual, { instance.with(fields, options); assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -const dstTimeZone = TemporalHelpers.springForwardFallBackTimeZone(); -const dstTimeZoneObserver = TemporalHelpers.timeZoneObserver(actual, "this.timeZone", { - getOffsetNanosecondsFor: dstTimeZone.getOffsetNanosecondsFor, - getPossibleInstantsFor: dstTimeZone.getPossibleInstantsFor, -}); - -const dstInstance = new Temporal.ZonedDateTime(37800_000_000_000n /* 1970-01-01T02:30-08:00 */, dstTimeZoneObserver, calendar); -actual.splice(0); // clear calls that happened in constructor - -const fallBackFields = TemporalHelpers.propertyBagObserver(actual, { - year: 2000, - month: 10, - monthCode: "M10", - day: 29, - hour: 1, - minute: 30, - second: 0, - millisecond: 0, - microsecond: 0, - nanosecond: 0, - offset: "+00:00", // ignored -}, "fields"); -dstInstance.with(fallBackFields, options); -assert.compareArray(actual, expected.concat([ - // extra call in InterpretISODateTimeOffset - "call this.timeZone.getOffsetNanosecondsFor", -]), "order of operations at repeated wall-clock time"); -actual.splice(0); // clear - -const springForwardFields = TemporalHelpers.propertyBagObserver(actual, { - year: 2000, - month: 4, - monthCode: "M04", - day: 2, - hour: 2, - minute: 30, - second: 0, - millisecond: 0, - microsecond: 0, - nanosecond: 0, - offset: "+00:00", // ignored -}, "fields"); -dstInstance.with(springForwardFields, options); -assert.compareArray(actual, expected.concat([ - // DisambiguatePossibleInstants - "call this.timeZone.getOffsetNanosecondsFor", - "call this.timeZone.getPossibleInstantsFor", -]), "order of operations at skipped wall-clock time"); -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-case-insensitive.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-case-insensitive.js index 69ae9b6229..591dbf48be 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-case-insensitive.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-case-insensitive.js @@ -7,29 +7,7 @@ description: Calendar names are case-insensitive features: [Temporal] ---*/ -const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601"); let arg = "iSo8601"; const result = instance.withCalendar(arg); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-iso-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-iso-string.js index 0c1fcad9ee..293899e0b7 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-iso-string.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-iso-string.js @@ -7,29 +7,7 @@ description: An ISO 8601 string can be converted to a calendar ID in Calendar features: [Temporal] ---*/ -const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601"); for (const arg of [ "2020-01-01", diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js index 07bf8b3603..36a4a68857 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js @@ -7,29 +7,7 @@ description: A number is not allowed to be a calendar features: [Temporal] ---*/ -const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601"); const numbers = [ 1, diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-string-leap-second.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-string-leap-second.js index 8f1dda0f14..6f7fa43f86 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-string-leap-second.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-string-leap-second.js @@ -7,29 +7,7 @@ description: Leap second is a valid ISO string for Calendar features: [Temporal] ---*/ -const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601"); const arg = "2016-12-31T23:59:60"; const result = instance.withCalendar(arg); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-string.js index 7760408bc9..7a57288cfb 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-string.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-string.js @@ -7,29 +7,7 @@ description: A calendar ID is valid input for Calendar features: [Temporal] ---*/ -const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601"); const arg = "iso8601"; diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-temporal-object.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-temporal-object.js index 8ab731918d..2ca1f9763c 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-temporal-object.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-temporal-object.js @@ -3,7 +3,9 @@ /*--- esid: sec-temporal.zoneddatetime.prototype.withcalendar -description: Fast path for converting other Temporal objects to Temporal.Calendar by reading internal slots +description: > + Fast path for converting other Temporal objects to calendar ID by reading + internal slots info: | sec-temporal-totemporalcalendar step 1.b: b. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then @@ -31,29 +33,7 @@ const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UT }, }); - const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); + const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601"); const result = instance.withCalendar(arg); assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-wrong-type.js index 4733414af7..b4a4f49e36 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-wrong-type.js @@ -5,33 +5,11 @@ esid: sec-temporal.zoneddatetime.prototype.withcalendar description: > Appropriate error thrown when argument cannot be converted to a valid string - or object for Calendar + for Calendar features: [BigInt, Symbol, Temporal] ---*/ -const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601"); const primitiveTests = [ [null, "null"], diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/subclassing-ignored.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/subclassing-ignored.js index 1dbc845185..f12f0e4024 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/subclassing-ignored.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/subclassing-ignored.js @@ -8,47 +8,22 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const customCalendar = { - year() { return 1900; }, - month() { return 2; }, - day() { return 5; }, - toString() { return "custom-calendar"; }, - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "custom-calendar", - inLeapYear() {}, - mergeFields() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; - TemporalHelpers.checkSubclassingIgnored( Temporal.ZonedDateTime, [10n, "UTC"], "withCalendar", - [customCalendar], + ["iso8601"], (result) => { assert.sameValue(result.epochNanoseconds, 10n, "epochNanoseconds result"); - assert.sameValue(result.year, 1900, "year result"); - assert.sameValue(result.month, 2, "month result"); - assert.sameValue(result.day, 5, "day result"); + assert.sameValue(result.year, 1970, "year result"); + assert.sameValue(result.month, 1, "month result"); + assert.sameValue(result.day, 1, "day result"); assert.sameValue(result.hour, 0, "hour result"); assert.sameValue(result.minute, 0, "minute result"); assert.sameValue(result.second, 0, "second result"); assert.sameValue(result.millisecond, 0, "millisecond result"); assert.sameValue(result.microsecond, 0, "microsecond result"); assert.sameValue(result.nanosecond, 10, "nanosecond result"); - assert.sameValue(result.getISOFields().calendar, customCalendar, "calendar result"); + assert.sameValue(result.getISOFields().calendar, "iso8601", "calendar result"); }, ); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/order-of-operations.js index 182d50d9b4..fd7352e94c 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/order-of-operations.js @@ -29,26 +29,9 @@ const expected = [ "get plainTimeLike.second", "get plainTimeLike.second.valueOf", "call plainTimeLike.second.valueOf", - // lookup - "get this.timeZone.getOffsetNanosecondsFor", - "get this.timeZone.getPossibleInstantsFor", - // GetPlainDateTimeFor - "call this.timeZone.getOffsetNanosecondsFor", - // GetInstantFor - "call this.timeZone.getPossibleInstantsFor", ]; -const calendar = TemporalHelpers.calendarObserver(actual, "this.calendar"); -const dstTimeZone = TemporalHelpers.springForwardFallBackTimeZone(); -const timeZone = TemporalHelpers.timeZoneObserver(actual, "this.timeZone", { - getOffsetNanosecondsFor: dstTimeZone.getOffsetNanosecondsFor, - getPossibleInstantsFor: dstTimeZone.getPossibleInstantsFor, -}); - -const instance = new Temporal.ZonedDateTime(946713600_000_000_000n /* 2000-01-01T00:00-08:00 */, timeZone, calendar); -const fallBackInstance = new Temporal.ZonedDateTime(972802800_000_000_000n /* 2000-10-29T00:00-07:00 */, timeZone, calendar); -const springForwardInstance = new Temporal.ZonedDateTime(954662400_000_000_000n /* 2000-04-02T00:00-08:00 */, timeZone, calendar); -actual.splice(0); // clear calls that happened in constructors +const instance = new Temporal.ZonedDateTime(946713600_000_000_000n /* 2000-01-01T00:00-08:00 */, "UTC"); const plainTimeLike = TemporalHelpers.propertyBagObserver(actual, { hour: 2, @@ -60,26 +43,5 @@ const plainTimeLike = TemporalHelpers.propertyBagObserver(actual, { }, "plainTimeLike"); instance.withPlainTime(plainTimeLike); -assert.compareArray(actual, expected, "order of operations at normal wall-clock time"); -actual.splice(0); // clear - -const plainTimeLike130 = TemporalHelpers.propertyBagObserver(actual, { - hour: 1, - minute: 30, - second: 0, - millisecond: 0, - microsecond: 0, - nanosecond: 0, -}, "plainTimeLike"); - -fallBackInstance.withPlainTime(plainTimeLike130); -assert.compareArray(actual, expected, "order of operations at repeated wall-clock time"); -actual.splice(0); // clear - -springForwardInstance.withPlainTime(plainTimeLike); -assert.compareArray(actual, expected.concat([ - "call this.timeZone.getOffsetNanosecondsFor", - "call this.timeZone.getOffsetNanosecondsFor", - "call this.timeZone.getPossibleInstantsFor", -]), "order of operations at skipped wall-clock time"); +assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear diff --git a/test/built-ins/Temporal/getOwnPropertyNames.js b/test/built-ins/Temporal/getOwnPropertyNames.js index 783d933765..054850ccfd 100644 --- a/test/built-ins/Temporal/getOwnPropertyNames.js +++ b/test/built-ins/Temporal/getOwnPropertyNames.js @@ -10,7 +10,6 @@ features: [Temporal] const keys = Object.getOwnPropertyNames(Temporal); assert(keys.indexOf("Instant") > -1, "Instant"); -assert(keys.indexOf("TimeZone") > -1, "TimeZone"); assert(keys.indexOf("PlainDate") > -1, "PlainDate"); assert(keys.indexOf("PlainTime") > -1, "PlainTime"); assert(keys.indexOf("PlainDateTime") > -1, "PlainDateTime"); @@ -18,5 +17,4 @@ assert(keys.indexOf("ZonedDateTime") > -1, "ZonedDateTime"); assert(keys.indexOf("PlainYearMonth") > -1, "PlainYearMonth"); assert(keys.indexOf("PlainMonthDay") > -1, "PlainMonthDay"); assert(keys.indexOf("Duration") > -1, "Duration"); -assert(keys.indexOf("Calendar") > -1, "Calendar"); assert(keys.indexOf("Now") > -1, "Now"); diff --git a/test/intl402/Temporal/Calendar/from/basic.js b/test/intl402/Temporal/Calendar/from/basic.js deleted file mode 100644 index 400a8911ed..0000000000 --- a/test/intl402/Temporal/Calendar/from/basic.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.from -description: Support for non-ISO calendars in Calendar.from(). -features: [Temporal] ----*/ - -function test(item, id = item) { - const calendar = Temporal.Calendar.from(item); - assert(calendar instanceof Temporal.Calendar, `Calendar.from(${item}) is a calendar`); - assert.sameValue(calendar.id, id, `Calendar.from(${item}) has the correct ID`); -} -test("gregory"); -test("japanese"); -test("1994-11-05T08:15:30-05:00[u-ca=gregory]", "gregory"); -test("1994-11-05T13:15:30Z[u-ca=japanese]", "japanese"); diff --git a/test/intl402/Temporal/Calendar/prototype/dateFromFields/one-of-era-erayear-undefined.js b/test/intl402/Temporal/Calendar/prototype/dateFromFields/one-of-era-erayear-undefined.js deleted file mode 100644 index 351deafdff..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/dateFromFields/one-of-era-erayear-undefined.js +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2023 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.datefromfields -description: Throw a TypeError if only one of era/eraYear fields is present -features: [Temporal] ----*/ - -const base = { year: 2000, month: 5, day: 2, era: 'ce' }; -const instance = new Temporal.Calendar('gregory'); -assert.throws(TypeError, () => { - instance.dateFromFields({ ...base }); -}); - -const base2 = { year: 2000, month: 5, day: 2, eraYear: 1 }; -assert.throws(TypeError, () => { - instance.dateFromFields({ ...base2 }); -}); diff --git a/test/intl402/Temporal/Calendar/prototype/era/argument-leap-second.js b/test/intl402/Temporal/Calendar/prototype/era/argument-leap-second.js deleted file mode 100644 index 42cb42f55a..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/era/argument-leap-second.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.era -description: Leap second is a valid ISO string for PlainDate -features: [Temporal] ----*/ - -const instance = new Temporal.Calendar("iso8601"); - -let arg = "2016-12-31T23:59:60"; -const result1 = instance.era(arg); -assert.sameValue( - result1, - undefined, - "leap second is a valid ISO string for PlainDate" -); - -arg = { year: 2016, month: 12, day: 31, hour: 23, minute: 59, second: 60 }; -const result2 = instance.era(arg); -assert.sameValue( - result2, - undefined, - "second: 60 is ignored in property bag for PlainDate" -); diff --git a/test/intl402/Temporal/Calendar/prototype/era/argument-number.js b/test/intl402/Temporal/Calendar/prototype/era/argument-number.js deleted file mode 100644 index e215edd320..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/era/argument-number.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.era -description: A number cannot be used in place of a Temporal.PlainDate -features: [Temporal] ----*/ - -const instance = new Temporal.Calendar("iso8601"); - -const numbers = [ - 1, - 19761118, - -19761118, - 1234567890, -]; - -for (const arg of numbers) { - assert.throws( - TypeError, - () => instance.era(arg), - 'Numbers cannot be used in place of an ISO string for PlainDate' - ); -} diff --git a/test/intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-leap-second.js b/test/intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-leap-second.js deleted file mode 100644 index 97a5dd6298..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-leap-second.js +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.era -description: Leap second is a valid ISO string for a calendar in a property bag -features: [Temporal] ----*/ - -const instance = new Temporal.Calendar("iso8601"); - -const calendar = "2016-12-31T23:59:60"; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.era(arg); -assert.sameValue( - result, - undefined, - "leap second is a valid ISO string for calendar" -); diff --git a/test/intl402/Temporal/Calendar/prototype/era/argument-string-invalid.js b/test/intl402/Temporal/Calendar/prototype/era/argument-string-invalid.js deleted file mode 100644 index b7a6b5c0bc..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/era/argument-string-invalid.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2022 Igalia S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.era -description: > - RangeError thrown if an invalid ISO string (or syntactically valid ISO string - that is not supported) is used as a PlainDate -features: [Temporal, arrow-function] ----*/ - -const invalidStrings = [ - // invalid ISO strings: - "", - "invalid iso8601", - "2020-01-00", - "2020-01-32", - "2020-02-30", - "2021-02-29", - "2020-00-01", - "2020-13-01", - "2020-01-01T", - "2020-01-01T25:00:00", - "2020-01-01T01:60:00", - "2020-01-01T01:60:61", - "2020-01-01junk", - "2020-01-01T00:00:00junk", - "2020-01-01T00:00:00+00:00junk", - "2020-01-01T00:00:00+00:00[UTC]junk", - "2020-01-01T00:00:00+00:00[UTC][u-ca=iso8601]junk", - "02020-01-01", - "2020-001-01", - "2020-01-001", - "2020-01-01T001", - "2020-01-01T01:001", - "2020-01-01T01:01:001", - // valid, but forms not supported in Temporal: - "2020-W01-1", - "2020-001", - "+0002020-01-01", - // valid, but this calendar must not exist: - "2020-01-01[u-ca=notexist]", - // may be valid in other contexts, but insufficient information for PlainDate: - "2020-01", - "+002020-01", - "01-01", - "2020-W01", - "P1Y", - "-P12Y", - // valid, but outside the supported range: - "-999999-01-01", - "+999999-01-01", -]; -const instance = new Temporal.Calendar("iso8601"); -for (const arg of invalidStrings) { - assert.throws( - RangeError, - () => instance.era(arg), - `"${arg}" should not be a valid ISO string for a PlainDate` - ); -} diff --git a/test/intl402/Temporal/Calendar/prototype/era/argument-string-with-utc-designator.js b/test/intl402/Temporal/Calendar/prototype/era/argument-string-with-utc-designator.js deleted file mode 100644 index 4ad95a15f8..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/era/argument-string-with-utc-designator.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.era -description: RangeError thrown if a string with UTC designator is used as a PlainDate -features: [Temporal, arrow-function] ----*/ - -const invalidStrings = [ - "2019-10-01T09:00:00Z", - "2019-10-01T09:00:00Z[UTC]", -]; -const instance = new Temporal.Calendar("iso8601"); -invalidStrings.forEach((arg) => { - assert.throws( - RangeError, - () => instance.era(arg), - "String with UTC designator should not be valid as a PlainDate" - ); -}); diff --git a/test/intl402/Temporal/Calendar/prototype/era/argument-wrong-type.js b/test/intl402/Temporal/Calendar/prototype/era/argument-wrong-type.js deleted file mode 100644 index 161a86e0c1..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/era/argument-wrong-type.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.era -description: > - Appropriate error thrown when argument cannot be converted to a valid string - or property bag for PlainDate -features: [BigInt, Symbol, Temporal] ----*/ - -const instance = new Temporal.Calendar("iso8601"); - -const primitiveTests = [ - [undefined, "undefined"], - [null, "null"], - [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], - [1n, "bigint"], -]; - -for (const [arg, description] of primitiveTests) { - assert.throws( - typeof arg === 'string' ? RangeError : TypeError, - () => instance.era(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ - [Symbol(), "symbol"], - [{}, "plain object"], - [Temporal.PlainDate, "Temporal.PlainDate, object"], - [Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"], -]; - -for (const [arg, description] of typeErrorTests) { - assert.throws(TypeError, () => instance.era(arg), `${description} is not a valid property bag and does not convert to a string`); -} diff --git a/test/intl402/Temporal/Calendar/prototype/era/argument-zoneddatetime-slots.js b/test/intl402/Temporal/Calendar/prototype/era/argument-zoneddatetime-slots.js deleted file mode 100644 index ae4ba429d2..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/era/argument-zoneddatetime-slots.js +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.era -description: Getters are not called when converting a ZonedDateTime to a PlainDate. -includes: [compareArray.js] -features: [Temporal] ----*/ - -const actual = []; -const prototypeDescrs = Object.getOwnPropertyDescriptors(Temporal.ZonedDateTime.prototype); -const getters = ["year", "month", "monthCode", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond", "calendar"]; - -for (const property of getters) { - Object.defineProperty(Temporal.ZonedDateTime.prototype, property, { - get() { - actual.push(`get ${property}`); - const value = prototypeDescrs[property].get.call(this); - return { - toString() { - actual.push(`toString ${property}`); - return value.toString(); - }, - valueOf() { - actual.push(`valueOf ${property}`); - return value; - }, - }; - }, - }); -} - -const arg = new Temporal.ZonedDateTime(0n, "UTC"); -const instance = new Temporal.Calendar("iso8601"); -instance.era(arg); -assert.compareArray(actual, []); diff --git a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-leap-second.js b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-leap-second.js deleted file mode 100644 index 3d1fabe6c2..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-leap-second.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.erayear -description: Leap second is a valid ISO string for PlainDate -features: [Temporal] ----*/ - -const instance = new Temporal.Calendar("iso8601"); - -let arg = "2016-12-31T23:59:60"; -const result1 = instance.eraYear(arg); -assert.sameValue( - result1, - undefined, - "leap second is a valid ISO string for PlainDate" -); - -arg = { year: 2016, month: 12, day: 31, hour: 23, minute: 59, second: 60 }; -const result2 = instance.eraYear(arg); -assert.sameValue( - result2, - undefined, - "second: 60 is ignored in property bag for PlainDate" -); diff --git a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-number.js b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-number.js deleted file mode 100644 index ec8903e125..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-number.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.erayear -description: A number cannot be used in place of a Temporal.PlainDate -features: [Temporal] ----*/ - -const instance = new Temporal.Calendar("iso8601"); - -const numbers = [ - 1, - 19761118, - -19761118, - 1234567890, -]; - -for (const arg of numbers) { - assert.throws( - TypeError, - () => instance.eraYear(arg), - 'Numbers cannot be used in place of an ISO string for PlainDate' - ); -} diff --git a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-leap-second.js b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-leap-second.js deleted file mode 100644 index 9f27c8d8da..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-leap-second.js +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.erayear -description: Leap second is a valid ISO string for a calendar in a property bag -features: [Temporal] ----*/ - -const instance = new Temporal.Calendar("iso8601"); - -const calendar = "2016-12-31T23:59:60"; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.eraYear(arg); -assert.sameValue( - result, - undefined, - "leap second is a valid ISO string for calendar" -); diff --git a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-string-invalid.js b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-string-invalid.js deleted file mode 100644 index 6b3f65b9ea..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-string-invalid.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2022 Igalia S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.erayear -description: > - RangeError thrown if an invalid ISO string (or syntactically valid ISO string - that is not supported) is used as a PlainDate -features: [Temporal, arrow-function] ----*/ - -const invalidStrings = [ - // invalid ISO strings: - "", - "invalid iso8601", - "2020-01-00", - "2020-01-32", - "2020-02-30", - "2021-02-29", - "2020-00-01", - "2020-13-01", - "2020-01-01T", - "2020-01-01T25:00:00", - "2020-01-01T01:60:00", - "2020-01-01T01:60:61", - "2020-01-01junk", - "2020-01-01T00:00:00junk", - "2020-01-01T00:00:00+00:00junk", - "2020-01-01T00:00:00+00:00[UTC]junk", - "2020-01-01T00:00:00+00:00[UTC][u-ca=iso8601]junk", - "02020-01-01", - "2020-001-01", - "2020-01-001", - "2020-01-01T001", - "2020-01-01T01:001", - "2020-01-01T01:01:001", - // valid, but forms not supported in Temporal: - "2020-W01-1", - "2020-001", - "+0002020-01-01", - // valid, but this calendar must not exist: - "2020-01-01[u-ca=notexist]", - // may be valid in other contexts, but insufficient information for PlainDate: - "2020-01", - "+002020-01", - "01-01", - "2020-W01", - "P1Y", - "-P12Y", - // valid, but outside the supported range: - "-999999-01-01", - "+999999-01-01", -]; -const instance = new Temporal.Calendar("iso8601"); -for (const arg of invalidStrings) { - assert.throws( - RangeError, - () => instance.eraYear(arg), - `"${arg}" should not be a valid ISO string for a PlainDate` - ); -} diff --git a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-string-with-utc-designator.js b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-string-with-utc-designator.js deleted file mode 100644 index a02303876a..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-string-with-utc-designator.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.erayear -description: RangeError thrown if a string with UTC designator is used as a PlainDate -features: [Temporal, arrow-function] ----*/ - -const invalidStrings = [ - "2019-10-01T09:00:00Z", - "2019-10-01T09:00:00Z[UTC]", -]; -const instance = new Temporal.Calendar("iso8601"); -invalidStrings.forEach((arg) => { - assert.throws( - RangeError, - () => instance.eraYear(arg), - "String with UTC designator should not be valid as a PlainDate" - ); -}); diff --git a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-wrong-type.js b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-wrong-type.js deleted file mode 100644 index 8cff13438a..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-wrong-type.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.erayear -description: > - Appropriate error thrown when argument cannot be converted to a valid string - or property bag for PlainDate -features: [BigInt, Symbol, Temporal] ----*/ - -const instance = new Temporal.Calendar("iso8601"); - -const primitiveTests = [ - [undefined, "undefined"], - [null, "null"], - [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], - [1n, "bigint"], -]; - -for (const [arg, description] of primitiveTests) { - assert.throws( - typeof arg === 'string' ? RangeError : TypeError, - () => instance.eraYear(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ - [Symbol(), "symbol"], - [{}, "plain object"], - [Temporal.PlainDate, "Temporal.PlainDate, object"], - [Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"], -]; - -for (const [arg, description] of typeErrorTests) { - assert.throws(TypeError, () => instance.eraYear(arg), `${description} is not a valid property bag and does not convert to a string`); -} diff --git a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-zoneddatetime-slots.js b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-zoneddatetime-slots.js deleted file mode 100644 index 341cdf1db4..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-zoneddatetime-slots.js +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.erayear -description: Getters are not called when converting a ZonedDateTime to a PlainDate. -includes: [compareArray.js] -features: [Temporal] ----*/ - -const actual = []; -const prototypeDescrs = Object.getOwnPropertyDescriptors(Temporal.ZonedDateTime.prototype); -const getters = ["year", "month", "monthCode", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond", "calendar"]; - -for (const property of getters) { - Object.defineProperty(Temporal.ZonedDateTime.prototype, property, { - get() { - actual.push(`get ${property}`); - const value = prototypeDescrs[property].get.call(this); - return { - toString() { - actual.push(`toString ${property}`); - return value.toString(); - }, - valueOf() { - actual.push(`valueOf ${property}`); - return value; - }, - }; - }, - }); -} - -const arg = new Temporal.ZonedDateTime(0n, "UTC"); -const instance = new Temporal.Calendar("iso8601"); -instance.eraYear(arg); -assert.compareArray(actual, []); diff --git a/test/intl402/Temporal/Calendar/prototype/mergeFields/gregorian-mutually-exclusive-fields.js b/test/intl402/Temporal/Calendar/prototype/mergeFields/gregorian-mutually-exclusive-fields.js deleted file mode 100644 index ffb5e1c067..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/mergeFields/gregorian-mutually-exclusive-fields.js +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (C) 2023 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.mergefields -description: Calendar-specific mutually exclusive keys in mergeFields -features: [Temporal] ----*/ - -function assertEntriesEqual(actual, expectedEntries, message) { - const names = Object.getOwnPropertyNames(actual); - const symbols = Object.getOwnPropertySymbols(actual); - const actualKeys = names.concat(symbols); - assert.sameValue( - actualKeys.length, - expectedEntries.length, - `${message}: expected object to have ${expectedEntries.length} properties, not ${actualKeys.length}:` - ); - for (var index = 0; index < actualKeys.length; index++) { - const actualKey = actualKeys[index]; - const expectedKey = expectedEntries[index][0]; - const expectedValue = expectedEntries[index][1]; - assert.sameValue(actualKey, expectedKey, `${message}: key ${index}:`); - assert.sameValue(actual[actualKey], expectedValue, `${message}: value ${index}:`); - } -} - -const instance = new Temporal.Calendar("gregory"); - -const fullFields = { - era: "ce", - eraYear: 1981, - year: 1981, - month: 12, - monthCode: "M12", - day: 15, -}; - -assertEntriesEqual(instance.mergeFields(fullFields, { era: "bce", eraYear: 1 }), [ - ["era", "bce"], - ["eraYear", 1], - ["month", 12], - ["monthCode", "M12"], - ["day", 15], -], "era and eraYear together exclude year"); - -assertEntriesEqual(instance.mergeFields(fullFields, { year: -2 }), [ - ["year", -2], - ["month", 12], - ["monthCode", "M12"], - ["day", 15], -], "year excludes era and eraYear"); - -assertEntriesEqual(instance.mergeFields(fullFields, { month: 5 }), [ - ["era", "ce"], - ["eraYear", 1981], - ["year", 1981], - ["month", 5], - ["day", 15], -], "month excludes monthCode"); - -assertEntriesEqual(instance.mergeFields(fullFields, { monthCode: "M05" }), [ - ["era", "ce"], - ["eraYear", 1981], - ["year", 1981], - ["monthCode", "M05"], - ["day", 15], -], "monthCode excludes month"); - -// Specific test cases, of mergeFields on information that is not complete -// enough to construct a PlainDate from, as discussed in -// https://github.com/tc39/proposal-temporal/issues/2407: - -assertEntriesEqual(instance.mergeFields({ day: 25, monthCode: "M12", year: 1997, era: "bce" }, { eraYear: 1 }), [ - ["day", 25], - ["monthCode", "M12"], - ["eraYear", 1], -], "eraYear excludes year and era"); - -assertEntriesEqual(instance.mergeFields({ day: 25, monthCode: "M12", era: "bce" }, { eraYear: 1, year: 1997 }), [ - ["day", 25], - ["monthCode", "M12"], - ["eraYear", 1], - ["year", 1997], -], "eraYear and year both exclude era"); - -assertEntriesEqual(instance.mergeFields({ day: 25, monthCode: "M12", eraYear: 1 }, { era: "bce", year: 1997 }), [ - ["day", 25], - ["monthCode", "M12"], - ["era", "bce"], - ["year", 1997], -], "era and year both exclude eraYear"); - -assertEntriesEqual(instance.mergeFields({ day: 25, monthCode: "M12", year: 1997, eraYear: 1 }, { era: "bce" }), [ - ["day", 25], - ["monthCode", "M12"], - ["era", "bce"], -], "era excludes year and eraYear"); - -assertEntriesEqual(instance.mergeFields({ day: 25, monthCode: "M12", year: 1997 }, { eraYear: 1, year: 2 }), [ - ["day", 25], - ["monthCode", "M12"], - ["year", 2], - ["eraYear", 1], -], "eraYear excludes year and era, year overwritten"); diff --git a/test/intl402/Temporal/Calendar/prototype/mergeFields/japanese-mutually-exclusive-fields.js b/test/intl402/Temporal/Calendar/prototype/mergeFields/japanese-mutually-exclusive-fields.js deleted file mode 100644 index 4dcb0a30e2..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/mergeFields/japanese-mutually-exclusive-fields.js +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2023 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.mergefields -description: Calendar-specific mutually exclusive keys in mergeFields -features: [Temporal] ----*/ - -function assertEntriesEqual(actual, expectedEntries, message) { - const names = Object.getOwnPropertyNames(actual); - const symbols = Object.getOwnPropertySymbols(actual); - const actualKeys = names.concat(symbols); - assert.sameValue( - actualKeys.length, - expectedEntries.length, - `${message}: expected object to have ${expectedEntries.length} properties, not ${actualKeys.length}:` - ); - for (var index = 0; index < actualKeys.length; index++) { - const actualKey = actualKeys[index]; - const expectedKey = expectedEntries[index][0]; - const expectedValue = expectedEntries[index][1]; - assert.sameValue(actualKey, expectedKey, `${message}: key ${index}:`); - assert.sameValue(actual[actualKey], expectedValue, `${message}: value ${index}:`); - } -} - -const instance = new Temporal.Calendar("japanese"); - -const lastDayOfShowaFields = { era: "showa", eraYear: 64, year: 1989, month: 1, monthCode: "M01", day: 7 }; - -assertEntriesEqual(instance.mergeFields(lastDayOfShowaFields, { day: 10 }), [ - ["year", 1989], - ["month", 1], - ["monthCode", "M01"], - ["day", 10], -], "day excludes era and eraYear"); - -assertEntriesEqual(instance.mergeFields(lastDayOfShowaFields, { month: 2 }), [ - ["year", 1989], - ["month", 2], - ["day", 7], -], "month excludes monthCode, era, and eraYear"); - -assertEntriesEqual(instance.mergeFields(lastDayOfShowaFields, { monthCode: "M03" }), [ - ["year", 1989], - ["monthCode", "M03"], - ["day", 7], -], "monthCode excludes month, era, and eraYear"); - -assertEntriesEqual(instance.mergeFields(lastDayOfShowaFields, { year: 1988 }), [ - ["year", 1988], - ["month", 1], - ["monthCode", "M01"], - ["day", 7], -], "year excludes era and eraYear (within same era)"); - -assertEntriesEqual(instance.mergeFields(lastDayOfShowaFields, { year: 1990 }), [ - ["year", 1990], - ["month", 1], - ["monthCode", "M01"], - ["day", 7], -], "year excludes era and eraYear (in a different era)"); - -assertEntriesEqual(instance.mergeFields(lastDayOfShowaFields, { eraYear: 1 }), [ - ["eraYear", 1], - ["month", 1], - ["monthCode", "M01"], - ["day", 7], -], "eraYear excludes year and era"); - -assertEntriesEqual(instance.mergeFields(lastDayOfShowaFields, { era: "heisei" }), [ - ["era", "heisei"], - ["month", 1], - ["monthCode", "M01"], - ["day", 7], -], "era excludes year and eraYear"); diff --git a/test/intl402/Temporal/Calendar/prototype/yearMonthFromFields/one-of-era-erayear-undefined.js b/test/intl402/Temporal/Calendar/prototype/yearMonthFromFields/one-of-era-erayear-undefined.js deleted file mode 100644 index 8d8be9bbd7..0000000000 --- a/test/intl402/Temporal/Calendar/prototype/yearMonthFromFields/one-of-era-erayear-undefined.js +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2023 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.calendar.prototype.yearmonthfromfields -description: Throw a TypeError if only one of era/eraYear fields is present -features: [Temporal] ----*/ - -const base = { year: 2000, month: 5, day: 2, era: 'ce' }; -const instance = new Temporal.Calendar('gregory'); -assert.throws(TypeError, () => { - instance.yearMonthFromFields({ ...base }); -}); - -const base2 = { year: 2000, month: 5, day: 2, eraYear: 1 }; -assert.throws(TypeError, () => { - instance.yearMonthFromFields({ ...base2 }); -}); diff --git a/test/intl402/Temporal/PlainDate/from/one-of-era-erayear-undefined.js b/test/intl402/Temporal/PlainDate/from/one-of-era-erayear-undefined.js new file mode 100644 index 0000000000..acf325779e --- /dev/null +++ b/test/intl402/Temporal/PlainDate/from/one-of-era-erayear-undefined.js @@ -0,0 +1,16 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.from +description: > + Throw a TypeError if only one of era/eraYear fields is present (for calendar + using eras) +features: [Temporal] +---*/ + +const base = { year: 2000, month: 5, day: 2, era: "ce", calendar: "gregory" }; +assert.throws(TypeError, () => Temporal.PlainDate.from(base)); + +const base2 = { year: 2000, month: 5, day: 2, eraYear: 1, calendar: "gregory" }; +assert.throws(TypeError, () => Temporal.PlainDate.from(base2)); diff --git a/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-always.js b/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-always.js new file mode 100644 index 0000000000..5264392666 --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-always.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tostring +description: If calendarName is "always", the calendar ID should be included. +features: [Temporal] +---*/ + +const tests = [ + [[], "2000-05-02[u-ca=iso8601]", "built-in ISO"], + [["gregory"], "2000-05-02[u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const date = new Temporal.PlainDate(2000, 5, 2, ...args); + const result = date.toString({ calendarName: "always" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = always`); +} diff --git a/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-auto.js b/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-auto.js new file mode 100644 index 0000000000..a0e655ae41 --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-auto.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tostring +description: If calendarName is "auto", "iso8601" should be omitted. +features: [Temporal] +---*/ + +const tests = [ + [[], "2000-05-02", "built-in ISO"], + [["gregory"], "2000-05-02[u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const date = new Temporal.PlainDate(2000, 5, 2, ...args); + const result = date.toString({ calendarName: "auto" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = auto`); +} diff --git a/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-critical.js b/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-critical.js new file mode 100644 index 0000000000..ee480960ee --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-critical.js @@ -0,0 +1,21 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tostring +description: > + If calendarName is "calendar", the calendar ID should be included and prefixed + with "!". +features: [Temporal] +---*/ + +const tests = [ + [[], "2000-05-02[!u-ca=iso8601]", "built-in ISO"], + [["gregory"], "2000-05-02[!u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const date = new Temporal.PlainDate(2000, 5, 2, ...args); + const result = date.toString({ calendarName: "critical" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = critical`); +} diff --git a/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-never.js b/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-never.js new file mode 100644 index 0000000000..94d094bc44 --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-never.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tostring +description: If calendarName is "never", the calendar ID should be omitted. +features: [Temporal] +---*/ + +const tests = [ + [[], "2000-05-02", "built-in ISO"], + [["gregory"], "2000-05-02", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const date = new Temporal.PlainDate(2000, 5, 2, ...args); + const result = date.toString({ calendarName: "never" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = never`); +} diff --git a/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-undefined.js b/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-undefined.js new file mode 100644 index 0000000000..b538529ce6 --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-undefined.js @@ -0,0 +1,27 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.protoype.tostring +description: Fallback value for calendarName option +info: | + sec-getoption step 3: + 3. If _value_ is *undefined*, return _fallback_. + sec-temporal-toshowcalendaroption step 1: + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). + sec-temporal.plaindate.protoype.tostring step 4: + 4. Let _showCalendar_ be ? ToShowCalendarOption(_options_). +features: [Temporal] +---*/ + +const tests = [ + [[], "2000-05-02", "built-in ISO"], + [["gregory"], "2000-05-02[u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const date = new Temporal.PlainDate(2000, 5, 2, ...args); + const result = date.toString({ calendarName: undefined }); + assert.sameValue(result, expected, `default calendarName option is auto with ${description} calendar`); + // See options-object.js for {} and options-undefined.js for absent options arg +} diff --git a/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-wrong-type.js b/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-wrong-type.js new file mode 100644 index 0000000000..dbc7116f60 --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/toString/calendarname-wrong-type.js @@ -0,0 +1,23 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.protoype.tostring +description: Type conversions for calendarName option +info: | + sec-getoption step 9.a: + a. Set _value_ to ? ToString(_value_). + sec-temporal-toshowcalendaroption step 1: + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). + sec-temporal.plaindate.protoype.tostring step 4: + 4. Let _showCalendar_ be ? ToShowCalendarOption(_options_). +includes: [compareArray.js, temporalHelpers.js] +features: [Temporal] +---*/ + +const date = new Temporal.PlainDate(2000, 5, 2, "gregory"); + +TemporalHelpers.checkStringOptionWrongType("calendarName", "auto", + (calendarName) => date.toString({ calendarName }), + (result, descr) => assert.sameValue(result, "2000-05-02[u-ca=gregory]", descr), +); diff --git a/test/intl402/Temporal/Calendar/prototype/dateUntil/until-across-lunisolar-leap-months.js b/test/intl402/Temporal/PlainDate/prototype/until/until-across-lunisolar-leap-months.js similarity index 82% rename from test/intl402/Temporal/Calendar/prototype/dateUntil/until-across-lunisolar-leap-months.js rename to test/intl402/Temporal/PlainDate/prototype/until/until-across-lunisolar-leap-months.js index f35f6332a8..7a50d895f5 100644 --- a/test/intl402/Temporal/Calendar/prototype/dateUntil/until-across-lunisolar-leap-months.js +++ b/test/intl402/Temporal/PlainDate/prototype/until/until-across-lunisolar-leap-months.js @@ -3,12 +3,10 @@ /*--- description: dateUntil works as expected after a leap month in a lunisolar calendar -esid: sec-temporal.calendar.prototype.dateuntil +esid: sec-temporal.plaindate.prototype.until features: [Temporal] ---*/ -const instance = new Temporal.Calendar("chinese"); - // 2001 is a leap year in the Chinese calendar with a M04L leap month. // Therefore, month: 6 is M05 in 2001 but M06 in 2000 which is not a leap year. const one = Temporal.PlainDate.from({ year: 2000, month: 6, day: 1, calendar: 'chinese' }); @@ -17,6 +15,6 @@ const two = Temporal.PlainDate.from({ year: 2001, month: 6, day: 1, calendar: 'c const expected = { years: 'P12M', months: 'P12M', weeks: 'P50W4D', days: 'P354D' }; Object.entries(expected).forEach(([largestUnit, expectedResult]) => { - const actualResult = instance.dateUntil(one, two, { largestUnit }); + const actualResult = one.until(two, { largestUnit }); assert.sameValue(actualResult.toString(), expectedResult); }); diff --git a/test/intl402/Temporal/PlainDate/prototype/with/gregorian-mutually-exclusive-fields.js b/test/intl402/Temporal/PlainDate/prototype/with/gregorian-mutually-exclusive-fields.js new file mode 100644 index 0000000000..8baa19b594 --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/with/gregorian-mutually-exclusive-fields.js @@ -0,0 +1,44 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.with +description: Calendar-specific mutually exclusive keys in mergeFields +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(1981, 12, 15, "gregory"); + +TemporalHelpers.assertPlainDate(instance, 1981, 12, "M12", 15, + "check that all fields are as expected", + /* era = */ "ce", /* eraYear = */ 1981 +); + +TemporalHelpers.assertPlainDate( + instance.with({ era: "bce", eraYear: 1 }), + 0, 12, "M12", 15, + "era and eraYear together exclude year", + "bce", 1 +); + +TemporalHelpers.assertPlainDate( + instance.with({ year: -2 }), + -2, 12, "M12", 15, + "year excludes era and eraYear", + "bce", 3 +); + +TemporalHelpers.assertPlainDate( + instance.with({ month: 5 }), + 1981, 5, "M05", 15, + "month excludes monthCode", + "ce", 1981 +); + +TemporalHelpers.assertPlainDate( + instance.with({ monthCode: "M05" }), + 1981, 5, "M05", 15, + "monthCode excludes month", + "ce", 1981 +); diff --git a/test/intl402/Temporal/PlainDate/prototype/with/japanese-mutually-exclusive-fields.js b/test/intl402/Temporal/PlainDate/prototype/with/japanese-mutually-exclusive-fields.js new file mode 100644 index 0000000000..5d9426bffc --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/with/japanese-mutually-exclusive-fields.js @@ -0,0 +1,63 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.with +description: Calendar-specific mutually exclusive keys in mergeFields +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const lastDayOfShowa = Temporal.PlainDate.from({ era: "showa", eraYear: 64, year: 1989, month: 1, monthCode: "M01", day: 7, calendar: "japanese" }); + +TemporalHelpers.assertPlainDate(lastDayOfShowa, 1989, 1, "M01", 7, + "check expected fields", + /* era = */ "showa", /* eraYear = */ 64 +); + +TemporalHelpers.assertPlainDate( + lastDayOfShowa.with({ day: 10 }), + 1989, 1, "M01", 10, + "day excludes era and eraYear", + /* era = */ "heisei", /* eraYear = */ 1 +); + +TemporalHelpers.assertPlainDate( + lastDayOfShowa.with({ month: 2 }), + 1989, 2, "M02", 7, + "month excludes monthCode, era, and eraYear", + "heisei", 1 +); + +TemporalHelpers.assertPlainDate( + lastDayOfShowa.with({ monthCode: "M03" }), + 1989, 3, "M03", 7, + "monthCode excludes month, era, and eraYear", + "heisei", 1 +); + +TemporalHelpers.assertPlainDate( + lastDayOfShowa.with({ year: 1988 }), + 1988, 1, "M01", 7, + "year excludes era and eraYear (within same era)", + "showa", 63 +); + +TemporalHelpers.assertPlainDate( + lastDayOfShowa.with({ year: 1990 }), + 1990, 1, "M01", 7, + "year excludes era and eraYear (in a different era)", + "heisei", 2 +); + +assert.throws( + TypeError, + () => lastDayOfShowa.with({ eraYear: 1 }), + "eraYear excludes year and era, and cannot be provided without era", +); + +assert.throws( + TypeError, + () => lastDayOfShowa.with({ era: "heisei" }), + "era excludes year and eraYear, and cannot be provided without eraYear", +); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-always.js b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-always.js index 727b24ce90..b862fd1598 100644 --- a/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-always.js +++ b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-always.js @@ -3,14 +3,17 @@ /*--- esid: sec-temporal.plaindatetime.prototype.tostring -description: Show calendar when calendarName is "always" +description: If calendarName is "always", the calendar ID should be included. features: [Temporal] ---*/ -const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, "gregory"); +const tests = [ + [[], "1976-11-18T15:23:00[u-ca=iso8601]", "built-in ISO"], + [["gregory"], "1976-11-18T15:23:00[u-ca=gregory]", "built-in Gregorian"], +]; -assert.sameValue( - dt.toString({ calendarName: "always" }), - "1976-11-18T15:23:00[u-ca=gregory]", - "shows non-ISO calendar if calendarName = always" -); +for (const [args, expected, description] of tests) { + const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, ...args); + const result = date.toString({ calendarName: "always" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = always`); +} diff --git a/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js index 2f9586a83d..218495e300 100644 --- a/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js +++ b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js @@ -3,12 +3,17 @@ /*--- esid: sec-temporal.plaindatetime.prototype.tostring -description: Possibly display calendar when calendarName is "auto" +description: If calendarName is "auto", "iso8601" should be omitted. features: [Temporal] ---*/ -const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, "gregory"); -const expected = "1976-11-18T15:23:00[u-ca=gregory]"; +const tests = [ + [[], "1976-11-18T15:23:00", "built-in ISO"], + [["gregory"], "1976-11-18T15:23:00[u-ca=gregory]", "built-in Gregorian"], +]; -assert.sameValue(dt.toString(), expected, "shows non-ISO calendar by default (no arguments)"); -assert.sameValue(dt.toString({ calendarName: "auto" }), expected, "shows only non-ISO calendar if calendarName = auto"); +for (const [args, expected, description] of tests) { + const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, ...args); + const result = date.toString({ calendarName: "auto" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = auto`); +} diff --git a/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-critical.js b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-critical.js new file mode 100644 index 0000000000..05f3af2634 --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-critical.js @@ -0,0 +1,21 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.tostring +description: > + If calendarName is "calendar", the calendar ID should be included and prefixed + with "!". +features: [Temporal] +---*/ + +const tests = [ + [[], "1976-11-18T15:23:00[!u-ca=iso8601]", "built-in ISO"], + [["gregory"], "1976-11-18T15:23:00[!u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, ...args); + const result = date.toString({ calendarName: "critical" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = critical`); +} diff --git a/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-never.js b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-never.js index 1bd9018a21..5b739a82d8 100644 --- a/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-never.js +++ b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-never.js @@ -3,14 +3,17 @@ /*--- esid: sec-temporal.plaindatetime.prototype.tostring -description: Do not show calendar (even non-ISO calendars) if calendarName = "never" +description: If calendarName is "never", the calendar ID should be omitted. features: [Temporal] ---*/ -const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23); +const tests = [ + [[], "1976-11-18T15:23:00", "built-in ISO"], + [["gregory"], "1976-11-18T15:23:00", "built-in Gregorian"], +]; -assert.sameValue( - dt.withCalendar("gregory").toString({ calendarName: "never" }), - "1976-11-18T15:23:00", - "omits non-ISO calendar if calendarName = never" -); +for (const [args, expected, description] of tests) { + const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, ...args); + const result = date.toString({ calendarName: "never" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = never`); +} diff --git a/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-undefined.js b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-undefined.js new file mode 100644 index 0000000000..a3ccfec072 --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-undefined.js @@ -0,0 +1,27 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.protoype.tostring +description: Fallback value for calendarName option +info: | + sec-getoption step 3: + 3. If _value_ is *undefined*, return _fallback_. + sec-temporal-toshowcalendaroption step 1: + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). + sec-temporal.plaindatetime.protoype.tostring step 6: + 6. Let _showCalendar_ be ? ToShowCalendarOption(_options_). +features: [Temporal] +---*/ + +const tests = [ + [[], "1976-11-18T15:23:00", "built-in ISO"], + [["gregory"], "1976-11-18T15:23:00[u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const datetime = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, ...args); + const result = datetime.toString({ calendarName: undefined }); + assert.sameValue(result, expected, `default calendarName option is auto with ${description} calendar`); + // See options-object.js for {} and options-undefined.js for absent options arg +} diff --git a/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-wrong-type.js b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-wrong-type.js new file mode 100644 index 0000000000..9ed20a7824 --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-wrong-type.js @@ -0,0 +1,23 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.protoype.tostring +description: Type conversions for calendarName option +info: | + sec-getoption step 9.a: + a. Set _value_ to ? ToString(_value_). + sec-temporal-toshowcalendaroption step 1: + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). + sec-temporal.plaindatetime.protoype.tostring step 6: + 6. Let _showCalendar_ be ? ToShowCalendarOption(_options_). +includes: [compareArray.js, temporalHelpers.js] +features: [Temporal] +---*/ + +const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, "gregory"); + +TemporalHelpers.checkStringOptionWrongType("calendarName", "auto", + (calendarName) => datetime.toString({ calendarName }), + (result, descr) => assert.sameValue(result, "2000-05-02T12:34:56.987654321[u-ca=gregory]", descr), +); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/toZonedDateTime/dst-disambiguation.js b/test/intl402/Temporal/PlainDateTime/prototype/toZonedDateTime/dst-disambiguation.js new file mode 100644 index 0000000000..5d8f7132e3 --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/toZonedDateTime/dst-disambiguation.js @@ -0,0 +1,72 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.tozoneddatetime +description: Basic tests for disambiguation option, with DST time zone +features: [Temporal] +---*/ + +const dtmFall = new Temporal.PlainDateTime(2000, 10, 29, 1, 45); + +assert.sameValue( + dtmFall.toZonedDateTime("America/Los_Angeles").epochNanoseconds, + 972809100_000_000_000n, // 2000-10-29T08:45:00Z + "epoch nanoseconds in fall back - no disambiguation" +); + +assert.sameValue( + dtmFall.toZonedDateTime("America/Los_Angeles", { disambiguation: "earlier" }).epochNanoseconds, + 972809100_000_000_000n, // 2000-10-29T08:45:00Z + "epoch nanoseconds in fall back - earlier" +); + +assert.sameValue( + dtmFall.toZonedDateTime("America/Los_Angeles", { disambiguation: "later" }).epochNanoseconds, + 972812700_000_000_000n, // 2000-10-29T09:45:00Z + "epoch nanoseconds in fall back - later" +); + +assert.sameValue( + dtmFall.toZonedDateTime("America/Los_Angeles", { disambiguation: "compatible" }).epochNanoseconds, + 972809100_000_000_000n, // 2000-10-29T08:45:00Z + "epoch nanoseconds in fall back - compatible" +); + +assert.throws( + RangeError, + () => dtmFall.toZonedDateTime("America/Los_Angeles", { disambiguation: "reject" }), + "fall back - reject" +); + +var dtmSpring = new Temporal.PlainDateTime(2000, 4, 2, 2, 30); + +assert.sameValue( + dtmSpring.toZonedDateTime("America/Los_Angeles").epochNanoseconds, + 954671400_000_000_000n, // 2000-04-02T10:30:00Z + "epoch nanoseconds in spring forward - no disambiguation" +); + +assert.sameValue( + dtmSpring.toZonedDateTime("America/Los_Angeles", { disambiguation: "earlier" }).epochNanoseconds, + 954667800_000_000_000n, // 2000-04-02T09:30:00Z + "epoch nanoseconds in spring forward - earlier" +); + +assert.sameValue( + dtmSpring.toZonedDateTime("America/Los_Angeles", { disambiguation: "later" }).epochNanoseconds, + 954671400_000_000_000n, // 2000-04-02T10:30:00Z + "epoch nanoseconds in spring forward - later" +); + +assert.sameValue( + dtmSpring.toZonedDateTime("America/Los_Angeles", { disambiguation: "compatible" }).epochNanoseconds, + 954671400_000_000_000n, // 2000-04-02T10:30:00Z + "epoch nanoseconds in spring forward - compatible" +); + +assert.throws( + RangeError, + () => dtmSpring.toZonedDateTime("America/Los_Angeles", { disambiguation: "reject" }), + "spring forward - reject" +); diff --git a/test/intl402/Temporal/Calendar/prototype/monthDayFromFields/fields-underspecified.js b/test/intl402/Temporal/PlainMonthDay/from/fields-underspecified.js similarity index 78% rename from test/intl402/Temporal/Calendar/prototype/monthDayFromFields/fields-underspecified.js rename to test/intl402/Temporal/PlainMonthDay/from/fields-underspecified.js index 712eb8f89a..7a067b5781 100644 --- a/test/intl402/Temporal/Calendar/prototype/monthDayFromFields/fields-underspecified.js +++ b/test/intl402/Temporal/PlainMonthDay/from/fields-underspecified.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.monthdayfromfields +esid: sec-temporal.plainmonthday.from description: Throw a RangeError if only one of era/eraYear fields is present features: [Temporal] ---*/ @@ -15,6 +15,5 @@ const tests = [ ]; for (const [calendarId, arg, description] of tests) { - const instance = new Temporal.Calendar(calendarId); - assert.throws(TypeError, () => instance.monthDayFromFields(arg), description); + assert.throws(TypeError, () => Temporal.PlainMonthDay.from({ ...arg, calendar: calendarId }), description); } diff --git a/test/intl402/Temporal/Calendar/prototype/monthDayFromFields/reference-year-1972.js b/test/intl402/Temporal/PlainMonthDay/from/reference-year-1972.js similarity index 63% rename from test/intl402/Temporal/Calendar/prototype/monthDayFromFields/reference-year-1972.js rename to test/intl402/Temporal/PlainMonthDay/from/reference-year-1972.js index 4e2ac6532d..c89bf601b5 100644 --- a/test/intl402/Temporal/Calendar/prototype/monthDayFromFields/reference-year-1972.js +++ b/test/intl402/Temporal/PlainMonthDay/from/reference-year-1972.js @@ -2,22 +2,20 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.calendar.prototype.monthdayfromfields +esid: sec-temporal.plainmonthday.from description: Deterministic choosing of the reference year includes: [temporalHelpers.js] features: [Temporal] ---*/ -const gregory = new Temporal.Calendar("gregory"); - -const result1 = gregory.monthDayFromFields({ year: 2021, monthCode: "M02", day: 29 }); +const result1 = Temporal.PlainMonthDay.from({ year: 2021, monthCode: "M02", day: 29, calendar: "gregory" }); TemporalHelpers.assertPlainMonthDay( result1, "M02", 29, "year is ignored and reference year should be 1972 if monthCode is given", 1972 ); -const result2 = gregory.monthDayFromFields({ year: 2021, month: 2, day: 29 }, { overflow: "constrain" }); +const result2 = Temporal.PlainMonthDay.from({ year: 2021, month: 2, day: 29, calendar: "gregory" }, { overflow: "constrain" }); TemporalHelpers.assertPlainMonthDay( result2, "M02", 28, "if monthCode is not given, year is used to determine if calendar date exists, but reference year should still be 1972", @@ -26,34 +24,32 @@ TemporalHelpers.assertPlainMonthDay( assert.throws( RangeError, - () => gregory.monthDayFromFields({ year: 2021, month: 2, day: 29 }, { overflow: "reject" }), + () => Temporal.PlainMonthDay.from({ year: 2021, month: 2, day: 29, calendar: "gregory" }, { overflow: "reject" }), "RangeError thrown if calendar date does not exist in given year and overflow is reject" ); -const hebrew = new Temporal.Calendar("hebrew"); - -const result3 = hebrew.monthDayFromFields({ monthCode: "M01", day: 1 }); +const result3 = Temporal.PlainMonthDay.from({ monthCode: "M01", day: 1, calendar: "hebrew" }); TemporalHelpers.assertPlainMonthDay( result3, "M01", 1, "reference year should be 1972 if date exists in 1972", 1972 ); -const result4 = hebrew.monthDayFromFields({ monthCode: "M05L", day: 1 }); +const result4 = Temporal.PlainMonthDay.from({ monthCode: "M05L", day: 1, calendar: "hebrew" }); TemporalHelpers.assertPlainMonthDay( result4, "M05L", 1, "reference year should be the latest ISO year before 1972 if date does not exist in 1972", 1970 ); -const result5 = hebrew.monthDayFromFields({ year: 5781, monthCode: "M02", day: 30 }); +const result5 = Temporal.PlainMonthDay.from({ year: 5781, monthCode: "M02", day: 30, calendar: "hebrew" }); TemporalHelpers.assertPlainMonthDay( result5, "M02", 30, "year is ignored if monthCode is given (Cheshvan 5781 has 29 days)", 1971 ); -const result6 = hebrew.monthDayFromFields({ year: 5781, month: 2, day: 30 }, { overflow: "constrain" }); +const result6 = Temporal.PlainMonthDay.from({ year: 5781, month: 2, day: 30, calendar: "hebrew" }, { overflow: "constrain" }); TemporalHelpers.assertPlainMonthDay( result6, "M02", 29, "if monthCode is not given, year is used to determine if calendar date exists, but reference year still correct", @@ -62,11 +58,11 @@ TemporalHelpers.assertPlainMonthDay( assert.throws( RangeError, - () => hebrew.monthDayFromFields({ year: 5781, month: 2, day: 30 }, { overflow: "reject" }), + () => Temporal.PlainMonthDay.from({ year: 5781, month: 2, day: 30, calendar: "hebrew" }, { overflow: "reject" }), "RangeError thrown if calendar date does not exist in given year and overflow is reject" ); -const result7 = hebrew.monthDayFromFields({ monthCode: "M04", day: 26 }); +const result7 = Temporal.PlainMonthDay.from({ monthCode: "M04", day: 26, calendar: "hebrew" }); TemporalHelpers.assertPlainMonthDay( result7, "M04", 26, "reference date should be the later one, if two options exist in ISO year 1972", diff --git a/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-always.js b/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-always.js new file mode 100644 index 0000000000..0dca04e70c --- /dev/null +++ b/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-always.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.prototype.tostring +description: If calendarName is "always", the calendar ID should be included. +features: [Temporal] +---*/ + +const tests = [ + [[], "1972-05-02[u-ca=iso8601]", "built-in ISO"], + [["gregory"], "1972-05-02[u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const monthday = new Temporal.PlainMonthDay(5, 2, ...args); + const result = monthday.toString({ calendarName: "always" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = always`); +} diff --git a/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-auto.js b/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-auto.js new file mode 100644 index 0000000000..3acb78b84f --- /dev/null +++ b/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-auto.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.prototype.tostring +description: If calendarName is "auto", "iso8601" should be omitted. +features: [Temporal] +---*/ + +const tests = [ + [[], "05-02", "built-in ISO"], + [["gregory"], "1972-05-02[u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const monthday = new Temporal.PlainMonthDay(5, 2, ...args); + const result = monthday.toString({ calendarName: "auto" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = auto`); +} diff --git a/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-critical.js b/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-critical.js new file mode 100644 index 0000000000..a3998621b3 --- /dev/null +++ b/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-critical.js @@ -0,0 +1,21 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.prototype.tostring +description: > + If calendarName is "calendar", the calendar ID should be included and prefixed + with "!". +features: [Temporal] +---*/ + +const tests = [ + [[], "1972-05-02[!u-ca=iso8601]", "built-in ISO"], + [["gregory"], "1972-05-02[!u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const monthday = new Temporal.PlainMonthDay(5, 2, ...args); + const result = monthday.toString({ calendarName: "critical" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = critical`); +} diff --git a/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-never.js b/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-never.js new file mode 100644 index 0000000000..2f13967f77 --- /dev/null +++ b/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-never.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.prototype.tostring +description: If calendarName is "never", the calendar ID should be omitted. +features: [Temporal] +---*/ + +const tests = [ + [[], "05-02", "built-in ISO"], + [["gregory"], "1972-05-02", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const monthday = new Temporal.PlainMonthDay(5, 2, ...args); + const result = monthday.toString({ calendarName: "never" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = never`); +} diff --git a/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-undefined.js b/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-undefined.js new file mode 100644 index 0000000000..e378d99857 --- /dev/null +++ b/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-undefined.js @@ -0,0 +1,27 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.protoype.tostring +description: Fallback value for calendarName option +info: | + sec-getoption step 3: + 3. If _value_ is *undefined*, return _fallback_. + sec-temporal-toshowcalendaroption step 1: + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). + sec-temporal.plainmonthday.protoype.tostring step 4: + 4. Let _showCalendar_ be ? ToShowCalendarOption(_options_). +features: [Temporal] +---*/ + +const tests = [ + [[], "05-02", "built-in ISO"], + [["gregory"], "1972-05-02[u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const monthday = new Temporal.PlainMonthDay(5, 2, ...args); + const result = monthday.toString({ calendarName: undefined }); + assert.sameValue(result, expected, `default calendarName option is auto with ${description} calendar`); + // See options-object.js for {} and options-undefined.js for absent options arg +} diff --git a/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-wrong-type.js b/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-wrong-type.js new file mode 100644 index 0000000000..35d25ccc4c --- /dev/null +++ b/test/intl402/Temporal/PlainMonthDay/prototype/toString/calendarname-wrong-type.js @@ -0,0 +1,23 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.protoype.tostring +description: Type conversions for calendarName option +info: | + sec-getoption step 9.a: + a. Set _value_ to ? ToString(_value_). + sec-temporal-toshowcalendaroption step 1: + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). + sec-temporal.plainmonthday.protoype.tostring step 4: + 4. Let _showCalendar_ be ? ToShowCalendarOption(_options_). +includes: [compareArray.js, temporalHelpers.js] +features: [Temporal] +---*/ + +const monthday = new Temporal.PlainMonthDay(5, 2, "gregory"); + +TemporalHelpers.checkStringOptionWrongType("calendarName", "auto", + (calendarName) => monthday.toString({ calendarName }), + (result, descr) => assert.sameValue(result, "1972-05-02[u-ca=gregory]", descr), +); diff --git a/test/intl402/Temporal/PlainYearMonth/from/one-of-era-erayear-undefined.js b/test/intl402/Temporal/PlainYearMonth/from/one-of-era-erayear-undefined.js new file mode 100644 index 0000000000..917e322f07 --- /dev/null +++ b/test/intl402/Temporal/PlainYearMonth/from/one-of-era-erayear-undefined.js @@ -0,0 +1,14 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: Throw a TypeError if only one of era/eraYear fields is present +features: [Temporal] +---*/ + +const base = { year: 2000, month: 5, day: 2, era: "ce", calendar: "gregory" }; +assert.throws(TypeError, () => Temporal.PlainYearMonth.from(base)); + +const base2 = { year: 2000, month: 5, day: 2, eraYear: 1, calendar: "gregory" }; +assert.throws(TypeError, () => Temporal.PlainYearMonth.from(base2)); diff --git a/test/intl402/Temporal/Calendar/prototype/yearMonthFromFields/reference-day-chinese.js b/test/intl402/Temporal/PlainYearMonth/from/reference-day-chinese.js similarity index 87% rename from test/intl402/Temporal/Calendar/prototype/yearMonthFromFields/reference-day-chinese.js rename to test/intl402/Temporal/PlainYearMonth/from/reference-day-chinese.js index 4d319c7a49..5235fbdd6a 100644 --- a/test/intl402/Temporal/Calendar/prototype/yearMonthFromFields/reference-day-chinese.js +++ b/test/intl402/Temporal/PlainYearMonth/from/reference-day-chinese.js @@ -11,8 +11,6 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const chinese = new Temporal.Calendar("chinese"); - // Month codes, month indices, and the ISO reference days of the months in 2022 const months2022TestData = [ // TODO: Sources conflict over whether M01L and M12L exist in _any_ year. @@ -37,11 +35,11 @@ const months2022TestData = [ ]; for (const [nonLeapMonthCode, month, referenceISODay] of months2022TestData) { // Allow implementation-defined "epoch year" for the Chinese calendar. - const year = new Temporal.PlainDate(2022, 3, 1).withCalendar(chinese).year; + const year = new Temporal.PlainDate(2022, 3, 1).withCalendar("chinese").year; const leapMonthCode = nonLeapMonthCode + "L"; - const fields = { year, monthCode: leapMonthCode }; + const fields = { year, monthCode: leapMonthCode, calendar: "chinese" }; - const result = chinese.yearMonthFromFields(fields, { overflow: "constrain" }); + const result = Temporal.PlainYearMonth.from(fields, { overflow: "constrain" }); TemporalHelpers.assertPlainYearMonth( result, year, month, nonLeapMonthCode, @@ -51,7 +49,7 @@ for (const [nonLeapMonthCode, month, referenceISODay] of months2022TestData) { assert.throws( RangeError, - () => chinese.yearMonthFromFields(fields, { overflow: "reject" }), + () => Temporal.PlainYearMonth.from(fields, { overflow: "reject" }), `Chinese intercalary month ${leapMonthCode} does not exist in year 2022 (overflow reject)` ); } @@ -72,8 +70,8 @@ const leapMonthsTestData = [ ]; for (const [monthCode, relatedYear, month, referenceISODay, isoYear = relatedYear, isoMonth = month] of leapMonthsTestData) { // Allow implementation-defined "epoch year" for the Chinese calendar. - const year = new Temporal.PlainDate(relatedYear, 3, 1).withCalendar(chinese).year; - const result = chinese.yearMonthFromFields({ year, monthCode }); + const year = new Temporal.PlainDate(relatedYear, 3, 1).withCalendar("chinese").year; + const result = Temporal.PlainYearMonth.from({ year, monthCode, calendar: "chinese" }); TemporalHelpers.assertPlainYearMonth( result, year, month, monthCode, diff --git a/test/intl402/Temporal/Calendar/prototype/yearMonthFromFields/reference-day-gregory.js b/test/intl402/Temporal/PlainYearMonth/from/reference-day-gregory.js similarity index 73% rename from test/intl402/Temporal/Calendar/prototype/yearMonthFromFields/reference-day-gregory.js rename to test/intl402/Temporal/PlainYearMonth/from/reference-day-gregory.js index 37ca10172c..03231f65eb 100644 --- a/test/intl402/Temporal/Calendar/prototype/yearMonthFromFields/reference-day-gregory.js +++ b/test/intl402/Temporal/PlainYearMonth/from/reference-day-gregory.js @@ -11,9 +11,7 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const gregory = new Temporal.Calendar("gregory"); - -const result1 = gregory.yearMonthFromFields({ year: 2023, monthCode: "M01", day: 13 }); +const result1 = Temporal.PlainYearMonth.from({ year: 2023, monthCode: "M01", day: 13, calendar: "gregory" }); TemporalHelpers.assertPlainYearMonth( result1, 2023, 1, "M01", @@ -21,7 +19,7 @@ TemporalHelpers.assertPlainYearMonth( "ce", 2023, /* reference day = */ 1 ); -const result2 = gregory.yearMonthFromFields({ year: 2021, monthCode: "M02", day: 50 }, { overflow: "constrain" }); +const result2 = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M02", day: 50, calendar: "gregory" }, { overflow: "constrain" }); TemporalHelpers.assertPlainYearMonth( result2, 2021, 2, "M02", @@ -29,7 +27,7 @@ TemporalHelpers.assertPlainYearMonth( "ce", 2021, /* reference day = */ 1 ); -const result3 = gregory.yearMonthFromFields({ year: 2021, monthCode: "M02", day: 50 }, { overflow: "reject" }); +const result3 = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M02", day: 50, calendar: "gregory" }, { overflow: "reject" }); TemporalHelpers.assertPlainYearMonth( result3, 2021, 2, "M02", diff --git a/test/intl402/Temporal/Calendar/prototype/yearMonthFromFields/reference-day-hebrew.js b/test/intl402/Temporal/PlainYearMonth/from/reference-day-hebrew.js similarity index 70% rename from test/intl402/Temporal/Calendar/prototype/yearMonthFromFields/reference-day-hebrew.js rename to test/intl402/Temporal/PlainYearMonth/from/reference-day-hebrew.js index a8e78d9855..b609c38ae8 100644 --- a/test/intl402/Temporal/Calendar/prototype/yearMonthFromFields/reference-day-hebrew.js +++ b/test/intl402/Temporal/PlainYearMonth/from/reference-day-hebrew.js @@ -11,9 +11,7 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const hebrew = new Temporal.Calendar("hebrew"); - -const result4 = hebrew.yearMonthFromFields({ year: 5782, monthCode: "M04", day: 20 }); +const result4 = Temporal.PlainYearMonth.from({ year: 5782, monthCode: "M04", day: 20, calendar: "hebrew" }); TemporalHelpers.assertPlainYearMonth( result4, 5782, 4, "M04", @@ -24,7 +22,7 @@ const isoFields = result4.getISOFields(); assert.sameValue(isoFields.isoYear, 2021, "Tevet 5782 begins in ISO year 2021"); assert.sameValue(isoFields.isoMonth, 12, "Tevet 5782 begins in ISO month 12"); -const result5 = hebrew.yearMonthFromFields({ year: 5783, monthCode: "M05L" }, { overflow: "constrain" }); +const result5 = Temporal.PlainYearMonth.from({ year: 5783, monthCode: "M05L", calendar: "hebrew" }, { overflow: "constrain" }); TemporalHelpers.assertPlainYearMonth( result5, 5783, 6, "M06", @@ -34,11 +32,11 @@ TemporalHelpers.assertPlainYearMonth( assert.throws( RangeError, - () => hebrew.yearMonthFromFields({ year: 5783, monthCode: "M05L" }, { overflow: "reject" }), + () => Temporal.PlainYearMonth.from({ year: 5783, monthCode: "M05L", calendar: "hebrew" }, { overflow: "reject" }), "month code M05L does not exist in year 5783 (overflow reject)", ); -const result6 = hebrew.yearMonthFromFields({ year: 5783, month: 13 }, { overflow: "constrain" }); +const result6 = Temporal.PlainYearMonth.from({ year: 5783, month: 13, calendar: "hebrew" }, { overflow: "constrain" }); TemporalHelpers.assertPlainYearMonth( result6, 5783, 12, "M12", @@ -48,11 +46,11 @@ TemporalHelpers.assertPlainYearMonth( assert.throws( RangeError, - () => hebrew.yearMonthFromFields({ year: 5783, month: 13 }, { overflow: "reject" }), + () => Temporal.PlainYearMonth.from({ year: 5783, month: 13, calendar: "hebrew" }, { overflow: "reject" }), "month 13 does not exist in year 5783 (overflow reject)", ); -const result7 = hebrew.yearMonthFromFields({ year: 5782, monthCode: "M04", day: 50 }, { overflow: "constrain" }); +const result7 = Temporal.PlainYearMonth.from({ year: 5782, monthCode: "M04", day: 50, calendar: "hebrew" }, { overflow: "constrain" }); TemporalHelpers.assertPlainYearMonth( result7, 5782, 4, "M04", @@ -60,7 +58,7 @@ TemporalHelpers.assertPlainYearMonth( /* era = */ undefined, /* era year = */ undefined, /* reference day = */ 5 ); -const result8 = hebrew.yearMonthFromFields({ year: 5782, monthCode: "M04", day: 50 }, { overflow: "reject" }); +const result8 = Temporal.PlainYearMonth.from({ year: 5782, monthCode: "M04", day: 50, calendar: "hebrew" }, { overflow: "reject" }); TemporalHelpers.assertPlainYearMonth( result8, 5782, 4, "M04", diff --git a/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-always.js b/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-always.js new file mode 100644 index 0000000000..49227c54ce --- /dev/null +++ b/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-always.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.tostring +description: If calendarName is "always", the calendar ID should be included. +features: [Temporal] +---*/ + +const tests = [ + [[], "2000-05-01[u-ca=iso8601]", "built-in ISO"], + [["gregory"], "2000-05-01[u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const yearmonth = new Temporal.PlainYearMonth(2000, 5, ...args); + const result = yearmonth.toString({ calendarName: "always" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = always`); +} diff --git a/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-auto.js b/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-auto.js new file mode 100644 index 0000000000..b5f77cdf1a --- /dev/null +++ b/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-auto.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.tostring +description: If calendarName is "auto", "iso8601" should be omitted. +features: [Temporal] +---*/ + +const tests = [ + [[], "2000-05", "built-in ISO"], + [["gregory"], "2000-05-01[u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const yearmonth = new Temporal.PlainYearMonth(2000, 5, ...args); + const result = yearmonth.toString({ calendarName: "auto" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = auto`); +} diff --git a/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-critical.js b/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-critical.js new file mode 100644 index 0000000000..e5ee9de94b --- /dev/null +++ b/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-critical.js @@ -0,0 +1,21 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.tostring +description: > + If calendarName is "calendar", the calendar ID should be included and prefixed + with "!". +features: [Temporal] +---*/ + +const tests = [ + [[], "2000-05-01[!u-ca=iso8601]", "built-in ISO"], + [["gregory"], "2000-05-01[!u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const yearmonth = new Temporal.PlainYearMonth(2000, 5, ...args); + const result = yearmonth.toString({ calendarName: "critical" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = critical`); +} diff --git a/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-never.js b/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-never.js new file mode 100644 index 0000000000..84d01b04a1 --- /dev/null +++ b/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-never.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.tostring +description: If calendarName is "never", the calendar ID should be omitted. +features: [Temporal] +---*/ + +const tests = [ + [[], "2000-05", "built-in ISO"], + [["gregory"], "2000-05-01", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const yearmonth = new Temporal.PlainYearMonth(2000, 5, ...args); + const result = yearmonth.toString({ calendarName: "never" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = never`); +} diff --git a/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-undefined.js b/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-undefined.js new file mode 100644 index 0000000000..b45ccfef78 --- /dev/null +++ b/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-undefined.js @@ -0,0 +1,27 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.protoype.tostring +description: Fallback value for calendarName option +info: | + sec-getoption step 3: + 3. If _value_ is *undefined*, return _fallback_. + sec-temporal-toshowcalendaroption step 1: + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). + sec-temporal.plainyearmonth.protoype.tostring step 4: + 4. Let _showCalendar_ be ? ToShowCalendarOption(_options_). +features: [Temporal] +---*/ + +const tests = [ + [[], "2000-05", "built-in ISO"], + [["gregory"], "2000-05-01[u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const yearmonth = new Temporal.PlainYearMonth(2000, 5, ...args); + const result = yearmonth.toString({ calendarName: undefined }); + assert.sameValue(result, expected, `default calendarName option is auto with ${description} calendar`); + // See options-object.js for {} and options-undefined.js for absent options arg +} diff --git a/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-wrong-type.js b/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-wrong-type.js new file mode 100644 index 0000000000..a7c0b49cf2 --- /dev/null +++ b/test/intl402/Temporal/PlainYearMonth/prototype/toString/calendarname-wrong-type.js @@ -0,0 +1,23 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.protoype.tostring +description: Type conversions for calendarName option +info: | + sec-getoption step 9.a: + a. Set _value_ to ? ToString(_value_). + sec-temporal-toshowcalendaroption step 1: + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). + sec-temporal.plainyearmonth.protoype.tostring step 4: + 4. Let _showCalendar_ be ? ToShowCalendarOption(_options_). +includes: [compareArray.js, temporalHelpers.js] +features: [Temporal] +---*/ + +const yearmonth = new Temporal.PlainYearMonth(2000, 5, "gregory"); + +TemporalHelpers.checkStringOptionWrongType("calendarName", "auto", + (calendarName) => yearmonth.toString({ calendarName }), + (result, descr) => assert.sameValue(result, "2000-05-01[u-ca=gregory]", descr), +); diff --git a/test/intl402/Temporal/TimeZone/from/argument-object.js b/test/intl402/Temporal/TimeZone/from/argument-object.js deleted file mode 100644 index 79147dc6c5..0000000000 --- a/test/intl402/Temporal/TimeZone/from/argument-object.js +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2020 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.timezone.from -description: An object is returned unchanged -features: [Temporal] ----*/ - -class CustomTimeZone extends Temporal.TimeZone {} - -const objects = [ - new Temporal.TimeZone("Europe/Madrid"), - new CustomTimeZone("Africa/Accra"), -]; - -const thisValues = [ - Temporal.TimeZone, - CustomTimeZone, - {}, - null, - undefined, - 7, -]; - -for (const thisValue of thisValues) { - for (const object of objects) { - const result = Temporal.TimeZone.from.call(thisValue, object); - assert.sameValue(result, object); - } - - const zdt = new Temporal.ZonedDateTime(0n, "Africa/Cairo"); - const fromZdt = Temporal.TimeZone.from.call(thisValue, zdt); - assert.notSameValue(fromZdt, zdt.getISOFields().timeZone, "from() creates a new object for a string slot value"); - assert.sameValue(fromZdt.id, "Africa/Cairo"); -} diff --git a/test/intl402/Temporal/TimeZone/from/timezone-string-legacy-non-iana.js b/test/intl402/Temporal/TimeZone/from/timezone-string-legacy-non-iana.js deleted file mode 100644 index 88008dc53d..0000000000 --- a/test/intl402/Temporal/TimeZone/from/timezone-string-legacy-non-iana.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2024 André Bargull. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.timezone.from -description: Only IANA time zone identifiers are allowed. -features: [Temporal] ----*/ - -// List of non-IANA link names, copied from: -// https://github.com/unicode-org/icu/blob/main/icu4c/source/tools/tzcode/icuzones -const invalidTimeZones = [ - "ACT", - "AET", - "AGT", - "ART", - "AST", - "BET", - "BST", - "CAT", - "CNT", - "CST", - "CTT", - "EAT", - "ECT", - "IET", - "IST", - "JST", - "MIT", - "NET", - "NST", - "PLT", - "PNT", - "PRT", - "PST", - "SST", - "VST", -]; - -for (let timeZone of invalidTimeZones) { - assert.throws(RangeError, () => { - Temporal.TimeZone.from(timeZone); - }, "Time zone: " + timeZone); -} diff --git a/test/intl402/Temporal/TimeZone/iana-legacy-names.js b/test/intl402/Temporal/TimeZone/iana-legacy-names.js deleted file mode 100644 index 4f6974fa62..0000000000 --- a/test/intl402/Temporal/TimeZone/iana-legacy-names.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.timezone -description: IANA legacy names must be supported -features: [Temporal] ----*/ - -const legacyNames = [ - "Etc/GMT0", - "GMT0", - "GMT-0", - "GMT+0", - "EST5EDT", - "CST6CDT", - "MST7MDT", - "PST8PDT" -]; - -legacyNames.forEach((arg) => { - const tz = new Temporal.TimeZone(arg); - assert.sameValue(tz.toString(), arg, `"${arg}" does not match "${tz.toString()}" time zone identifier`); -}); diff --git a/test/intl402/Temporal/TimeZone/timezone-case-insensitive.js b/test/intl402/Temporal/TimeZone/timezone-case-insensitive.js deleted file mode 100644 index fa90f4dcc6..0000000000 --- a/test/intl402/Temporal/TimeZone/timezone-case-insensitive.js +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.timezone -description: Time zone names are case insensitive -features: [Temporal] ----*/ - -const timeZone = 'eTc/gMt+1'; -const result = new Temporal.TimeZone(timeZone); -assert.sameValue(result.toString(), 'Etc/GMT+1', `Time zone created from string "${timeZone}"`); diff --git a/test/intl402/Temporal/TimeZone/etc-timezone.js b/test/intl402/Temporal/ZonedDateTime/etc-timezone.js similarity index 74% rename from test/intl402/Temporal/TimeZone/etc-timezone.js rename to test/intl402/Temporal/ZonedDateTime/etc-timezone.js index e2260dc744..955edf6539 100644 --- a/test/intl402/Temporal/TimeZone/etc-timezone.js +++ b/test/intl402/Temporal/ZonedDateTime/etc-timezone.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone +esid: sec-temporal.zoneddatetime description: Some Etc/GMT{+/-}{0}N timezones are valid, but not all features: [Temporal] ---*/ @@ -11,9 +11,9 @@ features: [Temporal] [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14].forEach((n) => { let tz = "Etc/GMT-" + n; - let instance = new Temporal.TimeZone(tz); + let instance = new Temporal.ZonedDateTime(0n, tz); assert.sameValue( - instance.toString(), + instance.timeZoneId, tz, tz + " is a valid timezone" ); @@ -22,7 +22,7 @@ features: [Temporal] let gmtMinus24TZ = "Etc/GMT-24"; assert.throws( RangeError, - () => { new Temporal.TimeZone(gmtMinus24TZ); }, + () => { new Temporal.ZonedDateTime(0n, gmtMinus24TZ); }, gmtMinus24TZ + " is an invalid timezone" ); @@ -31,7 +31,7 @@ assert.throws( let tz = "Etc/GMT-0" + n; assert.throws( RangeError, - () => { new Temporal.TimeZone(tz); }, + () => { new Temporal.ZonedDateTime(0n, tz); }, tz + " is an invalid timezone" ); }); @@ -41,7 +41,7 @@ assert.throws( let tz = "Etc/GMT+0" + n; assert.throws( RangeError, - () => { new Temporal.TimeZone(tz); }, + () => { new Temporal.ZonedDateTime(0n, tz); }, tz + " is an invalid timezone" ); }); @@ -50,9 +50,9 @@ assert.throws( [0,1,2,3,4,5,6,7,8,9,10,11,12].forEach((n) => { let tz = "Etc/GMT+" + n; - let instance = new Temporal.TimeZone(tz); + let instance = new Temporal.ZonedDateTime(0n, tz); assert.sameValue( - instance.toString(), + instance.timeZoneId, tz, tz + " is a valid timezone" ); @@ -61,6 +61,6 @@ assert.throws( let gmtPlus24TZ = "Etc/GMT+24"; assert.throws( RangeError, - () => { new Temporal.TimeZone(gmtPlus24TZ); }, + () => { new Temporal.ZonedDateTime(0n, gmtPlus24TZ); }, gmtPlus24TZ + " is an invalid timezone" ); diff --git a/test/intl402/Temporal/TimeZone/from/argument-valid.js b/test/intl402/Temporal/ZonedDateTime/from/argument-valid.js similarity index 70% rename from test/intl402/Temporal/TimeZone/from/argument-valid.js rename to test/intl402/Temporal/ZonedDateTime/from/argument-valid.js index 3671857ab1..ff897d932a 100644 --- a/test/intl402/Temporal/TimeZone/from/argument-valid.js +++ b/test/intl402/Temporal/ZonedDateTime/from/argument-valid.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone.from +esid: sec-temporal.zoneddatetime.from description: Built-in time zones are parsed correctly out of valid strings features: [Temporal] ---*/ @@ -21,8 +21,7 @@ const valids = [ ]; for (const [valid, canonical = valid] of valids) { - const result = Temporal.TimeZone.from(valid); - assert.sameValue(Object.getPrototypeOf(result), Temporal.TimeZone.prototype); - assert.sameValue(result.id, canonical); - assert.sameValue(result.toString(), canonical); + const result = Temporal.ZonedDateTime.from({ year: 1970, month: 1, day: 1, timeZone: valid }); + assert.sameValue(Object.getPrototypeOf(result), Temporal.ZonedDateTime.prototype); + assert.sameValue(result.timeZoneId, canonical); } diff --git a/test/intl402/Temporal/TimeZone/from/etc-timezone.js b/test/intl402/Temporal/ZonedDateTime/from/etc-timezone.js similarity index 68% rename from test/intl402/Temporal/TimeZone/from/etc-timezone.js rename to test/intl402/Temporal/ZonedDateTime/from/etc-timezone.js index a925836c19..4afd6ec3d5 100644 --- a/test/intl402/Temporal/TimeZone/from/etc-timezone.js +++ b/test/intl402/Temporal/ZonedDateTime/from/etc-timezone.js @@ -2,18 +2,20 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone.from +esid: sec-temporal.zoneddatetime.from description: Some Etc/GMT{+/-}{0}N timezones are valid, but not all features: [Temporal] ---*/ // "Etc/GMT-0" through "Etc/GMT-14" are OK +const fields = { year: 1970, month: 1, day: 1 }; + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14].forEach((n) => { const tz = "Etc/GMT-" + n; - const instance = Temporal.TimeZone.from(tz); + const instance = Temporal.ZonedDateTime.from({ ...fields, timeZone: tz }); assert.sameValue( - instance.toString(), + instance.timeZoneId, tz, tz + " is a valid timezone" ); @@ -22,7 +24,7 @@ features: [Temporal] const gmtMinus24TZ = "Etc/GMT-24"; assert.throws( RangeError, - () => Temporal.TimeZone.from(gmtMinus24TZ), + () => Temporal.ZonedDateTime.from({ ...fields, timeZone: gmtMinus24TZ }), gmtMinus24TZ + " is an invalid timezone" ); @@ -31,7 +33,7 @@ assert.throws( const tz = "Etc/GMT-0" + n; assert.throws( RangeError, - () => Temporal.TimeZone.from(tz), + () => Temporal.ZonedDateTime.from({ ...fields, timeZone: tz }), tz + " is an invalid timezone" ); }); @@ -41,7 +43,7 @@ assert.throws( const tz = "Etc/GMT+0" + n; assert.throws( RangeError, - () => Temporal.TimeZone.from(tz), + () => Temporal.ZonedDateTime.from({ ...fields, timeZone: tz }), tz + " is an invalid timezone" ); }); @@ -50,9 +52,9 @@ assert.throws( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].forEach((n) => { const tz = "Etc/GMT+" + n; - const instance = Temporal.TimeZone.from(tz); + const instance = Temporal.ZonedDateTime.from({ ...fields, timeZone: tz }); assert.sameValue( - instance.toString(), + instance.timeZoneId, tz, tz + " is a valid timezone" ); @@ -61,6 +63,6 @@ assert.throws( const gmtPlus24TZ = "Etc/GMT+24"; assert.throws( RangeError, - () => Temporal.TimeZone.from(gmtPlus24TZ), + () => Temporal.ZonedDateTime.from({ ...fields, timeZone: gmtPlus24TZ }), gmtPlus24TZ + " is an invalid timezone" ); diff --git a/test/intl402/Temporal/TimeZone/from/iana-legacy-names.js b/test/intl402/Temporal/ZonedDateTime/iana-legacy-names.js similarity index 64% rename from test/intl402/Temporal/TimeZone/from/iana-legacy-names.js rename to test/intl402/Temporal/ZonedDateTime/iana-legacy-names.js index d820320e17..7306570cee 100644 --- a/test/intl402/Temporal/TimeZone/from/iana-legacy-names.js +++ b/test/intl402/Temporal/ZonedDateTime/iana-legacy-names.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone +esid: sec-temporal.zoneddatetime description: IANA legacy names must be supported features: [Temporal] ---*/ @@ -19,6 +19,6 @@ const legacyNames = [ ]; legacyNames.forEach((arg) => { - const tz = Temporal.TimeZone.from(arg); - assert.sameValue(tz.toString(), arg, `"${arg}" does not match "${tz.toString()}" time zone identifier`); + const instance = new Temporal.ZonedDateTime(0n, arg); + assert.sameValue(instance.timeZoneId, arg, `"${arg}" does not match "${instance.timeZoneId}" time zone identifier`); }); diff --git a/test/intl402/Temporal/TimeZone/legacy-non-iana.js b/test/intl402/Temporal/ZonedDateTime/legacy-non-iana.js similarity index 90% rename from test/intl402/Temporal/TimeZone/legacy-non-iana.js rename to test/intl402/Temporal/ZonedDateTime/legacy-non-iana.js index 87db5d09f4..f51dc56a79 100644 --- a/test/intl402/Temporal/TimeZone/legacy-non-iana.js +++ b/test/intl402/Temporal/ZonedDateTime/legacy-non-iana.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone +esid: sec-temporal.zoneddatetime description: Only IANA time zone identifiers are allowed. features: [Temporal] ---*/ @@ -39,6 +39,6 @@ const invalidTimeZones = [ for (let timeZone of invalidTimeZones) { assert.throws(RangeError, () => { - new Temporal.TimeZone(timeZone); + new Temporal.ZonedDateTime(0n, timeZone); }, "Time zone: " + timeZone); } diff --git a/test/intl402/Temporal/TimeZone/links-africa.js b/test/intl402/Temporal/ZonedDateTime/links-africa.js similarity index 93% rename from test/intl402/Temporal/TimeZone/links-africa.js rename to test/intl402/Temporal/ZonedDateTime/links-africa.js index 05f36d73e3..4ddafb0c6f 100644 --- a/test/intl402/Temporal/TimeZone/links-africa.js +++ b/test/intl402/Temporal/ZonedDateTime/links-africa.js @@ -2,9 +2,8 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone -description: > - TimeZone constructor accepts link names as its input. +esid: sec-temporal.zoneddatetime +description: ZonedDateTime constructor accepts link names as time zone ID input features: [Temporal] ---*/ @@ -49,6 +48,6 @@ const testCases = [ ]; for (let id of testCases) { - const tz = new Temporal.TimeZone(id); - assert.sameValue(tz.id, id); + const instance = new Temporal.ZonedDateTime(0n, id); + assert.sameValue(instance.timeZoneId, id); } diff --git a/test/intl402/Temporal/TimeZone/links-asia.js b/test/intl402/Temporal/ZonedDateTime/links-asia.js similarity index 76% rename from test/intl402/Temporal/TimeZone/links-asia.js rename to test/intl402/Temporal/ZonedDateTime/links-asia.js index 0359cfb232..d7e30a1509 100644 --- a/test/intl402/Temporal/TimeZone/links-asia.js +++ b/test/intl402/Temporal/ZonedDateTime/links-asia.js @@ -2,9 +2,8 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone -description: > - TimeZone constructor accepts link names as its input. +esid: sec-temporal.zoneddatetime +description: ZonedDateTime constructor accepts link names as time zone ID input features: [Temporal] ---*/ @@ -20,6 +19,6 @@ const testCases = [ ]; for (let id of testCases) { - const tz = new Temporal.TimeZone(id); - assert.sameValue(tz.id, id); + const instance = new Temporal.ZonedDateTime(0n, id); + assert.sameValue(instance.timeZoneId, id); } diff --git a/test/intl402/Temporal/TimeZone/links-australasia.js b/test/intl402/Temporal/ZonedDateTime/links-australasia.js similarity index 71% rename from test/intl402/Temporal/TimeZone/links-australasia.js rename to test/intl402/Temporal/ZonedDateTime/links-australasia.js index 8aeaf33efb..8f55b49f9f 100644 --- a/test/intl402/Temporal/TimeZone/links-australasia.js +++ b/test/intl402/Temporal/ZonedDateTime/links-australasia.js @@ -2,9 +2,8 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone -description: > - TimeZone constructor accepts link names as its input. +esid: sec-temporal.zoneddatetime +description: ZonedDateTime constructor accepts link names as time zone ID input features: [Temporal] ---*/ @@ -16,6 +15,6 @@ const testCases = [ ]; for (let id of testCases) { - const tz = new Temporal.TimeZone(id); - assert.sameValue(tz.id, id); + const instance = new Temporal.ZonedDateTime(0n, id); + assert.sameValue(instance.timeZoneId, id); } diff --git a/test/intl402/Temporal/TimeZone/links-backward.js b/test/intl402/Temporal/ZonedDateTime/links-backward.js similarity index 97% rename from test/intl402/Temporal/TimeZone/links-backward.js rename to test/intl402/Temporal/ZonedDateTime/links-backward.js index bbcd5945cb..2589861fdd 100644 --- a/test/intl402/Temporal/TimeZone/links-backward.js +++ b/test/intl402/Temporal/ZonedDateTime/links-backward.js @@ -2,9 +2,8 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone -description: > - TimeZone constructor accepts link names as its input. +esid: sec-temporal.zoneddatetime +description: ZonedDateTime constructor accepts link names as time zone ID input features: [Temporal] ---*/ @@ -135,6 +134,6 @@ const testCases = [ ]; for (let id of testCases) { - const tz = new Temporal.TimeZone(id); - assert.sameValue(tz.id, id); + const instance = new Temporal.ZonedDateTime(0n, id); + assert.sameValue(instance.timeZoneId, id); } diff --git a/test/intl402/Temporal/TimeZone/links-backzone.js b/test/intl402/Temporal/ZonedDateTime/links-backzone.js similarity index 78% rename from test/intl402/Temporal/TimeZone/links-backzone.js rename to test/intl402/Temporal/ZonedDateTime/links-backzone.js index cfeb44ef85..f2017e0e96 100644 --- a/test/intl402/Temporal/TimeZone/links-backzone.js +++ b/test/intl402/Temporal/ZonedDateTime/links-backzone.js @@ -2,9 +2,8 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone -description: > - TimeZone constructor accepts link names as its input. +esid: sec-temporal.zoneddatetime +description: ZonedDateTime constructor accepts link names as time zone ID input features: [Temporal] ---*/ @@ -20,6 +19,6 @@ const testCases = [ ]; for (let id of testCases) { - const tz = new Temporal.TimeZone(id); - assert.sameValue(tz.id, id); + const instance = new Temporal.ZonedDateTime(0n, id); + assert.sameValue(instance.timeZoneId, id); } diff --git a/test/intl402/Temporal/TimeZone/links-etcetera.js b/test/intl402/Temporal/ZonedDateTime/links-etcetera.js similarity index 76% rename from test/intl402/Temporal/TimeZone/links-etcetera.js rename to test/intl402/Temporal/ZonedDateTime/links-etcetera.js index de1f19a92f..1eeff08dbc 100644 --- a/test/intl402/Temporal/TimeZone/links-etcetera.js +++ b/test/intl402/Temporal/ZonedDateTime/links-etcetera.js @@ -2,9 +2,8 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone -description: > - TimeZone constructor accepts link names as its input. +esid: sec-temporal.zoneddatetime +description: ZonedDateTime constructor accepts link names as time zone ID input features: [Temporal] ---*/ @@ -19,6 +18,6 @@ const testCases = [ ]; for (let id of testCases) { - const tz = new Temporal.TimeZone(id); - assert.sameValue(tz.id, id); + const instance = new Temporal.ZonedDateTime(0n, id); + assert.sameValue(instance.timeZoneId, id); } diff --git a/test/intl402/Temporal/TimeZone/links-europe.js b/test/intl402/Temporal/ZonedDateTime/links-europe.js similarity index 86% rename from test/intl402/Temporal/TimeZone/links-europe.js rename to test/intl402/Temporal/ZonedDateTime/links-europe.js index ba650e72d6..36eb1c04de 100644 --- a/test/intl402/Temporal/TimeZone/links-europe.js +++ b/test/intl402/Temporal/ZonedDateTime/links-europe.js @@ -2,9 +2,8 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone -description: > - TimeZone constructor accepts link names as its input. +esid: sec-temporal.zoneddatetime +description: ZonedDateTime constructor accepts link names as time zone ID input features: [Temporal] ---*/ @@ -28,6 +27,6 @@ const testCases = [ ]; for (let id of testCases) { - const tz = new Temporal.TimeZone(id); - assert.sameValue(tz.id, id); + const instance = new Temporal.ZonedDateTime(0n, id); + assert.sameValue(instance.timeZoneId, id); } diff --git a/test/intl402/Temporal/TimeZone/links-northamerica.js b/test/intl402/Temporal/ZonedDateTime/links-northamerica.js similarity index 90% rename from test/intl402/Temporal/TimeZone/links-northamerica.js rename to test/intl402/Temporal/ZonedDateTime/links-northamerica.js index 6f1d5bba9b..91141cc974 100644 --- a/test/intl402/Temporal/TimeZone/links-northamerica.js +++ b/test/intl402/Temporal/ZonedDateTime/links-northamerica.js @@ -2,9 +2,8 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone -description: > - TimeZone constructor accepts link names as its input. +esid: sec-temporal.zoneddatetime +description: ZonedDateTime constructor accepts link names as time zone ID input features: [Temporal] ---*/ @@ -35,6 +34,6 @@ const testCases = [ ]; for (let id of testCases) { - const tz = new Temporal.TimeZone(id); - assert.sameValue(tz.id, id); + const instance = new Temporal.ZonedDateTime(0n, id); + assert.sameValue(instance.timeZoneId, id); } diff --git a/test/intl402/Temporal/TimeZone/non-canonical-utc.js b/test/intl402/Temporal/ZonedDateTime/non-canonical-utc.js similarity index 62% rename from test/intl402/Temporal/TimeZone/non-canonical-utc.js rename to test/intl402/Temporal/ZonedDateTime/non-canonical-utc.js index f7cde4e07d..082797f48b 100644 --- a/test/intl402/Temporal/TimeZone/non-canonical-utc.js +++ b/test/intl402/Temporal/ZonedDateTime/non-canonical-utc.js @@ -2,9 +2,8 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone -description: > - TimeZone constructor canonicalises its input. +esid: sec-temporal.zoneddatetime +description: ZonedDateTime constructor accepts link names as time zone ID input features: [Temporal] ---*/ @@ -21,7 +20,7 @@ const testCases = [ ]; for (let id of testCases) { - let tz = new Temporal.TimeZone(id); + let instance = new Temporal.ZonedDateTime(0n, id); - assert.sameValue(tz.id, id); + assert.sameValue(instance.timeZoneId, id); } diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/equals/argument-object.js b/test/intl402/Temporal/ZonedDateTime/prototype/equals/argument-object.js index daac5530cd..a5e707f683 100644 --- a/test/intl402/Temporal/ZonedDateTime/prototype/equals/argument-object.js +++ b/test/intl402/Temporal/ZonedDateTime/prototype/equals/argument-object.js @@ -9,97 +9,36 @@ features: [Temporal] const instance = new Temporal.ZonedDateTime(0n, "UTC"); -class CustomTimeZone extends Temporal.TimeZone { - constructor(id) { - super("UTC"); - this._id = id; - } - get id() { - return this._id; - } -} - -const classInstancesIANA = [ - new Temporal.TimeZone("Asia/Calcutta"), - new CustomTimeZone("Asia/Calcutta"), - new Temporal.TimeZone("Asia/Kolkata"), - new CustomTimeZone("Asia/Kolkata"), - new CustomTimeZone("ASIA/calcutta"), - new CustomTimeZone("Asia/KOLKATA") +const namesIANA = [ + "Asia/Calcutta", + "Asia/Kolkata", + "ASIA/calcutta", + "Asia/KOLKATA", ]; -const plainObjectsIANA = [ - { id: "Asia/Calcutta", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }, - { id: "Asia/Kolkata", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }, - { id: "ASIA/calcutta", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }, - { id: "asia/kolkatA", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null } +for (const id1 of namesIANA) { + for (const id2 of namesIANA) { + assert( + instance.withTimeZone(id1).equals(instance.withTimeZone(id2)), + `Receiver ${id1} should equal argument ${id2}` + ); + } +} + +const namesIANADifferentCanonical = [ + "Asia/Colombo", + "ASIA/colombo", ]; -for (const object1 of classInstancesIANA) { - for (const object2 of classInstancesIANA) { +for (const id1 of namesIANADifferentCanonical) { + for (const id2 of namesIANA) { assert( - instance.withTimeZone(object1).equals(instance.withTimeZone(object2)), - `Receiver ${object1.id} should not equal argument ${object2.id}` + !instance.withTimeZone(id1).equals(instance.withTimeZone(id2)), + `Receiver ${id1} should not equal argument ${id2}` ); - } - for (const object2 of plainObjectsIANA) { assert( - instance.withTimeZone(object1).equals(instance.withTimeZone(object2)), - `Receiver ${object2.id} should not equal argument ${object1.id}` - ); - } -} - -const classInstancesIANADifferentCanonical = [ - new Temporal.TimeZone("Asia/Colombo"), - new CustomTimeZone("Asia/Colombo"), - new Temporal.TimeZone("ASIA/colombo"), - new CustomTimeZone("ASIA/colombo") -]; - -for (const object1 of classInstancesIANADifferentCanonical) { - for (const object2 of classInstancesIANA) { - assert( - !instance.withTimeZone(object1).equals(instance.withTimeZone(object2)), - `Receiver ${object1.id} should not equal argument ${object2.id}` - ); - assert( - !instance.withTimeZone(object2).equals(instance.withTimeZone(object1)), - `Receiver ${object2.id} should not equal argument ${object1.id}` - ); - } - for (const object2 of plainObjectsIANA) { - assert( - !instance.withTimeZone(object1).equals(instance.withTimeZone(object2)), - `Receiver ${object1.id} should not equal argument ${object2.id}` - ); - assert( - !instance.withTimeZone(object1).equals(instance.withTimeZone(object2.id)), - `Receiver ${object1.id} should not equal argument ${object2.id}` - ); - } -} - -const classInstancesCustomNotIANA = [new CustomTimeZone("Moon/Cheese")]; -for (const object1 of classInstancesCustomNotIANA) { - for (const object2 of classInstancesIANA) { - assert( - !instance.withTimeZone(object1).equals(instance.withTimeZone(object2)), - `Receiver ${object1.id} should not equal argument ${object2.id}` - ); - assert( - !instance.withTimeZone(object2).equals(instance.withTimeZone(object1)), - `Receiver ${object2.id} should not equal argument ${object1.id}` - ); - } - for (const object2 of plainObjectsIANA) { - assert( - !instance.withTimeZone(object1).equals(instance.withTimeZone(object2)), - `Receiver ${object1.id} should not equal argument ${object2.id}` - ); - assert( - !instance.withTimeZone(object1).equals(instance.withTimeZone(object2.id)), - `Receiver ${object1.id} should not equal argument ${object2.id}` + !instance.withTimeZone(id2).equals(instance.withTimeZone(id1)), + `Receiver ${id2} should not equal argument ${id1}` ); } } diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/hoursInDay/dst-midnight.js b/test/intl402/Temporal/ZonedDateTime/prototype/hoursInDay/dst-midnight.js new file mode 100644 index 0000000000..24e443d3d4 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/hoursInDay/dst-midnight.js @@ -0,0 +1,26 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-temporal.zoneddatetime.prototype.hoursinday +description: Test hoursInDay for DST changes at midnight +features: [Temporal] +---*/ + +const fall = Temporal.ZonedDateTime.from({ + year: 2018, + month: 2, + day: 17, + hour: 12, + timeZone: "America/Sao_Paulo", +}); +assert.sameValue(fall.hoursInDay, 25, "25-hour day with backward jump at midnight"); + +const spring = Temporal.ZonedDateTime.from({ + year: 2018, + month: 11, + day: 4, + hour: 12, + timeZone: "America/Sao_Paulo", +}); +assert.sameValue(spring.hoursInDay, 23, "23-hour day with forward jump at midnight"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/offset/basic-named-timezone.js b/test/intl402/Temporal/ZonedDateTime/prototype/offset/basic-named-timezone.js new file mode 100644 index 0000000000..217233f9f5 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/offset/basic-named-timezone.js @@ -0,0 +1,11 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.offset +description: Basic functionality in named time zone +features: [Temporal] +---*/ + +var instance = new Temporal.ZonedDateTime(0n, "America/Los_Angeles"); +assert.sameValue(instance.offset, "-08:00"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/offsetNanoseconds/basic-named-timezone.js b/test/intl402/Temporal/ZonedDateTime/prototype/offsetNanoseconds/basic-named-timezone.js new file mode 100644 index 0000000000..c99b8490ef --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/offsetNanoseconds/basic-named-timezone.js @@ -0,0 +1,11 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.offsetnanoseconds +description: Basic functionality in named time zone +features: [Temporal] +---*/ + +var instance = new Temporal.ZonedDateTime(0n, "America/Los_Angeles"); +assert.sameValue(instance.offsetNanoseconds, -8 * 3600000000000) diff --git a/test/intl402/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/nanoseconds-subtracted-or-added-at-dst-transition.js b/test/intl402/Temporal/ZonedDateTime/prototype/offsetNanoseconds/nanoseconds-subtracted-or-added-at-dst-transition.js similarity index 74% rename from test/intl402/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/nanoseconds-subtracted-or-added-at-dst-transition.js rename to test/intl402/Temporal/ZonedDateTime/prototype/offsetNanoseconds/nanoseconds-subtracted-or-added-at-dst-transition.js index 268924e79e..762153d7b0 100644 --- a/test/intl402/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/nanoseconds-subtracted-or-added-at-dst-transition.js +++ b/test/intl402/Temporal/ZonedDateTime/prototype/offsetNanoseconds/nanoseconds-subtracted-or-added-at-dst-transition.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone.prototype.getoffsetnanosecondsfor +esid: sec-temporal.zoneddatetime.prototype.offsetnanoseconds description: > Test offset when nanoseconds are subtracted or added from DST transition. features: [Temporal, exponentiation] @@ -19,19 +19,18 @@ features: [Temporal, exponentiation] // -8:00 CA P%sT 1967 // -8:00 US P%sT -let tz = new Temporal.TimeZone("America/Los_Angeles"); -let p = Temporal.Instant.from("1965-04-25T09:00:00Z"); +let p = Temporal.Instant.from("1965-04-25T09:00:00Z").toZonedDateTimeISO("America/Los_Angeles"); const nsPerHour = 60 * 60 * 1000**3; -assert.sameValue(tz.getOffsetNanosecondsFor(p), +assert.sameValue(p.offsetNanoseconds, -7 * nsPerHour, "DST transition"); -assert.sameValue(tz.getOffsetNanosecondsFor(p.add({nanoseconds: +1})), +assert.sameValue(p.add({nanoseconds: +1}).offsetNanoseconds, -7 * nsPerHour, "DST transition plus one nanosecond"); -assert.sameValue(tz.getOffsetNanosecondsFor(p.add({nanoseconds: -1})), +assert.sameValue(p.add({nanoseconds: -1}).offsetNanoseconds, -8 * nsPerHour, "DST transition minus one nanosecond"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/time-zone-canonicalized.js b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/time-zone-canonicalized.js index b1cc8b53b6..095e7d7c97 100644 --- a/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/time-zone-canonicalized.js +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/time-zone-canonicalized.js @@ -7,18 +7,7 @@ description: Custom time zone names are canonicalized features: [Temporal] ---*/ -const timeZone1 = { - id: "Asia/Kolkata", - getPossibleInstantsFor() {}, - getOffsetNanosecondsFor() {}, -}; -const datetime1 = new Temporal.ZonedDateTime(0n, timeZone1); - -const timeZone2 = { - id: "Asia/Calcutta", - getPossibleInstantsFor() {}, - getOffsetNanosecondsFor() {}, -}; -const datetime2 = new Temporal.ZonedDateTime(0n, timeZone2); +const datetime1 = new Temporal.ZonedDateTime(0n, "Asia/Kolkata"); +const datetime2 = new Temporal.ZonedDateTime(0n, "Asia/Calcutta"); assert.sameValue(datetime1.toLocaleString(), datetime2.toLocaleString(), "Time zone names are canonicalized before passing to DateTimeFormat"); diff --git a/test/intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/basic.js b/test/intl402/Temporal/ZonedDateTime/prototype/toPlainDateTime/basic.js similarity index 93% rename from test/intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/basic.js rename to test/intl402/Temporal/ZonedDateTime/prototype/toPlainDateTime/basic.js index aaa7f82ddd..327bf393c0 100644 --- a/test/intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/basic.js +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toPlainDateTime/basic.js @@ -2,18 +2,17 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone.prototype.getplaindatetimefor +esid: sec-temporal.zoneddatetime.prototype.toplaindatetime description: Sample of results for IANA time zones includes: [temporalHelpers.js] features: [Temporal] ---*/ function test(epochNs, results) { - const instant = new Temporal.Instant(epochNs); Object.entries(results).forEach(([id, expected]) => { - const tz = new Temporal.TimeZone(id); - const dt = tz.getPlainDateTimeFor(instant); - TemporalHelpers.assertPlainDateTime(dt, ...expected, `Local time of ${instant} in ${id}`); + const instance = new Temporal.ZonedDateTime(epochNs, id); + const dt = instance.toPlainDateTime(); + TemporalHelpers.assertPlainDateTime(dt, ...expected, `Local time of ${instance.toInstant()} in ${id}`); }); } diff --git a/test/intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/dst.js b/test/intl402/Temporal/ZonedDateTime/prototype/toPlainDateTime/dst.js similarity index 79% rename from test/intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/dst.js rename to test/intl402/Temporal/ZonedDateTime/prototype/toPlainDateTime/dst.js index dea36e2dcd..ddb26275b0 100644 --- a/test/intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/dst.js +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toPlainDateTime/dst.js @@ -2,17 +2,16 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone.prototype.getplaindatetimefor +esid: sec-temporal.zoneddatetime.prototype.toplaindatetime description: Sample of results for IANA time zones around DST changes includes: [temporalHelpers.js] features: [Temporal] ---*/ function test(epochNs, id, expected) { - const instant = new Temporal.Instant(epochNs); - const tz = new Temporal.TimeZone(id); - const dt = tz.getPlainDateTimeFor(instant); - TemporalHelpers.assertPlainDateTime(dt, ...expected, `Local time of ${instant} in ${id}`); + const instance = new Temporal.ZonedDateTime(epochNs, id); + const dt = instance.toPlainDateTime(); + TemporalHelpers.assertPlainDateTime(dt, ...expected, `Local time of ${instance.toInstant()} in ${id}`); } // Just before DST forward shift diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-always.js b/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-always.js new file mode 100644 index 0000000000..45c4178b9b --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-always.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.tostring +description: If calendarName is "always", the calendar ID should be included. +features: [Temporal] +---*/ + +const tests = [ + [[], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=iso8601]", "built-in ISO"], + [["gregory"], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", ...args); + const result = date.toString({ calendarName: "always" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = always`); +} diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-auto.js b/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-auto.js new file mode 100644 index 0000000000..e55b0dad3c --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-auto.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.tostring +description: If calendarName is "auto", "iso8601" should be omitted. +features: [Temporal] +---*/ + +const tests = [ + [[], "1970-01-01T01:01:01.987654321+00:00[UTC]", "built-in ISO"], + [["gregory"], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", ...args); + const result = date.toString({ calendarName: "auto" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = auto`); +} diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-critical.js b/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-critical.js new file mode 100644 index 0000000000..928a940cd9 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-critical.js @@ -0,0 +1,21 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.tostring +description: > + If calendarName is "calendar", the calendar ID should be included and prefixed + with "!". +features: [Temporal] +---*/ + +const tests = [ + [[], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=iso8601]", "built-in ISO"], + [["gregory"], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", ...args); + const result = date.toString({ calendarName: "critical" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = critical`); +} diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-never.js b/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-never.js new file mode 100644 index 0000000000..abec820828 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-never.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.tostring +description: If calendarName is "never", the calendar ID should be omitted. +features: [Temporal] +---*/ + +const tests = [ + [[], "1970-01-01T01:01:01.987654321+00:00[UTC]", "built-in ISO"], + [["gregory"], "1970-01-01T01:01:01.987654321+00:00[UTC]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", ...args); + const result = date.toString({ calendarName: "never" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = never`); +} diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-undefined.js b/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-undefined.js new file mode 100644 index 0000000000..8b334d50b9 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-undefined.js @@ -0,0 +1,27 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.protoype.tostring +description: Fallback value for calendarName option +info: | + sec-getoption step 3: + 3. If _value_ is *undefined*, return _fallback_. + sec-temporal-toshowcalendaroption step 1: + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). + sec-temporal.zoneddatetime.protoype.tostring step 6: + 6. Let _showCalendar_ be ? ToShowCalendarOption(_options_). +features: [Temporal] +---*/ + +const tests = [ + [[], "1970-01-01T01:01:01.987654321+00:00[UTC]", "built-in ISO"], + [["gregory"], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=gregory]", "built-in Gregorian"], +]; + +for (const [args, expected, description] of tests) { + const datetime = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", ...args); + const result = datetime.toString({ calendarName: undefined }); + assert.sameValue(result, expected, `default calendarName option is auto with ${description} calendar`); + // See options-object.js for {} and options-undefined.js for absent options arg +} diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-wrong-type.js b/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-wrong-type.js new file mode 100644 index 0000000000..ec73c3c37b --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toString/calendarname-wrong-type.js @@ -0,0 +1,23 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.protoype.tostring +description: Type conversions for calendarName option +info: | + sec-getoption step 9.a: + a. Set _value_ to ? ToString(_value_). + sec-temporal-toshowcalendaroption step 1: + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). + sec-temporal.zoneddatetime.protoype.tostring step 6: + 6. Let _showCalendar_ be ? ToShowCalendarOption(_options_). +includes: [compareArray.js, temporalHelpers.js] +features: [Temporal] +---*/ + +const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC", "gregory"); + +TemporalHelpers.checkStringOptionWrongType("calendarName", "auto", + (calendarName) => datetime.toString({ calendarName }), + (result, descr) => assert.sameValue(result, "2001-09-09T01:46:40.987654321+00:00[UTC][u-ca=gregory]", descr), +); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/withCalendar/calendar-case-insensitive.js b/test/intl402/Temporal/ZonedDateTime/prototype/withCalendar/calendar-case-insensitive.js index dd8d0ee48a..1b90e38394 100644 --- a/test/intl402/Temporal/ZonedDateTime/prototype/withCalendar/calendar-case-insensitive.js +++ b/test/intl402/Temporal/ZonedDateTime/prototype/withCalendar/calendar-case-insensitive.js @@ -7,29 +7,7 @@ description: Calendar names are case-insensitive features: [Temporal] ---*/ -const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "replace-me", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}); +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); const arg = "jApAnEsE";; const result = instance.withCalendar(arg); diff --git a/test/intl402/Temporal/TimeZone/supported-values-of.js b/test/intl402/Temporal/ZonedDateTime/supported-values-of.js similarity index 57% rename from test/intl402/Temporal/TimeZone/supported-values-of.js rename to test/intl402/Temporal/ZonedDateTime/supported-values-of.js index bcc87b2f2d..3c827a13c1 100644 --- a/test/intl402/Temporal/TimeZone/supported-values-of.js +++ b/test/intl402/Temporal/ZonedDateTime/supported-values-of.js @@ -2,15 +2,16 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone +esid: sec-temporal.zoneddatetime description: > - TimeZone constructor accepts all time zone identifiers from Intl.supportedValuesOf. + ZonedDateTime constructor accepts all time zone identifiers from + Intl.supportedValuesOf. features: [Temporal, Intl-enumeration] ---*/ // Ensure all identifiers are valid and canonical. for (let id of Intl.supportedValuesOf("timeZone")) { - let tz = new Temporal.TimeZone(id); + let instance = new Temporal.ZonedDateTime(0n, id); - assert.sameValue(tz.id, id); + assert.sameValue(instance.timeZoneId, id); } diff --git a/test/intl402/Temporal/TimeZone/from/timezone-case-insensitive.js b/test/intl402/Temporal/ZonedDateTime/timezone-case-insensitive.js similarity index 95% rename from test/intl402/Temporal/TimeZone/from/timezone-case-insensitive.js rename to test/intl402/Temporal/ZonedDateTime/timezone-case-insensitive.js index 53369d8377..2b6578bdec 100644 --- a/test/intl402/Temporal/TimeZone/from/timezone-case-insensitive.js +++ b/test/intl402/Temporal/ZonedDateTime/timezone-case-insensitive.js @@ -2,11 +2,15 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone.from -description: Time zone identifiers are case-normalized +esid: sec-temporal.zoneddatetime +description: Time zone names are case-normalized features: [Temporal] ---*/ +const timeZone = 'eTc/gMt+1'; +const result = new Temporal.ZonedDateTime(0n, timeZone); +assert.sameValue(result.timeZoneId, 'Etc/GMT+1', `Time zone created from string "${timeZone}"`); + const timeZoneIdentifiers = [ // IANA TZDB Zone names 'Africa/Abidjan', @@ -619,7 +623,7 @@ const ids = [...new Set([...timeZoneIdentifiers, ...Intl.supportedValuesOf('time for (const id of ids) { const lower = id.toLowerCase(); const upper = id.toUpperCase(); - assert.sameValue(new Temporal.TimeZone(id).toString(), id, `Time zone created from string "${id}"`); - assert.sameValue(new Temporal.TimeZone(upper).toString(), id, `Time zone created from string "${upper}"`); - assert.sameValue(new Temporal.TimeZone(lower).toString(), id, `Time zone created from string "${lower}"`); + assert.sameValue(new Temporal.ZonedDateTime(0n, id).timeZoneId, id, `Time zone created from string "${id}"`); + assert.sameValue(new Temporal.ZonedDateTime(0n, upper).timeZoneId, id, `Time zone created from string "${upper}"`); + assert.sameValue(new Temporal.ZonedDateTime(0n, lower).timeZoneId, id, `Time zone created from string "${lower}"`); } diff --git a/test/intl402/Temporal/TimeZone/basic.js b/test/intl402/Temporal/ZonedDateTime/timezone-ids-basic.js similarity index 64% rename from test/intl402/Temporal/TimeZone/basic.js rename to test/intl402/Temporal/ZonedDateTime/timezone-ids-basic.js index 11552287a1..b461240f77 100644 --- a/test/intl402/Temporal/TimeZone/basic.js +++ b/test/intl402/Temporal/ZonedDateTime/timezone-ids-basic.js @@ -2,8 +2,8 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.timezone -description: Basic tests for the Temporal.TimeZone constructor. +esid: sec-temporal.zoneddatetime +description: Basic tests for time zone IDs features: [Temporal] ---*/ @@ -18,12 +18,12 @@ const valid = [ ["GMT"] ]; for (const [zone, id = zone] of valid) { - const result = new Temporal.TimeZone(zone); + const result = new Temporal.ZonedDateTime(0n, zone); assert.sameValue(typeof result, "object", `object should be created for ${zone}`); - assert.sameValue(result.id, id, `id for ${zone} should be ${id}`); + assert.sameValue(result.timeZoneId, id, `id for ${zone} should be ${id}`); } const invalid = ["+00:01.1", "-01.1"]; for (const zone of invalid) { - assert.throws(RangeError, () => new Temporal.TimeZone(zone), `should throw for ${zone}`); + assert.throws(RangeError, () => new Temporal.ZonedDateTime(0n, zone), `should throw for ${zone}`); } diff --git a/test/staging/Intl402/Temporal/old/timezone-america-la.js b/test/staging/Intl402/Temporal/old/timezone-america-la.js deleted file mode 100644 index 2dec9fba44..0000000000 --- a/test/staging/Intl402/Temporal/old/timezone-america-la.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2018 Bloomberg LP. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal-timezone-objects -description: America/Los_Angeles -features: [Temporal] ----*/ - -var zone = new Temporal.TimeZone("America/Los_Angeles"); -var inst = new Temporal.Instant(0n); -var dtm = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789); -assert.sameValue(zone.id, `${ zone }`) -assert.sameValue(zone.getOffsetNanosecondsFor(inst), -8 * 3600000000000) -assert.sameValue(zone.getOffsetStringFor(inst), "-08:00") -assert(zone.getInstantFor(dtm) instanceof Temporal.Instant) diff --git a/test/staging/Temporal/Instant/old/limits.js b/test/staging/Temporal/Instant/old/limits.js index 408bbce1ca..d7818426a0 100644 --- a/test/staging/Temporal/Instant/old/limits.js +++ b/test/staging/Temporal/Instant/old/limits.js @@ -21,10 +21,3 @@ assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(-limit - assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(limit + 1)); assert.sameValue(`${ Temporal.Instant.fromEpochMilliseconds(-limit) }`, "-271821-04-20T00:00:00Z"); assert.sameValue(`${ Temporal.Instant.fromEpochMilliseconds(limit) }`, "+275760-09-13T00:00:00Z"); - -// converting from DateTime -var min = Temporal.PlainDateTime.from("-271821-04-19T00:00:00.000000001"); -var max = Temporal.PlainDateTime.from("+275760-09-13T23:59:59.999999999"); -var utc = Temporal.TimeZone.from("UTC"); -assert.throws(RangeError, () => utc.getInstantFor(min)); -assert.throws(RangeError, () => utc.getInstantFor(max)); diff --git a/test/staging/Temporal/TimeZone/old/dst-change.js b/test/staging/Temporal/TimeZone/old/dst-change.js deleted file mode 100644 index ca56831768..0000000000 --- a/test/staging/Temporal/TimeZone/old/dst-change.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018 Bloomberg LP. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal-timezone-objects -description: with DST change -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -// clock moving forward -var zone = TemporalHelpers.springForwardFallBackTimeZone(); -var dtm = new Temporal.PlainDateTime(2000, 4, 2, 2, 45); -assert.sameValue(`${ zone.getInstantFor(dtm) }`, "2000-04-02T10:45:00Z"); -assert.sameValue(`${ zone.getInstantFor(dtm, { disambiguation: "earlier" }) }`, "2000-04-02T09:45:00Z"); -assert.sameValue(`${ zone.getInstantFor(dtm, { disambiguation: "later" }) }`, "2000-04-02T10:45:00Z"); -assert.sameValue(`${ zone.getInstantFor(dtm, { disambiguation: "compatible" }) }`, "2000-04-02T10:45:00Z"); -assert.throws(RangeError, () => zone.getInstantFor(dtm, { disambiguation: "reject" })); - -// clock moving backward -var dtm = new Temporal.PlainDateTime(2000, 10, 29, 1, 45); -assert.sameValue(`${ zone.getInstantFor(dtm) }`, "2000-10-29T08:45:00Z"); -assert.sameValue(`${ zone.getInstantFor(dtm, { disambiguation: "earlier" }) }`, "2000-10-29T08:45:00Z"); -assert.sameValue(`${ zone.getInstantFor(dtm, { disambiguation: "later" }) }`, "2000-10-29T09:45:00Z"); -assert.sameValue(`${ zone.getInstantFor(dtm, { disambiguation: "compatible" }) }`, "2000-10-29T08:45:00Z"); -assert.throws(RangeError, () => zone.getInstantFor(dtm, { disambiguation: "reject" })); diff --git a/test/staging/Temporal/TimeZone/old/getInstantFor.js b/test/staging/Temporal/TimeZone/old/getInstantFor.js deleted file mode 100644 index 4569e2213b..0000000000 --- a/test/staging/Temporal/TimeZone/old/getInstantFor.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2018 Bloomberg LP. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal-timezone-objects -description: Temporal.TimeZone.prototype.getInstantFor() works -features: [Temporal] ----*/ - - -// recent date -var dt = Temporal.PlainDateTime.from("2019-10-29T10:46:38.271986102"); -var tz = Temporal.TimeZone.from("+01:00"); -assert.sameValue(`${ tz.getInstantFor(dt) }`, "2019-10-29T09:46:38.271986102Z"); - -// year ≤ 99 -var dt = Temporal.PlainDateTime.from("0098-10-29T10:46:38.271986102"); -var tz = Temporal.TimeZone.from("+06:00"); -assert.sameValue(`${ tz.getInstantFor(dt) }`, "0098-10-29T04:46:38.271986102Z"); -dt = Temporal.PlainDateTime.from("+000098-10-29T10:46:38.271986102"); -assert.sameValue(`${ tz.getInstantFor(dt) }`, "0098-10-29T04:46:38.271986102Z"); - -// year < 1 -var dt = Temporal.PlainDateTime.from("0000-10-29T10:46:38.271986102"); -var tz = Temporal.TimeZone.from("+06:00"); -assert.sameValue(`${ tz.getInstantFor(dt) }`, "0000-10-29T04:46:38.271986102Z"); -dt = Temporal.PlainDateTime.from("+000000-10-29T10:46:38.271986102"); -assert.sameValue(`${ tz.getInstantFor(dt) }`, "0000-10-29T04:46:38.271986102Z"); -dt = Temporal.PlainDateTime.from("-001000-10-29T10:46:38.271986102"); -assert.sameValue(`${ tz.getInstantFor(dt) }`, "-001000-10-29T04:46:38.271986102Z"); - -// year 0 leap day -var dt = Temporal.PlainDateTime.from("0000-02-29T00:00"); -var tz = Temporal.TimeZone.from("-00:01"); -assert.sameValue(`${ tz.getInstantFor(dt) }`, "0000-02-29T00:01:00Z"); -dt = Temporal.PlainDateTime.from("+000000-02-29T00:00"); -assert.sameValue(`${ tz.getInstantFor(dt) }`, "0000-02-29T00:01:00Z"); - -// outside of Instant range -var max = Temporal.PlainDateTime.from("+275760-09-13T23:59:59.999999999"); -var offsetTz = Temporal.TimeZone.from("-01:00"); -assert.throws(RangeError, () => offsetTz.getInstantFor(max)); -var namedTz = Temporal.TimeZone.from("Etc/GMT+12"); -assert.throws(RangeError, () => namedTz.getInstantFor(max)); - -// casts argument -var tz = Temporal.TimeZone.from("+01:00"); -assert.sameValue(`${ tz.getInstantFor("2019-10-29T10:46:38.271986102") }`, "2019-10-29T09:46:38.271986102Z"); -assert.sameValue(`${ tz.getInstantFor({ - year: 2019, - month: 10, - day: 29, - hour: 10, - minute: 46, - second: 38 -}) }`, "2019-10-29T09:46:38Z"); - - diff --git a/test/staging/Temporal/TimeZone/old/getPossibleInstantsFor.js b/test/staging/Temporal/TimeZone/old/getPossibleInstantsFor.js deleted file mode 100644 index f42050bd8c..0000000000 --- a/test/staging/Temporal/TimeZone/old/getPossibleInstantsFor.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2018 Bloomberg LP. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal-timezone-objects -description: Temporal.TimeZone.prototype.getPossibleInstantsFor() works as expected -includes: [deepEqual.js, temporalHelpers.js] -features: [Temporal] ----*/ - - -// with constant offset -var zone = Temporal.TimeZone.from("+03:30"); -var dt = Temporal.PlainDateTime.from("2019-02-16T23:45"); -assert.deepEqual(zone.getPossibleInstantsFor(dt).map(a => `${ a }`), ["2019-02-16T20:15:00Z"]); - -// with clock moving forward -var zone = TemporalHelpers.springForwardFallBackTimeZone(); -var dt = Temporal.PlainDateTime.from("2000-04-02T02:45"); -assert.deepEqual(zone.getPossibleInstantsFor(dt), []); - -// with clock moving backward -var dt = Temporal.PlainDateTime.from("2000-10-29T01:45"); -assert.deepEqual(zone.getPossibleInstantsFor(dt).map(a => `${ a }`), [ - "2000-10-29T08:45:00Z", - "2000-10-29T09:45:00Z" -]); - -// casts argument -var tz = Temporal.TimeZone.from("+03:30"); -assert.deepEqual(tz.getPossibleInstantsFor({ - year: 2019, - month: 2, - day: 16, - hour: 23, - minute: 45, - second: 30 -}).map(a => `${ a }`), ["2019-02-16T20:15:30Z"]); -assert.deepEqual(tz.getPossibleInstantsFor("2019-02-16T23:45:30").map(a => `${ a }`), ["2019-02-16T20:15:30Z"]); - -// object must contain at least the required properties -var tz = Temporal.TimeZone.from("UTC"); -assert.throws(TypeError, () => tz.getPossibleInstantsFor({ year: 2019 })); diff --git a/test/staging/Temporal/ZonedDateTime/old/compare.js b/test/staging/Temporal/ZonedDateTime/old/compare.js index 05678af3d0..0d7964d844 100644 --- a/test/staging/Temporal/ZonedDateTime/old/compare.js +++ b/test/staging/Temporal/ZonedDateTime/old/compare.js @@ -111,30 +111,7 @@ assert.throws(TypeError, () => Temporal.ZonedDateTime.compare(zdt1, { assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt1.withTimeZone("+05:30")), 0); // disregards calendar IDs if exact times and time zones are equal -var fakeJapanese = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "japanese", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt1.withCalendar(fakeJapanese)), 0); +assert.sameValue(Temporal.ZonedDateTime.compare(zdt1, zdt1.withCalendar("japanese")), 0); // compares exact time, not clock time var clockBefore = Temporal.ZonedDateTime.from("1999-12-31T23:30-08:00[-08:00]"); diff --git a/test/staging/Temporal/ZonedDateTime/old/construction-and-properties.js b/test/staging/Temporal/ZonedDateTime/old/construction-and-properties.js index d4a071a29f..4519338df6 100644 --- a/test/staging/Temporal/ZonedDateTime/old/construction-and-properties.js +++ b/test/staging/Temporal/ZonedDateTime/old/construction-and-properties.js @@ -48,36 +48,7 @@ assert.sameValue(`${ zdt }`, "1976-11-18T15:23:30.123456789+00:00[UTC]"); // Temporal.ZonedDateTime with non-UTC time zone and non-ISO calendar // can be constructed -var fakeGregorian = { - era() { return "ce"; }, - year(date) { return date.withCalendar("iso8601").year; }, - month(date) { return date.withCalendar("iso8601").month; }, - monthCode(date) { return date.withCalendar("iso8601").monthCode; }, - day(date) { return date.withCalendar("iso8601").day; }, - dayOfWeek(date) { return date.withCalendar("iso8601").dayOfWeek; }, - dayOfYear(date) { return date.withCalendar("iso8601").dayOfYear; }, - weekOfYear(date) { return date.withCalendar("iso8601").weekOfYear; }, - daysInWeek(date) { return date.withCalendar("iso8601").daysInWeek; }, - daysInMonth(date) { return date.withCalendar("iso8601").daysInMonth; }, - daysInYear(date) { return date.withCalendar("iso8601").daysInYear; }, - monthsInYear(date) { return date.withCalendar("iso8601").monthsInYear; }, - inLeapYear(date) { return date.withCalendar("iso8601").inLeapYear; }, - id: "gregory", - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - fields() {}, - mergeFields() {}, - monthDayFromFields() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -var fakeVienna = { - getOffsetNanosecondsFor() { return 3600_000_000_000; }, - getPossibleInstantsFor(datetime) { return [datetime.toZonedDateTime("+01:00").toInstant()]; }, - id: "Europe/Vienna", -} -var zdt = new Temporal.ZonedDateTime(epochNanos, fakeVienna, fakeGregorian); +var zdt = new Temporal.ZonedDateTime(epochNanos, "Europe/Vienna", "gregory"); assert(zdt instanceof Temporal.ZonedDateTime); assert.sameValue(typeof zdt, "object"); diff --git a/test/staging/Temporal/ZonedDateTime/old/equals.js b/test/staging/Temporal/ZonedDateTime/old/equals.js index b2623050ee..1a4a2e7816 100644 --- a/test/staging/Temporal/ZonedDateTime/old/equals.js +++ b/test/staging/Temporal/ZonedDateTime/old/equals.js @@ -7,35 +7,7 @@ description: Temporal.ZonedDateTime.prototype.equals() features: [Temporal] ---*/ -var tz = { - getOffsetNanosecondsFor() { return -5 * 3600_000_000_000; }, - getPossibleInstantsFor(pdt) { return Temporal.TimeZone.from("-05:00").getPossibleInstantsFor(pdt); }, - id: "America/New_York", -}; -var cal = { - dateFromFields(...args) { return Temporal.Calendar.from("iso8601").dateFromFields(...args); }, - id: "gregory", - dateAdd() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields(fieldNames) { return fieldNames; }, - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -var zdt = new Temporal.ZonedDateTime(0n, tz, cal); +var zdt = new Temporal.ZonedDateTime(0n, "-05:00", "iso8601"); // constructed from equivalent parameters are equal var zdt2 = Temporal.ZonedDateTime.from({ @@ -43,22 +15,22 @@ var zdt2 = Temporal.ZonedDateTime.from({ month: 12, day: 31, hour: 19, - timeZone: tz, - calendar: cal, + timeZone: "-05:00", + calendar: "iso8601", }); assert(zdt.equals(zdt2)); assert(zdt2.equals(zdt)); // different instant not equal -var zdt2 = new Temporal.ZonedDateTime(1n, tz, cal); +var zdt2 = new Temporal.ZonedDateTime(1n, "-05:00", "iso8601"); assert(!zdt.equals(zdt2)); // different time zone not equal -var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", cal); +var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", "iso8601"); assert(!zdt.equals(zdt2)); // different calendar not equal -var zdt2 = new Temporal.ZonedDateTime(0n, tz, "iso8601"); +var zdt2 = new Temporal.ZonedDateTime(0n, "-05:00", "gregory"); assert(!zdt.equals(zdt2)); // casts its argument @@ -77,22 +49,22 @@ assert(!zdt.equals({ year: 1969, month: 12, day: 31, - timeZone: tz + timeZone: "-05:00" })); assert.throws(TypeError, () => zdt.equals({ month: 12, day: 31, - timeZone: tz + timeZone: "-05:00" })); assert.throws(TypeError, () => zdt.equals({ year: 1969, day: 31, - timeZone: tz + timeZone: "-05:00" })); assert.throws(TypeError, () => zdt.equals({ year: 1969, month: 12, - timeZone: tz + timeZone: "-05:00" })); assert.throws(TypeError, () => zdt.equals({ year: 1969, @@ -103,6 +75,6 @@ assert.throws(TypeError, () => zdt.equals({ years: 1969, months: 12, days: 31, - timeZone: tz, - calendarName: "gregory" + timeZone: "-05:00", + calendarName: "iso8601" })); diff --git a/test/staging/Temporal/ZonedDateTime/old/since.js b/test/staging/Temporal/ZonedDateTime/old/since.js index 627defe613..324b09cc06 100644 --- a/test/staging/Temporal/ZonedDateTime/old/since.js +++ b/test/staging/Temporal/ZonedDateTime/old/since.js @@ -87,30 +87,7 @@ assert.notSameValue(monthsDifference.months, 0); // no two different calendars var zdt1 = new Temporal.ZonedDateTime(0n, "UTC"); -var fakeJapanese = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "japanese", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", fakeJapanese); +var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", "japanese"); assert.throws(RangeError, () => zdt1.since(zdt2)); var earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[+01:00]'); diff --git a/test/staging/Temporal/ZonedDateTime/old/toPlainDate.js b/test/staging/Temporal/ZonedDateTime/old/toPlainDate.js index 2957dfb73e..eca34dd442 100644 --- a/test/staging/Temporal/ZonedDateTime/old/toPlainDate.js +++ b/test/staging/Temporal/ZonedDateTime/old/toPlainDate.js @@ -12,28 +12,5 @@ var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTim assert.sameValue(`${ zdt.toPlainDate() }`, "2019-10-29"); // preserves the calendar -const fakeGregorian = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "gregory", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTimeISO(tz).withCalendar(fakeGregorian); -assert.sameValue(zdt.toPlainDate().getISOFields().calendar, fakeGregorian); +var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTimeISO("-07:00").withCalendar("gregory"); +assert.sameValue(zdt.toPlainDate().getISOFields().calendar, "gregory"); diff --git a/test/staging/Temporal/ZonedDateTime/old/toString.js b/test/staging/Temporal/ZonedDateTime/old/toString.js index 2faf125ea1..80637072a9 100644 --- a/test/staging/Temporal/ZonedDateTime/old/toString.js +++ b/test/staging/Temporal/ZonedDateTime/old/toString.js @@ -4,34 +4,10 @@ /*--- esid: sec-temporal-zoneddatetime-objects description: Temporal.ZonedDateTime.prototype.toString() -includes: [temporalHelpers.js] features: [Temporal] ---*/ var zdt1 = Temporal.ZonedDateTime.from("1976-11-18T15:23+00:00[UTC]"); -var fakeGregorian = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "gregory", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; // shows offset if offset = auto assert.sameValue(zdt1.toString({ offset: "auto" }), "1976-11-18T15:23:00+00:00[UTC]"); diff --git a/test/staging/Temporal/ZonedDateTime/old/until.js b/test/staging/Temporal/ZonedDateTime/old/until.js index 67280f879a..0f6a017f7c 100644 --- a/test/staging/Temporal/ZonedDateTime/old/until.js +++ b/test/staging/Temporal/ZonedDateTime/old/until.js @@ -87,30 +87,7 @@ assert.notSameValue(monthsDifference.months, 0); // no two different calendars var zdt1 = new Temporal.ZonedDateTime(0n, "UTC"); -var fakeJapanese = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "japanese", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", fakeJapanese); +var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", "japanese"); assert.throws(RangeError, () => zdt1.until(zdt2)); var earlier = Temporal.ZonedDateTime.from('2019-01-08T09:22:36.123456789+01:00[+01:00]'); diff --git a/test/staging/Temporal/ZonedDateTime/old/withCalendar.js b/test/staging/Temporal/ZonedDateTime/old/withCalendar.js index e97d4968e1..d6f0d4c382 100644 --- a/test/staging/Temporal/ZonedDateTime/old/withCalendar.js +++ b/test/staging/Temporal/ZonedDateTime/old/withCalendar.js @@ -10,34 +10,11 @@ features: [Temporal] var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789-08:00[-08:00]"); // zonedDateTime.withCalendar(japanese) works -var cal = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "japanese", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -assert.sameValue(`${ zdt.withCalendar(cal) }`, "2019-11-18T15:23:30.123456789-08:00[-08:00][u-ca=japanese]"); +assert.sameValue(`${ zdt.withCalendar("japanese") }`, "2019-11-18T15:23:30.123456789-08:00[-08:00][u-ca=japanese]"); // keeps instant and time zone the same var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789+01:00[+01:00][u-ca=iso8601]"); -var zdt2 = zdt.withCalendar(cal); +var zdt2 = zdt.withCalendar("japanese"); assert.sameValue(zdt.epochNanoseconds, zdt2.epochNanoseconds); -assert.sameValue(zdt2.getISOFields().calendar, cal); +assert.sameValue(zdt2.getISOFields().calendar, "japanese"); assert.sameValue(zdt2.timeZoneId, "+01:00"); diff --git a/test/staging/Temporal/ZonedDateTime/old/withTimezone.js b/test/staging/Temporal/ZonedDateTime/old/withTimezone.js index 3f635bb64c..2d7cf02aa5 100644 --- a/test/staging/Temporal/ZonedDateTime/old/withTimezone.js +++ b/test/staging/Temporal/ZonedDateTime/old/withTimezone.js @@ -8,32 +8,9 @@ features: [Temporal] ---*/ // keeps instant and calendar the same -var fakeGregorian = { - dateAdd() {}, - dateFromFields() {}, - dateUntil() {}, - day() {}, - dayOfWeek() {}, - dayOfYear() {}, - daysInMonth() {}, - daysInWeek() {}, - daysInYear() {}, - fields() {}, - id: "gregory", - inLeapYear() {}, - mergeFields() {}, - month() {}, - monthCode() {}, - monthDayFromFields() {}, - monthsInYear() {}, - weekOfYear() {}, - year() {}, - yearMonthFromFields() {}, - yearOfWeek() {}, -}; -var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789+01:00[+01:00]").withCalendar(fakeGregorian); +var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789+01:00[+01:00]").withCalendar("gregory"); var zdt2 = zdt.withTimeZone("-08:00"); assert.sameValue(zdt.epochNanoseconds, zdt2.epochNanoseconds); -assert.sameValue(zdt2.getISOFields().calendar, fakeGregorian); +assert.sameValue(zdt2.getISOFields().calendar, "gregory"); assert.sameValue(zdt2.timeZoneId, "-08:00"); assert.notSameValue(`${ zdt.toPlainDateTime() }`, `${ zdt2.toPlainDateTime() }`);