spencermountain / spacetime

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

Year addition perform unexpected result when value is a multiple of 5 #285

Closed YixiongJiang closed 3 years ago

YixiongJiang commented 3 years ago
const date = spacetime('2000-01-01 00:00:00');
expect(date.add(30, 'year').format(DateFormat.YYYY_MM_DD_HH_MM_SS)).toBe('2030-01-01 00:00:00');

Expected: "2030-01-01 00:00:00" Received: "2029-01-01 00:00:00"

It happens when unit is year and when the value is a multiple of 5.

Just curiosity, why not just add value to the year numerically?

spencermountain commented 3 years ago

thanks @YixiongJiang good find. I'll check it out. cheers

YixiongJiang commented 3 years ago

@spencermountain Thanks, for your more information, I found there is a workaround to avoid this bug: date.add(30*12, 'month'), will get correct result: "2030-01-01 00:00:00"

spencermountain commented 3 years ago

yikes! will add this to the next release, ideally next week. thank you

spencermountain commented 3 years ago

fixed in v6.16.3 - thank you!