Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TimePrecision WIP
Browse files Browse the repository at this point in the history
sffc committed Jan 11, 2025
1 parent 3878cf1 commit 610316a
Showing 17 changed files with 171 additions and 174 deletions.
38 changes: 19 additions & 19 deletions components/datetime/benches/fixtures/tests/components.json
Original file line number Diff line number Diff line change
@@ -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": "auto"
},
"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": "auto"
},
"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": "auto"
},
"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": "auto"
},
"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"
}
12 changes: 6 additions & 6 deletions components/datetime/benches/fixtures/tests/lengths.json
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@
"semantic": {
"fieldSet": ["time"],
"length": "short",
"timePrecision": "secondPlus"
"timePrecision": "auto"
}
}
},
@@ -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": "auto"
}
}
},
@@ -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": "auto"
}
}
},
@@ -133,7 +133,7 @@
"semantic": {
"fieldSet": ["year", "month", "day", "time"],
"length": "short",
"timePrecision": "minuteExact"
"timePrecision": "minute"
}
}
}
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
"semantic": {
"fieldSet": ["time", "zoneSpecific"],
"length": "long",
"timePrecision": "secondPlus"
"timePrecision": "auto"
}
}
},
@@ -25,7 +25,7 @@
"semantic": {
"fieldSet": ["time", "zoneSpecific"],
"length": "medium",
"timePrecision": "secondPlus"
"timePrecision": "auto"
}
}
},
@@ -39,7 +39,7 @@
"semantic": {
"fieldSet": ["year", "month", "day", "weekday", "time", "zoneSpecific"],
"length": "long",
"timePrecision": "secondPlus"
"timePrecision": "auto"
}
}
},
@@ -53,7 +53,7 @@
"semantic": {
"fieldSet": ["year", "month", "day", "time", "zoneSpecific"],
"length": "medium",
"timePrecision": "secondPlus"
"timePrecision": "auto"
}
}
}
8 changes: 4 additions & 4 deletions components/datetime/src/builder.rs
Original file line number Diff line number Diff line change
@@ -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::Second(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::Second(FractionalSecondDigits::F3));
//! builder.alignment = Some(Alignment::Column);
//! builder.zone_style = Some(ZoneStyle::Z);
//! let dynamic_field_set = builder.build_composite().unwrap();
8 changes: 4 additions & 4 deletions components/datetime/src/fieldsets.rs
Original file line number Diff line number Diff line change
@@ -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);
//! ```
@@ -276,9 +276,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
}
}
74 changes: 37 additions & 37 deletions components/datetime/src/neo_serde.rs
Original file line number Diff line number Diff line change
@@ -236,12 +236,9 @@ impl TryFrom<CompositeFieldSetSerde> 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,
@@ -251,48 +248,51 @@ pub(crate) enum TimePrecisionSerde {
SecondF7,
SecondF8,
SecondF9,
MinuteOptional,
SecondOptional,
MinuteSecondOptional,
}

impl From<TimePrecision> 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,
TimePrecision::SecondOptional => TimePrecisionSerde::SecondOptional,
TimePrecision::MinuteSecondOptional => TimePrecisionSerde::MinuteSecondOptional,
}
}
}

