Parsing String + Format doesn't handle timezone #371

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

Comments

Projects
None yet
2 participants

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 added a commit to deepwell/moment that referenced this issue Jul 24, 2012

Added a unit test for this issue.

timrwood added a commit that referenced this issue Jul 25, 2012

Owner

timrwood commented Jul 25, 2012

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!

@timrwood timrwood closed this Jul 25, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment