-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Make Date.parse recognize padded and negative years (Fixes #4178) #4318
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.parse recognize padded and negative years (Fixes #4178) #4318
Conversation
|
v8 and SpiderMonkey have the same issue. I've reported to them as well. |
|
Some tests failed on Ubuntu. That's because I think this can be fixed in either of the following two ways, but they both violate the spec:
|
|
Re: xplat test failures, in the short term you could split the test into two separate test files, move the cases that have xplat failures into the second file, and tag the one with xplat failures However it would be better to actually solve this problem before merging this change. In terms of how to solve this problem: (2.) we cannot violate this part of the spec. I think that behavior will be depended on much more readily than 1. (1.) Rather than violating the spec on whether those values agree... Can we manipulate the value returned in LMT by rounding or truncating the LMT offset from UTC to the minute (up/down/nearest) so that those values are consistent? Since the actual time and time zone might be implementation-defined (down to the minute so that we can follow all of the spec rules) making sure that we don't have a discrepancy between these two in the number of seconds would solve our problems without violating the spec in any way. /cc @obastemur |
|
Please disable the neg. year tests on xplat. TLDR; I had initially implemented with BC support on Linux (bunch of tricks involved) but wasn't enough for OSX (different system / different source of random tz data for years with no actual tz). |
|
Yes we probably can't have xplat tests for negative years which exactly match outputs on all platforms for the reasons stated above, however we can test that our implementation is spec-compliant on points (1) which is already tested by most tests, and (2) by testing equivalence of those two operations, rather than their actual values. |
|
@dilijev @obastemur Sorry for the long delay! I was kind of busy in the last month. I just pushed some commits which, I think, have fixed the remaining issues. I split the tests into two files ( To test the potential impact on performance (mentioned in #4300), I use the following benchmark code: The result for current The result for It seems it even gets slightly faster, so I think probably the runtime cost for this fix is negligible. I will squash the commits if it looks good to you. |
dilijev
left a comment
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.
LGTM
| int tBcAd = 0; | ||
|
|
||
| size_t numOfDigits = 0; | ||
|
|
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: while you are squashing, you might remove this space here
| goto LError; | ||
| } | ||
| lwMonth = pszs->lwVal; | ||
| if ('-' == *pch) |
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.
can we have a totally bogus test of - is being the last character? i.e. `Wed, 11 Oct-"
|
@xiaoyinl thanks for this! I have couple of minor requests. The rest; |
|
@dilijev @obastemur Thanks for the review! I have added the tests you mentioned, and commits are squashed. |
|
Testing internally before merging. |
… 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("2017-jan-01")` causes an assertion failure
…d 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("2017-jan-01")` causes an assertion failure
…ize 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("2017-jan-01")` causes an assertion failure
This PR will finally make
Date.parseable to parse any output ofDate.toString(),Date.toUTCString, andDate.toISOString().Fixes #4178
Fixes #4300
Todo:
new Date("2017-jan-01")causes an assertion failure