-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Original commit message: [intl] Enhance Date parser to take Unicode SPACE This is needed to prepare for the landing of ICU72. Allow U+202F in the Date String, which the toLocaleString("en-US") will generate w/ ICU72. Bug: v8:13494 Change-Id: I41b83c4094ce3d0737a72dcd6310b52c68fdcdca Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4027341 Reviewed-by: Yang Guo <yangguo@chromium.org> Reviewed-by: Jungshik Shin <jshin@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/main@{#84308} Refs: v8/v8@2ada52c Fixes: #45171 PR-URL: #45573 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
- Loading branch information
Showing
4 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2022 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Test the new Date( date.toLocaleString("en-US")) is not invalid. | ||
// This is not guaranteed by the standard but many code use that to set the | ||
// timezone as suggested in | ||
// https://stackoverflow.com/questions/15141762/how-to-initialize-a-javascript-date-to-a-particular-time-zone | ||
|
||
let d = new Date(); | ||
|
||
// https://tc39.es/ecma262/#sec-todatestring | ||
// 21.4.4.41.4 ToDateString ( tv ) | ||
// 1. If tv is NaN, return "Invalid Date". | ||
let invalid = "Invalid Date"; | ||
let largestDiff = 25*60*60*1000; | ||
|
||
let garbage = new Date("garbage"); | ||
assertTrue(invalid == garbage); | ||
assertEquals(NaN, garbage.getTime()); | ||
|
||
let d1 = new Date(d.toLocaleString("en-US")); | ||
assertTrue(d1 != invalid); | ||
assertTrue(d1.getTime() != NaN); | ||
// The milliseconds are different between d1 and d. | ||
assertTrue(Math.abs(d1-d) < 1000); | ||
|
||
// Force a version of date string which have U+202f before AM | ||
let nnbsp_am = new Date("11/16/2022, 9:04:55\u202fAM"); | ||
assertTrue(nnbsp_am != invalid); | ||
assertTrue(nnbsp_am.getTime() != NaN); | ||
// Force a version of date string which have U+202f before PM | ||
let nnbsp_pm = new Date("11/16/2022, 9:04:55\u202fPM"); | ||
assertTrue(nnbsp_pm != invalid); | ||
assertTrue(nnbsp_pm.getTime() != NaN); | ||
|
||
let d2 = new Date(d.toLocaleString("en-US", {timeZone: "Asia/Taipei"})); | ||
assertTrue(d2 != invalid); | ||
assertTrue(d2.getTime() != NaN); | ||
// The differences should be within 25 hours. | ||
assertTrue(Math.abs(d2-d) < largestDiff); | ||
|
||
let d3 = new Date(d.toLocaleString("en-US", {timeZone: "Africa/Lusaka"})); | ||
assertTrue(d3 != invalid); | ||
assertTrue(d3.getTime() != NaN); | ||
// The differences should be within 25 hours. | ||
assertTrue(Math.abs(d3-d) < largestDiff); |