While writing Rounding time duration of difference to end of day to whole hours in momentjs?, I ran a few commands in Firefox console, and I just noticed this: when I specify a "naive" date, without any timezone, the ultimate Date recorded in the ._d
property of the moment is one hour early:
var m1 = moment('2017-02-17 21:00:00');
<- undefined
m1
<- Object { _isAMomentObject: true, _i: "2017-02-17 21:00:00", \
_f: "YYYY-MM-DD HH:mm:ss", _isUTC: false, _pf: Object, _locale: Object, _a: Array[7], \
_d: Date 2017-02-17T20:00:00.000Z, \
_isValid: true, _z: null }
So, I request '2017-02-17 21:00:00', I get 2017-02-17T20:00:00.000Z
recorded inside, in the ._d
property. Now, I'm in CET, which is UTC+0100, so I guess moment.js assumes I enter a local datetime when I enter a "naive" one, and converts it to UTC when storing it in ._d
.
That is OK, I guess, but what confused me is this in context of `endOf('day'):
var m2 = moment(m1).endOf('day');
<- undefined
m2
<- Object { _isAMomentObject: true, _i: "2017-02-17 21:00:00", \
_f: "YYYY-MM-DD HH:mm:ss", _isUTC: false, _pf: Object, _locale: Object, _z: null, _a: Array[7], \
_d: Date 2017-02-17T22:59:59.999Z, \
_isValid: true }
So I request end of day for "2017-02-17 21:00:00", and I get 2017-02-17T22:59:59.999Z
, - that is, the time portion is "22:59:59", which I simply cannot see as end of day ?!
Then again, if I forget about this, the code I have that uses .endOf('day')
(say, in the linked post) works as expected.
Could anyone explain the logic how come this works - even if 22:59:59 is not really the end of day?