From fb9f30a180e7fa4b7dc58ef52891093e35c1fe05 Mon Sep 17 00:00:00 2001 From: Robert Bastian <4706271+robertbastian@users.noreply.github.com> Date: Thu, 31 Oct 2024 17:59:06 +0100 Subject: [PATCH] Make TZ fixture more readable (#5756) --- components/datetime/tests/datetime.rs | 108 +- .../tests/patterns/tests/time_zones.json | 1215 +++-------------- .../datetime/tests/patterns/time_zones.rs | 220 +-- 3 files changed, 240 insertions(+), 1303 deletions(-) diff --git a/components/datetime/tests/datetime.rs b/components/datetime/tests/datetime.rs index 414c873df55..a67159e1176 100644 --- a/components/datetime/tests/datetime.rs +++ b/components/datetime/tests/datetime.rs @@ -25,13 +25,13 @@ use icu_datetime::{ }; use icu_locale_core::{ extensions::unicode::{key, value, Value}, - locale, LanguageIdentifier, Locale, + locale, Locale, }; use icu_provider::prelude::*; use icu_timezone::{CustomZonedDateTime, TimeZoneIdMapper, TimeZoneInfo, UtcOffset}; use patterns::{ dayperiods::{DayPeriodExpectation, DayPeriodTests}, - time_zones::{TimeZoneExpectation, TimeZoneFormatterConfig, TimeZoneTests}, + time_zones::TimeZoneTests, }; use writeable::{assert_try_writeable_eq, assert_writeable_eq}; @@ -434,41 +434,30 @@ fn test_time_zone_format_configs() { .unwrap() .0 { - let data_locale: DataLocale = test.locale.parse::().unwrap().into(); + let data_locale: DataLocale = test.locale.parse::().unwrap().into(); let zoned_datetime = mock::parse_zoned_gregorian_from_str(&test.datetime); - for TimeZoneExpectation { - patterns: _, - configs, - expected, - } in &test.expectations - { - for &config_input in configs { - if matches!(config_input, TimeZoneFormatterConfig::Iso8601(_, _, _)) { - // TODO: ISO-8601 not yet supported via Semantic Skeleton - continue; - } - let skeleton = config_input.to_semantic_skeleton(); - for expect in expected { - let tzf = - FixedCalendarDateTimeFormatter::::try_new_with_skeleton( - &data_locale, - skeleton, - ) - .unwrap(); - assert_writeable_eq!( - writeable::adapters::LossyWrap(tzf.format(&zoned_datetime.zone)), - *expect, - "\n\ + for (pattern_input, expect) in &test.expectations { + let Some(skeleton) = patterns::time_zones::pattern_to_semantic_skeleton(pattern_input) + else { + continue; + }; + let tzf = FixedCalendarDateTimeFormatter::::try_new_with_skeleton( + &data_locale, + skeleton, + ) + .unwrap(); + assert_writeable_eq!( + writeable::adapters::LossyWrap(tzf.format(&zoned_datetime.zone)), + *expect, + "\n\ locale: `{}`,\n\ datetime: `{}`,\n\ config: `{:?}`,\n ", - data_locale, - test.datetime, - config_input, - ); - } - } + data_locale, + test.datetime, + pattern_input, + ); } } } @@ -508,44 +497,33 @@ fn test_time_zone_patterns() { .unwrap() .0 { - let locale: Locale = test.locale.parse().unwrap(); + let data_locale: DataLocale = test.locale.parse::().unwrap().into(); let zoned_datetime = mock::parse_zoned_gregorian_from_str(&test.datetime); - for TimeZoneExpectation { - patterns, - configs: _, - expected, - } in &test.expectations - { - for pattern_input in patterns { - if pattern_input == "VVV" { - // TODO(#5658): 'VVV' format not yet supported - continue; - } - let parsed_pattern = DateTimePattern::try_from_pattern_str(pattern_input).unwrap(); - for expect in expected.iter() { - let mut pattern_formatter = - TypedDateTimeNames::::try_new( - &(&locale).into(), - ) - .unwrap(); - let formatted_datetime = pattern_formatter - .include_for_pattern(&parsed_pattern) - .unwrap() - .format(&zoned_datetime); - assert_writeable_eq!( - writeable::adapters::LossyWrap(formatted_datetime), - *expect, - "\n\ + for (pattern_input, expect) in &test.expectations { + if pattern_input == "VVV" { + // TODO(#5658): 'VVV' format not yet supported + continue; + } + let parsed_pattern = DateTimePattern::try_from_pattern_str(pattern_input).unwrap(); + let mut pattern_formatter = + TypedDateTimeNames::::try_new(&data_locale) + .unwrap(); + let formatted_datetime = pattern_formatter + .include_for_pattern(&parsed_pattern) + .unwrap() + .format(&zoned_datetime); + assert_writeable_eq!( + writeable::adapters::LossyWrap(formatted_datetime), + *expect, + "\n\ locale: `{}`,\n\ datetime: `{}`,\n\ pattern: `{}`", - locale, - test.datetime, - pattern_input, - ); - } - } + data_locale, + test.datetime, + pattern_input, + ); } } } diff --git a/components/datetime/tests/patterns/tests/time_zones.json b/components/datetime/tests/patterns/tests/time_zones.json index 8e758c60676..46971e4a338 100644 --- a/components/datetime/tests/patterns/tests/time_zones.json +++ b/components/datetime/tests/patterns/tests/time_zones.json @@ -2,1100 +2,207 @@ { "locale": "en", "datetime": "2021-07-11T12:00:00.000-07:00[America/Los_Angeles]", - "expectations": [ - { - "patterns": [ - "z", - "zz", - "zzz" - ], - "configs": [ - "SpecificNonLocationShort" - ], - "expected": ["PDT"] - }, - { - "patterns": [ - "zzzz" - ], - "configs": [ - "SpecificNonLocationLong" - ], - "expected": ["Pacific Daylight Time"] - }, - { - "patterns": [ - "Z", - "ZZ", - "ZZZ" - ], - "configs": [ + "expectations": { + "z": "PDT", + "zzzz": "Pacific Daylight Time", - ], - "expected": ["-0700"] - }, - { - "patterns": [ - "O" - ], - "configs": [ - "LocalizedOffsetShort" - ], - "fallback_formats": ["LocalizedOffset"], - "expected": ["GMT-7"] - }, - { - "patterns": [ - "OOOO", - "ZZZZ" - ], - "configs": [ - "LocalizedOffsetLong" - ], - "expected": ["GMT-07:00"] - }, - { - "patterns": [ - "ZZZZZ" - ], - "configs": [ - { - "Iso8601": [ - "UtcExtended", - "Required", - "Optional" - ] - } - ], - "expected": ["-07:00"] - }, - { - "patterns": [ - "v" - ], - "configs": [ - "GenericNonLocationShort" - ], - "expected": ["PT"] - }, - { - "patterns": [ - "vvvv" - ], - "configs": [ - "GenericNonLocationLong" - ], - "expected": ["Pacific Time"] - }, - { - "patterns": [ - "VVV" - ], - "configs": [], - "expected": ["Los Angeles"] - }, - { - "patterns": [ - "VVVV" - ], - "configs": [ - "GenericLocation" - ], - "expected": ["Los Angeles Time"] - }, - { - "patterns": [ - "x", - "X" - ], - "configs": [ - { - "Iso8601": [ - "Basic", - "Optional", - "Never" - ] - } - ], - "expected": ["-07"] - }, - { - "patterns": [ - "xx", - "XX", - "xxxx", - "XXXX" - ], - "configs": [ - { - "Iso8601": [ - "Basic", - "Required", - "Never" - ] - } - ], - "expected": ["-0700"] - }, - { - "patterns": [ - "xxx", - "XXX", - "xxxxx", - "XXXXX" - ], - "configs": [ - { - "Iso8601": [ - "Extended", - "Required", - "Never" - ] - } - ], - "expected": ["-07:00"] - } - ] + "v": "PT", + "vvvv": "Pacific Time", + + "VVV": "Los Angeles", + "VVVV": "Los Angeles Time", + + "O": "GMT-7", + "OOOO": "GMT-07:00", + + "x": "-07", + "X": "-07", + + "xx": "-0700", + "XX": "-0700", + "Z": "-0700", + + "xxx": "-07:00", + "XXX": "-07:00", + "xxxx": "-0700", + "XXXX": "-0700", + + "XXXXX": "-07:00", + "xxxxx": "-07:00", + "ZZZZZ": "-07:00" + } }, { "locale": "en", "datetime": "2021-07-11T12:00:00.000+01:00[Europe/London]", - "expectations": [ - { - "patterns": [], - "configs": [ - "SpecificNonLocationShort" - ], - "expected": ["GMT+1"] - }, - { - "patterns": [], - "configs": [ - "SpecificNonLocationLong" - ], - "expected": ["British Summer Time"] - }, - { - "patterns": [], - "configs": [ - "LocalizedOffsetLong" - ], - "expected": ["GMT+01:00"] - }, - { - "patterns": [], - "configs": [ - { - "Iso8601": [ - "UtcExtended", - "Required", - "Optional" - ] - } - ], - "expected": ["+01:00"] - }, - { - "patterns": [], - "configs": [ - "GenericNonLocationShort" - ], - "expected": ["GMT"] - }, - { - "patterns": [], - "configs": [ - "GenericNonLocationLong" - ], - "expected": ["Greenwich Mean Time"] - }, - { - "patterns": [], - "configs": [ - "GenericLocation" - ], - "expected": ["UK Time"] - }, - { - "patterns": [], - "configs": [ - { - "Iso8601": [ - "Basic", - "Optional", - "Never" - ] - } - ], - "expected": ["+01"] - }, - { - "patterns": [], - "configs": [ - { - "Iso8601": [ - "Basic", - "Required", - "Never" - ] - } - ], - "expected": ["+0100"] - }, - { - "patterns": [], - "configs": [ - { - "Iso8601": [ - "Extended", - "Required", - "Never" - ] - } - ], - "expected": ["+01:00"] - } - ] + "expectations": { + "z": "GMT+1", + "zzzz": "British Summer Time", + + "v": "GMT", + "vvvv": "Greenwich Mean Time", + + "VVV": "London", + "VVVV": "UK Time", + + "O": "GMT+1", + "OOOO": "GMT+01:00" + } }, { "locale": "en", "datetime": "2021-07-11T12:00:00.000+01:00[Europe/Dublin]", - "expectations": [ - { - "patterns": [], - "configs": [ - "SpecificNonLocationShort" - ], - "expected": ["GMT+1"] - }, - { - "patterns": [], - "configs": [ - "SpecificNonLocationLong" - ], - "expected": ["Irish Standard Time"] - }, - { - "patterns": [], - "configs": [ - "LocalizedOffsetLong" - ], - "expected": ["GMT+01:00"] - }, - { - "patterns": [], - "configs": [ - { - "Iso8601": [ - "UtcExtended", - "Required", - "Optional" - ] - } - ], - "expected": ["+01:00"] - }, - { - "patterns": [], - "configs": [ - "GenericNonLocationShort" - ], - "expected": ["GMT"] - }, - { - "patterns": [], - "configs": [ - "GenericNonLocationLong" - ], - "expected": ["Greenwich Mean Time"] - }, - { - "patterns": [], - "configs": [ - "GenericLocation" - ], - "expected": ["Ireland Time"] - }, - { - "patterns": [], - "configs": [ - { - "Iso8601": [ - "Basic", - "Optional", - "Never" - ] - } - ], - "expected": ["+01"] - }, - { - "patterns": [], - "configs": [ - { - "Iso8601": [ - "Basic", - "Required", - "Never" - ] - } - ], - "expected": ["+0100"] - }, - { - "patterns": [], - "configs": [ - { - "Iso8601": [ - "Extended", - "Required", - "Never" - ] - } - ], - "expected": ["+01:00"] - } - ] + "expectations": { + "z": "GMT+1", + "zzzz": "Irish Standard Time", + + "v": "GMT", + "vvvv": "Greenwich Mean Time", + + "VVV": "Dublin", + "VVVV": "Ireland Time", + + "O": "GMT+1", + "OOOO": "GMT+01:00" + } }, { "locale": "ja", "datetime": "2021-01-11T12:00:00.000+09:00[Asia/Tokyo]", - "expectations": [ - { - "patterns": [ - "z", - "zz", - "zzz" - ], - "configs": [ - "SpecificNonLocationShort" - ], - "expected": ["JST"] - }, - { - "patterns": [ - "zzzz" - ], - "configs": [ - "SpecificNonLocationLong" - ], - "expected": ["日本標準時"] - }, - { - "patterns": [ - "Z", - "ZZ", - "ZZZ" - ], - "configs": [ - { - "Iso8601": [ - "Basic", - "Required", - "Optional" - ] - } - ], - "expected": ["+0900"] - }, - { - "patterns": [ - "O" - ], - "configs": [ - "LocalizedOffsetShort" - ], - "fallback_formats": ["LocalizedOffset"], - "expected": ["GMT+9"] - }, - { - "patterns": [ - "OOOO", - "ZZZZ" - ], - "configs": [ - "LocalizedOffsetLong" - ], - "expected": ["GMT+09:00"] - }, - { - "patterns": [ - "ZZZZZ" - ], - "configs": [ - { - "Iso8601": [ - "UtcExtended", - "Required", - "Optional" - ] - } - ], - "expected": ["+09:00"] - }, - { - "patterns": [ - "v" - ], - "configs": [ - "GenericNonLocationShort" - ], - "expected": ["JST"] - }, - { - "patterns": [ - "vvvv" - ], - "configs": [ - "GenericNonLocationLong" - ], - "expected": ["日本時間"] - }, - { - "patterns": [ - "VVV" - ], - "configs": [], - "expected": ["東京"] - }, - { - "patterns": [ - "VVVV" - ], - "configs": [ - "GenericLocation" - ], - "expected": ["日本時間"] - }, - { - "patterns": [ - "x", - "X" - ], - "configs": [ - { - "Iso8601": [ - "UtcBasic", - "Optional", - "Never" - ] - } - ], - "expected": ["+09"] - }, - { - "patterns": [ - "xx", - "XX", - "xxxx", - "XXXX" - ], - "configs": [ - { - "Iso8601": [ - "UtcBasic", - "Required", - "Never" - ] - } - ], - "expected": ["+0900"] - }, - { - "patterns": [ - "xxx", - "XXX", - "xxxxx", - "XXXXX" - ], - "configs": [ - { - "Iso8601": [ - "UtcExtended", - "Required", - "Never" - ] - } - ], - "expected": ["+09:00"] - } - ] + "expectations": { + "z": "JST", + "zzzz": "日本標準時", + + "v": "JST", + "vvvv": "日本時間", + + "VVV": "東京", + "VVVV": "日本時間", + + "O": "GMT+9", + "OOOO": "GMT+09:00" + } }, { "locale": "ru", "datetime": "2021-01-11T12:00:00.000+00:00[Antarctica/Troll]", - "expectations": [ - { - "patterns": [ - "z", - "zz", - "zzz" - ], - "configs": [ - "SpecificNonLocationShort" - ], - "expected": ["GMT"] - }, - { - "patterns": [ - "zzzz" - ], - "configs": [ - "SpecificNonLocationLong" - ], - "expected": ["Среднее время по Гринвичу"] - }, - { - "patterns": [ - "Z", - "ZZ", - "ZZZ" - ], - "configs": [ - { - "Iso8601": [ - "Basic", - "Required", - "Optional" - ] - } - ], - "expected": ["+0000"] - }, - { - "patterns": [ - "O", - "OOOO", - "ZZZZ" - ], - "configs": [ - "LocalizedOffsetShort", - "LocalizedOffsetLong" - ], - "expected": ["GMT"] - }, - { - "patterns": [ - "ZZZZZ" - ], - "configs": [ - { - "Iso8601": [ - "UtcExtended", - "Required", - "Optional" - ] - } - ], - "expected": ["Z"] - }, - { - "patterns": [ - "v" - ], - "configs": [ - "GenericNonLocationShort" - ], - "expected": ["Тролль"] - }, - { - "patterns": [ - "vvvv" - ], - "configs": [ - "GenericNonLocationLong" - ], - "expected": ["Среднее время по Гринвичу"] - }, - { - "patterns": [ - "VVV" - ], - "configs": [], - "expected": ["Тролль"] - }, - { - "patterns": [ - "VVVV" - ], - "configs": [ - "GenericLocation" - ], - "expected": ["Тролль"] - }, - { - "patterns": [ - "X" - ], - "configs": [ - { - "Iso8601": [ - "UtcBasic", - "Optional", - "Never" - ] - } - ], - "expected": ["Z"] - }, - { - "patterns": [ - "x" - ], - "configs": [ - { - "Iso8601": [ - "Basic", - "Optional", - "Never" - ] - } - ], - "expected": ["+00"] - }, - { - "patterns": [ - "XX", - "XXXX" - ], - "configs": [ - { - "Iso8601": [ - "UtcBasic", - "Required", - "Never" - ] - } - ], - "expected": ["Z"] - }, - { - "patterns": [ - "xx", - "xxxx" - ], - "configs": [ - { - "Iso8601": [ - "Basic", - "Required", - "Never" - ] - } - ], - "expected": ["+0000"] - }, - { - "patterns": [ - "XXX", - "XXXXX" - ], - "configs": [ - { - "Iso8601": [ - "UtcExtended", - "Required", - "Never" - ] - } - ], - "expected": ["Z"] - }, - { - "patterns": [ - "xxx", - "xxxxx" - ], - "configs": [ - { - "Iso8601": [ - "Extended", - "Required", - "Never" - ] - } - ], - "expected": ["+00:00"] - } - ] + "expectations": { + "z": "GMT", + "zzzz": "Среднее время по Гринвичу", + + "v": "Тролль", + "vvvv": "Среднее время по Гринвичу", + + "VVV": "Тролль", + "VVVV": "Тролль", + + "O": "GMT", + "OOOO": "GMT", + + "X": "Z" + } }, { "locale": "sr-Cyrl", "datetime": "2021-01-11T12:00:00.000+05:45[Asia/Kathmandu]", - "expectations": [ - { - "patterns": [ - "z", - "zz", - "zzz" - ], - "configs": [ - "SpecificNonLocationShort" - ], - "expected": ["GMT+5.45"] - }, - { - "patterns": [ - "zzzz" - ], - "configs": [ - "SpecificNonLocationLong" - ], - "expected": ["Непал време"] - }, - { - "patterns": [ - "Z", - "ZZ", - "ZZZ" - ], - "configs": [ - { - "Iso8601": [ - "Basic", - "Required", - "Optional" - ] - } - ], - "expected": ["+0545"] - }, - { - "patterns": [ - "O" - ], - "configs": [ - "LocalizedOffsetShort" - ], - "fallback_formats": ["LocalizedOffset"], - "expected": ["GMT+5.45"] - }, - { - "patterns": [ - "OOOO", - "ZZZZ" - ], - "configs": [ - "LocalizedOffsetLong" - ], - "expected": ["GMT+05.45"] - }, - { - "patterns": [ - "ZZZZZ" - ], - "configs": [ - { - "Iso8601": [ - "UtcExtended", - "Required", - "Optional" - ] - } - ], - "expected": ["+05:45"] - }, - { - "patterns": [ - "v" - ], - "configs": [ - "GenericNonLocationShort" - ], - "expected": ["Непал"] - }, - { - "patterns": [ - "vvvv" - ], - "configs": [ - "GenericNonLocationLong" - ], - "expected": ["Непал време"] - }, - { - "patterns": [ - "VVV" - ], - "configs": [], - "expected": ["Катманду"] - }, - { - "patterns": [ - "VVVV" - ], - "configs": [ - "GenericLocation" - ], - "expected": ["Непал"] - }, - { - "patterns": [ - "x", - "X" - ], - "configs": [ - { - "Iso8601": [ - "UtcBasic", - "Optional", - "Never" - ] - } - ], - "expected": ["+0545"] - }, - { - "patterns": [ - "xx", - "XX", - "xxxx", - "XXXX" - ], - "configs": [ - { - "Iso8601": [ - "UtcBasic", - "Required", - "Never" - ] - } - ], - "expected": ["+0545"] - }, - { - "patterns": [ - "xxx", - "XXX", - "xxxxx", - "XXXXX" - ], - "configs": [ - { - "Iso8601": [ - "UtcExtended", - "Required", - "Never" - ] - } - ], - "expected": ["+05:45"] - } - ] + "expectations": { + "z": "GMT+5.45", + "zzzz": "Непал време", + + "v": "Непал", + "vvvv": "Непал време", + + "VVV": "Катманду", + "VVVV": "Непал", + + "O": "GMT+5.45", + "OOOO": "GMT+05.45" + } }, { "locale": "bn", "datetime": "2021-01-11T12:00:00.000+05:45[Asia/Kathmandu]", - "expectations": [ - { - "patterns": [ - "Z", - "ZZ", - "ZZZ" - ], - "configs": [ - { - "Iso8601": [ - "Basic", - "Required", - "Optional" - ] - } - ], - "expected": ["+0545"] - }, - { - "patterns": [ - "O" - ], - "configs": [ - "LocalizedOffsetShort" - ], - "fallback_formats": ["LocalizedOffset"], - "expected": ["GMT +৫:৪৫"] - }, - { - "patterns": [ - "OOOO", - "ZZZZ" - ], - "configs": [ - "LocalizedOffsetLong" - ], - "expected": ["GMT +০৫:৪৫"] - } - ] + "expectations": { + "O": "GMT +৫:৪৫", + "OOOO": "GMT +০৫:৪৫", + "Z": "+0545" + } }, { "locale": "he", "datetime": "2021-01-11T12:00:00.000+03:00[Asia/Jerusalem]", - "expectations": [ - { - "patterns": [ - "Z", - "ZZ", - "ZZZ" - ], - "configs": [ - { - "Iso8601": [ - "Basic", - "Required", - "Optional" - ] - } - ], - "expected": ["+0300"] - }, - { - "patterns": [ - "O" - ], - "configs": [ - "LocalizedOffsetShort" - ], - "fallback_formats": ["LocalizedOffset"], - "expected": ["GMT\u200e+3\u200e"] - }, - { - "patterns": [ - "OOOO", - "ZZZZ" - ], - "configs": [ - "LocalizedOffsetLong" - ], - "expected": ["GMT\u200e+03:00\u200e"] - }, - { - "patterns": [ - "VVVV" - ], - "configs": [ - "GenericLocation" - ], - "expected": ["שעון ישראל"] - } - ] + "expectations": { + "z": "GMT\u200e+3\u200e", + "zzzz": "שעון ישראל (קיץ)", + + "v": "שעון ישראל", + "vvvv": "שעון ישראל", + + "VVV": "יְרוּשָׁלַיִם", + "VVVV": "שעון ישראל", + + "O": "GMT\u200e+3\u200e", + "OOOO": "GMT\u200e+03:00\u200e" + } }, { "locale": "en", "datetime": "2021-07-11T12:00:00.000-07:00[Etc/Unknown]", - "expectations": [ - { - "patterns": [ - "z", - "zz", - "zzz", - "v", - "O" - ], - "configs": [], - "expected": ["GMT-7"] - }, - { - "patterns": [ - "vvvv", - "VVVV", - "OOOO", - "zzzz", - "ZZZZ" - ], - "configs": [], - "expected": ["GMT-07:00"] - }, - { - "patterns": [ - "Z", - "ZZ", - "ZZZ" - ], - "configs": [], - "expected": ["-0700"] - }, - { - "patterns": [ - "ZZZZZ" - ], - "configs": [], - "expected": ["-07:00"] - } - ] + "expectations": { + "z": "GMT-7", + "zzzz": "GMT-07:00", + + "v": "GMT-7", + "vvvv": "GMT-07:00", + + "VVV": "Unknown City", + "VVVV": "GMT-07:00", + + "O": "GMT-7", + "OOOO": "GMT-07:00", + + "Z": "-0700", + "ZZZZZ": "-07:00" + } }, { "locale": "en", "datetime": "2021-07-11T12:00:00.000-07:00", - "expectations": [ - { - "patterns": [ - "z", - "zz", - "zzz", - "v", - "O" - ], - "configs": [], - "expected": ["GMT-7"] - }, - { - "patterns": [ - "ZZZZ", - "vvvv", - "VVVV", - "zzzz", - "OOOO" - ], - "configs": [], - "expected": ["GMT-07:00"] - }, - { - "patterns": [ - "Z", - "ZZ", - "ZZZ" - ], - "configs": [], - "expected": ["-0700"] - }, - { - "patterns": [ - "ZZZZZ" - ], - "configs": [], - "expected": ["-07:00"] - } - ] + "expectations": { + "z": "GMT-7", + "zzzz": "GMT-07:00", + + "v": "GMT-7", + "vvvv": "GMT-07:00", + + "VVV": "Unknown City", + "VVVV": "GMT-07:00", + + "O": "GMT-7", + "OOOO": "GMT-07:00", + + "Z": "-0700", + "ZZZZZ": "-07:00" + } }, { "locale": "en", "datetime": "2021-07-11T12:00:00.000[Etc/Unknown]", - "expectations": [ - { - "patterns": [ - "Z", - "ZZ", - "ZZZ", - "ZZZZZ" - ], - "configs": [], - "expected": ["+?"] - }, - { - "patterns": [ - "O", - "ZZZZ", - "OOOO", - "v", - "vvvv", - "VVVV", - "z", - "zz", - "zzz", - "zzzz" - ], - "configs": [], - "expected": ["GMT+?"] - } - ] + "expectations": { + "z": "GMT+?", + "zzzz": "GMT+?", + + "v": "GMT+?", + "vvvv": "GMT+?", + + "VVV": "Unknown City", + "VVVV": "GMT+?", + + "O": "GMT+?", + "OOOO": "GMT+?", + + "Z": "+?", + "ZZZZZ": "+?" + } } ] diff --git a/components/datetime/tests/patterns/time_zones.rs b/components/datetime/tests/patterns/time_zones.rs index 3ff360eecc0..b7605484f25 100644 --- a/components/datetime/tests/patterns/time_zones.rs +++ b/components/datetime/tests/patterns/time_zones.rs @@ -4,6 +4,7 @@ use icu_datetime::neo_skeleton::{NeoSkeletonLength, NeoTimeZoneSkeleton, NeoTimeZoneStyle}; use serde::{Deserialize, Serialize}; +use std::collections::HashMap; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct TimeZoneTests(pub Vec); @@ -12,188 +13,39 @@ pub struct TimeZoneTests(pub Vec); pub struct TimeZoneTest { pub locale: String, pub datetime: String, - pub expectations: Vec, -} - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct TimeZoneExpectation { - pub patterns: Vec, - pub configs: Vec, - pub expected: Vec, -} - -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] -pub enum FallbackFormat { - Iso8601(IsoFormat, IsoMinutes, IsoSeconds), - LocalizedOffset, -} - -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] -pub enum IsoSeconds { - Optional, - Never, -} - -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] -pub enum IsoMinutes { - Required, - Optional, -} - -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] -pub enum ZeroPadding { - On, - Off, -} - -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] -pub enum IsoFormat { - Basic, - Extended, - UtcBasic, - UtcExtended, -} - -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] -pub enum TimeZoneFormatterConfig { - GenericNonLocationLong, - GenericNonLocationShort, - GenericLocation, - SpecificNonLocationLong, - SpecificNonLocationShort, - LocalizedOffsetLong, - LocalizedOffsetShort, - Iso8601(IsoFormat, IsoMinutes, IsoSeconds), -} - -impl TimeZoneFormatterConfig { - pub fn to_semantic_skeleton(self) -> NeoTimeZoneSkeleton { - match self { - TimeZoneFormatterConfig::GenericNonLocationLong => { - NeoTimeZoneSkeleton::for_length_and_components( - NeoSkeletonLength::Long, - NeoTimeZoneStyle::Generic, - ) - } - TimeZoneFormatterConfig::GenericNonLocationShort => { - NeoTimeZoneSkeleton::for_length_and_components( - NeoSkeletonLength::Short, - NeoTimeZoneStyle::Generic, - ) - } - TimeZoneFormatterConfig::GenericLocation => { - NeoTimeZoneSkeleton::for_length_and_components( - NeoSkeletonLength::Long, - NeoTimeZoneStyle::Location, - ) - } - TimeZoneFormatterConfig::SpecificNonLocationLong => { - NeoTimeZoneSkeleton::for_length_and_components( - NeoSkeletonLength::Long, - NeoTimeZoneStyle::Specific, - ) - } - TimeZoneFormatterConfig::SpecificNonLocationShort => { - NeoTimeZoneSkeleton::for_length_and_components( - NeoSkeletonLength::Short, - NeoTimeZoneStyle::Specific, - ) - } - TimeZoneFormatterConfig::LocalizedOffsetLong => { - NeoTimeZoneSkeleton::for_length_and_components( - NeoSkeletonLength::Long, - NeoTimeZoneStyle::Offset, - ) - } - TimeZoneFormatterConfig::LocalizedOffsetShort => { - NeoTimeZoneSkeleton::for_length_and_components( - NeoSkeletonLength::Short, - NeoTimeZoneStyle::Offset, - ) - } - TimeZoneFormatterConfig::Iso8601( - IsoFormat::UtcBasic, - IsoMinutes::Optional, - IsoSeconds::Never, - ) => { - // TODO: X - todo!() - } - TimeZoneFormatterConfig::Iso8601( - IsoFormat::UtcBasic, - IsoMinutes::Required, - IsoSeconds::Never, - ) => { - // TODO: XX - todo!() - } - TimeZoneFormatterConfig::Iso8601( - IsoFormat::UtcExtended, - IsoMinutes::Required, - IsoSeconds::Never, - ) => { - // TODO: XXX - todo!() - } - TimeZoneFormatterConfig::Iso8601( - IsoFormat::UtcBasic, - IsoMinutes::Required, - IsoSeconds::Optional, - ) => { - // TODO: XXXX - todo!() - } - TimeZoneFormatterConfig::Iso8601( - IsoFormat::UtcExtended, - IsoMinutes::Required, - IsoSeconds::Optional, - ) => { - // TODO: XXXXX - todo!() - } - TimeZoneFormatterConfig::Iso8601( - IsoFormat::Basic, - IsoMinutes::Optional, - IsoSeconds::Never, - ) => { - // TODO: x - todo!() - } - TimeZoneFormatterConfig::Iso8601( - IsoFormat::Basic, - IsoMinutes::Required, - IsoSeconds::Never, - ) => { - // TODO: xx - todo!() - } - TimeZoneFormatterConfig::Iso8601( - IsoFormat::Extended, - IsoMinutes::Required, - IsoSeconds::Never, - ) => { - // TODO: xxx - todo!() - } - TimeZoneFormatterConfig::Iso8601( - IsoFormat::Basic, - IsoMinutes::Required, - IsoSeconds::Optional, - ) => { - // TODO: xxxx - todo!() - } - TimeZoneFormatterConfig::Iso8601( - IsoFormat::Extended, - IsoMinutes::Required, - IsoSeconds::Optional, - ) => { - // TODO: xxxxx - todo!() - } - TimeZoneFormatterConfig::Iso8601(_, _, _) => { - todo!() - } - } - } + pub expectations: HashMap, +} + +pub fn pattern_to_semantic_skeleton(p: &str) -> Option { + Some(match p { + "vvvv" => NeoTimeZoneSkeleton::for_length_and_components( + NeoSkeletonLength::Long, + NeoTimeZoneStyle::Generic, + ), + "v" => NeoTimeZoneSkeleton::for_length_and_components( + NeoSkeletonLength::Short, + NeoTimeZoneStyle::Generic, + ), + "VVVV" => NeoTimeZoneSkeleton::for_length_and_components( + NeoSkeletonLength::Long, + NeoTimeZoneStyle::Location, + ), + "zzzz" => NeoTimeZoneSkeleton::for_length_and_components( + NeoSkeletonLength::Long, + NeoTimeZoneStyle::Specific, + ), + "z" => NeoTimeZoneSkeleton::for_length_and_components( + NeoSkeletonLength::Short, + NeoTimeZoneStyle::Specific, + ), + "OOOO" => NeoTimeZoneSkeleton::for_length_and_components( + NeoSkeletonLength::Long, + NeoTimeZoneStyle::Offset, + ), + "O" => NeoTimeZoneSkeleton::for_length_and_components( + NeoSkeletonLength::Short, + NeoTimeZoneStyle::Offset, + ), + _ => return None, + }) }