Tell HN: The day that lasted 25 hours

5 points by finchisko ↗ HN
I wonder how many people using MomentJS are aware of this.

http://jsfiddle.net/mauron85/aujyeacc/

7 comments

[ 3.4 ms ] story [ 37.9 ms ] thread
A version for the US DST: http://jsfiddle.net/j7tf54xn/

It's the test spec that's wrong. On the day DST ends, the hour from 1:00 to 1:59 is repeated twice, which gives you 25 hours. When DST begins, that day is only 23 hours long. MomentJS isn't doing anything strange here.

Ok. I've been already punished on stackoverflow for this question. But what about moment isDSTShifted method? Doesn't seems working. The shift was on 2:00AM.

But both moment('2015-25-10 2:00', 'YYYY-MM-DD HH:mm').isDSTShifted() moment('2015-25-10 3:00', 'YYYY-MM-DD HH:mm').isDSTShifted()

return false

Those are both supposed to return false. isDSTShifted() tells you whether the datetime you entered was shifted by the library because it doesn't exist in daylight savings time. For example, in pseudocode, if you try to "add 1 day" to "2:30AM the day before DST begins", it'll be shifted because there is no 2:30AM on the resulting date. The clock skips from 1:59AM to 3AM that day.

Here's a fiddle showing isDSTShifted() working with the US DST start (I don't know what date to use for your location):

http://jsfiddle.net/d9tz0tv1/

I think you're looking for isDST()?

Ok you're test is failing in my timezone. But it is OK, as far I understand (still not 100% sure if I do) :-).

But: moment('2015-25-10 2:00', 'YYYY-MM-DD HH:mm').isDST() moment('2015-25-10 3:00', 'YYYY-MM-DD HH:mm').isDST()

return false.

That's not correct in my TZ. Confused.

Do I have to call something like moment.tz() before isDST()?
Ok you're test is failing in my timezone. But it is OK, as far I understand (still not 100% sure if I do) :-).

But: moment('2015-25-10 2:00', 'YYYY-MM-DD HH:mm').isDST() moment('2015-25-10 3:00', 'YYYY-MM-DD HH:mm').isDST()

return false.

That's not correct in my TZ. Confused.

DST ends at 1:59AM. 2AM and 3AM are after DST ended, so it is correct for isDST to return false.