moment / moment-timezone

Timezone support for moment.js
momentjs.com/timezone
MIT License
3.83k stars 838 forks source link

Minutes or smaller setters don't account for fall-back transitions #405

Open leo108 opened 8 years ago

leo108 commented 8 years ago

Here is my code:

moment.tz.setDefault('America/Los_Angeles');
var date = moment('2016-11-06'); // the PDT to PST day
console.log(date.clone().seconds(36000).format()); // 2016-11-06T09:00:00-08:00
console.log(date.clone().hours(10).format()); // 2016-11-06T10:00:00-08:00

Is that designed as that or a bug ?

mattjohnsonpint commented 8 years ago

Confirmed:

var dt = '2016-11-06';
var z = 'America/Los_Angeles';
moment.tz(dt, z).hours(10).format()               // "2016-11-06T10:00:00-08:00"  (ok)
moment.tz(dt, z).minutes(600).format()            // "2016-11-06T09:00:00-08:00"  (bad)
moment.tz(dt, z).seconds(36000).format()          // "2016-11-06T09:00:00-08:00"  (bad)
moment.tz(dt, z).milliseconds(36000000).format()  // "2016-11-06T09:00:00-08:00"  (bad)

Without moment-timezone, and with local time set to Pacific, it works as expected:

var dt = '2016-11-06';
moment(dt).hours(10).format()               // "2016-11-06T10:00:00-08:00"  (ok)
moment(dt).minutes(600).format()            // "2016-11-06T10:00:00-08:00"  (ok)
moment(dt).seconds(36000).format()          // "2016-11-06T10:00:00-08:00"  (ok)
moment(dt).milliseconds(36000000).format()  // "2016-11-06T10:00:00-08:00"  (ok)