class / @typed/id/DateTimes

DateTimes

Effect service for current epoch milliseconds and Date values.

Package version
1.0.0-beta.13
Category
Time services
Since
1.0.0

Import

import { DateTimes } from "@typed/id/DateTimes";

Signatures

export declare class DateTimes extends DateTimes_base {
    static readonly now: Effect.Effect<number, never, DateTimes>;
    static readonly date: Effect.Effect<Date, never, DateTimes>;
    static readonly Default: Layer.Layer<DateTimes, never, never>;
    static readonly Fixed: (baseDate: number | string | Date) => Layer.Layer<DateTimes, Cause.IllegalArgumentError, never>;
}

Why

Making time a service keeps time-based ID generators deterministic under tests and explicit under server or browser runtimes.

Ownership and lifetime

A DateTimes Layer owns its time source for the Layer lifetime; individual reads acquire no resources.

Property: Default

Provides DateTimes using the runtime wall clock.

Property: Default: Why

The production default is explicit and replaceable rather than hidden in each generator.

Property: Default: Ownership and lifetime

The surrounding Layer Scope owns the service; reads allocate only their returned Date values.

Property: Fixed

Provides DateTimes anchored to a base date and advanced by Effect Clock.

Property: Fixed: Why

Clock-relative time supports deterministic tests while still allowing controlled advancement; invalid bases fail with IllegalArgumentError.

Property: Fixed: Ownership and lifetime

Layer acquisition captures the base and current Clock reading; the surrounding Layer Scope owns that state.

Property: date

Reads a Date from the current DateTimes service.

Property: date: Why

The Date view stays aligned with the same replaceable time source as epoch-millisecond reads.

Property: date: Ownership and lifetime

This Effect acquires no resources and uses the DateTimes service for one invocation.

Property: now

Reads epoch milliseconds from the current DateTimes service.

Property: now: Why

A service-backed read avoids hard-wiring Date.now into generators and tests.

Property: now: Ownership and lifetime

This Effect acquires no resources and uses the DateTimes service for one invocation.

Examples

import { DateTimes } from "@typed/id/DateTimes"
import { Effect } from "effect"
const now = Effect.provide(DateTimes.now, DateTimes.Default)

See Effect Clock.

import { DateTimes } from "@typed/id/DateTimes"
const fixed = DateTimes.Fixed("2026-01-01T00:00:00Z")

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source