mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 21:27:34 +00:00
LibJS: Accept and ignore calendar annotation in Instant strings
This is a normative change in the Temporal spec.
See: 3cd9669
This commit is contained in:
parent
54bb6bf2c0
commit
9643a5c63f
2 changed files with 27 additions and 1 deletions
|
@ -1592,13 +1592,14 @@ bool ISO8601Parser::parse_duration()
|
||||||
bool ISO8601Parser::parse_temporal_instant_string()
|
bool ISO8601Parser::parse_temporal_instant_string()
|
||||||
{
|
{
|
||||||
// TemporalInstantString :
|
// TemporalInstantString :
|
||||||
// Date TimeSpecSeparator[opt] TimeZoneOffsetRequired
|
// Date TimeSpecSeparator[opt] TimeZoneOffsetRequired Calendar[opt]
|
||||||
StateTransaction transaction { *this };
|
StateTransaction transaction { *this };
|
||||||
if (!parse_date())
|
if (!parse_date())
|
||||||
return false;
|
return false;
|
||||||
(void)parse_time_spec_separator();
|
(void)parse_time_spec_separator();
|
||||||
if (!parse_time_zone_offset_required())
|
if (!parse_time_zone_offset_required())
|
||||||
return false;
|
return false;
|
||||||
|
(void)parse_calendar();
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,22 @@ describe("correct behavior", () => {
|
||||||
Temporal.Instant.from("1975-02-02T14:25:36.123456789Z[Custom/TimeZone]")
|
Temporal.Instant.from("1975-02-02T14:25:36.123456789Z[Custom/TimeZone]")
|
||||||
.epochNanoseconds
|
.epochNanoseconds
|
||||||
).toBe(160583136123456789n);
|
).toBe(160583136123456789n);
|
||||||
|
|
||||||
|
// Accepts but ignores the calendar.
|
||||||
|
let result = null;
|
||||||
|
expect(() => {
|
||||||
|
result = Temporal.Instant.from("1970-01-01T00:00Z[u-ca=UTC]");
|
||||||
|
}).not.toThrow();
|
||||||
|
expect(result).toBeInstanceOf(Temporal.Instant);
|
||||||
|
expect(result.epochNanoseconds).toBe(0n);
|
||||||
|
|
||||||
|
// Does not validate calendar name, it only checks that the calendar name matches the grammar.
|
||||||
|
result = null;
|
||||||
|
expect(() => {
|
||||||
|
result = Temporal.Instant.from("1970-01-01T00:00Z[u-ca=aAaAaAaA-bBbBbBb]");
|
||||||
|
}).not.toThrow();
|
||||||
|
expect(result).toBeInstanceOf(Temporal.Instant);
|
||||||
|
expect(result.epochNanoseconds).toBe(0n);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -48,4 +64,13 @@ describe("errors", () => {
|
||||||
"Invalid epoch nanoseconds value, must be in range -86400 * 10^17 to 86400 * 10^17"
|
"Invalid epoch nanoseconds value, must be in range -86400 * 10^17 to 86400 * 10^17"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("calendar annotation must match calendar grammar even though it's ignored", () => {
|
||||||
|
expect(() => {
|
||||||
|
Temporal.Instant.from("1970-01-01T00:00Z[u-ca=SerenityOS]");
|
||||||
|
}).toThrowWithMessage(
|
||||||
|
RangeError,
|
||||||
|
"Invalid instant string '1970-01-01T00:00Z[u-ca=SerenityOS]'"
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue