Temporal: Remove tests directly relating to custom calendar and time zones

These are tests that just won't apply anymore without custom calendars and
time zones.
This commit is contained in:
Philip Chimento 2024-05-15 18:19:52 -07:00 committed by Ms2ger
parent 6595838b3d
commit ea2268aa43
2251 changed files with 0 additions and 60665 deletions

View File

@ -1,30 +0,0 @@
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar
description: RangeError thrown when constructor invoked with the wrong type
features: [Temporal]
---*/
const tests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[19761118, "number that would convert to a valid ISO string in other contexts"],
[1n, "bigint"],
[Symbol(), "symbol"],
[{}, "object not implementing any protocol"],
[new Temporal.Calendar("iso8601"), "calendar instance"],
[new Temporal.TimeZone("UTC"), "time zone instance"],
[Temporal.ZonedDateTime.from("2020-01-01T00:00Z[UTC]"), "ZonedDateTime instance"],
];
for (const [arg, description] of tests) {
assert.throws(
typeof (arg) === "string" ? RangeError : TypeError,
() => new Temporal.Calendar(arg),
`${description} is not accepted by this constructor`
);
}

View File

@ -1,27 +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
description: Tests that Temporal.Calendar meets the requirements for built-in objects
info: |
Unless specified otherwise, a built-in object that is callable as a function is a built-in
function object with the characteristics described in 10.3. Unless specified otherwise, the
[[Extensible]] internal slot of a built-in object initially has the value true.
Unless otherwise specified every built-in function and every built-in constructor has the
Function prototype object [...] as the value of its [[Prototype]] internal slot.
features: [Temporal]
---*/
assert.sameValue(Object.isExtensible(Temporal.Calendar),
true, "Built-in objects must be extensible.");
assert.sameValue(Object.prototype.toString.call(Temporal.Calendar),
"[object Function]", "Object.prototype.toString");
assert.sameValue(Object.getPrototypeOf(Temporal.Calendar),
Function.prototype, "prototype");
assert.sameValue(typeof Temporal.Calendar.prototype,
"object", "prototype property");

View File

@ -1,12 +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
description: Temporal.Calendar constructor cannot be called as a function
info: |
1. If NewTarget is undefined, throw a TypeError exception.
features: [Temporal]
---*/
assert.throws(TypeError, () => Temporal.Calendar("iso8601"));

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.calendar.from
description: Tests that Temporal.Calendar.from meets the requirements for built-in objects
info: |
Built-in functions that are not constructors do not have a "prototype" property unless
otherwise specified in the description of a particular function.
Unless specified otherwise, a built-in object that is callable as a function is a built-in
function object with the characteristics described in 10.3. Unless specified otherwise, the
[[Extensible]] internal slot of a built-in object initially has the value true.
Unless otherwise specified every built-in function and every built-in constructor has the
Function prototype object [...] as the value of its [[Prototype]] internal slot.
features: [Temporal]
---*/
assert.sameValue(Object.isExtensible(Temporal.Calendar.from),
true, "Built-in objects must be extensible.");
assert.sameValue(Object.prototype.toString.call(Temporal.Calendar.from),
"[object Function]", "Object.prototype.toString");
assert.sameValue(Object.getPrototypeOf(Temporal.Calendar.from),
Function.prototype, "prototype");
assert.sameValue(Temporal.Calendar.from.hasOwnProperty("prototype"),
false, "prototype property");

View File

@ -1,13 +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.from
description: Calendar names are case-insensitive
features: [Temporal]
---*/
const arg = "iSo8601";
const result = Temporal.Calendar.from(arg);
assert.sameValue(result.id, "iso8601", "Calendar is case-insensitive");

View File

@ -1,22 +0,0 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.from
description: An ISO 8601 string can be converted to a calendar ID in Calendar
features: [Temporal]
---*/
for (const arg of [
"2020-01-01",
"2020-01-01[u-ca=iso8601]",
"2020-01-01T00:00:00.000000000",
"2020-01-01T00:00:00.000000000[u-ca=iso8601]",
"01-01",
"01-01[u-ca=iso8601]",
"2020-01",
"2020-01[u-ca=iso8601]",
]) {
const result = Temporal.Calendar.from(arg);
assert.sameValue(result.id, "iso8601", `Calendar created from string "${arg}"`);
}

View File

@ -1,23 +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.from
description: A number is not allowed to be a calendar
features: [Temporal]
---*/
const numbers = [
1,
-19761118,
19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.Calendar.from(arg),
"A number is not a valid ISO string for Calendar"
);
}

View File

@ -1,35 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.from
description: >
Converting an object implementing the Calendar protocol to Temporal.Calendar
gives the same object
features: [Temporal]
---*/
const custom = {
dateAdd() {},
dateFromFields() {},
dateUntil() {},
day() {},
dayOfWeek() {},
dayOfYear() {},
daysInMonth() {},
daysInWeek() {},
daysInYear() {},
fields() {},
id: "custom-calendar",
inLeapYear() {},
mergeFields() {},
month() {},
monthCode() {},
monthDayFromFields() {},
monthsInYear() {},
weekOfYear() {},
year() {},
yearMonthFromFields() {},
yearOfWeek() {},
};
assert.sameValue(Temporal.Calendar.from(custom), custom);

View File

@ -1,19 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.from
description: Calendar.from should support iso8601.
features: [Temporal]
---*/
const tests = [
"iso8601",
"1994-11-05T08:15:30-05:00",
];
for (const item of tests) {
const calendar = Temporal.Calendar.from(item);
assert(calendar instanceof Temporal.Calendar);
assert.sameValue(calendar.id, "iso8601");
}

View File

@ -1,16 +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.from
description: Leap second is a valid ISO string for Calendar
features: [Temporal]
---*/
const arg = "2016-12-31T23:59:60";
const result = Temporal.Calendar.from(arg);
assert.sameValue(
result.id,
"iso8601",
"leap second is a valid ISO string for Calendar"
);

View File

@ -1,19 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.from
description: from() throws if the argument is not a built-in calendar name.
features: [Temporal]
---*/
const tests = [
"local",
"iso-8601",
"[u-ca=iso8601]",
"invalid-calendar",
];
for (const item of tests) {
assert.throws(RangeError, () => Temporal.Calendar.from(item));
}

View File

@ -1,13 +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.from
description: A calendar ID is valid input for Calendar
features: [Temporal]
---*/
const arg = "iso8601";
const result = Temporal.Calendar.from(arg);
assert.sameValue(result.id, "iso8601", `Calendar created from string "${arg}"`);

View File

@ -1,38 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.from
description: Fast path for converting other Temporal objects to Temporal.Calendar 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
i. Return _temporalCalendarLike_.[[Calendar]].
includes: [compareArray.js]
features: [Temporal]
---*/
const plainDate = new Temporal.PlainDate(2000, 5, 2);
const plainDateTime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
const plainMonthDay = new Temporal.PlainMonthDay(5, 2);
const plainYearMonth = new Temporal.PlainYearMonth(2000, 5);
const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
[plainDate, plainDateTime, plainMonthDay, plainYearMonth, zonedDateTime].forEach((arg) => {
const actual = [];
const expected = [];
const calendar = arg.getISOFields().calendar;
Object.defineProperty(arg, "calendar", {
get() {
actual.push("get calendar");
return calendar;
},
});
const result = Temporal.Calendar.from(arg);
assert.sameValue(result.id, calendar, "Temporal object coerced to calendar");
assert.compareArray(actual, expected, "calendar getter not called");
});

View File

@ -1,37 +0,0 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.from
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or object for Calendar
features: [BigInt, Symbol, Temporal]
---*/
const primitiveTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [arg, description] of primitiveTests) {
assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => Temporal.Calendar.from(arg),
`${description} does not convert to a valid ISO string`
);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object that doesn't implement the protocol"],
[new Temporal.TimeZone("UTC"), "time zone instance"],
[Temporal.Calendar, "Temporal.Calendar, object"],
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => Temporal.Calendar.from(arg), `${description} is not a valid object and does not convert to a string`);
}

View File

@ -1,25 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.from
description: Temporal.Calendar.from.length is 1
info: |
Every built-in function object, including constructors, has a "length" property whose value is
an integer. Unless otherwise specified, this value is equal to the largest number of named
arguments shown in the subclause headings for the function description. Optional parameters
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
«...name») are not included in the default argument count.
Unless otherwise specified, the "length" property of a built-in function object has the
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/
verifyProperty(Temporal.Calendar.from, "length", {
value: 1,
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -1,23 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.from
description: Temporal.Calendar.from.name is "from"
info: |
Every built-in function object, including constructors, that is not identified as an anonymous
function has a "name" property whose value is a String. Unless otherwise specified, this value
is the name that is given to the function in this specification.
Unless otherwise specified, the "name" property of a built-in function object, if it exists,
has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/
verifyProperty(Temporal.Calendar.from, "name", {
value: "from",
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -1,20 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.from
description: Temporal.Calendar.from does not implement [[Construct]], is not new-able
info: |
Built-in function objects that are not identified as constructors do not implement the
[[Construct]] internal method unless otherwise specified in the description of a particular
function.
includes: [isConstructor.js]
features: [Reflect.construct, Temporal]
---*/
assert.throws(TypeError, () => {
new Temporal.Calendar.from();
}, "Calling as constructor");
assert.sameValue(isConstructor(Temporal.Calendar.from), false,
"isConstructor(Temporal.Calendar.from)");

View File

@ -1,21 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.from
description: The "from" property of Temporal.Calendar
includes: [propertyHelper.js]
features: [Temporal]
---*/
assert.sameValue(
typeof Temporal.Calendar.from,
"function",
"`typeof Calendar.from` is `function`"
);
verifyProperty(Temporal.Calendar, "from", {
writable: true,
enumerable: false,
configurable: true,
});

View File

@ -1,19 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.from
description: The receiver is never called when calling from()
includes: [temporalHelpers.js]
features: [Temporal]
---*/
TemporalHelpers.checkSubclassingIgnoredStatic(
Temporal.Calendar,
"from",
["iso8601"],
(result) => {
assert.sameValue(result.id, "iso8601", "id property of result");
assert.sameValue(result.toString(), "iso8601", "toString() of result");
},
);

View File

@ -1,25 +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
description: Temporal.Calendar.length is 1
info: |
Every built-in function object, including constructors, has a "length" property whose value is
an integer. Unless otherwise specified, this value is equal to the largest number of named
arguments shown in the subclause headings for the function description. Optional parameters
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
«...name») are not included in the default argument count.
Unless otherwise specified, the "length" property of a built-in function object has the
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/
verifyProperty(Temporal.Calendar, "length", {
value: 1,
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -1,11 +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
description: RangeError thrown when constructor invoked with no argument
features: [Temporal]
---*/
assert.throws(TypeError, () => new Temporal.Calendar());
assert.throws(TypeError, () => new Temporal.Calendar(undefined));

View File

@ -1,23 +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
description: Temporal.Calendar.name is "Calendar"
info: |
Every built-in function object, including constructors, that is not identified as an anonymous
function has a "name" property whose value is a String. Unless otherwise specified, this value
is the name that is given to the function in this specification.
Unless otherwise specified, the "name" property of a built-in function object, if it exists,
has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/
verifyProperty(Temporal.Calendar, "name", {
value: "Calendar",
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -1,21 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar
description: The "Calendar" property of Temporal
includes: [propertyHelper.js]
features: [Temporal]
---*/
assert.sameValue(
typeof Temporal.Calendar,
"function",
"`typeof Calendar` is `function`"
);
verifyProperty(Temporal, "Calendar", {
writable: true,
enumerable: false,
configurable: true,
});

View File

@ -1,17 +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.constructor
description: Test for Temporal.Calendar.prototype.constructor.
info: The initial value of Temporal.Calendar.prototype.constructor is %Temporal.Calendar%.
includes: [propertyHelper.js]
features: [Temporal]
---*/
verifyProperty(Temporal.Calendar.prototype, "constructor", {
value: Temporal.Calendar,
writable: true,
enumerable: false,
configurable: true,
});

View File

@ -1,21 +0,0 @@
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/
const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}
const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.dateAdd(arg, new Temporal.Duration());
Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;

View File

@ -1,16 +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.dateadd
description: >
Calendar.dateFromFields method is called with a null-prototype fields object
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = TemporalHelpers.calendarCheckFieldsPrototypePollution();
const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar };
instance.dateAdd(arg, new Temporal.Duration());
assert.sameValue(calendar.dateFromFieldsCallCount, 1, "dateFromFields should be called on the property bag's calendar");

View File

@ -1,14 +0,0 @@
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: If a calendar's fields() method returns a field named 'constructor', PrepareTemporalFields should throw a RangeError.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = TemporalHelpers.calendarWithExtraFields(['constructor']);
const arg = {year: 2023, month: 5, monthCode: 'M05', day: 1, calendar: calendar};
const instance = new Temporal.Calendar("iso8601");
assert.throws(RangeError, () => instance.dateAdd(arg, new Temporal.Duration()));

View File

@ -1,16 +0,0 @@
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: If a calendar's fields() method returns duplicate field names, PrepareTemporalFields should throw a RangeError.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
for (const extra_fields of [['foo', 'foo'], ['day'], ['month'], ['monthCode'], ['year']]) {
const calendar = TemporalHelpers.calendarWithExtraFields(extra_fields);
const arg = { year: 2023, month: 5, monthCode: 'M05', day: 1, calendar: calendar };
const instance = new Temporal.Calendar("iso8601");
assert.throws(RangeError, () => instance.dateAdd(arg, new Temporal.Duration()));
}

View File

@ -1,55 +0,0 @@
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: Maximum allowed duration
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const maxCases = [
["P273790Y8M12DT23H59M59.999999999S", "string with max years"],
[{ years: 273790, months: 8, days: 12, nanoseconds: 86399999999999 }, "property bag with max years"],
["P3285488M12DT23H59M59.999999999S", "string with max months"],
[{ months: 3285488, days: 12, nanoseconds: 86399999999999 }, "property bag with max months"],
["P14285714W2DT23H59M59.999999999S", "string with max weeks"],
[{ weeks: 14285714, days: 2, nanoseconds: 86399999999999 }, "property bag with max weeks"],
["P100000000DT23H59M59.999999999S", "string with max days"],
[{ days: 100000000, nanoseconds: 86399999999999 }, "property bag with max days"],
["PT2400000023H59M59.999999999S", "string with max hours"],
[{ hours: 2400000023, nanoseconds: 3599999999999 }, "property bag with max hours"],
["PT144000001439M59.999999999S", "string with max minutes"],
[{ minutes: 144000001439, nanoseconds: 59999999999 }, "property bag with max minutes"],
["PT8640000086399.999999999S", "string with max seconds"],
[{ seconds: 8640000086399, nanoseconds: 999999999 }, "property bag with max seconds"],
];
for (const [arg, descr] of maxCases) {
const result = instance.dateAdd(new Temporal.PlainDate(1970, 1, 1), arg);
TemporalHelpers.assertPlainDate(result, 275760, 9, "M09", 13, `operation succeeds with ${descr}`);
}
const minCases = [
["-P273790Y8M12DT23H59M59.999999999S", "string with min years"],
[{ years: -273790, months: -8, days: -12, nanoseconds: -86399999999999 }, "property bag with min years"],
["-P3285488M12DT23H59M59.999999999S", "string with min months"],
[{ months: -3285488, days: -12, nanoseconds: -86399999999999 }, "property bag with min months"],
["-P14285714W3DT23H59M59.999999999S", "string with min weeks"],
[{ weeks: -14285714, days: -3, nanoseconds: -86399999999999 }, "property bag with min weeks"],
["-P100000001DT23H59M59.999999999S", "string with min days"],
[{ days: -100000001, nanoseconds: -86399999999999 }, "property bag with min days"],
["-PT2400000047H59M59.999999999S", "string with min hours"],
[{ hours: -2400000047, nanoseconds: -3599999999999 }, "property bag with min hours"],
["-PT144000002879M59.999999999S", "string with min minutes"],
[{ minutes: -144000002879, nanoseconds: -59999999999 }, "property bag with min minutes"],
["-PT8640000172799.999999999S", "string with min seconds"],
[{ seconds: -8640000172799, nanoseconds: -999999999 }, "property bag with min seconds"],
];
for (const [arg, descr] of minCases) {
const result = instance.dateAdd(new Temporal.PlainDate(1970, 1, 1), arg);
TemporalHelpers.assertPlainDate(result, -271821, 4, "M04", 19, `operation succeeds with ${descr}`);
}

View File

@ -1,72 +0,0 @@
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: Duration-like argument that is out of range
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const cases = [
// 2^32 = 4294967296
["P4294967296Y", "string with years > max"],
[{ years: 4294967296 }, "property bag with years > max"],
["-P4294967296Y", "string with years < min"],
[{ years: -4294967296 }, "property bag with years < min"],
["P4294967296M", "string with months > max"],
[{ months: 4294967296 }, "property bag with months > max"],
["-P4294967296M", "string with months < min"],
[{ months: -4294967296 }, "property bag with months < min"],
["P4294967296W", "string with weeks > max"],
[{ weeks: 4294967296 }, "property bag with weeks > max"],
["-P4294967296W", "string with weeks < min"],
[{ weeks: -4294967296 }, "property bag with weeks < min"],
// ceil(max safe integer / 86400) = 104249991375
["P104249991375D", "string with days > max"],
[{ days: 104249991375 }, "property bag with days > max"],
["P104249991374DT24H", "string where hours balance into days > max"],
[{ days: 104249991374, hours: 24 }, "property bag where hours balance into days > max"],
["-P104249991375D", "string with days < min"],
[{ days: -104249991375 }, "property bag with days < min"],
["-P104249991374DT24H", "string where hours balance into days < min"],
[{ days: -104249991374, hours: -24 }, "property bag where hours balance into days < min"],
// ceil(max safe integer / 3600) = 2501999792984
["PT2501999792984H", "string with hours > max"],
[{ hours: 2501999792984 }, "property bag with hours > max"],
["PT2501999792983H60M", "string where minutes balance into hours > max"],
[{ hours: 2501999792983, minutes: 60 }, "property bag where minutes balance into hours > max"],
["-PT2501999792984H", "string with hours < min"],
[{ hours: -2501999792984 }, "property bag with hours < min"],
["-PT2501999792983H60M", "string where minutes balance into hours < min"],
[{ hours: -2501999792983, minutes: -60 }, "property bag where minutes balance into hours < min"],
// ceil(max safe integer / 60) = 150119987579017
["PT150119987579017M", "string with minutes > max"],
[{ minutes: 150119987579017 }, "property bag with minutes > max"],
["PT150119987579016M60S", "string where seconds balance into minutes > max"],
[{ minutes: 150119987579016, seconds: 60 }, "property bag where seconds balance into minutes > max"],
["-PT150119987579017M", "string with minutes < min"],
[{ minutes: -150119987579017 }, "property bag with minutes < min"],
["-PT150119987579016M60S", "string where seconds balance into minutes < min"],
[{ minutes: -150119987579016, seconds: -60 }, "property bag where seconds balance into minutes < min"],
// 2^53 = 9007199254740992
["PT9007199254740992S", "string with seconds > max"],
[{ seconds: 9007199254740992 }, "property bag with seconds > max"],
[{ seconds: 9007199254740991, milliseconds: 1000 }, "property bag where milliseconds balance into seconds > max"],
[{ seconds: 9007199254740991, microseconds: 1000000 }, "property bag where microseconds balance into seconds > max"],
[{ seconds: 9007199254740991, nanoseconds: 1000000000 }, "property bag where nanoseconds balance into seconds > max"],
["-PT9007199254740992S", "string with seconds < min"],
[{ seconds: -9007199254740992 }, "property bag with seconds < min"],
[{ seconds: -9007199254740991, milliseconds: -1000 }, "property bag where milliseconds balance into seconds < min"],
[{ seconds: -9007199254740991, microseconds: -1000000 }, "property bag where microseconds balance into seconds < min"],
[{ seconds: -9007199254740991, nanoseconds: -1000000000 }, "property bag where nanoseconds balance into seconds < min"],
];
for (const [arg, descr] of cases) {
assert.throws(RangeError, () => instance.dateAdd(new Temporal.PlainDate(1970, 1, 1), arg), `${descr} is out of range`);
}

View File

@ -1,35 +0,0 @@
// Copyright (C) 2022 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: >
Call BalanceISOYearMonth with 2³² - 1 and -(2³² - 1) for years/months.
info: |
Temporal.Calendar.prototype.dateAdd ( date, duration [ , options ] )
...
9. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]],
duration.[[Years]], duration.[[Months]], duration.[[Weeks]], balanceResult.[[Days]],
overflow).
10. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], calendar).
AddISODate ( year, month, day, years, months, weeks, days, overflow )
...
3. Let intermediate be ! BalanceISOYearMonth(year + years, month + months).
...
features: [Temporal]
---*/
var cal = new Temporal.Calendar("iso8601");
var date = new Temporal.PlainDate(1970, 1, 1);
const max = 4294967295; // 2³² - 1
var maxValue = new Temporal.Duration(max, max);
var minValue = new Temporal.Duration(-max, -max);
assert.throws(RangeError, () => cal.dateAdd(date, maxValue), "years/months is +Number.MAX_VALUE");
assert.throws(RangeError, () => cal.dateAdd(date, minValue), "years/months is -Number.MAX_VALUE");

View File

@ -1,27 +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.dateadd
description: Leap second is a valid ISO string for PlainDate
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
let arg = "2016-12-31T23:59:60";
const result1 = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(
result1,
2016, 12, "M12", 31,
"leap second is a valid ISO string for PlainDate"
);
arg = { year: 2016, month: 12, day: 31, hour: 23, minute: 59, second: 60 };
const result2 = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(
result2,
2016, 12, "M12", 31,
"second: 60 is ignored in property bag for PlainDate"
);

View File

@ -1,25 +0,0 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: A number cannot be used in place of a Temporal.PlainDate
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const numbers = [
1,
19761118,
-19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
'Numbers cannot be used in place of an ISO string for PlainDate'
);
}

View File

@ -1,23 +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: Fast path for converting Temporal.PlainDateTime to Temporal.PlainDate by reading internal slots
info: |
sec-temporal.calendar.prototype.dateadd step 4:
4. Set _date_ to ? ToTemporalDate(_date_).
sec-temporal-totemporaldate step 2.b:
b. If _item_ has an [[InitializedTemporalDateTime]] internal slot, then
i. Return ! CreateTemporalDate(_item_.[[ISOYear]], _item_.[[ISOMonth]], _item_.[[ISODay]], _item_.[[Calendar]]).
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
const calendar = new Temporal.Calendar("iso8601");
const duration = new Temporal.Duration(0, 1);
const result = calendar.dateAdd(datetime, duration);
TemporalHelpers.assertPlainDate(result, 2000, 6, "M06", 2);
assert.sameValue(result.hour, undefined, "instance of PlainDate returned, not PlainDateTime");
});

View File

@ -1,17 +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.dateadd
description: The calendar name is case-insensitive
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = "IsO8601";
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, "Calendar is case-insensitive");

View File

@ -1,26 +0,0 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: An ISO 8601 string can be converted to a calendar ID in Calendar
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
for (const calendar of [
"2020-01-01",
"2020-01-01[u-ca=iso8601]",
"2020-01-01T00:00:00.000000000",
"2020-01-01T00:00:00.000000000[u-ca=iso8601]",
"01-01",
"01-01[u-ca=iso8601]",
"2020-01",
"2020-01[u-ca=iso8601]",
]) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, `Calendar created from string "${calendar}"`);
}

View File

@ -1,21 +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.dateadd
description: Leap second is a valid ISO string for a calendar in a property bag
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = "2016-12-31T23:59:60";
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(
result,
1976, 11, "M11", 18,
"leap second is a valid ISO string for calendar"
);

View File

@ -1,26 +0,0 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: A number as calendar in a property bag is not accepted
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const numbers = [
1,
19970327,
-19970327,
1234567890,
];
for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws(
TypeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
"Numbers cannot be used as a calendar"
);
}

View File

@ -1,17 +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.dateadd
description: A calendar ID is valid input for Calendar
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = "iso8601";
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, `Calendar created from string "${calendar}"`);

View File

