Skip to content

Commit

Permalink
Merge pull request #280 from katox/timestamp-frac-precision
Browse files Browse the repository at this point in the history
Timestamp frac precision
  • Loading branch information
Miikka Koskinen authored Oct 14, 2020
2 parents d3f9605 + 1044dc5 commit 838b699
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/malli/transform.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,16 @@
#?(:clj
(def ^DateTimeFormatter +string->date-format+
(-> (DateTimeFormatterBuilder.)
(.appendPattern "yyyy-MM-dd['T'HH:mm:ss[.SSS][XXXX][XXXXX]]")
(.appendPattern "yyyy-MM-dd['T'HH:mm:ss]")
(.optionalStart)
(.appendFraction ChronoField/MICRO_OF_SECOND, 0, 9, true)
(.optionalEnd)
(.optionalStart)
(.appendOffset "+HHMMss", "Z")
(.optionalEnd)
(.optionalStart)
(.appendOffset "+HH:MM:ss", "Z")
(.optionalEnd)
(.parseDefaulting ChronoField/HOUR_OF_DAY 0)
(.parseDefaulting ChronoField/OFFSET_SECONDS 0)
(.toFormatter))))
Expand Down
11 changes: 11 additions & 0 deletions test/malli/transform_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,21 @@

(deftest string->date
(is (= #inst "2018-04-27T18:25:37Z" (mt/-string->date "2018-04-27T18:25:37Z")))
(is (= #inst "2018-04-27T18:25:37.100Z" (mt/-string->date "2018-04-27T18:25:37.1Z")))
(is (= #inst "2018-04-27T18:25:37.123Z" (mt/-string->date "2018-04-27T18:25:37.123Z")))
(is (= #inst "2018-04-27T18:25:37.123Z" (mt/-string->date "2018-04-27T18:25:37.123456Z")))
(is (= #inst "2018-04-27T18:25:37.123456Z" (mt/-string->date "2018-04-27T18:25:37.123456Z")))
(is (= #inst "2018-04-27T00:00:00Z" (mt/-string->date "2018-04-27")))
(is (= #inst "2018-04-27T05:00:00Z" (mt/-string->date "2018-04-27T08:00:00+03:00")))
(is (= #inst "2018-04-27T18:25:37Z" (mt/-string->date "2018-04-27T18:25:37.000Z")))
(is (= #inst "2018-04-27T18:25:37Z" (mt/-string->date "2018-04-27T18:25:37.000+0000")))
(is (= #inst "2018-04-27T18:25:37.100Z" (mt/-string->date "2018-04-27T18:25:37.1+0000")))
(is (= #inst "2018-04-27T18:25:37.123Z" (mt/-string->date "2018-04-27T18:25:37.123+0000")))
(is (= #inst "2018-04-27T18:25:37.123Z" (mt/-string->date "2018-04-27T18:25:37.123456+0000")))
(is (= #inst "2018-04-27T18:25:37.123456Z" (mt/-string->date "2018-04-27T18:25:37.123456+0000")))
(is (= #inst "2018-04-27T18:25:37.123Z" (mt/-string->date "2018-04-27T18:25:37.123+0000")))
(is (= #inst "2018-04-27T18:25:37.123Z" (mt/-string->date "2018-04-27T20:25:37.123+0200")))
(is (= #inst "2018-04-27T18:25:37.123Z" (mt/-string->date "2018-04-27T16:25:37.123-0200")))
(is (= #inst "2014-02-18T18:25:37Z" (mt/-string->date #inst "2014-02-18T18:25:37Z")))
(is (= #inst "2018-04-27T00:00:00Z" (mt/-string->date #inst "2018-04-27")))
(is (= #inst "2018-04-27T05:00:00Z" (mt/-string->date #inst "2018-04-27T08:00:00+03:00")))
Expand Down

0 comments on commit 838b699

Please sign in to comment.