diff --git a/polyfill/lib/calendar.mjs b/polyfill/lib/calendar.mjs index fc53ba5150..e0b658b8a2 100644 --- a/polyfill/lib/calendar.mjs +++ b/polyfill/lib/calendar.mjs @@ -1425,7 +1425,7 @@ const makeHelperGregorian = (id, originalEras) => { calendarIsVulnerableToJulianBug: false, checkIcuBugs(calendarDate, isoDate) { if (this.calendarIsVulnerableToJulianBug && this.v8IsVulnerableToJulianBug) { - const beforeJulianSwitch = ES.CompareISODate(isoDate.year, isoDate.month, isoDate.day, 1582, 10, 15) < 0; + const beforeJulianSwitch = ES.CompareTemporalDate(isoDate.year, isoDate.month, isoDate.day, 1582, 10, 15) < 0; if (beforeJulianSwitch) { throw new RangeError( `calendar '${this.id}' is broken for ISO dates before 1582-10-15` + diff --git a/polyfill/lib/ecmascript.mjs b/polyfill/lib/ecmascript.mjs index 20dcce2602..fd2e2f6919 100644 --- a/polyfill/lib/ecmascript.mjs +++ b/polyfill/lib/ecmascript.mjs @@ -2790,7 +2790,7 @@ export const ES = ObjectAssign({}, ES2020, { switch (largestUnit) { case 'years': case 'months': { - const sign = -ES.CompareISODate(y1, m1, d1, y2, m2, d2); + const sign = -ES.CompareTemporalDate(y1, m1, d1, y2, m2, d2); if (sign === 0) return { years: 0, months: 0, weeks: 0, days: 0 }; const start = { year: y1, month: m1, day: d1 }; @@ -2798,7 +2798,7 @@ export const ES = ObjectAssign({}, ES2020, { let years = end.year - start.year; let mid = ES.AddISODate(y1, m1, d1, years, 0, 0, 0, 'constrain'); - let midSign = -ES.CompareISODate(mid.year, mid.month, mid.day, y2, m2, d2); + let midSign = -ES.CompareTemporalDate(mid.year, mid.month, mid.day, y2, m2, d2); if (midSign === 0) { return largestUnit === 'years' ? { years, months: 0, weeks: 0, days: 0 } @@ -2810,7 +2810,7 @@ export const ES = ObjectAssign({}, ES2020, { months += sign * 12; } mid = ES.AddISODate(y1, m1, d1, years, months, 0, 0, 'constrain'); - midSign = -ES.CompareISODate(mid.year, mid.month, mid.day, y2, m2, d2); + midSign = -ES.CompareTemporalDate(mid.year, mid.month, mid.day, y2, m2, d2); if (midSign === 0) { return largestUnit === 'years' ? { years, months, weeks: 0, days: 0 } @@ -2825,7 +2825,7 @@ export const ES = ObjectAssign({}, ES2020, { months = 11 * sign; } mid = ES.AddISODate(y1, m1, d1, years, months, 0, 0, 'constrain'); - midSign = -ES.CompareISODate(y1, m1, d1, mid.year, mid.month, mid.day); + midSign = -ES.CompareTemporalDate(y1, m1, d1, mid.year, mid.month, mid.day); } let days = 0; @@ -2857,7 +2857,7 @@ export const ES = ObjectAssign({}, ES2020, { case 'weeks': case 'days': { let larger, smaller, sign; - if (ES.CompareISODate(y1, m1, d1, y2, m2, d2) < 0) { + if (ES.CompareTemporalDate(y1, m1, d1, y2, m2, d2) < 0) { smaller = { year: y1, month: m1, day: d1 }; larger = { year: y2, month: m2, day: d2 }; sign = 1; @@ -3882,7 +3882,7 @@ export const ES = ObjectAssign({}, ES2020, { return { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds, total }; }, - CompareISODate: (y1, m1, d1, y2, m2, d2) => { + CompareTemporalDate: (y1, m1, d1, y2, m2, d2) => { for (const [x, y] of [ [y1, y2], [m1, m2], diff --git a/polyfill/lib/plaindate.mjs b/polyfill/lib/plaindate.mjs index ba5004a5bd..4465a39640 100644 --- a/polyfill/lib/plaindate.mjs +++ b/polyfill/lib/plaindate.mjs @@ -438,7 +438,7 @@ export class PlainDate { static compare(one, two) { one = ES.ToTemporalDate(one, PlainDate); two = ES.ToTemporalDate(two, PlainDate); - const result = ES.CompareISODate( + return ES.CompareTemporalDate( GetSlot(one, ISO_YEAR), GetSlot(one, ISO_MONTH), GetSlot(one, ISO_DAY), @@ -446,8 +446,6 @@ export class PlainDate { GetSlot(two, ISO_MONTH), GetSlot(two, ISO_DAY) ); - if (result !== 0) return result; - return ES.CalendarCompare(GetSlot(one, CALENDAR), GetSlot(two, CALENDAR)); } } diff --git a/polyfill/lib/plaindatetime.mjs b/polyfill/lib/plaindatetime.mjs index d2a3b2aa53..85ddca03e8 100644 --- a/polyfill/lib/plaindatetime.mjs +++ b/polyfill/lib/plaindatetime.mjs @@ -794,7 +794,7 @@ export class PlainDateTime { const val2 = GetSlot(two, slot); if (val1 !== val2) return ES.ComparisonResult(val1 - val2); } - return ES.CalendarCompare(GetSlot(one, CALENDAR), GetSlot(two, CALENDAR)); + return 0; } } diff --git a/polyfill/lib/plainyearmonth.mjs b/polyfill/lib/plainyearmonth.mjs index 9bd82c8cac..d9a8786aa7 100644 --- a/polyfill/lib/plainyearmonth.mjs +++ b/polyfill/lib/plainyearmonth.mjs @@ -396,12 +396,14 @@ export class PlainYearMonth { static compare(one, two) { one = ES.ToTemporalYearMonth(one, PlainYearMonth); two = ES.ToTemporalYearMonth(two, PlainYearMonth); - for (const slot of [ISO_YEAR, ISO_MONTH, ISO_DAY]) { - const val1 = GetSlot(one, slot); - const val2 = GetSlot(two, slot); - if (val1 !== val2) return ES.ComparisonResult(val1 - val2); - } - return ES.CalendarCompare(GetSlot(one, CALENDAR), GetSlot(two, CALENDAR)); + return ES.CompareTemporalDate( + GetSlot(one, ISO_YEAR), + GetSlot(one, ISO_MONTH), + GetSlot(one, ISO_DAY), + GetSlot(two, ISO_YEAR), + GetSlot(two, ISO_MONTH), + GetSlot(two, ISO_DAY) + ); } } diff --git a/polyfill/lib/zoneddatetime.mjs b/polyfill/lib/zoneddatetime.mjs index d11ed7f69c..49714444ff 100644 --- a/polyfill/lib/zoneddatetime.mjs +++ b/polyfill/lib/zoneddatetime.mjs @@ -861,8 +861,6 @@ export class ZonedDateTime { const ns2 = GetSlot(two, EPOCHNANOSECONDS); if (bigInt(ns1).lesser(ns2)) return -1; if (bigInt(ns1).greater(ns2)) return 1; - const calendarResult = ES.CalendarCompare(GetSlot(one, CALENDAR), GetSlot(two, CALENDAR)); - if (calendarResult) return calendarResult; return ES.TimeZoneCompare(GetSlot(one, TIME_ZONE), GetSlot(two, TIME_ZONE)); } } diff --git a/polyfill/test/zoneddatetime.mjs b/polyfill/test/zoneddatetime.mjs index 5efcd414dd..e03a7a14ac 100644 --- a/polyfill/test/zoneddatetime.mjs +++ b/polyfill/test/zoneddatetime.mjs @@ -2813,9 +2813,6 @@ describe('ZonedDateTime', () => { it('compares time zone IDs if exact times are equal', () => { equal(ZonedDateTime.compare(zdt1, zdt1.withTimeZone('Asia/Kolkata')), 1); }); - it('compares calendar IDs if exact times and time zones are equal', () => { - equal(ZonedDateTime.compare(zdt1, zdt1.withCalendar('japanese')), -1); - }); it('compares exact time, not clock time', () => { const clockBefore = ZonedDateTime.from('1999-12-31T23:30-08:00[America/Vancouver]'); const clockAfter = ZonedDateTime.from('2000-01-01T01:30-04:00[America/Halifax]');