-
Notifications
You must be signed in to change notification settings - Fork 156
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
Further clarifications of calendar-dependent parts of yearMonthFromFields and monthDayFromFields #2461
Comments
To encourage consistency across implementations, maybe use language something like below for determining the reference year?
|
In order for CalendarDateToISO to work, we have to specify in _fields_ that we want the first of the month. See: #2461
This was missing from the non-ISO part of monthDayFromFields(). Calendars must choose a reference ISO year when creating a PlainMonthDay. This adds language specifying how the reference year is deterministically chosen, in a separate calendar operation from CalendarDateToISO. See: #2461
In order for CalendarDateToISO to work, we have to specify in _fields_ that we want the first of the month. See: #2461
This was missing from the non-ISO part of monthDayFromFields(). Calendars must choose a reference ISO year when creating a PlainMonthDay. This adds language specifying how the reference year is deterministically chosen, in a separate calendar operation from CalendarDateToISO. See: #2461
This was missing from the non-ISO part of monthDayFromFields(). Calendars must choose a reference ISO year when creating a PlainMonthDay. This adds language specifying how the reference year is deterministically chosen, in a separate calendar operation from CalendarDateToISO. See: #2461
This was missing from the non-ISO part of monthDayFromFields(). Calendars must choose a reference ISO year when creating a PlainMonthDay. This adds language specifying how the reference year is deterministically chosen, in a separate calendar operation from CalendarDateToISO. See: #2461
In order for CalendarDateToISO to work, we have to specify in _fields_ that we want the first of the month. See: #2461
This was missing from the non-ISO part of monthDayFromFields(). Calendars must choose a reference ISO year when creating a PlainMonthDay. This adds language specifying how the reference year is deterministically chosen, in a separate calendar operation from CalendarDateToISO. See: #2461
This was missing from the non-ISO part of monthDayFromFields(). Calendars must choose a reference ISO year when creating a PlainMonthDay. This adds language specifying how the reference year is deterministically chosen, in a separate calendar operation from CalendarDateToISO. See: #2461
May I ask; Why does Is it a bug? Should it be able to diff two |
Thanks for the report! As far as I know, no Temporal.PlainYearMonth.from('2021-06').until(Temporal.PlainYearMonth.from('2023-02'), {largestUnit: 'month', smallestUnit: 'month'})
// => duration of P20M (20 months) Please open a separate issue with a code example of what is not working, as I think it's probably not related to this. |
My bad; it was the next part... the Temporal.PlainYearMonth.from('2021-06')
.until(Temporal.PlainYearMonth.from('2023-02'))
.total({ unit: 'month' }) The snippet above does throw in the docs playground. Passing |
The problem you're running into is that, by the time While it's true that the duration One of our principles in designing Temporal's APIs is that determining which options are valid vs. invalid for a particular operation is performed only on the shape (meaning what properties & types) of the input(s), rather than the value of those inputs. This makes it easier to catch bugs while code is in development because the shape of inputs is usually known at development time, while their values are usually not determined until runtime. The downside of this design principle is that sometimes you need to use more verbose code in order to ensure that options will be accepted regardless of the values of the inputs. Anyway, if you want to avoid specifying a Temporal.PlainYearMonth.from('2021-06')
.until(Temporal.PlainYearMonth.from('2023-02'), { smallestUnit: 'month', largestUnit: 'month' }).months; |
It took me a while to wrap my head around it, but I get it now...
Does this mean that the values (rather than shape) will be checked once Temporal is implemented into browsers? |
Nope, the behavior of native implementations should match the current polyfills because both of them are built from the same underlying spec. To be clear, all polyfills and native implementations do validate values of inputs. If an invalid value is provided, then an exception will be thrown. But determining which options are required vs. optional usually relies only on the shape of the input(s). |
In order for CalendarDateToISO to work, we have to specify in _fields_ that we want the first of the month. See: #2461
This was missing from the non-ISO part of monthDayFromFields(). Calendars must choose a reference ISO year when creating a PlainMonthDay. This adds language specifying how the reference year is deterministically chosen, in a separate calendar operation from CalendarDateToISO. See: #2461
In order for CalendarDateToISO to work, we have to specify in _fields_ that we want the first of the month. See: #2461
This was missing from the non-ISO part of monthDayFromFields(). Calendars must choose a reference ISO year when creating a PlainMonthDay. This adds language specifying how the reference year is deterministically chosen, in a separate calendar operation from CalendarDateToISO. See: #2461
In order for CalendarDateToISO to work, we have to specify in _fields_ that we want the first of the month. See: #2461
This was missing from the non-ISO part of monthDayFromFields(). Calendars must choose a reference ISO year when creating a PlainMonthDay. This adds language specifying how the reference year is deterministically chosen, in a separate calendar operation from CalendarDateToISO. See: #2461
In order for CalendarDateToISO to work, we have to specify in _fields_ that we want the first of the month. See: #2461
This was missing from the non-ISO part of monthDayFromFields(). Calendars must choose a reference ISO year when creating a PlainMonthDay. This adds language specifying how the reference year is deterministically chosen, in a separate calendar operation from CalendarDateToISO. See: #2461
In order for CalendarDateToISO to work, we have to specify in _fields_ that we want the first of the month. See: tc39#2461
This was missing from the non-ISO part of monthDayFromFields(). Calendars must choose a reference ISO year when creating a PlainMonthDay. This adds language specifying how the reference year is deterministically chosen, in a separate calendar operation from CalendarDateToISO. See: tc39#2461
Spotted by @justingrant in #1502.
Temporal.Calendar.prototype.yearMonthFromFields and Temporal.Calendar.prototype.monthDayFromFields both go through CalendarDateToISO in the non-ISO case. This operation is implementation-defined, but doesn't say what to do if there isn't enough information on fields to produce a full ISO date, which would be the case in yearMonthFromFields and monthDayFromFields.
For yearMonthFromFields we can simply add a step "Perform ! CreateDataPropertyOrThrow(fields, "day", 1F)" but for monthDayFromFields we need to somehow describe the requirement to pick a reference year in the implementation-defined part. I'd suggest that we use a separate implementation-defined operation, CalendarMonthDayToISOReferenceDate.
The text was updated successfully, but these errors were encountered: