Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion core/engine/src/builtins/intl/date_time_format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use crate::{
},
intl::{
Service,
date_time_format::options::{DateStyle, FormatMatcher, FormatOptions, TimeStyle},
date_time_format::options::{
DateStyle, FormatMatcher, FormatOptions, SubsecondDigits, TimeStyle,
},
locale::{canonicalize_locale_list, filter_locales, resolve_locale},
options::{IntlOptions, coerce_options_to_object},
},
Expand Down Expand Up @@ -87,6 +89,7 @@ pub(crate) struct DateTimeFormat {
hour_cycle: Option<IcuHourCycle>,
date_style: Option<DateStyle>,
time_style: Option<TimeStyle>,
fractional_second_digits: Option<SubsecondDigits>,
time_zone: FormatTimeZone,
fieldset: CompositeFieldSet,
formatter: DateTimeFormatter<CompositeFieldSet>,
Expand Down Expand Up @@ -415,6 +418,18 @@ impl DateTimeFormat {
options.property(js_string!("hour12"), hour12, Attribute::all());
}

// Per Table 15, fractionalSecondDigits is only reported when neither
// dateStyle nor timeStyle is set; the constructor already guarantees this by
// rejecting explicit component options alongside a style, so the value is
// `None` whenever a style is present.
if let Some(fsd) = dtf.fractional_second_digits {
options.property(
js_string!("fractionalSecondDigits"),
fsd.digits(),
Attribute::all(),
);
}

if let Some(ds) = dtf.date_style {
let ds_str = match ds {
DateStyle::Full => "full",
Expand Down Expand Up @@ -816,6 +831,7 @@ pub(crate) fn create_date_time_format(
hour_cycle: intl_options.preferences.hour_cycle,
date_style,
time_style,
fractional_second_digits: format_options.fractional_second_digits(),
time_zone,
fieldset,
formatter,
Expand Down
12 changes: 12 additions & 0 deletions core/engine/src/builtins/intl/date_time_format/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ impl FormatOptions {
})
}

pub(super) fn fractional_second_digits(&self) -> Option<SubsecondDigits> {
self.fractional_second_digits
}

pub(super) fn set_date_defaults(&mut self) {
self.year = Some(Year::Numeric);
self.month = Some(Month::Numeric);
Expand Down Expand Up @@ -536,6 +540,14 @@ impl SubsecondDigits {
_ => unreachable!("subSecondDigits must be previously constrained."),
}
}

pub(super) fn digits(self) -> u8 {
match self {
SubsecondDigits::S1 => 1,
SubsecondDigits::S2 => 2,
SubsecondDigits::S3 => 3,
}
}
}

impl From<SubsecondDigits> for IcuSubsecondDigits {
Expand Down