Hyperlinkv0.8.0-beta.28

SchemaTransformation

SchemaTransformation.dateFromStringconsteffect/SchemaTransformation.ts:880
Transformation<Date, string, never, never>

Decodes a string into a Date and encodes a Date back to a string.

When to use

Use when you need a schema transformation to parse ISO 8601 date strings from APIs or user input.

Details

Decoding creates a Date from the string like new Date(s). Encoding converts the Date to an ISO string like date.toISOString(), returning "Invalid Date" for invalid dates.

Example (Converting a string to a Date)

import { Schema, SchemaTransformation } from "effect"

const schema = Schema.String.pipe(
  Schema.decodeTo(Schema.Date, SchemaTransformation.dateFromString)
)
export const dateFromString: Transformation<globalThis.Date, string> = new Transformation(
  SchemaGetter.Date(),
  SchemaGetter.transform(formatDate)
)
Referenced by 2 symbols