Date and time types
isoDate
Section titled “isoDate”A date on a calendar in ISO 8601 format YYYY-MM-DD.
A JSON example of this model.
"2025-01-01"The JSON Schema for this model.
$schema: https://json-schema.org/draft/2020-12/schema$id: isoDate.yamltype: stringformat: dateexamples: - 2025-01-01description: A date on a calendar in ISO 8601 format YYYY-MM-DDThe TypeSpec code for this model.
@example(isoDate.fromISO("2025-01-01"))@Versioning.added(CommonGrants.Versions.v0_1)scalar isoDate extends plainDate;The TypeScript code for this model.
* is rendered by `toStr` into the string format the inner schema expects. An * invalid `Date` is passed through unchanged so the inner validator rejects it, * rather than throwing a `RangeError` out of `toISOString()` and escaping * `safeParse`. Output is a `Date`.isoTime
Section titled “isoTime”A time on a clock, without a timezone, in ISO 8601 format HH:mm:ss.
A JSON example of this model.
"17:00:00"The JSON Schema for this model.
$schema: https://json-schema.org/draft/2020-12/schema$id: isoTime.yamltype: stringformat: timeexamples: - 17:00:00description: A time on a clock, without a timezone, in ISO 8601 format HH:mm:ssThe TypeSpec code for this model.
@example(isoTime.fromISO("17:00:00"))@Versioning.added(CommonGrants.Versions.v0_1)scalar isoTime extends plainTime;The TypeScript code for this model.
(toStr: (d: Date) => string) => (val: unknown): unknown => val instanceof Date && !isNaN(val.getTime()) ? toStr(val) : val;
/** Schema for UTC datetime fields (accepts an ISO string or a `Date`; outputs a `Date`) */export const UTCDateTimeSchema = z.preprocess( acceptDate(d => d.toISOString()), z.string().datetime().transform(ensureUTC)utcDateTime
Section titled “utcDateTime”A date and time with timezone in ISO 8601 format YYYY-MM-DDThh:mm:ssZ.
A JSON example of this model.
"2024-02-28T17:00:00Z"The JSON Schema for this model.
$schema: https://json-schema.org/draft/2020-12/schema$id: utcDateTime.yamltype: stringformat: date-timedescription: A date and time with timezone in ISO 8601 format YYYY-MM-DDThh:mm:ssZThe TypeScript code for this model.
* Accept a `Date` as input by normalizing it to a string before the stringoffsetDateTime
Section titled “offsetDateTime”A date and time with timezone in ISO 8601 format YYYY-MM-DDThh:mm:ss±hh:mm.
A JSON example of this model.
"2024-02-28T17:00:00+01:00"The JSON Schema for this model.
$schema: https://json-schema.org/draft/2020-12/schema$id: offsetDateTime.yamltype: stringformat: date-timedescription: A date and time with timezone in ISO 8601 format YYYY-MM-DDThh:mm:ss±hh:mmThe TypeScript code for this model.
/** Schema for ISO date format: YYYY-MM-DD (accepts a YYYY-MM-DD string or a `Date`; outputs a `Date`) */export const ISODateSchema = z.preprocess( acceptDate(d => d.toISOString().slice(0, 10)), zcalendarYear
Section titled “calendarYear”A calendar year in the format YYYY.
A JSON example of this model.
"2025"The JSON Schema for this model.
$schema: https://json-schema.org/draft/2020-12/schema$id: calendarYear.yamltype: stringexamples: - "2025"pattern: ^[0-9]{4}$description: A calendar yearThe TypeSpec code for this model.
@example("2025")@pattern("^[0-9]{4}$")@Versioning.added(CommonGrants.Versions.v0_2)scalar calendarYear extends string;