-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Date.to(UTC)String() outputs match web reality and spec language #4067
Merged
chakrabot
merged 1 commit into
chakra-core:release/1.8
from
xiaoyinl:parse_own_toString
Nov 22, 2017
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 (C) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | ||
//------------------------------------------------------------------------------------------------------- | ||
|
||
// For dates whose years are less than 1000, Date.toString() and Date.toUTCString() should pad the years | ||
// to 4 digits. | ||
// See https://github.com/Microsoft/ChakraCore/pull/4067 | ||
|
||
/// <reference path="../UnitTestFramework/UnitTestFramework.js" /> | ||
if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch | ||
this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js"); | ||
} | ||
|
||
function testDate(DateObj, toStringExpected, toUTCStringExpected) { | ||
assert.areEqual(toStringExpected, DateObj.toString(), "Date.toString() returns invalid value."); | ||
assert.areEqual(toUTCStringExpected, DateObj.toUTCString(), "Date.toUTCString() returns invalid value."); | ||
} | ||
|
||
let tests = [{ | ||
name: "test if Date.toString() and Date.toUTCString() pad positive years to four digits", | ||
body: function () { | ||
testDate(new Date("0001-10-13T05:16:33Z"), "Fri Oct 12 0001 22:16:33 GMT-0700 (Pacific Daylight Time)", | ||
"Sat, 13 Oct 0001 05:16:33 GMT"); | ||
testDate(new Date("0011-10-13T05:16:33Z"), "Wed Oct 12 0011 22:16:33 GMT-0700 (Pacific Daylight Time)", | ||
"Thu, 13 Oct 0011 05:16:33 GMT"); | ||
testDate(new Date("0111-10-13T05:16:33Z"), "Mon Oct 12 0111 22:16:33 GMT-0700 (Pacific Daylight Time)", | ||
"Tue, 13 Oct 0111 05:16:33 GMT"); | ||
testDate(new Date("1111-10-13T05:16:33Z"), "Thu Oct 12 1111 22:16:33 GMT-0700 (Pacific Daylight Time)", | ||
"Fri, 13 Oct 1111 05:16:33 GMT"); | ||
} | ||
}, | ||
{ | ||
name: "test if Date.toString() and Date.toUTCString() pad negative years to four digits", | ||
body: function () { | ||
testDate(new Date("-000001-10-13T05:16:33Z"), "Tue Oct 12 -0001 22:16:33 GMT-0700 (Pacific Daylight Time)", | ||
"Wed, 13 Oct -0001 05:16:33 GMT"); | ||
testDate(new Date("-000011-10-13T05:16:33Z"), "Thu Oct 12 -0011 22:16:33 GMT-0700 (Pacific Daylight Time)", | ||
"Fri, 13 Oct -0011 05:16:33 GMT"); | ||
testDate(new Date("-000111-10-13T05:16:33Z"), "Sat Oct 12 -0111 22:16:33 GMT-0700 (Pacific Daylight Time)", | ||
"Sun, 13 Oct -0111 05:16:33 GMT"); | ||
testDate(new Date("-001111-10-13T05:16:33Z"), "Wed Oct 12 -1111 22:16:33 GMT-0700 (Pacific Daylight Time)", | ||
"Thu, 13 Oct -1111 05:16:33 GMT"); | ||
} | ||
}]; | ||
|
||
testRunner.run(tests, { verbose: WScript.Arguments[0] != "summary" }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: newline after this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general the above function is a bit ugly but I understand the need to implement ~ this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't super clear from the read that the reason for converting the input number to uint16 is so that it is compatible with the char16 _u('0'). Can you add a comment explaining? What will behavior look like for years > 4 digits and > MAX_UINT16 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I fixed it by moving the
static_cast
to where the int32 value is assigned to char16, for readability and avoided > MAX_UINT16 issue.