The Day, and calendar arithmetic over it.
A Day is {:year int :month int :day int}, the calendar day as a person says it. It carries no zone, ever: the ambiguity that comes from writing a day as midnight in one zone and reading it in another is the whole reason a day is not an instant.
The arithmetic is by epoch-day, integer (Hinnant days_from_civil / civil_from_days): no floats, no js/Date, no java.time. That is why the same function answers the same in clj and cljs, and why a day does not depend on the process zone.
The map keys are the generic English names (:year :month :day). calendario's Portuguese facade renames them at its own boundary.
The Day, and calendar arithmetic over it.
A Day is {:year int :month int :day int}, the calendar day as a person says
it. It carries no zone, ever: the ambiguity that comes from writing a day as
midnight in one zone and reading it in another is the whole reason a day is
not an instant.
The arithmetic is by epoch-day, integer (Hinnant days_from_civil /
civil_from_days): no floats, no js/Date, no java.time. That is why the same
function answers the same in clj and cljs, and why a day does not depend on
the process zone.
The map keys are the generic English names (:year :month :day). calendario's
Portuguese facade renames them at its own boundary.(->day year month day)Validating constructor. Checks IMPOSSIBLE first (a LocalDate/of would throw), then the range: a year outside 1900..2199 -> :time/day-out-of-range; a month outside 1..12 or a day outside 1..(days-in-month) -> :time/day-impossible. The order is the oracle's: 0001-01-01 -> :time/day-out-of-range, 2026-02-31 -> :time/day-impossible, 13/13/2026 -> :time/day-impossible.
Validating constructor. Checks IMPOSSIBLE first (a LocalDate/of would throw), then the range: a year outside 1900..2199 -> :time/day-out-of-range; a month outside 1..12 or a day outside 1..(days-in-month) -> :time/day-impossible. The order is the oracle's: 0001-01-01 -> :time/day-out-of-range, 2026-02-31 -> :time/day-impossible, 13/13/2026 -> :time/day-impossible.
(add-days d n)d plus n days, revalidated by ->day (range).
`d` plus `n` days, revalidated by ->day (range).
(compare-day a b)Day comparator: negative when a < b.
Day comparator: negative when `a` < `b`.
(day-of-week d)ISO day of week: 1=Monday .. 7=Sunday. 1970-01-01 was a Thursday (=4).
ISO day of week: 1=Monday .. 7=Sunday. 1970-01-01 was a Thursday (=4).
(day? x)True when x is structurally a Day AND a real day in range. Never throws.
True when `x` is structurally a Day AND a real day in range. Never throws.
(days-between from to)Exact days from from to to: may be negative. Never ms/86400000.
Exact days from `from` to `to`: may be negative. Never ms/86400000.
(days-in-month year month)How many days month has in year.
How many days `month` has in `year`.
(epoch d)The epoch-day of an already-built Day.
The epoch-day of an already-built Day.
(epoch-day year month day)Days since 1970-01-01 (epoch-day). Hinnant days_from_civil, integer.
Days since 1970-01-01 (epoch-day). Hinnant days_from_civil, integer.
(from-epoch-day n)The Day of an epoch-day. Hinnant civil_from_days, integer.
The Day of an epoch-day. Hinnant civil_from_days, integer.
(leap-year? year)True when year is a leap year in the Gregorian calendar.
True when `year` is a leap year in the Gregorian calendar.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |