Liking cljdoc? Tell your friends :D

lambdaisland.deja-fu

Time/Date types for use on the frontend. This provides the following equivalents:

| #time/date "2020-10-10" | java.time.LocalDate | goog.date.Date | | #time/time "05:30:45" | java.time.LocalTime | lambdaisland.deja-fu/LocalTime | | #time/date-time "2020-10-07T12:16:41.761088" | java.time.LocalDateTime | goog.date.DateTime |

For all of these we make sure the tagged reader literals are read correctly, and that values of these types print with these reader tags.

All times are "local", they don't carry timezone information.

We also implement an ad-hoc API here, adding things as we need them, making sure that these functions hide the details of these types. All date/time manipulation on the frontend should go through this namespace. Avoid calling properties/methods of concrete types directly, and avoid using js/Date.

Create a new local-date-time using the same syntax from goog.Date or js/Date: (local-date-time 2021 4 19 15 39 0 0)

Parse a time string: (parse-local-date-time "2021-01-01T23:59")

Get the current time: (local-date-time)

Adjust the seconds component: (assoc (local-date-time) :seconds 0)

Get the next day: (add-interval (local-date-time) {:hours 1})

Works well with threading: (-> (parse-local-date-time "2021-01-01T23:59") (assoc :seconds 0) (to-local-date))

Time/Date types for use on the frontend. This provides the following
equivalents:

| #time/date "2020-10-10"                      | java.time.LocalDate     | goog.date.Date                 |
| #time/time "05:30:45"                        | java.time.LocalTime     | lambdaisland.deja-fu/LocalTime |
| #time/date-time "2020-10-07T12:16:41.761088" | java.time.LocalDateTime | goog.date.DateTime             |

For all of these we make sure the tagged reader literals are read correctly,
and that values of these types print with these reader tags.

All times are "local", they don't carry timezone information.

We also implement an ad-hoc API here, adding things as we need them, making
sure that these functions hide the details of these types. All date/time
manipulation on the frontend should go through this namespace. Avoid calling
properties/methods of concrete types directly, and avoid using js/Date.

Create a new local-date-time using the same syntax from goog.Date or js/Date:
  (local-date-time 2021 4 19 15 39 0 0)

Parse a time string:
  (parse-local-date-time "2021-01-01T23:59")

Get the current time:
  (local-date-time)

Adjust the seconds component:
  (assoc (local-date-time) :seconds 0)

Get the next day:
  (add-interval (local-date-time) {:hours 1})

Works well with threading:
  (-> (parse-local-date-time "2021-01-01T23:59")
   (assoc :seconds 0)
   (to-local-date))
raw docstring

browser-timezone-offsetcljs

(browser-timezone-offset)

Get the difference, in minutes, between browser's time zone and UTC. e.g. when in CET (+1) this returns -60.

Get the difference, in minutes, between browser's time zone and UTC.
e.g. when in CET (+1) this returns -60.
sourceraw docstring

Conversionscljsprotocol

add-intervalcljs

(add-interval obj values)

Add an interval to the date/time

Add an interval to the date/time

epoch-mscljs

(epoch-ms obj)

Milliseconds since January 1, 1970

Milliseconds since January 1, 1970

to-local-datecljs

(to-local-date obj)

Date part of a date or date-time

Date part of a date or date-time

to-local-timecljs

(to-local-time obj)

Time part of a date-time or local time

Time part of a date-time or local time

with-datecljs

(with-date obj date)

Set the date part of a DateTime

Set the date part of a DateTime

with-timecljs

(with-time obj time)

Set the time part of a DateTime

Set the time part of a DateTime
source

current-time-milliscljs

(current-time-millis)

Get the current UNIX timestamp in milliseconds.

Get the current UNIX timestamp in milliseconds.
sourceraw docstring

date-string-regexcljs

source

days-betweencljs

(days-between begin end)

Get the interval between two date/time objects in days

Get the interval between two date/time objects in days
sourceraw docstring

distance-in-wordscljs

(distance-in-words from to)
(distance-in-words from
                   to
                   {:keys [patterns] :or {patterns relative-time-patterns}})
source

Formatcljsprotocol

formatcljs

(format obj)
(format obj format-str)

Symbol Meaning Presentation Example


G# era designator (Text) AD y# year (Number) 1996 Y year (week of year) (Number) 1997 u* extended year (Number) 4601 Q# quarter (Text) Q3 & 3rd quarter M month in year (Text & Number) July & 07 L month in year (standalone) (Text & Number) July & 07 d day in month (Number) 10 h hour in am/pm (1~12) (Number) 12 H hour in day (0~23) (Number) 0 m minute in hour (Number) 30 s second in minute (Number) 55 S fractional second (Number) 978 E# day of week (Text) Tue & Tuesday e* day of week (local 1~7) (Number) 2 c# day of week (standalone) (Text & Number) 2 & Tues & Tuesday & T D* day in year (Number) 189 F* day of week in month (Number) 2 (2nd Wed in July) w week in year (Number) 27 W* week in month (Number) 2 a am/pm marker (Text) PM k hour in day (1~24) (Number) 24 K hour in am/pm (0~11) (Number) 0 z time zone (Text) Pacific Standard Time Z# time zone (RFC 822) (Number) -0800 v# time zone (generic) (Text) America/Los_Angeles V# time zone (Text) Los Angeles Time g* Julian day (Number) 2451334 A* milliseconds in day (Number) 69540000 ' escape for text (Delimiter) 'Date=' '' single quote (Literal) 'o''clock'

Item marked with '*' are not supported yet. Item marked with '#' works different than java

The count of pattern letters determine the format.

  • (Text) 4 or more, use full form, <4, use short or abbreviated form if it exists. (e.g., "EEEE" produces "Monday", "EEE" produces "Mon")

  • (Number) the minimum number of digits. Shorter numbers are zero-padded to this amount (e.g. if "m" produces "6", "mm" produces "06"). Year is handled specially; that is, if the count of 'y' is 2, the Year will be truncated to 2 digits. (e.g., if "yyyy" produces "1997", "yy" produces "97".) Unlike other fields, fractional seconds are padded on the right with zero.

  • (Text & Number) 3 or over, use text, otherwise use number. (e.g., "M" produces "1", "MM" produces "01", "MMM" produces "Jan", and "MMMM" produces "January".)

Any characters in the pattern that are not in the ranges of ['a'..'z'] and ['A'..'Z'] will be treated as quoted text. For instance, characters like ':', '.', ' ', '#' and '@' will appear in the resulting time text even if they are not inside single quotes.

Symbol   Meaning                    Presentation       Example
------   -------                    ------------       -------
G#       era designator             (Text)             AD
y#       year                       (Number)           1996
Y        year (week of year)        (Number)           1997
u*       extended year              (Number)           4601
Q#       quarter                    (Text)             Q3 & 3rd quarter
M        month in year              (Text & Number)    July & 07
L        month in year (standalone) (Text & Number)    July & 07
d        day in month               (Number)           10
h        hour in am/pm (1~12)       (Number)           12
H        hour in day (0~23)         (Number)           0
m        minute in hour             (Number)           30
s        second in minute           (Number)           55
S        fractional second          (Number)           978
E#       day of week                (Text)             Tue & Tuesday
e*       day of week (local 1~7)    (Number)           2
c#       day of week (standalone)   (Text & Number)    2 & Tues & Tuesday & T
D*       day in year                (Number)           189
F*       day of week in month       (Number)           2 (2nd Wed in July)
w        week in year               (Number)           27
W*       week in month              (Number)           2
a        am/pm marker               (Text)             PM
k        hour in day (1~24)         (Number)           24
K        hour in am/pm (0~11)       (Number)           0
z        time zone                  (Text)             Pacific Standard Time
Z#       time zone (RFC 822)        (Number)           -0800
v#       time zone (generic)        (Text)             America/Los_Angeles
V#       time zone                  (Text)             Los Angeles Time
g*       Julian day                 (Number)           2451334
A*       milliseconds in day        (Number)           69540000
'        escape for text            (Delimiter)        'Date='
''       single quote               (Literal)          'o''clock'

Item marked with '*' are not supported yet.
Item marked with '#' works different than java

The count of pattern letters determine the format.
- (Text) 4 or more, use full form, <4, use short or abbreviated form if it
exists. (e.g., "EEEE" produces "Monday", "EEE" produces "Mon")

- (Number) the minimum number of digits. Shorter numbers are zero-padded to
this amount (e.g. if "m" produces "6", "mm" produces "06"). Year is handled
specially; that is, if the count of 'y' is 2, the Year will be truncated to
2 digits. (e.g., if "yyyy" produces "1997", "yy" produces "97".) Unlike other
fields, fractional seconds are padded on the right with zero.

- (Text & Number) 3 or over, use text, otherwise use number. (e.g., "M"
produces "1", "MM" produces "01", "MMM" produces "Jan", and "MMMM" produces
"January".)

Any characters in the pattern that are not in the ranges of ['a'..'z'] and
['A'..'Z'] will be treated as quoted text. For instance, characters like ':',
'.', ' ', '#' and '@' will appear in the resulting time text even if they are
not inside single quotes.
source

formattercljs

source

leap-year?cljs

(leap-year? year-or-date-like)

Does the year, or the year field of the given local date/date-time, a leap year?

Does the year, or the year field of the given local date/date-time, a leap
year?
sourceraw docstring

local-datecljs

(local-date)
(local-date year month day)

contstructs a goog.date.Date

  • no arguments: returns the date for today
  • multiple arguments: takes year,month,day
contstructs a goog.date.Date

- no arguments: returns the date for today
- multiple arguments: takes year,month,day
sourceraw docstring

local-date-timecljs

(local-date-time)
(local-date-time epoch-ms)
(local-date-time year month day hours minutes)
(local-date-time year month day hours minutes seconds)
(local-date-time year month day hours minutes seconds nanos)

contstructs a goog.date.DateTime

  • no arguments: get the current date and time
  • single argument: convert UNIX timestamp (milliseconds) to a DateTime
  • multiple arguments: takes year,month,day,hours,minutes,seconds,nanos. Seconds and nanos are optional.
contstructs a goog.date.DateTime

- no arguments: get the current date and time
- single argument: convert UNIX timestamp (milliseconds) to a DateTime
- multiple arguments: takes year,month,day,hours,minutes,seconds,nanos.
  Seconds and nanos are optional.
sourceraw docstring

local-timecljs

(local-time)
(local-time hours & args)

constructs a LocalTime

  • no arguments: get the current time
  • multiple arguments: takes hours,minutes,seconds,nanos
constructs a LocalTime
- no arguments: get the current time
- multiple arguments: takes hours,minutes,seconds,nanos
sourceraw docstring

millis-betweencljs

(millis-between begin end)

Get the interval between two date/time objects in milliseconds

Get the interval between two date/time objects in milliseconds
sourceraw docstring

minutes-betweencljs

(minutes-between begin end)

Get the interval between two date/time objects in minutes

Get the interval between two date/time objects in minutes
sourceraw docstring

parse-local-datecljs

(parse-local-date yyyy-mm-dd)

Parse a date (YYYY-MM-DD) to a goog.date.Date

Reimplementation of goog.date.Date.fromIsostring but with support for single digit month/day.

Parse a date (YYYY-MM-DD) to a goog.date.Date

Reimplementation of goog.date.Date.fromIsostring but with support for single
digit month/day.
sourceraw docstring

parse-local-date-timecljs

(parse-local-date-time date-time)

Parse an ISO timestamp without time zone information to a goog.date.DateTime. We implement our own parsing logic for the time section, to prevent time zone shifting. The numbers you provide in the timestamp are the numbers that end up in the DateTime. If we leave it to goog.date then it will assume the timestamp is UTC, and shift it to the browser's timezone.

Parse an ISO timestamp without time zone information to a goog.date.DateTime.
We implement our own parsing logic for the time section, to prevent time zone
shifting. The numbers you provide in the timestamp are the numbers that end up
in the DateTime. If we leave it to goog.date then it will assume the timestamp
is UTC, and shift it to the browser's timezone.
sourceraw docstring

parse-local-timecljs

(parse-local-time time)

Parse a timestamp (HH:MM:SS or HH:MM:SS.mmm or HH:MM:SS.nnnnnn) to a LocalTime.

Parse a timestamp (HH:MM:SS or HH:MM:SS.mmm or HH:MM:SS.nnnnnn) to a LocalTime.
sourceraw docstring

parse-offset-date-timecljs

(parse-offset-date-time date-time)

Parse an ISO timestamp with timezone offset (Z or +/-) to a goog.date.DateTime. Note that the result is essentially a LocalDateTime, since none of the types at our disposal on the frontend actually store a timezone or offset. Instead goog.date's parsing logic will shift the time based on the difference between the time zone in the timestamp, and the timezone the browser is in.

Parse an ISO timestamp with timezone offset (Z or +/-) to a goog.date.DateTime.
Note that the result is essentially a LocalDateTime, since none of the types
at our disposal on the frontend actually store a timezone or offset. Instead
goog.date's parsing logic will shift the time based on the difference between
the time zone in the timestamp, and the timezone the browser is in.
sourceraw docstring

relative-time-patternscljs

Word patterns, can be passed in for i18n

Word patterns, can be passed in for i18n
sourceraw docstring

todaycljs

(today)

Get a #time/date with the current date, convenience API alternative to calling (local-date) without args.

Get a #time/date with the current date, convenience API alternative to
calling `(local-date)` without args.
sourceraw docstring

utc-nowcljs

(utc-now)

Get a local-date-time, representing the current time in UTC.

Get a local-date-time, representing the current time in UTC.
sourceraw docstring

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

× close