decoders

Dates

Date decoders for validating and parsing date values.

date

date: Decoder<Date> (source)

Accepts and returns Date instances.

Try it
date.verify(input)
InputResult
Date { "2026-03-18T07:22:57.919Z" }
123 ^^^ Must be a Date
"hello" ^^^^^^^ Must be a Date

isoDate

isoDate: Decoder<Date> (source)
iso8601: Decoder<Date> alias

Available since 2.9.

Accepts ISO8601-formatted strings, returns them as Date instances.

Try it
isoDate.verify(input)
InputResult
Date { "2020-06-01T12:00:00.000Z" }
"2020-06-01" ^^^^^^^^^^^^ Must be ISO8601 format
"hello" ^^^^^^^ Must be ISO8601 format
123 ^^^ Must be string
new Date('2026-03-18T07:22:57.922Z') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Must be string

isoDateString

isoDateString: Decoder<string> (source)
dateString: Decoder<string> deprecatediRenamed to isoDateString in 2.9. Will be removed in the next major release.

Available since 2.9.

Accepts and returns ISO8601-formatted strings.

Try it
isoDateString.verify(input)
InputResult
"2020-06-01T12:00:00Z"
"2020-06-01" ^^^^^^^^^^^^ Must be ISO8601 format
"hello" ^^^^^^^ Must be ISO8601 format
123 ^^^ Must be string
new Date('2026-03-18T07:22:57.923Z') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Must be string

flexDate

flexDate: Decoder<Date> (source)
datelike: Decoder<Date> deprecatediRenamed to flexDate in 2.9. Will be removed in the next major release.

Available since 2.9.

Accepts either a Date, or an ISO date string, returns a Date instance. This is commonly useful to build decoders that can be reused to validate object with Date instances as well as objects coming from JSON payloads.

Try it
flexDate.verify(input)
InputResult
Date { "2024-01-08T12:00:00.000Z" }
Date { "2026-03-18T07:22:57.923Z" }
"2020-06-01" ^^^^^^^^^^^^ Must be ISO8601 format
"hello" ^^^^^^^ Must be ISO8601 format
123 ^^^ Must be a Date or date string

On this page