andrewmcveigh / cljs-time

A clj-time inspired date library for clojurescript.
342 stars 57 forks source link

Parsing "2014-04-01T14:57:00+01:00" using :date-time-no-ms returns nil #3

Closed annapawlicka closed 10 years ago

annapawlicka commented 10 years ago

I'm executing this line:

(tf/parse (ft/formatter "yyyy-MM-dd'T'HH:mm:ssZZ") "2014-04-01T14:57:00+01:00")

or

(tf/parse (ft/formatters :date-time-no-ms) "2014-04-01T14:57:00+01:00")

and both cases return nil and throw no exceptions. I'm using cljs-time 0.1.3 and clojurescript 0.0-2173. Is this a bug? The same thing works fine in clj-time:

user> (tf/parse (tf/formatter "yyyy-MM-dd'T'HH:mm:ssZZ") "2014-04-01T14:57:00+01:00") #<DateTime 2014-04-01T13:57:00.000Z>

andrewmcveigh commented 10 years ago

This is partly a bug, and partly javascript's poor support for timezones.

I've got a fix (see d57c2d6) that will at least parse the string into the correct UTC time, but timezone information cannot be kept with the goog.date library I'm using as a backing, unfortunately.

Would you consider that enough of a fix?

I've been considering adding timezone support, but not got there yet.

annapawlicka commented 10 years ago

UTC time zone is better than nothing :+1: It would also be useful if you could update :date-time-no-ms formatter (e.g. add a comment) so that it's clear that it timezone information won't be kept.

Thanks for looking into this that quickly!

andrewmcveigh commented 10 years ago

OK, I'll put some info in #'cljs-time.format/formatters doc-string I think. This doesn't just concern the :date-time-no-ms formatter, but all formatters with a tz parser.

Thanks for drawing my attention to this, I've noticed that there's a couple of errors in this area that the tests don't catch.

This specific issue should be fixed in the latest snapshot (0.1.4-SNAPSHOT) as of last night.

No problem!

annapawlicka commented 10 years ago

Thanks!