Skip to content

Commit

Permalink
[JSC] Parse a critical flag on TZ annotation for Temporal
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=277942

Reviewed by Yusuke Suzuki.

RFC 3339[1] and RFC 9557[2] allows that bracketed timezone annotations include a critical flag(!)[3].
It indicate that the parsing should be rejected if there is a conflict between the offset and the
timezone annotation.

Temporal API has added this feature into the spec[4]. While the critical flag does not affect the
behavior of Temporal, parsing must still succeed.

Currently, JSC throws an error when creating a Temporal object from a string that includes a
critical flag.

This patch changes to allow creating Temporal objects from strings that include a critical flag.

[1]: https://www.rfc-editor.org/rfc/rfc3339
[2]: https://www.rfc-editor.org/rfc/rfc9557
[3]: https://www.rfc-editor.org/rfc/rfc9557.html#name-inconsistent-time-offset-an
[4]: tc39/proposal-temporal#2397

* JSTests/stress/temporal-instant-tz-critical-flags.js: Added.
* JSTests/stress/temporal-plaindate-tz-critical-flags.js: Added.
* JSTests/stress/temporal-plaindatetime-tz-critical-flags.js: Added.
* JSTests/stress/temporal-plaintime-tz-critical-flags.js: Added.
* JSTests/test262/expectations.yaml:
* Source/JavaScriptCore/runtime/ISO8601.cpp:
(JSC::ISO8601::parseTimeZoneBracketedAnnotation):

Canonical link: https://commits.webkit.org/282211@main
  • Loading branch information
sosukesuzuki authored and Constellation committed Aug 14, 2024
1 parent 5870ffb commit 380f93b
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 37 deletions.
14 changes: 14 additions & 0 deletions JSTests/stress/temporal-instant-tz-critical-flags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ requireOptions("--useTemporal=1")

const cases = [
["1970-01-01T00:00:00Z[!UTC]", "1970-01-01T00:00:00Z[!UTC]"],
["1970-01-01T00:00:00Z[!UTC]", "1970-01-01T00:00:00Z"],
["1970-01-01T00:00:00+02:00[!UTC]", "1970-01-01T00:00:00+02:00"],
["1970-01-01T00:00:00+09:00[!UTC]", "1970-01-01T00:00:00+09:00[Asia/Tokyo]"]
];

for (const [str1, str2] of cases) {
const instant = Temporal.Instant.from(str1);
if (!instant.equals(str2))
throw new Error(`"${str1}" and "${str2}" should result in the same Temporal.Instant.`)
}
14 changes: 14 additions & 0 deletions JSTests/stress/temporal-plaindate-tz-critical-flags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ requireOptions("--useTemporal=1")

const cases = [
["2000-05-02T00+00:00[!UTC]", "2000-05-02T00+00:00[!UTC]"],
["2000-05-02T00+00:00[!UTC]", "2000-05-02T00+00:00"],
["2000-05-02T00+02:00[!UTC]", "2000-05-02T00+02:00"],
["2000-05-02T00+09:00[!UTC]", "2000-05-02T00+09:00[Asia/Tokyo]"],
];

for (const [str1, str2] of cases) {
const plainDate = Temporal.PlainDate.from(str1);
if (!plainDate.equals(str2))
throw new Error(`"${str1}" and "${str2}" should result in the same Temporal.PlainDate.`)
}
14 changes: 14 additions & 0 deletions JSTests/stress/temporal-plaindatetime-tz-critical-flags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ requireOptions("--useTemporal=1")

const cases = [
["1976-11-18T15:23+00:00[!UTC]", "1976-11-18T15:23+00:00[!UTC]"],
["1976-11-18T15:23+00:00[!UTC]", "1976-11-18T15:23+00:00"],
["1976-11-18T15:23+02:00[!UTC]", "1976-11-18T15:23+02:00"],
["1976-11-18T15:23+09:00[!UTC]", "1976-11-18T15:23+09:00[Asia/Tokyo]"],
];

for (const [str1, str2] of cases) {
const plainDateTime = Temporal.PlainDateTime.from(str1);
if (!plainDateTime.equals(str2))
throw new Error(`"${str1}" and "${str2}" should result in the same Temporal.PlainDateTime.`)
}
14 changes: 14 additions & 0 deletions JSTests/stress/temporal-plaintime-tz-critical-flags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ requireOptions("--useTemporal=1")

const cases = [
["12:34:56.987654321+00:00[!UTC]", "12:34:56.987654321+00:00[!UTC]"],
["12:34:56.987654321+00:00[!UTC]", "12:34:56.987654321+00:00"],
["12:34:56.987654321+02:00[!UTC]", "12:34:56.987654321+02:00"],
["12:34:56.987654321+09:00[!UTC]", "12:34:56.987654321+09:00[Asia/Tokyo]"],
];

for (const [str1, str2] of cases) {
const plainTime = Temporal.PlainTime.from(str1);
if (!plainTime.equals(str2))
throw new Error(`"${str1}" and "${str2}" should result in the same Temporal.PlainTime.`)
}
Loading

0 comments on commit 380f93b

Please sign in to comment.