Skip to content

Commit

Permalink
DurationFormatter: Digital Data Provider SourceDataProvider impl (#5208)
Browse files Browse the repository at this point in the history
  • Loading branch information
kartva authored Jul 21, 2024
1 parent 9a70082 commit e2a03b2
Show file tree
Hide file tree
Showing 30 changed files with 630 additions and 74 deletions.
86 changes: 86 additions & 0 deletions components/experimental/src/duration/provider.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

// Provider structs must be stable
#![allow(clippy::exhaustive_structs, clippy::exhaustive_enums)]

//! Provider structs for digital data.
use alloc::borrow::Cow;
use icu_provider::prelude::*;

#[icu_provider::data_struct(DigitalDurationDataV1Marker = "duration/digital@1")]
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(
feature = "datagen",
derive(serde::Serialize, databake::Bake),
databake(path = icu_experimental::duration::provider)
)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]

/// A struct containing digital duration data (durationUnit-type-* patterns).
pub struct DigitalDurationDataV1<'data> {
/// The separator between the hour, minute, and second fields.
#[cfg_attr(feature = "serde", serde(borrow))]
pub separator: Cow<str, 'data>,

/// The number of digits to pad hours when hour, minutes and seconds must be displayed.
/// Calculated from the hms pattern.
pub hms_padding: HmsPadding,

/// The number of digits to pad hours when only hour and minutes must be displayed.
/// Calculated from the hm pattern.
pub hm_padding: HmPadding,

/// The number of digits to pad minutes when only minutes and seconds must be displayed.
/// Calculated from the ms pattern.
pub ms_padding: MsPadding,
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(
feature = "datagen",
derive(serde::Serialize, databake::Bake),
databake(path = icu_experimental::duration::provider)
)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
/// A struct containing the number of digits to pad hours, minutes, and seconds.
pub struct HmsPadding {
/// Hour padding.
pub h: u8,
/// Minute padding.
pub m: u8,
/// Second padding.
pub s: u8,
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(
feature = "datagen",
derive(serde::Serialize, databake::Bake),
databake(path = icu_experimental::duration::provider)
)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
/// A struct containing the number of digits to pad minutes, and seconds.
pub struct MsPadding {
/// Minute padding.
pub m: u8,
/// Second padding.
pub s: u8,
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(
feature = "datagen",
derive(serde::Serialize, databake::Bake),
databake(path = icu_experimental::duration::provider)
)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
/// A struct containing the number of digits to pad hours and minutes.
pub struct HmPadding {
/// Hour padding.
pub h: u8,
/// Minute padding.
pub m: u8,
}
64 changes: 0 additions & 64 deletions components/experimental/src/duration/provider/digital.rs

This file was deleted.

10 changes: 0 additions & 10 deletions components/experimental/src/duration/provider/mod.rs

This file was deleted.

2 changes: 2 additions & 0 deletions components/experimental/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub mod provider {
impl_units_display_name_v1_marker!(Baked);
impl_units_essentials_v1_marker!(Baked);
impl_language_display_names_v1_marker!(Baked);
impl_digital_duration_data_v1_marker!(Baked);
impl_locale_display_names_v1_marker!(Baked);
impl_region_display_names_v1_marker!(Baked);
impl_script_display_names_v1_marker!(Baked);
Expand Down Expand Up @@ -96,6 +97,7 @@ pub mod provider {
super::dimension::provider::units_essentials::UnitsEssentialsV1Marker::INFO,
super::dimension::provider::units::UnitsDisplayNameV1Marker::INFO,
super::displaynames::provider::LanguageDisplayNamesV1Marker::INFO,
super::duration::provider::DigitalDurationDataV1Marker::INFO,
super::displaynames::provider::LocaleDisplayNamesV1Marker::INFO,
super::displaynames::provider::RegionDisplayNamesV1Marker::INFO,
super::displaynames::provider::ScriptDisplayNamesV1Marker::INFO,
Expand Down

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

3 changes: 3 additions & 0 deletions provider/data/experimental/data/mod.rs

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

18 changes: 18 additions & 0 deletions provider/data/experimental/fingerprints.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,24 @@ displaynames/variants@1, zh-HK, 2311B, 5a7434f5d9429164
displaynames/variants@1, zh-Hant, 2320B, eb896ef02b8254b
displaynames/variants@1, zh-MO, 2311B, -> zh-HK
displaynames/variants@1, zu, 2916B, ede929b5c378882b
duration/digital@1, <lookup>, 100B, 16 identifiers
duration/digital@1, <total>, 198B, 6 unique payloads
duration/digital@1, af, 33B, 8174d4566fb4f92c
duration/digital@1, be, 33B, -> af
duration/digital@1, da, 33B, f7d3e46aa713acbe
duration/digital@1, es-CL, 33B, 47468baef9fec4e1
duration/digital@1, fi, 33B, -> da
duration/digital@1, ia, 33B, -> af
duration/digital@1, id, 33B, -> da
duration/digital@1, lt, 33B, -> af
duration/digital@1, mn, 33B, 3c33ef6863d54c8e
duration/digital@1, si, 33B, -> da
duration/digital@1, sl, 33B, -> da
duration/digital@1, sr, 33B, -> da
duration/digital@1, sr-Latn, 33B, -> da
duration/digital@1, su, 33B, -> da
duration/digital@1, tk, 33B, a6c1148d5562d04c
duration/digital@1, und, 33B, 1b23261b619ff3eb
percent/essentials@1, <lookup>, 267B, 59 identifiers
percent/essentials@1, <total>, 1035B, 9 unique payloads
percent/essentials@1, ar, 117B, 8ebf290af62091f
Expand Down

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

Loading

0 comments on commit e2a03b2

Please sign in to comment.