DateTimeUtcFromMillisType-level representation of DateTimeUtcFromMillis.
export interface DateTimeUtcFromMillis 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<interface instanceOf<T, Iso = T>Creates a schema that validates values using instanceof.
Decoding and encoding pass the value through unchanged.
Example (Defining a schema for a built-in class)
import { Schema } from "effect"
const DateSchema = Schema.instanceOf(Date)
const decoded = Schema.decodeUnknownSync(DateSchema)(new Date("2024-01-01"))
// decoded: Date
Type-level representation returned by
instanceOf
.
instanceOf<import DateTimeDateTime.type DateTime.Utc = /*unresolved*/ anyUtc>, Number> {
readonly "Rebuild": DateTimeUtcFromMillis
}
/**
* Schema that decodes a number into a `DateTime.Utc`.
*
* **Details**
*
* Decoding:
* - A number of milliseconds since the Unix epoch is decoded as a `DateTime.Utc`
*
* Encoding:
* - A `DateTime.Utc` is encoded as a number of milliseconds since the Unix epoch.
*
* @see {@link DateTimeUtcFromDate} for decoding JavaScript Date values into UTC values
* @see {@link DateTimeUtcFromString} for decoding date-time strings into UTC values
* @see {@link DateFromMillis} for decoding epoch milliseconds into JavaScript Date instances
*
* @category DateTime
* @since 4.0.0
*/
export const const DateTimeUtcFromMillis: DateTimeUtcFromMillisconst DateTimeUtcFromMillis: {
Rebuild: DateTimeUtcFromMillis;
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 []>) => DateTimeUtcFromMillis;
annotateKey: (annotations: Annotations.Key<DateTime.Utc>) => DateTimeUtcFromMillis;
check: (checks_0: SchemaAST.Check<DateTime.Utc>, ...checks: Array<SchemaAST.Check<DateTime.Utc>>) => DateTimeUtcFromMillis;
rebuild: (ast: SchemaAST.Declaration) => DateTimeUtcFromMillis;
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
DateTimeUtcFromMillis
.
Schema that decodes a number into a DateTime.Utc.
Details
Decoding:
- A number of milliseconds since the Unix epoch is decoded as a
DateTime.Utc
Encoding:
- A
DateTime.Utc is encoded as a number of milliseconds since the Unix epoch.
DateTimeUtcFromMillis: DateTimeUtcFromMillis = const Number: Numberconst Number: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<number, readonly []>) => Number;
annotateKey: (annotations: Annotations.Key<number>) => Number;
check: (checks_0: SchemaAST.Check<number>, ...checks: Array<SchemaAST.Check<number>>) => Number;
rebuild: (ast: SchemaAST.Number) => Number;
make: (input: number, options?: MakeOptions) => number;
makeOption: (input: number, options?: MakeOptions) => Option_.Option<number>;
makeEffect: (input: number, options?: MakeOptions) => Effect.Effect<number, 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
Number
.
Schema for number values, including NaN, Infinity, and -Infinity.
Details
Default JSON serializer:
- Finite numbers are serialized as numbers.
- Non-finite values are serialized as strings (
"NaN", "Infinity", "-Infinity").
Number.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,
number,
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, number, never>;
compose: (other: SchemaGetter.Getter<T2, DateTime.Utc, R2>) => SchemaGetter.Getter<T2, number, 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<
number,
DateTime.DateTime,
never
>
(property) encode: {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: (f: (t: number) => T2) => SchemaGetter.Getter<T2, DateTime.DateTime, never>;
compose: (other: SchemaGetter.Getter<T2, number, 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.toEpochMillis)
})
)