Aller au contenu
Krizaka TypeScript
Krizaka TypeScript

@krizaka/time

L’arithmétique des dates sur un instant, exacte dans tous les fuseaux : la façade que pointe la règle « Krizaka d’abord » des dates.

Installer

bashTerminal
npm install @krizaka/time

Le README ci-dessous est celui du paquet sur npm, en anglais.

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

Les 16 noms que le paquet exporte, lus dans ses types.

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

Paquet

Version sur npm0.2.0 (npm)
LicenceApache-2.0
Node.js>=22
Dépendancesdate-fns ^4.4.0
Code sourcetime

Journal des versions

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.

Sur cette page