ConstDurationSchema.parse('1 hour'); // → 3600000
DurationSchema.parse('30 minutes'); // → 1800000
DurationSchema.parse('2 days'); // → 172800000
DurationSchema.parse('500 ms'); // → 500
DurationSchema.parse('1 week'); // → 604800000
DurationSchema.parse('1 year'); // → 31536000000 (approximate)
DurationSchema.parse('invalid'); // ✗ Throws - invalid format
A Zod schema that validates and transforms duration strings to milliseconds.
This schema extends DurationFormatSchema by adding a transformation step that converts valid duration strings into their equivalent values in milliseconds. It supports the same flexible duration format but returns a numeric value representing the total duration in milliseconds.
The transformation handles all supported time units with accurate conversions, except for months and years which use approximate values (30 days per month, 365 days per year) due to the variability of these units.
Conversion rates: