Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behaviour of moment().local() after moment.tz.setDefault() #258

Open
joelmukuthu opened this issue Oct 12, 2015 · 3 comments
Open

Behaviour of moment().local() after moment.tz.setDefault() #258

joelmukuthu opened this issue Oct 12, 2015 · 3 comments
Labels

Comments

@joelmukuthu
Copy link

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'
@mattjohnsonpint
Copy link
Contributor

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?

@maggiepint
Copy link
Member

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.

@mattjohnsonpint
Copy link
Contributor

I believe this will be addressed if moment/moment-rfcs#1 is adopted.

@WORMSS
Copy link

WORMSS commented Oct 14, 2019

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants