Skip to content

parseDate

parseDate<T>(spec, format?): MapSpec<T>

Defined in: extract/spec.ts:809

Parse a string value into an ISO date string (YYYY-MM-DD).

Without format: validates the input as an ISO date and returns it as-is. With format: compiles the format string into a parser that converts the input string into an ISO date.

Tokens (uppercase = strict 2-digit, lowercase/single = lenient 1-2 digit):

  • YYYY (4-digit year), YY (2-digit year: <70 → 20xx, >=70 → 19xx)
  • MM (zero-padded month), M (1-2 digit month)
  • DD (zero-padded day), D (1-2 digit day)

Produces schemaHint: { type: 'string', format: 'date' } for schema derivation.

T extends Spec

T

string

MapSpec<T>

// ISO validation
parseDate($.get('date').string())
// Strict zero-padded format
parseDate($.get('date').string(), 'MM/DD/YYYY')
// Lenient format (handles "10/1/21")
parseDate($.get('date').string(), 'M/D/YY')
// With fallback
tryExtract(parseDate($.get('date').string(), 'M/D/YY'), literal(null))