8000 Parsing String + Format doesn't handle timezone · Issue #371 · moment/moment · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Parsing String + Format doesn't handle timezone #371

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 “S 8000 ign 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

Closed
deepwell opened this issue Jul 24, 2012 · 2 comments
Closed

Parsing String + Format doesn't handle timezone #371

deepwell opened this issue Jul 24, 2012 · 2 comments

Comments

@deepwell
Copy link

This is a regression of Issue #147 in Moment 1.6.0

When parsing a date with a timezone offset "-0700" the offset is not applied.

Example:

var emailHeader = 'Fri, 20 Jul 2012 16:14:09 -0700';
var receivedAt = moment.utc(emailHeader, 'ddd, DD MMM YYYY HH:mm:ss ZZ');
var formatted = receivedAt.format('YYYY-MM-DD HH:mm:ss ZZ');

console.log('input  ' + emailHeader);
console.log('parsed ' + formatted);
console.log('expect 2012-07-20 23:14:09 +0000');

Output in Moment 1.6.0-1.6.2

input  Fri, 20 Jul 2012 16:14:09 -0700
parsed 2012-07-20 16:14:09 +0000
expect 2012-07-20 23:14:09 +0000

Output in Moment 1.5.1

input  Fri, 20 Jul 2012 16:14:09 -0700
parsed 2012-07-20 23:14:09 +0000
expect 2012-07-20 23:14:09 +0000

This was working fine in moment 1.5, but is now broken in moment 1.6

@deepwell
Copy link
Author

Added a unit test for this issue.

timrwood added a commit that referenced this issue Jul 25, 2012
@timrwood
Copy link
Member

So the bug was that when using moment.utc with a string and a format, the parser was adding +0000 to the string and Z to the format. This needs to happen so that the parser parses into utc, however, it shouldnt be added if there is already a timezone in the string.

We already had this check for auto parsing iso8601, so i just moved it up so that string+format gets it as well.

Thanks for catching this @deepwell!

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
0