From 3b2bc2c5b690f1f642e02b2ce37378e742240223 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 18 Nov 2025 16:47:58 -0800 Subject: [PATCH] Temporal: Add tests for date differencing across era boundaries for Hijri and Ethiopic calendars --- .../prototype/since/era-boundary-ethiopic.js | 90 +++++++++++++++++++ .../since/era-boundary-islamic-civil.js | 77 ++++++++++++++++ .../since/era-boundary-islamic-tbla.js | 77 ++++++++++++++++ .../since/era-boundary-islamic-umalqura.js | 77 ++++++++++++++++ .../prototype/until/era-boundary-ethiopic.js | 90 +++++++++++++++++++ .../until/era-boundary-islamic-civil.js | 77 ++++++++++++++++ .../until/era-boundary-islamic-tbla.js | 77 ++++++++++++++++ .../until/era-boundary-islamic-umalqura.js | 77 ++++++++++++++++ .../prototype/since/era-boundary-ethiopic.js | 90 +++++++++++++++++++ .../since/era-boundary-islamic-civil.js | 77 ++++++++++++++++ .../since/era-boundary-islamic-tbla.js | 77 ++++++++++++++++ .../since/era-boundary-islamic-umalqura.js | 77 ++++++++++++++++ .../prototype/until/era-boundary-ethiopic.js | 90 +++++++++++++++++++ .../until/era-boundary-islamic-civil.js | 77 ++++++++++++++++ .../until/era-boundary-islamic-tbla.js | 77 ++++++++++++++++ .../until/era-boundary-islamic-umalqura.js | 77 ++++++++++++++++ .../prototype/since/era-boundary-ethiopic.js | 90 +++++++++++++++++++ .../since/era-boundary-islamic-civil.js | 77 ++++++++++++++++ .../since/era-boundary-islamic-tbla.js | 77 ++++++++++++++++ .../since/era-boundary-islamic-umalqura.js | 77 ++++++++++++++++ .../prototype/until/era-boundary-ethiopic.js | 90 +++++++++++++++++++ .../until/era-boundary-islamic-civil.js | 77 ++++++++++++++++ .../until/era-boundary-islamic-tbla.js | 77 ++++++++++++++++ .../until/era-boundary-islamic-umalqura.js | 77 ++++++++++++++++ 24 files changed, 1926 insertions(+) create mode 100644 test/intl402/Temporal/PlainDate/prototype/since/era-boundary-ethiopic.js create mode 100644 test/intl402/Temporal/PlainDate/prototype/since/era-boundary-islamic-civil.js create mode 100644 test/intl402/Temporal/PlainDate/prototype/since/era-boundary-islamic-tbla.js create mode 100644 test/intl402/Temporal/PlainDate/prototype/since/era-boundary-islamic-umalqura.js create mode 100644 test/intl402/Temporal/PlainDate/prototype/until/era-boundary-ethiopic.js create mode 100644 test/intl402/Temporal/PlainDate/prototype/until/era-boundary-islamic-civil.js create mode 100644 test/intl402/Temporal/PlainDate/prototype/until/era-boundary-islamic-tbla.js create mode 100644 test/intl402/Temporal/PlainDate/prototype/until/era-boundary-islamic-umalqura.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-ethiopic.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-islamic-civil.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-islamic-tbla.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-islamic-umalqura.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-ethiopic.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-islamic-civil.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-islamic-tbla.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-islamic-umalqura.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-ethiopic.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-islamic-civil.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-islamic-tbla.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-islamic-umalqura.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-ethiopic.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-islamic-civil.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-islamic-tbla.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-islamic-umalqura.js diff --git a/test/intl402/Temporal/PlainDate/prototype/since/era-boundary-ethiopic.js b/test/intl402/Temporal/PlainDate/prototype/since/era-boundary-ethiopic.js new file mode 100644 index 0000000000..e50c053d0c --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/since/era-boundary-ethiopic.js @@ -0,0 +1,90 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "ethiopic"; +const options = { overflow: "reject" }; + +const aa5500 = Temporal.PlainDate.from({ era: "aa", eraYear: 5500, monthCode: "M01", day: 1, calendar }, options); +const am1 = Temporal.PlainDate.from({ era: "am", eraYear: 1, monthCode: "M01", day: 1, calendar }, options); +const am2000 = Temporal.PlainDate.from({ era: "am", eraYear: 2000, monthCode: "M06", day: 15, calendar }, options); +const am2005 = Temporal.PlainDate.from({ era: "am", eraYear: 2005, monthCode: "M06", day: 15, calendar }, options); +const aa5450 = Temporal.PlainDate.from({ era: "aa", eraYear: 5450, monthCode: "M07", day: 12, calendar }, options); +const aa5455 = Temporal.PlainDate.from({ era: "aa", eraYear: 5455, monthCode: "M07", day: 12, calendar }, options); +const am5 = Temporal.PlainDate.from({ era: "am", eraYear: 5, monthCode: "M01", day: 1, calendar }, options); + +const tests = [ + // From 5500 AA to 1 AM + [ + aa5500, am1, + [-1, 0, 0, 0, "-1y backwards from 5500 AA to 1 AM"], + [0, -13, 0, 0, 0, "-13mo backwards from 5500 AA to 1 AM"], + ], + [ + am1, aa5500, + [1, 0, 0, 0, "1y from 5500 AA to 1 AM"], + [0, 13, 0, 0, 0, "13mo from 1 AM to 5500 AA"], + ], + // From 2000 AM to 2005 AM + [ + am2000, am2005, + [-5, 0, 0, 0, "-5y backwards from 2000 AM to 2005 AM"], + [0, -65, 0, 0, "-65mo backwards from 2000 AM to 2005 AM"], + ], + [ + am2005, am2000, + [5, 0, 0, 0, "5y from 2000 AM to 2005 AM"], + [0, 65, 0, 0, "65mo from 2000 AM to 2005 AM"], + ], + // From 5450 AA to 5455 AA + [ + aa5450, aa5455, + [-5, 0, 0, 0, "-5y backwards from 5450 AA to 5455 AA"], + [0, -65, 0, 0, "-65mo backwards from 5450 AA to 5455 AA"], + ], + [ + aa5455, aa5450, + [5, 0, 0, 0, "5y from 5450 AA to 5455 AA"], + [0, 65, 0, 0, "65mo from 5450 AA to 5455 AA"], + ], + // From 5 AM to 5500 AA + [ + aa5500, am5, + [-5, 0, 0, 0, "-5y backwards from 5 AM to 5500 AA"], + [0, -65, 0, 0, "-65mo backwards from 5 AM to 5500 AA"], + ], + [ + am5, aa5500, + [5, 0, 0, 0, "5y from 5 AM to 5500 AA"], + [0, 65, 0, 0, "65mo from 5 AM to 5500 AA"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.since(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.since(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.since(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.since(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.since(two); + const resultDaysISO = oneISO.since(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/PlainDate/prototype/since/era-boundary-islamic-civil.js b/test/intl402/Temporal/PlainDate/prototype/since/era-boundary-islamic-civil.js new file mode 100644 index 0000000000..e888e01cda --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/since/era-boundary-islamic-civil.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-civil"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.PlainDate.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, calendar }, options); +const bh2 = Temporal.PlainDate.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, calendar }, options); +const bh1 = Temporal.PlainDate.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, calendar }, options); +const ah1 = Temporal.PlainDate.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, calendar }, options); +const ah2 = Temporal.PlainDate.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, calendar }, options); +const ah5 = Temporal.PlainDate.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.since(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.since(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.since(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.since(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.since(two); + const resultDaysISO = oneISO.since(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/PlainDate/prototype/since/era-boundary-islamic-tbla.js b/test/intl402/Temporal/PlainDate/prototype/since/era-boundary-islamic-tbla.js new file mode 100644 index 0000000000..8a44158cfb --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/since/era-boundary-islamic-tbla.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-tbla"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.PlainDate.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, calendar }, options); +const bh2 = Temporal.PlainDate.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, calendar }, options); +const bh1 = Temporal.PlainDate.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, calendar }, options); +const ah1 = Temporal.PlainDate.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, calendar }, options); +const ah2 = Temporal.PlainDate.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, calendar }, options); +const ah5 = Temporal.PlainDate.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.since(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.since(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.since(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.since(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.since(two); + const resultDaysISO = oneISO.since(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/PlainDate/prototype/since/era-boundary-islamic-umalqura.js b/test/intl402/Temporal/PlainDate/prototype/since/era-boundary-islamic-umalqura.js new file mode 100644 index 0000000000..ac6022c28f --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/since/era-boundary-islamic-umalqura.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-umalqura"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.PlainDate.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, calendar }, options); +const bh2 = Temporal.PlainDate.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, calendar }, options); +const bh1 = Temporal.PlainDate.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, calendar }, options); +const ah1 = Temporal.PlainDate.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, calendar }, options); +const ah2 = Temporal.PlainDate.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, calendar }, options); +const ah5 = Temporal.PlainDate.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.since(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.since(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.since(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.since(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.since(two); + const resultDaysISO = oneISO.since(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/PlainDate/prototype/until/era-boundary-ethiopic.js b/test/intl402/Temporal/PlainDate/prototype/until/era-boundary-ethiopic.js new file mode 100644 index 0000000000..ed93f5949c --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/until/era-boundary-ethiopic.js @@ -0,0 +1,90 @@ +// Copyright (C) 2025 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: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "ethiopic"; +const options = { overflow: "reject" }; + +const aa5500 = Temporal.PlainDate.from({ era: "aa", eraYear: 5500, monthCode: "M01", day: 1, calendar }, options); +const am1 = Temporal.PlainDate.from({ era: "am", eraYear: 1, monthCode: "M01", day: 1, calendar }, options); +const am2000 = Temporal.PlainDate.from({ era: "am", eraYear: 2000, monthCode: "M06", day: 15, calendar }, options); +const am2005 = Temporal.PlainDate.from({ era: "am", eraYear: 2005, monthCode: "M06", day: 15, calendar }, options); +const aa5450 = Temporal.PlainDate.from({ era: "aa", eraYear: 5450, monthCode: "M07", day: 12, calendar }, options); +const aa5455 = Temporal.PlainDate.from({ era: "aa", eraYear: 5455, monthCode: "M07", day: 12, calendar }, options); +const am5 = Temporal.PlainDate.from({ era: "am", eraYear: 5, monthCode: "M01", day: 1, calendar }, options); + +const tests = [ + // From 5500 AA to 1 AM + [ + aa5500, am1, + [1, 0, 0, 0, "1y from 5500 AA to 1 AM"], + [0, 13, 0, 0, 0, "13mo from 5500 AA to 1 AM"], + ], + [ + am1, aa5500, + [-1, 0, 0, 0, "-1y backwards from 5500 AA to 1 AM"], + [0, -13, 0, 0, 0, "-13mo backwards from 1 AM to 5500 AA"], + ], + // From 2000 AM to 2005 AM + [ + am2000, am2005, + [5, 0, 0, 0, "5y from 2000 AM to 2005 AM"], + [0, 65, 0, 0, "65mo from 2000 AM to 2005 AM"], + ], + [ + am2005, am2000, + [-5, 0, 0, 0, "-5y backwards from 2000 AM to 2005 AM"], + [0, -65, 0, 0, "-65mo backwards from 2000 AM to 2005 AM"], + ], + // From 5450 AA to 5455 AA + [ + aa5450, aa5455, + [5, 0, 0, 0, "5y from 5450 AA to 5455 AA"], + [0, 65, 0, 0, "65mo from 5450 AA to 5455 AA"], + ], + [ + aa5455, aa5450, + [-5, 0, 0, 0, "-5y backwards from 5450 AA to 5455 AA"], + [0, -65, 0, 0, "-65mo backwards from 5450 AA to 5455 AA"], + ], + // From 5 AM to 5500 AA + [ + aa5500, am5, + [5, 0, 0, 0, "5y from 5 AM to 5500 AA"], + [0, 65, 0, 0, "65mo from 5 AM to 5500 AA"], + ], + [ + am5, aa5500, + [-5, 0, 0, 0, "-5y backwards from 5 AM to 5500 AA"], + [0, -65, 0, 0, "-65mo backwards from 5 AM to 5500 AA"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.until(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.until(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.until(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.until(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.until(two); + const resultDaysISO = oneISO.until(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/PlainDate/prototype/until/era-boundary-islamic-civil.js b/test/intl402/Temporal/PlainDate/prototype/until/era-boundary-islamic-civil.js new file mode 100644 index 0000000000..6fd7d50c44 --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/until/era-boundary-islamic-civil.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 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: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-civil"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.PlainDate.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, calendar }, options); +const bh2 = Temporal.PlainDate.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, calendar }, options); +const bh1 = Temporal.PlainDate.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, calendar }, options); +const ah1 = Temporal.PlainDate.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, calendar }, options); +const ah2 = Temporal.PlainDate.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, calendar }, options); +const ah5 = Temporal.PlainDate.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.until(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.until(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.until(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.until(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.until(two); + const resultDaysISO = oneISO.until(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/PlainDate/prototype/until/era-boundary-islamic-tbla.js b/test/intl402/Temporal/PlainDate/prototype/until/era-boundary-islamic-tbla.js new file mode 100644 index 0000000000..a95dc0c3f9 --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/until/era-boundary-islamic-tbla.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 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: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-tbla"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.PlainDate.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, calendar }, options); +const bh2 = Temporal.PlainDate.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, calendar }, options); +const bh1 = Temporal.PlainDate.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, calendar }, options); +const ah1 = Temporal.PlainDate.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, calendar }, options); +const ah2 = Temporal.PlainDate.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, calendar }, options); +const ah5 = Temporal.PlainDate.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.until(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.until(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.until(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.until(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.until(two); + const resultDaysISO = oneISO.until(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/PlainDate/prototype/until/era-boundary-islamic-umalqura.js b/test/intl402/Temporal/PlainDate/prototype/until/era-boundary-islamic-umalqura.js new file mode 100644 index 0000000000..d60a3876a4 --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/until/era-boundary-islamic-umalqura.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 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: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-umalqura"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.PlainDate.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, calendar }, options); +const bh2 = Temporal.PlainDate.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, calendar }, options); +const bh1 = Temporal.PlainDate.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, calendar }, options); +const ah1 = Temporal.PlainDate.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, calendar }, options); +const ah2 = Temporal.PlainDate.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, calendar }, options); +const ah5 = Temporal.PlainDate.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.until(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.until(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.until(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.until(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.until(two); + const resultDaysISO = oneISO.until(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-ethiopic.js b/test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-ethiopic.js new file mode 100644 index 0000000000..52ab0c5150 --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-ethiopic.js @@ -0,0 +1,90 @@ +// Copyright (C) 2025 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: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "ethiopic"; +const options = { overflow: "reject" }; + +const aa5500 = Temporal.PlainDateTime.from({ era: "aa", eraYear: 5500, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options); +const am1 = Temporal.PlainDateTime.from({ era: "am", eraYear: 1, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options); +const am2000 = Temporal.PlainDateTime.from({ era: "am", eraYear: 2000, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const am2005 = Temporal.PlainDateTime.from({ era: "am", eraYear: 2005, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const aa5450 = Temporal.PlainDateTime.from({ era: "aa", eraYear: 5450, monthCode: "M07", day: 12, hour: 12, minute: 34, calendar }, options); +const aa5455 = Temporal.PlainDateTime.from({ era: "aa", eraYear: 5455, monthCode: "M07", day: 12, hour: 12, minute: 34, calendar }, options); +const am5 = Temporal.PlainDateTime.from({ era: "am", eraYear: 5, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options); + +const tests = [ + // From 5500 AA to 1 AM + [ + aa5500, am1, + [-1, 0, 0, 0, "-1y backwards from 5500 AA to 1 AM"], + [0, -13, 0, 0, 0, "-13mo backwards from 5500 AA to 1 AM"], + ], + [ + am1, aa5500, + [1, 0, 0, 0, "1y from 5500 AA to 1 AM"], + [0, 13, 0, 0, 0, "13mo from 1 AM to 5500 AA"], + ], + // From 2000 AM to 2005 AM + [ + am2000, am2005, + [-5, 0, 0, 0, "-5y backwards from 2000 AM to 2005 AM"], + [0, -65, 0, 0, "-65mo backwards from 2000 AM to 2005 AM"], + ], + [ + am2005, am2000, + [5, 0, 0, 0, "5y from 2000 AM to 2005 AM"], + [0, 65, 0, 0, "65mo from 2000 AM to 2005 AM"], + ], + // From 5450 AA to 5455 AA + [ + aa5450, aa5455, + [-5, 0, 0, 0, "-5y backwards from 5450 AA to 5455 AA"], + [0, -65, 0, 0, "-65mo backwards from 5450 AA to 5455 AA"], + ], + [ + aa5455, aa5450, + [5, 0, 0, 0, "5y from 5450 AA to 5455 AA"], + [0, 65, 0, 0, "65mo from 5450 AA to 5455 AA"], + ], + // From 5 AM to 5500 AA + [ + aa5500, am5, + [-5, 0, 0, 0, "-5y backwards from 5 AM to 5500 AA"], + [0, -65, 0, 0, "-65mo backwards from 5 AM to 5500 AA"], + ], + [ + am5, aa5500, + [5, 0, 0, 0, "5y from 5 AM to 5500 AA"], + [0, 65, 0, 0, "65mo from 5 AM to 5500 AA"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.since(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.since(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.since(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.since(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.since(two); + const resultDaysISO = oneISO.since(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-islamic-civil.js b/test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-islamic-civil.js new file mode 100644 index 0000000000..8d7ff6b5bf --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-islamic-civil.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 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: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-civil"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const bh2 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, hour: 12, minute: 34, calendar }, options); +const bh1 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const ah1 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const ah2 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options); +const ah5 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.since(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.since(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.since(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.since(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.since(two); + const resultDaysISO = oneISO.since(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-islamic-tbla.js b/test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-islamic-tbla.js new file mode 100644 index 0000000000..0be8e94a2b --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-islamic-tbla.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 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: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-tbla"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const bh2 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, hour: 12, minute: 34, calendar }, options); +const bh1 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const ah1 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const ah2 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options); +const ah5 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.since(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.since(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.since(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.since(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.since(two); + const resultDaysISO = oneISO.since(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-islamic-umalqura.js b/test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-islamic-umalqura.js new file mode 100644 index 0000000000..2f6753f384 --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/since/era-boundary-islamic-umalqura.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 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: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-umalqura"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const bh2 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, hour: 12, minute: 34, calendar }, options); +const bh1 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const ah1 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const ah2 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options); +const ah5 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.since(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.since(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.since(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.since(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.since(two); + const resultDaysISO = oneISO.since(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-ethiopic.js b/test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-ethiopic.js new file mode 100644 index 0000000000..54ab1ccfdd --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-ethiopic.js @@ -0,0 +1,90 @@ +// Copyright (C) 2025 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: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "ethiopic"; +const options = { overflow: "reject" }; + +const aa5500 = Temporal.PlainDateTime.from({ era: "aa", eraYear: 5500, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options); +const am1 = Temporal.PlainDateTime.from({ era: "am", eraYear: 1, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options); +const am2000 = Temporal.PlainDateTime.from({ era: "am", eraYear: 2000, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const am2005 = Temporal.PlainDateTime.from({ era: "am", eraYear: 2005, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const aa5450 = Temporal.PlainDateTime.from({ era: "aa", eraYear: 5450, monthCode: "M07", day: 12, hour: 12, minute: 34, calendar }, options); +const aa5455 = Temporal.PlainDateTime.from({ era: "aa", eraYear: 5455, monthCode: "M07", day: 12, hour: 12, minute: 34, calendar }, options); +const am5 = Temporal.PlainDateTime.from({ era: "am", eraYear: 5, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options); + +const tests = [ + // From 5500 AA to 1 AM + [ + aa5500, am1, + [1, 0, 0, 0, "1y from 5500 AA to 1 AM"], + [0, 13, 0, 0, 0, "13mo from 5500 AA to 1 AM"], + ], + [ + am1, aa5500, + [-1, 0, 0, 0, "-1y backwards from 5500 AA to 1 AM"], + [0, -13, 0, 0, 0, "-13mo backwards from 1 AM to 5500 AA"], + ], + // From 2000 AM to 2005 AM + [ + am2000, am2005, + [5, 0, 0, 0, "5y from 2000 AM to 2005 AM"], + [0, 65, 0, 0, "65mo from 2000 AM to 2005 AM"], + ], + [ + am2005, am2000, + [-5, 0, 0, 0, "-5y backwards from 2000 AM to 2005 AM"], + [0, -65, 0, 0, "-65mo backwards from 2000 AM to 2005 AM"], + ], + // From 5450 AA to 5455 AA + [ + aa5450, aa5455, + [5, 0, 0, 0, "5y from 5450 AA to 5455 AA"], + [0, 65, 0, 0, "65mo from 5450 AA to 5455 AA"], + ], + [ + aa5455, aa5450, + [-5, 0, 0, 0, "-5y backwards from 5450 AA to 5455 AA"], + [0, -65, 0, 0, "-65mo backwards from 5450 AA to 5455 AA"], + ], + // From 5 AM to 5500 AA + [ + aa5500, am5, + [5, 0, 0, 0, "5y from 5 AM to 5500 AA"], + [0, 65, 0, 0, "65mo from 5 AM to 5500 AA"], + ], + [ + am5, aa5500, + [-5, 0, 0, 0, "-5y backwards from 5 AM to 5500 AA"], + [0, -65, 0, 0, "-65mo backwards from 5 AM to 5500 AA"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.until(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.until(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.until(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.until(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.until(two); + const resultDaysISO = oneISO.until(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-islamic-civil.js b/test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-islamic-civil.js new file mode 100644 index 0000000000..94d9011f8c --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-islamic-civil.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 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: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-civil"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const bh2 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, hour: 12, minute: 34, calendar }, options); +const bh1 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const ah1 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const ah2 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options); +const ah5 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.until(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.until(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.until(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.until(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.until(two); + const resultDaysISO = oneISO.until(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-islamic-tbla.js b/test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-islamic-tbla.js new file mode 100644 index 0000000000..8afbbb68d2 --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-islamic-tbla.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 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: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-tbla"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const bh2 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, hour: 12, minute: 34, calendar }, options); +const bh1 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const ah1 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const ah2 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options); +const ah5 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.until(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.until(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.until(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.until(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.until(two); + const resultDaysISO = oneISO.until(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-islamic-umalqura.js b/test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-islamic-umalqura.js new file mode 100644 index 0000000000..0270e2afbb --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/until/era-boundary-islamic-umalqura.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 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: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-umalqura"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const bh2 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, hour: 12, minute: 34, calendar }, options); +const bh1 = Temporal.PlainDateTime.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const ah1 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); +const ah2 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options); +const ah5 = Temporal.PlainDateTime.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.until(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.until(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.until(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.until(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.until(two); + const resultDaysISO = oneISO.until(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-ethiopic.js b/test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-ethiopic.js new file mode 100644 index 0000000000..34d3413094 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-ethiopic.js @@ -0,0 +1,90 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.since +description: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "ethiopic"; +const options = { overflow: "reject" }; + +const aa5500 = Temporal.ZonedDateTime.from({ era: "aa", eraYear: 5500, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const am1 = Temporal.ZonedDateTime.from({ era: "am", eraYear: 1, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const am2000 = Temporal.ZonedDateTime.from({ era: "am", eraYear: 2000, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const am2005 = Temporal.ZonedDateTime.from({ era: "am", eraYear: 2005, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const aa5450 = Temporal.ZonedDateTime.from({ era: "aa", eraYear: 5450, monthCode: "M07", day: 12, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const aa5455 = Temporal.ZonedDateTime.from({ era: "aa", eraYear: 5455, monthCode: "M07", day: 12, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const am5 = Temporal.ZonedDateTime.from({ era: "am", eraYear: 5, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); + +const tests = [ + // From 5500 AA to 1 AM + [ + aa5500, am1, + [-1, 0, 0, 0, "-1y backwards from 5500 AA to 1 AM"], + [0, -13, 0, 0, 0, "-13mo backwards from 5500 AA to 1 AM"], + ], + [ + am1, aa5500, + [1, 0, 0, 0, "1y from 5500 AA to 1 AM"], + [0, 13, 0, 0, 0, "13mo from 1 AM to 5500 AA"], + ], + // From 2000 AM to 2005 AM + [ + am2000, am2005, + [-5, 0, 0, 0, "-5y backwards from 2000 AM to 2005 AM"], + [0, -65, 0, 0, "-65mo backwards from 2000 AM to 2005 AM"], + ], + [ + am2005, am2000, + [5, 0, 0, 0, "5y from 2000 AM to 2005 AM"], + [0, 65, 0, 0, "65mo from 2000 AM to 2005 AM"], + ], + // From 5450 AA to 5455 AA + [ + aa5450, aa5455, + [-5, 0, 0, 0, "-5y backwards from 5450 AA to 5455 AA"], + [0, -65, 0, 0, "-65mo backwards from 5450 AA to 5455 AA"], + ], + [ + aa5455, aa5450, + [5, 0, 0, 0, "5y from 5450 AA to 5455 AA"], + [0, 65, 0, 0, "65mo from 5450 AA to 5455 AA"], + ], + // From 5 AM to 5500 AA + [ + aa5500, am5, + [-5, 0, 0, 0, "-5y backwards from 5 AM to 5500 AA"], + [0, -65, 0, 0, "-65mo backwards from 5 AM to 5500 AA"], + ], + [ + am5, aa5500, + [5, 0, 0, 0, "5y from 5 AM to 5500 AA"], + [0, 65, 0, 0, "65mo from 5 AM to 5500 AA"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.since(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.since(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.since(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.since(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.since(two); + const resultDaysISO = oneISO.since(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-islamic-civil.js b/test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-islamic-civil.js new file mode 100644 index 0000000000..39e4d24213 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-islamic-civil.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.since +description: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-civil"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const bh2 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const bh1 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah1 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah2 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah5 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.since(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.since(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.since(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.since(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.since(two); + const resultDaysISO = oneISO.since(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-islamic-tbla.js b/test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-islamic-tbla.js new file mode 100644 index 0000000000..6fa1d4122d --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-islamic-tbla.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.since +description: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-tbla"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const bh2 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const bh1 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah1 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah2 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah5 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.since(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.since(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.since(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.since(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.since(two); + const resultDaysISO = oneISO.since(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-islamic-umalqura.js b/test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-islamic-umalqura.js new file mode 100644 index 0000000000..17e4c0a3f7 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/since/era-boundary-islamic-umalqura.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.since +description: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-umalqura"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const bh2 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const bh1 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah1 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah2 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah5 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.since(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.since(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.since(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.since(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.since(two); + const resultDaysISO = oneISO.since(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-ethiopic.js b/test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-ethiopic.js new file mode 100644 index 0000000000..0db0866ba8 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-ethiopic.js @@ -0,0 +1,90 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.until +description: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "ethiopic"; +const options = { overflow: "reject" }; + +const aa5500 = Temporal.ZonedDateTime.from({ era: "aa", eraYear: 5500, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const am1 = Temporal.ZonedDateTime.from({ era: "am", eraYear: 1, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const am2000 = Temporal.ZonedDateTime.from({ era: "am", eraYear: 2000, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const am2005 = Temporal.ZonedDateTime.from({ era: "am", eraYear: 2005, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const aa5450 = Temporal.ZonedDateTime.from({ era: "aa", eraYear: 5450, monthCode: "M07", day: 12, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const aa5455 = Temporal.ZonedDateTime.from({ era: "aa", eraYear: 5455, monthCode: "M07", day: 12, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const am5 = Temporal.ZonedDateTime.from({ era: "am", eraYear: 5, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); + +const tests = [ + // From 5500 AA to 1 AM + [ + aa5500, am1, + [1, 0, 0, 0, "1y from 5500 AA to 1 AM"], + [0, 13, 0, 0, 0, "13mo from 5500 AA to 1 AM"], + ], + [ + am1, aa5500, + [-1, 0, 0, 0, "-1y backwards from 5500 AA to 1 AM"], + [0, -13, 0, 0, 0, "-13mo backwards from 1 AM to 5500 AA"], + ], + // From 2000 AM to 2005 AM + [ + am2000, am2005, + [5, 0, 0, 0, "5y from 2000 AM to 2005 AM"], + [0, 65, 0, 0, "65mo from 2000 AM to 2005 AM"], + ], + [ + am2005, am2000, + [-5, 0, 0, 0, "-5y backwards from 2000 AM to 2005 AM"], + [0, -65, 0, 0, "-65mo backwards from 2000 AM to 2005 AM"], + ], + // From 5450 AA to 5455 AA + [ + aa5450, aa5455, + [5, 0, 0, 0, "5y from 5450 AA to 5455 AA"], + [0, 65, 0, 0, "65mo from 5450 AA to 5455 AA"], + ], + [ + aa5455, aa5450, + [-5, 0, 0, 0, "-5y backwards from 5450 AA to 5455 AA"], + [0, -65, 0, 0, "-65mo backwards from 5450 AA to 5455 AA"], + ], + // From 5 AM to 5500 AA + [ + aa5500, am5, + [5, 0, 0, 0, "5y from 5 AM to 5500 AA"], + [0, 65, 0, 0, "65mo from 5 AM to 5500 AA"], + ], + [ + am5, aa5500, + [-5, 0, 0, 0, "-5y backwards from 5 AM to 5500 AA"], + [0, -65, 0, 0, "-65mo backwards from 5 AM to 5500 AA"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.until(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.until(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.until(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.until(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.until(two); + const resultDaysISO = oneISO.until(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-islamic-civil.js b/test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-islamic-civil.js new file mode 100644 index 0000000000..0b9ce583bc --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-islamic-civil.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.until +description: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-civil"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const bh2 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const bh1 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah1 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah2 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah5 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.until(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.until(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.until(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.until(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.until(two); + const resultDaysISO = oneISO.until(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-islamic-tbla.js b/test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-islamic-tbla.js new file mode 100644 index 0000000000..067e70e152 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-islamic-tbla.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.until +description: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-tbla"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const bh2 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const bh1 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah1 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah2 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah5 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.until(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.until(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.until(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.until(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.until(two); + const resultDaysISO = oneISO.until(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +} diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-islamic-umalqura.js b/test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-islamic-umalqura.js new file mode 100644 index 0000000000..f5e3f73292 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/until/era-boundary-islamic-umalqura.js @@ -0,0 +1,77 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.until +description: Date difference works correctly across era boundaries +includes: [temporalHelpers.js] +features: [Temporal, Intl.Era-monthcode] +---*/ + +const calendar = "islamic-umalqura"; +const options = { overflow: "reject" }; + +const bh5 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const bh2 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 2, monthCode: "M12", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const bh1 = Temporal.ZonedDateTime.from({ era: "bh", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah1 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 1, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah2 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 2, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); +const ah5 = Temporal.ZonedDateTime.from({ era: "ah", eraYear: 5, monthCode: "M06", day: 15, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); + +const tests = [ + // From 5 BH to 5 AH + [ + bh5, ah5, + [9, 0, 0, 0, "9y from 5 BH to 5 AH (no year 0)"], + [0, 108, 0, 0, 0, "108mo from 5 BH to 5 AH (no year 0)"], + ], + [ + ah5, bh5, + [-9, 0, 0, 0, "-9y backwards from 5 BH to 5 AH (no year 0)"], + [0, -108, 0, 0, 0, "-108mo backwards from 5 BH to 5 AH (no year 0)"], + ], + // AH-BH boundary + [ + bh1, ah1, + [1, 0, 0, 0, "1y from 1 BH to 1 AH"], + [0, 12, 0, 0, "12mo from 1 BH to 1 AH"], + ], + [ + ah1, bh1, + [-1, 0, 0, 0, "-1y backwards from 1 BH to 1 AH"], + [0, -12, 0, 0, "-12mo backwards from 1 BH to 1 AH"], + ], + [ + bh2, ah2, + [2, 1, 0, 0, "2y 1mo from 2 BH Dec to 2 AH Jan"], + [0, 25, 0, 0, "25mo from 2 BH Dec to 2 AH Jan"], + ], + [ + ah2, bh2, + [-2, -1, 0, 0, "-2y -1mo backwards from 2 BH Dec to 2 AH Jan"], + [0, -25, 0, 0, "-25mo backwards from 2 BH Dec to 2 AH Jan"], + ], +]; + +for (const [one, two, yearsTest, monthsTest] of tests) { + let [years, months, weeks, days, descr] = yearsTest; + let result = one.until(two, { largestUnit: "years" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + [years, months, weeks, days, descr] = monthsTest; + result = one.until(two, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, years, months, weeks, days, 0, 0, 0, 0, 0, 0, descr); + + const oneISO = one.withCalendar("iso8601"); + const twoISO = two.withCalendar("iso8601"); + + const resultWeeks = one.until(two, { largestUnit: "weeks" }); + const resultWeeksISO = oneISO.until(twoISO, { largestUnit: "weeks" }); + TemporalHelpers.assertDurationsEqual(resultWeeks, resultWeeksISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit weeks`); + + const resultDays = one.until(two); + const resultDaysISO = oneISO.until(twoISO); + TemporalHelpers.assertDurationsEqual(resultDays, resultDaysISO, + `${one.year}-${one.monthCode}-${one.day} : ${two.year}-${two.monthCode}-${two.day} largestUnit days`); +}