API reference › @evolu/common › Type › DateIso
const DateIso: brand("DateIso", String, (value) => {
if (value.length !== 24) {
return err<DateIsoError>({ type: "DateIso", value });
}
const parsed = globalThis.Date.parse(value);
if (isNaN(parsed)) {
return err<DateIsoError>({ type: "DateIso", value });
}
// Round-trip test: ensure the string is actually a proper ISO format
const roundTrip = new globalThis.Date(parsed).toISOString();
if (roundTrip !== value) {
return err<DateIsoError>({ type: "DateIso", value });
}
return ok(value);
});
Defined in: packages/common/src/Type.ts:1185
ISO 8601 date-time string.
This Type represents a date-time string that follows the ISO 8601 format and is compatible with SQLite, which lacks a native date type and relies on ISO 8601 strings for sorting. Enforcing a 24-character format ensures correct lexicographic ordering.
It must be a valid JavaScript Date string that can be parsed.
Valid range: "0000-01-01T00:00:00.000Z" to "9999-12-31T23:59:59.999Z".
Example
const result = DateIso.from("2023-01-01T12:00:00.000Z"); // ok
const error = DateIso.from("10000-01-01T00:00:00.000Z"); // err