-
Notifications
You must be signed in to change notification settings - Fork 183
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
Add cyclic year to FormattableYear
#3581
Add cyclic year to FormattableYear
#3581
Conversation
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 looks good!
@@ -37,9 +37,6 @@ impl FromStr for Era { | |||
} | |||
|
|||
/// Representation of a formattable year. | |||
/// | |||
/// More fields may be added in the future, for things like | |||
/// the cyclic or extended 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.
nit: we should probably keep the comment around for extended 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.
I've added the comment back in
components/calendar/src/types.rs
Outdated
@@ -49,6 +46,10 @@ pub struct FormattableYear { | |||
/// The year number in the current era (usually 1-based). | |||
pub number: i32, | |||
|
|||
/// The year in the current cycle for cyclic calendars; | |||
/// can be ignored and set to any value for non-cyclic calendars. | |||
pub cyclic: 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.
issue: this should probably be an Option
, allowing formatter implementations to choose how to handle unknown cyclics
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.
Ok, I made this an Option with all currently existing calendars having this field set to None
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.
LGTM
Traditionally, instead of counting ordinal years (ex. 1, 2, 3, ... 2022, 2023, ...), the Chinese calendar counts years in cycles of 60 (ex. 1, 2, 3, ... 59, 60, 1, 2, 3, ...), at least insofar as the names of years repeat each 60 years. Although in modern times the year can be counted by using the associated Gregorian/ISO year (which already has a
related_iso
field inFormattableYear
), cyclic year is still necessary to provide complete date formatting for the Chinese calendar.Considering this, I propose adding a single field
pub cyclic: i32
toFormattableYear
, which can be set to any value for non-cyclic calendars (I set the field to be 0 in all currently-existing calendars, but it doesn't matter for those calendars since this value should not be read), and set to an integer value for calendars like the Chinese calendar which use cyclic years.