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

Implement the Japanese calendar #1394

Merged
merged 17 commits into from
Dec 18, 2021
Merged

Conversation

Manishearth
Copy link
Member

Fixes #1116

This data is not zero-copy (followup at #1393, it is blocked on zbraniecki/tinystr#56), but otherwise this works fine.

I elected to put end-to-end tests for japanese era data as a separate datetime fixture.

This change does not consider era breaks to change the number of "days in a year"; I'm not sure if this really should be the case but a lot of other things get very confusing (how does adding a year work around an era break?).

@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • provider/testdata/data/testdata.postcard is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

zbraniecki
zbraniecki previously approved these changes Dec 17, 2021
day: 1,
};

const FALLBACK_ERA: (EraStartDate, TinyStr16) = (REIWA_START, tinystr16!("reiwa"));
Copy link
Member

Choose a reason for hiding this comment

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

question: is there a good reason for that to be hardcoded? Should it be in some data file?

Copy link
Member Author

Choose a reason for hiding this comment

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

The era start dates are never going to change, this is an optimization

Copy link
Member Author

Choose a reason for hiding this comment

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

And the fallback era will only be hit if the data file has bugs.

let era_data = self.eras.get();
let deref_tuple = |x: (&EraStartDate, &TinyStr16)| (*x.0, *x.1);
if date >= MEIJI_START {
if era_data.dates_to_eras.len() == 5 {
Copy link
Member

Choose a reason for hiding this comment

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

question: how did you chose 5 as a cut-off for hardcoded eras? Can you document your thinking to help someone one day follow the logics when updating it if needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, "Meiji" onwards are the five modern eras.

zbraniecki
zbraniecki previously approved these changes Dec 17, 2021
@Manishearth
Copy link
Member Author

Argh, needed to rebase

@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • provider/testdata/data/testdata.postcard is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

@Manishearth Manishearth merged commit e165d22 into unicode-org:main Dec 18, 2021
"stand_alone": null
},
"eras": {
"names": {
Copy link
Member

Choose a reason for hiding this comment

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

Issue: including the premodern era names bloats data size. I recall us discussing that premodern eras would use Gregorian eras.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't recall that being resolved, perhaps we should have a followup? I think the resolution was that premodern eras get the more complex era codes.

Copy link
Member

Choose a reason for hiding this comment

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

I think we may consider shipping the historic eras as an optional extension. But yes, we should file an issue, because this is simply way too much data without a great way to slice it

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah we can have calendar/japanese@1/{modern, historical} variants and by default it only loads modern. An interesting question would be if it should load historical unconditionally if it's present in the data, or if it should be an option during construction (enum Historical { Yes, No, Try })

A nice property of such an architecture is that we can have the hardcoded fallback for when modern data is unavailable as well.

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 feels like a good mentorable help wanted bug

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Implement the Japanese calendar
3 participants