API reference@evolu/commonType › DateIso

const DateIso:  brand(
  "DateIso",
  String,
  (value) =>
    value.length === 24 && new globalThis.Date(value).toJSON() === value
      ? ok()
      : err<DateIsoError>({ type: "DateIso", value }),
  (error) =>
    The value ${safelyStringifyUnknownValue(error.value)} is not a canonical ISO date-time string.,
) ;

Defined in: packages/common/src/Type.ts:5009

Canonical ISO date-time String.

Uses the YYYY-MM-DDTHH:mm:ss.sssZ format. Date-only strings, timezone offsets, and extended-year forms are rejected. The fixed-width UTC form sorts chronologically as text, which is useful for SQLite and other stores without a dedicated date-time representation.

Valid values range from "0000-01-01T00:00:00.000Z" through "9999-12-31T23:59:59.999Z".

Example

import {
  assertEqual,
  assertErr,
  assertOk,
  assertType,
  Data,
  DateIso,
} from "@evolu/common";

const value = "2023-01-01T12:00:00.000Z";
assertOk(DateIso.fromUnknown(value), value);
const invalid = DateIso.fromUnknown("2023-01-01");
assertErr(invalid);
assertType(Data, invalid.error);
assertEqual(invalid.error, {
  type: "DateIso",
  value: "2023-01-01",
});