moment-timezone
moment-timezone copied to clipboard
Behaviour of moment().local() after moment.tz.setDefault()
I think this is a bug in moment.js, but before I post there I wanted to get your opinion on it.
After setting the default timezone, subsequent calls to moment() create moment objects in that timezone, whereas the behaviour before that is that moment() creates objects in whichever local timezone. Shouldn't it then follow that after setting a default timezone, subsequent calls to moment().local() should convert an object to the default timezone and NOT the local timezone?
Currently, this happens:
moment.tz.setDefault('America/Los_Angeles');
moment().tz(); // 'America/Los_Angeles'
moment().local().tz(); // 'America/Los_Angeles'
moment.utc().local().tz(); // undefined. Also, this converts the moment to the local timezone and not 'America/Los_Angeles'
Currently, the expected behavior is that local() should always set back to the local time zone, not necessarily to the "default" time zone. See #247.
There is a bug here though. I would expect moment().local().tz() to always return undefined. It would appear that local() doesn't do anything unless the moment is in UTC.
See setOffsetToLocal line 149.
If indeed "local" is defined as "local to the machine", and not "the default time zone which happens to be local when not explicitly set", then calling .local() should always clear any time zone. This would also address #239.
@timrwood - thoughts?
Just a cool little addition to this - I think it's basically the same issue.
moment.tz('2016-05-03T22:15:01+02:00', 'Europe/Berlin').local().format()
"2016-05-03T15:15:01-05:00"
moment.tz('2016-05-03T22:15:01+02:00', 'Europe/Berlin').local().add(6, 'months').format()
"2016-11-03T15:15:01+01:00"
Timezone appears to clear, but the minute you mutate the moment and UpdateOffset runs, back to the original timezone.
I believe this will be addressed if moment/moment-rfcs#1 is adopted.
How would one get back to the "default" timezone from a utc one? if we cannot use
moment.utc(...).local()
Do we have a ??
moment.utc(...).default()