Skip to content

Commit

Permalink
polyfill: compare methods should not include calendar
Browse files Browse the repository at this point in the history
This commit updates the polyfill to reflect the spec changes made for
addressing tc39#1431.
  • Loading branch information
ryzokuken committed Mar 23, 2021
1 parent 00e7d72 commit cc05a27
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 15 deletions.
4 changes: 1 addition & 3 deletions polyfill/lib/plaindate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,14 @@ export class PlainDate {
static compare(one, two) {
one = ES.ToTemporalDate(one, PlainDate);
two = ES.ToTemporalDate(two, PlainDate);
const result = ES.CompareISODate(
return ES.CompareISODate(
GetSlot(one, ISO_YEAR),
GetSlot(one, ISO_MONTH),
GetSlot(one, ISO_DAY),
GetSlot(two, ISO_YEAR),
GetSlot(two, ISO_MONTH),
GetSlot(two, ISO_DAY)
);
if (result !== 0) return result;
return ES.CalendarCompare(GetSlot(one, CALENDAR), GetSlot(two, CALENDAR));
}
}

Expand Down
2 changes: 1 addition & 1 deletion polyfill/lib/plaindatetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
14 changes: 8 additions & 6 deletions polyfill/lib/plainyearmonth.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.CompareISODate(
GetSlot(one, ISO_YEAR),
GetSlot(one, ISO_MONTH),
GetSlot(one, ISO_DAY),
GetSlot(two, ISO_YEAR),
GetSlot(two, ISO_MONTH),
GetSlot(two, ISO_DAY)
);
}
}

Expand Down
2 changes: 0 additions & 2 deletions polyfill/lib/zoneddatetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal-comparetemporaldate
esid: sec-temporal-compareisodate
---*/

function CustomError() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal-comparetemporaldatetime
esid: sec-temporal-compareisodatetime
---*/

function CustomError() {}
Expand Down
2 changes: 1 addition & 1 deletion polyfill/test/zoneddatetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2814,7 +2814,7 @@ describe('ZonedDateTime', () => {
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);
equal(ZonedDateTime.compare(zdt1, zdt1.withCalendar('japanese')), 0);
});
it('compares exact time, not clock time', () => {
const clockBefore = ZonedDateTime.from('1999-12-31T23:30-08:00[America/Vancouver]');
Expand Down

0 comments on commit cc05a27

Please sign in to comment.