This library adds additional types for Zod to parse and validate dates, times and durations as
Temporal types. This library has support for both zod/v4
and zod/v4/mini
.
Install via your favorite package manager:
npm install zod-temporal
# or
pnpm add zod-temporal
# or
yarn add zod-temporal
Import the schema types from this package. You can either import individual types or import all types via a convenience method:
import { zt } from 'zod-temporal';
For zod/v4/mini
, import from the mini sub-path:
import { zt } from 'zod-temporal/mini';
This library supplies the following types:
zt.duration()
zt.plainDate()
zt.plainDateTime()
zt.plainTime()
zt.offsetDateTime()
zt.zonedDateTime()
In contrast to zod-joda, zt.zonedDateTime()
represents date times with timezone information, while
zt.offsetDateTime()
also parses to a Temporal.ZonedDateTime
but cast to UTC.
The temporal schemas are implemented as codecs. This allows you to not only parse temporal values from their ISO string representation but also to encode them back:
const schema = zt.plainTime();
const value = schema.encode(Temporal.PlainTime.from('12:34:56.789'));