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/proposal-temporal#1431.
  • Loading branch information
ryzokuken authored and ptomato committed May 6, 2021
1 parent 29f7bc3 commit 33ff8ad
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
4 changes: 1 addition & 3 deletions 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 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 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 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
4 changes: 2 additions & 2 deletions test/zoneddatetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2813,8 +2813,8 @@ 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('disregards calendar IDs if exact times and time zones are equal', () => {
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 33ff8ad

Please sign in to comment.