API reference › @evolu/common › Type › DateIsoFromDate
const DateIsoFromDate: transform(
"DateIsoFromDate",
Date,
DateIso,
{
from: (value) =>
trySync(
() => globalThis.Date.prototype.toISOString.call(value),
(): DateIsoFromDateError => ({ type: "DateIsoFromDate", value }),
),
to: (value) => new globalThis.Date(value),
},
() => "The Date cannot be represented as DateIso.",
);
Defined in: packages/common/src/Type.ts:5047
Safely transforms a Date into a canonical DateIso.
Example
import { assertEqual, assertOk, DateIsoFromDate } from "@evolu/common";
const date = new Date("2025-01-01T12:00:00.000Z");
const result = DateIsoFromDate.fromUnknown(date);
assertOk(result, "2025-01-01T12:00:00.000Z");
assertEqual(DateIsoFromDate.to(result.value), date);