Skip to content

Commit

Permalink
move data
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Oct 15, 2024
1 parent a503202 commit a363450
Show file tree
Hide file tree
Showing 17 changed files with 174 additions and 171 deletions.
4 changes: 4 additions & 0 deletions components/datetime/src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ const _: () = {
impl_locations_v1_marker!(Baked);
impl_metazone_generic_names_long_v1_marker!(Baked);
impl_metazone_generic_names_short_v1_marker!(Baked);
impl_metazone_period_v1_marker!(Baked);
impl_metazone_specific_names_long_v1_marker!(Baked);
impl_metazone_specific_names_short_v1_marker!(Baked);
impl_time_zone_essentials_v1_marker!(Baked);
impl_zone_offset_period_v1_marker!(Baked);

impl_weekday_names_v1_marker!(Baked);
impl_day_period_names_v1_marker!(Baked);
Expand Down Expand Up @@ -110,9 +112,11 @@ pub const MARKERS: &[DataMarkerInfo] = &[
time_zones::LocationsV1Marker::INFO,
time_zones::MetazoneGenericNamesLongV1Marker::INFO,
time_zones::MetazoneGenericNamesShortV1Marker::INFO,
time_zones::MetazonePeriodV1Marker::INFO,
time_zones::MetazoneSpecificNamesLongV1Marker::INFO,
time_zones::MetazoneSpecificNamesShortV1Marker::INFO,
time_zones::TimeZoneEssentialsV1Marker::INFO,
time_zones::ZoneOffsetPeriodV1Marker::INFO,
neo::WeekdayNamesV1Marker::INFO,
neo::DayPeriodNamesV1Marker::INFO,
neo::GluePatternV1Marker::INFO,
Expand Down
105 changes: 103 additions & 2 deletions components/datetime/src/provider/time_zones.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
use alloc::borrow::Cow;
use icu_pattern::{DoublePlaceholderPattern, SinglePlaceholderPattern};
use icu_provider::prelude::*;
use zerovec::{ZeroMap, ZeroMap2d};
use tinystr::TinyAsciiStr;
use zerovec::{
ule::{AsULE, ULE},
ZeroMap, ZeroMap2d, ZeroSlice, ZeroVec,
};

pub use icu_timezone::provider::{MetazoneId, TimeZoneBcp47Id};
pub use icu_timezone::provider::TimeZoneBcp47Id;
use icu_timezone::ZoneVariant;

/// Time zone type aliases for cleaner code
Expand Down Expand Up @@ -170,3 +174,100 @@ pub struct MetazoneSpecificNamesV1<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
pub overrides: ZeroMap2d<'data, TimeZoneBcp47Id, ZoneVariant, str>,
}

/// Metazone ID in a compact format
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[repr(transparent)]
#[derive(Debug, Clone, Copy, Eq, Ord, PartialEq, PartialOrd, yoke::Yokeable, ULE, Hash)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
#[cfg_attr(feature = "datagen", databake(path = icu_datetime::provider::time_zones))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub struct MetazoneId(pub TinyAsciiStr<4>);

impl AsULE for MetazoneId {
type ULE = Self;

#[inline]
fn to_unaligned(self) -> Self::ULE {
self
}

#[inline]
fn from_unaligned(unaligned: Self::ULE) -> Self {
unaligned
}
}

impl<'a> zerovec::maps::ZeroMapKV<'a> for MetazoneId {
type Container = ZeroVec<'a, MetazoneId>;
type Slice = ZeroSlice<MetazoneId>;
type GetType = MetazoneId;
type OwnedType = MetazoneId;
}

/// An ICU4X mapping to the metazones at a given period.
/// See CLDR-JSON metaZones.json for more context.
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[icu_provider::data_struct(marker(
MetazonePeriodV1Marker,
"time_zone/metazone_period@1",
singleton
))]
#[derive(PartialEq, Debug, Clone, Default)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
#[cfg_attr(feature = "datagen", databake(path = icu_datetime::provider::time_zones))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[yoke(prove_covariance_manually)]
pub struct MetazonePeriodV1<'data>(
/// The default mapping between period and metazone id. The second level key is a wall-clock time represented as
/// the number of minutes since the local unix epoch. It represents when the metazone started to be used.
#[cfg_attr(feature = "serde", serde(borrow))]
pub ZeroMap2d<'data, TimeZoneBcp47Id, IsoMinutesSinceEpoch, Option<MetazoneId>>,
);

/// Storage type for storing UTC offsets as eights of an hour.
pub type EighthsOfHourOffset = i8;
/// Storage type for storing `DateTime<Iso>` as minutes since the UNIX epoch.
pub type IsoMinutesSinceEpoch = i32;

/// An ICU4X mapping to the time zone offsets at a given period.
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[icu_provider::data_struct(marker(
ZoneOffsetPeriodV1Marker,
"time_zone/offset_period@1",
singleton
))]
#[derive(PartialEq, Debug, Clone, Default)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
#[cfg_attr(feature = "datagen", databake(path = icu_datetime::provider::time_zones))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[yoke(prove_covariance_manually)]
pub struct ZoneOffsetPeriodV1<'data>(
/// The default mapping between period and offsets. The second level key is a wall-clock time represented as
/// the number of minutes since the local unix epoch. It represents when the offsets ended to be used.
///
/// The values are the standard offset, and the daylight offset *relative to the standard offset*. As such,
/// if the second value is 0, there is no daylight time.
#[cfg_attr(feature = "serde", serde(borrow))]
pub ZeroMap2d<
'data,
TimeZoneBcp47Id,
IsoMinutesSinceEpoch,
(EighthsOfHourOffset, EighthsOfHourOffset),
>,
);
17 changes: 9 additions & 8 deletions components/datetime/src/time_zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

//! A formatter specifically for the time zone.

use crate::provider::time_zones::MetazoneId;
use crate::{
fields::{FieldLength, TimeZone},
input::ExtractedInput,
Expand All @@ -12,7 +13,7 @@ use crate::{
use core::fmt;
use fixed_decimal::FixedDecimal;
use icu_decimal::FixedDecimalFormatter;
use icu_timezone::{provider::MetazoneId, TimeZoneBcp47Id, UtcOffset, ZoneVariant};
use icu_timezone::{TimeZoneBcp47Id, UtcOffset, ZoneVariant};
use writeable::Writeable;

/// All time zone styles that this crate can format
Expand Down Expand Up @@ -217,7 +218,7 @@ impl ExtractedInput {
fn zone_variant_or_guess(
&self,
time_zone_id: TimeZoneBcp47Id,
offset_period: &icu_timezone::provider::ZoneOffsetPeriodV1,
offset_period: &crate::provider::time_zones::ZoneOffsetPeriodV1,
) -> ZoneVariant {
if let Some(zv) = self.zone_variant {
return zv;
Expand Down Expand Up @@ -268,7 +269,7 @@ impl ExtractedInput {
fn metazone(
&self,
time_zone_id: TimeZoneBcp47Id,
metazone_period: &icu_timezone::provider::MetazonePeriodV1,
metazone_period: &crate::provider::time_zones::MetazonePeriodV1,
) -> Option<MetazoneId> {
match metazone_period.0.get0(&time_zone_id) {
Some(cursor) => {
Expand Down Expand Up @@ -433,7 +434,7 @@ impl FormatTimeZone for GenericNonLocationFormat {

let metazone_id = input.metazone(
time_zone_id,
icu_timezone::provider::Baked::SINGLETON_METAZONE_PERIOD_V1_MARKER,
crate::provider::Baked::SINGLETON_METAZONE_PERIOD_V1_MARKER,
);

let Some(name) = metazone_id.and_then(|mz| {
Expand Down Expand Up @@ -469,7 +470,7 @@ impl FormatTimeZone for SpecificNonLocationFormat {
};
let zone_variant = input.zone_variant_or_guess(
time_zone_id,
icu_timezone::provider::Baked::SINGLETON_ZONE_OFFSET_PERIOD_V1_MARKER,
crate::provider::Baked::SINGLETON_ZONE_OFFSET_PERIOD_V1_MARKER,
);

let Some(names) = (match self.0 {
Expand All @@ -481,7 +482,7 @@ impl FormatTimeZone for SpecificNonLocationFormat {

let metazone_id = input.metazone(
time_zone_id,
icu_timezone::provider::Baked::SINGLETON_METAZONE_PERIOD_V1_MARKER,
crate::provider::Baked::SINGLETON_METAZONE_PERIOD_V1_MARKER,
);

let Some(name) = metazone_id.and_then(|mz| {
Expand Down Expand Up @@ -647,7 +648,7 @@ impl FormatTimeZone for SpecificLocationFormat {

let zone_variant = input.zone_variant_or_guess(
time_zone_id,
icu_timezone::provider::Baked::SINGLETON_ZONE_OFFSET_PERIOD_V1_MARKER,
crate::provider::Baked::SINGLETON_ZONE_OFFSET_PERIOD_V1_MARKER,
);

if let Some(location) = locations.locations.get(&time_zone_id) {
Expand Down Expand Up @@ -697,7 +698,7 @@ impl FormatTimeZone for GenericPartialLocationFormat {

let metazone_id = input.metazone(
time_zone_id,
icu_timezone::provider::Baked::SINGLETON_METAZONE_PERIOD_V1_MARKER,
crate::provider::Baked::SINGLETON_METAZONE_PERIOD_V1_MARKER,
);

let Some(location) = locations.locations.get(&time_zone_id) else {
Expand Down
103 changes: 1 addition & 102 deletions components/timezone/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use core::ops::Deref;
use icu_provider::prelude::*;
use tinystr::TinyAsciiStr;
use zerovec::ule::{AsULE, ULE};
use zerovec::{ZeroMap2d, ZeroSlice, ZeroVec};
use zerovec::{ZeroSlice, ZeroVec};

pub mod names;
pub mod windows;
Expand All @@ -45,19 +45,15 @@ const _: () = {
make_provider!(Baked);
impl_bcp47_to_iana_map_v1_marker!(Baked);
impl_iana_to_bcp47_map_v3_marker!(Baked);
impl_metazone_period_v1_marker!(Baked);
impl_windows_zones_to_bcp47_map_v1_marker!(Baked);
impl_zone_offset_period_v1_marker!(Baked);
};

#[cfg(feature = "datagen")]
/// The latest minimum set of markers required by this component.
pub const MARKERS: &[DataMarkerInfo] = &[
MetazonePeriodV1Marker::INFO,
names::Bcp47ToIanaMapV1Marker::INFO,
names::IanaToBcp47MapV3Marker::INFO,
windows::WindowsZonesToBcp47MapV1Marker::INFO,
ZoneOffsetPeriodV1Marker::INFO,
];

/// TimeZone ID in BCP47 format
Expand Down Expand Up @@ -112,100 +108,3 @@ impl<'a> zerovec::maps::ZeroMapKV<'a> for TimeZoneBcp47Id {
type GetType = TimeZoneBcp47Id;
type OwnedType = TimeZoneBcp47Id;
}

/// Metazone ID in a compact format
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[repr(transparent)]
#[derive(Debug, Clone, Copy, Eq, Ord, PartialEq, PartialOrd, yoke::Yokeable, ULE, Hash)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
#[cfg_attr(feature = "datagen", databake(path = icu_timezone::provider))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub struct MetazoneId(pub TinyAsciiStr<4>);

impl AsULE for MetazoneId {
type ULE = Self;

#[inline]
fn to_unaligned(self) -> Self::ULE {
self
}

#[inline]
fn from_unaligned(unaligned: Self::ULE) -> Self {
unaligned
}
}

impl<'a> zerovec::maps::ZeroMapKV<'a> for MetazoneId {
type Container = ZeroVec<'a, MetazoneId>;
type Slice = ZeroSlice<MetazoneId>;
type GetType = MetazoneId;
type OwnedType = MetazoneId;
}

/// An ICU4X mapping to the metazones at a given period.
/// See CLDR-JSON metaZones.json for more context.
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[icu_provider::data_struct(marker(
MetazonePeriodV1Marker,
"time_zone/metazone_period@1",
singleton
))]
#[derive(PartialEq, Debug, Clone, Default)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
#[cfg_attr(feature = "datagen", databake(path = icu_timezone::provider))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[yoke(prove_covariance_manually)]
pub struct MetazonePeriodV1<'data>(
/// The default mapping between period and metazone id. The second level key is a wall-clock time represented as
/// the number of minutes since the local unix epoch. It represents when the metazone started to be used.
#[cfg_attr(feature = "serde", serde(borrow))]
pub ZeroMap2d<'data, TimeZoneBcp47Id, IsoMinutesSinceEpoch, Option<MetazoneId>>,
);

/// Storage type for storing UTC offsets as eights of an hour.
pub type EighthsOfHourOffset = i8;
/// Storage type for storing `DateTime<Iso>` as minutes since the UNIX epoch.
pub type IsoMinutesSinceEpoch = i32;

/// An ICU4X mapping to the time zone offsets at a given period.
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[icu_provider::data_struct(marker(
ZoneOffsetPeriodV1Marker,
"time_zone/offset_period@1",
singleton
))]
#[derive(PartialEq, Debug, Clone, Default)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
#[cfg_attr(feature = "datagen", databake(path = icu_timezone::provider))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[yoke(prove_covariance_manually)]
pub struct ZoneOffsetPeriodV1<'data>(
/// The default mapping between period and offsets. The second level key is a wall-clock time represented as
/// the number of minutes since the local unix epoch. It represents when the offsets ended to be used.
///
/// The values are the standard offset, and the daylight offset *relative to the standard offset*. As such,
/// if the second value is 0, there is no daylight time.
#[cfg_attr(feature = "serde", serde(borrow))]
pub ZeroMap2d<
'data,
TimeZoneBcp47Id,
IsoMinutesSinceEpoch,
(EighthsOfHourOffset, EighthsOfHourOffset),
>,
);

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions provider/data/datetime/data/mod.rs

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

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions provider/data/datetime/fingerprints.csv
Original file line number Diff line number Diff line change
Expand Up @@ -35814,6 +35814,8 @@ time_zone/locations@1, zh-Hant, 9144B, 8985B, 26eed758c6fb3d8d
time_zone/locations@1, zh-MO, -> zh-HK
time_zone/locations@1, zh-SG, 9247B, 9088B, dbf3a8f8eb62d828
time_zone/locations@1, zu, 9086B, 8927B, cebb6ba6c35f2d98
time_zone/metazone_period@1, <singleton>, 11097B, 11009B, dcfa50fb39ebd549
time_zone/offset_period@1, <singleton>, 13374B, 13286B, 397b18d3f2345411
time_zone/specific_long@1, <lookup>, 948B, 190 identifiers
time_zone/specific_long@1, <total>, 1638778B, 1605415B, 185 unique payloads
time_zone/specific_long@1, af, 6872B, 6692B, 92b73e3a6b592d73
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit a363450

Please sign in to comment.