diff --git a/components/datetime/benches/datetime.rs b/components/datetime/benches/datetime.rs index 72499bdc5ca..c8218e3e57c 100644 --- a/components/datetime/benches/datetime.rs +++ b/components/datetime/benches/datetime.rs @@ -7,21 +7,10 @@ mod fixtures; use criterion::{criterion_group, criterion_main, Criterion}; #[cfg(feature = "experimental")] use icu_datetime::neo::TypedNeoFormatter; -#[cfg(feature = "experimental")] -use icu_datetime::neo_skeleton::{NeoDateSkeleton, NeoSkeletonLength, NeoTimeComponents}; -#[cfg(feature = "experimental")] -use icu_datetime::neo_skeleton::{NeoDateTimeComponents, NeoDateTimeSkeleton}; -#[cfg(feature = "experimental")] -use icu_datetime::options::length; -use std::fmt::Write; use icu_calendar::{DateTime, Gregorian}; -#[cfg(feature = "experimental")] -use icu_datetime::DateTimeFormatterOptions; -use icu_datetime::TypedDateTimeFormatter; -use icu_datetime::{time_zone::TimeZoneFormatterOptions, TypedZonedDateTimeFormatter}; use icu_locale_core::Locale; -use icu_timezone::CustomZonedDateTime; +use icu_timezone::{CustomTimeZone, CustomZonedDateTime}; #[cfg(feature = "experimental")] use writeable::TryWriteable; @@ -31,106 +20,38 @@ mod mock; fn datetime_benches(c: &mut Criterion) { let mut group = c.benchmark_group("datetime"); - let mut bench_datetime_with_fixture = |name, file| { - let fxs = serde_json::from_str::(file).unwrap(); - group.bench_function(&format!("datetime_{name}"), |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_gregorian_from_str(value)) - .collect(); - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().expect("Failed to parse locale."); - let options = fixtures::get_options(&setup.options).unwrap(); - #[cfg(feature = "experimental")] - let dtf = { - TypedDateTimeFormatter::::try_new_experimental( - &locale.into(), - options, - ) - .expect("Failed to create TypedDateTimeFormatter.") - }; - #[cfg(not(feature = "experimental"))] - let dtf = { - TypedDateTimeFormatter::::try_new(&locale.into(), options) - .expect("Failed to create TypedDateTimeFormatter.") - }; - - let mut result = String::new(); - - for dt in &datetimes { - let fdt = dtf.format(dt); - write!(result, "{fdt}").expect("Failed to write to date time format."); - result.clear(); - } - } - } - }) - }); - }; - - bench_datetime_with_fixture("lengths", include_str!("fixtures/tests/lengths.json")); - - #[cfg(feature = "experimental")] - bench_datetime_with_fixture("components", include_str!("fixtures/tests/components.json")); - #[cfg(feature = "experimental")] - let mut bench_neoneo_datetime_with_fixture = |name, file| { + let mut bench_neoneo_datetime_with_fixture = |name, file, has_zones| { let fxs = serde_json::from_str::(file).unwrap(); - group.bench_function(&format!("neoneo/datetime_{name}"), |b| { + group.bench_function(&format!("semantic/{name}"), |b| { b.iter(|| { for fx in &fxs.0 { - let datetimes: Vec> = fx + let datetimes: Vec> = fx .values .iter() - .map(|value| mock::parse_gregorian_from_str(value)) + .map(move |value| { + if has_zones { + mock::parse_zoned_gregorian_from_str(value) + } else { + let DateTime { date, time } = mock::parse_gregorian_from_str(value); + CustomZonedDateTime { + date, + time, + // zone is unused but we need to make the types match + zone: CustomTimeZone::utc(), + } + } + }) .collect(); for setup in &fx.setups { let locale: Locale = setup.locale.parse().expect("Failed to parse locale."); - let options = fixtures::get_options(&setup.options).unwrap(); - - let (neo_components, length) = match options { - DateTimeFormatterOptions::Length(length::Bag { - date: Some(date), - time: Some(time), - .. - }) => { - let neo_skeleton = - NeoDateTimeSkeleton::from_date_time_length(date, time); - (neo_skeleton.components, neo_skeleton.length) - } - DateTimeFormatterOptions::Length(length::Bag { - date: Some(date), - time: None, - .. - }) => { - let neo_skeleton = NeoDateSkeleton::from_date_length(date); - ( - NeoDateTimeComponents::Date(neo_skeleton.components), - NeoSkeletonLength::Short, - ) - } - DateTimeFormatterOptions::Length(length::Bag { - date: None, - time: Some(time), - .. - }) => { - let neo_time_components = NeoTimeComponents::from_time_length(time); - ( - NeoDateTimeComponents::Time(neo_time_components), - NeoSkeletonLength::Short, - ) - } - _ => todo!(), // Err(LoadError::UnsupportedOptions), - }; + let skeleton = setup.options.semantic.unwrap(); let dtf = { TypedNeoFormatter::::try_new_with_components( &locale.into(), - neo_components, - length.into(), + skeleton.components, + skeleton.length.into(), ) .expect("Failed to create TypedNeoFormatter.") }; @@ -151,356 +72,27 @@ fn datetime_benches(c: &mut Criterion) { }; #[cfg(feature = "experimental")] - bench_neoneo_datetime_with_fixture("lengths", include_str!("fixtures/tests/lengths.json")); - - let fxs = serde_json::from_str::(include_str!( - "fixtures/tests/lengths_with_zones.json" - )) - .unwrap(); - group.bench_function("zoned_datetime_overview", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_zoned_gregorian_from_str(value)) - .collect(); - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = TypedZonedDateTimeFormatter::::try_new( - &locale.into(), - options, - TimeZoneFormatterOptions::default(), - ) - .unwrap(); + bench_neoneo_datetime_with_fixture( + "lengths", + include_str!("fixtures/tests/lengths.json"), + false, + ); - let mut result = String::new(); + #[cfg(feature = "experimental")] + bench_neoneo_datetime_with_fixture( + "components", + include_str!("fixtures/tests/components.json"), + false, + ); - for zdt in &datetimes { - let dt = DateTime { - date: zdt.date, - time: zdt.time, - }; - let fdt = dtf.format(&dt, &zdt.zone); - write!(result, "{fdt}").unwrap(); - result.clear(); - } - } - } - }) - }); + #[cfg(feature = "experimental")] + bench_neoneo_datetime_with_fixture( + "lengths_with_zones", + include_str!("fixtures/tests/lengths_with_zones.json"), + true, + ); group.finish(); - - #[cfg(feature = "bench")] - { - use writeable::Writeable; - - let mut group = c.benchmark_group("datetime"); - - let fxs = - serde_json::from_str::(include_str!("fixtures/tests/lengths.json")) - .unwrap(); - group.bench_function("TypedDateTimeFormatter/format_to_write", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = - TypedDateTimeFormatter::::try_new(&locale.into(), options) - .unwrap(); - - let mut scratch = String::new(); - - for dt in &datetimes { - let _ = dtf.format(dt).write_to(&mut scratch); - scratch.clear(); - } - } - } - }) - }); - - group.bench_function("TypedDateTimeFormatter/format_to_string", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = - TypedDateTimeFormatter::::try_new(&locale.into(), options) - .unwrap(); - - for dt in &datetimes { - let _ = dtf.format_to_string(dt); - } - } - } - }) - }); - - group.bench_function("FormattedDateTime/format", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = - TypedDateTimeFormatter::::try_new(&locale.into(), options) - .unwrap(); - - let mut result = String::new(); - - for dt in &datetimes { - let fdt = dtf.format(dt); - write!(result, "{fdt}").unwrap(); - result.clear(); - } - } - } - }) - }); - - group.bench_function("FormattedDateTime/to_string", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = - TypedDateTimeFormatter::::try_new(&locale.into(), options) - .unwrap(); - - for dt in &datetimes { - let fdt = dtf.format(dt); - let _ = fdt.to_string(); - } - } - } - }) - }); - - group.bench_function("FormattedDateTime/write_to_string", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = - TypedDateTimeFormatter::::try_new(&locale.into(), options) - .unwrap(); - - for dt in &datetimes { - let fdt = dtf.format(dt); - let _ = fdt.write_to_string(); - } - } - } - }) - }); - - let fxs = serde_json::from_str::(include_str!( - "fixtures/tests/lengths_with_zones.json" - )) - .unwrap(); - group.bench_function("TypedZonedDateTimeFormatter/format_to_write", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_zoned_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = TypedZonedDateTimeFormatter::::try_new( - &locale.into(), - options, - TimeZoneFormatterOptions::default(), - ) - .unwrap(); - - let mut scratch = String::new(); - - for zdt in &datetimes { - let dt = DateTime { - date: zdt.date, - time: zdt.time, - }; - let _ = dtf.format(&dt, &zdt.zone).write_to(&mut scratch); - scratch.clear(); - } - } - } - }) - }); - - group.bench_function("TypedZonedDateTimeFormatter/format_to_string", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_zoned_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = TypedZonedDateTimeFormatter::::try_new( - &locale.into(), - options, - TimeZoneFormatterOptions::default(), - ) - .unwrap(); - - for zdt in &datetimes { - let dt = DateTime { - date: zdt.date, - time: zdt.time, - }; - let _ = dtf.format_to_string(&dt, &zdt.zone); - } - } - } - }) - }); - - group.bench_function("FormattedZonedDateTime/format", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_zoned_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = TypedZonedDateTimeFormatter::::try_new( - &locale.into(), - options, - TimeZoneFormatterOptions::default(), - ) - .unwrap(); - - let mut result = String::new(); - - for zdt in &datetimes { - let dt = DateTime { - date: zdt.date, - time: zdt.time, - }; - let fdt = dtf.format(&dt, &zdt.zone); - write!(result, "{fdt}").unwrap(); - result.clear(); - } - } - } - }) - }); - - group.bench_function("FormattedZonedDateTime/to_string", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_zoned_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = TypedZonedDateTimeFormatter::::try_new( - &locale.into(), - options, - TimeZoneFormatterOptions::default(), - ) - .unwrap(); - - for zdt in &datetimes { - let dt = DateTime { - date: zdt.date, - time: zdt.time, - }; - let fdt = dtf.format(&dt, &zdt.zone); - let _ = fdt.to_string(); - } - } - } - }) - }); - - group.bench_function("FormattedZonedDateTime/write_to_string", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_zoned_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = TypedZonedDateTimeFormatter::::try_new( - &locale.into(), - options, - TimeZoneFormatterOptions::default(), - ) - .unwrap(); - - for zdt in &datetimes { - let dt = DateTime { - date: zdt.date, - time: zdt.time, - }; - let fdt = dtf.format(&dt, &zdt.zone); - let _ = fdt.write_to_string(); - } - } - } - }) - }); - - group.finish(); - } } criterion_group!(benches, datetime_benches); diff --git a/components/datetime/benches/fixtures/mod.rs b/components/datetime/benches/fixtures/mod.rs index 7e2df0a9954..7c53f1a98a8 100644 --- a/components/datetime/benches/fixtures/mod.rs +++ b/components/datetime/benches/fixtures/mod.rs @@ -2,7 +2,6 @@ // 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::options; use icu_datetime::options::DateTimeFormatterOptions; use serde::{Deserialize, Serialize}; @@ -22,15 +21,14 @@ pub struct TestInput { } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub enum TestOptions { - #[serde(rename = "length")] - Length(options::length::Bag), - #[serde(rename = "components")] +pub struct TestOptions { + pub length: Option, #[cfg(feature = "experimental")] - Components(options::components::Bag), - #[serde(rename = "components")] - #[cfg(not(feature = "experimental"))] - Components(serde_json::Value), + pub components: Option, + #[cfg(feature = "experimental")] + pub semantic: Option, + #[cfg(feature = "experimental")] + pub preferences: Option, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -56,11 +54,12 @@ pub struct PatternsFixture(pub Vec); #[allow(dead_code)] pub fn get_options(input: &TestOptions) -> Option { - match input { - TestOptions::Length(bag) => Some((*bag).into()), - #[cfg(feature = "experimental")] - TestOptions::Components(bag) => Some((*bag).into()), - #[cfg(not(feature = "experimental"))] - TestOptions::Components(_) => None, + if let Some(bag) = input.length { + return Some(bag.into()); + } + #[cfg(feature = "experimental")] + if let Some(bag) = input.components { + return Some(bag.into()); } + None } diff --git a/components/datetime/benches/fixtures/tests/components.json b/components/datetime/benches/fixtures/tests/components.json index 63266679e10..f2a984c5693 100644 --- a/components/datetime/benches/fixtures/tests/components.json +++ b/components/datetime/benches/fixtures/tests/components.json @@ -6,6 +6,10 @@ "options": { "components": { "year": "numeric" + }, + "semantic": { + "fieldSet": ["year"], + "length": "short" } } }, @@ -15,6 +19,10 @@ "components": { "year": "numeric", "month": "numeric" + }, + "semantic": { + "fieldSet": ["year", "month"], + "length": "short" } } }, @@ -25,6 +33,10 @@ "year": "numeric", "month": "numeric", "day": "numeric-day-of-month" + }, + "semantic": { + "fieldSet": ["year", "month", "day"], + "length": "short" } } }, @@ -36,6 +48,10 @@ "month": "numeric", "day": "numeric-day-of-month", "weekday": "short" + }, + "semantic": { + "fieldSet": ["year", "month", "day", "weekday"], + "length": "short" } } }, @@ -45,6 +61,10 @@ "components": { "year": "numeric", "month": "short" + }, + "semantic": { + "fieldSet": ["year", "month"], + "length": "medium" } } }, @@ -55,6 +75,10 @@ "year": "numeric", "month": "short", "day": "numeric-day-of-month" + }, + "semantic": { + "fieldSet": ["year", "month", "day"], + "length": "medium" } } }, @@ -66,6 +90,10 @@ "month": "short", "day": "numeric-day-of-month", "weekday": "short" + }, + "semantic": { + "fieldSet": ["year", "month", "day", "weekday"], + "length": "medium" } } }, @@ -75,6 +103,10 @@ "components": { "year": "numeric", "month": "long" + }, + "semantic": { + "fieldSet": ["year", "month"], + "length": "long" } } }, @@ -82,7 +114,13 @@ "locale": "en", "options": { "components": { - "month": "short" + "year": "numeric", + "month": "long", + "day": "numeric-day-of-month" + }, + "semantic": { + "fieldSet": ["year", "month", "day"], + "length": "long" } } }, @@ -92,6 +130,10 @@ "components": { "month": "numeric", "day": "numeric-day-of-month" + }, + "semantic": { + "fieldSet": ["month", "day"], + "length": "short" } } }, @@ -102,6 +144,10 @@ "month": "numeric", "day": "numeric-day-of-month", "weekday": "short" + }, + "semantic": { + "fieldSet": ["month", "day", "weekday"], + "length": "short" } } }, @@ -110,6 +156,10 @@ "options": { "components": { "month": "short" + }, + "semantic": { + "fieldSet": ["month"], + "length": "medium" } } }, @@ -119,6 +169,10 @@ "components": { "month": "short", "day": "numeric-day-of-month" + }, + "semantic": { + "fieldSet": ["month", "day"], + "length": "medium" } } }, @@ -129,6 +183,10 @@ "month": "short", "day": "numeric-day-of-month", "weekday": "short" + }, + "semantic": { + "fieldSet": ["month", "day", "weekday"], + "length": "medium" } } }, @@ -138,6 +196,10 @@ "components": { "month": "long", "day": "numeric-day-of-month" + }, + "semantic": { + "fieldSet": ["month", "day"], + "length": "long" } } }, @@ -146,6 +208,10 @@ "options": { "components": { "day": "numeric-day-of-month" + }, + "semantic": { + "fieldSet": ["day"], + "length": "short" } } }, @@ -155,6 +221,10 @@ "components": { "day": "numeric-day-of-month", "weekday": "short" + }, + "semantic": { + "fieldSet": ["day", "weekday"], + "length": "medium" } } }, @@ -163,6 +233,10 @@ "options": { "components": { "weekday": "short" + }, + "semantic": { + "fieldSet": ["weekday"], + "length": "medium" } } }, @@ -172,9 +246,13 @@ "components": { "weekday": "short", "hour": "numeric", - "minute": "numeric", - "preferences": { "hourCycle": "h12" } - } + "minute": "numeric" + }, + "semantic": { + "fieldSet": ["weekday", "hour", "minute"], + "length": "medium" + }, + "preferences": { "hourCycle": "h12" } } }, { @@ -184,9 +262,13 @@ "weekday": "short", "hour": "numeric", "minute": "numeric", - "second": "numeric", - "preferences": { "hourCycle": "h12" } - } + "second": "numeric" + }, + "semantic": { + "fieldSet": ["weekday", "hour", "minute", "second"], + "length": "medium" + }, + "preferences": { "hourCycle": "h12" } } }, { @@ -195,9 +277,13 @@ "components": { "weekday": "short", "hour": "numeric", - "minute": "numeric", - "preferences": { "hourCycle": "h23" } - } + "minute": "numeric" + }, + "semantic": { + "fieldSet": ["weekday", "hour", "minute"], + "length": "medium" + }, + "preferences": { "hourCycle": "h23" } } }, { @@ -207,18 +293,26 @@ "weekday": "short", "hour": "numeric", "minute": "numeric", - "second": "numeric", - "preferences": { "hourCycle": "h23" } - } + "second": "numeric" + }, + "semantic": { + "fieldSet": ["weekday", "hour", "minute", "second"], + "length": "medium" + }, + "preferences": { "hourCycle": "h23" } } }, { "locale": "en", "options": { "components": { - "hour": "numeric", - "preferences": { "hourCycle": "h12" } - } + "hour": "numeric" + }, + "semantic": { + "fieldSet": ["hour"], + "length": "medium" + }, + "preferences": { "hourCycle": "h12" } } }, { @@ -226,9 +320,13 @@ "options": { "components": { "hour": "numeric", - "minute": "numeric", - "preferences": { "hourCycle": "h12" } - } + "minute": "numeric" + }, + "semantic": { + "fieldSet": ["hour", "minute"], + "length": "medium" + }, + "preferences": { "hourCycle": "h12" } } }, { @@ -237,18 +335,26 @@ "components": { "hour": "numeric", "minute": "numeric", - "second": "numeric", - "preferences": { "hourCycle": "h12" } - } + "second": "numeric" + }, + "semantic": { + "fieldSet": ["hour", "minute", "second"], + "length": "medium" + }, + "preferences": { "hourCycle": "h12" } } }, { "locale": "en", "options": { "components": { - "hour": "numeric", - "preferences": { "hourCycle": "h23" } - } + "hour": "numeric" + }, + "semantic": { + "fieldSet": ["hour"], + "length": "medium" + }, + "preferences": { "hourCycle": "h23" } } }, { @@ -256,9 +362,13 @@ "options": { "components": { "hour": "numeric", - "minute": "numeric", - "preferences": { "hourCycle": "h23" } - } + "minute": "numeric" + }, + "semantic": { + "fieldSet": ["hour", "minute"], + "length": "medium" + }, + "preferences": { "hourCycle": "h23" } } }, { @@ -267,9 +377,13 @@ "components": { "hour": "numeric", "minute": "numeric", - "second": "numeric", - "preferences": { "hourCycle": "h23" } - } + "second": "numeric" + }, + "semantic": { + "fieldSet": ["hour", "minute", "second"], + "length": "medium" + }, + "preferences": { "hourCycle": "h23" } } }, { @@ -278,6 +392,10 @@ "components": { "minute": "numeric", "second": "numeric" + }, + "semantic": { + "fieldSet": ["hour", "minute"], + "length": "medium" } } }, @@ -286,16 +404,10 @@ "options": { "components": { "year": "two-digit" - } - } - }, - { - "locale": "en", - "options": { - "components": { - "year": "numeric", - "month": "numeric", - "day": "numeric-day-of-month" + }, + "semantic": { + "fieldSet": ["year"], + "length": "short" } } }, @@ -306,36 +418,11 @@ "year": "numeric", "month": "two-digit", "day": "numeric-day-of-month" - } - } - }, - { - "locale": "en", - "options": { - "components": { - "year": "numeric", - "month": "short", - "day": "numeric-day-of-month" - } - } - }, - { - "locale": "en", - "options": { - "components": { - "year": "numeric", - "month": "long", - "day": "numeric-day-of-month" - } - } - }, - { - "locale": "en", - "options": { - "components": { - "year": "numeric", - "month": "narrow", - "day": "numeric-day-of-month" + }, + "semantic": { + "fieldSet": ["year"], + "length": "short", + "alignment": "column" } } }, @@ -349,9 +436,13 @@ "weekday": "short", "hour": "numeric", - "minute": "numeric", - "preferences": { "hourCycle": "h12" } - } + "minute": "numeric" + }, + "semantic": { + "fieldSet": ["year", "month", "day", "weekday", "hour", "minute"], + "length": "medium" + }, + "preferences": { "hourCycle": "h12" } } }, { @@ -364,9 +455,13 @@ "weekday": "long", "hour": "numeric", - "minute": "numeric", - "preferences": { "hourCycle": "h12" } - } + "minute": "numeric" + }, + "semantic": { + "fieldSet": ["year", "month", "day", "weekday", "hour", "minute"], + "length": "long" + }, + "preferences": { "hourCycle": "h12" } } }, { @@ -374,9 +469,13 @@ "options": { "components": { "hour": "numeric", - "minute": "numeric", - "preferences": { "hourCycle": "h11" } - } + "minute": "numeric" + }, + "semantic": { + "fieldSet": ["hour", "minute"], + "length": "short" + }, + "preferences": { "hourCycle": "h11" } } }, { @@ -384,39 +483,27 @@ "options": { "components": { "hour": "numeric", - "minute": "numeric", - "preferences": { "hourCycle": "h12" } - } + "minute": "numeric" + }, + "semantic": { + "fieldSet": ["hour", "minute"], + "length": "short" + }, + "preferences": { "hourCycle": "h24" } } }, - { - "locale": "en", - "options": { - "components": { - "hour": "numeric", - "minute": "numeric", - "preferences": { "hourCycle": "h23" } - } - } - }, - { - "locale": "en", - "options": { - "components": { - "hour": "numeric", - "minute": "numeric", - "preferences": { "hourCycle": "h24" } - } - } - }, { "locale": "ar", "options": { "components": { "hour": "numeric", - "minute": "numeric", - "preferences": { "hourCycle": "h11" } - } + "minute": "numeric" + }, + "semantic": { + "fieldSet": ["hour", "minute"], + "length": "short" + }, + "preferences": { "hourCycle": "h11" } } }, { @@ -424,29 +511,41 @@ "options": { "components": { "hour": "numeric", - "minute": "numeric", - "preferences": { "hourCycle": "h12" } - } + "minute": "numeric" + }, + "semantic": { + "fieldSet": ["hour", "minute"], + "length": "short" + }, + "preferences": { "hourCycle": "h12" } } }, { - "locale": "ar", - "options": { - "components": { - "hour": "numeric", - "minute": "numeric", - "preferences": { "hourCycle": "h23" } - } - } + "locale": "ar", + "options": { + "components": { + "hour": "numeric", + "minute": "numeric" + }, + "semantic": { + "fieldSet": ["hour", "minute"], + "length": "short" + }, + "preferences": { "hourCycle": "h23" } + } }, { "locale": "ar", "options": { "components": { "hour": "numeric", - "minute": "numeric", - "preferences": { "hourCycle": "h24" } - } + "minute": "numeric" + }, + "semantic": { + "fieldSet": ["hour", "minute"], + "length": "short" + }, + "preferences": { "hourCycle": "h24" } } } ], diff --git a/components/datetime/benches/fixtures/tests/lengths.json b/components/datetime/benches/fixtures/tests/lengths.json index 5ce3ed80b4a..d3ee07c234e 100644 --- a/components/datetime/benches/fixtures/tests/lengths.json +++ b/components/datetime/benches/fixtures/tests/lengths.json @@ -7,6 +7,10 @@ "length": { "date": "full", "time": null + }, + "semantic": { + "fieldSet": ["year", "month", "day", "weekday"], + "length": "long" } } }, @@ -16,6 +20,10 @@ "length": { "date": "long", "time": null + }, + "semantic": { + "fieldSet": ["year", "month", "day"], + "length": "long" } } }, @@ -25,6 +33,10 @@ "length": { "date": "medium", "time": null + }, + "semantic": { + "fieldSet": ["year", "month", "day"], + "length": "medium" } } }, @@ -34,6 +46,10 @@ "length": { "date": "short", "time": null + }, + "semantic": { + "fieldSet": ["year", "month", "day"], + "length": "short" } } }, @@ -43,6 +59,10 @@ "length": { "date": null, "time": "medium" + }, + "semantic": { + "fieldSet": ["hour", "minute", "second"], + "length": "short" } } }, @@ -52,6 +72,10 @@ "length": { "date": null, "time": "short" + }, + "semantic": { + "fieldSet": ["hour", "minute"], + "length": "short" } } }, @@ -61,6 +85,10 @@ "length": { "date": "full", "time": "medium" + }, + "semantic": { + "fieldSet": ["year", "month", "day", "weekday", "hour", "minute", "second"], + "length": "long" } } }, @@ -70,6 +98,10 @@ "length": { "date": "long", "time": "short" + }, + "semantic": { + "fieldSet": ["year", "month", "day", "hour", "minute"], + "length": "long" } } }, @@ -79,6 +111,10 @@ "length": { "date": "medium", "time": "medium" + }, + "semantic": { + "fieldSet": ["year", "month", "day", "hour", "minute", "second"], + "length": "medium" } } }, @@ -88,6 +124,10 @@ "length": { "date": "short", "time": "short" + }, + "semantic": { + "fieldSet": ["year", "month", "day", "hour", "minute"], + "length": "short" } } } diff --git a/components/datetime/benches/fixtures/tests/lengths_with_zones.json b/components/datetime/benches/fixtures/tests/lengths_with_zones.json index f41f5ce62d4..f01f414a13d 100644 --- a/components/datetime/benches/fixtures/tests/lengths_with_zones.json +++ b/components/datetime/benches/fixtures/tests/lengths_with_zones.json @@ -1,48 +1,16 @@ [ { "setups": [ - { - "locale": "ru", - "options": { - "length": { - "date": "full", - "time": null - } - } - }, - { - "locale": "ru", - "options": { - "length": { - "date": "long", - "time": null - } - } - }, - { - "locale": "ru", - "options": { - "length": { - "date": "medium", - "time": null - } - } - }, - { - "locale": "ru", - "options": { - "length": { - "date": "short", - "time": null - } - } - }, { "locale": "ru", "options": { "length": { "date": null, "time": "full" + }, + "semantic": { + "fieldSet": ["hour", "minute", "second", "zoneSpecific"], + "length": "long" } } }, @@ -52,24 +20,10 @@ "length": { "date": null, "time": "long" - } - } - }, - { - "locale": "ru", - "options": { - "length": { - "date": null, - "time": "medium" - } - } - }, - { - "locale": "ru", - "options": { - "length": { - "date": null, - "time": "short" + }, + "semantic": { + "fieldSet": ["hour", "minute", "second", "zoneSpecific"], + "length": "medium" } } }, @@ -79,6 +33,10 @@ "length": { "date": "full", "time": "full" + }, + "semantic": { + "fieldSet": ["year", "month", "day", "weekday", "hour", "minute", "second", "zoneSpecific"], + "length": "long" } } }, @@ -88,24 +46,10 @@ "length": { "date": "long", "time": "long" - } - } - }, - { - "locale": "ru", - "options": { - "length": { - "date": "medium", - "time": "medium" - } - } - }, - { - "locale": "ru", - "options": { - "length": { - "date": "short", - "time": "short" + }, + "semantic": { + "fieldSet": ["year", "month", "day", "hour", "minute", "second", "zoneSpecific"], + "length": "medium" } } }