marnusw / date-fns-tz

Complementary library for date-fns v2 adding IANA time zone support
MIT License
1.07k stars 116 forks source link

Etc/UTC Zone is not parsed correctly #30

Open VladimirMilenko opened 4 years ago

VladimirMilenko commented 4 years ago

When trying to call dateFnsTz.toDate("2019-11-20T22:59Z[Etc/UTC]") we get an exception:

RangeError: Expected Area/Location(/Location)* for time zone, got Z[Etc/U

However, Etc/UTC is a valid IANA zone

marnusw commented 4 years ago

This is due to a failing RegEx match, not verifying the time zone value itself. I'm pretty sure, at least as far as I can recall, that "2019-11-20T22:59Z Etc/UTC" should work fine. (The time zone is redundant here, since the Z is sufficient to indicate UTC time. I'm assuming you might also provide different time zones; if that's not the case just omit it.) It looks like the RegEx in question is including Z[ in the value under consideration and then fails.

I'm not sure when I would get around to looking into this, so if you can sort this out with tests in a PR in the meantime I'd be happy to review and merge if it's worth your while.