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

ISO-8601 parsing doesn't work with named timezones #804

Closed
frabcus opened this issue May 25, 2013 · 4 comments
Closed

ISO-8601 parsing doesn't work with named timezones #804

frabcus opened this issue May 25, 2013 · 4 comments
Labels

Comments

@frabcus
Copy link

frabcus commented May 25, 2013

If I parse an ISO-8601 with a three letter timezone at the end, it comes out as invalid.

Curiously, if I call Date.parse then it works fine, which points to it being a bug in the extra browser-compatible ISO-8601 parser in moment.

> moment("2013-04-23 15:23:47 UTC").isValid()
false
> moment(Date.parse("2013-04-23 15:23:47 UTC")).isValid()
true
> moment("2013-04-23 15:23:47 UTC")
D {_i: "2013-04-23 15:23:47 UTC", _f: "YYYY-MM-DDTHH:mm:ss", _l: undefined, _isUTC: false, _a: Array[7]}
> moment(Date.parse("2013-04-23 15:23:47 UTC"))
D {_i: 1366730627000, _f: undefined, _l: undefined, _isUTC: false, _d: Tue Apr 23 2013 16:23:47 GMT+0100 (BST)}
@ichernev
Copy link
Contributor

look at #162. Basically there is no reliable way to get time zone abbreviations. So there is no way we can parse them. I guess detecting them and passing them to the browser makes sense, but that won't work everywhere, for the same reason getting the zone abbr doesn't work.

@timrwood
Copy link
Member

Hmm, it does look like a bug in the auto iso8601 parser.

moment("2013-04-23 15:23:47 UTC"); // this is equivalent to the following
moment("2013-04-23 15:23:47 UTC", "YYYY-MM-DDTHH:mm:ss");

Because the parser is finding the T in the zone at the end of the string instead of in between the DD and HH tokens, it is trimming off the 15:23:47 U part to get to the T. Then, because there is no data for the HH, mm, or ss, the parser is marking the date as invalid.

This is something I'll definitely add tests against.

Out of curiosity, where are you getting the input that contains the UTC at the end of the string? As far as I know, ISO 8601 only allows for "Z" or +-HH:mm timezone designations, not "UTC".

@frabcus
Copy link
Author

frabcus commented May 29, 2013

Thanks!

Sorry, I've completely forgotten which of my datasets it was that had
that form of time in it :(

On Tue, May 28, 2013 at 05:46:02PM -0700, Tim Wood wrote:

Hmm, it does look like a bug in the auto iso8601 parser.

moment("2013-04-23 15:23:47 UTC"); // this is equivalent to the following
moment("2013-04-23 15:23:47 UTC", "YYYY-MM-DDTHH:mm:ss");

Because the parser is finding the T in the zone at the end of the string instead of in between the DD and HH tokens, it is trimming off the 15:23:47 U part to get to the T. Then, because there is no data for the HH, mm, or ss, the parser is marking the date as invalid.

This is something I'll definitely add tests against.

Out of curiosity, where are you getting the input that contains the UTC at the end of the string? As far as I know, ISO 8601 only allows for "Z" or +-HH:mm timezone designations, not "UTC".


Reply to this email directly or view it on GitHub:
#804 (comment)

@timrwood
Copy link
Member

timrwood commented Jun 3, 2013

The commit above solves this problem by not adding a 'T' in the format string if there is not one in the input string. I added your specific use case as a unit test as well.

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

3 participants