Set of functions helpful for working with time.
Add [district0x/district-time "1.0.1"] into your project.clj
Include [district.time] in your CLJS file
time-units [milis]Divides given miliseconds into seconds, minutes, hours, days.
(time/time-units 400000000)
;; => {:seconds 40 :minutes 6 :hours 15 :days 4}
biggest-time-unit [{:keys [:seconds :minutes :hours :days]}]Returns biggest positive time unit from given parameters.
(time/biggest-time-unit (time/time-units 400000000))
;; => [:days 4]
time-remaining [from-time to-time]Time remaining from from-time to to-time. Passed times are from cljs-time format.
(time/time-remaining (t/now) (t/plus (t/now) (t/hours 3)))
;; => {:seconds 0 :minutes 0 :hours 3 :days 0}
time-remaining-biggest-unit [from-time to-time]Returns biggest time unit from remaining time. Passed times are from cljs-time format.
(time/time-remaining-biggest-unit (t/now) (t/plus (t/now) (t/hours 3)))
;; => [:hours 3]
epoch->long [x]Converts epoch to long time format.
(time/epoch->long 1516314507)
;; => 1516314507000
long->epoch [x]Converts long to epoch time format.
(time/long->epoch 1516314507000)
;; => 1516314507
days->seconds [x]Converts days to seconds.
(time/days->seconds 3)
;; => 259200
seconds->days [x]Converts seconds to days.
(time/seconds->days 345600)
;; => 259200
lein deps
# To run tests and rerun on changes
lein doo chrome tests
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |