Liking cljdoc? Tell your friends :D

cljs-time.core

The core namespace for date-time operations in the cljs-time library.

Create a DateTime instance with date-time (or a local DateTime instance with local-date-time), specifying the year, month, day, hour, minute, second, and millisecond:

=> (date-time 1986 10 14 4 3 27 456)
#<DateTime 1986-10-14T04:03:27.456Z>

=> (local-date-time 1986 10 14 4 3 27 456)
#<DateTime 1986-10-14T04:03:27.456>

ss-significant fields can be omitted:

=> (date-time 1986 10 14)
#<DateTime 1986-10-14T00:00:00.000Z>

=> (local-date-time 1986 10 14)
#<DateTime 1986-10-14T00:00:00.000>

Get the current time with (now) and the start of the Unix epoch with (epoch).

Once you have a date-time, use accessors like hour and second to access the corresponding fields:

=> (hour (date-time 1986 10 14 22))
22

=> (hour (local-date-time 1986 10 14 22))
22

The functions after? and before? determine the relative position of two DateTime instances:

=> (after? (date-time 1986 10) (date-time 1986 9))
true

=> (after? (local-date-time 1986 10) (local-date-time 1986 9))
true

Often you will want to find a date some amount of time from a given date. For example, to find the time 1 month and 3 weeks from a given date-time:

=> (plus (date-time 1986 10 14) (months 1) (weeks 3))
#<DateTime 1986-12-05T00:00:00.000Z>

=> (plus (local-date-time 1986 10 14) (months 1) (weeks 3))
#<DateTime 1986-12-05T00:00:00.000Z>

An Interval is used to represent the span of time between two DateTime instances. Construct one using interval, then query them using within?, overlaps?, and abuts?

=> (within? (interval (date-time 1986) (date-time 1990)) (date-time 1987))
true

To find the amount of time encompased by an interval, use in-seconds and in-minutes:

=> (in-minutes (interval (date-time 1986 10 2) (date-time 1986 10 14)))
17280

Note that all functions in this namespace work with Joda objects or ints. If you need to print or parse date-times, see cljs-time.format. If you need to ceorce date-times to or from other types, see cljs-time.coerce.

### The core namespace for date-time operations in the cljs-time library.

  Create a DateTime instance with date-time (or a local DateTime instance with local-date-time),
  specifying the year, month, day, hour, minute, second, and millisecond:

```clojure
=> (date-time 1986 10 14 4 3 27 456)
#<DateTime 1986-10-14T04:03:27.456Z>

=> (local-date-time 1986 10 14 4 3 27 456)
#<DateTime 1986-10-14T04:03:27.456>

ss-significant fields can be omitted:

=> (date-time 1986 10 14)
#<DateTime 1986-10-14T00:00:00.000Z>

=> (local-date-time 1986 10 14)
#<DateTime 1986-10-14T00:00:00.000>
```

  Get the current time with (now) and the start of the Unix epoch with (epoch).

  Once you have a date-time, use accessors like hour and second to access the
  corresponding fields:

```clojure
=> (hour (date-time 1986 10 14 22))
22

=> (hour (local-date-time 1986 10 14 22))
22
```

  The functions after? and before? determine the relative position of two
  DateTime instances:

```clojure
=> (after? (date-time 1986 10) (date-time 1986 9))
true

=> (after? (local-date-time 1986 10) (local-date-time 1986 9))
true
```

  Often you will want to find a date some amount of time from a given date. For
  example, to find the time 1 month and 3 weeks from a given date-time:

```clojure
=> (plus (date-time 1986 10 14) (months 1) (weeks 3))
#<DateTime 1986-12-05T00:00:00.000Z>

=> (plus (local-date-time 1986 10 14) (months 1) (weeks 3))
#<DateTime 1986-12-05T00:00:00.000Z>
```

  An Interval is used to represent the span of time between two DateTime
  instances. Construct one using interval, then query them using within?,
  overlaps?, and abuts?

```clojure
=> (within? (interval (date-time 1986) (date-time 1990)) (date-time 1987))
true
```

  To find the amount of time encompased by an interval, use in-seconds and
  in-minutes:

```clojure
=> (in-minutes (interval (date-time 1986 10 2) (date-time 1986 10 14)))
17280
```

  Note that all functions in this namespace work with Joda objects or ints. If
  you need to print or parse date-times, see cljs-time.format. If you need to
  ceorce date-times to or from other types, see cljs-time.coerce.
raw docstring

*ms-fn*cljs

source

=cljs

Note: Equality in goog.date.* (and also with plain javascript dates) is not the same as in Joda/clj-time. Two date objects representing the same instant in time in goog.date.* are not equal.

If you need to test for equality use either cljs-time.core/=, or optionally you can require the cljs-time.extend namespace which will extend the goog.date.* datatypes, so that clojure.core/= works as expected.

**Note:** Equality in goog.date.* (and also with plain
javascript dates) is not the same as in Joda/clj-time. Two date
objects representing the same instant in time in goog.date.* are not
equal.

If you need to test for equality use either `cljs-time.core/=`, or
optionally you can require the `cljs-time.extend` namespace which will
extend the goog.date.* datatypes, so that clojure.core/= works as
expected.
sourceraw docstring

abuts?cljs

(abuts? {start-a :start end-a :end} {start-b :start end-b :end})

Returns true if Interval a abuts b, i.e. then end of a is exactly the beginning of b.

Returns true if Interval a abuts b, i.e. then end of a is exactly the
beginning of b.
sourceraw docstring

agocljs

(ago period)

Returns a DateTime a supplied period before the present.

e.g. (-> 5 years ago)

Returns a DateTime a supplied period before the present.

e.g. `(-> 5 years ago)`
sourceraw docstring

at-midnightcljs

(at-midnight datetime)
source

conversion-errorcljs

(conversion-error from to)
source

date-midnightcljs

(date-midnight year)
(date-midnight year month)
(date-midnight year month day)

Constructs and returns a new DateTime at midnight in UTC.

Specify the year, month of year, day of month. Note that month and day are 1-indexed. Any number of least-significant components can be ommited, in which case they will default to 1.

Constructs and returns a new DateTime at midnight in UTC.

Specify the year, month of year, day of month. Note that month and day are
1-indexed. Any number of least-significant components can be ommited, in
which case they will default to 1.
sourceraw docstring

date-timecljs

(date-time year)
(date-time year month)
(date-time year month day)
(date-time year month day hour)
(date-time year month day hour minute)
(date-time year month day hour minute second)
(date-time year month day hour minute second millis)

Constructs and returns a new DateTime in UTC.

Specify the year, month of year, day of month, hour of day, minute if hour, second of minute, and millisecond of second. Note that month and day are 1-indexed while hour, second, minute, and millis are 0-indexed.

Any number of least-significant components can be ommited, in which case they will default to 1 or 0 as appropriate.

Constructs and returns a new DateTime in UTC.

Specify the year, month of year, day of month, hour of day, minute if hour,
second of minute, and millisecond of second. Note that month and day are
1-indexed while hour, second, minute, and millis are 0-indexed.

Any number of least-significant components can be ommited, in which case
they will default to 1 or 0 as appropriate.
sourceraw docstring

date?cljs

(date? x)
source

DateTimeProtocolcljsprotocol

Interface for various date time functions

Interface for various date time functions

minutecljs

(minute this)

Return the minute of hour component of the given date/time.

Return the minute of hour component of the given date/time.

after?cljs

(after? this that)

Returns true if DateTime 'this' is strictly after date/time 'that'.

Returns true if DateTime 'this' is strictly after date/time 'that'.

hourcljs

(hour this)

Return the hour of day component of the given date/time. A time of 12:01am will have an hour component of 0.

Return the hour of day component of the given date/time. A time of 12:01am will have an hour component of 0.

daycljs

(day this)

Return the day of month component of the given date/time.

Return the day of month component of the given date/time.

secondcljs

(second this)

Return the second of minute component of the given date/time.

Return the second of minute component of the given date/time.

plus-cljs

(plus- this period)

Returns a new date/time corresponding to the given date/time moved forwards by the given Period(s).

Returns a new date/time corresponding to the given date/time moved forwards by the given Period(s).

day-of-weekcljs

(day-of-week this)

Return the day of week component of the given date/time. Monday is 1 and Sunday is 7

Return the day of week component of the given date/time. Monday is 1 and Sunday is 7

last-day-of-the-month-cljs

(last-day-of-the-month- this)

Returns the last day of the month

Returns the last day of the month

monthcljs

(month this)

Return the month component of the given date/time.

Return the month component of the given date/time.

equal?cljs

(equal? this that)

Returns true if DateTime 'this' is strictly equal to date/time 'that'.

Returns true if DateTime 'this' is strictly equal to date/time 'that'.

before?cljs

(before? this that)

Returns true if DateTime 'this' is strictly before date/time 'that'.

Returns true if DateTime 'this' is strictly before date/time 'that'.

yearcljs

(year this)

Return the year component of the given date/time.

Return the year component of the given date/time.

week-number-of-yearcljs

(week-number-of-year this)

Returs the number of weeks in the year

Returs the number of weeks in the year

minus-cljs

(minus- this period)

Returns a new date/time corresponding to the given date/time moved backwards by the given Period(s).

Returns a new date/time corresponding to the given date/time moved backwards by the given Period(s).

seccljs

(sec this)

Return the second of minute component of the given date/time.

Return the second of minute component of the given date/time.

first-day-of-the-month-cljs

(first-day-of-the-month- this)

Returns the first day of the month

Returns the first day of the month

millicljs

(milli this)

Return the millisecond of second component of the given date/time.

Return the millisecond of second component of the given date/time.
sourceraw docstring

dayscljs

(days)
(days n)

Given a number, returns a Period representing that many days. Without an argument, returns a Period representing only days.

Given a number, returns a Period representing that many days.
Without an argument, returns a Period representing only days.
sourceraw docstring

days?cljs

(days? val)

Returns true if the given value is an instance of Days

Returns true if the given value is an instance of Days
sourceraw docstring

default-ms-fncljs

(default-ms-fn)
source

default-time-zonecljs

(default-time-zone)

Returns the default timezone map for the current environment.

Returns the default timezone map for the current environment.
sourceraw docstring

deprecatedcljs

(deprecated message)
source

do-at*cljs

(do-at* base-date-time body-fn)
source

earliestcljs

(earliest dts)
(earliest dt1 dt2)

Returns the earliest of the supplied DateTimes

Returns the earliest of the supplied DateTimes
sourceraw docstring

endcljs

(end in)

Returns the end DateTime of an Interval.

Returns the end DateTime of an Interval.
sourceraw docstring

epochcljs

(epoch)

Returns a DateTime for the begining of the Unix epoch in the UTC time zone.

Returns a DateTime for the begining of the Unix epoch in the UTC time zone.
sourceraw docstring

extendcljs

(extend in & by)

Returns an Interval with an end DateTime the specified Period after the end of the given Interval

Returns an Interval with an end DateTime the specified Period after the end
of the given Interval
sourceraw docstring

first-day-of-the-monthcljs

(first-day-of-the-month dt)
(first-day-of-the-month year month)
source

floorcljs

(floor dt dt-fn)

Floors the given date-time dt to the given time unit dt-fn, e.g. (floor (now) hour) returns (now) for all units up to and including the hour

Floors the given date-time dt to the given time unit dt-fn,
e.g. (floor (now) hour) returns (now) for all units
up to and including the hour
sourceraw docstring

from-default-time-zonecljs

(from-default-time-zone dt)

Assuming dt is in the UTC timezone, returns a DateTime corresponding to the same point in calendar time as the given DateTime, but for a correspondingly different absolute instant in time in the default (local) timezone.

Note: This implementation uses the ECMAScript 5.1 implementation which trades some historical daylight savings transition accuracy for simplicity. see http://es5.github.io/#x15.9.1.8

Assuming `dt` is in the UTC timezone, returns a DateTime
corresponding to the same point in calendar time as the given
DateTime, but for a correspondingly different absolute instant in
time in the default (local) timezone.

Note: This implementation uses the ECMAScript 5.1 implementation which
trades some historical daylight savings transition accuracy for simplicity.
see http://es5.github.io/#x15.9.1.8
sourceraw docstring

from-nowcljs

(from-now period)

Returns a DateTime a supplied period after the present. e.g. (-> 30 minutes from-now)

Returns a DateTime a supplied period after the present.
e.g. `(-> 30 minutes from-now)`
sourceraw docstring

from-utc-time-zonecljs

(from-utc-time-zone dt)

Assuming dt is in the local timezone, returns a UtcDateTime corresponding to the same point in calendar time as the given DateTime, but for a correspondingly different absolute instant in time in the UTC timezone.

Note: This implementation uses the ECMAScript 5.1 implementation which trades some historical daylight savings transition accuracy for simplicity. see http://es5.github.io/#x15.9.1.8

Assuming `dt` is in the local timezone, returns a UtcDateTime
corresponding to the same point in calendar time as the given
DateTime, but for a correspondingly different absolute instant in
time in the UTC timezone.

Note: This implementation uses the ECMAScript 5.1 implementation which
trades some historical daylight savings transition accuracy for simplicity.
see http://es5.github.io/#x15.9.1.8
sourceraw docstring

hourscljs

(hours)
(hours n)

Given a number, returns a Period representing that many hours. Without an argument, returns a Period representing only hours.

Given a number, returns a Period representing that many hours.
Without an argument, returns a Period representing only hours.
sourceraw docstring

hours?cljs

(hours? val)

Returns true if the given value is an instance of Hours

Returns true if the given value is an instance of Hours
sourceraw docstring

Intervalcljs

source

intervalcljs

(interval start end)

Returns an Interval representing the span between the two given DateTime. Note that intervals are closed on the left and open on the right.

Returns an Interval representing the span between the two given DateTime.
Note that intervals are closed on the left and open on the right.
sourceraw docstring

interval?cljs

(interval? x)
source

InTimeUnitProtocolcljsprotocol

Interface for in-<time unit> functions

Interface for in-<time unit> functions

in-dayscljs

(in-days this)

Return the time in days.

Return the time in days.

in-hourscljs

(in-hours this)

Return the time in hours.

Return the time in hours.

in-milliscljs

(in-millis this)

Return the time in milliseconds.

Return the time in milliseconds.

in-minutescljs

(in-minutes this)

Return the time in minutes.

Return the time in minutes.

in-monthscljs

(in-months this)

Return the time in months

Return the time in months

in-secondscljs

(in-seconds this)

Return the time in seconds.

Return the time in seconds.

in-weekscljs

(in-weeks this)

Return the time in weeks

Return the time in weeks

in-yearscljs

(in-years this)

Return the time in years

Return the time in years
sourceraw docstring

IToPeriodcljsprotocol

->periodcljs

(->period obj)
source

last-day-of-the-monthcljs

(last-day-of-the-month dt)
(last-day-of-the-month year month)
source

latestcljs

(latest dts)
(latest dt1 dt2)

Returns the latest of the supplied DateTimes

Returns the latest of the supplied DateTimes
sourceraw docstring

local-datecljs

(local-date year month day)

Constructs and returns a new goog.date.Date in the local timezone. Specify the year, month, and day.

Constructs and returns a new goog.date.Date in the local timezone.
Specify the year, month, and day.
sourceraw docstring

local-date-timecljs

(local-date-time year)
(local-date-time year month)
(local-date-time year month day)
(local-date-time year month day hour)
(local-date-time year month day hour minute)
(local-date-time year month day hour minute second)
(local-date-time year month day hour minute second millis)

Constructs and returns a new local DateTime. Specify the year, month of year, day of month, hour of day, minute of hour, second of minute, and millisecond of second. Note that month and day are 1-indexed while hour, second, minute, and millis are 0-indexed. Any number of least-significant components can be ommited, in which case they will default to 1 or 0 as appropriate.

Constructs and returns a new local DateTime.
Specify the year, month of year, day of month, hour of day, minute of hour,
second of minute, and millisecond of second. Note that month and day are
1-indexed while hour, second, minute, and millis are 0-indexed.
Any number of least-significant components can be ommited, in which case
they will default to 1 or 0 as appropriate.
sourceraw docstring

milliscljs

(millis)
(millis n)

Given a number, returns a Period representing that many milliseconds. Without an argument, returns a Period representing only milliseconds.

Given a number, returns a Period representing that many milliseconds.
Without an argument, returns a Period representing only milliseconds.
sourceraw docstring

mins-agocljs

(mins-ago d)
source

minuscljs

(minus dt p)
(minus dt p & ps)

Returns a new date/time object corresponding to the given date/time moved backwards by the given Period(s).

Returns a new date/time object corresponding to the given date/time
moved backwards by the given Period(s).
sourceraw docstring

minutescljs

(minutes)
(minutes n)

Given a number, returns a Period representing that many minutes. Without an argument, returns a Period representing only minutes.

Given a number, returns a Period representing that many minutes.
Without an argument, returns a Period representing only minutes.
sourceraw docstring

minutes?cljs

(minutes? val)

Returns true if the given value is an instance of Minutes

Returns true if the given value is an instance of Minutes
sourceraw docstring

monthscljs

(months)
(months n)

Given a number, returns a Period representing that many months. Without an argument, returns a Period representing only months.

Given a number, returns a Period representing that many months.
Without an argument, returns a Period representing only months.
sourceraw docstring

months?cljs

(months? val)

Returns true if the given value is an instance of Months

Returns true if the given value is an instance of Months
sourceraw docstring

nowcljs

(now)

Returns a DateTime for the current instant in the UTC time zone.

Returns a DateTime for the current instant in the UTC time zone.
sourceraw docstring

number-of-days-in-the-monthcljs

(number-of-days-in-the-month dt)
(number-of-days-in-the-month year month)
source

offset-ms-fncljs

(offset-ms-fn offset)
source

overlapcljs

(overlap i-a i-b)

Returns an Interval representing the overlap of the specified Intervals. Returns nil if the Intervals do not overlap. The first argument must not be nil. If the second argument is nil then the overlap of the first argument and a zero duration interval with both start and end times equal to the current time is returned.

Returns an Interval representing the overlap of the specified Intervals.
Returns nil if the Intervals do not overlap.
The first argument must not be nil.
If the second argument is nil then the overlap of the first argument
and a zero duration interval with both start and end times equal to the
current time is returned.
sourceraw docstring

overlaps?cljs

(overlaps? {start-a :start end-a :end} {start-b :start end-b :end})
(overlaps? start-a end-a start-b end-b)

With 2 arguments: Returns true of the two given Intervals overlap. Note that intervals that satisfy abuts? do not satisfy overlaps?

With 4 arguments: Returns true if the range specified by start-a and end-a overlaps with the range specified by start-b and end-b.

With 2 arguments: Returns true of the two given Intervals overlap.
Note that intervals that satisfy abuts? do not satisfy overlaps?

With 4 arguments: Returns true if the range specified by start-a and end-a
overlaps with the range specified by start-b and end-b.
sourceraw docstring

Periodcljs

source

periodcljs

(period period value)
(period p1 v1 & kvs)
source

period-fncljs

(period-fn p)
source

period-fnscljs

source

period-type?cljs

(period-type? type x)
source

period?cljs

(period? x)
source

periodscljs

source

pluscljs

(plus dt p)
(plus dt p & ps)

Returns a new date/time corresponding to the given date/time moved forwards by the given Period(s).

Returns a new date/time corresponding to the given date/time moved
forwards by the given Period(s).
sourceraw docstring

secondscljs

(seconds)
(seconds n)

Given a number, returns a Period representing that many seconds. Without an argument, returns a Period representing only seconds.

Given a number, returns a Period representing that many seconds.
Without an argument, returns a Period representing only seconds.
sourceraw docstring

seconds?cljs

(seconds? val)

Returns true if the given value is an instance of Seconds

Returns true if the given value is an instance of Seconds
sourceraw docstring

startcljs

(start in)

Returns the start DateTime of an Interval.

Returns the start DateTime of an Interval.
sourceraw docstring

static-ms-fncljs

(static-ms-fn ms)
source

time-nowcljs

(time-now)

Returns a local DateTime for the current instant without date or time zone in the current time zone.

Returns a local DateTime for the current instant without date or time zone
in the current time zone.
sourceraw docstring

time-zone-for-offsetcljs

(time-zone-for-offset hours)
(time-zone-for-offset hours minutes)

Returns a timezone map for the given offset, specified either in hours or hours and minutes.

Returns a timezone map for the given offset, specified either in hours or
hours and minutes.
sourceraw docstring

to-default-time-zonecljs

(to-default-time-zone dt)

Assuming dt is in the UTC timezone, returns a DateTime corresponding to the same absolute instant in time as the given DateTime, but with calendar fields corresponding to the default (local) timezone.

Assuming `dt` is in the UTC timezone, returns a DateTime
corresponding to the same absolute instant in time as the given
DateTime, but with calendar fields corresponding to the default
(local) timezone.
sourceraw docstring

to-utc-time-zonecljs

(to-utc-time-zone dt)

Assuming dt is in the Local timezone, returns a UtcDateTime corresponding to the same absolute instant in time as the given DateTime, but with calendar fields corresponding to the UTC timezone.

Assuming `dt` is in the Local timezone, returns a UtcDateTime
corresponding to the same absolute instant in time as the given
DateTime, but with calendar fields corresponding to the UTC
timezone.
sourceraw docstring

todaycljs

(today)

Constructs and returns a new goog.date.Date representing today in the local timezone.

Constructs and returns a new goog.date.Date representing today in the local timezone.
sourceraw docstring

today-atcljs

(today-at hours minutes)
(today-at hours minutes seconds)
(today-at hours minutes seconds millis)
source

today-at-midnightcljs

(today-at-midnight)

Returns a DateTime for today at midnight in the UTC time zone.

Returns a DateTime for today at midnight in the UTC time zone.
sourceraw docstring

utccljs

source

weekscljs

(weeks)
(weeks n)

Given a number, returns a Period representing that many weeks. Without an argument, returns a Period representing only weeks.

Given a number, returns a Period representing that many weeks.
Without an argument, returns a Period representing only weeks.
sourceraw docstring

weeks?cljs

(weeks? val)

Returns true if the given value is an instance of Weeks

Returns true if the given value is an instance of Weeks
sourceraw docstring

within?cljs

(within? {:keys [start end]} date)
(within? start end date)

With 2 arguments: Returns true if the given Interval contains the given DateTime. Note that if the DateTime is exactly equal to the end of the interval, this function returns false.

With 3 arguments: Returns true if the start DateTime is equal to or before and the end DateTime is equal to or after the test DateTime.

With 2 arguments: Returns true if the given Interval contains the given
DateTime. Note that if the DateTime is exactly equal to the
end of the interval, this function returns false.

With 3 arguments: Returns true if the start DateTime is
equal to or before and the end DateTime is equal to or after the test
DateTime.
sourceraw docstring

yearscljs

(years)
(years n)

Given a number, returns a Period representing that many years. Without an argument, returns a Period representing only years.

Given a number, returns a Period representing that many years.
Without an argument, returns a Period representing only years.
sourceraw docstring

years?cljs

(years? val)

Returns true if the given value is an instance of Years

Returns true if the given value is an instance of Years
sourceraw docstring

yesterdaycljs

(yesterday)

Returns a DateTime for yesterday relative to now

Returns a DateTime for yesterday relative to now
sourceraw docstring

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

× close