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

moment.local() fails to clear the timezone #738

Closed
jorroll opened this issue Mar 29, 2019 · 4 comments
Closed

moment.local() fails to clear the timezone #738

jorroll opened this issue Mar 29, 2019 · 4 comments
Assignees
Labels

Comments

@jorroll
Copy link

jorroll commented Mar 29, 2019

Similar to issue #86, a call to momentDate.local() fails to clear the timezone associated with momentDate.tz().

At the, ahem, moment, the only (supported) way I've found to clear the timezone is to use both momentdate.utc() and momentDate.local(). The first call clears the timezone and the second sets the moment to local time. I.e. momentDate.utc().local()

@mattjohnsonpint
Copy link
Contributor

Agreed that _z should be cleared when .local() is called, but it shouldn't have any effect if it doesn't since local mode functions don't use _z. Can you give an example where it matters?

@jorroll
Copy link
Author

jorroll commented Apr 16, 2019

I'm working from memory at the moment (😄), but I believe that currently, moment-timezone exhibits the following, undesired behavior:

const date = moment.tz('America/Los_Angeles');
date.tz() // => 'America/Los_Angeles'
date.local()
date.tz() // => 'America/Los_Angeles'

The following is what I expected to happen:

const date = moment.tz('America/Los_Angeles');
date.tz() // => 'America/Los_Angeles'
date.local()
date.tz() // => undefined

Specifically, once set, there is no straightforward way of clearing a moment's timezone info and resetting it to the local timezone.

I also tried date.tz(undefined) and date.tz(null). I found that date.tz('local') did work to clear the timezone, but it is most definitely a hack. It appears that, whenever you pass an invalid timezone to moment#tz(), the timezone info is cleared and an warning is logged to the console. Since "local" is an invalid timezone, it clears the timezone but also logs an error. momentDate.utc().local() is a better solution at the moment.

@mattjohnsonpint
Copy link
Contributor

Agreed. Also, the same is true when setting the offset explicitly with .utcOffset(offset).

Will fix shortly.

@jorroll
Copy link
Author

jorroll commented Apr 18, 2019

Thanks!!!

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

2 participants