Liking cljdoc? Tell your friends :D

d-core.libs.time


after?clj

(after? a b)

Returns true if instant a is after instant b.

Returns true if instant a is after instant b.
raw docstring

before?clj

(before? a b)

Returns true if instant a is before instant b.

Returns true if instant a is before instant b.
raw docstring

between?clj

(between? instant start end)

Returns true if instant is within [start, end] inclusive.

Returns true if instant is within [start, end] inclusive.
raw docstring

bucketclj

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

compare-instantsclj

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

durationclj

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

duration->mapclj

(duration->map d)

Converts a Duration to a map with a :millis key.

Converts a Duration to a map with a :millis key.
raw docstring

format-durationclj

(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"`.
raw docstring

format-instantclj

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

instant->mapclj

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

instant-map?clj

(instant-map? value)

Returns true if the value looks like an instant map.

Supported shapes:

  • {:epoch-ms <long>}
  • {:epoch-second <long> :nano <int>}
Returns true if the value looks like an instant map.

Supported shapes:
- {:epoch-ms <long>}
- {:epoch-second <long> :nano <int>}
raw docstring

instant=clj

(instant= a b)

Returns true if both instants represent the same moment.

Returns true if both instants represent the same moment.
raw docstring

instant?clj

(instant? value)

Returns true if the value is a java.time.Instant.

Returns true if the value is a java.time.Instant.
raw docstring

map->instantclj

(map->instant m)

Converts a time map into an Instant.

Converts a time map into an Instant.
raw docstring

minusclj

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

nano-span->msclj

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

nano-span->secondsclj

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

new-clockclj

(new-clock)
(new-clock {:keys [type zone instant clock offset tick] :or {type :system}})

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

nowclj

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

now-mapclj

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

parse-durationclj

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

parse-duration!clj

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

parse-instantclj

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

parse-instant!clj

(parse-instant! value)

Throwing variant of parse-instant.

Throwing variant of `parse-instant`.
raw docstring

parse-instant-safeclj

(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->`.
raw docstring

plusclj

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

sinceclj

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

truncateclj

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

windowclj

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

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close