DateType-level representation of Date.
export interface Date extends 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<module globalThisglobalThis.Date> {
readonly "Rebuild": Date
}
type type DateArbitraryConstraints = anyDateArbitraryConstraints = import FastCheckFastCheck.type FastCheck.DateConstraints = /*unresolved*/ anyDateConstraints & {
readonly valid?: boolean | undefinedvalid?: boolean | undefined
}
function function dateArbitraryConstraints<
T = globalThis.Date
>(
constraint:
| Annotations.ToArbitrary.GenerationConstraint
| undefined,
ordered:
| Annotations.ToArbitrary.OrderedConstraint<T>
| undefined,
base?: DateArbitraryConstraints | undefined,
toDate?: (value: T) => globalThis.Date
): FastCheck.DateConstraints
dateArbitraryConstraints<function (type parameter) T in dateArbitraryConstraints<T = globalThis.Date>(constraint: Annotations.ToArbitrary.GenerationConstraint | undefined, ordered: Annotations.ToArbitrary.OrderedConstraint<T> | undefined, base?: DateArbitraryConstraints | undefined, toDate?: (value: T) => globalThis.Date): FastCheck.DateConstraintsT = module globalThisglobalThis.Date>(
constraint: | Annotations.ToArbitrary.GenerationConstraint
| undefined
constraint: Annotations.namespace Annotations.ToArbitraryTypes used by arbitrary-derivation annotations to configure toArbitrary
hooks, filter hints, candidate sources, diagnostics, and merged generation
constraints.
ToArbitrary.interface Annotations.ToArbitrary.GenerationConstraintNode-local arbitrary-generation constraint accumulated from schema checks.
Details
GenerationConstraint is a generation hint for the current schema AST
node, not a self-describing validation contract. Each generator consumes
the fields it understands for the current node and ignores the rest;
final schema filters still validate every generated value.
minLength and maxLength represent node-local cardinality: string
length for strings, array length for arrays, final own-property count for
objects, and final size/cardinality for sets, maps, hash collections, and
chunks. patterns are concatenated and used by string generators.
integer, noNaN, noInfinity, valid, and unique are true when any
contributing filter sets them. Range bounds live in ordered so ordered
values can share the same representation.
GenerationConstraint | undefined,
ordered: | Annotations.ToArbitrary.OrderedConstraint<T>
| undefined
ordered: Annotations.namespace Annotations.ToArbitraryTypes used by arbitrary-derivation annotations to configure toArbitrary
hooks, filter hints, candidate sources, diagnostics, and merged generation
constraints.
ToArbitrary.interface Annotations.ToArbitrary.OrderedConstraint<T>Ordered constraint accumulated from range checks.
Details
Generators consume these constraints only when they recognize order,
such as Order.Number, Order.BigInt, DateTime, or BigDecimal. Merging
constraints with different Order instances fails fast.
OrderedConstraint<function (type parameter) T in dateArbitraryConstraints<T = globalThis.Date>(constraint: Annotations.ToArbitrary.GenerationConstraint | undefined, ordered: Annotations.ToArbitrary.OrderedConstraint<T> | undefined, base?: DateArbitraryConstraints | undefined, toDate?: (value: T) => globalThis.Date): FastCheck.DateConstraintsT> | undefined,
base: anybase?: type DateArbitraryConstraints = anyDateArbitraryConstraints | undefined,
toDate: | ((value: T) => globalThis.Date)
| undefined
toDate?: (value: T = globalThis.Datevalue: function (type parameter) T in dateArbitraryConstraints<T = globalThis.Date>(constraint: Annotations.ToArbitrary.GenerationConstraint | undefined, ordered: Annotations.ToArbitrary.OrderedConstraint<T> | undefined, base?: DateArbitraryConstraints | undefined, toDate?: (value: T) => globalThis.Date): FastCheck.DateConstraintsT) => module globalThisglobalThis.Date
): import FastCheckFastCheck.type FastCheck.DateConstraints = /*unresolved*/ anyDateConstraints {
const const out: FastCheck.DateConstraintsout: import FastCheckFastCheck.type FastCheck.DateConstraints = /*unresolved*/ anyDateConstraints = { ...base: anybase }
delete (const out: FastCheck.DateConstraintsout as any).valid
if (base: anybase?.valid || constraint: | Annotations.ToArbitrary.GenerationConstraint
| undefined
constraint?.Annotations.ToArbitrary.GenerationConstraint.valid?: boolean | undefinedvalid) {
const out: FastCheck.DateConstraintsout.noInvalidDate = true
}
if (ordered: | Annotations.ToArbitrary.OrderedConstraint<T>
| undefined
ordered?.Annotations.ToArbitrary.OrderedConstraint<T>.minimum?: T | undefinedminimum !== var undefinedundefined) {
const const minimum: globalThis.Dateminimum = toDate: | ((value: T) => globalThis.Date)
| undefined
toDate === var undefinedundefined ? ordered: Annotations.ToArbitrary.OrderedConstraint<T>(parameter) ordered: {
order: Order.Order<T>;
minimum: T | undefined;
exclusiveMinimum: boolean | undefined;
maximum: T | undefined;
exclusiveMaximum: boolean | undefined;
}
ordered.Annotations.ToArbitrary.OrderedConstraint<T>.minimum?: T & ({} | null)minimum as module globalThisglobalThis.Date : toDate: (value: T) => globalThis.DatetoDate(ordered: Annotations.ToArbitrary.OrderedConstraint<T>(parameter) ordered: {
order: Order.Order<T>;
minimum: T | undefined;
exclusiveMinimum: boolean | undefined;
maximum: T | undefined;
exclusiveMaximum: boolean | undefined;
}
ordered.Annotations.ToArbitrary.OrderedConstraint<T>.minimum?: T & ({} | null)minimum)
const const nextMin: globalThis.DatenextMin = ordered: Annotations.ToArbitrary.OrderedConstraint<T>(parameter) ordered: {
order: Order.Order<T>;
minimum: T | undefined;
exclusiveMinimum: boolean | undefined;
maximum: T | undefined;
exclusiveMaximum: boolean | undefined;
}
ordered.Annotations.ToArbitrary.OrderedConstraint<T>.exclusiveMinimum?: boolean | undefinedexclusiveMinimum ? new module globalThisglobalThis.var Date: DateConstructor
new (value: number | string | globalThis.Date) => globalThis.Date (+4 overloads)
Date(const minimum: globalThis.Dateminimum.Date.getTime(): numberReturns the stored time value in milliseconds since midnight, January 1, 1970 UTC.
getTime() + 1) : const minimum: globalThis.Dateminimum
if (const out: FastCheck.DateConstraintsout.min === var undefinedundefined || const nextMin: globalThis.DatenextMin.Date.getTime(): numberReturns the stored time value in milliseconds since midnight, January 1, 1970 UTC.
getTime() > const out: FastCheck.DateConstraintsout.min.getTime()) {
const out: FastCheck.DateConstraintsout.min = const nextMin: globalThis.DatenextMin
}
}
if (ordered: | Annotations.ToArbitrary.OrderedConstraint<T>
| undefined
ordered?.Annotations.ToArbitrary.OrderedConstraint<T>.maximum?: T | undefinedmaximum !== var undefinedundefined) {
const const maximum: globalThis.Datemaximum = toDate: | ((value: T) => globalThis.Date)
| undefined
toDate === var undefinedundefined ? ordered: Annotations.ToArbitrary.OrderedConstraint<T>(parameter) ordered: {
order: Order.Order<T>;
minimum: T | undefined;
exclusiveMinimum: boolean | undefined;
maximum: T | undefined;
exclusiveMaximum: boolean | undefined;
}
ordered.Annotations.ToArbitrary.OrderedConstraint<T>.maximum?: T & ({} | null)maximum as module globalThisglobalThis.Date : toDate: (value: T) => globalThis.DatetoDate(ordered: Annotations.ToArbitrary.OrderedConstraint<T>(parameter) ordered: {
order: Order.Order<T>;
minimum: T | undefined;
exclusiveMinimum: boolean | undefined;
maximum: T | undefined;
exclusiveMaximum: boolean | undefined;
}
ordered.Annotations.ToArbitrary.OrderedConstraint<T>.maximum?: T & ({} | null)maximum)
const const nextMax: globalThis.DatenextMax = ordered: Annotations.ToArbitrary.OrderedConstraint<T>(parameter) ordered: {
order: Order.Order<T>;
minimum: T | undefined;
exclusiveMinimum: boolean | undefined;
maximum: T | undefined;
exclusiveMaximum: boolean | undefined;
}
ordered.Annotations.ToArbitrary.OrderedConstraint<T>.exclusiveMaximum?: boolean | undefinedexclusiveMaximum ? new module globalThisglobalThis.var Date: DateConstructor
new (value: number | string | globalThis.Date) => globalThis.Date (+4 overloads)
Date(const maximum: globalThis.Datemaximum.Date.getTime(): numberReturns the stored time value in milliseconds since midnight, January 1, 1970 UTC.
getTime() - 1) : const maximum: globalThis.Datemaximum
if (const out: FastCheck.DateConstraintsout.max === var undefinedundefined || const nextMax: globalThis.DatenextMax.Date.getTime(): numberReturns the stored time value in milliseconds since midnight, January 1, 1970 UTC.
getTime() < const out: FastCheck.DateConstraintsout.max.getTime()) {
const out: FastCheck.DateConstraintsout.max = const nextMax: globalThis.DatenextMax
}
}
return const out: FastCheck.DateConstraintsout
}
const const DateString: Stringconst DateString: {
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; <…;
}
DateString = const String: Stringconst String: {
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; <…;
}
Type-level representation of
String
.
Schema for string values. Validates that the input is typeof "string".
String.Bottom<string, string, never, never, String, String, string, string, readonly [], string, "readonly", "required", "no-default", "readonly", "required">.annotate(annotations: Annotations.Bottom<string, readonly []>): Stringannotate({ Annotations.Augment.expected?: string | undefinedHuman-readable description of what a value is expected to satisfy.
Details
For filter and refinement failures, the default formatter uses
message first, then expected, and finally falls back to <filter>.
Use this to name a failed filter in the default message:
Expected <expected>, got <actual>.
expected: "a string in ISO 8601 format that will be decoded as a Date" })
/**
* Schema for JavaScript `Date` objects.
*
* **When to use**
*
* Use to validate in-memory values that must already be JavaScript date
* objects.
*
* **Details**
*
* This schema accepts any `Date` instance, including invalid dates. The default
* JSON serializer encodes valid dates as ISO 8601 strings; invalid dates encode
* as `"Invalid Date"`.
*
* **Example** (Defining a Date schema)
*
* ```ts
* import { Schema } from "effect"
*
* Schema.decodeUnknownSync(Schema.Date)(new Date("2024-01-01"))
* // => Date { 2024-01-01T00:00:00.000Z }
* ```
*
* @see {@link DateValid} for accepting only valid Date instances
* @see {@link DateFromString} for decoding strings into Date instances
* @see {@link DateFromMillis} for decoding epoch milliseconds into Date instances
*
* @category Date
* @since 4.0.0
*/
export const const Date: Dateconst Date: {
Rebuild: Date;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<globalThis.Date, readonly []>) => Date;
annotateKey: (annotations: Annotations.Key<globalThis.Date>) => Date;
check: (checks_0: SchemaAST.Check<globalThis.Date>, ...checks: Array<SchemaAST.Check<globalThis.Date>>) => Date;
rebuild: (ast: SchemaAST.Declaration) => Date;
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
Date
.
Schema for JavaScript Date objects.
When to use
Use to validate in-memory values that must already be JavaScript date
objects.
Details
This schema accepts any Date instance, including invalid dates. The default
JSON serializer encodes valid dates as ISO 8601 strings; invalid dates encode
as "Invalid Date".
Example (Defining a Date schema)
import { Schema } from "effect"
Schema.decodeUnknownSync(Schema.Date)(new Date("2024-01-01"))
// => Date { 2024-01-01T00:00:00.000Z }
Date: Date = function instanceOf<
C extends abstract new (...args: any) => any,
Iso = InstanceType<C>
>(
constructor: C,
annotations?:
| Annotations.Declaration<InstanceType<C>>
| undefined
): instanceOf<InstanceType<C>, Iso>
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
instanceOf(
module globalThisglobalThis.var Date: DateConstructorEnables basic storage and retrieval of dates and times.
Date,
{
Annotations.Declaration<globalThis.Date, readonly []>.typeConstructor?: {
readonly [key: string]: unknown;
readonly _tag: string;
} | undefined
typeConstructor: {
_tag: string_tag: "Date"
},
Annotations.Declaration<globalThis.Date, readonly []>.generation?: {
readonly runtime: string;
readonly Type: string;
readonly Encoded?: string | undefined;
readonly importDeclaration?: string | undefined;
} | undefined
generation: {
runtime: stringruntime: `Schema.Date`,
type Type: stringType: `globalThis.Date`
},
Annotations.Augment.expected?: string | undefinedHuman-readable description of what a value is expected to satisfy.
Details
For filter and refinement failures, the default formatter uses
message first, then expected, and finally falls back to <filter>.
Use this to name a failed filter in the default message:
Expected <expected>, got <actual>.
expected: "Date",
Annotations.Declaration<globalThis.Date, readonly []>.toCodecJson?: ((typeParameters: readonly []) => SchemaAST.Link) | undefinedtoCodecJson: () =>
function link<T>(): <
To extends Constraint
>(
encodeTo: To,
transformation: {
readonly decode: SchemaGetter.Getter<
T,
NoInfer<To["Type"]>
>
readonly encode: SchemaGetter.Getter<
NoInfer<To["Type"]>,
T
>
}
) => SchemaAST.Link
Constructs an SchemaAST.Link that describes how a value of type T encodes to and decodes from a To schema.
Used when building low-level AST transformations that bridge two schema types.
link<module globalThisglobalThis.Date>()(
const DateString: Stringconst DateString: {
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; <…;
}
DateString,
import SchemaTransformationSchemaTransformation.const dateFromString: Transformation<
globalThis.Date,
string
>
const dateFromString: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => SchemaTransformation.Transformation<string, globalThis.Date, never, never>;
compose: (other: SchemaTransformation.Transformation<T2, globalThis.Date, RD2, RE2>) => SchemaTransformation.Transformation<T2, string, RD2, RE2>;
}
Decodes a string into a Date and encodes a Date back to a string.
When to use
Use when you need a schema transformation to parse ISO 8601 date strings from
APIs or user input.
Details
Decoding creates a Date from the string like new Date(s). Encoding
converts the Date to an ISO string like date.toISOString(), returning
"Invalid Date" for invalid dates.
Example (Converting a string to a Date)
import { Schema, SchemaTransformation } from "effect"
const schema = Schema.String.pipe(
Schema.decodeTo(Schema.Date, SchemaTransformation.dateFromString)
)
dateFromString
),
Annotations.Declaration<globalThis.Date, readonly []>.toArbitrary?: Annotations.ToArbitrary.Declaration<globalThis.Date, readonly []> | undefinedtoArbitrary: () => (fc: typeof FastCheckfc, ctx: Annotations.ToArbitrary.Context(parameter) ctx: {
constraint: ToArbitrary.GenerationConstraint | undefined;
recursion: ToArbitrary.Recursion | undefined;
}
ctx) =>
fc: typeof FastCheckfc.date(function dateArbitraryConstraints<any>(
constraint:
| Annotations.ToArbitrary.GenerationConstraint
| undefined,
ordered:
| Annotations.ToArbitrary.OrderedConstraint<any>
| undefined,
base?: DateArbitraryConstraints | undefined,
toDate?:
| ((value: any) => globalThis.Date)
| undefined
): FastCheck.DateConstraints
dateArbitraryConstraints(
ctx: Annotations.ToArbitrary.Context(parameter) ctx: {
constraint: ToArbitrary.GenerationConstraint | undefined;
recursion: ToArbitrary.Recursion | undefined;
}
ctx?.Annotations.ToArbitrary.Context.constraint?: Annotations.ToArbitrary.GenerationConstraint | undefinedconstraint,
ctx: Annotations.ToArbitrary.Context(parameter) ctx: {
constraint: ToArbitrary.GenerationConstraint | undefined;
recursion: ToArbitrary.Recursion | undefined;
}
ctx?.Annotations.ToArbitrary.Context.constraint?: Annotations.ToArbitrary.GenerationConstraint | undefinedconstraint?.Annotations.ToArbitrary.GenerationConstraint.ordered?: Annotations.ToArbitrary.OrderedConstraint<any> | undefinedordered?.Annotations.ToArbitrary.OrderedConstraint<any>.order: Order.Order<T>order === import OrderOrder.Date ? ctx: Annotations.ToArbitrary.Context(parameter) ctx: {
constraint: ToArbitrary.GenerationConstraint | undefined;
recursion: ToArbitrary.Recursion | undefined;
}
ctx.Annotations.ToArbitrary.Context.constraint?: Annotations.ToArbitrary.GenerationConstraint | undefined(property) Annotations.ToArbitrary.Context.constraint?: {
minLength: number | undefined;
maxLength: number | undefined;
patterns: readonly [string, ...Array<string>];
integer: boolean | undefined;
noInfinity: boolean | undefined;
noNaN: boolean | undefined;
valid: boolean | undefined;
unique: boolean | undefined;
ordered: OrderedConstraint<any> | undefined;
}
constraint.Annotations.ToArbitrary.GenerationConstraint.ordered?: Annotations.ToArbitrary.OrderedConstraint<any> | undefined(property) Annotations.ToArbitrary.GenerationConstraint.ordered?: {
order: Order.Order<T>;
minimum: T | undefined;
exclusiveMinimum: boolean | undefined;
maximum: T | undefined;
exclusiveMaximum: boolean | undefined;
}
ordered : var undefinedundefined
))
}
)