Liking cljdoc? Tell your friends :D

Durations & periods

Construction

CodeDescriptionReturn type
(seconds 1)

Duration of a second

java.time.Duration
(seconds 10)

Duration of 10 seconds

java.time.Duration
(nanos 1200)

Duration of 1200 nanoseconds

java.time.Duration
(days 100)

Duration of 100 days

java.time.Duration
(period 100 :days)

Period of 100 days

java.time.Period
(months 2)

Period of 2 months

java.time.Period

Days, Months, Years…

Instances of other java.time types are readily constructed with tick.

ExampleDescriptionReturn type
(day "mon")

Monday

java.time.DayOfWeek
(month "August")

August

java.time.Month
(month 12)

December

java.time.Month
(year-month "2012-12")

December 2012

java.time.YearMonth
(year 1999)

The year 1999

java.time.Year

Derivation

  • Add durations to durations

Misc

TODO Don’t forget you can create zone-offsets from durations!
TODO Don’t forget you can create instants from durations - this is often needed when you get Unix times (e.g. JWT OAuth2 tokens)

The problem with numeric times is that there are cases where the units are in seconds and cases where milliseconds are used. If tick were to convert numbers to times, it would be a source of confusion and bugs if the units were not clear. For this reason, you cannot convert numbers to times. However, you can first create the duration from the number, specifying the units explicitly, and then convert the duration to an instant (or inst).

(instant (new-duration 1531467976048 :millis))
(inst (new-duration 1531468976 :seconds))

Can you improve this documentation?Edit on GitHub

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

× close