-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Times: JS: Remove implicit UTC convesion. #5614
Conversation
The conversion would produce incorrect timestamp.
I asked for tests in the last PR (#5581). I will ask again because I think we run the risk of continuously changing the |
Yeah, I'm totally with you on the necessity of tests. In fact, I was very much puzzled by Araq accepting the PR without the tests. I just wanted to file the change right away so that I wouldn't have to remember to submit it. I am not hoping the PR will be merged until I provide the tests. If it's bad/annoying/distracting to post PRs this way, please feel free to delete this one. I'll resubmit it later with tests (when I figure out how to write and run them with Koch). |
Add yearday calculation to getLocalTime and getGMTime, so that yearday is not 0 for TimeInfo instances under JS backend. Yearday 0 has no sense and contradicts the behaviour under C backend, where yearday is an int from 1 to 365, i.e. cannot be 0 even theoretically.
In fact I was just going to submit another untested PR (moigagoo@bef86f5). I'll hold it until you tell me what the right thing to do is. |
If you place a (I'm not an expert at this, so dom can probably add to this.) |
@stisa Thanks for the info! I actually figured it out myself. I was having trouble writing the actual test, namely making it fail. It turns out if the first line of a test is a comment, it always passes no matter what content it has. I spent about an hour to realize that. Like, this always passes: # a comment
discard """
action: run
"""
doAssert false == true And this always fails: discard """
action: run
"""
doAssert false == true |
OK, the previous examples work like they should, but here's the actual tests that passes when it should not: # test times module with JS backend
discard """
action: run
"""
import times
# $ date --date='@2147483647'
# Tue 19 Jan 03:14:07 GMT 2038
block yeardayTest:
# check
doAssert fromSeconds(2147483647).getGMTime().yearday == 0 This one fails as it should: discard """
action: run
"""
import times
# $ date --date='@2147483647'
# Tue 19 Jan 03:14:07 GMT 2038
block yeardayTest:
# check
doAssert fromSeconds(2147483647).getGMTime().yearday == 0 |
I have no idea why this happens. @dom96 maybe you could tell? UPD: Now this is complete nonsense. This comment breaks the test: |
@moigagoo the |
@Araq Thanks a lot for the clarification! |
The tests do pass locally. Could you rerun the build to see if the checks pass now? |
Well your tests fail. |
@Araq thanks for the update. I'll investigate. |
@Araq While fixing the test I've encountered a problem. I hope you could help me. Proc proc toTime*(timeInfo: TimeInfo): Time =
result = internGetTime()
result.setMinutes(timeInfo.minute)
result.setHours(timeInfo.hour)
result.setMonth(ord(timeInfo.month))
result.setFullYear(timeInfo.year)
result.setDate(timeInfo.monthday)
result.setSeconds(timeInfo.second) Since JS can produce Date objects from strings, the better way to do the conversion seems to be to call proc newDate(value: cstring): Time {.importc: "new Date".} # fix type: string → cstring
...
proc toTime*(timeInfo: TimeInfo): Time = newDate($timeInfo) However, for some reason, Also, I can't use I feel that the problem is that I could, of course, build the string manually (e.g. "$#-$#-$#T$#:$#:$#" % [timeInfo.year, ...]), but this is ugly and I'm sure there's a better way. |
I don't know. To test your hypothesis, move the declarations around as you see fit. |
To use JS's Date creation from string, I moved the TimeInfo formatting code above the toTime proc declaration. Also, I changed the argument type for newDate from string to cstring for it to work.
…TC+4. `parse` returns TimeInfo with the local timezone, which may not be the same as the one in the original string. To compare the moments encoded in the original string and returned by `parse`, we normalize them to UTC.
According to the build logs, the tests have actually passed, but the build still failed with |
Travis is really failing us here. We seem to be hitting some sort of bug in it. |
@dom96 Could this be related? |
Perhaps. I restarted it in any case, we'll see if it succeeds this time. |
Yay! It passed! |
Brilliant! Merging :) |
The conversion would produce incorrect timestamps during parsing.
See https://forum.nim-lang.org/t/2876, point 2.