Transformation<DateTime.Utc, string, never, never>Decodes a date-time string into a DateTime.Utc and encodes it back to an ISO
string.
When to use
Use when you need a schema transformation to decode date-time strings to a
normalized DateTime.Utc and encode back as a UTC ISO string.
Details
Decode accepts strings supported by DateTime.make, converts the result to
UTC, and fails with InvalidValue when parsing fails. Encode uses
DateTime.formatIso.
export const const dateTimeUtcFromString: Transformation<
DateTime.Utc,
string
>
const dateTimeUtcFromString: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => Transformation<string, DateTime.Utc, never, never>;
compose: (other: Transformation<T2, DateTime.Utc, RD2, RE2>) => Transformation<T2, string, RD2, RE2>;
}
Decodes a date-time string into a DateTime.Utc and encodes it back to an ISO
string.
When to use
Use when you need a schema transformation to decode date-time strings to a
normalized DateTime.Utc and encode back as a UTC ISO string.
Details
Decode accepts strings supported by DateTime.make, converts the result to
UTC, and fails with InvalidValue when parsing fails. Encode uses
DateTime.formatIso.
dateTimeUtcFromString: class Transformation<in out T, in out E, RD = never, RE = never>class Transformation {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => Transformation<E, T, RE, RD>;
compose: <T2, RD2, RE2>(other: Transformation<T2, T, RD2, RE2>) => Transformation<T2, E, RD | RD2, RE | RE2>;
}
Represents a bidirectional transformation between a decoded type T and an encoded
type E, built from a pair of Getters.
When to use
Use when you need a schema transformation that defines how a schema converts
between two representations.
- You want to compose multiple transformations into a pipeline.
- You want to flip a transformation to swap decode/encode.
Details
This is the primary building block for Schema.decodeTo, Schema.encodeTo,
Schema.decode, Schema.encode, and Schema.link. Each direction is a
SchemaGetter.Getter that handles optionality, failure, and Effect services.
- Immutable —
flip() and compose() return new instances.
flip() swaps the decode and encode getters.
compose(other) chains: this.decode then other.decode for decoding,
other.encode then this.encode for encoding.
Example (Composing two transformations)
import { SchemaTransformation } from "effect"
const trimAndLower = SchemaTransformation.trim().compose(
SchemaTransformation.toLowerCase()
)
// decode: trim then lowercase
// encode: passthrough (both directions)
Transformation<import DateTimeDateTime.type DateTime.Utc = /*unresolved*/ anyUtc, string> = function transformOrFail<
T,
E,
RD = never,
RE = never
>(options: {
readonly decode: (
e: E,
options: SchemaAST.ParseOptions
) => Effect.Effect<T, SchemaIssue.Issue, RD>
readonly encode: (
t: T,
options: SchemaAST.ParseOptions
) => Effect.Effect<E, SchemaIssue.Issue, RE>
}): Transformation<T, E, RD, RE>
Creates a Transformation from effectful decode and encode functions that
can fail with Issue.
When to use
Use when you need a schema transformation that may fail or require Effect
services.
Details
- Each function receives the input value and
ParseOptions.
- Must return an
Effect that succeeds with the output or fails with Issue.
- Skips
None inputs (missing keys) — functions are only called on present values.
Example (Parsing a date string that can fail)
import { Effect, Option, Schema, SchemaIssue, SchemaTransformation } from "effect"
const DateFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Date,
SchemaTransformation.transformOrFail({
decode: (s) => {
const d = new Date(s)
return isNaN(d.getTime())
? Effect.fail(new SchemaIssue.InvalidValue(Option.some(s), { message: "Invalid date" }))
: Effect.succeed(d)
},
encode: (d) => Effect.succeed(d.toISOString())
})
)
)
transformOrFail<
import DateTimeDateTime.type DateTime.Utc = /*unresolved*/ anyUtc,
string
>({
decode: (
e: string,
options: SchemaAST.ParseOptions
) => Effect.Effect<
DateTime.Utc,
SchemaIssue.Issue,
never
>
decode: (s: strings) => {
return import OptionOption.match(import DateTimeDateTime.make(s: strings), {
onNone: () => anyonNone: () =>
import EffectEffect.fail(new import SchemaIssueSchemaIssue.InvalidValue(import OptionOption.some(s: strings), { message: stringmessage: `Invalid UTC DateTime string: ${s: strings}` })),
onSome: (result: any) => anyonSome: (result: DateTime.Utc(parameter) result: {
_tag: "Utc";
epochMilliseconds: number;
partsUtc: DateTime.PartsWithWeekday | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
result) => import EffectEffect.succeed(import DateTimeDateTime.toUtc(result: DateTime.Utc(parameter) result: {
_tag: "Utc";
epochMilliseconds: number;
partsUtc: DateTime.PartsWithWeekday | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
result))
})
},
encode: (
t: DateTime.Utc,
options: SchemaAST.ParseOptions
) => Effect.Effect<
string,
SchemaIssue.Issue,
never
>
encode: (utc: DateTime.Utc(parameter) utc: {
_tag: "Utc";
epochMilliseconds: number;
partsUtc: DateTime.PartsWithWeekday | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
utc) => import EffectEffect.succeed(import DateTimeDateTime.formatIso(utc: DateTime.Utc(parameter) utc: {
_tag: "Utc";
epochMilliseconds: number;
partsUtc: DateTime.PartsWithWeekday | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
utc))
})