-
Notifications
You must be signed in to change notification settings - Fork 153
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
How should the overflow
option behave with leap days and months in PlainMonthDay.from()
?
#1237
Comments
I have to confess that I do not understand the reference to an ISO year for defining a PlainMonthDay record in any non-ISO calendar, be it solar or not. Despite my non-understanding, I succeeded managing PlainMonthDay in several non-ISO custom calendar, namely: IMHO the MonthDay concept is closely related to the corresponding calendar, like the concept of month. The (sole ?) use case of this concept is: given a Year (in the custom calendar) and a MonthDay record, what is the "best fit" date corresponding to (Year, MonthDay) ? This "best fit" date should be computed in the custom calendar (the "target calendar"). Then it is easy to translate this date into any other calendar, including ISO. Hence I do not understand why there should be an ISO reference year in the I understand that another use case could be: which is the date of Hanoucca, the hebrew feast that falls on 25 of Kislev, in a given Milesian year? Since the Milesian calendar has a very tight relation to the ISO, and since 25 Kislev exists in all (hebrew) year, you would say that the solution is straightforward. Not at all. In Milesian 2019, there was no Hanoucca, whereas in 2020 there were two occurrences : 2 1m 2020 (23 Dec. 2019), and 21 12m 2020 (11 Dec. 2020). If you want to avoid citing the Milesian calendar, take the 20 Tevet: no occurrence in ISO 2019, two occurrences in ISO 2020. So I think this use case should be asked in another way. Ideally, each calendar should define the way of handling the
As you can see, there is no reference to any ISO year in this algorithm. And this solves most current cases, like anniversaries of Gioachino Rossini (born Feb. 29 1792), unique 30 Feb. of the Swedish calendar, dates in Adar II or in leap years of the Chinese calendar. The case of "non-existing" dates around switching dates to the Gregorian calendars would probably lead to an error, even for the very particular case of the "German" calendar (of most protestant states of Germany) in which BTW I do not either understand the reference to an |
Coming back to this simple "use cases":
|
I may not be understanding the issue here, so forgive me if this is an answer to the wrong question 😄 The option is intended for when the given month or day are invalid, in other words this combination never exists in any year, for example The part I don't understand is the questions about the reference year, since that should be considered internal to the calendar. |
If we require calendars to canonicalize the reference year, per our discussion in #1239, then the approach in the OP (start from the current year and work backwards) won't work. Instead, each calendar would have to pick a constant year (like we do with 1972 for the Gregorian calendar) and work backwards from there. And once released, the calendar can never change that constant year or it'd break backwards compatibility. I answered some of @Louis-Aime's questions over in #1239 (comment). |
But the value of the reference year doesn't actually matter for the algorithm in the OP? Or maybe I'm misreading it? |
BTW, I just realized (duh) that because there's a limited set of possible month/day combinations (Chinese has the most of all ICU calendars and it has less than 800 possible combinations), picking a reference year will always be easy via a statically-defined map of If it does change, however, then all existing serialized values will be broken, so this is an important restriction. #1239 would make changes less of a big deal, though. |
One more related issue (I'll update the OP too with this info): how should the calendar react to an invalid |
Maybe I'm still not understanding the question, but I think the status quo is okay? As for the question about an invalid month code, should |
Yep, this is really about documentation for calendar builders (including built-in calendars) not any impact to Temporal spec or API. FWIW, here's the current implementation in the #1245:
The general idea is this:
I'm not saying those are the correct principles to follow, only that there should be general principles that are followed unless there are cultural practices that override. The overall goal is to ensure that I can take a |
Consensus from 2021-01-19 meeting:
(We didn't pass any judgement on whether the above principles were correct to be used in the absence of cultural practices, but it seems reasonable to me.) Closing this issue. |
PlainMonthDay.from()
accepts anoverflow: 'constrain' | 'reject'
option. How should this option behave when the input is a leap day or a day in a leap month? In the ISO calendar this is easy because there's only one leap day and it's always at the end of the same month. So the ISO calendar can use a fixed reference year, which currently is 1972 which was the first leap year after UNIX epoch.However, non-ISO calendars:
This means that the ISO reference year cannot be a constant, and it makes it harder to know how
overflow
should behave.My assumption is that the correct
overflow
behavior in any calendar is this:'constrain'
- try to find a year where this month/day exists. If one can be found, use it for computation ofreferenceISOYear
. If one cannot be found:'reject'
- try to find a year where this month/day exists. If one can be found, use it for computation ofreferenceISOYear
. If one cannot be found, throw aRangeError
.In my non-ISO calendar PR, I'm implementing the logic above by starting from the current date and working backwards one calendar year at a time for up to 100 years to try to find a year where the month/day exists. AFAICT, all built-in calendars have cycle lengths less than 100 years so if a match is going to happen, it should happen within a century. (I'm actually optimizing a little by checking for definitely-invalid values like
day: 0
ormonth: 14
before doing the up-to-100-year loop on maybe-valid month/day pairs, but that optimization shouldn't affect the spec above.)If you disagree with this approach, LMK soon!
EDIT: How should the calendar react to an invalid leap-month
monthCode
, e.g. '4L' for any calendar other than Chinese/Dangi. Should it constrain down to the last day ofmonthCode: '4'
per the constrain algorithm in the OP? Or throw a RangeError because that month code is never valid for that calendar?The text was updated successfully, but these errors were encountered: