Skip to content

Commit

Permalink
Create ZoneOffsetCalculator (#5540)
Browse files Browse the repository at this point in the history
#5466

Supersedes #5515

---------

Co-authored-by: Shane F. Carr <shane@unicode.org>
  • Loading branch information
robertbastian and sffc authored Sep 16, 2024
1 parent b72d6df commit d6dffe2
Show file tree
Hide file tree
Showing 61 changed files with 26,086 additions and 375 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ indexmap = "1.0.0"
itertools = "0.10.3"
ndarray = "0.15.0"
nom = "7.0.0"
parse-zoneinfo = "0.3.1"
proc-macro2 = "1.0.61"
quote = "1.0.28"
rand = "0.8"
Expand Down
24 changes: 0 additions & 24 deletions components/datetime/src/format/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,6 @@ size_test!(
/// // but we did not load any data!
///
/// let mut dtz = CustomZonedDateTime::try_from_str("2023-11-20T11:35:03+00:00[Europe/London]").unwrap().to_calendar(Gregorian);
/// // TODO(#5466): Set the zone variant automatically
/// dtz.zone.zone_variant = Some(icu_timezone::ZoneVariant::standard());
///
/// // Missing data is filled in on a best-effort basis, and an error is signaled.
/// assert_try_writeable_parts_eq!(
Expand Down Expand Up @@ -931,10 +929,6 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
/// let mut zone_london_winter = CustomZonedDateTime::try_from_str("2024-01-01T00:00:00+00:00[Europe/London]").unwrap().zone;
/// let mut zone_london_summer = CustomZonedDateTime::try_from_str("2024-07-01T00:00:00+01:00[Europe/London]").unwrap().zone;
///
/// // TODO(#5466): Set the zone variant automatically
/// zone_london_winter.zone_variant = Some(icu_timezone::ZoneVariant::standard());
/// zone_london_summer.zone_variant = Some(icu_timezone::ZoneVariant::daylight());
///
/// let mut names =
/// TypedDateTimeNames::<Gregorian, NeoTimeZoneSkeleton>::try_new(&locale!("en-GB").into())
/// .unwrap();
Expand Down Expand Up @@ -1030,8 +1024,6 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
/// use writeable::assert_try_writeable_eq;
///
/// let mut zone_london_winter = CustomZonedDateTime::try_from_str("2024-01-01T00:00:00+00:00[Europe/London]").unwrap().zone;
/// // TODO(#5466): Set the zone variant automatically
/// zone_london_winter.zone_variant = Some(icu_timezone::ZoneVariant::standard());
///
/// let mut names =
/// TypedDateTimeNames::<Gregorian, NeoTimeZoneSkeleton>::try_new(&locale!("en-GB").into())
Expand Down Expand Up @@ -1107,10 +1099,6 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
/// let mut zone_london_winter = CustomZonedDateTime::try_from_str("2024-01-01T00:00:00+00:00[Europe/London]").unwrap().zone;
/// let mut zone_london_summer = CustomZonedDateTime::try_from_str("2024-07-01T00:00:00+01:00[Europe/London]").unwrap().zone;
///
/// // TODO(#5466): Set the zone variant automatically
/// zone_london_winter.zone_variant = Some(icu_timezone::ZoneVariant::standard());
/// zone_london_summer.zone_variant = Some(icu_timezone::ZoneVariant::daylight());
///
/// let mut names =
/// TypedDateTimeNames::<Gregorian, NeoTimeZoneSkeleton>::try_new(&locale!("en-GB").into())
/// .unwrap();
Expand Down Expand Up @@ -1180,10 +1168,6 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
/// let mut zone_london_winter = CustomZonedDateTime::try_from_str("2024-01-01T00:00:00+00:00[Europe/London]").unwrap().zone;
/// let mut zone_london_summer = CustomZonedDateTime::try_from_str("2024-07-01T00:00:00+01:00[Europe/London]").unwrap().zone;
///
/// // TODO(#5466): Set the zone variant automatically
/// zone_london_winter.zone_variant = Some(icu_timezone::ZoneVariant::standard());
/// zone_london_summer.zone_variant = Some(icu_timezone::ZoneVariant::daylight());
///
/// let mut names =
/// TypedDateTimeNames::<Gregorian, NeoTimeZoneSkeleton>::try_new(&locale!("en-GB").into())
/// .unwrap();
Expand Down Expand Up @@ -1253,10 +1237,6 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
/// let mut zone_london_winter = CustomZonedDateTime::try_from_str("2024-01-01T00:00:00+00:00[Europe/London]").unwrap().zone;
/// let mut zone_london_summer = CustomZonedDateTime::try_from_str("2024-07-01T00:00:00+01:00[Europe/London]").unwrap().zone;
///
/// // TODO(#5466): Set the zone variant automatically
/// zone_london_winter.zone_variant = Some(icu_timezone::ZoneVariant::standard());
/// zone_london_summer.zone_variant = Some(icu_timezone::ZoneVariant::daylight());
///
/// let mut names =
/// TypedDateTimeNames::<Gregorian, NeoTimeZoneSkeleton>::try_new(&locale!("en-GB").into())
/// .unwrap();
Expand Down Expand Up @@ -1326,10 +1306,6 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
/// let mut zone_london_winter = CustomZonedDateTime::try_from_str("2024-01-01T00:00:00+00:00[Europe/London]").unwrap().zone;
/// let mut zone_london_summer = CustomZonedDateTime::try_from_str("2024-07-01T00:00:00+01:00[Europe/London]").unwrap().zone;
///
/// // TODO(#5466): Set the zone variant automatically
/// zone_london_winter.zone_variant = Some(icu_timezone::ZoneVariant::standard());
/// zone_london_summer.zone_variant = Some(icu_timezone::ZoneVariant::daylight());
///
/// let mut names =
/// TypedDateTimeNames::<Gregorian, NeoTimeZoneSkeleton>::try_new(&locale!("en-GB").into())
/// .unwrap();
Expand Down
4 changes: 0 additions & 4 deletions components/datetime/src/neo_marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2057,8 +2057,6 @@ macro_rules! impl_zoneddatetime_marker {
/// .unwrap();
///
/// let mut dtz = CustomZonedDateTime::try_from_str("2024-05-17T15:47:50+01:00[Europe/London]").unwrap();
/// // TODO(#5466): Set the zone variant automatically
/// dtz.zone.zone_variant = Some(icu_timezone::ZoneVariant::daylight());
///
/// assert_try_writeable_eq!(
/// fmt.convert_and_format(&dtz),
Expand Down Expand Up @@ -2087,8 +2085,6 @@ macro_rules! impl_zoneddatetime_marker {
/// let mut dtz = CustomZonedDateTime::try_from_str("2024-05-17T15:47:50+01:00[Europe/London]")
/// .unwrap()
/// .to_calendar(Gregorian);
/// // TODO(#5466): Set the zone variant automatically
/// dtz.zone.zone_variant = Some(icu_timezone::ZoneVariant::daylight());
///
/// assert_try_writeable_eq!(
/// fmt.format(&dtz),
Expand Down
39 changes: 7 additions & 32 deletions components/datetime/tests/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,18 @@ use icu_datetime::{
neo_pattern::DateTimePattern,
neo_skeleton::{NeoDateTimeComponents, NeoSkeleton, NeoSkeletonLength, NeoTimeZoneSkeleton},
options::preferences::{self, HourCycle},
provider::time_zones::{MetazoneId, TimeZoneBcp47Id},
TypedDateTimeNames,
};
use icu_locale_core::{
extensions::unicode::{key, value, Value},
locale, LanguageIdentifier, Locale,
};
use icu_provider::prelude::*;
use icu_timezone::{CustomTimeZone, CustomZonedDateTime, ZoneVariant};
use icu_timezone::{CustomTimeZone, CustomZonedDateTime};
use patterns::{
dayperiods::{DayPeriodExpectation, DayPeriodTests},
time_zones::{TimeZoneConfig, TimeZoneExpectation, TimeZoneFormatterConfig, TimeZoneTests},
time_zones::{TimeZoneExpectation, TimeZoneFormatterConfig, TimeZoneTests},
};
use tinystr::tinystr;
use writeable::{assert_try_writeable_eq, assert_writeable_eq};

mod mock;
Expand Down Expand Up @@ -350,7 +348,7 @@ fn assert_fixture_element<A>(
}
}

fn test_fixture_with_time_zones(fixture_name: &str, file: &str, config: TimeZoneConfig) {
fn test_fixture_with_time_zones(fixture_name: &str, file: &str) {
for fx in serde_json::from_str::<fixtures::Fixture>(file)
.expect("Unable to get fixture.")
.0
Expand All @@ -368,10 +366,7 @@ fn test_fixture_with_time_zones(fixture_name: &str, file: &str, config: TimeZone
options.era_display = skeleton.era_display;
options.fractional_second_digits = skeleton.fractional_second_digits;

let mut zoned_datetime = mock::parse_zoned_gregorian_from_str(&fx.input.value);
zoned_datetime.zone.time_zone_id = config.time_zone_id.map(TimeZoneBcp47Id);
zoned_datetime.zone.metazone_id = config.metazone_id.map(MetazoneId);
zoned_datetime.zone.zone_variant = config.zone_variant.map(ZoneVariant);
let zoned_datetime = mock::parse_zoned_gregorian_from_str(&fx.input.value);

let description = match fx.description {
Some(description) => {
Expand Down Expand Up @@ -454,11 +449,7 @@ fn test_time_zone_format_configs() {
.0
{
let data_locale: DataLocale = test.locale.parse::<LanguageIdentifier>().unwrap().into();
let mut config = test.config;
let mut zoned_datetime = mock::parse_zoned_gregorian_from_str(&test.datetime);
zoned_datetime.zone.time_zone_id = config.time_zone_id.take().map(TimeZoneBcp47Id);
zoned_datetime.zone.metazone_id = config.metazone_id.take().map(MetazoneId);
zoned_datetime.zone.zone_variant = config.zone_variant.take().map(ZoneVariant);
let zoned_datetime = mock::parse_zoned_gregorian_from_str(&test.datetime);
for TimeZoneExpectation {
patterns: _,
configs,
Expand Down Expand Up @@ -506,12 +497,7 @@ fn test_time_zone_format_offset_not_set_debug_assert_panic() {
neo_marker::NeoTimeZoneOffsetShortMarker, DateTimeWriteError, NeverCalendar,
};

let time_zone = CustomTimeZone {
offset: None,
time_zone_id: Some(TimeZoneBcp47Id(tinystr!(8, "uslax"))),
metazone_id: Some(MetazoneId(tinystr!(4, "ampa"))),
zone_variant: Some(ZoneVariant::daylight()),
};
let time_zone = CustomTimeZone::try_from_str("America/Los_Angeles").unwrap();
let tzf = TypedNeoFormatter::<NeverCalendar, NeoTimeZoneOffsetShortMarker>::try_new(
&locale!("en").into(),
Default::default(),
Expand All @@ -532,11 +518,7 @@ fn test_time_zone_patterns() {
.0
{
let locale: Locale = test.locale.parse().unwrap();
let mut config = test.config;
let mut zoned_datetime = mock::parse_zoned_gregorian_from_str(&test.datetime);
zoned_datetime.zone.time_zone_id = config.time_zone_id.take().map(TimeZoneBcp47Id);
zoned_datetime.zone.metazone_id = config.metazone_id.take().map(MetazoneId);
zoned_datetime.zone.zone_variant = config.zone_variant.take().map(ZoneVariant);
let zoned_datetime = mock::parse_zoned_gregorian_from_str(&test.datetime);

for TimeZoneExpectation {
patterns,
Expand Down Expand Up @@ -584,16 +566,10 @@ fn test_length_fixtures() {
test_fixture_with_time_zones(
"lengths_with_zones",
include_str!("fixtures/tests/lengths_with_zones.json"),
TimeZoneConfig::default(),
);
test_fixture_with_time_zones(
"lengths_with_zones_from_pdt",
include_str!("fixtures/tests/lengths_with_zones_from_pdt.json"),
TimeZoneConfig {
metazone_id: Some(tinystr!(4, "ampa")),
zone_variant: Some(tinystr!(2, "dt")),
..TimeZoneConfig::default()
},
);
}

Expand Down Expand Up @@ -639,7 +615,6 @@ fn test_components_with_zones() {
test_fixture_with_time_zones(
"components_with_zones",
include_str!("fixtures/tests/components_with_zones.json"),
TimeZoneConfig::default(),
);
}

Expand Down
Loading

0 comments on commit d6dffe2

Please sign in to comment.