DateTimeUtcFromDateType-level representation of DateTimeUtcFromDate.
export interface DateTimeUtcFromDate 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<DateTimeUtc, Date> {
readonly "Rebuild": DateTimeUtcFromDate
}
/**
* Schema that decodes a `Date` into a `DateTime.Utc`.
*
* **When to use**
*
* Use when you need to decode valid JavaScript `Date` objects into
* `DateTime.Utc` values.
*
* **Details**
*
* Decoding:
* - A **valid** `Date` is decoded as a `DateTime.Utc`
*
* Encoding:
* - A `DateTime.Utc` is encoded as a `Date`
*
* @see {@link DateTimeUtc} for validating values that are already `DateTime.Utc`
* @see {@link DateTimeUtcFromString} for decoding date-time strings into UTC values
* @see {@link DateTimeUtcFromMillis} for decoding epoch milliseconds into UTC values
* @see {@link DateValid} for validating Date instances without converting them
*
* @category DateTime
* @since 3.12.0
*/
export const const DateTimeUtcFromDate: DateTimeUtcFromDateconst DateTimeUtcFromDate: {
Rebuild: DateTimeUtcFromDate;
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.Utc, readonly []>) => DateTimeUtcFromDate;
annotateKey: (annotations: Annotations.Key<DateTime.Utc>) => DateTimeUtcFromDate;
check: (checks_0: SchemaAST.Check<DateTime.Utc>, ...checks: Array<SchemaAST.Check<DateTime.Utc>>) => DateTimeUtcFromDate;
rebuild: (ast: SchemaAST.Declaration) => DateTimeUtcFromDate;
make: (input: DateTime.Utc, options?: MakeOptions) => DateTime.Utc;
makeOption: (input: DateTime.Utc, options?: MakeOptions) => Option_.Option<DateTime.Utc>;
makeEffect: (input: DateTime.Utc, options?: MakeOptions) => Effect.Effect<DateTime.Utc, 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
DateTimeUtcFromDate
.
Schema that decodes a Date into a DateTime.Utc.
When to use
Use when you need to decode valid JavaScript Date objects into
DateTime.Utc values.
Details
Decoding:
- A valid
Date is decoded as a DateTime.Utc
Encoding:
- A
DateTime.Utc is encoded as a Date
DateTimeUtcFromDate: DateTimeUtcFromDate = const DateValid: DateValidconst DateValid: {
Rebuild: DateValid;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<globalThis.Date, readonly []>) => DateValid;
annotateKey: (annotations: Annotations.Key<globalThis.Date>) => DateValid;
check: (checks_0: SchemaAST.Check<globalThis.Date>, ...checks: Array<SchemaAST.Check<globalThis.Date>>) => DateValid;
rebuild: (ast: SchemaAST.Declaration) => DateValid;
make: (input: globalThis.Date, options?: MakeOptions) => globalThis.Date;
makeOption: (input: globalThis.Date, options?: MakeOptions) => Option_.Option<globalThis.Date>;
makeEffect: (input: globalThis.Date, options?: MakeOptions) => Effect.Effect<globalThis.Date, 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
DateValid
.
Schema for valid JavaScript Date objects.
Details
This schema accepts Date instances but rejects invalid dates (such as new
Date("invalid")).
DateValid.pipe(
function decodeTo<DateTimeUtc, Constraint, never, never>(to: DateTimeUtc, transformation: {
readonly decode: SchemaGetter.Getter<DateTime.Utc, unknown, never>;
readonly encode: SchemaGetter.Getter<unknown, DateTime.Utc, never>;
}): (from: Constraint) => decodeTo<DateTimeUtc, 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 DateTimeUtc: DateTimeUtcconst DateTimeUtc: {
Rebuild: DateTimeUtc;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<DateTime.Utc, readonly []>) => DateTimeUtc;
annotateKey: (annotations: Annotations.Key<DateTime.Utc>) => DateTimeUtc;
check: (checks_0: SchemaAST.Check<DateTime.Utc>, ...checks: Array<SchemaAST.Check<DateTime.Utc>>) => DateTimeUtc;
rebuild: (ast: SchemaAST.Declaration) => DateTimeUtc;
make: (input: DateTime.Utc, options?: MakeOptions) => DateTime.Utc;
makeOption: (input: DateTime.Utc, options?: MakeOptions) => Option_.Option<DateTime.Utc>;
makeEffect: (input: DateTime.Utc, options?: MakeOptions) => Effect.Effect<DateTime.Utc, 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
DateTimeUtc
.
Schema for DateTime.Utc values.
When to use
Use to validate existing DateTime.Utc schema values and use the default JSON
codec that represents them as UTC ISO strings.
Details
The default JSON codec decodes UTC ISO strings into DateTime.Utc values and
encodes DateTime.Utc values as UTC ISO strings.
DateTimeUtc, {
decode: SchemaGetter.Getter<
DateTime.Utc,
NoInfer<globalThis.Date>,
never
>
(property) decode: {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: (f: (t: DateTime.Utc) => T2) => SchemaGetter.Getter<T2, NoInfer<globalThis.Date>, never>;
compose: (other: SchemaGetter.Getter<T2, DateTime.Utc, R2>) => SchemaGetter.Getter<T2, NoInfer<globalThis.Date>, R2>;
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; <…;
}
decode: import SchemaGetterSchemaGetter.function dateTimeUtcFromInput<
E extends DateTime.DateTime.Input
>(): Getter<DateTime.Utc, E>
Parses a DateTime.Input value into a DateTime.Utc.
When to use
Use when you need a schema getter to decode a present encoded date/time value
to a DateTime.Utc.
Details
- Accepted input includes existing
DateTime values, partial date/time parts,
instant objects, zoned instant objects, JavaScript Date instances, epoch
milliseconds, and date strings.
- Converts successfully parsed values to UTC.
- Fails with
SchemaIssue.InvalidValue if the input cannot be parsed as a valid
DateTime.
Example (Parsing DateTime)
import { SchemaGetter } from "effect"
const parseDate = SchemaGetter.dateTimeUtcFromInput<string>()
// Getter<DateTime.Utc, string>
dateTimeUtcFromInput(),
encode: SchemaGetter.Getter<
globalThis.Date,
DateTime.DateTime,
never
>
(property) encode: {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: (f: (t: globalThis.Date) => T2) => SchemaGetter.Getter<T2, DateTime.DateTime, never>;
compose: (other: SchemaGetter.Getter<T2, globalThis.Date, R2>) => SchemaGetter.Getter<T2, DateTime.DateTime, R2>;
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; <…;
}
encode: import SchemaGetterSchemaGetter.function transform<T, E>(
f: (e: E) => T
): Getter<T, E>
Creates a getter that applies a pure function to present values.
When to use
Use when you need a schema getter for a pure, infallible transformation
between types.
- Building encode/decode pairs for
Schema.decodeTo.
Details
- This is the most commonly used constructor.
- Transforms
Some(e) to Some(f(e)) and leaves None unchanged.
- Skips
None inputs — only called when a value is present.
- Never fails.
Example (Transforming strings to numbers)
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))
})
)
transform(import DateTimeDateTime.toDateUtc)
})
)