Title: [295258] trunk
- Revision
- 295258
- Author
- [email protected]
- Date
- 2022-06-03 19:09:18 -0700 (Fri, 03 Jun 2022)
Log Message
[WTF] Handle "at" in Date parse heuristics to make Date picker work in CNBC.com
https://bugs.webkit.org/show_bug.cgi?id=241258
rdar://93920424
Reviewed by Darin Adler.
AppleICU changes Intl.DateTimeFormat's formatting result to align it to Apple HI. But we
observed regression in CNBC.com since it reparses Intl.DateTimeFormat's string with Date
constructor.
Strictly speaking, there is no guarantee that code works. Date constructor's parsing
is implementation-dependent, and the spec does not require that Intl.DateTimeFormat's output
should be accepted by Date constructor. And this works only for English case anyway even before
this AppleICU change: if date is formatted via `ja-JP`, then Date constructor does not accept it.
But previously, this English case was working by chance, but now, new ICU format inserts "at"
in the string, and it makes that string unaccepted in Date constructor.
To workaround this web-compatibility issue, we extend our Date parsing heuristics to
accept "at". This is OK since the goal of this heuristics is accepting wider range of date
strings. Also it is OK that accepting English word "at" since this heuristics already handle
weekday and month names in English.
* JSTests/complex.yaml:
* JSTests/complex/intl-date-time-format-date-parse.js: Added.
(shouldBe):
* Source/WTF/wtf/DateMath.cpp:
(WTF::parseDateFromNullTerminatedCharacters):
Canonical link: https://commits.webkit.org/251304@main
Modified Paths
Added Paths
Diff
Added: trunk/JSTests/complex/intl-date-time-format-date-parse.js (0 => 295258)
--- trunk/JSTests/complex/intl-date-time-format-date-parse.js (rev 0)
+++ trunk/JSTests/complex/intl-date-time-format-date-parse.js 2022-06-04 02:09:18 UTC (rev 295258)
@@ -0,0 +1,21 @@
+function shouldBe(actual, expected) {
+ if (actual !== expected)
+ throw new Error(`bad value: ${actual}, expected ${expected}`);
+}
+
+let date = new Date(1654191240000);
+let t = Intl.DateTimeFormat("en-US", {
+ timeZone: "America/New_York",
+ weekday: "short",
+ year: "numeric",
+ month: "short",
+ day: "numeric",
+ hour: "numeric",
+ minute: "numeric"
+}).format(date);
+let reparsed = new Date(t)
+shouldBe(reparsed.getTime(), date.getTime());
+
+// "at" case
+shouldBe(new Date(`Thu, May 26, 2022, 6:27 PM`).getTime(), 1653604020000);
+shouldBe(new Date(`Thu, May 26, 2022 at 6:27 PM`).getTime(), 1653604020000);
Modified: trunk/JSTests/complex.yaml (295257 => 295258)
--- trunk/JSTests/complex.yaml 2022-06-04 01:10:29 UTC (rev 295257)
+++ trunk/JSTests/complex.yaml 2022-06-04 02:09:18 UTC (rev 295258)
@@ -61,3 +61,6 @@
- path: complex/for-in-clobberize.js
cmd: runComplexTest [], [], "", "--destroy-vm"
+
+- path: complex/intl-date-time-format-date-parse.js
+ cmd: runComplexTest [], [], "TZ=America/New_York"
Modified: trunk/Source/WTF/wtf/DateMath.cpp (295257 => 295258)
--- trunk/Source/WTF/wtf/DateMath.cpp 2022-06-04 01:10:29 UTC (rev 295257)
+++ trunk/Source/WTF/wtf/DateMath.cpp 2022-06-04 02:09:18 UTC (rev 295258)
@@ -836,7 +836,12 @@
year = std::nullopt;
} else {
// in the normal case (we parsed the year), advance to the next number
- dateString = ++newPosStr;
+ // ' at 23:12:40 GMT'
+ if (isASCIISpace(newPosStr[0]) && isASCIIAlphaCaselessEqual(newPosStr[1], 'a') && isASCIIAlphaCaselessEqual(newPosStr[2], 't'))
+ newPosStr += 3;
+ else
+ ++newPosStr; // space or comma
+ dateString = newPosStr;
skipSpacesAndComments(dateString);
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes