-
Notifications
You must be signed in to change notification settings - Fork 250
Add full support for r datetime symbol
#7327
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
base: main
Are you sure you want to change the base?
Conversation
c0cea90 to
e6b97e4
Compare
components/calendar/src/types.rs
Outdated
| /// | ||
| /// Lunar calendars, like [`Hijri`](crate::cal::Hijri), drift quickly through the Gregorian year, so related Gregorian | ||
| /// years are frequently repeated. | ||
| pub fn related_gregorian(self) -> i32 { |
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.
given that it's allowed to be negative (no eras), this should be ISO year, yes? or gregorian extended year.
I agree that hte "ISO calendar" isn't the most consistent concept, but "ISO year" is much more well defined
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.
CLDR calls it "related Gregorian" year
ISO is a format, Gregorian is a calendar. I will die on this hill
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.
If that's what CLDR calls it fair enough.
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.
Gregorian does not have signed years.
It has extended years; you could call it related_extended_gregorian but I don't think anyone wants that.
Plus, we already call it related_iso for cyclic years. You're the king of consistency.
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 happy to deprecate any mentions of related_iso
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.
ISO is a format
ISO-8601 defines a calendar system, not just a format.
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.
it defines a string format for the proleptic Gregorian calendar
sffc
left a comment
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.
It's in CLDR, but it seems to have footguns. We shouldn't add new things that have known footguns.
| } | ||
| } | ||
|
|
||
| /// The Gregorian year in which this year started. |
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.
Observation: This produces surprising results for calendars with new years in the second half of the year, like Hebrew, Ethiopian, Coptic. It also means that multiple Hijri years will have the same related ISO year.
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.
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.
Yeah, and I consider it a footgun. It is there because of Chinese, and it has a definition for other calendars, but that doesn't mean it should be used by those other calendars.
For Hebrew, I did some research with help from Gemini and found that there are a number of sources that use the later of the two years since it has more overlap (5786 <-> 2026, not 2025). For example:
https://web.library.yale.edu/cataloging/hebraica/about-hebrew-calendar
However, most sources write it as "2025-2026"
https://www.judaicaplace.com/jewish-year-calendar-5786-2025-2026-spiralbound/767278911413/
So in that sense, maybe r should print 2025-2026.
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.
do you want to take that up with CLDR? this PR moves towards parity with ICU and implements the spec
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.
It's long been a principle that we don't implement spec that we know is garbage.
Sometimes we accidentally implement spec that we didn't know was garbage and it's almost always been a pain point.
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.
Question: is there data in CLDR that is impacted by this? As in, are there Hebrew formatting patterns that use this? (I can go searching, but I suspect that answer to already be known). That impacts how much our choices matter here. If there is no such data we can start by documenting this as "The related ISO year, this is currently the ISO year in which this calendar year started, but we may tweak this definition later" and then pursue proper resolution in CLDR.
Also, what I see here is that if the spec is garbage, it's not necessarily garbage in a "simple" way, it's garbage in an architecturally-relevant way that we may not be able to quickly work around. A good design here would probably allow the symbols {r}, {r +1}, and {r - 1}, so Chinese calendars could use {r} and Hebrew calendars could use {r - 1} - {r} (or whatever, as needed). The needs of Chinese and Hebrew are different here.
I'm in favor of bopping this to CLDR, landing the code as-is with documentation saying that it may change.
Overall I would prefer to not delay proper Chinese formatting based on open questions about Hebrew formatting.
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.
Overall I would prefer to not delay proper Chinese formatting based on open questions about Hebrew formatting.
Hm? r already works for Chinese and anything that returns cyclic years.
I'm not aware of any data that uses r except in cyclic calendars.
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 misunderstood, I thought we still had hacks for chinese formatting.
In that case I think we can wait on CLDR.
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 am still also in favor of landing this with less committal docs, though.
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.
The actual behavior change is in components/datetime/src/format/datetime.rs. Previously it checked for cyclic year before trying to load the related year. This PR adds the ability to load the related year from other calendars by adding things to the traits.
I probably have comments on the trait structure, too, but I don't agree with the PR on principle so I haven't spent time thinking too much abut them.
sffc
left a comment
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.
We've been consistent about Gregorian meaning the calendar with eras and nonzero year numbers. Let's not muck it up
what's the footgun?
|
That there isn't a 1-to-1 mapping.
I prefer Temporal uses ISO for this. It's literally encoded into the API: |
The |
I consider ECMA's and Temporal's distinction between ISO and Gregorian a major flaw. I'd also like to point out that |
|
There were lengthy discussions in Temporal where we arrived at these designs, weighing lots and lots of tradeoffs. I could write it up but I have better things to spend my time on today. |
|
I don't really care about the name here. Self-consistency is a good motivator. I'd like to avoid deprecating things further just for naming reasons. |
robertbastian
left a comment
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.
There were lengthy discussions in Temporal where we arrived at these designs, weighing lots and lots of tradeoffs.
I'm not arguing against Temporal's decision, I'm arguing that we should follow it.
| } | ||
| } | ||
|
|
||
| /// The Gregorian year in which this year started. |
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.
| } | ||
| } | ||
|
|
||
| /// The Gregorian year in which this year started. |
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.
Yeah, and I consider it a footgun. It is there because of Chinese, and it has a definition for other calendars, but that doesn't mean it should be used by those other calendars.
For Hebrew, I did some research with help from Gemini and found that there are a number of sources that use the later of the two years since it has more overlap (5786 <-> 2026, not 2025). For example:
https://web.library.yale.edu/cataloging/hebraica/about-hebrew-calendar
However, most sources write it as "2025-2026"
https://www.judaicaplace.com/jewish-year-calendar-5786-2025-2026-spiralbound/767278911413/
So in that sense, maybe r should print 2025-2026.
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.
Fine architecturally.
On the ISO vs Gregorian debate I find myself slightly in favor of ISO naming (as it is currently in the PR): CLDR nomenclature compatability is a compelling argument, but I also find "ISO year" to be a good shorthand for "Gregorian extended year"
The year overlap direction question is probably something that can be figured out in a CLDR context.
sffc
left a comment
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 see a path for this PR until we work with CLDR on improving the spec
Currently we only support the
rsymbol for cyclic calendars, however nothing in the LDML says that it is only usable with cyclic calendars. This adds support for all other calendars.