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

Refactor YearInfo to separate cyclic/Temporal/Formatting eras #5509

Merged
merged 31 commits into from
Sep 12, 2024

Conversation

Manishearth
Copy link
Member

@Manishearth Manishearth commented Sep 6, 2024

Part of #3821

This produces a more precise YearInfo that produces multiple era types, and separates out cyclic from non-cyclic. Consumers of this data get to be more specific about the fallback behavior they want when asking for eras from cyclic calendars (etc).

@Manishearth Manishearth requested a review from sffc September 6, 2024 00:55
@Manishearth Manishearth force-pushed the year-refactor branch 2 times, most recently from 3540469 to 02def68 Compare September 6, 2024 01:33
@Manishearth Manishearth marked this pull request as ready for review September 6, 2024 01:38
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.

I think the main point of splitting Month/FormattableMonth and Year/FormattableYear is that the month codes and era codes are in different namespaces.

For example:

  • Hebrew month code is "M06" for Temporal but "M06L" for data
  • Islamic era code is the Islamic calendar name for Temporal but could be anything for data

I wonder if maybe the right design is, rather than splitting Year/FormattableYear, to just make a struct with a field for both namespaces of codes?

pub related_iso: Option<i32>,
/// Knowing the cyclic year is typically not enough to pinpoint a date, however cyclic calendars
/// don't typically use eras, so disambiguation can be done by saying things like "Year 甲辰 (2024)"
Cyclic(NonZeroU8, i32),
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why the cyclic year is NonZeroU8? Is it just because Chinese and Dangi count from 1 to 60?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's what it was before.

People don't really use zeroes in calendar systems.

}
}
}

impl FormattableYear {
/// Construct a new Year given an era and number
pub fn new_era(extended_year: i32, era: TinyStr16, number: i32) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I think this should probably take Era not TinyStr16

Copy link
Member Author

Choose a reason for hiding this comment

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

This mostly gets us slightly cleaner ctor calls everywhere

@Manishearth
Copy link
Member Author

I think the main point of splitting Month/FormattableMonth and Year/FormattableYear is that the month codes and era codes are in different namespaces.

I think there were some other reasons too, things were diverging over time. I'm not opposed to keeping these merged, but perhaps we can discuss this in more depth later today.

@Manishearth Manishearth changed the title Split FormattableYear and YearInfo Refactor YearInfo to separate cyclic/Temporal/Formatting eras Sep 11, 2024
@Manishearth Manishearth requested a review from a team as a code owner September 12, 2024 04:58
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.

Good work! Lots of meticulous changes

});
}
1 - year
} else if era.0 == tinystr!(16, "mundi") || era.0 == tinystr!(16, "ethiopicaa") {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: ethioaa not ethiopicaa

Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't what the spec says

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated, but the spec should also be fixed, then.

Copy link
Member Author

Choose a reason for hiding this comment

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

tc39/proposal-intl-era-monthcode#19 , seems like there already was a PR to fix this

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I thought that PR was merged long ago but no one ever hit the button.

@Manishearth Manishearth merged commit 9db1a31 into unicode-org:main Sep 12, 2024
27 of 28 checks passed
@Manishearth Manishearth deleted the year-refactor branch September 12, 2024 22:18
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.

2 participants