A common set of date/time functions for CLJC. These functions give client-server agreement on dealing with common date/time processing that happens with respect to UI controls. There is a general formatting function that uses Java DateTimeFormatter on the JVM for server-side, but in order to keep the UI code a light as possible that formatter is hand-written using the built-in browser Intl function (which has the locale data for many locales and does not bloat your js file).
As such the formatter
from this namespace is not completely isomophic in CLJ vs CLJS, since in CLJ that formatter
can be used for general parsing, but in CLJS it cannot. This should not generally be a problem because the parsing
you usually need in the UI is for date controls, and there are functions for ISO parsing that work just fine without
needing locale data.
A common set of date/time functions for CLJC. These functions give client-server agreement on dealing with common date/time processing that happens with respect to UI controls. There is a general formatting function that uses Java DateTimeFormatter on the JVM for server-side, but in order to keep the UI code a light as possible that formatter is hand-written using the built-in browser Intl function (which has the locale data for many locales and does not bloat your js file). As such the `formatter` from this namespace is not completely isomophic in CLJ vs CLJS, since in CLJ that formatter can be used for general parsing, but in CLJS it cannot. This should not generally be a problem because the parsing you usually need in the UI is for date controls, and there are functions for ISO parsing that work just fine without needing locale data.
The current time zone for all date time operations. Defaults to nil. Should be set using
set-timezone!
in cljs, and should be thread-bound to a processing request using binding
in CLJ.
The value of this var is a java.time.ZoneId, which can be obtained from a string with cljc.time.zone-id/of.
The current time zone for all date time operations. Defaults to nil. Should be set using `set-timezone!` in cljs, and should be thread-bound to a processing request using `binding` in CLJ. The value of this var is a java.time.ZoneId, which can be obtained from a string with cljc.time.zone-id/of.
The current time zone for all date time operations. Defaults to nil. Should be set using
set-timezone!
in cljs, and should be thread-bound to a processing request using binding
in CLJ.
The value of this var is a java.time.ZoneId, which can be obtained from a string with cljc.time.zone-id/of.
The current time zone for all date time operations. Defaults to nil. Should be set using `set-timezone!` in cljs, and should be thread-bound to a processing request using `binding` in CLJ. The value of this var is a java.time.ZoneId, which can be obtained from a string with cljc.time.zone-id/of.
(beginning-of-day)
(beginning-of-day inst)
Returns an inst? that is adjusted to midnight (local time of current time zone) on the day of the
input instant (which defaults to now
).
Returns an inst? that is adjusted to midnight (local time of current time zone) on the day of the input instant (which defaults to `now`).
(beginning-of-month)
(beginning-of-month inst)
Returns an inst? that is adjusted to midnight (local time of current time zone) on the first day of the month of the
input instant (which defaults to now
).
Returns an inst? that is adjusted to midnight (local time of current time zone) on the first day of the month of the input instant (which defaults to `now`).
(beginning-of-year)
(beginning-of-year inst)
Returns an inst? that is adjusted to midnight (local time of current time zone) on the first day of January in this year.
Returns an inst? that is adjusted to midnight (local time of current time zone) on the first day of January in this year.
(end-of-day)
(end-of-day inst)
Returns an inst? that is adjusted to midnight (local time of current time zone) on the next day of the
input instant (which defaults to now
). This creates an open interval for end.
Returns an inst? that is adjusted to midnight (local time of current time zone) on the next day of the input instant (which defaults to `now`). This creates an open interval for end.
(end-of-month)
(end-of-month inst)
Returns an inst? that is adjusted to midnight (local time of current time zone) on the first day of the next month of the
input instant (which defaults to now
). This creates an open interval for end.
Returns an inst? that is adjusted to midnight (local time of current time zone) on the first day of the next month of the input instant (which defaults to `now`). This creates an open interval for end.
(end-of-year)
(end-of-year inst)
Returns an inst? that is adjusted to midnight (local time of current time zone) on the first day of January in the next year.
Returns an inst? that is adjusted to midnight (local time of current time zone) on the first day of January in the next year.
(formatter fmt)
(formatter fmt locale)
Constructs a DateTimeFormatter out of either a
and a Locale, which is optional.
NOTE: In CLJS this generates a formatter that uses Intl, and IS NOT a java-time DateTimeFormatter. This means you CANNOT use it for parsing. If you need parsing, you must add a js-joda locale to your deps and use cljc.java-time directly, or come up with some other solution.
Constructs a DateTimeFormatter out of either a * format string - "YYYY/mm/DD" "YYY HH:MM" etc. or * formatter name - :iso-instant :iso-local-date etc and a Locale, which is optional. NOTE: In CLJS this generates a formatter that uses Intl, and IS NOT a java-time DateTimeFormatter. This means you CANNOT use it for parsing. If you need parsing, you must add a js-joda locale to your deps and use cljc.java-time directly, or come up with some other solution.
(formatter f)
(formatter f l)
(get-zone-id zone-name)
Returns the ZoneID of zone-name, or current-timezone if zone-name is nil.
Returns the ZoneID of zone-name, or *current-timezone* if zone-name is nil.
(html-date->inst html-date local-time)
Convert an HTML date input string to an inst at the given local time, adjusted to the correct current-timezone.
Convert an HTML date input string to an inst at the given local time, adjusted to the correct *current-timezone*.
(html-date-string->local-date s)
Convert a standard HTML5 date input string to a local date
Convert a standard HTML5 date input string to a local date
(html-datetime-string->inst date-time-string)
(html-datetime-string->inst zone-name date-time-string)
(inst->html-date inst)
Convert an inst to an HTML date input string. Assumes current-timezone. Always returns a string. Will return today's date if inst is nil or otherwise fails to convert.
Convert an inst to an HTML date input string. Assumes *current-timezone*. Always returns a string. Will return today's date if inst is nil or otherwise fails to convert.
(inst->html-datetime-string inst)
(inst->html-datetime-string zone-name inst)
(inst->human-readable-date inst)
Converts a UTC Instant into the correctly-offset and human-readable (e.g. America/Los_Angeles) date string.
Uses locale from locale/current-locale
.
Converts a UTC Instant into the correctly-offset and human-readable (e.g. America/Los_Angeles) date string. Uses locale from `locale/current-locale`.
(inst->local-date inst)
(inst->local-date zone-name inst)
Converts a UTC Instant into the correctly-offset (e.g. America/Los_Angeles) LocalDate.
Converts a UTC Instant into the correctly-offset (e.g. America/Los_Angeles) LocalDate.
(inst->local-datetime inst)
(inst->local-datetime zone-name inst)
Converts a UTC Instant into the correctly-offset (e.g. America/Los_Angeles) LocalDateTime.
Converts a UTC Instant into the correctly-offset (e.g. America/Los_Angeles) LocalDateTime.
(inst->zoned-date-time inst)
(inst->zoned-date-time zone-name inst)
Converts a UTC Instant into the correctly-offset (e.g. America/Los_Angeles) ZonedDateTime.
Converts a UTC Instant into the correctly-offset (e.g. America/Los_Angeles) ZonedDateTime.
(local-date->html-date-string d)
Convert a standard HTML5 date input string to a local date
Convert a standard HTML5 date input string to a local date
(local-date->inst local-dt)
(local-date->inst zone-name local-dt)
(local-date->inst zone-name month day yyyy)
Returns a UTC Clojure inst based on the date given as time in the named (ISO) zone (e.g. America/Los_Angeles).
If no zone name (or nil) is given, then the *current-timezone*
will be used.
Returns a UTC Clojure inst based on the date given as time in the named (ISO) zone (e.g. America/Los_Angeles). If no zone name (or nil) is given, then the `*current-timezone*` will be used.
(local-datetime->inst local-dt)
(local-datetime->inst zone-name local-dt)
(local-datetime->inst zone-name month day yyyy hh mm)
(local-datetime->inst zone-name month day yyyy hh mm ss)
Returns a UTC Clojure inst based on the date/time given as time in the named (ISO) zone (e.g. America/Los_Angeles).
If no zone name (or nil) is given, then the *current-timezone*
will be used.
Returns a UTC Clojure inst based on the date/time given as time in the named (ISO) zone (e.g. America/Los_Angeles). If no zone name (or nil) is given, then the `*current-timezone*` will be used.
(max-inst & insts)
Returns the maximum inst from a list of insts. Returns nil if no insts are passed.
Returns the maximum inst from a list of insts. Returns nil if no insts are passed.
(min-inst & insts)
Returns the minimum inst from a list of insts. Returns nil if no insts are passed.
Returns the minimum inst from a list of insts. Returns nil if no insts are passed.
(new-date)
(new-date millis)
Create a Date object from milliseconds (defaults to now).
Create a Date object from milliseconds (defaults to now).
(now)
Returns the current time as an inst.
Returns the current time as an inst.
(now-ms)
Returns the current time in ms.
Returns the current time in ms.
(set-timezone! zone-name)
Set the root binding of timezone, a dynamic var. In CLJS there is a lot of async behavior, but the overall
time zone is typically fixed for a user. In CLJ the timezone usually needs to be bound to the local processing
thread for a request. Therefore, the typical CLJS code will call this function on start, and the typical
CLJ code will do a (binding [*current-timezone* (z/of user-zone)] ...)
.
Set the root binding of timezone, a dynamic var. In CLJS there is a lot of async behavior, but the overall time zone is typically fixed for a user. In CLJ the timezone usually needs to be bound to the local processing thread for a request. Therefore, the typical CLJS code will call this function on start, and the typical CLJ code will do a `(binding [*current-timezone* (z/of user-zone)] ...)`.
(with-timezone zone-name & body)
Set the (thread-local) "current time zone"to the given zone-name
(a string zone id) for the duration of the rest of the
body
. Simply a short-hand for (binding [*current-timezone* (zone-id/of zone-name)] ...)
.
Set the (thread-local) "current time zone"to the given `zone-name` (a string zone id) for the duration of the rest of the `body`. Simply a short-hand for `(binding [*current-timezone* (zone-id/of zone-name)] ...)`.
(zoned-date-time->inst ztm)
Convert a zoned-date-time back to a low-level inst?
Convert a zoned-date-time back to a low-level inst?
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close