Transformation<DateTime.Zoned, string, never, never>Decodes a zoned date-time string into a DateTime.Zoned and encodes it back
to an ISO zoned string.
When to use
Use when you need a schema transformation for ISO zoned date-time strings
that decode to DateTime.Zoned and encode with DateTime.formatIsoZoned.
Details
Decode uses DateTime.makeZonedFromString and fails with InvalidValue when
the input is not a valid zoned date-time. Encode uses
DateTime.formatIsoZoned.
export const const dateTimeZonedFromString: Transformation<
DateTime.Zoned,
string
>
const dateTimeZonedFromString: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => Transformation<string, DateTime.Zoned, never, never>;
compose: (other: Transformation<T2, DateTime.Zoned, RD2, RE2>) => Transformation<T2, string, RD2, RE2>;
}
Decodes a zoned date-time string into a DateTime.Zoned and encodes it back
to an ISO zoned string.
When to use
Use when you need a schema transformation for ISO zoned date-time strings
that decode to DateTime.Zoned and encode with DateTime.formatIsoZoned.
Details
Decode uses DateTime.makeZonedFromString and fails with InvalidValue when
the input is not a valid zoned date-time. Encode uses
DateTime.formatIsoZoned.
dateTimeZonedFromString: 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.Zoned, 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.Zoned,
string
>({
decode: (
e: string,
options: SchemaAST.ParseOptions
) => Effect.Effect<
DateTime.Zoned,
SchemaIssue.Issue,
never
>
decode: (s: strings) => {
return import OptionOption.const match: {
<B, A, C = B>(options: {
readonly onNone: LazyArg<B>
readonly onSome: (a: A) => C
}): (self: Option<A>) => B | C
<A, B, C = B>(
self: Option<A>,
options: {
readonly onNone: LazyArg<B>
readonly onSome: (a: A) => C
}
): B | C
}
match(import DateTimeDateTime.const makeZonedFromString: (
input: string
) => Option.Option<Zoned>
Parses an ISO zoned date-time string into a DateTime.Zoned safely.
Details
Accepts named-zone strings such as
YYYY-MM-DDTHH:mm:ss.sss+HH:MM[Time/Zone] and offset-only strings such as
YYYY-MM-DDTHH:mm:ss.sss+HH:MM. Returns None when the input cannot be
parsed.
Example (Parsing zoned DateTime strings)
import { DateTime } from "effect"
const result1 = DateTime.makeZonedFromString(
"2024-01-01T12:00:00+02:00[Europe/Berlin]"
)
console.log(result1._tag === "Some") // true
const result2 = DateTime.makeZonedFromString("2024-01-01T12:00:00Z")
console.log(result2._tag === "Some") // true
const invalid = DateTime.makeZonedFromString("invalid")
console.log(invalid._tag === "None") // true
makeZonedFromString(s: strings), {
onNone: LazyArg<
Effect.Effect<
never,
SchemaIssue.InvalidValue,
never
>
>
onNone: () =>
import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(new import SchemaIssueSchemaIssue.constructor InvalidValue(actual: Option.Option<unknown>, annotations?: Annotations.Issue | undefined): SchemaIssue.InvalidValueRepresents a schema issue produced when the input has the correct type but its value violates a
constraint (e.g. a string that is too short, a number out of range).
When to use
Use when you need to detect constraint violations from Schema.filter,
Schema.minLength, Schema.greaterThan, or similar checks.
Details
actual is Option.some(value) when the failing value is known, or
Option.none() when absent.
annotations optionally carries a message string for formatting.
- The default formatter renders this as
"Invalid data <actual>" unless a
custom message annotation is provided.
Example (Returning InvalidValue from a custom filter)
import { Option, SchemaIssue } from "effect"
const issue = new SchemaIssue.InvalidValue(
Option.some(""),
{ message: "must not be empty" }
)
console.log(String(issue))
// "must not be empty"
InvalidValue(import OptionOption.const some: <A>(value: A) => Option<A>Wraps the given value into an Option to represent its presence.
When to use
Use to wrap a known present value as Option
- Returning a successful result from a partial function
Details
- Always returns
Some<A>
- Does not filter
null or undefined; use
fromNullishOr
for that
Example (Wrapping a value)
import { Option } from "effect"
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
some(s: strings), { Annotations.Issue.message?: string | undefinedmessage: `Invalid Zoned DateTime string: ${s: strings}` })),
onSome: <A>(value: A) => Effect<A>onSome: import EffectEffect.const succeed: <A>(value: A) => Effect<A>Creates an Effect that always succeeds with a given value.
When to use
Use when an effect should complete successfully with a specific value without any errors
or external dependencies.
Example (Creating a successful effect)
import { Effect } from "effect"
// Creating an effect that represents a successful scenario
//
// ┌─── Effect<number, never, never>
// ▼
const success = Effect.succeed(42)
succeed
})
},
encode: (
t: DateTime.Zoned,
options: SchemaAST.ParseOptions
) => Effect.Effect<
string,
SchemaIssue.Issue,
never
>
encode: (zoned: DateTime.Zoned(parameter) zoned: {
_tag: "Zoned";
epochMilliseconds: number;
zone: TimeZone;
adjustedEpochMilliseconds: number | undefined;
partsAdjusted: DateTime.PartsWithWeekday | undefined;
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;
}
zoned) => import EffectEffect.const succeed: <A>(value: A) => Effect<A>Creates an Effect that always succeeds with a given value.
When to use
Use when an effect should complete successfully with a specific value without any errors
or external dependencies.
Example (Creating a successful effect)
import { Effect } from "effect"
// Creating an effect that represents a successful scenario
//
// ┌─── Effect<number, never, never>
// ▼
const success = Effect.succeed(42)
succeed(import DateTimeDateTime.const formatIsoZoned: (
self: Zoned
) => string
Formats a DateTime.Zoned as a string.
Details
It uses the format: YYYY-MM-DDTHH:mm:ss.sss+HH:MM[Time/Zone].
Example (Formatting zoned DateTime values)
import { DateTime } from "effect"
const zoned = DateTime.makeZonedUnsafe("2024-06-15T14:30:45.123Z", {
timeZone: "Europe/London"
})
const formatted = DateTime.formatIsoZoned(zoned)
console.log(formatted) // "2024-06-15T15:30:45.123+01:00[Europe/London]"
const offsetZone = DateTime.makeZonedUnsafe("2024-06-15T14:30:45.123Z", {
timeZone: DateTime.zoneMakeOffset(3 * 60 * 60 * 1000)
})
const offsetFormatted = DateTime.formatIsoZoned(offsetZone)
console.log(offsetFormatted) // "2024-06-15T17:30:45.123+03:00"
formatIsoZoned(zoned: DateTime.Zoned(parameter) zoned: {
_tag: "Zoned";
epochMilliseconds: number;
zone: TimeZone;
adjustedEpochMilliseconds: number | undefined;
partsAdjusted: DateTime.PartsWithWeekday | undefined;
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;
}
zoned))
})