Metakit / @doeixd/metakit

Time

namespace · packages/metakit/src/ops/time.ts:11

export * as Time from './ops/time.js'

Calendar-day time operations (time.*): addDays, addMonths (clamped to month-end), daysBetween, startOfMonth, and half-open overlaps.

Dates are integer epoch days (days since 1970-01-01, matching CalendarDay). Calendar arithmetic (addMonths, startOfMonth) uses Howard Hinnant's exact proleptic Gregorian integer formulas over years 0001–9999 (-719_162 .. 2_932_896), matching SQLite and Postgres with zero timezone dependence.

Members

Time.addDays

function · packages/metakit/src/ops/time.ts:198

function addDays<D extends NullableNumber, N extends NullableNumber>(
  day: D,
  days: N,
): Expr<EnvOfInput<D> & EnvOfInput<N>, number | NullOf<D> | NullOf<N>>

Add an integer number of days to a calendar day.

Time.addDaysOp

const · packages/metakit/src/ops/time.ts:114

const addDaysOp = { id, returns, nulls, evaluate }

Time.addMonths

function · packages/metakit/src/ops/time.ts:205

function addMonths<D extends NullableNumber, N extends NullableNumber>(
  day: D,
  months: N,
): Expr<EnvOfInput<D> & EnvOfInput<N>, number | NullOf<D> | NullOf<N>>

Add an integer number of months to a calendar day, clamping to the target month's end.

Time.addMonthsInt

function · packages/metakit/src/ops/time.ts:77

function addMonthsInt(day: number, months: number): number | Node.Refusal

Add months to epoch day day, clamping to the target month's last day.

Time.addMonthsOp

const · packages/metakit/src/ops/time.ts:135

const addMonthsOp = { id, returns, nulls, evaluate }

Time.civilToDays

function · packages/metakit/src/ops/time.ts:43

function civilToDays(y: number, m: number, d: number): number

Convert a proleptic Gregorian [year, month, day] to an epoch day (0 = 1970-01-01).

Time.daysBetween

function · packages/metakit/src/ops/time.ts:212

function daysBetween<A extends NullableNumber, B extends NullableNumber>(
  a: A,
  b: B,
): Expr<EnvOfInput<A> & EnvOfInput<B>, number | NullOf<A> | NullOf<B>>

Signed day difference a - b in days.

Time.daysBetweenOp

const · packages/metakit/src/ops/time.ts:148

const daysBetweenOp = { id, returns, nulls, evaluate }

Time.daysToCivil

function · packages/metakit/src/ops/time.ts:27

function daysToCivil(z: number): readonly [number, number, number]

Convert an epoch day (0 = 1970-01-01) to proleptic Gregorian [year, month, day].

Time.EARLIEST_DAY

const · packages/metakit/src/ops/time.ts:17

const EARLIEST_DAY: -719162

0001-01-01 as an epoch day.

Time.LATEST_DAY

const · packages/metakit/src/ops/time.ts:19

const LATEST_DAY: 2932896

9999-12-31 as an epoch day.

Time.overlaps

function · packages/metakit/src/ops/time.ts:224

function overlaps<
  S1 extends ExprInput<never, number | null>,
  E1 extends ExprInput<never, number | null>,
  S2 extends ExprInput<never, number | null>,
  E2 extends ExprInput<never, number | null>,
>(
  s1: S1,
  e1: E1,
  s2: S2,
  e2: E2,
): Expr<
  EnvOfInput<S1> & EnvOfInput<E1> & EnvOfInput<S2> & EnvOfInput<E2>,
  boolean | NullOf<S1> | NullOf<E1> | NullOf<S2> | NullOf<E2>
>

Whether half-open ranges [s1, e1) and [s2, e2) overlap (s1 < e2 && s2 < e1).

Time.overlapsOp

const · packages/metakit/src/ops/time.ts:180

const overlapsOp = { id, returns, nulls, evaluate }

Time.startOfMonth

function · packages/metakit/src/ops/time.ts:219

function startOfMonth<D extends NullableNumber>(
  day: D,
): Expr<EnvOfInput<D>, number | NullOf<D>>

First day of the calendar month holding day.

Time.startOfMonthInt

function · packages/metakit/src/ops/time.ts:106

function startOfMonthInt(day: number): number | Node.Refusal

First day of the calendar month holding epoch day day.

Time.startOfMonthOp

const · packages/metakit/src/ops/time.ts:169

const startOfMonthOp = { id, returns, nulls, evaluate }