ConstDurationFormatSchema.parse('1 hour'); // ✓ Valid
DurationFormatSchema.parse('30 minutes'); // ✓ Valid
DurationFormatSchema.parse('2 days'); // ✓ Valid
DurationFormatSchema.parse('  5 seconds  '); // ✓ Valid (whitespace trimmed)
DurationFormatSchema.parse('1h'); // ✓ Valid abbreviation
DurationFormatSchema.parse('10 ms'); // ✓ Valid milliseconds
DurationFormatSchema.parse('-5 minutes'); // ✗ Throws - negative not allowed
DurationFormatSchema.parse('1.5 hours'); // ✗ Throws - decimal not allowed
DurationFormatSchema.parse('5'); // ✗ Throws - missing unit
DurationFormatSchema.parse('five minutes'); // ✗ Throws - non-numeric amount
A Zod schema that validates duration string formats.
This schema validates human-readable duration strings using a flexible format that supports various time units with both full names and abbreviations. The format is "{amount} {unit}" where amount is a positive integer and unit can be any supported time unit. Extra whitespace is automatically trimmed.
Supported units (case-insensitive):
millisecond,milliseconds,mssecond,seconds,sminute,minutes,mhour,hours,hday,days,dweek,weeks,wmonth,months(approximate: 30 days)year,years,y(approximate: 365 days)