dm3/clojure.java-time

time shifts forward a year on formatting?

joefromct opened this issue · 1 comments

I think i'm confused on the usage... there is no way this could be a real bug.

I want a function that translates a date in string format from "yyyy-MM-dd'T'HH:mm:ss" format to "MM/dd/YYYY hh:mm:ss a" format.

Here's my function:

(require '[java-time :as jt])

(defn change-ds-format [in-ds]
  {:pre [(string? in-ds  )]
   :post [(string? %  )]}
  (let [input-format "yyyy-MM-dd'T'HH:mm:ss"
        output-format "MM/dd/YYYY hh:mm:ss a"]
    (->> in-ds
         (jt/local-date-time input-format)
         (jt/format output-format))))

I have no idea why this pushed the year to 2020?

(change-ds-format "2019-12-29T00:00:00" )
;=> "12/29/2020 12:00:00 AM"
;; Why is this one 2020 ???

This looks ok:

(change-ds-format "2019-12-28T00:00:00" )
;=> "12/28/2019 12:00:00 AM"

and even this, same day from 2018 stays in the correct year:

(change-ds-format "2018-12-29T00:00:00" )
;=> "12/29/2018 12:00:00 AM"

I thought maybe it was a timezone offset issue but there is no way it should be shifting to the year 2020 I believe...

Opps, I had a typo in my output-format; needs the lowercase yyyy for "era based year" rather than week based year.

        output-format "MM/dd/yyyy hh:mm:ss a"]

https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html