Utility functions for working with datetimes of different types, and other related tasks.
Utility functions for working with datetimes of different types, and other related tasks.
The timezone of the data being queried. Today this is the same as the database timezone.
The timezone of the data being queried. Today this is the same as the database timezone.
Timezone to be used when formatting timestamps for display or for the data (pre aggregation)
Timezone to be used when formatting timestamps for display or for the data (pre aggregation)
(->iso-8601-datetime this timezone-id-or-nil)
Coerce object to an ISO8601 date-time string such as "2015-11-18T23:55:03.841Z" with a given timezone-id
string (such as '"UTC"'), or nil
, which defaults to "UTC" (?)
Coerce object to an ISO8601 date-time string such as "2015-11-18T23:55:03.841Z" with a given `timezone-id` string (such as '"UTC"'), or `nil`, which defaults to "UTC" (?)
(calculate-duration begin-time end-time)
Inputs: [begin-time :- (s/protocol coerce/ICoerce) end-time :- (s/protocol coerce/ICoerce)] Returns: su/NonNegativeInt
Given two datetimes, caculate the time between them, return the result in millis
Inputs: [begin-time :- (s/protocol coerce/ICoerce) end-time :- (s/protocol coerce/ICoerce)] Returns: su/NonNegativeInt Given two datetimes, caculate the time between them, return the result in millis
(call-with-effective-timezone db f)
Invokes f
with *report-timezone*
and *data-timezone*
bound for the given db
Invokes `f` with `*report-timezone*` and `*data-timezone*` bound for the given `db`
(coerce-to-timestamp this)
(coerce-to-timestamp this timezone-coercible)
Coerce this object to a java.sql.Timestamp
. Strings are parsed as ISO-8601.
Coerce this object to a `java.sql.Timestamp`. Strings are parsed as ISO-8601.
(coerce-to-timezone this)
Coerce this
to java.util.TimeZone
Coerce `this` to `java.util.TimeZone`
(date->iso-8601)
(date->iso-8601 date)
Format date
a an ISO-8601 string.
Format `date` a an ISO-8601 string.
(date-extract unit)
(date-extract unit date)
(date-extract unit date timezone-id)
Extract unit
from date
. date
defaults to now.
(date-extract :year) -> 2015
Extract `unit` from `date`. `date` defaults to now. (date-extract :year) -> 2015
Units which return a (numerical, periodic) component of a date
Units which return a (numerical, periodic) component of a date
(date-string? s)
Is S a valid ISO 8601 date string?
Is S a valid ISO 8601 date string?
(date-trunc unit)
(date-trunc unit date)
(date-trunc unit date timezone-id)
Truncate date
to unit
. date
defaults to now.
(date-trunc :month). ;; -> #inst "2015-11-01T00:00:00"
Truncate `date` to `unit`. `date` defaults to now. (date-trunc :month). ;; -> #inst "2015-11-01T00:00:00"
(date-trunc-or-extract unit)
(date-trunc-or-extract unit date)
(date-trunc-or-extract unit date timezone-id)
Apply date bucketing with unit
to date
. date
defaults to now.
Apply date bucketing with `unit` to `date`. `date` defaults to now.
(format-date date-format)
(format-date date-format date)
Format date
using a given date-format
. NOTE: This will create a date string in the JVM's timezone, not the report
timezone.
date
is anything that can coerced to a Timestamp
via ->Timestamp
, such as a Date
, Timestamp
,
Long
(ms since the epoch), or an ISO-8601 String
. date
defaults to the current moment in time.
date-format
is anything that can be passed to ->DateTimeFormatter
, such as String
(using the usual date format args),
Keyword
, or DateTimeFormatter
.
(format-date "yyyy-MM-dd") -> "2015-11-18" (format-date :year (java.util.Date.)) -> "2015" (format-date :date-time (System/currentTimeMillis)) -> "2015-11-18T23:55:03.841Z"
Format `date` using a given `date-format`. NOTE: This will create a date string in the JVM's timezone, not the report timezone. `date` is anything that can coerced to a `Timestamp` via `->Timestamp`, such as a `Date`, `Timestamp`, `Long` (ms since the epoch), or an ISO-8601 `String`. `date` defaults to the current moment in time. `date-format` is anything that can be passed to `->DateTimeFormatter`, such as `String` (using [the usual date format args](http://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html)), `Keyword`, or `DateTimeFormatter`. (format-date "yyyy-MM-dd") -> "2015-11-18" (format-date :year (java.util.Date.)) -> "2015" (format-date :date-time (System/currentTimeMillis)) -> "2015-11-18T23:55:03.841Z"
(format-microseconds microseconds)
Format a time interval in microseconds into something more readable.
Format a time interval in microseconds into something more readable.
(format-milliseconds milliseconds)
Format a time interval in milliseconds into something more readable.
Format a time interval in milliseconds into something more readable.
(format-nanoseconds nanoseconds)
Format a time interval in nanoseconds to something more readable (µs/ms/etc.)
Useful for logging elapsed time when using (System/nanotime)
Format a time interval in nanoseconds to something more readable (µs/ms/etc.) Useful for logging elapsed time when using `(System/nanotime)`
(format-seconds seconds)
Format a time interval in seconds into something more readable.
Format a time interval in seconds into something more readable.
(format-time t time-zone-id)
Returns a string representation of the time found in t
Returns a string representation of the time found in `t`
(is-temporal? v)
Is VALUE an instance of a datetime class like java.util.Date
or org.joda.time.DateTime
?
Is VALUE an instance of a datetime class like `java.util.Date` or `org.joda.time.DateTime`?
(is-time? v)
Returns true if v
is a Time object
Returns true if `v` is a Time object
(new-sql-timestamp)
java.sql.Date
doesn't have an empty constructor so this is a convenience that lets you make one with the current
date. (Some DBs like Postgres will get snippy if you don't use a java.sql.Timestamp
).
`java.sql.Date` doesn't have an empty constructor so this is a convenience that lets you make one with the current date. (Some DBs like Postgres will get snippy if you don't use a `java.sql.Timestamp`).
(parse-date date-format s)
Parse a datetime string s
with a custom date-format
, which can be a format string, clj-time formatter keyword, or
anything else that can be coerced to a DateTimeFormatter
.
(parse-date "yyyyMMdd" "20160201") -> #inst "2016-02-01" (parse-date :date-time "2016-02-01T00:00:00.000Z") -> #inst "2016-02-01"
Parse a datetime string `s` with a custom `date-format`, which can be a format string, clj-time formatter keyword, or anything else that can be coerced to a `DateTimeFormatter`. (parse-date "yyyyMMdd" "20160201") -> #inst "2016-02-01" (parse-date :date-time "2016-02-01T00:00:00.000Z") -> #inst "2016-02-01"
(profile form)
(profile message & body)
Like clojure.core/time
, but lets you specify a message
that gets printed with the total time, and formats the
time nicely using format-nanoseconds
.
Like `clojure.core/time`, but lets you specify a `message` that gets printed with the total time, and formats the time nicely using `format-nanoseconds`.
(relative-date unit amount)
(relative-date unit amount date)
Return a new Timestamp relative to the current time using a relative date unit
.
(relative-date :year -1) -> #inst 2014-11-12 ...
Return a new Timestamp relative to the current time using a relative date `unit`. (relative-date :year -1) -> #inst 2014-11-12 ...
(str->date-time date-str)
(str->date-time date-str tz)
Like clj-time.format/parse but uses an ordered list of parsers to be faster. Returns the parsed date, or nil
if it
was unable to be parsed.
Like clj-time.format/parse but uses an ordered list of parsers to be faster. Returns the parsed date, or `nil` if it was unable to be parsed.
(str->time date-str)
(str->time date-str tz)
Parse time-str
and return a java.sql.Time
instance. Returns nil
if time-str
can't be parsed.
Parse `time-str` and return a `java.sql.Time` instance. Returns `nil` if `time-str` can't be parsed.
(with-effective-timezone db & body)
Runs body
with *report-timezone*
and *data-timezone*
configured using the given db
Runs `body` with `*report-timezone*` and `*data-timezone*` configured using the given `db`
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close