diff --git a/components/datetime/benches/fixtures/mod.rs b/components/datetime/benches/fixtures/mod.rs index bb0a951c6e1..10368b840cf 100644 --- a/components/datetime/benches/fixtures/mod.rs +++ b/components/datetime/benches/fixtures/mod.rs @@ -2,9 +2,7 @@ // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). -use icu_datetime::{ - fieldsets::serde::CompositeFieldSetSerde, options, provider::fields::components, -}; +use icu_datetime::{fieldsets::serde::CompositeFieldSetSerde, provider::fields::components}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -61,7 +59,7 @@ pub struct TestComponentsBag { pub hour: Option, pub minute: Option, pub second: Option, - pub fractional_second: Option, + pub fractional_second: Option, pub time_zone_name: Option, } diff --git a/components/datetime/benches/fixtures/tests/components.json b/components/datetime/benches/fixtures/tests/components.json index 52e6bda3721..b5d1135985a 100644 --- a/components/datetime/benches/fixtures/tests/components.json +++ b/components/datetime/benches/fixtures/tests/components.json @@ -251,7 +251,7 @@ "semantic": { "fieldSet": ["weekday", "time"], "length": "medium", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h12" } @@ -268,7 +268,7 @@ "semantic": { "fieldSet": ["weekday", "time"], "length": "medium", - "timePrecision": "secondPlus" + "timePrecision": "second" }, "hourCycle": "h12" } @@ -284,7 +284,7 @@ "semantic": { "fieldSet": ["weekday", "time"], "length": "medium", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h23" } @@ -301,7 +301,7 @@ "semantic": { "fieldSet": ["weekday", "time"], "length": "medium", - "timePrecision": "secondPlus" + "timePrecision": "second" }, "hourCycle": "h23" } @@ -315,7 +315,7 @@ "semantic": { "fieldSet": ["time"], "length": "medium", - "timePrecision": "hourExact" + "timePrecision": "hour" }, "hourCycle": "h12" } @@ -330,7 +330,7 @@ "semantic": { "fieldSet": ["time"], "length": "medium", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h12" } @@ -346,7 +346,7 @@ "semantic": { "fieldSet": ["time"], "length": "medium", - "timePrecision": "secondPlus" + "timePrecision": "second" }, "hourCycle": "h12" } @@ -360,7 +360,7 @@ "semantic": { "fieldSet": ["time"], "length": "medium", - "timePrecision": "hourExact" + "timePrecision": "hour" }, "hourCycle": "h23" } @@ -375,7 +375,7 @@ "semantic": { "fieldSet": ["time"], "length": "medium", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h23" } @@ -391,7 +391,7 @@ "semantic": { "fieldSet": ["time"], "length": "medium", - "timePrecision": "secondPlus" + "timePrecision": "second" }, "hourCycle": "h23" } @@ -406,7 +406,7 @@ "semantic": { "fieldSet": ["time"], "length": "medium", - "timePrecision": "minuteExact" + "timePrecision": "minute" } } }, @@ -452,7 +452,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "weekday", "time"], "length": "medium", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h12" } @@ -472,7 +472,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "weekday", "time"], "length": "long", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h12" } @@ -487,7 +487,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h11" } @@ -502,7 +502,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h24" } @@ -517,7 +517,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h11" } @@ -532,7 +532,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h12" } @@ -547,7 +547,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h23" } @@ -562,7 +562,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h24" } diff --git a/components/datetime/benches/fixtures/tests/lengths.json b/components/datetime/benches/fixtures/tests/lengths.json index b5daeb37155..4c6c4f8eabe 100644 --- a/components/datetime/benches/fixtures/tests/lengths.json +++ b/components/datetime/benches/fixtures/tests/lengths.json @@ -63,7 +63,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "secondPlus" + "timePrecision": "second" } } }, @@ -77,7 +77,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" } } }, @@ -91,7 +91,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "weekday", "time"], "length": "long", - "timePrecision": "secondPlus" + "timePrecision": "second" } } }, @@ -105,7 +105,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "time"], "length": "long", - "timePrecision": "minuteExact" + "timePrecision": "minute" } } }, @@ -119,7 +119,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "time"], "length": "medium", - "timePrecision": "secondPlus" + "timePrecision": "second" } } }, @@ -133,7 +133,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" } } } diff --git a/components/datetime/benches/fixtures/tests/lengths_with_zones.json b/components/datetime/benches/fixtures/tests/lengths_with_zones.json index af2e9b71de1..54b58b83a2d 100644 --- a/components/datetime/benches/fixtures/tests/lengths_with_zones.json +++ b/components/datetime/benches/fixtures/tests/lengths_with_zones.json @@ -11,7 +11,7 @@ "semantic": { "fieldSet": ["time", "zoneSpecific"], "length": "long", - "timePrecision": "secondPlus" + "timePrecision": "second" } } }, @@ -25,7 +25,7 @@ "semantic": { "fieldSet": ["time", "zoneSpecific"], "length": "medium", - "timePrecision": "secondPlus" + "timePrecision": "second" } } }, @@ -39,7 +39,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "weekday", "time", "zoneSpecific"], "length": "long", - "timePrecision": "secondPlus" + "timePrecision": "second" } } }, @@ -53,7 +53,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "time", "zoneSpecific"], "length": "medium", - "timePrecision": "secondPlus" + "timePrecision": "second" } } } diff --git a/components/datetime/src/builder.rs b/components/datetime/src/builder.rs index ef4629bce65..589c74432b6 100644 --- a/components/datetime/src/builder.rs +++ b/components/datetime/src/builder.rs @@ -46,11 +46,11 @@ //! // Display time to the minute //! //! let static_field_set = fieldsets::ET::medium() -//! .with_time_precision(TimePrecision::MinuteExact); +//! .with_time_precision(TimePrecision::Minute); //! //! let mut builder = FieldSetBuilder::default(); //! builder.date_fields = Some(DateFields::E); -//! builder.time_precision = Some(TimePrecision::MinuteExact); +//! builder.time_precision = Some(TimePrecision::Minute); //! let dynamic_field_set = builder.build_date_and_time().unwrap(); //! //! assert_eq!( @@ -65,13 +65,13 @@ //! // Render for column alignment //! //! let static_field_set = fieldsets::T::short() -//! .with_time_precision(TimePrecision::SecondExact(FractionalSecondDigits::F3)) +//! .with_time_precision(TimePrecision::FractionalSecond(FractionalSecondDigits::F3)) //! .with_alignment(Alignment::Column) //! .with_zone_specific_long(); //! //! let mut builder = FieldSetBuilder::default(); //! builder.length = Some(Length::Short); -//! builder.time_precision = Some(TimePrecision::SecondExact(FractionalSecondDigits::F3)); +//! builder.time_precision = Some(TimePrecision::FractionalSecond(FractionalSecondDigits::F3)); //! builder.alignment = Some(Alignment::Column); //! builder.zone_style = Some(ZoneStyle::Z); //! let dynamic_field_set = builder.build_composite().unwrap(); diff --git a/components/datetime/src/fieldsets.rs b/components/datetime/src/fieldsets.rs index 70073fcf037..6e459cfbd93 100644 --- a/components/datetime/src/fieldsets.rs +++ b/components/datetime/src/fieldsets.rs @@ -39,12 +39,12 @@ //! let field_set_1 = YMDT::long() //! .with_year_style(YearStyle::Full) //! .with_alignment(Alignment::Column) -//! .with_time_precision(TimePrecision::MinuteExact); +//! .with_time_precision(TimePrecision::Minute); //! //! let mut field_set_2 = YMDT::long(); //! field_set_2.year_style = Some(YearStyle::Full); //! field_set_2.alignment = Some(Alignment::Column); -//! field_set_2.time_precision = Some(TimePrecision::MinuteExact); +//! field_set_2.time_precision = Some(TimePrecision::Minute); //! //! assert_eq!(field_set_1, field_set_2); //! ``` @@ -277,9 +277,9 @@ macro_rules! impl_marker_with_options { self.time_precision = Some(yes_to!(time_precision, $timeprecision_yes)); self } - /// Sets the time precision to [`TimePrecision::MinuteExact`] + /// Sets the time precision to [`TimePrecision::Minute`] pub fn hm(mut self) -> Self { - self.time_precision = Some(TimePrecision::MinuteExact); + self.time_precision = Some(TimePrecision::Minute); self } } diff --git a/components/datetime/src/neo_serde.rs b/components/datetime/src/neo_serde.rs index 70c1330c476..4efaccea3c8 100644 --- a/components/datetime/src/neo_serde.rs +++ b/components/datetime/src/neo_serde.rs @@ -238,12 +238,9 @@ impl TryFrom for CompositeFieldSet { #[derive(Copy, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub(crate) enum TimePrecisionSerde { - HourPlus, - HourExact, - MinutePlus, - MinuteExact, - SecondPlus, - SecondF0, + Hour, + Minute, + Second, SecondF1, SecondF2, SecondF3, @@ -253,26 +250,43 @@ pub(crate) enum TimePrecisionSerde { SecondF7, SecondF8, SecondF9, + MinuteOptional, } impl From for TimePrecisionSerde { fn from(value: TimePrecision) -> Self { match value { - TimePrecision::HourPlus => TimePrecisionSerde::HourPlus, - TimePrecision::HourExact => TimePrecisionSerde::HourExact, - TimePrecision::MinutePlus => TimePrecisionSerde::MinutePlus, - TimePrecision::MinuteExact => TimePrecisionSerde::MinuteExact, - TimePrecision::SecondPlus => TimePrecisionSerde::SecondPlus, - TimePrecision::SecondExact(FractionalSecondDigits::F0) => TimePrecisionSerde::SecondF0, - TimePrecision::SecondExact(FractionalSecondDigits::F1) => TimePrecisionSerde::SecondF1, - TimePrecision::SecondExact(FractionalSecondDigits::F2) => TimePrecisionSerde::SecondF2, - TimePrecision::SecondExact(FractionalSecondDigits::F3) => TimePrecisionSerde::SecondF3, - TimePrecision::SecondExact(FractionalSecondDigits::F4) => TimePrecisionSerde::SecondF4, - TimePrecision::SecondExact(FractionalSecondDigits::F5) => TimePrecisionSerde::SecondF5, - TimePrecision::SecondExact(FractionalSecondDigits::F6) => TimePrecisionSerde::SecondF6, - TimePrecision::SecondExact(FractionalSecondDigits::F7) => TimePrecisionSerde::SecondF7, - TimePrecision::SecondExact(FractionalSecondDigits::F8) => TimePrecisionSerde::SecondF8, - TimePrecision::SecondExact(FractionalSecondDigits::F9) => TimePrecisionSerde::SecondF9, + TimePrecision::Hour => TimePrecisionSerde::Hour, + TimePrecision::Minute => TimePrecisionSerde::Minute, + TimePrecision::Second => TimePrecisionSerde::Second, + TimePrecision::FractionalSecond(FractionalSecondDigits::F1) => { + TimePrecisionSerde::SecondF1 + } + TimePrecision::FractionalSecond(FractionalSecondDigits::F2) => { + TimePrecisionSerde::SecondF2 + } + TimePrecision::FractionalSecond(FractionalSecondDigits::F3) => { + TimePrecisionSerde::SecondF3 + } + TimePrecision::FractionalSecond(FractionalSecondDigits::F4) => { + TimePrecisionSerde::SecondF4 + } + TimePrecision::FractionalSecond(FractionalSecondDigits::F5) => { + TimePrecisionSerde::SecondF5 + } + TimePrecision::FractionalSecond(FractionalSecondDigits::F6) => { + TimePrecisionSerde::SecondF6 + } + TimePrecision::FractionalSecond(FractionalSecondDigits::F7) => { + TimePrecisionSerde::SecondF7 + } + TimePrecision::FractionalSecond(FractionalSecondDigits::F8) => { + TimePrecisionSerde::SecondF8 + } + TimePrecision::FractionalSecond(FractionalSecondDigits::F9) => { + TimePrecisionSerde::SecondF9 + } + TimePrecision::MinuteOptional => TimePrecisionSerde::MinuteOptional, } } } @@ -280,21 +294,37 @@ impl From for TimePrecisionSerde { impl From for TimePrecision { fn from(value: TimePrecisionSerde) -> Self { match value { - TimePrecisionSerde::HourPlus => TimePrecision::HourPlus, - TimePrecisionSerde::HourExact => TimePrecision::HourExact, - TimePrecisionSerde::MinutePlus => TimePrecision::MinutePlus, - TimePrecisionSerde::MinuteExact => TimePrecision::MinuteExact, - TimePrecisionSerde::SecondPlus => TimePrecision::SecondPlus, - TimePrecisionSerde::SecondF0 => TimePrecision::SecondExact(FractionalSecondDigits::F0), - TimePrecisionSerde::SecondF1 => TimePrecision::SecondExact(FractionalSecondDigits::F1), - TimePrecisionSerde::SecondF2 => TimePrecision::SecondExact(FractionalSecondDigits::F2), - TimePrecisionSerde::SecondF3 => TimePrecision::SecondExact(FractionalSecondDigits::F3), - TimePrecisionSerde::SecondF4 => TimePrecision::SecondExact(FractionalSecondDigits::F4), - TimePrecisionSerde::SecondF5 => TimePrecision::SecondExact(FractionalSecondDigits::F5), - TimePrecisionSerde::SecondF6 => TimePrecision::SecondExact(FractionalSecondDigits::F6), - TimePrecisionSerde::SecondF7 => TimePrecision::SecondExact(FractionalSecondDigits::F7), - TimePrecisionSerde::SecondF8 => TimePrecision::SecondExact(FractionalSecondDigits::F8), - TimePrecisionSerde::SecondF9 => TimePrecision::SecondExact(FractionalSecondDigits::F9), + TimePrecisionSerde::Hour => TimePrecision::Hour, + TimePrecisionSerde::Minute => TimePrecision::Minute, + TimePrecisionSerde::Second => TimePrecision::Second, + TimePrecisionSerde::SecondF1 => { + TimePrecision::FractionalSecond(FractionalSecondDigits::F1) + } + TimePrecisionSerde::SecondF2 => { + TimePrecision::FractionalSecond(FractionalSecondDigits::F2) + } + TimePrecisionSerde::SecondF3 => { + TimePrecision::FractionalSecond(FractionalSecondDigits::F3) + } + TimePrecisionSerde::SecondF4 => { + TimePrecision::FractionalSecond(FractionalSecondDigits::F4) + } + TimePrecisionSerde::SecondF5 => { + TimePrecision::FractionalSecond(FractionalSecondDigits::F5) + } + TimePrecisionSerde::SecondF6 => { + TimePrecision::FractionalSecond(FractionalSecondDigits::F6) + } + TimePrecisionSerde::SecondF7 => { + TimePrecision::FractionalSecond(FractionalSecondDigits::F7) + } + TimePrecisionSerde::SecondF8 => { + TimePrecision::FractionalSecond(FractionalSecondDigits::F8) + } + TimePrecisionSerde::SecondF9 => { + TimePrecision::FractionalSecond(FractionalSecondDigits::F9) + } + TimePrecisionSerde::MinuteOptional => TimePrecision::MinuteOptional, } } } @@ -596,7 +626,7 @@ fn test_basic() { length: Length::Medium, alignment: Some(Alignment::Column), year_style: Some(YearStyle::Always), - time_precision: Some(TimePrecision::SecondExact(FractionalSecondDigits::F3)), + time_precision: Some(TimePrecision::FractionalSecond(FractionalSecondDigits::F3)), }), ZoneFieldSet::Vs(fieldsets::Vs::new()), )); diff --git a/components/datetime/src/options/mod.rs b/components/datetime/src/options/mod.rs index b22d303de51..89e16979607 100644 --- a/components/datetime/src/options/mod.rs +++ b/components/datetime/src/options/mod.rs @@ -317,6 +317,10 @@ impl IntoOption for YearStyle { /// 2. 16:20 (4:20 pm) with 24-hour time /// 3. 7:15:01.85 with 24-hour time /// +/// Fractional second digits can be displayed with a fixed precision. If you would like +/// additional options for fractional second digit display, please leave a comment in +/// . +/// /// # Examples /// /// ``` @@ -329,12 +333,11 @@ impl IntoOption for YearStyle { /// use writeable::assert_writeable_eq; /// /// let formatters = [ -/// TimePrecision::HourPlus, -/// TimePrecision::HourExact, -/// TimePrecision::MinutePlus, -/// TimePrecision::MinuteExact, -/// TimePrecision::SecondPlus, -/// TimePrecision::SecondExact(FractionalSecondDigits::F0), +/// TimePrecision::Hour, +/// TimePrecision::Minute, +/// TimePrecision::Second, +/// TimePrecision::FractionalSecond(FractionalSecondDigits::F2), +/// TimePrecision::MinuteOptional, /// ] /// .map(|time_precision| { /// FixedCalendarDateTimeFormatter::<(), _>::try_new( @@ -347,18 +350,16 @@ impl IntoOption for YearStyle { /// let times = [ /// Time::try_new(7, 0, 0, 0).unwrap(), /// Time::try_new(7, 0, 10, 0).unwrap(), -/// Time::try_new(7, 12, 20, 5).unwrap(), +/// Time::try_new(7, 12, 20, 543_200_000).unwrap(), /// ]; /// -/// // TODO(#5782): the Plus variants should render fractional digits /// let expected_value_table = [ /// // 7:00:00, 7:00:10, 7:12:20.5432 -/// ["7 AM", "7:00:10 AM", "7:12:20 AM"], // HourPlus -/// ["7 AM", "7 AM", "7 AM"], // HourExact -/// ["7:00 AM", "7:00:10 AM", "7:12:20 AM"], // MinutePlus -/// ["7:00 AM", "7:00 AM", "7:12 AM"], // MinuteExact -/// ["7:00:00 AM", "7:00:10 AM", "7:12:20 AM"], // SecondPlus -/// ["7:00:00 AM", "7:00:10 AM", "7:12:20 AM"], // SecondExact +/// ["7 AM", "7 AM", "7 AM"], // Hour +/// ["7:00 AM", "7:00 AM", "7:12 AM"], // Minute +/// ["7:00:00 AM", "7:00:10 AM", "7:12:20 AM"], // Second +/// ["7:00:00.00 AM", "7:00:10.00 AM", "7:12:20.54 AM"], // FractionalSecond(F2) +/// ["7 AM", "7 AM", "7:12 AM"], // MinuteOptional /// ]; /// /// for (expected_value_row, formatter) in @@ -375,7 +376,7 @@ impl IntoOption for YearStyle { /// } /// } /// ``` -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default)] #[cfg_attr( all(feature = "serde", feature = "experimental"), derive(serde::Serialize, serde::Deserialize) @@ -386,48 +387,33 @@ impl IntoOption for YearStyle { )] #[non_exhaustive] pub enum TimePrecision { - /// Always display the hour. Display smaller fields if they are nonzero. - /// - /// Examples: - /// - /// 1. `11 am` - /// 2. `16:20` - /// 3. `07:15:01.85` - HourPlus, - /// Always display the hour. Hide all other time fields. + /// Display the hour. Hide all other time fields. /// /// Examples: /// /// 1. `11 am` /// 2. `16h` /// 3. `07h` - HourExact, - /// Always display the hour and minute. Display the second if nonzero. - /// - /// Examples: - /// - /// 1. `11:00 am` - /// 2. `16:20` - /// 3. `07:15:01.85` - MinutePlus, - /// Always display the hour and minute. Hide the second. + Hour, + /// Display the hour and minute. Hide the second. /// /// Examples: /// /// 1. `11:00 am` /// 2. `16:20` /// 3. `07:15` - MinuteExact, - /// Display the hour, minute, and second. Display fractional seconds if nonzero. + Minute, + /// Display the hour, minute, and second. Hide fractional seconds. /// - /// This is the default. + /// This is currently the default, but the default is subject to change. /// /// Examples: /// /// 1. `11:00:00 am` /// 2. `16:20:00` - /// 3. `07:15:01.85` - SecondPlus, + /// 3. `07:15:01` + #[default] + Second, /// Display the hour, minute, and second with the given number of /// fractional second digits. /// @@ -436,7 +422,15 @@ pub enum TimePrecision { /// 1. `11:00:00.0 am` /// 2. `16:20:00.0` /// 3. `07:15:01.8` - SecondExact(FractionalSecondDigits), + FractionalSecond(FractionalSecondDigits), + /// Display the hour; display the minute if nonzero. Hide the second. + /// + /// Examples: + /// + /// 1. `11 am` + /// 2. `16:20` + /// 3. `07:15` + MinuteOptional, } impl IntoOption for TimePrecision { @@ -469,7 +463,7 @@ impl IntoOption for TimePrecision { /// /// let formatter = FixedCalendarDateTimeFormatter::<(), _>::try_new( /// locale!("en-US").into(), -/// T::short().with_time_precision(TimePrecision::SecondExact( +/// T::short().with_time_precision(TimePrecision::FractionalSecond( /// FractionalSecondDigits::F2, /// )), /// ) @@ -481,36 +475,26 @@ impl IntoOption for TimePrecision { /// ); /// ``` #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -#[cfg_attr( - all(feature = "serde", feature = "experimental"), - derive(serde::Serialize, serde::Deserialize) -)] -#[cfg_attr( - all(feature = "serde", feature = "experimental"), - serde(try_from = "u8", into = "u8") -)] #[non_exhaustive] pub enum FractionalSecondDigits { - /// Zero fractional digits. This is the default. - F0, /// One fractional digit (tenths of a second). - F1, + F1 = 1, /// Two fractional digits (hundredths of a second). - F2, + F2 = 2, /// Three fractional digits (thousandths of a second). - F3, + F3 = 3, /// Four fractional digits. - F4, + F4 = 4, /// Five fractional digits. - F5, + F5 = 5, /// Six fractional digits. - F6, + F6 = 6, /// Seven fractional digits. - F7, + F7 = 7, /// Eight fractional digits. - F8, + F8 = 8, /// Nine fractional digits. - F9, + F9 = 9, } /// An error from constructing [`FractionalSecondDigits`]. @@ -527,7 +511,6 @@ impl From for u8 { fn from(value: FractionalSecondDigits) -> u8 { use FractionalSecondDigits::*; match value { - F0 => 0, F1 => 1, F2 => 2, F3 => 3, @@ -546,7 +529,6 @@ impl TryFrom for FractionalSecondDigits { fn try_from(value: u8) -> Result { use FractionalSecondDigits::*; match value { - 0 => Ok(F0), 1 => Ok(F1), 2 => Ok(F2), 3 => Ok(F3), diff --git a/components/datetime/src/parts.rs b/components/datetime/src/parts.rs index 3ff5fb55762..e55e4de1f9b 100644 --- a/components/datetime/src/parts.rs +++ b/components/datetime/src/parts.rs @@ -21,7 +21,7 @@ //! //! let dtf = DateTimeFormatter::try_new( //! locale!("en-u-ca-buddhist").into(), -//! fieldsets::YMDT::medium().with_time_precision(TimePrecision::SecondExact(FractionalSecondDigits::F2)).with_zone_specific(), +//! fieldsets::YMDT::medium().with_time_precision(TimePrecision::FractionalSecond(FractionalSecondDigits::F2)).with_zone_specific(), //! ) //! .unwrap(); //! diff --git a/components/datetime/src/provider/fields/symbols.rs b/components/datetime/src/provider/fields/symbols.rs index f5c72821077..32997369299 100644 --- a/components/datetime/src/provider/fields/symbols.rs +++ b/components/datetime/src/provider/fields/symbols.rs @@ -178,7 +178,6 @@ impl FieldSymbol { ) -> Self { use FractionalSecondDigits::*; match fractional_second_digits { - F0 => FieldSymbol::Second(Second::Second), F1 => FieldSymbol::DecimalSecond(DecimalSecond::SecondF1), F2 => FieldSymbol::DecimalSecond(DecimalSecond::SecondF2), F3 => FieldSymbol::DecimalSecond(DecimalSecond::SecondF3), diff --git a/components/datetime/src/provider/skeleton/helpers.rs b/components/datetime/src/provider/skeleton/helpers.rs index c8603178efb..89bfd2571ef 100644 --- a/components/datetime/src/provider/skeleton/helpers.rs +++ b/components/datetime/src/provider/skeleton/helpers.rs @@ -350,7 +350,6 @@ fn apply_fractional_seconds( pattern: &mut runtime::Pattern, fractional_seconds: Option, ) { - use FractionalSecondDigits::*; if let Some(fractional_seconds) = fractional_seconds { let mut items = pattern.items.to_vec(); for item in items.iter_mut() { @@ -368,11 +367,7 @@ fn apply_fractional_seconds( *pattern = runtime::Pattern::from(items); pattern .metadata - .set_time_granularity(if fractional_seconds == F0 { - TimeGranularity::Seconds - } else { - TimeGranularity::Nanoseconds - }); + .set_time_granularity(TimeGranularity::Nanoseconds); } } diff --git a/components/datetime/src/raw/neo.rs b/components/datetime/src/raw/neo.rs index ff51e680a46..a2c46c4121e 100644 --- a/components/datetime/src/raw/neo.rs +++ b/components/datetime/src/raw/neo.rs @@ -256,27 +256,19 @@ impl ExtractedInput { &self, time_precision: TimePrecision, ) -> (PackedSkeletonVariant, Option) { - enum HourMinute { - Hour, - Minute, - } - let smallest_required_field = match time_precision { - TimePrecision::HourExact => return (PackedSkeletonVariant::Standard, None), - TimePrecision::MinuteExact => return (PackedSkeletonVariant::Variant0, None), - TimePrecision::SecondExact(f) => return (PackedSkeletonVariant::Variant1, Some(f)), - TimePrecision::HourPlus => HourMinute::Hour, - TimePrecision::MinutePlus => HourMinute::Minute, - TimePrecision::SecondPlus => return (PackedSkeletonVariant::Variant1, None), - }; - let minute = self.minute.unwrap_or_default(); - let second = self.second.unwrap_or_default(); - let nanosecond = self.nanosecond.unwrap_or_default(); - if !nanosecond.is_zero() || !second.is_zero() { - (PackedSkeletonVariant::Variant1, None) - } else if !minute.is_zero() || matches!(smallest_required_field, HourMinute::Minute) { - (PackedSkeletonVariant::Variant0, None) - } else { - (PackedSkeletonVariant::Standard, None) + match time_precision { + TimePrecision::Hour => (PackedSkeletonVariant::Standard, None), + TimePrecision::Minute => (PackedSkeletonVariant::Variant0, None), + TimePrecision::Second => (PackedSkeletonVariant::Variant1, None), + TimePrecision::FractionalSecond(f) => (PackedSkeletonVariant::Variant1, Some(f)), + TimePrecision::MinuteOptional => { + let minute = self.minute.unwrap_or_default(); + if minute.is_zero() { + (PackedSkeletonVariant::Standard, None) + } else { + (PackedSkeletonVariant::Variant0, None) + } + } } } } @@ -347,7 +339,7 @@ impl OverlapPatternSelectionData { // year and a time because that would involve 3*3 = 9 variants // instead of 3 variants. debug_assert!(options.year_style.is_none()); - let time_precision = options.time_precision.unwrap_or(TimePrecision::SecondPlus); + let time_precision = options.time_precision.unwrap_or_default(); let (variant, fractional_second_digits) = input.resolve_time_precision(time_precision); TimePatternDataBorrowed::Resolved( @@ -432,7 +424,7 @@ impl TimePatternSelectionData { prefs, payload, } => { - let time_precision = options.time_precision.unwrap_or(TimePrecision::SecondPlus); + let time_precision = options.time_precision.unwrap_or_default(); let (variant, fractional_second_digits) = input.resolve_time_precision(time_precision); TimePatternDataBorrowed::Resolved( diff --git a/components/datetime/tests/fixtures/mod.rs b/components/datetime/tests/fixtures/mod.rs index 5596004d55f..c6366f84bf9 100644 --- a/components/datetime/tests/fixtures/mod.rs +++ b/components/datetime/tests/fixtures/mod.rs @@ -4,8 +4,8 @@ #![cfg(feature = "serde")] +use icu_datetime::fieldsets::serde::CompositeFieldSetSerde; use icu_datetime::provider::fields::components; -use icu_datetime::{fieldsets::serde::CompositeFieldSetSerde, options}; use icu_locale_core::preferences::extensions::unicode::keywords::HourCycle; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -65,7 +65,7 @@ pub struct TestComponentsBag { pub hour: Option, pub minute: Option, pub second: Option, - pub fractional_second: Option, + pub fractional_second: Option, pub time_zone_name: Option, } diff --git a/components/datetime/tests/fixtures/tests/components-combine-datetime.json b/components/datetime/tests/fixtures/tests/components-combine-datetime.json index 37c2035fb98..99e069503ab 100644 --- a/components/datetime/tests/fixtures/tests/components-combine-datetime.json +++ b/components/datetime/tests/fixtures/tests/components-combine-datetime.json @@ -16,7 +16,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "weekday", "time"], "length": "medium", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h12" } @@ -47,7 +47,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "weekday", "time"], "length": "long", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h12" } diff --git a/components/datetime/tests/fixtures/tests/components-exact-matches.json b/components/datetime/tests/fixtures/tests/components-exact-matches.json index a5ea69c2bf7..bcbdd7a7b0a 100644 --- a/components/datetime/tests/fixtures/tests/components-exact-matches.json +++ b/components/datetime/tests/fixtures/tests/components-exact-matches.json @@ -397,7 +397,7 @@ "semantic": { "fieldSet": ["weekday", "time"], "length": "medium", - "timePrecision": "minuteExact" + "timePrecision": "minute" } } }, @@ -421,7 +421,7 @@ "semantic": { "fieldSet": ["weekday", "time"], "length": "medium", - "timePrecision": "secondPlus" + "timePrecision": "second" } } }, @@ -444,7 +444,7 @@ "semantic": { "fieldSet": ["weekday", "time"], "length": "medium", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h23" } @@ -469,7 +469,7 @@ "semantic": { "fieldSet": ["weekday", "time"], "length": "medium", - "timePrecision": "secondPlus" + "timePrecision": "second" }, "hourCycle": "h23" } @@ -491,7 +491,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "hourExact" + "timePrecision": "hour" }, "hourCycle": "h12" } @@ -514,7 +514,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h12" } @@ -538,7 +538,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "secondPlus" + "timePrecision": "second" }, "hourCycle": "h12" } @@ -560,7 +560,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "hourExact" + "timePrecision": "hour" }, "hourCycle": "h23" } @@ -583,7 +583,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h23" } @@ -607,7 +607,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "secondPlus" + "timePrecision": "second" }, "hourCycle": "h23" } diff --git a/components/datetime/tests/fixtures/tests/components.json b/components/datetime/tests/fixtures/tests/components.json index f27c2c48ac4..2e3e5ed0786 100644 --- a/components/datetime/tests/fixtures/tests/components.json +++ b/components/datetime/tests/fixtures/tests/components.json @@ -16,7 +16,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "weekday", "time"], "length": "long", - "timePrecision": "secondPlus", + "timePrecision": "second", "yearStyle": "always" }, "hourCycle": "h23" @@ -74,7 +74,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "weekday", "time"], "length": "long", - "timePrecision": "secondPlus", + "timePrecision": "second", "yearStyle": "always" }, "hourCycle": "h23" @@ -104,7 +104,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "weekday", "time"], "length": "long", - "timePrecision": "secondPlus", + "timePrecision": "second", "yearStyle": "always" }, "hourCycle": "h23" @@ -130,7 +130,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "secondPlus" + "timePrecision": "second" }, "hourCycle": "h23" } diff --git a/components/datetime/tests/fixtures/tests/components_hour_cycle.json b/components/datetime/tests/fixtures/tests/components_hour_cycle.json index b70e6b9f6ac..0ca69ffe0db 100644 --- a/components/datetime/tests/fixtures/tests/components_hour_cycle.json +++ b/components/datetime/tests/fixtures/tests/components_hour_cycle.json @@ -11,7 +11,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h11" } @@ -37,7 +37,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h12" } @@ -63,7 +63,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h23" } @@ -89,7 +89,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h24" } @@ -116,7 +116,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h11" } @@ -139,7 +139,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h12" } @@ -162,7 +162,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h23" } @@ -185,7 +185,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "minuteExact" + "timePrecision": "minute" }, "hourCycle": "h24" } @@ -207,7 +207,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "hourExact" + "timePrecision": "hour" }, "hourCycle": "h11" } @@ -229,7 +229,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "hourExact" + "timePrecision": "hour" }, "hourCycle": "h12" } @@ -251,7 +251,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "hourExact" + "timePrecision": "hour" }, "hourCycle": "h23" } @@ -273,7 +273,7 @@ "semantic": { "fieldSet": ["time"], "length": "short", - "timePrecision": "hourExact" + "timePrecision": "hour" }, "hourCycle": "h24" } diff --git a/components/datetime/tests/fixtures/tests/components_with_zones.json b/components/datetime/tests/fixtures/tests/components_with_zones.json index d31538d7ed9..eca2c713bb2 100644 --- a/components/datetime/tests/fixtures/tests/components_with_zones.json +++ b/components/datetime/tests/fixtures/tests/components_with_zones.json @@ -17,7 +17,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "weekday", "time", "zoneGeneric"], "length": "long", - "timePrecision": "secondPlus" + "timePrecision": "second" }, "hourCycle": "h23" } @@ -46,7 +46,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "weekday", "time", "zoneGeneric"], "length": "long", - "timePrecision": "secondPlus" + "timePrecision": "second" }, "hourCycle": "h23" } @@ -75,7 +75,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "weekday", "time", "zoneSpecific"], "length": "long", - "timePrecision": "secondPlus" + "timePrecision": "second" }, "hourCycle": "h23" } @@ -104,7 +104,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "weekday", "time", "zoneSpecific"], "length": "long", - "timePrecision": "secondPlus" + "timePrecision": "second" }, "hourCycle": "h23" } @@ -133,7 +133,7 @@ "semantic": { "fieldSet": ["year", "month", "day", "weekday", "time", "zoneOffset"], "length": "long", - "timePrecision": "secondPlus" + "timePrecision": "second" }, "hourCycle": "h23" } diff --git a/components/datetime/tests/resolved_components.rs b/components/datetime/tests/resolved_components.rs index 62194ef8c89..9e73be59bcd 100644 --- a/components/datetime/tests/resolved_components.rs +++ b/components/datetime/tests/resolved_components.rs @@ -82,7 +82,7 @@ fn test_date_and_time() { fieldsets::YMDET::medium() .with_year_style(YearStyle::Always) .with_alignment(Alignment::Column) - .with_time_precision(TimePrecision::SecondExact(FractionalSecondDigits::F4)), + .with_time_precision(TimePrecision::FractionalSecond(FractionalSecondDigits::F4)), )); let mut input_bag = components::Bag::default();