std.time.coerce

coerce-instant

(coerce-instant value {:keys [type], :as opts})

coerce-instant for java.time datastructures (coerce-instant 0 {:type Long :timezone “GMT”}) => 0

(-> (coerce-instant 0 {:type ZonedDateTime :timezone “GMT”}) (map/to-map {} common/+default-keys+)) => {:type ZonedDateTime :timezone “GMT”, :long 0, :year 1970, :month 1, :day 1, :hour 0, :minute 0, :second 0 :millisecond 0}

(-> (time/-from-long 0 {:type ZonedDateTime :timezone “GMT”}) (coerce-instant {:type Clock :timezone “Asia/Kolkata”}) (map/to-map {} common/+default-keys+)) => {:type java.time.Clock$FixedClock, :timezone “Asia/Kolkata”, :long 0, :year 1970, :month 1, :day 1, :hour 5, :minute 30, :second 0 :millisecond 0}

(-> (time/-from-long 0 {:type Clock :timezone “GMT”}) (coerce-instant {:type Calendar :timezone “Asia/Kolkata”}) (map/to-map {} common/+default-keys+)) => {:type java.util.GregorianCalendar :timezone “Asia/Kolkata”, :long 0, :year 1970, :month 1, :day 1, :hour 5, :minute 30, :second 0 :millisecond 0}

coerce-zone

added in 3.0

(coerce-zone value {:keys [type], :as opts})

coercion of one zone object to another (-> (coerce-zone “Asia/Kolkata” {:type TimeZone}) (string/-to-string)) => “Asia/Kolkata”

(-> (coerce-zone nil {:type TimeZone}) (string/-to-string)) => (-> (TimeZone/getDefault) (string/-to-string))