Skip to content
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

Merged
merged 4 commits into from
Jun 28, 2023

Conversation

atcupps
Copy link
Contributor

@atcupps atcupps commented Jun 26, 2023

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 in FormattableYear), 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 to FormattableYear, 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.

Copy link
Member

@Manishearth Manishearth left a 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
Copy link
Member

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

Copy link
Contributor Author

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

@@ -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,
Copy link
Member

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

Copy link
Contributor Author

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

Manishearth
Manishearth previously approved these changes Jun 27, 2023
@Manishearth Manishearth merged commit 03e4e31 into unicode-org:main Jun 28, 2023
22 checks passed
Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@atcupps atcupps deleted the cyclic-formattable-year branch July 11, 2023 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants