Liking cljdoc? Tell your friends :D

metabase.util.date

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

*data-timezone*clj

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.
sourceraw docstring

*report-timezone*clj

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)
sourceraw docstring

->iso-8601-datetimeclj

(->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" (?)
sourceraw docstring

calculate-durationclj

(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
sourceraw docstring

call-with-effective-timezoneclj

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

coerce-to-timestampclj

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

coerce-to-timezoneclj

(coerce-to-timezone this)

Coerce this to java.util.TimeZone

Coerce `this` to `java.util.TimeZone`
sourceraw docstring

date->iso-8601clj

(date->iso-8601)
(date->iso-8601 date)

Format date a an ISO-8601 string.

Format `date` a an ISO-8601 string.
sourceraw docstring

date-extractclj

(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
sourceraw docstring

date-extract-unitsclj

Units which return a (numerical, periodic) component of a date

Units which return a (numerical, periodic) component of a date
sourceraw docstring

date-string?clj

(date-string? s)

Is S a valid ISO 8601 date string?

Is S a valid ISO 8601 date string?
sourceraw docstring

date-truncclj

(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"
sourceraw docstring

date-trunc-or-extractclj

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

date-trunc-unitsclj

Valid date bucketing units

Valid date bucketing units
sourceraw docstring

format-dateclj

(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"
sourceraw docstring

format-microsecondsclj

(format-microseconds microseconds)

Format a time interval in microseconds into something more readable.

Format a time interval in microseconds into something more readable.
sourceraw docstring

format-millisecondsclj

(format-milliseconds milliseconds)

Format a time interval in milliseconds into something more readable.

Format a time interval in milliseconds into something more readable.
sourceraw docstring

format-nanosecondsclj

(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)`
sourceraw docstring

format-secondsclj

(format-seconds seconds)

Format a time interval in seconds into something more readable.

Format a time interval in seconds into something more readable.
sourceraw docstring

format-timeclj

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

is-temporal?clj

(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`?
sourceraw docstring

is-time?clj

(is-time? v)

Returns true if v is a Time object

Returns true if `v` is a Time object
sourceraw docstring

jvm-timezoneclj

Machine time zone

Machine time zone
sourceraw docstring

new-sql-timestampclj

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

parse-dateclj

(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"
sourceraw docstring

profilecljmacro

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

relative-dateclj

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

str->date-timeclj

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

str->timeclj

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

utcclj

UTC TimeZone

UTC TimeZone
sourceraw docstring

with-effective-timezonecljmacro

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

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

× close