DateTimeZonedFromStringType-level representation of DateTimeZonedFromString.
export interface DateTimeZonedFromString extends interface decodeTo<To extends Constraint, From extends Constraint, RD = never, RE = never>Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
Type-level representation returned by
decodeTo
.
decodeTo<DateTimeZoned, String> {
readonly "Rebuild": DateTimeZonedFromString
}
/**
* Schema that parses a zoned DateTime string into a `DateTime.Zoned`.
*
* **Details**
*
* Decoding:
* - A `string` (e.g. `2024-01-01T00:00:00.000+00:00[Europe/London]`) is decoded as a `DateTime.Zoned`.
*
* Encoding:
* - A `DateTime.Zoned` is encoded as a `string`.
*
* @category DateTime
* @since 4.0.0
*/
export const const DateTimeZonedFromString: DateTimeZonedFromStringconst DateTimeZonedFromString: {
Rebuild: DateTimeZonedFromString;
Type: To["Type"];
Encoded: From["Encoded"];
DecodingServices: To["DecodingServices"] | From["DecodingServices"] | RD;
EncodingServices: To["EncodingServices"] | From["EncodingServices"] | RE;
Iso: To["Iso"];
from: From;
to: To;
ast: Ast;
annotate: (annotations: Annotations.Bottom<DateTime.Zoned, readonly []>) => DateTimeZonedFromString;
annotateKey: (annotations: Annotations.Key<DateTime.Zoned>) => DateTimeZonedFromString;
check: (checks_0: SchemaAST.Check<DateTime.Zoned>, ...checks: Array<SchemaAST.Check<DateTime.Zoned>>) => DateTimeZonedFromString;
rebuild: (ast: SchemaAST.Declaration) => DateTimeZonedFromString;
make: (input: DateTime.Zoned, options?: MakeOptions) => DateTime.Zoned;
makeOption: (input: DateTime.Zoned, options?: MakeOptions) => Option_.Option<DateTime.Zoned>;
makeEffect: (input: DateTime.Zoned, options?: MakeOptions) => Effect.Effect<DateTime.Zoned, SchemaError, never>;
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; <…;
}
Type-level representation of
DateTimeZonedFromString
.
Schema that parses a zoned DateTime string into a DateTime.Zoned.
Details
Decoding:
- A
string (e.g. 2024-01-01T00:00:00.000+00:00[Europe/London]) is decoded as a DateTime.Zoned.
Encoding:
- A
DateTime.Zoned is encoded as a string.
DateTimeZonedFromString: DateTimeZonedFromString = const DateTimeZonedString: Stringconst DateTimeZonedString: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<string, readonly []>) => String;
annotateKey: (annotations: Annotations.Key<string>) => String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => String;
rebuild: (ast: SchemaAST.String) => String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
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; <…;
}
DateTimeZonedString.pipe(
function decodeTo<DateTimeZoned, Constraint, never, never>(to: DateTimeZoned, transformation: {
readonly decode: SchemaGetter.Getter<DateTime.Zoned, unknown, never>;
readonly encode: SchemaGetter.Getter<unknown, DateTime.Zoned, never>;
}): (from: Constraint) => decodeTo<DateTimeZoned, Constraint, never, never> (+1 overload)
Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
decodeTo(const DateTimeZoned: DateTimeZonedconst DateTimeZoned: {
Rebuild: DateTimeZoned;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<DateTime.Zoned, readonly []>) => DateTimeZoned;
annotateKey: (annotations: Annotations.Key<DateTime.Zoned>) => DateTimeZoned;
check: (checks_0: SchemaAST.Check<DateTime.Zoned>, ...checks: Array<SchemaAST.Check<DateTime.Zoned>>) => DateTimeZoned;
rebuild: (ast: SchemaAST.Declaration) => DateTimeZoned;
make: (input: DateTime.Zoned, options?: MakeOptions) => DateTime.Zoned;
makeOption: (input: DateTime.Zoned, options?: MakeOptions) => Option_.Option<DateTime.Zoned>;
makeEffect: (input: DateTime.Zoned, options?: MakeOptions) => Effect.Effect<DateTime.Zoned, SchemaError, never>;
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; <…;
}
Type-level representation of
DateTimeZoned
.
Schema for DateTime.Zoned values.
Details
Default JSON serializer:
- encodes offset zones as an ISO date-time with a numeric offset, such as
YYYY-MM-DDTHH:mm:ss.sss+HH:MM
- encodes named zones by appending the IANA identifier in brackets, such as
YYYY-MM-DDTHH:mm:ss.sss+HH:MM[Time/Zone]
DateTimeZoned, import SchemaTransformationSchemaTransformation.const dateTimeZonedFromString: Transformation<
DateTime.Zoned,
string
>
const dateTimeZonedFromString: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => SchemaTransformation.Transformation<string, DateTime.Zoned, never, never>;
compose: (other: SchemaTransformation.Transformation<T2, DateTime.Zoned, RD2, RE2>) => SchemaTransformation.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)
)