-
Notifications
You must be signed in to change notification settings - Fork 8
Editorial: Refactor the last bit of prose in NonISOCalendarDateToISO to AOs #74
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
Conversation
1. Let _daysInMonth_ be CalendarDaysInMonth(_calendar_, _arithmeticYear_, _ordinalMonth_). | ||
1. If _daysInMonth_ < _day_, then | ||
1. If _overflow_ is ~reject~, throw a *RangeError* exception. | ||
1. Let _regulatedDay_ be _daysInMonth_. | ||
1. Else, | ||
1. Let _regulatedDay_ be _day_. | ||
1. Return ? CalendarIntegersToISO(_calendar_, _arithmeticYear_, _ordinalMonth_, _regulatedDay_). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this spec works by interpreting day as an ordinal day. I don't think we use any other type of day. I think this AO reads as though @ptomato had thought that day should be the day number as opposed to an ordinal day. I'm open to using language such as ordinalDay to make my interpretation more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the definition of [[Day]]
:
<tr>
<td>[[Day]]</td>
<td>a positive integer</td>
<td>
The 1-based ordinal position of the date's day within its month.
</td>
</tr>
It already says it is the ordinal day, not the day number.
Should we still be more clear?
The edge case, of course, are dates such as October 10, 1867 that don't exist in certain regions like Alaska due to Gregorian switchover. If you write code such as
Temporal.PlainDate.from({ calendar: "gregory-usak", year: 1867, month: 10, day: 10 })
should it:
- Constrain down to October 5, 1867
- Constrain up to October 18, 1867
- Interpret the day as an ordinal and return October 22, 1867 (the 10th day in October that year)
Option 3 is much easier implementation-wise than anything else.
This is also more of an academic question at this point because we don't have julian-gregorian support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see your point now about this looking like it refers to non-ordinal days. I intended it to refer to days that ran off the end of a month, like February 30. I got the language from NonISOCalendarDateToISO and probably "If there are two equally-close dates in that month, pick the later one" should be removed from there. I would guess that was written before we defined day
as ordinal day (which happened in a normative change in January 2023)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, in CalendarYearMonthFromFields:
- Let firstDayIndex be the 1-based index of the first day of the month described by fields (i.e., 1 unless the month's first day is skipped by this calendar.)
1. Return an implementation-defined ISO Date Record that corresponds to the date described by _calendar_, _arithmeticYear_, _ordinalMonth_, and _day_. | ||
1. Let _daysInMonth_ be CalendarDaysInMonth(_calendar_, _arithmeticYear_, _ordinalMonth_). | ||
1. If _daysInMonth_ < _day_, then | ||
1. If _overflow_ is ~reject~, throw a *RangeError* exception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that this RangeError isn't in the prose being edited, but I think it was wrongfully removed in #73. Previously the spec said
1. If _fields_ describes an existing date in _calendar_, return an implementation-defined ISO Date Record that corresponds to the date described by _fields_.
1. If _overflow_ is ~reject~, throw a *RangeError* exception.
So it would have thrown on an invalid day.
spec.emu
Outdated
1. Else if _day_ < 1, then | ||
1. If _overflow_ is ~reject~, throw a *RangeError* exception. | ||
1. Let _regulatedDay_ be 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can get here - Calendar Fields Records can only have a positive integer or UNSET in the [[Day]] field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, good catch
|
||
<emu-clause id="sec-temporal-calendarintegerstoiso" type="implementation-defined abstract operation"> | ||
<h1> | ||
CalendarIntegersToISO ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this operation adds much when pulled out into its own AO, and everywhere else we use year/month code/day to refer unambiguously to a date, not the ordinal month. (Same thing for CalendarDaysInMonth.) I don't see this operation on the ICU4X flowchart either? Should it conceptually be part of ICU4X and not Temporal?
I guess you probably have some purpose in mind for it.
If you decide to keep it I'd probably look for a different name. I find the term "calendar integers" confusing, how about NonISOCalendarDateWithOrdinalMonthToISO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This AO makes more sense in the next PR but I can hold it for then if you prefer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is valuable even in the context of the current PR because it makes the calendar-specific algorithm be isolated to a small AO.
I was complimented by @gibson042 for making smaller PRs with pieces of #69. Here is the Thursday/Friday edition.