summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until')
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-iso-string.js29
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-year-zero.js3
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/argument-string-calendar-annotation-invalid-key.js25
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/largestunit-higher-units.js10
-rw-r--r--js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/wrapping-at-end-of-month.js120
5 files changed, 181 insertions, 6 deletions
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-iso-string.js b/js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-iso-string.js
new file mode 100644
index 0000000000..2ec1c255b3
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDate/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.plaindate.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.PlainDate(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/PlainDate/prototype/until/argument-propertybag-calendar-year-zero.js b/js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-year-zero.js
index abe100487e..5111e057ee 100644
--- a/js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-year-zero.js
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDate/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.PlainDate(2000, 5, 2);
-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/PlainDate/prototype/until/argument-string-calendar-annotation-invalid-key.js b/js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/argument-string-calendar-annotation-invalid-key.js
new file mode 100644
index 0000000000..38bba39b1d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDate/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.plaindate.prototype.until
+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.PlainDate(2000, 5, 2);
+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/PlainDate/prototype/until/largestunit-higher-units.js b/js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/largestunit-higher-units.js
index a8f8812d9d..5962cf31bc 100644
--- a/js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/largestunit-higher-units.js
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/largestunit-higher-units.js
@@ -20,10 +20,10 @@ TemporalHelpers.assertDuration(feb20.until(feb21, { largestUnit: "years" }), /*
TemporalHelpers.assertDuration(feb20.until(feb21, { largestUnit: "months" }), 0, /* months = */ 12, 0, 0, 0, 0, 0, 0, 0, 0, "start of February, months");
TemporalHelpers.assertDuration(feb20.until(feb21, { largestUnit: "weeks" }), 0, 0, /* weeks = */ 52, /* days = */ 2, 0, 0, 0, 0, 0, 0, "start of February, weeks");
-const lastFeb20 = Temporal.PlainDate.from("2020-02-29");
-const lastFeb21 = Temporal.PlainDate.from("2021-02-28");
-TemporalHelpers.assertDuration(lastFeb20.until(lastFeb21, { largestUnit: "years" }), /* years = */ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "end of February, years");
-TemporalHelpers.assertDuration(lastFeb20.until(lastFeb21, { largestUnit: "months" }), 0, /* months = */ 12, 0, 0, 0, 0, 0, 0, 0, 0, "end of February, months");
-TemporalHelpers.assertDuration(lastFeb20.until(lastFeb21, { largestUnit: "weeks" }), 0, 0, /* weeks = */ 52, /* days = */ 1, 0, 0, 0, 0, 0, 0, "end of February, weeks");
+const lastFeb21 = new Temporal.PlainDate(2021, 2, 28);
+const lastFeb22 = new Temporal.PlainDate(2022, 2, 28);
+TemporalHelpers.assertDuration(lastFeb21.until(lastFeb22, { largestUnit: "years" }), /* years = */ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "end of February, years");
+TemporalHelpers.assertDuration(lastFeb21.until(lastFeb22, { largestUnit: "months" }), 0, /* months = */ 12, 0, 0, 0, 0, 0, 0, 0, 0, "end of February, months");
+TemporalHelpers.assertDuration(lastFeb21.until(lastFeb22, { largestUnit: "weeks" }), 0, 0, /* weeks = */ 52, /* days = */ 1, 0, 0, 0, 0, 0, 0, "end of February, weeks");
reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/wrapping-at-end-of-month.js b/js/src/tests/test262/built-ins/Temporal/PlainDate/prototype/until/wrapping-at-end-of-month.js
new file mode 100644
index 0000000000..082ba05283
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/PlainDate/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.plaindate.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.PlainDate(1970, 2, 28);
+ for (const largestUnit of ["years", "months"]) {
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDate(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.PlainDate(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.PlainDate(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.PlainDate(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.PlainDate(1972, 2, 29);
+ for (const largestUnit of ["years", "months"]) {
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDate(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.PlainDate(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.PlainDate(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.PlainDate(1970, 11, 30);
+ for (const largestUnit of ["years", "months"]) {
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDate(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.PlainDate(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.PlainDate(1973, 4, 30);
+ TemporalHelpers.assertDuration(
+ new Temporal.PlainDate(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.PlainDate(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.PlainDate(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.PlainDate(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.PlainDate(1970, 1, 29).until(new Temporal.PlainDate(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.PlainDate(1970, 1, 31).until(new Temporal.PlainDate(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);