Skip to content
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

Hours on day of UNIX epoch don't work correctly #47

Closed
nelsonxb opened this issue Mar 2, 2015 · 3 comments · Fixed by #48
Closed

Hours on day of UNIX epoch don't work correctly #47

nelsonxb opened this issue Mar 2, 2015 · 3 comments · Fixed by #48

Comments

@nelsonxb
Copy link

nelsonxb commented Mar 2, 2015

strftimeUTC prints 01 for '%H instead of 00 when d.getTime() === 0, however only on the day of the UNIX epoch:

var strftimeUTC = require('strftime').strftimeUTC;
strftimeUTC('%F %T', new Date(0)) // '1970-01-01 01:00:00'

This doesn't seem to happen on other days:

strftimeUTC('%F %T', new Date(86400000)) // '1970-01-02 00:00:00'

This causes things to go a bit wrong when doing a stopwatch-like thing. A quick-fix is to add 86400000 (1 day) whenever using Date.setTime(), and subtract when using Date.getTime().

@alexandrnikitin
Copy link
Collaborator

Weird, works for me. What's your local timezone? Could you post more details e.g. run the code below

var strftimeUTC = require('../strftime.js').strftimeUTC;
var date = new Date(0);
console.log(date.getTime());
console.log(date.getTimezoneOffset());
console.log(date.getHours());
console.log(date.getUTCHours());
console.log(strftimeUTC('%H', date));

@nelsonxb
Copy link
Author

nelsonxb commented Mar 3, 2015

Here's the code I ended up running:

var strftime = require('strftime');
var strftimeUTC = strftime.strftimeUTC;
var date = new Date(0);
console.log('getTime:', date.getTime());
console.log('getTimezoneOffset:', date.getTimezoneOffset());
console.log('%Z %z:', strftime('%Z %z', date));
console.log('getHours:', date.getHours());
console.log('getUTCHours:', date.getUTCHours());
console.log('%H:', strftimeUTC('%H', date));
console.log();
date = new Date();
console.log('getTime:', date.getTime());
console.log('getTimezoneOffset:', date.getTimezoneOffset());
console.log('%Z %z:', strftime('%Z %z', date));
console.log('getHours:', date.getHours());
console.log('getUTCHours:', date.getUTCHours());
console.log('%H:', strftimeUTC('%H', date));

And here's the result:

getTime: 0
getTimezoneOffset: -720
%Z %z: NZST +1200
getHours: 12
getUTCHours: 0
%H: 01

getTime: 1425374897052
getTimezoneOffset: -780
%Z %z: NZDT +1300
getHours: 22
getUTCHours: 9
%H: 09

I should note that while it shows a different time zone between these, using date (GNU coreutils) 8.23 also does this and doesn't have this issue:

$ date -u --date='@0'
Thu Jan  1 00:00:00 UTC 1970
$ date --date='@0'
Thu Jan  1 12:00:00 NZST 1970

samsonjs added a commit that referenced this issue Mar 4, 2015
…ntWorkCorrectly

(Fixes #47) Fix conversion of date to UTC
@samsonjs
Copy link
Owner

samsonjs commented Mar 4, 2015

Thanks for the report @NelsonCrosby. This will get rolled into a release soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants