summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype')
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-iso-string.js28
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-year-zero.js3
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/equals/argument-string-calendar-annotation-invalid-key.js25
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-iso-string.js29
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number.js3
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-year-zero.js3
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-string-calendar-annotation-invalid-key.js25
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/result-mixed-sign.js29
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/wrapping-at-end-of-month.js120
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getoffsetnanosecondsfor-maximum-forward-offset-shift.js49
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getoffsetnanosecondsfor-out-of-range-forward-offset-shift.js44
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getpossibleinstantsfor-maximum-backward-offset-shift.js53
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getpossibleinstantsfor-out-of-range-backward-offset-shift.js49
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-iso-string.js29
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number.js3
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-year-zero.js3
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-string-calendar-annotation-invalid-key.js25
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/no-unnecessary-units.js8
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/result-mixed-sign.js29
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/wrapping-at-end-of-month.js120
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/custom-calendar-weekofyear.js26
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/validate-calendar-value.js1
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-iso-string.js49
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-iso-string.js29
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js3
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-year-zero.js3
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-string-calendar-annotation-invalid-key.js25
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-calendar-annotation-invalid-key.js31
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/custom-calendar-weekofyear.js26
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/validate-calendar-value.js1
30 files changed, 858 insertions, 13 deletions
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-iso-string.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-iso-string.js
new file mode 100644
index 0000000000..eaa94f9313
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-iso-string.js
@@ -0,0 +1,28 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.equals
+description: An ISO 8601 string can be converted to a calendar ID in Calendar
+features: [Temporal]
+---*/
+
+const instance = new Temporal.PlainDateTime(1976, 11, 18);
+
+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.equals(arg);
+ assert.sameValue(result, true, `Calendar created from string "${calendar}"`);
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-year-zero.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-year-zero.js
index 967839b97e..3abda8c843 100644
--- a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-year-zero.js
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-year-zero.js
@@ -16,7 +16,8 @@ const invalidStrings = [
"-000000-10-31T17:45+00:00[UTC]",
];
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
-invalidStrings.forEach((arg) => {
+invalidStrings.forEach((str) => {
+ const arg = { year: 1976, month: 11, day: 18, calendar: str };
assert.throws(
RangeError,
() => instance.equals(arg),
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/equals/argument-string-calendar-annotation-invalid-key.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/equals/argument-string-calendar-annotation-invalid-key.js
new file mode 100644
index 0000000000..7c1070bcf7
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/equals/argument-string-calendar-annotation-invalid-key.js
@@ -0,0 +1,25 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.equals
+description: Annotation keys are lowercase-only
+features: [Temporal]
+---*/
+
+const invalidStrings = [
+ ["1970-01-01T00:00[U-CA=iso8601]", "invalid capitalized key"],
+ ["1970-01-01T00:00[u-CA=iso8601]", "invalid partially-capitalized key"],
+ ["1970-01-01T00:00[FOO=bar]", "invalid capitalized unrecognized key"],
+];
+const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
+invalidStrings.forEach(([arg, descr]) => {
+ assert.throws(
+ RangeError,
+ () => instance.equals(arg),
+ `annotation keys must be lowercase: ${arg} - ${descr}`
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-iso-string.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-iso-string.js
new file mode 100644
index 0000000000..f23d5b2eb0
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-iso-string.js
@@ -0,0 +1,29 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.since
+description: An ISO 8601 string can be converted to a calendar ID in Calendar
+includes: [temporalHelpers.js]
+features: [Temporal]
+---*/
+
+const instance = new Temporal.PlainDateTime(1976, 11, 18);
+
+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.since(arg);
+ TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, `Calendar created from string "${calendar}"`);
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number.js
index 9c7f65ec05..93932c89d5 100644
--- a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number.js
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number.js
@@ -8,7 +8,7 @@ description: A number as calendar in a property bag is not accepted
features: [Temporal]
---*/
-const instance = new Temporal.PlainDate(1976, 11, 18);
+const instance = new Temporal.PlainDateTime(1976, 11, 18);
const numbers = [
1,
@@ -16,6 +16,7 @@ const numbers = [
-19970327,
1234567890,
];
+
for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws(
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-year-zero.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-year-zero.js
index 6cd66acaf2..e869362840 100644
--- a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-year-zero.js
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-year-zero.js
@@ -16,7 +16,8 @@ const invalidStrings = [
"-000000-10-31T17:45+00:00[UTC]",
];
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
-invalidStrings.forEach((arg) => {
+invalidStrings.forEach((str) => {
+ const arg = { year: 1976, month: 11, day: 18, calendar: str };
assert.throws(
RangeError,
() => instance.since(arg),
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-string-calendar-annotation-invalid-key.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-string-calendar-annotation-invalid-key.js
new file mode 100644
index 0000000000..b5b7f9ce2c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/argument-string-calendar-annotation-invalid-key.js
@@ -0,0 +1,25 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.since
+description: Annotation keys are lowercase-only
+features: [Temporal]
+---*/
+
+const invalidStrings = [
+ ["1970-01-01T00:00[U-CA=iso8601]", "invalid capitalized key"],
+ ["1970-01-01T00:00[u-CA=iso8601]", "invalid partially-capitalized key"],
+ ["1970-01-01T00:00[FOO=bar]", "invalid capitalized unrecognized key"],
+];
+const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
+invalidStrings.forEach(([arg, descr]) => {
+ assert.throws(
+ RangeError,
+ () => instance.since(arg),
+ `annotation keys must be lowercase: ${arg} - ${descr}`
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/result-mixed-sign.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/result-mixed-sign.js
new file mode 100644
index 0000000000..838de26784
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/result-mixed-sign.js
@@ -0,0 +1,29 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.since
+description: >
+ RangeError when inconsistent custom calendar method causes mixed signs of
+ Duration components
+features: [Temporal]
+---*/
+
+// Test case provided by André Bargull
+
+const cal = new (class extends Temporal.Calendar {
+ dateAdd(date, duration, options) {
+ return super.dateAdd(date, duration.negated(), options);
+ }
+})("iso8601");
+
+const one = new Temporal.PlainDateTime(2000, 1, 1, 0, 0, 0, 0, 0, 0, cal);
+const two = new Temporal.PlainDateTime(2020, 5, 10, 12, 12, 0, 0, 0, 0, cal);
+
+assert.throws(RangeError, () => two.since(one, {
+ largestUnit: "years",
+ smallestUnit: "hours"
+}));
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/wrapping-at-end-of-month.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/wrapping-at-end-of-month.js
new file mode 100644
index 0000000000..23cecf8d1a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/since/wrapping-at-end-of-month.js
@@ -0,0 +1,120 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.since
+description: Tests balancing of days to months at end of month
+includes: [temporalHelpers.js]
+features: [Temporal]
+---*/
+
+// Difference between end of longer month to end of following shorter month
+{
+ const end = new Temporal.PlainDateTime(1970, 2, 28);
+ for (const largestUnit of ["years", "months"]) {
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 1, 28).since(end, { largestUnit }),
+ 0, -1, 0, 0, 0, 0, 0, 0, 0, 0,
+ "Jan 28th to Feb 28th is one month"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 1, 29).since(end, { largestUnit }),
+ 0, 0, 0, -30, 0, 0, 0, 0, 0, 0,
+ "Jan 29th to Feb 28th is 30 days, not one month"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 1, 30).since(end, { largestUnit }),
+ 0, 0, 0, -29, 0, 0, 0, 0, 0, 0,
+ "Jan 30th to Feb 28th is 29 days, not one month"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 1, 31).since(end, { largestUnit }),
+ 0, 0, 0, -28, 0, 0, 0, 0, 0, 0,
+ "Jan 31st to Feb 28th is 28 days, not one month"
+ );
+ }
+}
+
+// Difference between end of leap-year January to end of leap-year February
+{
+ const end = new Temporal.PlainDateTime(1972, 2, 29);
+ for (const largestUnit of ["years", "months"]) {
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1972, 1, 29).since(end, { largestUnit }),
+ 0, -1, 0, 0, 0, 0, 0, 0, 0, 0,
+ "Jan 29th to Feb 29th is one month"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1972, 1, 30).since(end, { largestUnit }),
+ 0, 0, 0, -30, 0, 0, 0, 0, 0, 0,
+ "Jan 30th to Feb 29th is 30 days, not one month"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1972, 1, 31).since(end, { largestUnit }),
+ 0, 0, 0, -29, 0, 0, 0, 0, 0, 0,
+ "Jan 31st to Feb 29th is 29 days, not one month"
+ );
+ }
+}
+
+// Difference between end of longer month to end of not-immediately-following
+// shorter month
+{
+ const end = new Temporal.PlainDateTime(1970, 11, 30);
+ for (const largestUnit of ["years", "months"]) {
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 8, 30).since(end, { largestUnit }),
+ 0, -3, 0, 0, 0, 0, 0, 0, 0, 0,
+ "Aug 30th to Nov 30th is 3 months"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 8, 31).since(end, { largestUnit }),
+ 0, -2, 0, -30, 0, 0, 0, 0, 0, 0,
+ "Aug 31st to Nov 30th is 2 months 30 days, not 3 months"
+ );
+ }
+}
+
+// Difference between end of longer month in one year to shorter month in
+// later year
+{
+ const end = new Temporal.PlainDateTime(1973, 4, 30);
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 12, 30).since(end, { largestUnit: "months" }),
+ 0, -28, 0, 0, 0, 0, 0, 0, 0, 0,
+ "Dec 30th 1970 to Apr 30th 1973 is 28 months"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 12, 30).since(end, { largestUnit: "years" }),
+ -2, -4, 0, 0, 0, 0, 0, 0, 0, 0,
+ "Dec 30th 1970 to Apr 30th 1973 is 2 years, 4 months"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 12, 31).since(end, { largestUnit: "months" }),
+ 0, -27, 0, -30, 0, 0, 0, 0, 0, 0,
+ "Dec 30th 1970 to Apr 30th 1973 is 27 months, 30 days, not 28 months"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 12, 31).since(end, { largestUnit: "years" }),
+ -2, -3, 0, -30, 0, 0, 0, 0, 0, 0,
+ "Dec 30th 1970 to Apr 30th 1973 is 2 years, 3 months, 30 days, not 2 years 4 months"
+ );
+}
+
+// Difference where months passes through a month that's the same length or
+// shorter than either the start or end month
+{
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 1, 29).since(new Temporal.PlainDateTime(1970, 3, 28), { largestUnit: "months" }),
+ 0, -1, 0, -28, 0, 0, 0, 0, 0, 0,
+ "Jan 29th to Mar 28th is 1 month 28 days, not 58 days"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 1, 31).since(new Temporal.PlainDateTime(1971, 5, 30), { largestUnit: "years" }),
+ -1, -3, 0, -30, 0, 0, 0, 0, 0, 0,
+ "Jan 31st 1970 to May 30th 1971 is 1 year, 3 months, 30 days, not 1 year, 2 months, 60 days"
+ );
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getoffsetnanosecondsfor-maximum-forward-offset-shift.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getoffsetnanosecondsfor-maximum-forward-offset-shift.js
new file mode 100644
index 0000000000..af7f128a9c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getoffsetnanosecondsfor-maximum-forward-offset-shift.js
@@ -0,0 +1,49 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.tozoneddatetime
+description: >
+ UTC offset shift returned by adjacent invocations of getOffsetNanosecondsFor
+ in DisambiguatePossibleInstants can be at most 24 hours.
+features: [Temporal]
+info: |
+ DisambiguatePossibleInstants:
+ 18. If abs(_nanoseconds_) > nsPerDay, throw a *RangeError* exception.
+---*/
+
+let calls = 0;
+
+class Shift24Hour extends Temporal.TimeZone {
+ id = 'TestTimeZone';
+ _shiftEpochNs = 12n * 3600n * 1_000_000_000n; // 1970-01-01T12:00Z
+
+ constructor() {
+ super('UTC');
+ }
+
+ getOffsetNanosecondsFor(instant) {
+ calls++;
+ if (instant.epochNanoseconds < this._shiftEpochNs) return -12 * 3600e9;
+ return 12 * 3600e9;
+ }
+
+ getPossibleInstantsFor(plainDateTime) {
+ const [utcInstant] = super.getPossibleInstantsFor(plainDateTime);
+ const { year, month, day } = plainDateTime;
+
+ if (year < 1970) return [utcInstant.subtract({ hours: 12 })];
+ if (year === 1970 && month === 1 && day === 1) return [];
+ return [utcInstant.add({ hours: 12 })];
+ }
+}
+
+const timeZone = new Shift24Hour();
+
+const instance = new Temporal.PlainDateTime(1970, 1, 1, 12);
+instance.toZonedDateTime(timeZone);
+
+assert(calls >= 2, "getOffsetNanosecondsFor should be called at least twice");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getoffsetnanosecondsfor-out-of-range-forward-offset-shift.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getoffsetnanosecondsfor-out-of-range-forward-offset-shift.js
new file mode 100644
index 0000000000..3fe9f52dbf
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getoffsetnanosecondsfor-out-of-range-forward-offset-shift.js
@@ -0,0 +1,44 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.tozoneddatetime
+description: >
+ UTC offset shift returned by adjacent invocations of getOffsetNanosecondsFor
+ in DisambiguatePossibleInstants cannot be greater than 24 hours.
+features: [Temporal]
+info: |
+ DisambiguatePossibleInstants:
+ 18. If abs(_nanoseconds_) > nsPerDay, throw a *RangeError* exception.
+---*/
+
+class ShiftLonger24Hour extends Temporal.TimeZone {
+ id = 'TestTimeZone';
+ _shiftEpochNs = 12n * 3600n * 1_000_000_000n; // 1970-01-01T12:00Z
+
+ constructor() {
+ super('UTC');
+ }
+
+ getOffsetNanosecondsFor(instant) {
+ if (instant.epochNanoseconds < this._shiftEpochNs) return -12 * 3600e9;
+ return 12 * 3600e9 + 1;
+ }
+
+ getPossibleInstantsFor(plainDateTime) {
+ const [utcInstant] = super.getPossibleInstantsFor(plainDateTime);
+ const { year, month, day } = plainDateTime;
+
+ if (year < 1970) return [utcInstant.subtract({ hours: 12 })];
+ if (year === 1970 && month === 1 && day === 1) return [];
+ return [utcInstant.add({ hours: 12, nanoseconds: 1 })];
+ }
+}
+
+const timeZone = new ShiftLonger24Hour();
+
+const instance = new Temporal.PlainDateTime(1970, 1, 1, 12);
+assert.throws(RangeError, () => instance.toZonedDateTime(timeZone), "RangeError should be thrown");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getpossibleinstantsfor-maximum-backward-offset-shift.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getpossibleinstantsfor-maximum-backward-offset-shift.js
new file mode 100644
index 0000000000..a1a8898838
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getpossibleinstantsfor-maximum-backward-offset-shift.js
@@ -0,0 +1,53 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.tozoneddatetime
+description: >
+ UTC offset shift returned by getPossibleInstantsFor can be at most 24 hours.
+features: [Temporal]
+info: |
+ GetPossibleInstantsFor:
+ 5.b.i. Let _numResults_ be _list_'s length.
+ ii. If _numResults_ > 1, then
+ 1. Let _epochNs_ be a new empty List.
+ 2. For each value _instant_ in list, do
+ a. Append _instant_.[[EpochNanoseconds]] to the end of the List _epochNs_.
+ 3. Let _min_ be the least element of the List _epochNs_.
+ 4. Let _max_ be the greatest element of the List _epochNs_.
+ 5. If abs(ℝ(_max_ - _min_)) > nsPerDay, throw a *RangeError* exception.
+---*/
+
+let calls = 0;
+
+class Shift24Hour extends Temporal.TimeZone {
+ id = 'TestTimeZone';
+
+ constructor() {
+ super('UTC');
+ }
+
+ getOffsetNanosecondsFor(instant) {
+ return 0;
+ }
+
+ getPossibleInstantsFor(plainDateTime) {
+ calls++;
+ const utc = new Temporal.TimeZone("UTC");
+ const [utcInstant] = utc.getPossibleInstantsFor(plainDateTime);
+ return [
+ utcInstant.subtract({ hours: 12 }),
+ utcInstant.add({ hours: 12 })
+ ];
+ }
+}
+
+const timeZone = new Shift24Hour();
+
+const instance = new Temporal.PlainDateTime(1970, 1, 1, 12);
+instance.toZonedDateTime(timeZone);
+
+assert(calls >= 1, "getPossibleInstantsFor should be called at least once");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getpossibleinstantsfor-out-of-range-backward-offset-shift.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getpossibleinstantsfor-out-of-range-backward-offset-shift.js
new file mode 100644
index 0000000000..29703ed59f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/getpossibleinstantsfor-out-of-range-backward-offset-shift.js
@@ -0,0 +1,49 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.tozoneddatetime
+description: >
+ UTC offset shift returned by getPossibleInstantsFor can be at most 24 hours.
+features: [Temporal]
+info: |
+ GetPossibleInstantsFor:
+ 5.b.i. Let _numResults_ be _list_'s length.
+ ii. If _numResults_ > 1, then
+ 1. Let _epochNs_ be a new empty List.
+ 2. For each value _instant_ in list, do
+ a. Append _instant_.[[EpochNanoseconds]] to the end of the List _epochNs_.
+ 3. Let _min_ be the least element of the List _epochNs_.
+ 4. Let _max_ be the greatest element of the List _epochNs_.
+ 5. If abs(ℝ(_max_ - _min_)) > nsPerDay, throw a *RangeError* exception.
+---*/
+
+class ShiftLonger24Hour extends Temporal.TimeZone {
+ id = 'TestTimeZone';
+
+ constructor() {
+ super('UTC');
+ }
+
+ getOffsetNanosecondsFor(instant) {
+ return 0;
+ }
+
+ getPossibleInstantsFor(plainDateTime) {
+ const utc = new Temporal.TimeZone("UTC");
+ const [utcInstant] = utc.getPossibleInstantsFor(plainDateTime);
+ return [
+ utcInstant.subtract({ hours: 12, nanoseconds: 1 }),
+ utcInstant.add({ hours: 12 }),
+ utcInstant, // add a third value in case the implementation doesn't sort
+ ];
+ }
+}
+
+const timeZone = new ShiftLonger24Hour();
+
+const instance = new Temporal.PlainDateTime(1970, 1, 1, 12);
+assert.throws(RangeError, () => instance.toZonedDateTime(timeZone), "RangeError should be thrown");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-iso-string.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-iso-string.js
new file mode 100644
index 0000000000..0f06b77fa8
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-iso-string.js
@@ -0,0 +1,29 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.until
+description: An ISO 8601 string can be converted to a calendar ID in Calendar
+includes: [temporalHelpers.js]
+features: [Temporal]
+---*/
+
+const instance = new Temporal.PlainDateTime(1976, 11, 18);
+
+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.until(arg);
+ TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, `Calendar created from string "${calendar}"`);
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number.js
index cf43c5a168..ab3cea6b6c 100644
--- a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number.js
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number.js
@@ -8,7 +8,7 @@ description: A number as calendar in a property bag is not accepted
features: [Temporal]
---*/
-const instance = new Temporal.PlainDate(1976, 11, 18);
+const instance = new Temporal.PlainDateTime(1976, 11, 18);
const numbers = [
1,
@@ -16,6 +16,7 @@ const numbers = [
-19970327,
1234567890,
];
+
for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws(
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-year-zero.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-year-zero.js
index 099de48b51..b1d165cc6e 100644
--- a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-year-zero.js
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-year-zero.js
@@ -16,7 +16,8 @@ const invalidStrings = [
"-000000-10-31T17:45+00:00[UTC]",
];
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
-invalidStrings.forEach((arg) => {
+invalidStrings.forEach((str) => {
+ const arg = { year: 1976, month: 11, day: 18, calendar: str };
assert.throws(
RangeError,
() => instance.until(arg),
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-string-calendar-annotation-invalid-key.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-string-calendar-annotation-invalid-key.js
new file mode 100644
index 0000000000..94dcaf9e99
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/argument-string-calendar-annotation-invalid-key.js
@@ -0,0 +1,25 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.until
+description: Annotation keys are lowercase-only
+features: [Temporal]
+---*/
+
+const invalidStrings = [
+ ["1970-01-01T00:00[U-CA=iso8601]", "invalid capitalized key"],
+ ["1970-01-01T00:00[u-CA=iso8601]", "invalid partially-capitalized key"],
+ ["1970-01-01T00:00[FOO=bar]", "invalid capitalized unrecognized key"],
+];
+const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
+invalidStrings.forEach(([arg, descr]) => {
+ assert.throws(
+ RangeError,
+ () => instance.until(arg),
+ `annotation keys must be lowercase: ${arg} - ${descr}`
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/no-unnecessary-units.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/no-unnecessary-units.js
index 7e311f8dca..8966496ca9 100644
--- a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/no-unnecessary-units.js
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/no-unnecessary-units.js
@@ -9,17 +9,17 @@ features: [Temporal]
includes: [temporalHelpers.js]
---*/
-const feb29 = new Temporal.PlainDateTime(2020, 2, 29, 0, 0);
-const feb28 = new Temporal.PlainDateTime(2021, 2, 28, 0, 0);
+const lastFeb21 = new Temporal.PlainDateTime(2021, 2, 28);
+const lastFeb22 = new Temporal.PlainDateTime(2022, 2, 28);
TemporalHelpers.assertDuration(
- feb29.until(feb28, { largestUnit: "months" }),
+ lastFeb21.until(lastFeb22, { largestUnit: "months" }),
0, 12, 0, 0, 0, 0, 0, 0, 0, 0,
"does not include higher units than necessary (largest unit = months)"
);
TemporalHelpers.assertDuration(
- feb29.until(feb28, { largestUnit: "years" }),
+ lastFeb21.until(lastFeb22, { largestUnit: "years" }),
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
"does not include higher units than necessary (largest unit = years)"
);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/result-mixed-sign.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/result-mixed-sign.js
new file mode 100644
index 0000000000..7287c706b9
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/result-mixed-sign.js
@@ -0,0 +1,29 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.until
+description: >
+ RangeError when inconsistent custom calendar method causes mixed signs of
+ Duration components
+features: [Temporal]
+---*/
+
+// Test case provided by André Bargull
+
+const cal = new (class extends Temporal.Calendar {
+ dateAdd(date, duration, options) {
+ return super.dateAdd(date, duration.negated(), options);
+ }
+})("iso8601");
+
+const one = new Temporal.PlainDateTime(2000, 1, 1, 0, 0, 0, 0, 0, 0, cal);
+const two = new Temporal.PlainDateTime(2020, 5, 10, 12, 12, 0, 0, 0, 0, cal);
+
+assert.throws(RangeError, () => one.until(two, {
+ largestUnit: "years",
+ smallestUnit: "hours"
+}));
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/wrapping-at-end-of-month.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/wrapping-at-end-of-month.js
new file mode 100644
index 0000000000..3a83eb2138
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/until/wrapping-at-end-of-month.js
@@ -0,0 +1,120 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.until
+description: Tests balancing of days to months at end of month
+includes: [temporalHelpers.js]
+features: [Temporal]
+---*/
+
+// Difference between end of longer month to end of following shorter month
+{
+ const end = new Temporal.PlainDateTime(1970, 2, 28);
+ for (const largestUnit of ["years", "months"]) {
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 1, 28).until(end, { largestUnit }),
+ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
+ "Jan 28th to Feb 28th is one month"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 1, 29).until(end, { largestUnit }),
+ 0, 0, 0, 30, 0, 0, 0, 0, 0, 0,
+ "Jan 29th to Feb 28th is 30 days, not one month"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 1, 30).until(end, { largestUnit }),
+ 0, 0, 0, 29, 0, 0, 0, 0, 0, 0,
+ "Jan 30th to Feb 28th is 29 days, not one month"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 1, 31).until(end, { largestUnit }),
+ 0, 0, 0, 28, 0, 0, 0, 0, 0, 0,
+ "Jan 31st to Feb 28th is 28 days, not one month"
+ );
+ }
+}
+
+// Difference between end of leap-year January to end of leap-year February
+{
+ const end = new Temporal.PlainDateTime(1972, 2, 29);
+ for (const largestUnit of ["years", "months"]) {
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1972, 1, 29).until(end, { largestUnit }),
+ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
+ "Jan 29th to Feb 29th is one month"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1972, 1, 30).until(end, { largestUnit }),
+ 0, 0, 0, 30, 0, 0, 0, 0, 0, 0,
+ "Jan 30th to Feb 29th is 30 days, not one month"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1972, 1, 31).until(end, { largestUnit }),
+ 0, 0, 0, 29, 0, 0, 0, 0, 0, 0,
+ "Jan 31st to Feb 29th is 29 days, not one month"
+ );
+ }
+}
+
+// Difference between end of longer month to end of not-immediately-following
+// shorter month
+{
+ const end = new Temporal.PlainDateTime(1970, 11, 30);
+ for (const largestUnit of ["years", "months"]) {
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 8, 30).until(end, { largestUnit }),
+ 0, 3, 0, 0, 0, 0, 0, 0, 0, 0,
+ "Aug 30th to Nov 30th is 3 months"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 8, 31).until(end, { largestUnit }),
+ 0, 2, 0, 30, 0, 0, 0, 0, 0, 0,
+ "Aug 31st to Nov 30th is 2 months 30 days, not 3 months"
+ );
+ }
+}
+
+// Difference between end of longer month in one year to shorter month in
+// later year
+{
+ const end = new Temporal.PlainDateTime(1973, 4, 30);
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 12, 30).until(end, { largestUnit: "months" }),
+ 0, 28, 0, 0, 0, 0, 0, 0, 0, 0,
+ "Dec 30th 1970 to Apr 30th 1973 is 28 months"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 12, 30).until(end, { largestUnit: "years" }),
+ 2, 4, 0, 0, 0, 0, 0, 0, 0, 0,
+ "Dec 30th 1970 to Apr 30th 1973 is 2 years, 4 months"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 12, 31).until(end, { largestUnit: "months" }),
+ 0, 27, 0, 30, 0, 0, 0, 0, 0, 0,
+ "Dec 30th 1970 to Apr 30th 1973 is 27 months, 30 days, not 28 months"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 12, 31).until(end, { largestUnit: "years" }),
+ 2, 3, 0, 30, 0, 0, 0, 0, 0, 0,
+ "Dec 30th 1970 to Apr 30th 1973 is 2 years, 3 months, 30 days, not 2 years 4 months"
+ );
+}
+
+// Difference where months passes through a month that's the same length or
+// shorter than either the start or end month
+{
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 1, 29).until(new Temporal.PlainDateTime(1970, 3, 28), { largestUnit: "months" }),
+ 0, 1, 0, 28, 0, 0, 0, 0, 0, 0,
+ "Jan 29th to Mar 28th is 1 month 28 days, not 58 days"
+ );
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDateTime(1970, 1, 31).until(new Temporal.PlainDateTime(1971, 5, 30), { largestUnit: "years" }),
+ 1, 3, 0, 30, 0, 0, 0, 0, 0, 0,
+ "Jan 31st 1970 to May 30th 1971 is 1 year, 3 months, 30 days, not 1 year, 2 months, 60 days"
+ );
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/custom-calendar-weekofyear.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/custom-calendar-weekofyear.js
new file mode 100644
index 0000000000..97242a19c4
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/custom-calendar-weekofyear.js
@@ -0,0 +1,26 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.weekofyear
+description: >
+ Temporal.PlainDateTime.prototype.weekOfYear returns undefined for all
+ custom calendars where weekOfYear() returns undefined.
+features: [Temporal]
+---*/
+
+class CustomCalendar extends Temporal.Calendar {
+ constructor() {
+ super("iso8601");
+ }
+ weekOfYear() {
+ return undefined;
+ }
+}
+
+const calendar = new CustomCalendar();
+const customCalendarDate = new Temporal.PlainDateTime(2024, 1, 1, 12, 34, 56, 987, 654, 321, calendar);
+assert.sameValue(customCalendarDate.weekOfYear, undefined);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/validate-calendar-value.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/validate-calendar-value.js
index d1624e1617..89d47a3566 100644
--- a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/validate-calendar-value.js
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/validate-calendar-value.js
@@ -9,7 +9,6 @@ features: [Temporal]
---*/
const badResults = [
- [undefined, TypeError],
[null, TypeError],
[false, TypeError],
[Infinity, RangeError],
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-iso-string.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-iso-string.js
new file mode 100644
index 0000000000..7ba0d5a207
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-iso-string.js
@@ -0,0 +1,49 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.withcalendar
+description: An ISO 8601 string can be converted to a calendar ID in Calendar
+features: [Temporal]
+---*/
+
+const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, {
+ dateAdd() {},
+ dateFromFields() {},
+ dateUntil() {},
+ day() {},
+ dayOfWeek() {},
+ dayOfYear() {},
+ daysInMonth() {},
+ daysInWeek() {},
+ daysInYear() {},
+ fields() {},
+ id: "replace-me",
+ inLeapYear() {},
+ mergeFields() {},
+ month() {},
+ monthCode() {},
+ monthDayFromFields() {},
+ monthsInYear() {},
+ weekOfYear() {},
+ year() {},
+ yearMonthFromFields() {},
+ yearOfWeek() {},
+});
+
+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 = instance.withCalendar(arg);
+ assert.sameValue(result.getISOFields().calendar, "iso8601", `Calendar created from string "${arg}"`);
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-iso-string.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-iso-string.js
new file mode 100644
index 0000000000..e514b4b7d3
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-iso-string.js
@@ -0,0 +1,29 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.withplaindate
+description: An ISO 8601 string can be converted to a calendar ID in Calendar
+includes: [temporalHelpers.js]
+features: [Temporal]
+---*/
+
+const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
+
+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.withPlainDate(arg);
+ TemporalHelpers.assertPlainDateTime(result, 1976, 11, "M11", 18, 12, 34, 56, 987, 654, 321, `Calendar created from string "${calendar}"`);
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js
index cbd1950207..57c77ae669 100644
--- a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js
@@ -8,7 +8,7 @@ description: A number as calendar in a property bag is not accepted
features: [Temporal]
---*/
-const instance = new Temporal.PlainDate(1976, 11, 18);
+const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
const numbers = [
1,
@@ -16,6 +16,7 @@ const numbers = [
-19970327,
1234567890,
];
+
for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws(
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-year-zero.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-year-zero.js
index d39551d616..201aba871b 100644
--- a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-year-zero.js
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-year-zero.js
@@ -16,7 +16,8 @@ const invalidStrings = [
"-000000-10-31T17:45+00:00[UTC]",
];
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
-invalidStrings.forEach((arg) => {
+invalidStrings.forEach((str) => {
+ const arg = { year: 1976, month: 11, day: 18, calendar: str };
assert.throws(
RangeError,
() => instance.withPlainDate(arg),
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-string-calendar-annotation-invalid-key.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-string-calendar-annotation-invalid-key.js
new file mode 100644
index 0000000000..8f9827733c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-string-calendar-annotation-invalid-key.js
@@ -0,0 +1,25 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.withplaindate
+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.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
+invalidStrings.forEach(([arg, descr]) => {
+ assert.throws(
+ RangeError,
+ () => instance.withPlainDate(arg),
+ `annotation keys must be lowercase: ${arg} - ${descr}`
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-calendar-annotation-invalid-key.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-calendar-annotation-invalid-key.js
new file mode 100644
index 0000000000..5d63e53dc4
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-calendar-annotation-invalid-key.js
@@ -0,0 +1,31 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.withplaintime
+description: Annotation keys are lowercase-only
+features: [Temporal]
+---*/
+
+const invalidStrings = [
+ ["00:00[U-CA=iso8601]", "invalid capitalized key, time-only"],
+ ["T00:00[U-CA=iso8601]", "invalid capitalized key, time designator"],
+ ["1970-01-01T00:00[U-CA=iso8601]", "invalid capitalized key"],
+ ["00:00[u-CA=iso8601]", "invalid partially-capitalized key, time-only"],
+ ["T00:00[u-CA=iso8601]", "invalid partially-capitalized key, time designator"],
+ ["1970-01-01T00:00[u-CA=iso8601]", "invalid partially-capitalized key"],
+ ["00:00[FOO=bar]", "invalid capitalized unrecognized key, time-only"],
+ ["T00:00[FOO=bar]", "invalid capitalized unrecognized key, time designator"],
+ ["1970-01-01T00:00[FOO=bar]", "invalid capitalized unrecognized key"],
+];
+const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
+invalidStrings.forEach(([arg, descr]) => {
+ assert.throws(
+ RangeError,
+ () => instance.withPlainTime(arg),
+ `annotation keys must be lowercase: ${arg} - ${descr}`
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/custom-calendar-weekofyear.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/custom-calendar-weekofyear.js
new file mode 100644
index 0000000000..81b9ae2086
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/custom-calendar-weekofyear.js
@@ -0,0 +1,26 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.yearofweek
+description: >
+ Temporal.PlainDateTime.prototype.yearOfWeek returns undefined for all
+ custom calendars where yearOfWeek() returns undefined.
+features: [Temporal]
+---*/
+
+class CustomCalendar extends Temporal.Calendar {
+ constructor() {
+ super("iso8601");
+ }
+ yearOfWeek() {
+ return undefined;
+ }
+}
+
+const calendar = new CustomCalendar();
+const customCalendarDate = new Temporal.PlainDateTime(2024, 1, 1, 12, 34, 56, 987, 654, 321, calendar);
+assert.sameValue(customCalendarDate.yearOfWeek, undefined);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/validate-calendar-value.js b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/validate-calendar-value.js
index cd43fd4474..8c67a02491 100644
--- a/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/validate-calendar-value.js
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/validate-calendar-value.js
@@ -9,7 +9,6 @@ features: [Temporal]
---*/
const badResults = [
- [undefined, TypeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[Symbol("foo"), TypeError],