Open henriklundahl opened 9 years ago
Thanks for the report!
This is actually not implemented yet, due to JS having very limited timezone support. I think I have a solution though.
OK, I see. I got this to work for converting from JS Date to textual representation in local time:
(unparse (formatter "yyyy-MM-dd HH:mm") (to-default-time-zone dt))
And the other way around:
(js/Date. (.getTime (to-local-date-time
(parse (formatter "yyyy-MM-dd HH:mm")
dt-text))))
I have just run into this issue and tried to solve it by cljc reader conditionals:
(def formatter-ddMMyyyyHHmm (time-format/formatter "dd.MM.yyyy HH:mm" #?(:clj (time/default-time-zone))))
(defn datetime-to-str [date]
(if (nil? date)
""
(->> date
from-date
#?(:cljs time/to-default-time-zone)
(time-format/unparse formatter-ddMMyyyyHHmm))))
(defn str-to-datetime [str]
(when-not (string/blank? str)
(->> str
(time-format/parse formatter-ddMMyyyyHHmm)
#?(:cljs time/from-default-time-zone)
to-date)))
Unfortunately it stops to work on the clojurescript side when compiled in advanced mode (in dev and simple works fine).
Supplying a time zone to a formatter makes no difference when formatting:
Same thing when parsing.