ChakraCore
ChakraCore copied to clipboard
Date constructor with negative value argument
OS: Ubuntu 16.04 x86 chakra: 1.11.0.0-beta
Hi everyone,
I found an inconsistence on Date() with a negative value. I was looking on ES6 specification about this issue but I didn't found an answer, maybe the correct way is convert the -0 to +0 as V8 and SpiderMonkey do.
Steps to reproduce:
d = new Date(-0);
print(Object.is(d.getTime(), +0))
Actual results: false
Expected results: true
V8 and SpiderMonkey works as expected.
I took a quick look at this. Relevant spec https://tc39.github.io/ecma262/#sec-date-value in particular point 4.(d) and then https://tc39.github.io/ecma262/#sec-timeclip
I believe that v8 and spidermonkey are correct and the fix would be to edit the date constructor here (after the if/else): https://github.com/Microsoft/ChakraCore/blob/d5479383f757b86676ef30ec50b1a8050d325e13/lib/Runtime/Library/JavascriptDate.cpp#L175-L183 To specifically check for -0 and convert to +0.
Confirmed we're the only engine that diverges from spec here.
>eshost --tags jsvu -ise "Object.is(new Date(-0).getTime(), +0)"
## Source
print(Object.is(new Date(-0).getTime(), +0))
#### jsvu-ch
false
#### jsvu-jsc, jsvu-sm, jsvu-v8, jsvu-xs
true
I believe TimeClip is new -- I added it in Intl.cpp for use in DateTimeFormat, but it looks like it should be moved to somewhere more common and used in regular date parsing too.
cinfuzz
Marking this as a good first issue, should be less than 10 lines of code to fix though will also needed a test case which will be at leats the same again.
My previous comment highlights where the code change is needed - though also should check if can share code with Intl.cpp per jack's comment.
Can I work on this issue?
Can I work on this issue?
Go for it, Read all the previous comments for a starting point - also please check the contributing guidelines. Tag me if you have any questions and if/when you open a PR.