Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 2 additions & 4 deletions polyfill/lib/calendar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,10 +1056,8 @@ const nonIsoHelperBase = {
case 'year': {
// Sign is -1 if calendarTwo < calendarOne, 1 if calendarTwo > calendarOne
const sign = this.compareCalendarDates(calendarTwo, calendarOne);
// If dates are equal, return 0 date duration
if (!sign) {
return { years: 0, months: 0, weeks: 0, days: 0 };
}
// If dates were equal, this would have been checked in CalendarDateUntil
assert(sign, 'equal dates should have been checked earlier');
// Take the difference between the years of the two dates
const diffYears = calendarTwo.year - calendarOne.year;
// Take the difference between the days of the two dates
Expand Down
3 changes: 3 additions & 0 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,9 @@ export function CalendarDateAdd(calendar, isoDate, dateDuration, overflow) {
}

export function CalendarDateUntil(calendar, isoDate, isoOtherDate, largestUnit) {
if (CompareISODate(isoDate, isoOtherDate) === 0) {
return { years: 0, months: 0, weeks: 0, days: 0 };
}
return calendarImplForID(calendar).dateUntil(isoDate, isoOtherDate, largestUnit);
}

Expand Down
6 changes: 4 additions & 2 deletions spec/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,11 @@ <h1>
</dd>
</dl>
<emu-alg>
1. Let _sign_ be CompareISODate(_one_, _two_).
1. If _sign_ is 0, then
1. Return ZeroDateDuration().
1. If _calendar_ is *"iso8601"*, then
1. Let _sign_ be -CompareISODate(_one_, _two_).
1. If _sign_ = 0, return ZeroDateDuration().
1. Set _sign_ to -sign.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a bit odd-looking but I'm not sure how else to do it that would make sense.

1. Let _years_ be 0.
1. If _largestUnit_ is ~year~, then
1. Let _candidateYears_ be _sign_.
Expand Down