This repository has been archived by the owner on Oct 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deps: update ChakraCore to chakra-core/ChakraCore@d1c4faf38b
[1.8>1.9] [MERGE #4318 @xiaoyinl] Make Date.parse recognize padded and negative years (Fixes #4178) Merge pull request #4318 from xiaoyinl:DateParse_zero_padded_years This PR will finally make `Date.parse` able to parse any output of `Date.toString()`, `Date.toUTCString`, and `Date.toISOString()`. Fixes #4178 Fixes #4300 Todo: - [x] Add, update and re-enable tests (#4300) - [x] `new Date( Reviewed-By: chakrabot <chakrabot@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
176 additions
and
13 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,41 @@ | ||
//------------------------------------------------------------------------------------------------------- | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | ||
//------------------------------------------------------------------------------------------------------- | ||
|
||
// Date.parse must be able to parse the strings returned by Date.toString() for negative and zero-padded | ||
// years. See https://github.com/Microsoft/ChakraCore/pull/4318 | ||
|
||
// This test is disabled on xplat because the time zone for negative years on xplat is different from | ||
// time zone on Windows. | ||
|
||
/// <reference path="../UnitTestFramework/UnitTestFramework.js" /> | ||
if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch | ||
this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js"); | ||
} | ||
|
||
function testDate(isoDateString) { | ||
let Dateobj = new Date(isoDateString); | ||
let value = Dateobj.valueOf(); | ||
let str = Dateobj.toString(); | ||
|
||
assert.areEqual(value, Date.parse(str), "Date.parse('" + str + "') returns wrong value."); | ||
} | ||
|
||
let tests = [{ | ||
name: "test if Date.parse() can correctly parse outputs of Date.toString()", | ||
body: function () { | ||
testDate("0001-10-13T05:16:33Z"); | ||
testDate("0011-10-13T05:16:33Z"); | ||
testDate("0111-10-13T05:16:33Z"); | ||
testDate("1111-10-13T05:16:33Z"); | ||
|
||
// test BC years | ||
testDate("-000001-11-13T19:40:33Z"); | ||
testDate("-000011-11-13T19:40:33Z"); | ||
testDate("-000111-11-13T19:40:33Z"); | ||
testDate("-001111-11-13T19:40:33Z"); | ||
} | ||
}]; | ||
|
||
testRunner.run(tests, { verbose: WScript.Arguments[0] != "summary" }); |
41 changes: 41 additions & 0 deletions
41
deps/chakrashim/core/test/Date/parseToUTCStringAndToISOStringResults.js
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,41 @@ | ||
//------------------------------------------------------------------------------------------------------- | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | ||
//------------------------------------------------------------------------------------------------------- | ||
|
||
// Date.parse must be able to parse the strings returned by Date.toUTCString() and Date.toISOString() | ||
// for negative and zero-padded years. | ||
// See https://github.com/Microsoft/ChakraCore/pull/4318 | ||
|
||
/// <reference path="../UnitTestFramework/UnitTestFramework.js" /> | ||
if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch | ||
this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js"); | ||
} | ||
|
||
function testDate(isoDateString) { | ||
let Dateobj = new Date(isoDateString); | ||
let value = Dateobj.valueOf(); | ||
let UTCstr = Dateobj.toUTCString(); | ||
let ISOstr = Dateobj.toISOString(); | ||
|
||
assert.areEqual(value, Date.parse(UTCstr), "Date.parse('" + UTCstr + "') returns wrong value."); | ||
assert.areEqual(value, Date.parse(ISOstr), "Date.parse('" + ISOstr + "') returns wrong value."); | ||
} | ||
|
||
let tests = [{ | ||
name: "test if Date.parse() can correctly parse outputs of Date.toUTCString() and Date.toISOString()", | ||
body: function () { | ||
testDate("0001-10-13T05:16:33Z"); | ||
testDate("0011-10-13T05:16:33Z"); | ||
testDate("0111-10-13T05:16:33Z"); | ||
testDate("1111-10-13T05:16:33Z"); | ||
|
||
// test BC years | ||
testDate("-000001-11-13T19:40:33Z"); | ||
testDate("-000011-11-13T19:40:33Z"); | ||
testDate("-000111-11-13T19:40:33Z"); | ||
testDate("-001111-11-13T19:40:33Z"); | ||
} | ||
}]; | ||
|
||
testRunner.run(tests, { verbose: WScript.Arguments[0] != "summary" }); |
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