Skip to content

Commit

Permalink
Set zone variant for unknown zones (#5695)
Browse files Browse the repository at this point in the history
This should not be a missing field error.
  • Loading branch information
robertbastian authored Oct 16, 2024
1 parent f99af85 commit ad99dd4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"output": {
"values": {
"en": "Tuesday, January 21, 2020, 08:25:07 {v}"
"en": "Tuesday, January 21, 2020, 08:25:07 Unknown City Time"
}
}
},
Expand Down Expand Up @@ -51,7 +51,7 @@
},
"output": {
"values": {
"en": "Tuesday, January 21, 2020, 08:25:07 {v}"
"en": "Tuesday, January 21, 2020, 08:25:07 Unknown City Time"
}
}
},
Expand Down Expand Up @@ -79,7 +79,7 @@
},
"output": {
"values": {
"en": "Tuesday, January 21, 2020, 08:25:07 {z}"
"en": "Tuesday, January 21, 2020, 08:25:07 GMT+5"
}
}
},
Expand Down Expand Up @@ -107,7 +107,7 @@
},
"output": {
"values": {
"en": "Tuesday, January 21, 2020, 08:25:07 {z}"
"en": "Tuesday, January 21, 2020, 08:25:07 GMT+5"
}
}
},
Expand Down
25 changes: 4 additions & 21 deletions components/datetime/tests/patterns/tests/time_zones.json
Original file line number Diff line number Diff line change
Expand Up @@ -986,13 +986,7 @@
"patterns": [
"z",
"zz",
"zzz"
],
"configs": [],
"expected": ["{z}"]
},
{
"patterns": [
"zzz",
"O"
],
"configs": [],
Expand All @@ -1001,6 +995,7 @@
{
"patterns": [
"OOOO",
"zzzz",
"ZZZZ"
],
"configs": [],
Expand Down Expand Up @@ -1042,13 +1037,6 @@
"z",
"zz",
"zzz",
"zzzz"
],
"configs": [],
"expected": ["{z}"]
},
{
"patterns": [
"O"
],
"configs": [],
Expand All @@ -1057,6 +1045,7 @@
{
"patterns": [
"ZZZZ",
"zzzz",
"OOOO"
],
"configs": [],
Expand All @@ -1081,13 +1070,7 @@
{
"patterns": [
"v",
"vvvv"
],
"configs": [],
"expected": ["{v}"]
},
{
"patterns": [
"vvvv",
"VVVV"
],
"configs": [],
Expand Down
29 changes: 17 additions & 12 deletions components/timezone/src/ixdtf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ impl TimeZoneInfo {
Ok(Self {
time_zone_id: crate::TimeZoneBcp47Id::unknown(),
offset: Some(UtcOffset::try_from_utc_offset_record(record)?),
zone_variant: None,
local_time: None,
zone_variant: Some(ZoneVariant::standard()),
local_time: Some((Date::unix_epoch(), Time::midnight())),
})
}

Expand All @@ -144,17 +144,22 @@ impl TimeZoneInfo {
time.second,
)?;
if let Some(offset) = offset {
if let Some((std_offset, dst_offset)) = ZoneOffsetCalculator::new()
.compute_offsets_from_time_zone(time_zone_id, &iso)
{
zone_variant = if offset == std_offset {
Some(ZoneVariant::standard())
} else if Some(offset) == dst_offset {
Some(ZoneVariant::daylight())
zone_variant = Some(
if let Some((std_offset, dst_offset)) = ZoneOffsetCalculator::new()
.compute_offsets_from_time_zone(time_zone_id, &iso)
{
if offset == std_offset {
ZoneVariant::standard()
} else if Some(offset) == dst_offset {
ZoneVariant::daylight()
} else {
return Err(ParseError::InvalidOffsetError);
}
} else {
return Err(ParseError::InvalidOffsetError);
};
}
debug_assert_eq!(time_zone_id.0.as_str(), "unk");
ZoneVariant::standard()
},
);
}
local_time = Some((iso.date, iso.time));
};
Expand Down

0 comments on commit ad99dd4

Please sign in to comment.