diff --git a/src/malli/transform.cljc b/src/malli/transform.cljc index f13075e1b..b35d4f013 100644 --- a/src/malli/transform.cljc +++ b/src/malli/transform.cljc @@ -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)))) diff --git a/test/malli/transform_test.cljc b/test/malli/transform_test.cljc index 50fb81455..b22365532 100644 --- a/test/malli/transform_test.cljc +++ b/test/malli/transform_test.cljc @@ -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")))