Janet 1.41.2-0fea20c Documentation
(Other Versions: 1.41.1 1.40.1 1.40.0 1.39.1 1.38.0 1.37.1 1.36.0 1.35.0 1.34.0 1.31.0 1.29.1 1.28.0 1.27.0 1.26.0 1.25.1 1.24.0 1.23.0 1.22.0 1.21.0 1.20.0 1.19.0 1.18.1 1.17.1 1.16.1 1.15.0 1.13.1 1.12.2 1.11.1 1.10.1 1.9.1 1.8.1 1.7.0 1.6.0 1.5.1 1.5.0 1.4.0 1.3.1 )

date

Utility wrappers around `os/time` and `os/date` for working with dates, particularly formatting them as strings (with `date/to-string`) and reading dates from strings (with `date/from-string`).

Reference

date/add date/assert-date date/between? date/compare-dates date/date? date/diff date/from-string date/gt date/leap-year? date/local-now date/lt date/sub date/to-string date/utc-now


date/add function source
(add date &named years months days hours minutes seconds)

Add time to a well-formed `date` (`date`). Returns a new struct 
that will pass the `date?` validation function.

date/assert-date function source
(`assert-date` `date`)

Raises an error if `date` is not a well-formed date. Otherwise,
returns `date` unmodified.

A `date` is a struct that contains at least the following keys: 

- `:dst`
- `:year`
- `:year-day`
- `:month`
- `:month-day`
- `:week-day`
- `:hours`
- `:minutes`
- `:seconds`

The `(os/date)` function returns well-formed `date`s of this type.

date/between? function source
(between? date start end)

Given three well-formed `date`s (`date`, `start`, and `end`), 
will return `true` if `date` occurs between `start` and `end`.

date/compare-dates function source
(compare-dates d1 d2)

Compares `date` values (`d1` and `d2`).

Returns -1 if `d1` is strictly less than `d2`, 1 if `d2` is 
strictly less than `d1`, and 0 if they are exactly the same. 

date/date? function source
(`date?` `date`)

Returns a boolean indicating whether `date` is a well-formed date.

A `date` is a struct that contains at least the following keys: 

- `:dst`
- `:year`
- `:year-day`
- `:month`
- `:month-day`
- `:week-day`
- `:hours`
- `:minutes`
- `:seconds`

The `(os/date)` function returns well-formed `date`s of this type.

date/diff function source
(diff later-date earlier-date)

Subtract two well-formed `date`s (`later-date` and `earlier-date`),
returning a time in seconds. 

Not commutative, i.e., order matters. If `earlier-date` precedes 
`later-date`, the resulting duration will be negative.

date/from-string function source
(from-string date-str format-str)

Construct a well-formed `date` from a string (`date-str`), using 
a second string to indicate the format to be read (`format-str`). 
Returns a new struct that will pass the `date?` validation function. 

`format-str` is case sensitive and can understand any of:

- `y` = Year (either 2 or 4 characters)
- `M` = Month (between 1 and 4 characters)
- `d` = Day of month (1 or 2 characters)
- `H` = Hour, 24-hour format (1 or 2 characters)
- `h` = Hour, 12-hour format (1 or 2 characters)
- `m` = Minute (must be 2 characters)
- `s` = Second (must be 2 characters)
- `AM` or `PM` = AM/PM (either upper- or lower-case, use with `h`)

Any other characters (e.g. `:`, ` `, `,`, `-` or `/`) will be treated 
as separators and ignored.

date/gt function source
(gt & dates)

Check if `dates` is in descending order. Returns a boolean.
 
Equivalent to `(> ;(map os/mktime dates))`.

date/leap-year? function source
(leap-year? year)

Given a numeric `year`, returns a boolean indicating whether 
that year is a leap year according to the Gregorian rules.

date/local-now function source
(local-now)

Returns a well-formed date representing the current datetime in the 
local time zone. Equivalent to `(os/date nil true)`.

date/lt function source
(lt & dates)

Check if `dates` is in ascending order. Returns a boolean.
 
Equivalent to `(< ;(map os/mktime dates))`.

date/sub function source
(sub date &named years months days hours minutes seconds)

Subtract time from a well-formed `date` (`date`). Returns a new struct 
that will pass the `date?` validation function.

date/to-string function source
(to-string date format-str)

Convert a well-formed date (`date`) to a string, using a string 
(`format-str`) to indicate the expected output format. Returns a 
string representing the formatted date.

`format-str` is case sensitive and can understand any of:

- `y` = Year (either 2 or 4 characters)
- `M` = Month (between 1 and 4 characters)
- `d` = Day of month (1 or 2 characters)
- `H` = Hour, 24-hour format (1 or 2 characters)
- `h` = Hour, 12-hour format (1 or 2 characters)
- `m` = Minute (must be 2 characters)
- `s` = Second (must be 2 characters)
- `AM` or `PM` = AM/PM (either upper- or lower-case, use with `h`)

Any other characters (e.g. `:`, ` `, `,`, `-` or `/`) will be 
treated as separators and preserved identically.

date/utc-now function source
(utc-now)

Returns a well-formed `date` representing the current datetime in UTC. 
Equivalent to `(os/date)`.