(after? a b)Returns true if instant a is after instant b.
Returns true if instant a is after instant b.
(before? a b)Returns true if instant a is before instant b.
Returns true if instant a is before instant b.
(between? instant start end)Returns true if instant is within [start, end] inclusive.
Returns true if instant is within [start, end] inclusive.
(bucket inst width)Floors an instant to an arbitrary-width boundary, measured from the epoch.
Epoch arithmetic rather than ChronoUnit/truncatedTo, which cannot express
widths like 5 or 7 minutes:
(bucket inst (duration 5 :minutes)) ;; => Instant floored to a 5-minute boundary
Floors an instant to an arbitrary-width boundary, measured from the epoch. Epoch arithmetic rather than `ChronoUnit/truncatedTo`, which cannot express widths like 5 or 7 minutes: ```clojure (bucket inst (duration 5 :minutes)) ;; => Instant floored to a 5-minute boundary ```
(compare-instants a b)Compares two instants (or maps/epoch values). Returns -1, 0, or 1.
Compares two instants (or maps/epoch values). Returns -1, 0, or 1.
(duration value)(duration amount unit)Creates a Duration. Accepts a map like {:seconds 1 :millis 250}, a Duration instance, or an amount + unit.
Creates a Duration. Accepts a map like {:seconds 1 :millis 250},
a Duration instance, or an amount + unit.(duration->map d)Converts a Duration to a map with a :millis key.
Converts a Duration to a map with a :millis key.
(format-duration d)Formats a Duration as a compact literal, the inverse of parse-duration.
(format-duration (Duration/ofMinutes 90)) ;; => "1h30m"
(format-duration (Duration/ofMillis 500)) ;; => "500ms"
Units are emitted largest-first, skipping zero components; a whole zero
duration is "0s".
Formats a `Duration` as a compact literal, the inverse of `parse-duration`. ```clojure (format-duration (Duration/ofMinutes 90)) ;; => "1h30m" (format-duration (Duration/ofMillis 500)) ;; => "500ms" ``` Units are emitted largest-first, skipping zero components; a whole zero duration is `"0s"`.
(format-instant inst)Formats an instant as ISO-8601 UTC, preserving sub-second precision.
Formats an instant as ISO-8601 UTC, preserving sub-second precision.
(instant->map inst)(instant->map inst zone)Converts an Instant into a time map.
The map uses {:epoch-ms <long>} and optionally a :zone string.
Converts an Instant into a time map.
The map uses {:epoch-ms <long>} and optionally a :zone string.(instant-map? value)Returns true if the value looks like an instant map.
Supported shapes:
Returns true if the value looks like an instant map.
Supported shapes:
- {:epoch-ms <long>}
- {:epoch-second <long> :nano <int>}(instant= a b)Returns true if both instants represent the same moment.
Returns true if both instants represent the same moment.
(instant? value)Returns true if the value is a java.time.Instant.
Returns true if the value is a java.time.Instant.
(map->instant m)Converts a time map into an Instant.
Converts a time map into an Instant.
(minus value dur)(minus value unit amount)Subtracts a duration from a Clock, Instant, or time map.
Subtracts a duration from a Clock, Instant, or time map.
(nano-span->ms nanos)Converts a nanosecond span (e.g. from System/nanoTime) to milliseconds.
Converts a nanosecond span (e.g. from `System/nanoTime`) to milliseconds.
(nano-span->seconds nanos)Converts a nanosecond span (e.g. from System/nanoTime) to seconds.
Converts a nanosecond span (e.g. from `System/nanoTime`) to seconds.
(new-clock)(new-clock {:keys [type zone instant clock offset tick] :or {type :system}})Creates a java.time.Clock.
Options:
Creates a java.time.Clock.
Options:
- {:type :system :zone "UTC"}
- {:type :fixed :instant <instant|map|epoch-ms> :zone "UTC"}
- {:type :offset :clock <clock|opts> :offset <duration|map>}
- {:type :tick :clock <clock|opts> :tick <duration|map>}(now)(now clock)Returns the current Instant for the provided Clock (or system default).
Returns the current Instant for the provided Clock (or system default).
(now-map)(now-map clock)Returns a time map for now, optionally including the clock zone.
Returns a time map for now, optionally including the clock zone.
(parse-duration value)Parses a human duration literal into a Duration.
(parse-duration "15m") ;; => #object[java.time.Duration "PT15M"]
(parse-duration "2h30m") ;; => 2.5 hours
(parse-duration "nonsense") ;; => {:error :invalid-duration :input "nonsense" :at 0}
(parse-duration 1500) ;; => 1500 millis, matching the platform's epoch-ms habit
Total by design: invalid input returns an error map rather than throwing, so an
ingest path can skip a poison config value. Use parse-duration! when a
malformed literal is a programming error.
Parses a human duration literal into a `Duration`.
```clojure
(parse-duration "15m") ;; => #object[java.time.Duration "PT15M"]
(parse-duration "2h30m") ;; => 2.5 hours
(parse-duration "nonsense") ;; => {:error :invalid-duration :input "nonsense" :at 0}
(parse-duration 1500) ;; => 1500 millis, matching the platform's epoch-ms habit
```
Total by design: invalid input returns an error map rather than throwing, so an
ingest path can skip a poison config value. Use `parse-duration!` when a
malformed literal is a programming error.(parse-duration! value)Throwing variant of parse-duration for call sites where a bad literal is a bug.
Throwing variant of `parse-duration` for call sites where a bad literal is a bug.
(parse-instant value)Parses an ISO-8601 instant string. Total: returns an error map on failure.
Parses an ISO-8601 instant string. Total: returns an error map on failure.
(parse-instant! value)Throwing variant of parse-instant.
Throwing variant of `parse-instant`.
(parse-instant-safe value)Returns the parsed instant or nil, so it composes with some->.
Returns the parsed instant or nil, so it composes with `some->`.
(plus value dur)(plus value unit amount)Adds a duration to a Clock, Instant, or time map.
When called with a Clock, uses now as the base. When called with a map, returns a map.
Adds a duration to a Clock, Instant, or time map. When called with a Clock, uses now as the base. When called with a map, returns a map.
(since instant)(since clock instant)Returns a Duration between an instant (or map) and now.
Returns a Duration between an instant (or map) and now.
(truncate inst unit)(truncate inst unit opts)Floors an instant to the start of the containing unit.
(truncate inst :minute) ;; => Instant floored to the minute (UTC)
(truncate inst :day {:zone "America/Sao_Paulo"}) ;; => start of that local day, as a UTC Instant
Returns an Instant (UTC) in every case: the zone parameter only decides where
the local day boundary falls. Defaults to UTC, never the JVM default zone.
Floors an instant to the start of the containing unit.
```clojure
(truncate inst :minute) ;; => Instant floored to the minute (UTC)
(truncate inst :day {:zone "America/Sao_Paulo"}) ;; => start of that local day, as a UTC Instant
```
Returns an `Instant` (UTC) in every case: the zone parameter only decides where
the local day boundary falls. Defaults to UTC, never the JVM default zone.(window inst unit)(window inst unit opts)Returns the half-open [start, end) window containing an instant.
(window inst :hour) ;; => {:start .. :end ..}
(window inst :day {:zone "America/New_York"}) ;; a DST day is 23 or 25 hours
Both bounds are UTC Instants. A zone only positions the boundary, so a day
window across a DST transition is correctly 23 or 25 hours long rather than a
naive 24.
Returns the half-open `[start, end)` window containing an instant.
```clojure
(window inst :hour) ;; => {:start .. :end ..}
(window inst :day {:zone "America/New_York"}) ;; a DST day is 23 or 25 hours
```
Both bounds are UTC `Instant`s. A zone only positions the boundary, so a day
window across a DST transition is correctly 23 or 25 hours long rather than a
naive 24.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 |