-
Notifications
You must be signed in to change notification settings - Fork 220
Open
Labels
C-calendarComponent: CalendarsComponent: Calendarsdiscuss-priorityDiscuss at the next ICU4X meetingDiscuss at the next ICU4X meeting
Milestone
Description
Since China and Korea have different leap years, in #6910, I added a month_day_to_reference_year
function to the new Rules trait that was added by @robertbastian in #6938.
This is intended as a stopgap solution to unblock my Date::try_from_fields
PR. We should discuss whether this is the right trait function. Some options:
- An ECMA-specific
month_day_to_reference_year
as currently proposed- Can be bikeshed: function name? Types of arguments and return value?
- A similar but less ECMA-specific MonthDay function such as
[prev|next]_year_containing(LunarChineseYearData, MonthCode, u8) -> LunarChineseYearData
- It would return the year containing the given month/day that is less than or greater than the given year.
- The stock calendars could implement this efficiently for modern dates and maybe special-case the handful of far-away dates, falling back to a linear search.
- An intermediate solution akin to
CalendarResolveFields
in ECMA-402: take&mut DateFields
and fill in missing fields according to the MissingFieldsStrategy - Put the whole
try_from_fields
on the trait- Pro: Aligns with the contract of the
Calendar
trait - Con: Clients need to handle weird behavior like the ECMA-specific options, as well as any options we add in the future
- Pro: Aligns with the contract of the
- Don't have this on the trait at all and use a linear search at runtime following the Temporal algorithm to find the reference year
- This is what we might have been forced to do if the trait had already been stable
- Maybe it's not actually that slow: if the year lookup is constant-time, and we need to check only 200 total years in the common case
Related questions:
- Should we do the same treatment to Hijri? Since all Hijris have the same epoch, I found I didn't need it (see the implementation), but it means that any future Hijri needs to have the same extended year epoch as the stock Hijris.
- Are we confident enough in this trait for it to be public? I tend to think that we should keep it
UnstableSealed
for a while.- Do we need it to ever be actually stable? It seems like the kind of power-user feature that we can just ask people now and in the future to add the
UnstableSealed
bound and accept the contract that the trait is subject to change. This is still more convenient for them than having to implement the wholeCalendar
trait! Should the Rules traits be marked UnstableSealed? #6962
- Do we need it to ever be actually stable? It seems like the kind of power-user feature that we can just ask people now and in the future to add the
CC @Manishearth
Metadata
Metadata
Assignees
Labels
C-calendarComponent: CalendarsComponent: Calendarsdiscuss-priorityDiscuss at the next ICU4X meetingDiscuss at the next ICU4X meeting