impl From<TimePrecisionSerde> 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,
TimePrecisionSerde::SecondOptional => TimePrecision::SecondOptional,
TimePrecisionSerde::MinuteSecondOptional => TimePrecision::MinuteSecondOptional,
}
}
}
@@ -594,7 +594,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::Second(FractionalSecondDigits::F3)),
}),
ZoneFieldSet::Vs(fieldsets::Vs::new()),
));
94 changes: 50 additions & 44 deletions components/datetime/src/options/mod.rs
Original file line number Diff line number Diff line change
@@ -329,12 +329,13 @@ impl IntoOption<YearStyle> for YearStyle {
/// use writeable::assert_writeable_eq;
///
/// let formatters = [
/// TimePrecision::HourPlus,
/// TimePrecision::HourExact,
/// TimePrecision::MinutePlus,
/// TimePrecision::MinuteExact,
/// TimePrecision::SecondPlus,
/// TimePrecision::SecondExact(FractionalSecondDigits::F0),
/// TimePrecision::Auto,
/// TimePrecision::Hour,
/// TimePrecision::Minute,
/// TimePrecision::Second(FractionalSecondDigits::F0),
/// TimePrecision::Second(FractionalSecondDigits::F2),
/// TimePrecision::MinuteOptional,
/// TimePrecision::SecondOptional,
/// ]
/// .map(|time_precision| {
/// FixedCalendarDateTimeFormatter::<(), _>::try_new(
@@ -353,12 +354,12 @@ impl IntoOption<YearStyle> for YearStyle {
/// // 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"], // SecondF2
/// ["7 AM", "7 AM", "7:12 AM"], // MinuteOptional
/// ["7:00 AM", "7:00:10 AM", "7:12:20.5432 AM"], // SecondOptional
/// ];
///
/// for (expected_value_row, formatter) in
@@ -375,7 +376,7 @@ impl IntoOption<YearStyle> 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,30 @@ impl IntoOption<YearStyle> 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.
///
/// This is the default.
Minute,
/// Display the hour, minute, and second. Hide fractional seconds.
///
/// Examples:
///
/// 1. `11:00:00 am`
/// 2. `16:20:00`
/// 3. `07:15:01.85`
SecondPlus,
/// 3. `07:15:01`
Second,
/// Display the hour, minute, and second with the given number of
/// fractional second digits.
///
@@ -436,7 +419,34 @@ 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,
/// Display the hour and minute; display the second and fractional second if nonzero.
///
/// This is currently the default.
///
/// Examples:
///
/// 1. `11:00 am`
/// 2. `16:20`
/// 3. `07:15:01.85`
#[default]
SecondOptional,
/// Display the hour; display the minute, second, and fractional second if nonzero.
///
/// Examples:
///
/// 1. `11 am`
/// 2. `16:20`
/// 3. `07:15:01.85`
MinuteSecondOptional,
}

impl IntoOption<TimePrecision> for TimePrecision {
@@ -469,7 +479,7 @@ impl IntoOption<TimePrecision> for TimePrecision {
///
/// let formatter = FixedCalendarDateTimeFormatter::<(), _>::try_new(
/// locale!("en-US").into(),
/// T::short().with_time_precision(TimePrecision::SecondExact(
/// T::short().with_time_precision(TimePrecision::Second(
/// FractionalSecondDigits::F2,
/// )),
/// )
@@ -491,8 +501,6 @@ impl IntoOption<TimePrecision> for TimePrecision {
)]
#[non_exhaustive]
pub enum FractionalSecondDigits {
/// Zero fractional digits. This is the default.
F0,
/// One fractional digit (tenths of a second).
F1,
/// Two fractional digits (hundredths of a second).
@@ -525,7 +533,6 @@ impl From<FractionalSecondDigits> for u8 {
fn from(value: FractionalSecondDigits) -> u8 {
use FractionalSecondDigits::*;
match value {
F0 => 0,
F1 => 1,
F2 => 2,
F3 => 3,
@@ -544,7 +551,6 @@ impl TryFrom<u8> for FractionalSecondDigits {
fn try_from(value: u8) -> Result<Self, Self::Error> {
use FractionalSecondDigits::*;
match value {
0 => Ok(F0),
1 => Ok(F1),
2 => Ok(F2),
3 => Ok(F3),
2 changes: 1 addition & 1 deletion components/datetime/src/parts.rs
Original file line number Diff line number Diff line change
@@ -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::Second(FractionalSecondDigits::F2)).with_zone_specific(),
//! )
//! .unwrap();
//!
1 change: 0 additions & 1 deletion components/datetime/src/provider/fields/symbols.rs
Original file line number Diff line number Diff line change
@@ -179,7 +179,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),
7 changes: 1 addition & 6 deletions components/datetime/src/provider/skeleton/helpers.rs
Original file line number Diff line number Diff line change
@@ -350,7 +350,6 @@ fn apply_fractional_seconds(
pattern: &mut runtime::Pattern,
fractional_seconds: Option<FractionalSecondDigits>,
) {
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);
}
}

25 changes: 11 additions & 14 deletions components/datetime/src/raw/neo.rs
Original file line number Diff line number Diff line change
@@ -254,24 +254,21 @@ impl ExtractedInput {
&self,
time_precision: TimePrecision,
) -> (PackedSkeletonVariant, Option<FractionalSecondDigits>) {
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 minutes_required = match time_precision {
TimePrecision::Hour => return (PackedSkeletonVariant::Standard, None),
TimePrecision::Minute => return (PackedSkeletonVariant::Variant0, None),
TimePrecision::Second => return (PackedSkeletonVariant::Variant1, None),
TimePrecision::FractionalSecond(f) => return (PackedSkeletonVariant::Variant1, Some(f)),
TimePrecision::MinuteOptional => false,
TimePrecision::SecondOptional => true,
TimePrecision::MinuteSecondOptional => false,
};
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) {
} else if !minute.is_zero() || minutes_required {
(PackedSkeletonVariant::Variant0, None)
} else {
(PackedSkeletonVariant::Standard, None)
@@ -343,7 +340,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(
@@ -426,7 +423,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(
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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": "auto"
}
}
},
@@ -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": "auto"
},
"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": "auto"
},
"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": "auto"
},
"hourCycle": "h23"
}
8 changes: 4 additions & 4 deletions components/datetime/tests/fixtures/tests/components.json
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
"semantic": {
"fieldSet": ["year", "month", "day", "weekday", "time"],
"length": "long",
"timePrecision": "secondPlus",
"timePrecision": "auto",
"yearStyle": "always"
},
"hourCycle": "h23"
@@ -74,7 +74,7 @@
"semantic": {
"fieldSet": ["year", "month", "day", "weekday", "time"],
"length": "long",
"timePrecision": "secondPlus",
"timePrecision": "auto",
"yearStyle": "always"
},
"hourCycle": "h23"
@@ -104,7 +104,7 @@
"semantic": {
"fieldSet": ["year", "month", "day", "weekday", "time"],
"length": "long",
"timePrecision": "secondPlus",
"timePrecision": "auto",
"yearStyle": "always"
},
"hourCycle": "h23"
@@ -130,7 +130,7 @@
"semantic": {
"fieldSet": ["time"],
"length": "short",
"timePrecision": "secondPlus"
"timePrecision": "auto"
},
"hourCycle": "h23"
}
24 changes: 12 additions & 12 deletions components/datetime/tests/fixtures/tests/components_hour_cycle.json
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
"semantic": {
"fieldSet": ["year", "month", "day", "weekday", "time", "zoneGeneric"],
"length": "long",
"timePrecision": "secondPlus"
"timePrecision": "auto"
},
"hourCycle": "h23"
}
@@ -46,7 +46,7 @@
"semantic": {
"fieldSet": ["year", "month", "day", "weekday", "time", "zoneGeneric"],
"length": "long",
"timePrecision": "secondPlus"
"timePrecision": "auto"
},
"hourCycle": "h23"
}
@@ -75,7 +75,7 @@
"semantic": {
"fieldSet": ["year", "month", "day", "weekday", "time", "zoneSpecific"],
"length": "long",
"timePrecision": "secondPlus"
"timePrecision": "auto"
},
"hourCycle": "h23"
}
@@ -104,7 +104,7 @@
"semantic": {
"fieldSet": ["year", "month", "day", "weekday", "time", "zoneSpecific"],
"length": "long",
"timePrecision": "secondPlus"
"timePrecision": "auto"
},
"hourCycle": "h23"
}
@@ -133,7 +133,7 @@
"semantic": {
"fieldSet": ["year", "month", "day", "weekday", "time", "zoneOffset"],
"length": "long",
"timePrecision": "secondPlus"
"timePrecision": "auto"
},
"hourCycle": "h23"
}
2 changes: 1 addition & 1 deletion components/datetime/tests/resolved_components.rs
Original file line number Diff line number Diff line change
@@ -81,7 +81,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::Second(FractionalSecondDigits::F4)),
));

let mut input_bag = components::Bag::default();

0 comments on commit 610316a

Please sign in to comment.