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-01T00:00:00.000Z"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.
/** A date on a calendar in ISO 8601 format YYYY-MM-DD */@example(isoDate.fromISO("2025-01-01"))scalar isoDate extends plainDate;The TypeScript code for this model.
export const ISODateSchema = z .string() .date() .transform(str => new Date(str));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.
/** A time on a clock, without a timezone, in ISO 8601 format HH:mm:ss */@example(isoTime.fromISO("17:00:00"))scalar isoTime extends plainTime;The TypeScript code for this model.
export const ISOTimeSchema = z.preprocess(val => { if (typeof val === "string") { // Remove timezone indicator (e.g., "17:00:00.123Z" → "17:00:00.123", "17:00:00+05:00" → "17:00:00") // Zod's time() accepts HH:MM:SS[.fraction] but not timezone indicators return val.replace(/(Z|[+-]\d{2}:\d{2})$/, ""); } return val;}, z.string().time());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.
export const UTCDateTimeSchema = z.string().datetime().transform(ensureUTC);offsetDateTime
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.
export const OffsetDateTimeSchema = z .string() .datetime({ offset: true }) .transform(str => new Date(str));calendarYear
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.
/** A calendar year */@example("2025")@pattern("^[0-9]{4}$")@Versioning.added(CommonGrants.Versions.v0_2)scalar calendarYear extends string;