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

Time zone is neglected when formatting #23

Open
henriklundahl opened this issue Jan 31, 2015 · 3 comments
Open

Time zone is neglected when formatting #23

henriklundahl opened this issue Jan 31, 2015 · 3 comments

Comments

@henriklundahl
Copy link

Supplying a time zone to a formatter makes no difference when formatting:

(unparse (formatter "yyyy-MM-dd HH:mm" (time-zone-for-offset 2)) (date-time 2015))
=> 2015-01-01 00:00
(unparse (formatter "yyyy-MM-dd HH:mm" (time-zone-for-offset -2)) (date-time 2015))
=> 2015-01-01 00:00

Same thing when parsing.

@andrewmcveigh
Copy link
Owner

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.

@henriklundahl
Copy link
Author

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))))

@kajism
Copy link

kajism commented Jan 28, 2016

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants