1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

LibJS+LibUnicode: Support ambiguous time zone transitions

For example, time zone transitions can result in repeated or skipped
wall times. Temporal wants us to handle these transitions.
This commit is contained in:
Timothy Flynn 2025-06-02 11:04:29 -04:00 committed by Shannon Booth
parent c8b4dc4847
commit 8145572180
Notes: github-actions[bot] 2025-06-02 21:10:26 +00:00
4 changed files with 92 additions and 12 deletions

View file

@ -403,13 +403,15 @@ Vector<Crypto::SignedBigInteger> get_named_time_zone_epoch_nanoseconds(StringVie
auto local_nanoseconds = get_utc_epoch_nanoseconds(iso_date_time);
auto local_time = UnixDateTime::from_nanoseconds_since_epoch(clip_bigint_to_sane_time(local_nanoseconds));
// FIXME: LibUnicode does not behave exactly as the spec expects. It does not consider repeated or skipped time points.
auto offset = Unicode::time_zone_offset(time_zone_identifier, local_time);
auto offsets = Unicode::disambiguated_time_zone_offsets(time_zone_identifier, local_time);
// Can only fail if the time zone identifier is invalid, which cannot be the case here.
VERIFY(offset.has_value());
Vector<Crypto::SignedBigInteger> result;
result.ensure_capacity(offsets.size());
return { local_nanoseconds.minus(Crypto::SignedBigInteger { offset->offset.to_nanoseconds() }) };
for (auto const& offset : offsets)
result.unchecked_append(local_nanoseconds.minus(Crypto::SignedBigInteger { offset.offset.to_nanoseconds() }));
return result;
}
// 21.4.1.21 GetNamedTimeZoneOffsetNanoseconds ( timeZoneIdentifier, epochNanoseconds ), https://tc39.es/ecma262/#sec-getnamedtimezoneoffsetnanoseconds

View file

@ -68,7 +68,7 @@ describe("correct behavior", () => {
expect(result).toBe(-1);
});
test("sub-minute time zone offset", () => {
test("sub-minute time zone offset (unambiguous time zone transition)", () => {
const duration1 = new Temporal.Duration(0, 0, 0, 31);
const duration2 = new Temporal.Duration(0, 1);
@ -82,6 +82,26 @@ describe("correct behavior", () => {
});
expect(result).toBe(0);
});
test("sub-minute time zone offset (ambiguous time zone transition)", () => {
const duration1 = new Temporal.Duration(0, 0, 0, 0, 24);
const duration2 = new Temporal.Duration(0, 0, 0, 1);
let result = Temporal.Duration.compare(duration1, duration2, {
relativeTo: "1952-10-15T23:59:59-11:19:40[Pacific/Niue]",
});
expect(result).toBe(-1);
result = Temporal.Duration.compare(duration1, duration2, {
relativeTo: "1952-10-15T23:59:59-11:20[Pacific/Niue]",
});
expect(result).toBe(-1);
result = Temporal.Duration.compare(duration1, duration2, {
relativeTo: "1952-10-15T23:59:59-11:20:00[Pacific/Niue]",
});
expect(result).toBe(0);
});
});
describe("errors", () => {
@ -148,7 +168,7 @@ describe("errors", () => {
);
});
test("sub-minute time zone offset mismatch", () => {
test("sub-minute time zone offset mismatch (unambiguous time zone transition)", () => {
const duration1 = new Temporal.Duration(0, 0, 0, 31);
const duration2 = new Temporal.Duration(0, 1);
@ -170,4 +190,18 @@ describe("errors", () => {
"Invalid offset for the provided date and time in the current time zone"
);
});
test("sub-minute time zone offset mismatch (ambiguous time zone transition)", () => {
const duration1 = new Temporal.Duration(0, 0, 0, 0, 24);
const duration2 = new Temporal.Duration(0, 0, 0, 1);
expect(() => {
Temporal.Duration.compare(duration1, duration2, {
relativeTo: "1952-10-15T23:59:59-11:19:50[Pacific/Niue]",
});
}).toThrowWithMessage(
RangeError,
"Invalid offset for the provided date and time in the current time zone"
);
});
});