Skip to content

Conversation

justingrant
Copy link
Contributor

Port of tc39/proposal-temporal#1977 and tc39/proposal-temporal#1983 to fix a bunch of smaller issues with non-ISO calendar.

This is (hopefully!) the last ported PR so that #109 can be limited to type changes only.

We should merge this PR only after tc39/proposal-temporal#1977 is approved and merged.

The current code is correct, so no need for this comment.
`year` might have been mutated in the first line of this method.
So it's not OK to pass `calendarDate` to `maximumMonthLength`.
Need to pass current year/month values instead.
This adds an additional check to make sure that the (hard-coded)
era definitions for each calendar aren't missing required `isoEpoch`
properties. Note that this code is only run once at load time, not each
time calendars are accessed, so there's no runtime impact.
Re-order code to guarantee that `calendarDate.year` is set before
calculating the number of months in that year. The old code would
break for any calendar that a) used a constant `era` like `islamic`
and b) had a variable number of months in each year like `hebrew`.
Today no ICU calendars fit in that Venn diagram, but if any are added
in the future this code will break when initializing any calendar using
an eraYear/era pair in a property bag. Better to fix it now!
@justingrant justingrant requested a review from ptomato December 16, 2021 02:13
This was originally part of tc39/proposal-temporal#1977
but I removed it because it wasn't high-priority for JS.
But it's still needed in this repo so I'm adding it back.

Why? TS complains when you assign a maybe-undefined
value to a must-not-be-undefined variable. This small
runtime change is cleaner than adding a lotta type casts.
Copy link
Contributor

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants