andrewmcveigh / cljs-time

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

Unparse ignores ZZ format for localtime #81

Open seryh opened 7 years ago

seryh commented 7 years ago

I use [com.andrewmcveigh/cljs-time "0.5.0-alpha2"]

(let [date-format-custom (formatter "yyyy-MM-dd'T'HH:mm:ss.SSSZZ")]
  (unparse date-format-custom (cljs-time.local/local-now)))
;; => "2016-12-12T13:34:52.992"

ZZ - it was ignored; I expected to see "2016-12-12T13:34:52.992+07:00", how to get the string with time zone?

danielcompton commented 7 years ago

Did this work on previous versions?

seryh commented 7 years ago

Thank you, in the version of "0.4.0" is working:

;;[com.andrewmcveigh/cljs-time "0.4.0"]
(let [format (formatters :date-time)]
  (unparse format (local-date-time (now))))
;; => "2016-12-13T12:10:32.814+07:00"

But I was too deeply embedded in my project version "0.5.0-alpha2" so used the fix:

;; [com.andrewmcveigh/cljs-time "0.5.0-alpha2"]
(let [date (cljs-time.local/local-now)
      date-format (formatters :date-time)
      str-date (as-> date $
                     (unparse date-format $)
                     (str $ (.getTimezoneOffsetString date)))]
  str-date)
;; => "2016-12-13T12:16:22.361+07:00"
binarykitchen commented 7 years ago

experiencing this bug too here with 0.5.0-alpha2

AriPaaWun commented 6 years ago

I'm having a similar issue.

(let [format (cljs-time.format/formatters :date-time-no-ms)]; or "yyyy-MM-dd'T'HH:mm:ssZZ"
  (cljs-time.format/parse-local format "2017-12-20T12:00:00+02:00"))

;;0.4.0
;; => #object[Object 20171220T120000]

;;0.5.2
;; => #object[Object 20171220T100000]
enragedginger commented 6 years ago

I ran into this same issue. I'm not sure what's causing it, but I couldn't find a way around it with cljs-time, so I switched to a different library.