Skip to content

Commit

Permalink
Implement PackedPatternsV1 with packing and unpacking (#5580)
Browse files Browse the repository at this point in the history
Part of #257
  • Loading branch information
sffc authored Sep 25, 2024
1 parent b8a0b36 commit 1141c8e
Show file tree
Hide file tree
Showing 6 changed files with 537 additions and 2 deletions.
10 changes: 10 additions & 0 deletions components/datetime/src/pattern/runtime/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use super::super::{reference, PatternError, PatternItem, TimeGranularity};
use alloc::vec::Vec;
use core::str::FromStr;
use icu_plurals::provider::FourBitMetadata;
use icu_provider::prelude::*;
use zerovec::{ule::AsULE, ZeroSlice, ZeroVec};

Expand Down Expand Up @@ -75,6 +76,15 @@ impl PatternMetadata {
pub(crate) fn set_time_granularity(&mut self, time_granularity: TimeGranularity) {
self.0 = time_granularity.ordinal();
}

pub(crate) fn to_four_bit_metadata(self) -> FourBitMetadata {
#[allow(clippy::unwrap_used)] // valid values for self.0 are 0, 1, 2, 3, or 4
FourBitMetadata::try_from_byte(self.0).unwrap()
}

pub(crate) fn from_u8(other: u8) -> Self {
Self(TimeGranularity::from_ordinal(other).ordinal())
}
}

impl Default for PatternMetadata {
Expand Down
1 change: 1 addition & 0 deletions components/datetime/src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

pub mod calendar;
pub(crate) mod date_time;
pub mod packed_pattern;
pub mod time_zones;

/// Module for new DateSymbols design
Expand Down
Loading

0 comments on commit 1141c8e

Please sign in to comment.