Skip to content

Commit 6279b08

Browse files
Add "GMT+?" field to data struct, fall back to it (#5694)
This will be added to CLDR in the future.
1 parent ad99dd4 commit 6279b08

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+337
-557
lines changed

components/datetime/src/provider/time_zones.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ pub struct TimeZoneEssentialsV1<'data> {
6262
/// The localized zero-offset format.
6363
#[cfg_attr(feature = "serde", serde(borrow))]
6464
pub offset_zero: Cow<'data, str>,
65+
/// The localized unknown-offset format.
66+
#[cfg_attr(feature = "serde", serde(borrow))]
67+
pub offset_unknown: Cow<'data, str>,
6568
}
6669

6770
/// An ICU4X mapping to the CLDR timeZoneNames exemplar cities.
@@ -82,9 +85,6 @@ pub struct LocationsV1<'data> {
8285
/// Per-zone location display name
8386
#[cfg_attr(feature = "serde", serde(borrow))]
8487
pub locations: ZeroMap<'data, TimeZoneBcp47Id, str>,
85-
/// The display name for an unknown time zone. This is not combined with a pattern.
86-
#[cfg_attr(feature = "serde", serde(borrow))]
87-
pub unknown: Cow<'data, str>,
8888
/// The format string for a region's generic time.
8989
#[cfg_attr(
9090
feature = "serde",

