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 era formatting #1346

Merged
merged 21 commits into from
Nov 30, 2021
Merged

Implement era formatting #1346

merged 21 commits into from
Nov 30, 2021

Conversation

Manishearth
Copy link
Member

@Manishearth Manishearth commented Nov 25, 2021

Based on #1344

Fixes #1312

This is ready to review, but still contains commits from #1344 (this PR starts at the commit labeled "add era field parsing" f75ac59)

This implements DTF handling for the era symbol G and the ability to format eras.

components/datetime/tests/datetime.rs Outdated Show resolved Hide resolved
8 => Second::idx_in_range(&symbol),
9 => TimeZone::idx_in_range(&symbol),
0 => true, // eras
1 => Year::idx_in_range(&symbol),
Copy link
Member

Choose a reason for hiding this comment

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

Comment: Changing these numbers would break the data file for older ICU4X versions. It's okay to make this change now, but after 1.0, we should add new items to the end, rather than changing the indices for all the old values.

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 I'm trying to keep these in order; I think before 1.0 if we're missing symbols we should add them and just have them raise runtime errors

Copy link
Member

Choose a reason for hiding this comment

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

(later) We should discuss options with Zibi. Perhaps we should use TinyStr here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps, but we won't be able to postprocess the TinyStr without allocating, so we'd have to use a string-matching ZeroMap, which isn't as cheap

components/datetime/src/provider/date_time.rs Outdated Show resolved Hide resolved
@Manishearth
Copy link
Member Author

I think I'll move the code to using tinystr as a followup and simultaneously make the data structs borrow

@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • components/calendar/src/gregorian.rs is no longer changed in the branch
  • components/datetime/src/calendar.rs is no longer changed in the branch
  • components/datetime/src/provider/calendar/symbols.rs is no longer changed in the branch
  • provider/cldr/src/cldr_serde/ca.rs is no longer changed in the branch
  • provider/cldr/src/transform/datetime/symbols.rs is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/ar-EG.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/ar.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/bn.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/ccp.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/en-001.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/en-ZA.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/en.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/es-AR.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/es.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/fil.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/fr.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/ja.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/ru.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/sr-Cyrl.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/sr-Latn.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/sr.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/th.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/tr.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/buddhist/und.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/ar-EG.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/ar.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/bn.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/ccp.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/en-001.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/en-ZA.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/en.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/es-AR.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/es.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/fil.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/fr.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/ja.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/ru.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/sr-Cyrl.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/sr-Latn.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/sr.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/th.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/tr.json is no longer changed in the branch
  • provider/testdata/data/json/datetime/symbols@1/gregory/und.json is no longer changed in the branch

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

@Manishearth
Copy link
Member Author

No code changes, just a rebase over the landed dep PR

zbraniecki
zbraniecki previously approved these changes Nov 29, 2021
Copy link
Member

@zbraniecki zbraniecki left a comment

Choose a reason for hiding this comment

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

lgtm!

components/datetime/src/fields/symbols.rs Outdated Show resolved Hide resolved
return symbols
.0
.get(idx)
.map(|x| &**x)
Copy link
Member

Choose a reason for hiding this comment

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

optional (n-b): can you use .map(|x| x.as_ref()) here? It's more readable.

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 won't work since we're dereferencing a Cow here, deref coercions don't work through iterators like that

Copy link
Member

Choose a reason for hiding this comment

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

Did you check? I pulled your branch, replaced with x.as_ref() and it compiles.

Copy link
Member

Choose a reason for hiding this comment

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

.map(AsRef::as_ref) works as well

sffc
sffc previously approved these changes Nov 30, 2021
@Manishearth Manishearth dismissed stale reviews from sffc and zbraniecki via 688ad9a November 30, 2021 01:43
@Manishearth Manishearth merged commit fcf248c into unicode-org:main Nov 30, 2021
@Manishearth Manishearth deleted the era-format branch November 30, 2021 02: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.

Implement era formatting
3 participants