Skip to content

Commit

Permalink
Add TimeZoneIdMapper to icu_timezone (#4774)
Browse files Browse the repository at this point in the history
Fixes #4031
Replaces #4548

This new all-in-one type supports all of the time zone ID operations we
need, with some operations being asymptotically faster than others.

Not sure if we want to deprecate the old ones or keep them around, at
least IanaBcp47RoundTripMapper. It's not completely obsolete since it
has different performance characteristics.

---------

Co-authored-by: Robert Bastian <4706271+robertbastian@users.noreply.github.com>
  • Loading branch information
sffc and robertbastian committed May 23, 2024
1 parent 782a01a commit d2c4f63
Show file tree
Hide file tree
Showing 50 changed files with 2,280 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
- Implement Hangul_Syllable_Type property (https://github.com/unicode-org/icu4x/pull/4885)
- `icu_segmenter`
- Fix Unicode 15.0 line breaking (https://github.com/unicode-org/icu4x/pull/4389)
- `icu_timezone`
- Added `TimeZoneIdMapper` to replace `IanaToBcp47Mapper` (https://github.com/unicode-org/icu4x/pull/4774)
- Data model and providers
- `icu_datagen`
- Datagen shows elapsed time for keys that are slow to generate (https://github.com/unicode-org/icu4x/pull/4469)
Expand Down
6 changes: 3 additions & 3 deletions components/datetime/src/time_zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ where
///
/// ```
/// use icu::calendar::DateTime;
/// use icu::timezone::{CustomTimeZone, MetazoneCalculator, IanaToBcp47Mapper};
/// use icu::timezone::{CustomTimeZone, MetazoneCalculator, TimeZoneIdMapper};
/// use icu::datetime::{DateTimeError, time_zone::TimeZoneFormatter};
/// use icu::locid::locale;
/// use tinystr::tinystr;
Expand All @@ -87,7 +87,7 @@ where
/// // Set up the Metazone calculator, time zone ID mapper,
/// // and the DateTime to use in calculation
/// let mzc = MetazoneCalculator::new();
/// let mapper = IanaToBcp47Mapper::new();
/// let mapper = TimeZoneIdMapper::new();
/// let datetime = DateTime::try_new_iso_datetime(2022, 8, 29, 0, 0, 0)
/// .unwrap();
///
Expand All @@ -102,7 +102,7 @@ where
///
/// // "uschi" - has metazone symbol data for generic_non_location_short
/// let mut time_zone = "-0600".parse::<CustomTimeZone>().unwrap();
/// time_zone.time_zone_id = mapper.as_borrowed().get("America/Chicago");
/// time_zone.time_zone_id = mapper.as_borrowed().iana_to_bcp47("America/Chicago");
/// time_zone.maybe_calculate_metazone(&mzc, &datetime);
/// assert_writeable_eq!(
/// tzf.format(&time_zone),
Expand Down
2 changes: 1 addition & 1 deletion components/timezone/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ displaydoc = { workspace = true }
icu_calendar = { workspace = true }
icu_provider = { workspace = true, features = ["macros"] }
tinystr = { workspace = true, features = ["alloc", "zerovec"] }
zerotrie = { workspace = true, features = ["yoke", "zerofrom"] }
zerotrie = { workspace = true, features = ["alloc", "yoke", "zerofrom"] }
zerovec = { workspace = true, features = ["derive", "yoke"] }

databake = { workspace = true, optional = true, features = ["derive"] }
Expand Down
8 changes: 4 additions & 4 deletions components/timezone/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions components/timezone/src/iana_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

#![allow(deprecated)] // all APIS in here are deprecated

use crate::error::TimeZoneError;
use crate::provider::names::*;
use crate::TimeZoneBcp47Id;
Expand Down Expand Up @@ -36,6 +38,7 @@ use icu_provider::prelude::*;
/// );
/// ```
#[derive(Debug)]
#[deprecated(since = "1.5.0", note = "use `TimeZoneIdMapper` instead")]
pub struct IanaToBcp47Mapper {
data: DataPayload<IanaToBcp47MapV1Marker>,
}
Expand Down Expand Up @@ -98,6 +101,7 @@ impl IanaToBcp47Mapper {
/// A borrowed wrapper around IANA-to-BCP47 time zone data, returned by
/// [`IanaToBcp47Mapper::as_borrowed()`]. More efficient to query.
#[derive(Debug)]
#[deprecated(since = "1.5.0", note = "use `TimeZoneIdMapper` instead")]
pub struct IanaToBcp47MapperBorrowed<'a> {
data: &'a IanaToBcp47MapV1<'a>,
}
Expand Down Expand Up @@ -167,6 +171,7 @@ impl<'a> IanaToBcp47MapperBorrowed<'a> {
/// assert_eq!(iana_id, Some("Asia/Kolkata"))
/// ```
#[derive(Debug)]
#[deprecated(since = "1.5.0", note = "use `TimeZoneIdMapper` instead")]
pub struct IanaBcp47RoundTripMapper {
data1: DataPayload<IanaToBcp47MapV1Marker>,
data2: DataPayload<Bcp47ToIanaMapV1Marker>,
Expand Down Expand Up @@ -243,6 +248,7 @@ impl IanaBcp47RoundTripMapper {
/// A borrowed wrapper around IANA-BCP47 time zone data, returned by
/// [`IanaBcp47RoundTripMapper::as_borrowed()`]. More efficient to query.
#[derive(Debug)]
#[deprecated(since = "1.5.0", note = "use `TimeZoneIdMapper` instead")]
pub struct IanaBcp47RoundTripMapperBorrowed<'a> {
data1: &'a IanaToBcp47MapV1<'a>,
data2: &'a Bcp47ToIanaMapV1<'a>,
Expand Down
Loading

0 comments on commit d2c4f63

Please sign in to comment.