Skip to the content
Krizaka TypeScript
Krizaka TypeScript

@krizaka/time

Date arithmetic on an instant, exact in any time zone: the facade the « Krizaka first » dates rule points to.

Install

bashTerminal
npm install @krizaka/time

Date arithmetic for every Krizaka backend, in one place. The « Krizaka first » dates rule (@krizaka/config) refuses a date library inside a package; this is the facade it points to, so addSeconds, addHours, differenceInSeconds and isBefore are written once and the library behind them can change without touching a package.

import { addSeconds, differenceInSeconds, isBefore } from "@krizaka/time";

const resetAt = addSeconds(clock.now(), 900);
if (isBefore(resetAt, clock.now())) { /* ended */ }
const retryAfter = differenceInSeconds(resetAt, clock.now());
  • Exact on the instant. Adding two hours adds 7 200 000 ms whatever the server's time zone, so « a session of 14 days » is addHours(now, 14 * 24) and lasts the same on every server, across a daylight-saving change.
  • Not the calendar. The day a law, a deadline or a receipt means, in a person's zone, is not arithmetic on an instant: use localDay of @krizaka/intl. For that reason there is no addDays here.
  • Missing function? Add it here first (with its test), never import the library beside it.
  • Pure: no clock of its own (take a Clock from @krizaka/db), no environment, no I/O.

Validation shapes

isIsoDate (YYYY-MM-DD), isEmail, isHttpUrl, isSlug, isE164Phone, isCanadianPostalCode: type guards on unknown, pure, no I/O. The no-hand-written-validation-regex rule of @krizaka/config refuses a hand-written pattern for these shapes and points here. An email check says the shape is right, never that the mailbox exists. Missing a fact? Add it here first, with its test.

Exports

The 16 names the package exports, read from its types.

NameKindWhat it is
addHourstype
addMinutestype
addSecondstype
differenceInMillisecondstype
differenceInSecondstype
isAftertype
isBeforetype
isCanadianPostalCodefunctionTrue for a Canadian postal code (H2T 1S6, with or without the space).
isE164PhonefunctionTrue for an international phone number in E.164 form (+14185551234).
isEmailfunctionTrue for [email protected] (no spaces, one @, a dotted domain).
isHttpUrlfunctionTrue for an absolute http: or https: URL that the platform's URL parser accepts.
isIsoDatefunctionTrue when value is a real calendar date written YYYY-MM-DD (2026-02-30 is not).
isSlugfunctionTrue for a lowercase URL slug: letters and digits separated by single hyphens.
subHourstype
subMinutestype
subSecondstype

Package

Version on npm0.2.0 (npm)
LicenceApache-2.0
Node.js>=22
Dependenciesdate-fns ^4.4.0
Sourcetime

Changelog

0.2.0

Minor changes

  • isIsoDate, isEmail, isHttpUrl, isSlug, isE164Phone, isCanadianPostalCode: the helpers the new no-hand-written-validation-regex rule points to (krizaka/.github#422).

0.1.0

Minor changes

  • New package: date arithmetic on an instant (addSeconds, addMinutes, addHours, subSeconds, subMinutes, subHours, differenceInSeconds, differenceInMilliseconds, isBefore, isAfter), exact in any time zone: the facade the « Krizaka first » dates rule points to (krizaka-ts#76), so the new packages import no date library of their own.

On this page