Transformation<Date, number, never, never>Decodes epoch milliseconds into a Date and encodes a Date back to epoch
milliseconds.
When to use
Use when you need a schema transformation for numeric timestamps represented as milliseconds since the Unix epoch.
Details
Decoding creates a Date from the number like new Date(ms). Encoding
returns the Date timestamp like date.getTime().
Gotchas
This transformation does not validate date validity. NaN, Infinity, and
-Infinity decode to invalid Date instances.
Example (Converting milliseconds to a Date)
import { Schema, SchemaTransformation } from "effect"
const schema = Schema.Number.pipe(
Schema.decodeTo(Schema.Date, SchemaTransformation.dateFromMillis)
)export const const dateFromMillis: Transformation<
globalThis.Date,
number
>
const dateFromMillis: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => Transformation<number, Date, never, never>;
compose: (other: Transformation<T2, Date, RD2, RE2>) => Transformation<T2, number, RD2, RE2>;
}
Decodes epoch milliseconds into a Date and encodes a Date back to epoch
milliseconds.
When to use
Use when you need a schema transformation for numeric timestamps represented
as milliseconds since the Unix epoch.
Details
Decoding creates a Date from the number like new Date(ms). Encoding
returns the Date timestamp like date.getTime().
Gotchas
This transformation does not validate date validity. NaN, Infinity, and
-Infinity decode to invalid Date instances.
Example (Converting milliseconds to a Date)
import { Schema, SchemaTransformation } from "effect"
const schema = Schema.Number.pipe(
Schema.decodeTo(Schema.Date, SchemaTransformation.dateFromMillis)
)
dateFromMillis: 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<module globalThisglobalThis.Date, number> = new constructor Transformation<Date, number, never, never>(decode: SchemaGetter.Getter<Date, number, never>, encode: SchemaGetter.Getter<number, Date, never>): Transformation<Date, number, never, never>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 SchemaGetterSchemaGetter.Date(),
import SchemaGetterSchemaGetter.transform((date: anydate) => date: anydate.getTime())
)