@arki/date
For @arki/[email protected] · source AGENTS.md
AGENTS.md = laws, docs/agent-guide.md = tasks, llms.txt = map.
@arki/date
Date and time math on Temporal values, with one arithmetic policy. Read docs/agent-guide.md for tasks. When a doc and the code disagree, src/index.ts wins.
Laws
- Values are Temporal's own types:
PlainDate,PlainDateTime,ZonedDateTime,Instant,Duration. The package adds no parallel classes. The only shape it adds isInterval<T> = { start, end }. - No hidden now. Time comes from an
@arki/clockClockthat the caller passes. Never callDate.now()ornew Date()for logic insrc/. - No hidden zone. A zone-less string is never guessed into a zone. Functions that need a zone take it as an argument.
systemTimeZone()is the only door to the runtime zone, and it says so. - Overflow clamps by default and
{ overflow: 'reject' }throws. Every function that does arithmetic follows that one rule. - Calendar units move the wall clock and exact units move the instant.
diffcounts calendar units anddiffElapsedcounts exact time. A function states which. - Intervals are half-open:
[start, end). Touching intervals do not overlap.unionnever bridges a gap. - Iteration is lazy and bounded. More than
maxItemsthrows. Nothing truncates silently. - Invalid input throws
RangeError. Mixed kinds throwTypeError. Thetry*functions returnundefinedand are the only non-throwing doors. - The default locale is
en-US, so a server and a client render the same text. A caller passes its own locale. - The runtime floor is
ECMAScriptplusIntl.temporal-polyfillsuppliesTemporalwhere the engine has none. Nonode:*import in portable entries. - The optional subpaths (
zod,react,orpc,tanstack) keep their peers optional and are not re-exported from the root. - The token formatter and
parseISOstay differential-tested against date-fns. A change to either needs a new row in the comparison. - Never write benchmark numbers by hand.
bun run bench --write-readmewrites them from an idle machine. A run on a busy machine prints "Not publishable" and nobody quotes it.
Changing this package
- Pick the module (
src/math.ts,src/business.ts, and so on). One concern per module, one subpath per module. - Write the test first, next to the module. Pin the DST edge, the month-end clamp and the zone, not only the happy path.
- Keep
README.mdtruthful. Behaviour claims in the Policies section need a test. - A new module needs an
exportskey inpackage.json, a top JSDoc line and a run ofbun ../../tooling/library/src/llms.ts --write. - Update
examples/delivery-estimate.tsonly with its test. The README mirrors its region, so runarki-doc-examples --writeafter an edit. - Add a changeset in
.changeset/. Documentation-only changes usepatchand the lineno demo impact: documentation and doc-example changes only, runtime behaviour unchanged.
Verify
bun run build
bun run typecheck
bun run test
bun run test:bun
bun run test:docs
bun run test:runtimes
bun ../../tooling/library/src/llms.ts --check