spencermountain / spacetime

A lightweight javascript timezone library
http://spacetime.how/
Other
3.99k stars 183 forks source link

Array date input support doesn't work for leap year #177

Closed lvillasica closed 4 years ago

lvillasica commented 4 years ago

spacetime([2020, 1, 29]) returns date 2020-28-02.

Upon checking the code it lead me to this https://github.com/spencermountain/spacetime/blob/master/src/methods/set/set.js#L113. When month is 1 (February), n would be equal to 28 because max is equal to 28.

spencermountain commented 4 years ago

hi Leo, thanks for this. Yeah, some date inputs have 0-based months, and some don't. The javascript date object has these ambiguities too. It appears this array-version of a date is 0-based. Maybe it shouldn't be. I'm happy to change it. It will be a breaking change though. Either way, some better documentation about this is in-order, i'm sure. cheers

lvillasica commented 4 years ago

yeah I know the month is 0-based but the days don't seem to be 0-based as what I am seeing here https://github.com/spencermountain/spacetime/blob/master/src/data/monthLengths.js#L2

lvillasica commented 4 years ago

Right now I am able to use the number support instead out of the date object spacetime(dateObj.getTime()) and seems to work pretty fine. Thanks so much for responding :)

spencermountain commented 4 years ago

oh right, 29 is hard-coded, isn't it. good find!

spencermountain commented 4 years ago

hey Leo, this is fixed in 6.6.2 thanks for the heads-up.