Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for editorial issues #2708

Merged
merged 12 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5907,6 +5907,22 @@ export function CompareISODate(y1, m1, d1, y2, m2, d2) {
return 0;
}

export function CompareTemporalTime(h1, min1, s1, ms1, µs1, ns1, h2, min2, s2, ms2, µs2, ns2) {
if (h1 !== h2) return ComparisonResult(h1 - h2);
if (min1 !== min2) return ComparisonResult(min1 - min2);
if (s1 !== s2) return ComparisonResult(s1 - s2);
if (ms1 !== ms2) return ComparisonResult(ms1 - ms2);
if (µs1 !== µs2) return ComparisonResult(µs1 - µs2);
Comment on lines +5884 to +5886
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codecov claims the second and microsecond branches are not covered, could you have a look?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added another commit on to tc39/test262#3944: tc39/test262@315b4df

if (ns1 !== ns2) return ComparisonResult(ns1 - ns2);
return 0;
}

export function CompareISODateTime(y1, m1, d1, h1, min1, s1, ms1, µs1, ns1, y2, m2, d2, h2, min2, s2, ms2, µs2, ns2) {
const dateResult = CompareISODate(y1, m1, d1, y2, m2, d2);
if (dateResult !== 0) return dateResult;
return CompareTemporalTime(h1, min1, s1, ms1, µs1, ns1, h2, min2, s2, ms2, µs2, ns2);
}

// Not abstract operations from the spec

export function NonNegativeBigIntDivmod(x, y) {
Expand Down
71 changes: 44 additions & 27 deletions polyfill/lib/plaindatetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,30 @@ export class PlainDateTime {
equals(other) {
if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver');
other = ES.ToTemporalDateTime(other);
if (GetSlot(this, ISO_YEAR) !== GetSlot(other, ISO_YEAR)) return false;
if (GetSlot(this, ISO_MONTH) !== GetSlot(other, ISO_MONTH)) return false;
if (GetSlot(this, ISO_DAY) !== GetSlot(other, ISO_DAY)) return false;
if (GetSlot(this, ISO_HOUR) !== GetSlot(other, ISO_HOUR)) return false;
if (GetSlot(this, ISO_MINUTE) !== GetSlot(other, ISO_MINUTE)) return false;
if (GetSlot(this, ISO_SECOND) !== GetSlot(other, ISO_SECOND)) return false;
if (GetSlot(this, ISO_MILLISECOND) !== GetSlot(other, ISO_MILLISECOND)) return false;
if (GetSlot(this, ISO_MICROSECOND) !== GetSlot(other, ISO_MICROSECOND)) return false;
if (GetSlot(this, ISO_NANOSECOND) !== GetSlot(other, ISO_NANOSECOND)) return false;
if (
ES.CompareISODateTime(
GetSlot(this, ISO_YEAR),
GetSlot(this, ISO_MONTH),
GetSlot(this, ISO_DAY),
GetSlot(this, ISO_HOUR),
GetSlot(this, ISO_MINUTE),
GetSlot(this, ISO_SECOND),
GetSlot(this, ISO_MILLISECOND),
GetSlot(this, ISO_MICROSECOND),
GetSlot(this, ISO_NANOSECOND),
GetSlot(other, ISO_YEAR),
GetSlot(other, ISO_MONTH),
GetSlot(other, ISO_DAY),
GetSlot(other, ISO_HOUR),
GetSlot(other, ISO_MINUTE),
GetSlot(other, ISO_SECOND),
GetSlot(other, ISO_MILLISECOND),
GetSlot(other, ISO_MICROSECOND),
GetSlot(other, ISO_NANOSECOND)
) !== 0
) {
return false;
}
return ES.CalendarEquals(GetSlot(this, CALENDAR), GetSlot(other, CALENDAR));
}
toString(options = undefined) {
Expand Down Expand Up @@ -461,24 +476,26 @@ export class PlainDateTime {
static compare(one, two) {
one = ES.ToTemporalDateTime(one);
two = ES.ToTemporalDateTime(two);
const slots = [
ISO_YEAR,
ISO_MONTH,
ISO_DAY,
ISO_HOUR,
ISO_MINUTE,
ISO_SECOND,
ISO_MILLISECOND,
ISO_MICROSECOND,
ISO_NANOSECOND
];
for (let index = 0; index < slots.length; index++) {
const slot = slots[index];
const val1 = GetSlot(one, slot);
const val2 = GetSlot(two, slot);
if (val1 !== val2) return ES.ComparisonResult(val1 - val2);
}
return 0;
return ES.CompareISODateTime(
GetSlot(one, ISO_YEAR),
GetSlot(one, ISO_MONTH),
GetSlot(one, ISO_DAY),
GetSlot(one, ISO_HOUR),
GetSlot(one, ISO_MINUTE),
GetSlot(one, ISO_SECOND),
GetSlot(one, ISO_MILLISECOND),
GetSlot(one, ISO_MICROSECOND),
GetSlot(one, ISO_NANOSECOND),
GetSlot(two, ISO_YEAR),
GetSlot(two, ISO_MONTH),
GetSlot(two, ISO_DAY),
GetSlot(two, ISO_HOUR),
GetSlot(two, ISO_MINUTE),
GetSlot(two, ISO_SECOND),
GetSlot(two, ISO_MILLISECOND),
GetSlot(two, ISO_MICROSECOND),
GetSlot(two, ISO_NANOSECOND)
);
}
}

Expand Down
20 changes: 14 additions & 6 deletions polyfill/lib/plaintime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,20 @@ export class PlainTime {
static compare(one, two) {
one = ES.ToTemporalTime(one);
two = ES.ToTemporalTime(two);
for (const slot of [ISO_HOUR, ISO_MINUTE, ISO_SECOND, ISO_MILLISECOND, ISO_MICROSECOND, ISO_NANOSECOND]) {
const val1 = GetSlot(one, slot);
const val2 = GetSlot(two, slot);
if (val1 !== val2) return ES.ComparisonResult(val1 - val2);
}
return 0;
return ES.CompareTemporalTime(
GetSlot(one, ISO_HOUR),
GetSlot(one, ISO_MINUTE),
GetSlot(one, ISO_SECOND),
GetSlot(one, ISO_MILLISECOND),
GetSlot(one, ISO_MICROSECOND),
GetSlot(one, ISO_NANOSECOND),
GetSlot(two, ISO_HOUR),
GetSlot(two, ISO_MINUTE),
GetSlot(two, ISO_SECOND),
GetSlot(two, ISO_MILLISECOND),
GetSlot(two, ISO_MICROSECOND),
GetSlot(two, ISO_NANOSECOND)
);
}
}

Expand Down