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

What's the difference between zone.parse and zone.offset #246

Closed
zhangchiqing opened this issue Aug 28, 2015 · 4 comments
Closed

What's the difference between zone.parse and zone.offset #246

zhangchiqing opened this issue Aug 28, 2015 · 4 comments

Comments

@zhangchiqing
Copy link

According to the document, both zone.parse and zone.offset accept a timestamp and return the offset. Why zone.parse and zone.offset print different offset result? What's the difference between them?

var zone = moment.tz.zone('America/New_York')
zone.parse(Date.UTC(2015, 10, 1, 4, 30, 0)); // => 300
zone.offset(Date.UTC(2015, 10, 1, 4, 30, 0)); // => 240
@mattjohnsonpint
Copy link
Contributor

I agree the documentation isn't very clear. The difference is that zone.offset takes a true UTC-based timestamp, while zone.parse takes an timestamp that is based on that particular time zone.

In other words, even though Date.UTC returns the number of milliseconds since 1970-01-01T00:00:00Z, the zone.parse function treats it as if it were the number of milliseconds since either 1970-01-01T00:00:00-05:00 or 1970-01-01T00:00:00-04:00 (for the America/New_York zone), depending on which is in effect for the given timestamp. If the time could exist in both offsets (or can't exist in either), then the rules detailed in Parsing Ambiguities are followed.

@mattjohnsonpint
Copy link
Contributor

IMHO, zone.parse doesn't have many external use cases. I would have expected it to be an internal function, not exposed through the public API.

@mattjohnsonpint
Copy link
Contributor

Also, note that the ambiguous parsing behavior has changed with #101 - and the docs have not yet been updated.

@zhangchiqing
Copy link
Author

Cool! Thanks @mj1856 for the explanation :)

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

No branches or pull requests

2 participants