@ -1,43 +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.dateadd
description: >
Appropriate error thrown when a calendar property from a property bag cannot
be converted to a calendar object or string
features: [BigInt, Symbol, Temporal]
---*/
const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601");
const primitiveTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`${description} does not convert to a valid ISO string`
);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object that doesn't implement the protocol"],
[new Temporal.TimeZone("UTC"), "time zone instance"],
[Temporal.Calendar, "Temporal.Calendar, object"],
[Temporal.Calendar.prototype, "Temporal.Calendar.prototype, object"], // fails brand check in dateFromFields()
];
for (const [calendar, description] of typeErrorTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(TypeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} is not a valid property bag and does not convert to a string`);
}

View File

@ -1,25 +0,0 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T17:45",
"-000000-10-31T17:45Z",
"-000000-10-31T17:45+01:00",
"-000000-10-31T17:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((str) => {
const arg = { year: 1976, month: 11, day: 18, calendar: str };
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
"reject minus zero as extended year"
);
});

View File

@ -1,14 +0,0 @@
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: If a calendar's fields() method returns a field named '__proto__', PrepareTemporalFields should throw a RangeError.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = TemporalHelpers.calendarWithExtraFields(['__proto__']);
const arg = {year: 2023, month: 5, monthCode: 'M05', day: 1, calendar: calendar};
const instance = new Temporal.Calendar("iso8601");
assert.throws(RangeError, () => instance.dateAdd(arg, new Temporal.Duration()));

View File

@ -1,22 +0,0 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: Annotation keys are lowercase-only
features: [Temporal]
---*/
const invalidStrings = [
["1970-01-01[U-CA=iso8601]", "invalid capitalized key"],
["1970-01-01[u-CA=iso8601]", "invalid partially-capitalized key"],
["1970-01-01[FOO=bar]", "invalid capitalized unrecognized key"],
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach(([arg, descr]) => {
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`annotation keys must be lowercase: ${arg} - ${descr}`
);
});

View File

@ -1,31 +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.dateadd
description: Various forms of calendar annotation; critical flag has no effect
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const tests = [
["2000-05-02[u-ca=iso8601]", "without time or time zone"],
["2000-05-02[UTC][u-ca=iso8601]", "with time zone and no time"],
["2000-05-02T15:23[u-ca=iso8601]", "without time zone"],
["2000-05-02T15:23[UTC][u-ca=iso8601]", "with time zone"],
["2000-05-02T15:23[!u-ca=iso8601]", "with ! and no time zone"],
["2000-05-02T15:23[UTC][!u-ca=iso8601]", "with ! and time zone"],
["2000-05-02T15:23[u-ca=iso8601][u-ca=discord]", "second annotation ignored"],
];
const instance = new Temporal.Calendar("iso8601");
tests.forEach(([arg, description]) => {
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(
result,
2000, 5, "M05", 2,
`calendar annotation (${description})`
);
});

View File

@ -1,25 +0,0 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: Unknown annotations with critical flag are rejected
features: [Temporal]
---*/
const invalidStrings = [
"1970-01-01[!foo=bar]",
"1970-01-01T00:00[!foo=bar]",
"1970-01-01T00:00[UTC][!foo=bar]",
"1970-01-01T00:00[u-ca=iso8601][!foo=bar]",
"1970-01-01T00:00[UTC][!foo=bar][u-ca=iso8601]",
"1970-01-01T00:00[foo=bar][!_foo-bar0=Dont-Ignore-This-99999999999]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`reject unknown annotation with critical flag: ${arg}`
);
});

View File

@ -1,46 +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.dateadd
description: UTC offset not valid with format that does not include a time
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const instance = new Temporal.Calendar("iso8601");
const validStrings = [
"2000-05-02T00+00:00",
"2000-05-02T00+00:00[UTC]",
"2000-05-02T00+00:00[!UTC]",
"2000-05-02T00-02:30[America/St_Johns]",
];
for (const arg of validStrings) {
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(
result,
2000, 5, "M05", 2,
`"${arg}" is a valid UTC offset with time for PlainDate`
);
}
const invalidStrings = [
"2022-09-15Z",
"2022-09-15Z[UTC]",
"2022-09-15Z[Europe/Vienna]",
"2022-09-15+00:00",
"2022-09-15+00:00[UTC]",
"2022-09-15-02:30",
"2022-09-15-02:30[America/St_Johns]",
];
for (const arg of invalidStrings) {
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`"${arg}" UTC offset without time is not valid for PlainDate`
);
}

View File

@ -1,61 +0,0 @@
// Copyright (C) 2022 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: >
RangeError thrown if an invalid ISO string (or syntactically valid ISO string
that is not supported) is used as a PlainDate
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
// invalid ISO strings:
"",
"invalid iso8601",
"2020-01-00",
"2020-01-32",
"2020-02-30",
"2021-02-29",
"2020-00-01",
"2020-13-01",
"2020-01-01T",
"2020-01-01T25:00:00",
"2020-01-01T01:60:00",
"2020-01-01T01:60:61",
"2020-01-01junk",
"2020-01-01T00:00:00junk",
"2020-01-01T00:00:00+00:00junk",
"2020-01-01T00:00:00+00:00[UTC]junk",
"2020-01-01T00:00:00+00:00[UTC][u-ca=iso8601]junk",
"02020-01-01",
"2020-001-01",
"2020-01-001",
"2020-01-01T001",
"2020-01-01T01:001",
"2020-01-01T01:01:001",
// valid, but forms not supported in Temporal:
"2020-W01-1",
"2020-001",
"+0002020-01-01",
// valid, but this calendar must not exist:
"2020-01-01[u-ca=notexist]",
// may be valid in other contexts, but insufficient information for PlainDate:
"2020-01",
"+002020-01",
"01-01",
"2020-W01",
"P1Y",
"-P12Y",
// valid, but outside the supported range:
"-999999-01-01",
"+999999-01-01",
];
const instance = new Temporal.Calendar("iso8601");
for (const arg of invalidStrings) {
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`"${arg}" should not be a valid ISO string for a PlainDate`
);
}

View File

@ -1,29 +0,0 @@
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: >
More than one calendar annotation is not syntactical if any have the criical
flag
features: [Temporal]
---*/
const invalidStrings = [
"1970-01-01[u-ca=iso8601][!u-ca=iso8601]",
"1970-01-01[!u-ca=iso8601][u-ca=iso8601]",
"1970-01-01[UTC][u-ca=iso8601][!u-ca=iso8601]",
"1970-01-01[u-ca=iso8601][foo=bar][!u-ca=iso8601]",
"1970-01-01T00:00[u-ca=iso8601][!u-ca=iso8601]",
"1970-01-01T00:00[!u-ca=iso8601][u-ca=iso8601]",
"1970-01-01T00:00[UTC][u-ca=iso8601][!u-ca=iso8601]",
"1970-01-01T00:00[u-ca=iso8601][foo=bar][!u-ca=iso8601]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`reject more than one calendar annotation if any critical: ${arg}`
);
});

View File

@ -1,25 +0,0 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: More than one time zone annotation is not syntactical
features: [Temporal]
---*/
const invalidStrings = [
"1970-01-01[UTC][UTC]",
"1970-01-01T00:00[UTC][UTC]",
"1970-01-01T00:00[!UTC][UTC]",
"1970-01-01T00:00[UTC][!UTC]",
"1970-01-01T00:00[UTC][u-ca=iso8601][UTC]",
"1970-01-01T00:00[UTC][foo=bar][UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`reject more than one time zone annotation: ${arg}`
);
});

View File

@ -1,27 +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.dateadd
description: Time separator in string argument can vary
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const tests = [
["2000-05-02T15:23", "uppercase T"],
["2000-05-02t15:23", "lowercase T"],
["2000-05-02 15:23", "space between date and time"],
];
const instance = new Temporal.Calendar("iso8601");
tests.forEach(([arg, description]) => {
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(
result,
2000, 5, "M05", 2,
`variant time separators (${description})`
);
});

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.dateadd
description: Various forms of time zone annotation; critical flag has no effect
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const tests = [
["2000-05-02[Asia/Kolkata]", "named, with no time"],
["2000-05-02[!Europe/Vienna]", "named, with ! and no time"],
["2000-05-02[+00:00]", "numeric, with no time"],
["2000-05-02[!-02:30]", "numeric, with ! and no time"],
["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"],
["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"],
["2000-05-02T15:23[-02:30]", "numeric, with no offset"],
["2000-05-02T15:23[!+00:00]", "numeric, with ! and no offset"],
["2000-05-02T15:23+00:00[America/New_York]", "named, with offset"],
["2000-05-02T15:23+00:00[!UTC]", "named, with offset and !"],
["2000-05-02T15:23+00:00[+01:00]", "numeric, with offset"],
["2000-05-02T15:23+00:00[!-08:00]", "numeric, with offset and !"],
];
const instance = new Temporal.Calendar("iso8601");
tests.forEach(([arg, description]) => {
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(
result,
2000, 5, "M05", 2,
`time zone annotation (${description})`
);
});

View File

@ -1,30 +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.dateadd
description: Various forms of unknown annotation
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const tests = [
["2000-05-02[foo=bar]", "without time"],
["2000-05-02T15:23[foo=bar]", "alone"],
["2000-05-02T15:23[UTC][foo=bar]", "with time zone"],
["2000-05-02T15:23[u-ca=iso8601][foo=bar]", "with calendar"],
["2000-05-02T15:23[UTC][foo=bar][u-ca=iso8601]", "with time zone and calendar"],
["2000-05-02T15:23[foo=bar][_foo-bar0=Ignore-This-999999999999]", "with another unknown annotation"],
];
const instance = new Temporal.Calendar("iso8601");
tests.forEach(([arg, description]) => {
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(
result,
2000, 5, "M05", 2,
`unknown annotation (${description})`
);
});

View File

@ -1,21 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: RangeError thrown if a string with UTC designator is used as a PlainDate
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
"2019-10-01T09:00:00Z",
"2019-10-01T09:00:00Z[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
"String with UTC designator should not be valid as a PlainDate"
);
});

View File

@ -1,40 +0,0 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or property bag for PlainDate
features: [BigInt, Symbol, Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const primitiveTests = [
[undefined, "undefined"],
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [arg, description] of primitiveTests) {
assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`${description} does not convert to a valid ISO string`
);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object"],
[Temporal.PlainDate, "Temporal.PlainDate, object"],
[Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"],
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} is not a valid property bag and does not convert to a string`);
}

View File

@ -1,19 +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.dateadd
description: An exception from TimeZone#getOffsetNanosecondsFor() is propagated.
features: [Temporal]
---*/
class TZ extends Temporal.TimeZone {
constructor() { super("UTC") }
getOffsetNanosecondsFor() { throw new Test262Error() }
}
const tz = new TZ();
const arg = new Temporal.ZonedDateTime(0n, tz);
const instance = new Temporal.Calendar("iso8601");
assert.throws(Test262Error, () => instance.dateAdd(arg, new Temporal.Duration()));

View File

@ -1,37 +0,0 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: Getters are not called when converting a ZonedDateTime to a PlainDate.
includes: [compareArray.js]
features: [Temporal]
---*/
const actual = [];
const prototypeDescrs = Object.getOwnPropertyDescriptors(Temporal.ZonedDateTime.prototype);
const getters = ["year", "month", "monthCode", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond", "calendar"];
for (const property of getters) {
Object.defineProperty(Temporal.ZonedDateTime.prototype, property, {
get() {
actual.push(`get ${property}`);
const value = prototypeDescrs[property].get.call(this);
return {
toString() {
actual.push(`toString ${property}`);
return value.toString();
},
valueOf() {
actual.push(`valueOf ${property}`);
return value;
},
};
},
});
}
const arg = new Temporal.ZonedDateTime(0n, "UTC");
const instance = new Temporal.Calendar("iso8601");
instance.dateAdd(arg, new Temporal.Duration());
assert.compareArray(actual, []);

View File

@ -1,17 +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: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds
features: [Temporal]
includes: [temporalHelpers.js]
---*/
[3600_000_000_000.5, NaN, -Infinity, Infinity].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
const calendar = new Temporal.Calendar("iso8601");
const duration = new Temporal.Duration(1);
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
assert.throws(RangeError, () => calendar.dateAdd(datetime, duration));
});

View File

@ -1,21 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: TypeError thrown if timeZone.getOffsetNanosecondsFor is not callable
features: [BigInt, Symbol, Temporal, arrow-function]
---*/
[undefined, null, true, Math.PI, 'string', Symbol('sym'), 42n, {}].forEach((notCallable) => {
const timeZone = new Temporal.TimeZone("UTC");
const calendar = new Temporal.Calendar("iso8601");
const duration = new Temporal.Duration(1);
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
timeZone.getOffsetNanosecondsFor = notCallable;
assert.throws(
TypeError,
() => calendar.dateAdd(datetime, duration),
`Uncallable ${notCallable === null ? 'null' : typeof notCallable} getOffsetNanosecondsFor should throw TypeError`
);
});

View File

@ -1,17 +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: RangeError thrown if time zone reports an offset that is out of range
features: [Temporal]
includes: [temporalHelpers.js]
---*/
[-86400_000_000_000, 86400_000_000_000].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
const calendar = new Temporal.Calendar("iso8601");
const duration = new Temporal.Duration(1);
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
assert.throws(RangeError, () => calendar.dateAdd(datetime, duration));
});

View File

@ -1,26 +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: TypeError thrown if time zone reports an offset that is not a Number
features: [Temporal]
includes: [temporalHelpers.js]
---*/
[
undefined,
null,
true,
"+01:00",
Symbol(),
3600_000_000_000n,
{},
{ valueOf() { return 3600_000_000_000; } },
].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
const calendar = new Temporal.Calendar("iso8601");
const duration = new Temporal.Duration(1);
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
assert.throws(TypeError, () => calendar.dateAdd(datetime, duration));
});

View File

@ -1,22 +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: Durations with units smaller than days are balanced before adding
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = new Temporal.Calendar("iso8601");
const date = new Temporal.PlainDate(2000, 5, 2, calendar);
const duration = new Temporal.Duration(0, 0, 0, 1, 24, 1440, 86400, 86400_000, 86400_000_000, 86400_000_000_000);
const result = calendar.dateAdd(date, duration);
TemporalHelpers.assertPlainDate(result, 2000, 5, "M05", 9, "units smaller than days are balanced");
const resultString = calendar.dateAdd(date, "P1DT24H1440M86400S");
TemporalHelpers.assertPlainDate(resultString, 2000, 5, "M05", 6, "units smaller than days are balanced");
const resultPropBag = calendar.dateAdd(date, { days: 1, hours: 24, minutes: 1440, seconds: 86400, milliseconds: 86400_000, microseconds: 86400_000_000, nanoseconds: 86400_000_000_000 });
TemporalHelpers.assertPlainDate(resultPropBag, 2000, 5, "M05", 9, "units smaller than days are balanced");

View File

@ -1,24 +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: Throw a TypeError if the receiver is invalid
features: [Symbol, Temporal]
---*/
const dateAdd = Temporal.Calendar.prototype.dateAdd;
assert.sameValue(typeof dateAdd, "function");
const args = [new Temporal.PlainDate(2000, 1, 1), new Temporal.Duration(1)];
assert.throws(TypeError, () => dateAdd.apply(undefined, args), "undefined");
assert.throws(TypeError, () => dateAdd.apply(null, args), "null");
assert.throws(TypeError, () => dateAdd.apply(true, args), "true");
assert.throws(TypeError, () => dateAdd.apply("", args), "empty string");
assert.throws(TypeError, () => dateAdd.apply(Symbol(), args), "symbol");
assert.throws(TypeError, () => dateAdd.apply(1, args), "1");
assert.throws(TypeError, () => dateAdd.apply({}, args), "plain object");
assert.throws(TypeError, () => dateAdd.apply(Temporal.Calendar, args), "Temporal.Calendar");
assert.throws(TypeError, () => dateAdd.apply(Temporal.Calendar.prototype, args), "Temporal.Calendar.prototype");

View File

@ -1,33 +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: >
Tests that Temporal.Calendar.prototype.dateAdd
meets the requirements for built-in objects defined by the
introduction of chapter 17 of the ECMAScript Language Specification.
info: |
Built-in functions that are not constructors do not have a "prototype" property unless
otherwise specified in the description of a particular function.
Unless specified otherwise, a built-in object that is callable as a function is a built-in
function object with the characteristics described in 10.3. Unless specified otherwise, the
[[Extensible]] internal slot of a built-in object initially has the value true.
Unless otherwise specified every built-in function and every built-in constructor has the
Function prototype object [...] as the value of its [[Prototype]] internal slot.
features: [Temporal]
---*/
assert.sameValue(Object.isExtensible(Temporal.Calendar.prototype.dateAdd),
true, "Built-in objects must be extensible.");
assert.sameValue(Object.prototype.toString.call(Temporal.Calendar.prototype.dateAdd),
"[object Function]", "Object.prototype.toString");
assert.sameValue(Object.getPrototypeOf(Temporal.Calendar.prototype.dateAdd),
Function.prototype, "prototype");
assert.sameValue(Temporal.Calendar.prototype.dateAdd.hasOwnProperty("prototype"),
false, "prototype property");

View File

@ -1,15 +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.dateadd
description: >
Calendar.dateFromFields method is called with undefined as the options value
when call originates internally
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = TemporalHelpers.calendarFromFieldsUndefinedOptions();
calendar.dateAdd({ year: 2000, month: 5, day: 2, calendar }, new Temporal.Duration(1));
assert.sameValue(calendar.dateFromFieldsCallCount, 1);

View File

@ -1,33 +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: Verify the result of calendar.fields() is treated correctly.
info: |
sec-temporal.calendar.prototype.dateadd step 4:
4. Set _date_ to ? ToTemporalDate(_date_).
sec-temporal-totemporaldate step 2.c:
c. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"day"*, *"month"*, *"monthCode"*, *"year"* »).
sec-temporal-calendarfields step 4:
4. Let _result_ be ? IterableToListOfType(_fieldsArray_, « String »).
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const expected = [
"day",
"month",
"monthCode",
"year",
];
const duration = new Temporal.Duration(0, 1);
const calendar1 = TemporalHelpers.calendarFieldsIterable();
const calendar2 = TemporalHelpers.calendarFieldsIterable();
calendar1.dateAdd({ year: 2000, month: 5, day: 2, calendar: calendar2 }, duration);
assert.sameValue(calendar1.fieldsCallCount, 0, "fields() method not called");
assert.sameValue(calendar2.fieldsCallCount, 1, "fields() method called once");
assert.compareArray(calendar2.fieldsCalledWith[0], expected, "fields() method called with correct args");
assert(calendar2.iteratorExhausted[0], "iterated through the whole iterable");

View File

@ -1,27 +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: Fast path for converting other Temporal objects to Temporal.Calendar by reading internal slots
info: |
sec-temporal.calendar.prototype.dateadd step 4:
4. Set _date_ to ? ToTemporalDate(_date_).
sec-temporal-totemporaldate step 2.c:
c. Let _calendar_ be ? GetTemporalCalendarWithISODefault(_item_).
sec-temporal-gettemporalcalendarwithisodefault step 2:
2. Return ? ToTemporalCalendarWithISODefault(_calendar_).
sec-temporal-totemporalcalendarwithisodefault step 2:
3. Return ? ToTemporalCalendar(_temporalCalendarLike_).
sec-temporal-totemporalcalendar step 1.a:
a. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
i. Return _temporalCalendarLike_.[[Calendar]].
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => {
const calendar = new Temporal.Calendar("iso8601");
const duration = new Temporal.Duration(0, 1);
calendar.dateAdd({ year: 2000, month: 5, day: 2, calendar: temporalObject }, duration);
});

View File

@ -1,26 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Throws if any value in the property bag is Infinity or -Infinity
esid: sec-temporal.calendar.prototype.dateadd
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const duration = new Temporal.Duration(1);
const base = { year: 2000, month: 5, day: 2 };
[Infinity, -Infinity].forEach((inf) => {
["year", "month", "day"].forEach((prop) => {
["constrain", "reject"].forEach((overflow) => {
assert.throws(RangeError, () => instance.dateAdd({ ...base, [prop]: inf }, duration, { overflow }), `${prop} property cannot be ${inf} (overflow ${overflow}`);
const calls = [];
const obj = TemporalHelpers.toPrimitiveObserver(calls, inf, prop);
assert.throws(RangeError, () => instance.dateAdd({ ...base, [prop]: obj }, duration, { overflow }));
assert.compareArray(calls, [`get ${prop}.valueOf`, `call ${prop}.valueOf`], "it fails after fetching the primitive value");
});
});
});

View File

@ -1,25 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: Temporal.Calendar.prototype.dateAdd.length is 2
info: |
Every built-in function object, including constructors, has a "length" property whose value is
an integer. Unless otherwise specified, this value is equal to the largest number of named
arguments shown in the subclause headings for the function description. Optional parameters
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
«...name») are not included in the default argument count.
Unless otherwise specified, the "length" property of a built-in function object has the
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/
verifyProperty(Temporal.Calendar.prototype.dateAdd, "length", {
value: 2,
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -1,23 +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: Temporal.Calendar.prototype.dateAdd.name is "dateAdd".
info: |
Every built-in function object, including constructors, that is not identified as an anonymous
function has a "name" property whose value is a String. Unless otherwise specified, this value
is the name that is given to the function in this specification.
Unless otherwise specified, the "name" property of a built-in function object, if it exists,
has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/
verifyProperty(Temporal.Calendar.prototype.dateAdd, "name", {
value: "dateAdd",
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -1,21 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: >
Temporal.Calendar.prototype.dateAdd does not implement [[Construct]], is not new-able
info: |
Built-in function objects that are not identified as constructors do not implement the
[[Construct]] internal method unless otherwise specified in the description of a particular
function.
includes: [isConstructor.js]
features: [Reflect.construct, Temporal]
---*/
assert.throws(TypeError, () => {
new Temporal.Calendar.prototype.dateAdd();
}, "Calling as constructor");
assert.sameValue(isConstructor(Temporal.Calendar.prototype.dateAdd), false,
"isConstructor(Temporal.Calendar.prototype.dateAdd)");

View File

@ -1,23 +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.dateadd
description: Empty or a function object may be used as options
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const result1 = instance.dateAdd(new Temporal.PlainDate(1976, 11, 18), new Temporal.Duration(1), {});
TemporalHelpers.assertPlainDate(
result1, 1977, 11, "M11", 18,
"options may be an empty plain object"
);
const result2 = instance.dateAdd(new Temporal.PlainDate(1976, 11, 18), new Temporal.Duration(1), () => {});
TemporalHelpers.assertPlainDate(
result2, 1977, 11, "M11", 18,
"options may be a function object"
);

View File

@ -1,23 +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.dateadd
description: TypeError thrown when options argument is a primitive
features: [BigInt, Symbol, Temporal]
---*/
const badOptions = [
null,
true,
"some string",
Symbol(),
1,
2n,
];
const instance = new Temporal.Calendar("iso8601");
for (const value of badOptions) {
assert.throws(TypeError, () => instance.dateAdd(new Temporal.PlainDate(1976, 11, 18), new Temporal.Duration(1), value),
`TypeError on wrong options type ${typeof value}`);
};

View File

@ -1,119 +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.dateadd
description: Properties on an object passed to dateAdd() are accessed in the correct order
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const expected = [
// ToTemporalDate → GetTemporalCalendarSlotValueWithISODefault
"get date.calendar",
"has date.calendar.dateAdd",
"has date.calendar.dateFromFields",
"has date.calendar.dateUntil",
"has date.calendar.day",
"has date.calendar.dayOfWeek",
"has date.calendar.dayOfYear",
"has date.calendar.daysInMonth",
"has date.calendar.daysInWeek",
"has date.calendar.daysInYear",
"has date.calendar.fields",
"has date.calendar.id",
"has date.calendar.inLeapYear",
"has date.calendar.mergeFields",
"has date.calendar.month",
"has date.calendar.monthCode",
"has date.calendar.monthDayFromFields",
"has date.calendar.monthsInYear",
"has date.calendar.weekOfYear",
"has date.calendar.year",
"has date.calendar.yearMonthFromFields",
"has date.calendar.yearOfWeek",
// lookup
"get date.calendar.dateFromFields",
"get date.calendar.fields",
// ToTemporalDate → CalendarFields
"call date.calendar.fields",
// ToTemporalDate → PrepareTemporalFields
"get date.day",
"get date.day.valueOf",
"call date.day.valueOf",
"get date.month",
"get date.month.valueOf",
"call date.month.valueOf",
"get date.monthCode",
"get date.monthCode.toString",
"call date.monthCode.toString",
"get date.year",
"get date.year.valueOf",
"call date.year.valueOf",
// ToTemporalDate → CalendarDateFromFields
"call date.calendar.dateFromFields",
// ToTemporalDuration
"get duration.days",
"get duration.days.valueOf",
"call duration.days.valueOf",
"get duration.hours",
"get duration.hours.valueOf",
"call duration.hours.valueOf",
"get duration.microseconds",
"get duration.microseconds.valueOf",
"call duration.microseconds.valueOf",
"get duration.milliseconds",
"get duration.milliseconds.valueOf",
"call duration.milliseconds.valueOf",
"get duration.minutes",
"get duration.minutes.valueOf",
"call duration.minutes.valueOf",
"get duration.months",
"get duration.months.valueOf",
"call duration.months.valueOf",
"get duration.nanoseconds",
"get duration.nanoseconds.valueOf",
"call duration.nanoseconds.valueOf",
"get duration.seconds",
"get duration.seconds.valueOf",
"call duration.seconds.valueOf",
"get duration.weeks",
"get duration.weeks.valueOf",
"call duration.weeks.valueOf",
"get duration.years",
"get duration.years.valueOf",
"call duration.years.valueOf",
// ToTemporalOverflow
"get options.overflow",
"get options.overflow.toString",
"call options.overflow.toString",
];
const actual = [];
const instance = new Temporal.Calendar("iso8601");
const date = TemporalHelpers.propertyBagObserver(actual, {
year: 2000,
month: 5,
monthCode: "M05",
day: 2,
calendar: TemporalHelpers.calendarObserver(actual, "date.calendar"),
}, "date");
const duration = TemporalHelpers.propertyBagObserver(actual, {
years: 1,
months: 2,
weeks: 3,
days: 4,
hours: 5,
minutes: 6,
seconds: 7,
milliseconds: 8,
microseconds: 9,
nanoseconds: 10,
}, "duration");
const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options");
instance.dateAdd(date, duration, options);
assert.compareArray(actual, expected, "order of operations");

View File

@ -1,27 +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: RangeError thrown when overflow option not one of the allowed string values
info: |
sec-getoption step 10:
10. If _values_ is not *undefined* and _values_ does not contain an element equal to _value_, throw a *RangeError* exception.
sec-temporal-totemporaloverflow step 1:
1. Return ? GetOption(_normalizedOptions_, *"overflow"*, « String », « *"constrain"*, *"reject"* », *"constrain"*).
sec-temporal.calendar.prototype.dateadd step 7:
7. Let _overflow_ be ? ToTemporalOverflow(_options_).
features: [Temporal, arrow-function]
---*/
const calendar = new Temporal.Calendar("iso8601");
const date = new Temporal.PlainDate(2000, 5, 2, calendar);
const duration = new Temporal.Duration(3, 3, 0, 3);
const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => calendar.dateAdd(date, duration, { overflow }),
`invalid overflow ("${overflow}")`
);
}

View File

@ -1,25 +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: Fallback value for overflow option
info: |
sec-getoption step 3:
3. If _value_ is *undefined*, return _fallback_.
sec-temporal-totemporaloverflow step 1:
1. Return ? GetOption(_normalizedOptions_, *"overflow"*, « String », « *"constrain"*, *"reject"* », *"constrain"*).
sec-temporal.calendar.prototype.dateadd step 7:
7. Let _overflow_ be ? ToTemporalOverflow(_options_).
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = new Temporal.Calendar("iso8601");
const date = new Temporal.PlainDate(2000, 5, 31, calendar);
const duration = new Temporal.Duration(3, 1);
const explicit = calendar.dateAdd(date, duration, { overflow: undefined });
TemporalHelpers.assertPlainDate(explicit, 2003, 6, "M06", 30, "default overflow is constrain");
const implicit = calendar.dateAdd(date, duration, {});
TemporalHelpers.assertPlainDate(implicit, 2003, 6, "M06", 30, "default overflow is constrain");

View File

@ -1,24 +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: Type conversions for overflow option
info: |
sec-getoption step 9.a:
a. Set _value_ to ? ToString(_value_).
sec-temporal-totemporaloverflow step 1:
1. Return ? GetOption(_normalizedOptions_, *"overflow"*, « String », « *"constrain"*, *"reject"* », *"constrain"*).
sec-temporal.calendar.prototype.dateadd step 7:
7. Let _overflow_ be ? ToTemporalOverflow(_options_).
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const calendar = new Temporal.Calendar("iso8601");
const date = new Temporal.PlainDate(2000, 5, 2, calendar);
const duration = new Temporal.Duration(3, 3, 0, 3);
TemporalHelpers.checkStringOptionWrongType("overflow", "constrain",
(overflow) => calendar.dateAdd(date, duration, { overflow }),
(result, descr) => TemporalHelpers.assertPlainDate(result, 2003, 8, "M08", 5, descr),
);

View File

@ -1,21 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: The "dateAdd" property of Temporal.Calendar.prototype
includes: [propertyHelper.js]
features: [Temporal]
---*/
assert.sameValue(
typeof Temporal.Calendar.prototype.dateAdd,
"function",
"`typeof Calendar.prototype.dateAdd` is `function`"
);
verifyProperty(Temporal.Calendar.prototype, "dateAdd", {
writable: true,
enumerable: false,
configurable: true,
});

View File

@ -1,23 +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.dateadd
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
"-000000-10-31",
"-000000-10-31T00:45",
"-000000-10-31T00:45+01:00",
"-000000-10-31T00:45+00:00[UTC]",
];
const instance = new Temporal.Calendar("iso8601");
invalidStrings.forEach((arg) => {
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
"reject minus zero as extended year"
);
});

View File

@ -1,24 +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.datefromfields
description: Throw a TypeError if the receiver is invalid
features: [Symbol, Temporal]
---*/
const dateFromFields = Temporal.Calendar.prototype.dateFromFields;
assert.sameValue(typeof dateFromFields, "function");
const args = [{ year: 2000, month: 1, day: 1 }];
assert.throws(TypeError, () => dateFromFields.apply(undefined, args), "undefined");
assert.throws(TypeError, () => dateFromFields.apply(null, args), "null");
assert.throws(TypeError, () => dateFromFields.apply(true, args), "true");
assert.throws(TypeError, () => dateFromFields.apply("", args), "empty string");
assert.throws(TypeError, () => dateFromFields.apply(Symbol(), args), "symbol");
assert.throws(TypeError, () => dateFromFields.apply(1, args), "1");
assert.throws(TypeError, () => dateFromFields.apply({}, args), "plain object");
assert.throws(TypeError, () => dateFromFields.apply(Temporal.Calendar, args), "Temporal.Calendar");
assert.throws(TypeError, () => dateFromFields.apply(Temporal.Calendar.prototype, args), "Temporal.Calendar.prototype");

View File

@ -1,33 +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.datefromfields
description: >
Tests that Temporal.Calendar.prototype.dateFromFields
meets the requirements for built-in objects defined by the
introduction of chapter 17 of the ECMAScript Language Specification.
info: |
Built-in functions that are not constructors do not have a "prototype" property unless
otherwise specified in the description of a particular function.
Unless specified otherwise, a built-in object that is callable as a function is a built-in
function object with the characteristics described in 10.3. Unless specified otherwise, the
[[Extensible]] internal slot of a built-in object initially has the value true.
Unless otherwise specified every built-in function and every built-in constructor has the
Function prototype object [...] as the value of its [[Prototype]] internal slot.
features: [Temporal]
---*/
assert.sameValue(Object.isExtensible(Temporal.Calendar.prototype.dateFromFields),
true, "Built-in objects must be extensible.");
assert.sameValue(Object.prototype.toString.call(Temporal.Calendar.prototype.dateFromFields),
"[object Function]", "Object.prototype.toString");
assert.sameValue(Object.getPrototypeOf(Temporal.Calendar.prototype.dateFromFields),
Function.prototype, "prototype");
assert.sameValue(Temporal.Calendar.prototype.dateFromFields.hasOwnProperty("prototype"),
false, "prototype property");

View File

@ -1,20 +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.datefromfields
description: Throw a TypeError if the fields is not an object
info: |
4. If Type(_fields_) is not Object, throw a *TypeError* exception.
features: [BigInt, Symbol, Temporal, arrow-function]
---*/
const tests = [undefined, null, true, false, "string", Symbol("sym"), Infinity, NaN, Math.PI, 42n];
const iso = Temporal.Calendar.from("iso8601");
for (const fields of tests) {
assert.throws(
TypeError,
() => iso.dateFromFields(fields, {})
`dateFromFields(${typeof fields}) throws a TypeError exception`
);
}

View File

@ -1,25 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Throws if any value in the property bag is Infinity or -Infinity
esid: sec-temporal.calendar.prototype.datefromfields
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const base = { year: 2000, month: 5, day: 2 };
[Infinity, -Infinity].forEach((inf) => {
["year", "month", "day"].forEach((prop) => {
["constrain", "reject"].forEach((overflow) => {
assert.throws(RangeError, () => instance.dateFromFields({ ...base, [prop]: inf }, { overflow }), `${prop} property cannot be ${inf} (overflow ${overflow}`);
const calls = [];
const obj = TemporalHelpers.toPrimitiveObserver(calls, inf, prop);
assert.throws(RangeError, () => instance.dateFromFields({ ...base, [prop]: obj }, { overflow }));
assert.compareArray(calls, [`get ${prop}.valueOf`, `call ${prop}.valueOf`], "it fails after fetching the primitive value");
});
});
});

View File

@ -1,25 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.datefromfields
description: Temporal.Calendar.prototype.dateFromFields.length is 1
info: |
Every built-in function object, including constructors, has a "length" property whose value is
an integer. Unless otherwise specified, this value is equal to the largest number of named
arguments shown in the subclause headings for the function description. Optional parameters
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
«...name») are not included in the default argument count.
Unless otherwise specified, the "length" property of a built-in function object has the
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/
verifyProperty(Temporal.Calendar.prototype.dateFromFields, "length", {
value: 1,
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -1,23 +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.datefromfields
description: Temporal.Calendar.prototype.dateFromFields.name is "dateFromFields".
info: |
Every built-in function object, including constructors, that is not identified as an anonymous
function has a "name" property whose value is a String. Unless otherwise specified, this value
is the name that is given to the function in this specification.
Unless otherwise specified, the "name" property of a built-in function object, if it exists,
has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/
verifyProperty(Temporal.Calendar.prototype.dateFromFields, "name", {
value: "dateFromFields",
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -1,21 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.datefromfields
description: >
Temporal.Calendar.prototype.dateFromFields does not implement [[Construct]], is not new-able
info: |
Built-in function objects that are not identified as constructors do not implement the
[[Construct]] internal method unless otherwise specified in the description of a particular
function.
includes: [isConstructor.js]
features: [Reflect.construct, Temporal]
---*/
assert.throws(TypeError, () => {
new Temporal.Calendar.prototype.dateFromFields();
}, "Calling as constructor");
assert.sameValue(isConstructor(Temporal.Calendar.prototype.dateFromFields), false,
"isConstructor(Temporal.Calendar.prototype.dateFromFields)");

View File

@ -1,23 +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: Empty or a function object may be used as options
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const result1 = instance.dateFromFields({ year: 1976, month: 11, day: 18 }, {});
TemporalHelpers.assertPlainDate(
result1, 1976, 11, "M11", 18,
"options may be an empty plain object"
);
const result2 = instance.dateFromFields({ year: 1976, month: 11, day: 18 }, () => {});
TemporalHelpers.assertPlainDate(
result2, 1976, 11, "M11", 18,
"options may be a function object"
);

View File

@ -1,23 +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: TypeError thrown when options argument is a primitive
features: [BigInt, Symbol, Temporal]
---*/
const badOptions = [
null,
true,
"some string",
Symbol(),
1,
2n,
];
const instance = new Temporal.Calendar("iso8601");
for (const value of badOptions) {
assert.throws(TypeError, () => instance.dateFromFields({ year: 1976, month: 11, day: 18 }, value),
`TypeError on wrong options type ${typeof value}`);
};

View File

@ -1,46 +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: Properties on objects passed to dateFromFields() are accessed in the correct order
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const expected = [
"get fields.day",
"get fields.day.valueOf",
"call fields.day.valueOf",
"get fields.month",
"get fields.month.valueOf",
"call fields.month.valueOf",
"get fields.monthCode",
"get fields.monthCode.toString",
"call fields.monthCode.toString",
"get fields.year",
"get fields.year.valueOf",
"call fields.year.valueOf",
"get options.overflow",
"get options.overflow.toString",
"call options.overflow.toString",
];
const actual = [];
const instance = new Temporal.Calendar("iso8601");
const fields = TemporalHelpers.propertyBagObserver(actual, {
year: 1.7,
month: 1.7,
monthCode: "M01",
day: 1.7,
}, "fields");
const options = TemporalHelpers.propertyBagObserver(actual, {
overflow: "reject",
}, "options");
const result = instance.dateFromFields(fields, options);
TemporalHelpers.assertPlainDate(result, 1, 1, "M01", 1, "date result");
assert.sameValue(result.getISOFields().calendar, "iso8601", "calendar slot should store a string");
assert.compareArray(actual, expected, "order of operations");

View File

@ -1,28 +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.datefromfields
description: RangeError thrown when overflow option not one of the allowed string values
info: |
sec-getoption step 10:
10. If _values_ is not *undefined* and _values_ does not contain an element equal to _value_, throw a *RangeError* exception.
sec-temporal-totemporaloverflow step 1:
1. Return ? GetOption(_normalizedOptions_, *"overflow"*, « String », « *"constrain"*, *"reject"* », *"constrain"*).
sec-temporal-isodatefromfields step 2:
2. Let _overflow_ be ? ToTemporalOverflow(_options_).
sec-temporal.calendar.prototype.datefromfields step 6:
6. Let _result_ be ? ISODateFromFields(_fields_, _options_).
features: [Temporal, arrow-function]
---*/
const calendar = new Temporal.Calendar("iso8601");
const badOverflows = ["", "CONSTRAIN", "balance", "other string", "constra\u0131n", "reject\0"];
for (const overflow of badOverflows) {
assert.throws(
RangeError,
() => calendar.dateFromFields({ year: 2000, month: 5, day: 2 },
{ overflow }),
`invalid overflow ("${overflow}")`
);
}

View File

@ -1,25 +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.datefromfields
description: Fallback value for overflow option
info: |
sec-getoption step 3:
3. If _value_ is *undefined*, return _fallback_.
sec-temporal-totemporaloverflow step 1:
1. Return ? GetOption(_normalizedOptions_, *"overflow"*, « String », « *"constrain"*, *"reject"* », *"constrain"*).
sec-temporal-isodatefromfields step 2:
2. Let _overflow_ be ? ToTemporalOverflow(_options_).
sec-temporal.calendar.prototype.datefromfields step 6:
6. Let _result_ be ? ISODateFromFields(_fields_, _options_).
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = new Temporal.Calendar("iso8601");
const explicit = calendar.dateFromFields({ year: 2000, month: 15, day: 2 }, { overflow: undefined });
TemporalHelpers.assertPlainDate(explicit, 2000, 12, "M12", 2, "default overflow is constrain");
const implicit = calendar.dateFromFields({ year: 2000, month: 15, day: 2 }, {});
TemporalHelpers.assertPlainDate(implicit, 2000, 12, "M12", 2, "default overflow is constrain");

View File

@ -1,24 +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.datefromfields
description: Type conversions for overflow option
info: |
sec-getoption step 9.a:
a. Set _value_ to ? ToString(_value_).
sec-temporal-totemporaloverflow step 1:
1. Return ? GetOption(_normalizedOptions_, *"overflow"*, « String », « *"constrain"*, *"reject"* », *"constrain"*).
sec-temporal-isodatefromfields step 2:
2. Let _overflow_ be ? ToTemporalOverflow(_options_).
sec-temporal.calendar.prototype.datefromfields step 6:
6. Let _result_ be ? ISODateFromFields(_fields_, _options_).
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const calendar = new Temporal.Calendar("iso8601");
TemporalHelpers.checkStringOptionWrongType("overflow", "constrain",
(overflow) => calendar.dateFromFields({ year: 2000, month: 5, day: 2 }, { overflow }),
(result, descr) => TemporalHelpers.assertPlainDate(result, 2000, 5, "M05", 2, descr),
);

View File

@ -1,21 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.datefromfields
description: The "dateFromFields" property of Temporal.Calendar.prototype
includes: [propertyHelper.js]
features: [Temporal]
---*/
assert.sameValue(
typeof Temporal.Calendar.prototype.dateFromFields,
"function",
"`typeof Calendar.prototype.dateFromFields` is `function`"
);
verifyProperty(Temporal.Calendar.prototype, "dateFromFields", {
writable: true,
enumerable: false,
configurable: true,
});

View File

@ -1,22 +0,0 @@
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateuntil
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/
const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}
const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19));
instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg);
Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;

View File

@ -1,23 +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.dateuntil
description: >
Calendar.dateFromFields method is called with a null-prototype fields object
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = TemporalHelpers.calendarCheckFieldsPrototypePollution();
const instance = new Temporal.Calendar("iso8601");
const arg1 = { year: 2000, month: 5, day: 2, calendar };
const arg2 = new Temporal.PlainDate(1977, 11, 19);
instance.dateUntil(arg1, arg2);
assert.sameValue(calendar.dateFromFieldsCallCount, 1, "dateFromFields should be called on the property bag's calendar (first argument)");
calendar.dateFromFieldsCallCount = 0;
instance.dateUntil(arg2, arg1);
assert.sameValue(calendar.dateFromFieldsCallCount, 1, "dateFromFields should be called on the property bag's calendar (second argument)");

View File

@ -1,14 +0,0 @@
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateuntil
description: If a calendar's fields() method returns a field named 'constructor', PrepareTemporalFields should throw a RangeError.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = TemporalHelpers.calendarWithExtraFields(['constructor']);
const arg = {year: 2023, month: 5, monthCode: 'M05', day: 1, calendar: calendar};
const instance = new Temporal.Calendar("iso8601");
assert.throws(RangeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)));

View File

@ -1,17 +0,0 @@
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateuntil
description: If a calendar's fields() method returns duplicate field names, PrepareTemporalFields should throw a RangeError.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
for (const extra_fields of [['foo', 'foo'], ['day'], ['month'], ['monthCode'], ['year']]) {
const calendar = TemporalHelpers.calendarWithExtraFields(extra_fields);
const arg = { year: 2023, month: 5, monthCode: 'M05', day: 1, calendar: calendar };
const instance = new Temporal.Calendar("iso8601");
assert.throws(RangeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)));
assert.throws(RangeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg));
}

View File

@ -1,31 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Throws if any value in a property bag for either argument is Infinity or -Infinity
esid: sec-temporal.calendar.prototype.dateuntil
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const other = new Temporal.PlainDate(2001, 6, 3);
const base = { year: 2000, month: 5, day: 2 };
[Infinity, -Infinity].forEach((inf) => {
["year", "month", "day"].forEach((prop) => {
assert.throws(RangeError, () => instance.dateUntil({ ...base, [prop]: inf }, other), `${prop} property cannot be ${inf}`);
assert.throws(RangeError, () => instance.dateUntil(other, { ...base, [prop]: inf }), `${prop} property cannot be ${inf}`);
const calls1 = [];
const obj1 = TemporalHelpers.toPrimitiveObserver(calls1, inf, prop);
assert.throws(RangeError, () => instance.dateUntil({ ...base, [prop]: obj1 }, other));
assert.compareArray(calls1, [`get ${prop}.valueOf`, `call ${prop}.valueOf`], "it fails after fetching the primitive value");
const calls2 = [];
const obj2 = TemporalHelpers.toPrimitiveObserver(calls2, inf, prop);
assert.throws(RangeError, () => instance.dateUntil(other, { ...base, [prop]: obj2 }));
assert.compareArray(calls2, [`get ${prop}.valueOf`, `call ${prop}.valueOf`], "it fails after fetching the primitive value");
});
});

View File

@ -1,30 +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.dateuntil
description: A number cannot be used in place of a Temporal.PlainDate
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const numbers = [
1,
19761118,
-19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 18)),
"A number is not a valid ISO string for PlainDate (first argument)"
);
assert.throws(
TypeError,
() => instance.dateUntil(new Temporal.PlainDate(1977, 11, 18), arg),
"A number is not a valid ISO string for PlainDate (second argument)"
);
}

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.calendar.prototype.dateuntil
description: Fast path for converting Temporal.PlainDateTime to Temporal.PlainDate by reading internal slots
info: |
sec-temporal.calendar.prototype.dateuntil steps 45:
4. Set _one_ to ? ToTemporalDate(_one_).
5. Set _two_ to ? ToTemporalDate(_two_).
sec-temporal-totemporaldate step 2.b:
b. If _item_ has an [[InitializedTemporalDateTime]] internal slot, then
i. Return ! CreateTemporalDate(_item_.[[ISOYear]], _item_.[[ISOMonth]], _item_.[[ISODay]], _item_.[[Calendar]]).
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const date = new Temporal.PlainDate(2000, 5, 2);
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
const calendar = new Temporal.Calendar("iso8601");
const result = calendar.dateUntil(datetime, date);
assert.sameValue(result.total({ unit: "nanoseconds" }), 0, "time part dropped");
});
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
const calendar = new Temporal.Calendar("iso8601");
const result = calendar.dateUntil(date, datetime);
assert.sameValue(result.total({ unit: "nanoseconds" }), 0, "time part dropped");
});

View File

@ -1,19 +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.dateuntil
description: The calendar name is case-insensitive
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Calendar("iso8601");
const calendar = "IsO8601";
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19));
TemporalHelpers.assertDuration(result1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive (first argument)");
const result2 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg);
TemporalHelpers.assertDuration(result2, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive (second argument)");

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