Time-related Utility Functions
This namespace contains some utility functions for working with objects
related to time; it is mostly based off of the Period class from
Java's JodaTime library.
Time-related Utility Functions This namespace contains some utility functions for working with objects related to time; it is mostly based off of the `Period` class from Java's JodaTime library.
(attempt-date-time-parse formatter timestamp-str)Inputs: [formatter :- DateTimeFormatter timestamp-str :- String]
Parses timestamp-str using formatter. Returns nil if an
Exception is thrown, otherwise the parsed DateTime object
Inputs: [formatter :- DateTimeFormatter timestamp-str :- String] Parses `timestamp-str` using `formatter`. Returns nil if an Exception is thrown, otherwise the parsed DateTime object
A formatter that converts Day Period objects to strings formatted as, e.g.,
'2 days'.
A formatter that converts Day `Period` objects to strings formatted as, e.g., '2 days'.
A parser that matches strings ending with d and returns a Period of days
A parser that matches strings ending with `d` and returns a `Period` of days
(ephemeral-now-ns)Returns the current time as signed integer nanoseconds with respect to some ephemeral time line. Values are only comparable within the same process, and the range of values may be limited, but differences between successive calls within no more than 250 years of each other will be correct.
Returns the current time as *signed* integer nanoseconds with respect to some ephemeral time line. Values are only comparable within the same process, and the range of values may be limited, but differences between successive calls within no more than 250 years of each other will be correct.
(format-period p)Convert a Period object into a human-readable String; e.g.:
`(format-period (clj-time.core/seconds 120))`
returns '2 minutes'. The Period will only be normalized to
the largest round unit; e.g., a Period of 121 seconds will
not be normalized to minutes.
Convert a `Period` object into a human-readable String; e.g.:
`(format-period (clj-time.core/seconds 120))`
returns '2 minutes'. The `Period` will only be normalized to
the largest round unit; e.g., a `Period` of 121 seconds will
not be normalized to minutes.A formatter that converts Hour Period objects to strings formatted as,
e.g., '2 hours'.
A formatter that converts Hour `Period` objects to strings formatted as, e.g., '2 hours'.
A parser that matches strings ending with h and returns a Period of hours
A parser that matches strings ending with `h` and returns a `Period` of hours
(joda-datetime->java-zoneddatetime date)Convert a org.joda.time.DateTime object to a java.time.ZonedDateTime
Convert a org.joda.time.DateTime object to a java.time.ZonedDateTime
A formatter that converts Period objects to strings formatted as, e.g.,
'2 milliseconds'.
A formatter that converts `Period` objects to strings formatted as, e.g., '2 milliseconds'.
A parser that matches strings ending with ms and returns a Period of
milliseconds
A parser that matches strings ending with `ms` and returns a `Period` of milliseconds
A formatter that converts Minute Period objects to strings formatted as,
e.g., '2 minutes'.
A formatter that converts Minute `Period` objects to strings formatted as, e.g., '2 minutes'.
A parser that matches strings ending with m and returns a Period of minutes
A parser that matches strings ending with `m` and returns a `Period` of minutes
Like clj-time.format/formatters but ordered with the more likely successful formats first
Like clj-time.format/formatters but ordered with the more likely successful formats first
(parse-iso-z s)Returns a pdb instant (UTC timestamp) if s represents an ISO formatted timestamp like "2011-12-03T10:15:30Z" or nil.
Returns a pdb instant (UTC timestamp) if s represents an ISO formatted timestamp like "2011-12-03T10:15:30Z" or nil.
Returns a pdb instant (UTC timestamp) if s represents an ISO formatted timestamp with offset like "2011-12-03T10:15:30+01:00" or nil.
Returns a pdb instant (UTC timestamp) if s represents an ISO formatted timestamp with offset like "2011-12-03T10:15:30+01:00" or nil.
(parse-period s)Parse a String into an instance of Period, representing a duration of time.
For example, (parse-period "2d") returns a Period representing a duration
of 2 days. Currently supported suffixes are 'd', 'h', 'm', 's', and
'ms'.
Parse a String into an instance of `Period`, representing a duration of time. For example, `(parse-period "2d")` returns a `Period` representing a duration of 2 days. Currently supported suffixes are `'d'`, `'h'`, `'m'`, `'s'`, and `'ms'`.
(parse-wire-datetime s)Parses s as a PuppetDB wire format <datetime> and returns a LocalDate, or nil if the string cannot be parsed.
Parses s as a PuppetDB wire format <datetime> and returns a LocalDate, or nil if the string cannot be parsed.
A formatter that converts Period objects to human-readable strings.
A formatter that converts `Period` objects to human-readable strings.
(period-longer? p1 p2)Given two instances of period, return true if the first Period is longer than then second. Uses .toStandardDuration so it will not be affected by daylight savings time, etc
Given two instances of period, return true if the first Period is longer than then second. Uses .toStandardDuration so it will not be affected by daylight savings time, etc
A parser that matches strings ending with d, h, m, s, or ms and
returns a Period object representing the specified amount of time.
A parser that matches strings ending with `d`, `h`, `m`, `s`, or `ms` and returns a `Period` object representing the specified amount of time.
(period? p)Returns true if p is a ReadablePeriod instance, false otherwise.
Returns true if `p` is a ReadablePeriod instance, false otherwise.
(periods-equal? _p)(periods-equal? p1 p2)(periods-equal? p1 p2 & more)Given two or more instances of Period, returns true if they all represent
the same duration of time (regardless of whether or not they are specified in
the same units of time... in other words, the following will return true:
`(periods-equal? (days 2) (hours 48))`
even though this will return false:
`(= (days 2) (hours 48))`
Given two or more instances of `Period`, returns true if they all represent
the same duration of time (regardless of whether or not they are specified in
the same units of time... in other words, the following will return `true`:
`(periods-equal? (days 2) (hours 48))`
even though this will return `false`:
`(= (days 2) (hours 48))`A formatter that converts Second Period objects to strings formatted as,
e.g., '2 seconds'.
A formatter that converts Second `Period` objects to strings formatted as, e.g., '2 seconds'.
A parser that matches strings ending with s and returns a Period of seconds
A parser that matches strings ending with `s` and returns a `Period` of seconds
Given an instance of Period, return an integer representing the number of days
Given an instance of `Period`, return an integer representing the number of days
Given an instance of Period, return an integer representing the number of hours
Given an instance of `Period`, return an integer representing the number of hours
Given an instance of Period, return an integer representing the number of milliseconds
Given an instance of `Period`, return an integer representing the number of milliseconds
Given an instance of Period, return an integer representing the number of minutes
Given an instance of `Period`, return an integer representing the number of minutes
Given an instance of Period, return an integer representing the number of seconds
Given an instance of `Period`, return an integer representing the number of seconds
(to-timestamp ts)Inputs: [ts] Returns: (s/maybe java.sql.Timestamp)
Delegates to clj-time's to-timestamp, except when ts is a
String. When a String, this function will attempt to convert it
using a more likely correct date format first (which is faster than
to-timestamp's more naive approach)
Inputs: [ts] Returns: (s/maybe java.sql.Timestamp) Delegates to clj-time's to-timestamp, except when `ts` is a String. When a String, this function will attempt to convert it using a more likely correct date format first (which is faster than to-timestamp's more naive approach)
(to-java-date x)Converts x to a java.util.Date.
Converts x to a java.util.Date.
(wire-datetime->instant s)Parses s as a PuppetDB wire format <datetime> and returns a LocalDate, or nil if the string cannot be parsed.
Parses s as a PuppetDB wire format <datetime> and returns a LocalDate, or nil if the string cannot be parsed.
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 |