Completed years from a birth Day to a Day, with an explicit leap policy.
The leap policy is REQUIRED, with no default: a birth on 29 February has no anniversary in a common year, and WHICH day it completes on is a legal statement, not arithmetic. The statute lives in the consumer (calendario binds :leap/mar-01, Codigo Civil art. 132 paragraph 3); the arithmetic lives here.
:leap/feb-28 -- the birthday falls on 28 February in a common year; :leap/mar-01 -- it falls on 1 March (the next day).
The arithmetic stays integer calendar arithmetic: y = day.year - birth.year, minus 1 when the (month, day) pair has not yet arrived. Never days/365.25, never day-of-year, never a plusYears loop.
A missing or unknown policy is refused with its OWN reason (:time/leap-policy-missing, :time/leap-policy-unknown), distinct from the before-birth refusal (:time/age-before-birth).
Completed years from a birth Day to a Day, with an explicit leap policy. The leap policy is REQUIRED, with no default: a birth on 29 February has no anniversary in a common year, and WHICH day it completes on is a legal statement, not arithmetic. The statute lives in the consumer (calendario binds :leap/mar-01, Codigo Civil art. 132 paragraph 3); the arithmetic lives here. :leap/feb-28 -- the birthday falls on 28 February in a common year; :leap/mar-01 -- it falls on 1 March (the next day). The arithmetic stays integer calendar arithmetic: y = day.year - birth.year, minus 1 when the (month, day) pair has not yet arrived. Never days/365.25, never day-of-year, never a plusYears loop. A missing or unknown policy is refused with its OWN reason (:time/leap-policy-missing, :time/leap-policy-unknown), distinct from the before-birth refusal (:time/age-before-birth).
The Clock port: the one way the library reads the current instant.
A port is the only way the library reaches the world. The clock comes from a Clock, never from a direct System/currentTimeMillis call: the protocol IS the seam, so a test swaps behaviour with a VALUE (fixed-clock), never a with-redefs and never a dynamic var.
now returns epoch milliseconds, the same unit the instant codec uses.
today(clock, zone) is the ONE place a clock read meets a zone: it reads the
clock and turns the instant into the Day in zone. It lives here (not in
zone.cljc) because it is a clock read first; zone is required only to
interpret the instant.
The Clock port: the one way the library reads the current instant. A port is the only way the library reaches the world. The clock comes from a Clock, never from a direct System/currentTimeMillis call: the protocol IS the seam, so a test swaps behaviour with a VALUE (fixed-clock), never a with-redefs and never a dynamic var. now returns epoch milliseconds, the same unit the instant codec uses. today(clock, zone) is the ONE place a clock read meets a zone: it reads the clock and turns the instant into the Day in `zone`. It lives here (not in zone.cljc) because it is a clock read first; zone is required only to interpret the instant.
The ISO-8601 text codecs: between the ISO form on the wire and the value objects.
Pure. The regexes are the oracle's (tools/golden_check.clj): the golden table is the truth, and a parser that disagrees with it is the parser that is wrong.
There is no format here: a cljc pad keeps clj and cljs emitting the
same bytes.
Only the GENERIC ISO half lives here. The pt-BR half (br->dia, dia->br, competencia->br, competencia->extenso) and the wire parse (iso->periodo) stay in calendario's Portuguese facade.
Map keys are the generic English names (:year :month :day, :start :end).
The ISO-8601 text codecs: between the ISO form on the wire and the value objects. Pure. The regexes are the oracle's (tools/golden_check.clj): the golden table is the truth, and a parser that disagrees with it is the parser that is wrong. There is no `format` here: a cljc `pad` keeps clj and cljs emitting the same bytes. Only the GENERIC ISO half lives here. The pt-BR half (br->dia, dia->br, competencia->br, competencia->extenso) and the wire parse (iso->periodo) stay in calendario's Portuguese facade. Map keys are the generic English names (:year :month :day, :start :end).
The facade: the library's public API, one entry point.
This namespace re-exports the op table -- the GENERIC half (18 ops) that lives in this coordinate. Every op carries an m/=> contract (malli), so the shape of each argument and return is stated once, here, and a consumer (reitit, the calendario facade) can read it. The FUNERARIA half (br->dia, dia->br, competencia->br, competencia->extenso, instante->br, vencimento-em, vencido?, prazo, data-reajuste, fb-timestamp->dia) stays in calendario and is NOT here.
Which ops are in the facade: the 18 op-table ops, nothing else. Supporting API (->day, day?, epoch, days-in-month, add-months, ->zone, zone?, offset-ms, instant->local, day-start, the instant codec parse-instant/format-instant, the codec pads) is reached through its own namespace, not re-exported.
offset-ms is PUBLIC in zone.cljc but is NOT one of the 28 op-table ops: no op in the table needs it as a consumer entry point (period->instant-interval and day->instant go through day-start), so it stays OUT of the facade. The instant codec is the same case: parse-instant / format-instant have no op of their own in the table (they are used by day->instant / instant->*), so they stay in instant.cljc, OUT of the facade. A consumer that wants either imports hive-ttracking.time.zone / hive-ttracking.time.instant directly.
The value-object schemas of schema.cljc are re-exported below as a convenience, so a consumer can validate with one require.
The facade: the library's public API, one entry point. This namespace re-exports the op table -- the GENERIC half (18 ops) that lives in this coordinate. Every op carries an m/=> contract (malli), so the shape of each argument and return is stated once, here, and a consumer (reitit, the calendario facade) can read it. The FUNERARIA half (br->dia, dia->br, competencia->br, competencia->extenso, instante->br, vencimento-em, vencido?, prazo, data-reajuste, fb-timestamp->dia) stays in calendario and is NOT here. Which ops are in the facade: the 18 op-table ops, nothing else. Supporting API (->day, day?, epoch, days-in-month, add-months, ->zone, zone?, offset-ms, instant->local, day-start, the instant codec parse-instant/format-instant, the codec pads) is reached through its own namespace, not re-exported. offset-ms is PUBLIC in zone.cljc but is NOT one of the 28 op-table ops: no op in the table needs it as a consumer entry point (period->instant-interval and day->instant go through day-start), so it stays OUT of the facade. The instant codec is the same case: parse-instant / format-instant have no op of their own in the table (they are used by day->instant / instant->*), so they stay in instant.cljc, OUT of the facade. A consumer that wants either imports hive-ttracking.time.zone / hive-ttracking.time.instant directly. The value-object schemas of schema.cljc are re-exported below as a convenience, so a consumer can validate with one require.
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.The one refusal of the time core.
A refusal is an ex-info carrying :time/reason -- the CLOSED vocabulary below -- and :autonomous/error with the SAME value, so the autonomous runtime turns the throw into the right kind of refusal (autonomous.domain.answer/from-exception).
A reason outside the vocabulary is not a refusal: it is a caller defect, and becomes an ordinary ex-info with no :time/reason. A designed refusal is always recognisable; a defect never passes for one.
Closed sets are malli :enum, never hive-dsl defadt: hive-dsl 0.6.2 pulls data.json and core.async into every cljs client, too heavy to buy keyword dispatch for a handful of sets.
The one refusal of the time core. A refusal is an ex-info carrying :time/reason -- the CLOSED vocabulary below -- and :autonomous/error with the SAME value, so the autonomous runtime turns the throw into the right kind of refusal (autonomous.domain.answer/from-exception). A reason outside the vocabulary is not a refusal: it is a caller defect, and becomes an ordinary ex-info with no :time/reason. A designed refusal is always recognisable; a defect never passes for one. Closed sets are malli :enum, never hive-dsl defadt: hive-dsl 0.6.2 pulls data.json and core.async into every cljs client, too heavy to buy keyword dispatch for a handful of sets.
The instant codec: an RFC 3339 instant <-> epoch milliseconds.
Pure on both legs: epoch-day arithmetic, no platform at all, no zone. A
pad keeps clj and cljs emitting the same bytes (no format).
This is the shape of java.time.Instant/toString: YYYY-MM-DDTHH:MM:SSZ,
with .mmm appended only when the millisecond-of-second is non-zero. A test
asserts that equality against java.time on the RFC 3339 samples (clj leg).
The instant codec: an RFC 3339 instant <-> epoch milliseconds. Pure on both legs: epoch-day arithmetic, no platform at all, no zone. A `pad` keeps clj and cljs emitting the same bytes (no `format`). This is the shape of `java.time.Instant/toString`: YYYY-MM-DDTHH:MM:SSZ, with `.mmm` appended only when the millisecond-of-second is non-zero. A test asserts that equality against java.time on the RFC 3339 samples (clj leg).
The Month: the month a charge refers to, the way a person says it ("the July 2026 instalment"). A MONTH, never an instant.
A month written as 01T00:00Z and read at UTC-3 shows the PREVIOUS month -- which is the whole reason a month is not an instant.
Map keys are the generic English names (:year :month).
The Month: the month a charge refers to, the way a person says it ("the
July 2026 instalment"). A MONTH, never an instant.
A month written as 01T00:00Z and read at UTC-3 shows the PREVIOUS month --
which is the whole reason a month is not an instant.
Map keys are the generic English names (:year :month).The Period: a CLOSED interval of days, "from 01/11 to 25/11", both ends included. Half-open is a property of the interval of INSTANTS a Period becomes under a zone, never of the Period.
Both ends are required: a missing end is a REFUSAL, never an open interval -- it is not "up to today".
Map keys are the generic English names (:start :end).
The Period: a CLOSED interval of days, "from 01/11 to 25/11", both ends included. Half-open is a property of the interval of INSTANTS a Period becomes under a zone, never of the Period. Both ends are required: a missing end is a REFUSAL, never an open interval -- it is not "up to today". Map keys are the generic English names (:start :end).
The validating malli schemas for the time core's value objects.
Every schema here is CLOSED and validating, never shape-only: [:and [:map {:closed true} ...] [:fn pred?]] -- the closed map pins the shape (no stray keys) and the predicate pins the invariant, so a map that LOOKS right but is not a real Day (2026-02-31, year 1) fails. Consumers (reitit, the facade, calendario's wire layer) validate against these; the library itself does not depend on them.
Reuse, never duplicate: the Zone and Local schemas are the ones zone.cljc already defined and exports, and the closed sets (:enum) are the ones error.cljc (Reason) and age.cljc (policies) already defined. Only Day, Month, TimeOfDay and Period are NEW here, built on the predicates the earlier steps exported (day?, month?, time-of-day?, period?).
An Instant is NOT a value object: it is epoch milliseconds, a long. So there is no Instant schema; the instant CODEC (parse-instant / format-instant) is in instant.cljc.
Closed sets are malli :enum, never hive-dsl defadt: hive-dsl 0.6.2 pulls data.json and core.async into every cljs client, too heavy to buy keyword dispatch for a handful of sets.
The validating malli schemas for the time core's value objects.
Every schema here is CLOSED and validating, never shape-only:
[:and [:map {:closed true} ...] [:fn pred?]] -- the closed map pins the shape
(no stray keys) and the predicate pins the invariant, so a map that LOOKS
right but is not a real Day (2026-02-31, year 1) fails. Consumers (reitit,
the facade, calendario's wire layer) validate against these; the library
itself does not depend on them.
Reuse, never duplicate: the Zone and Local schemas are the ones zone.cljc
already defined and exports, and the closed sets (:enum) are the ones
error.cljc (Reason) and age.cljc (policies) already defined. Only Day,
Month, TimeOfDay and Period are NEW here, built on the predicates the earlier
steps exported (day?, month?, time-of-day?, period?).
An Instant is NOT a value object: it is epoch milliseconds, a long. So there
is no Instant schema; the instant CODEC (parse-instant / format-instant) is
in instant.cljc.
Closed sets are malli :enum, never hive-dsl defadt: hive-dsl 0.6.2 pulls
data.json and core.async into every cljs client, too heavy to buy keyword
dispatch for a handful of sets.The TimeOfDay: a time of day with no date and no zone. "08:30", "23:59:59".
Map keys are the generic English names (:hour :minute :second).
The TimeOfDay: a time of day with no date and no zone. "08:30", "23:59:59". Map keys are the generic English names (:hour :minute :second).
The zone seam: the ONE place the library touches the platform.
Every other namespace is pure. Here lives the bridge between a Day and an instant, and it is a FUNCTION OF A LIBRARY, never a field of a Day.
The zone is ALWAYS an explicit argument: ttrack has NO default zone. A library that silently reaches for America/Sao_Paulo is exactly the coupling this coordinate was carved out to break.
The two rules the dst-* rows fix, on BOTH legs:
clj leg: java.time ZoneId / LocalDateTime with getValidOffsets. cljs leg: Intl.DateTimeFormat with formatToParts, hourCycle h23, cached per zone in a js/Map, plus a two-candidate offset search. NO tz library -- the zone rules come from the engine's ICU tzdata.
Map keys are the generic English names (:year :month :day, :hour :minute :second, :start :end).
The zone seam: the ONE place the library touches the platform.
Every other namespace is pure. Here lives the bridge between a Day and an
instant, and it is a FUNCTION OF A LIBRARY, never a field of a Day.
The zone is ALWAYS an explicit argument: ttrack has NO default zone. A
library that silently reaches for America/Sao_Paulo is exactly the coupling
this coordinate was carved out to break.
The two rules the dst-* rows fix, on BOTH legs:
- a gap (DST start) is an EXPLICIT error (:time/zone-gap), never a silent
shift of the wall clock;
- in an overlap (DST end) the EARLIEST offset wins, deterministically
(java.time's default; the cljs two-candidate search's min).
clj leg: java.time ZoneId / LocalDateTime with getValidOffsets.
cljs leg: Intl.DateTimeFormat with formatToParts, hourCycle h23, cached per
zone in a js/Map, plus a two-candidate offset search. NO tz library -- the
zone rules come from the engine's ICU tzdata.
Map keys are the generic English names (:year :month :day, :hour :minute
:second, :start :end).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 |