Hours on day of UNIX epoch don't work correctly
nelsonxb opened this issue · comments
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()
.
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));
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
Thanks for the report @NelsonCrosby. This will get rolled into a release soon.