components/datetime/src/time_zone.rs

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,18 @@ impl ResolvedNeoTimeZoneSkeleton {
7474
self.to_field().length,
7575
)),
7676
Some(TimeZoneFormatterUnit::GenericLocation),
77-
None,
77+
Some(TimeZoneFormatterUnit::LocalizedOffset(
78+
self.to_field().length,
79+
)),
7880
],
7981
// 'VVVV'
80-
ResolvedNeoTimeZoneSkeleton::Location => {
81-
[Some(TimeZoneFormatterUnit::GenericLocation), None, None]
82-
}
82+
ResolvedNeoTimeZoneSkeleton::Location => [
83+
Some(TimeZoneFormatterUnit::GenericLocation),
84+
Some(TimeZoneFormatterUnit::LocalizedOffset(
85+
self.to_field().length,
86+
)),
87+
None,
88+
],
8389
// `O`, `OOOO`, `ZZZZ`
8490
ResolvedNeoTimeZoneSkeleton::OffsetShort | ResolvedNeoTimeZoneSkeleton::OffsetLong => [
8591
Some(TimeZoneFormatterUnit::LocalizedOffset(
@@ -459,15 +465,16 @@ impl FormatTimeZone for LocalizedOffsetFormat {
459465
data_payloads: TimeZoneDataPayloadsBorrowed,
460466
fdf: Option<&FixedDecimalFormatter>,
461467
) -> Result<Result<(), FormatTimeZoneError>, fmt::Error> {
462-
let Some(offset) = input.offset else {
463-
return Ok(Err(FormatTimeZoneError::MissingInputField("zone_offset")));
464-
};
465468
let Some(essentials) = data_payloads.essentials else {
466469
return Ok(Err(FormatTimeZoneError::MissingZoneSymbols));
467470
};
468471
let Some(fdf) = fdf else {
469472
return Ok(Err(FormatTimeZoneError::MissingFixedDecimalFormatter));
470473
};
474+
let Some(offset) = input.offset else {
475+
sink.write_str(&essentials.offset_unknown)?;
476+
return Ok(Ok(()));
477+
};
471478
Ok(if offset.is_zero() {
472479
sink.write_str(&essentials.offset_zero)?;
473480
Ok(())
@@ -554,14 +561,14 @@ impl FormatTimeZone for GenericLocationFormat {
554561
return Ok(Err(FormatTimeZoneError::MissingZoneSymbols));
555562
};
556563

557-
if let Some(location) = locations.locations.get(&time_zone_id) {
558-
locations
559-
.pattern_generic
560-
.interpolate([location])
561-
.write_to(sink)?;
562-
} else {
563-
sink.write_str(&locations.unknown)?;
564-
}
564+
let Some(location) = locations.locations.get(&time_zone_id) else {
565+
return Ok(Err(FormatTimeZoneError::Fallback));
566+
};
567+
568+
locations
569+
.pattern_generic
570+
.interpolate([location])
571+
.write_to(sink)?;
565572

566573
Ok(Ok(()))
567574
}
@@ -591,19 +598,19 @@ impl FormatTimeZone for SpecificLocationFormat {
591598
return Ok(Err(FormatTimeZoneError::MissingZoneSymbols));
592599
};
593600

594-
if let Some(location) = locations.locations.get(&time_zone_id) {
595-
if zone_variant == ZoneVariant::daylight() {
596-
&locations.pattern_daylight
597-
} else if zone_variant == ZoneVariant::standard() {
598-
&locations.pattern_standard
599-
} else {
600-
&locations.pattern_generic
601-
}
602-
.interpolate([location])
603-
.write_to(sink)?;
601+
let Some(location) = locations.locations.get(&time_zone_id) else {
602+
return Ok(Err(FormatTimeZoneError::Fallback));
603+
};
604+
605+
if zone_variant == ZoneVariant::daylight() {
606+
&locations.pattern_daylight
607+
} else if zone_variant == ZoneVariant::standard() {
608+
&locations.pattern_standard
604609
} else {
605-
sink.write_str(&locations.unknown)?;
610+
&locations.pattern_generic
606611
}
612+
.interpolate([location])
613+
.write_to(sink)?;
607614

608615
Ok(Ok(()))
609616
}
@@ -691,7 +698,8 @@ impl FormatTimeZone for Iso8601Format {
691698
_fdf: Option<&FixedDecimalFormatter>,
692699
) -> Result<Result<(), FormatTimeZoneError>, fmt::Error> {
693700
let Some(offset) = input.offset else {
694-
return Ok(Err(FormatTimeZoneError::MissingInputField("zone_offset")));
701+
sink.write_str("+?")?;
702+
return Ok(Ok(()));
695703
};
696704
self.format_infallible(sink, offset).map(|()| Ok(()))
697705
}

components/datetime/tests/datetime.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,7 @@ fn test_time_zone_format_offset_seconds() {
487487

488488
#[test]
489489
fn test_time_zone_format_offset_not_set_debug_assert_panic() {
490-
use icu_datetime::{
491-
neo_marker::NeoTimeZoneOffsetMarker, neo_skeleton::NeoSkeletonLength, DateTimeWriteError,
492-
};
490+
use icu_datetime::{neo_marker::NeoTimeZoneOffsetMarker, neo_skeleton::NeoSkeletonLength};
493491

494492
let time_zone = TimeZoneInfo {
495493
time_zone_id: TimeZoneIdMapper::new()
@@ -502,11 +500,7 @@ fn test_time_zone_format_offset_not_set_debug_assert_panic() {
502500
NeoTimeZoneOffsetMarker::with_length(NeoSkeletonLength::Medium),
503501
)
504502
.unwrap();
505-
assert_try_writeable_eq!(
506-
tzf.format(&time_zone),
507-
"{O}",
508-
Err(DateTimeWriteError::MissingInputField("zone_offset"))
509-
);
503+
assert_try_writeable_eq!(tzf.format(&time_zone), "GMT+?",);
510504
}
511505

512506
#[test]

components/datetime/tests/fixtures/tests/components_with_zones.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"output": {
2525
"values": {
26-
"en": "Tuesday, January 21, 2020, 08:25:07 Unknown City Time"
26+
"en": "Tuesday, January 21, 2020, 08:25:07 GMT+5"
2727
}
2828
}
2929
},
@@ -51,7 +51,7 @@
5151
},
5252
"output": {
5353
"values": {
54-
"en": "Tuesday, January 21, 2020, 08:25:07 Unknown City Time"
54+
"en": "Tuesday, January 21, 2020, 08:25:07 GMT+5"
5555
}
5656
}
5757
},

components/datetime/tests/patterns/tests/time_zones.json

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -987,13 +987,16 @@
987987
"z",
988988
"zz",
989989
"zzz",
990+
"v",
990991
"O"
991992
],
992993
"configs": [],
993994
"expected": ["GMT-7"]
994995
},
995996
{
996997
"patterns": [
998+
"vvvv",
999+
"VVVV",
9971000
"OOOO",
9981001
"zzzz",
9991002
"ZZZZ"
@@ -1016,15 +1019,6 @@
10161019
],
10171020
"configs": [],
10181021
"expected": ["-07:00"]
1019-
},
1020-
{
1021-
"patterns": [
1022-
"v",
1023-
"vvvv",
1024-
"VVVV"
1025-
],
1026-
"configs": [],
1027-
"expected": ["Unknown City Time"]
10281022
}
10291023
]
10301024
},
@@ -1037,6 +1031,7 @@
10371031
"z",
10381032
"zz",
10391033
"zzz",
1034+
"v",
10401035
"O"
10411036
],
10421037
"configs": [],
@@ -1045,6 +1040,8 @@
10451040
{
10461041
"patterns": [
10471042
"ZZZZ",
1043+
"vvvv",
1044+
"VVVV",
10481045
"zzzz",
10491046
"OOOO"
10501047
],
@@ -1066,15 +1063,6 @@
10661063
],
10671064
"configs": [],
10681065
"expected": ["-07:00"]
1069-
},
1070-
{
1071-
"patterns": [
1072-
"v",
1073-
"vvvv",
1074-
"VVVV"
1075-
],
1076-
"configs": [],
1077-
"expected": ["Unknown City Time"]
10781066
}
10791067
]
10801068
},
@@ -1097,28 +1085,22 @@
10971085
"Z",
10981086
"ZZ",
10991087
"ZZZ",
1100-
"ZZZZ",
11011088
"ZZZZZ"
11021089
],
11031090
"configs": [],
1104-
"expected": ["{Z}"]
1091+
"expected": ["+?"]
11051092
},
11061093
{
11071094
"patterns": [
11081095
"O",
1109-
"OOOO"
1110-
],
1111-
"configs": [],
1112-
"expected": ["{O}"]
1113-
},
1114-
{
1115-
"patterns": [
1096+
"ZZZZ",
1097+
"OOOO",
11161098
"v",
11171099
"vvvv",
11181100
"VVVV"
11191101
],
11201102
"configs": [],
1121-
"expected": ["Unknown City Time"]
1103+
"expected": ["GMT+?"]
11221104
}
11231105
]
11241106
}

0 commit comments

Comments
 (0)