moment-round
moment-round copied to clipboard
Incrementing by 5 minutes and rounding to 5 minute interval over a daylight savings time change fails to increment the hour correctly.
Yeah, it's a weird one.
Here's code to reproduce:
const start = moment.tz('2017-11-01T01:00:00', 'America/Chicago');
const end = moment.tz('2017-11-10T00:55:00', 'America/Chicago');
while (start.isBefore(end)) {
start.add(5, 'minutes')
.round(5, 'minutes');
this.logger.info(start.format());
}
This will behave as expected, at first:
info: 2017-11-01T01:05:00-05:00
info: 2017-11-01T01:10:00-05:00
info: 2017-11-01T01:15:00-05:00
info: 2017-11-01T01:20:00-05:00
info: 2017-11-01T01:25:00-05:00
info: 2017-11-01T01:30:00-05:00
info: 2017-11-01T01:35:00-05:00
Until Nov. 5 at 13:00 UTC:
info: 2017-11-05T07:00:00-06:00
info: 2017-11-05T07:05:00-06:00
info: 2017-11-05T07:10:00-06:00
info: 2017-11-05T07:15:00-06:00
info: 2017-11-05T07:20:00-06:00
info: 2017-11-05T07:25:00-06:00
info: 2017-11-05T07:30:00-06:00
info: 2017-11-05T07:35:00-06:00
info: 2017-11-05T07:40:00-06:00
info: 2017-11-05T07:45:00-06:00
info: 2017-11-05T07:50:00-06:00
info: 2017-11-05T07:55:00-06:00
info: 2017-11-05T07:00:00-06:00 <------- we've looped back to 07:00
info: 2017-11-05T07:05:00-06:00
info: 2017-11-05T07:10:00-06:00
info: 2017-11-05T07:15:00-06:00
info: 2017-11-05T07:20:00-06:00
info: 2017-11-05T07:25:00-06:00
Works as expected if I drop the round(5, 'minutes')
call from inside of the while
loop above.