Temporal: Test adjustments for removing calendar and time zone objects

This commit is contained in:
Philip Chimento 2024-06-04 13:17:54 +02:00 committed by Ms2ger
parent 5cd7e9077d
commit 9671c4a613
335 changed files with 2443 additions and 9425 deletions

View File

@ -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

View File

@ -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");

View File

@ -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");

View File

@ -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');

View File

@ -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');

View File

@ -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'
);
});

View File

@ -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");

View File

@ -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'
);
});

View File

@ -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');

View File

@ -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');

View File

@ -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");

View File

@ -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");
});

View File

@ -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");
});

View File

@ -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');
});

View File

@ -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');

View File

@ -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'
);
});

View File

@ -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}`);
});

View File

@ -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");

View File

@ -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");

View File

@ -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`);
});

View File

@ -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`);
});

View File

@ -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`);
});

View File

@ -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}`);
});

View File

@ -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");

View File

@ -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`);
});

View File

@ -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");

View File

@ -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`
);
});

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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",
];

View File

@ -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 = [];

View File

@ -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",
];

View File

@ -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);

View File

@ -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");

View File

@ -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(

View File

@ -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");

View File

@ -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));

View File

@ -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 = [];

View File

@ -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);

View File

@ -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 = [];

View File

@ -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"}));

View File

@ -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");

View File

@ -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");

View File

@ -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.");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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);

View File

@ -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));

View File

@ -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");

View File

@ -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

View File

@ -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`);

View File

@ -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`);

View File

@ -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`);

View File

@ -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`);

View File

@ -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

View File

@ -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),
);

View File

@ -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");

View File

@ -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",

View File

@ -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

View File

@ -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);

View File

@ -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));

View File

@ -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");
});

View File

@ -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");
});

View File

@ -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");
});

View File

@ -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");
});

View File

@ -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");

View File

@ -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");

View File

@ -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")
});

View File

@ -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 = [];

View File

@ -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);

View File

@ -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",

View File

@ -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,

View File

@ -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);

View File

@ -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";

View File

@ -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");

View File

@ -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"],

View File

@ -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");
},
);

View File

@ -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,
"="

View File

@ -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");

View File

@ -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 = [];

View File

@ -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 = [];

View File

@ -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

View File

@ -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");

View File

@ -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,

Some files were not shown because too many files have changed in this diff Show More