dm3 / clojure.java-time

Java 8 Date-Time API for Clojure
MIT License
471 stars 47 forks source link

Add missing chrono fields (v0.3.3 has breaking changes) #78

Closed liquidz closed 3 years ago

liquidz commented 3 years ago

Problem

The following code returns expected value with v0.3.2 while v0.3.3 throws Exception.

(require '[java-time :as j])
(j/as (j/zoned-date-time) :instant-seconds))

Expected

(j/as (j/zoned-date-time) :instant-seconds)) should return integer.

Actual

Throws the following exception.

java.time.DateTimeException: Property :instant-seconds doesn't exist in [2021-10-27T15:34:44.773+09:00[Asia/Tokyo]]!

How to solve

java-time.properties/chrono-fields does'nt have a field for :instant-seconds, so I added missing fields.

(clojure.set/difference 
 (set (keys (->map (vals (jt.u/get-static-fields-of-type ChronoField TemporalField)))))
 (set (keys (->map chrono-fields))))
;; => #{:aligned-week-of-month :epoch-day :aligned-week-of-year :minute-of-day :clock-hour-of-day :instant-seconds :aligned-day-of-week-in-month :am-pm-of-day :aligned-day-of-week-in-year :clock-hour-of-am-pm :minute-of-hour}
dm3 commented 3 years ago

Looks good. Thanks! Sorry for the delay... It looks like this brings backs the 0.3.2 behaviour.