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

convert metazone period from string to i32 #2085

Merged
merged 6 commits into from
Jul 6, 2022

Conversation

samchen61661
Copy link
Member

Convert metazone period from string to i32 (#2034)

@sffc
Copy link
Member

sffc commented Jun 27, 2022

Hi Sam! Sorry for the delay on this! I am working on my review but I wanted to add @Manishearth to review the icu_calendar part of it.

components/calendar/src/iso.rs Outdated Show resolved Hide resolved
components/calendar/src/iso.rs Outdated Show resolved Hide resolved
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.

Praise: Nice savings! 8% over the whole data file is great.

components/datetime/src/provider/time_zones.rs Outdated Show resolved Hide resolved
components/calendar/src/iso.rs Outdated Show resolved Hide resolved
components/calendar/src/iso.rs Outdated Show resolved Hide resolved
components/calendar/src/iso.rs Outdated Show resolved Hide resolved
components/calendar/src/iso.rs Outdated Show resolved Hide resolved
provider/datagen/src/transform/cldr/time_zones/convert.rs Outdated Show resolved Hide resolved
"2020-03-07 16:00": "auwe",
"2020-10-03 16:01": "case"
"0": "auwe",
"20931480": "case",
Copy link
Member

Choose a reason for hiding this comment

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

Thought: I wonder if we should serialize the integer in Postcard and the nice string in JSON.

The way to do this would be to make a new type like MinutesSinceEpoch, use it instead of i32 in the ZeroMap, and give it a custom Serialize and Deserialize impl.

I don't want you to do it in this PR, but if you think it's a good idea, you can open an issue and do it as a follow-up.

Copy link
Member Author

Choose a reason for hiding this comment

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

What benefits we can get from it apart from type checking and code style?

Copy link
Member Author

Choose a reason for hiding this comment

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

Json file would be more readable, json file API customized.

Serialize as raw date timestamp in Json and deserialize as MinutesSinceEpoch.

File an issue for it.

@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • components/calendar/src/error.rs is now changed in the branch
  • components/calendar/src/iso.rs is different
  • components/datetime/src/provider/time_zones.rs is different
  • provider/datagen/src/transform/cldr/time_zones/convert.rs is different
  • provider/datagen/src/transform/cldr/time_zones/mod.rs is different
  • provider/testdata/data/baked/time_zone/metazone_period_v1.rs is different
  • provider/testdata/data/json/time_zone/metazone_period@1/ar-EG.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/ar.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/bn.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/ccp.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/en-001.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/en-ZA.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/en.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/es-AR.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/es.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/fil.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/fr.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/ja.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/ru.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/sr-Cyrl.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/sr-Latn.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/sr.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/th.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/tr.json is different
  • provider/testdata/data/json/time_zone/metazone_period@1/und.json is different
  • provider/testdata/data/testdata.postcard is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

let minutes_a_hour = 60;
let hours_a_day = 24;
let minutes_a_day = minutes_a_hour * hours_a_day;
if let Ok(unix_epoch) = DateTime::new_iso_datetime(1970, 1, 1, 0, 0, 0) {
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 the math since we need to consider time here.

Manishearth
Manishearth previously approved these changes Jul 1, 2022
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.

calendar code is mostly fine, one issue

components/calendar/src/iso.rs Outdated Show resolved Hide resolved
sffc
sffc previously approved these changes Jul 2, 2022
components/calendar/src/iso.rs Outdated Show resolved Hide resolved
components/calendar/src/iso.rs Outdated Show resolved Hide resolved
@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • components/calendar/src/iso.rs is different
  • provider/testdata/data/baked/time_zone/metazone_period_v1.rs is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

/// assert_eq!(today.minutes_since_local_unix_epoch(), 0);
/// assert_eq!(DateTime::from_minutes_since_local_unix_epoch(0), Ok(today));
/// ```
pub fn minutes_since_local_unix_epoch(&self) -> i32 {
Copy link
Member

Choose a reason for hiding this comment

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

Thought: We need to think about what happens when overflow occurs, but this is a problem that is all over the icu_calendar crate, not just this function, so we shouldn't block this PR on a resolution to it. I opened #2151

Copy link
Member Author

Choose a reason for hiding this comment

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

sg!

@samchen61661 samchen61661 merged commit 3b9553e into unicode-org:main Jul 6, 2022
samchen61661 added a commit to samchen61661/icu4x that referenced this pull request Jul 12, 2022
* convert metazone period from string to i32

* address comments

* address minor comments

* remove unnecssary import

* fix test

* make testdata
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