Liking cljdoc? Tell your friends :D

std.time.coerce


coerce-instantclj

(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-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}
raw docstring

coerce-zoneclj

(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))

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))
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close