TimeZoneType-level representation of TimeZone.
export interface TimeZone extends interface declare<T, Iso = T>Creates a schema for a non-parametric opaque type using a type-guard
function. The schema accepts any unknown value and succeeds when is returns
true, failing with an InvalidType issue otherwise.
When to use
Use when you are defining a schema for an opaque type with no type parameters
and validation can be expressed as a type guard.
Example (Defining a schema for a custom UserId branded type)
import { Schema } from "effect"
type UserId = string & { readonly _tag: "UserId" }
const isUserId = (u: unknown): u is UserId =>
typeof u === "string" && u.startsWith("user_")
const UserId = Schema.declare<UserId>(isUserId, {
title: "UserId",
description: "A user identifier starting with 'user_'"
})
Type-level representation returned by
declare
.
declare<import DateTimeDateTime.type TimeZone = DateTime.TimeZone.Offset | DateTime.TimeZone.NamedRepresents a time zone used by DateTime.Zoned.
Details
A TimeZone is either a fixed offset from UTC or a named IANA time zone.
Companion namespace containing the public variant and protocol types for
TimeZone.
TimeZone> {
readonly "Rebuild": TimeZone
}
const const TimeZoneString: Stringconst TimeZoneString: {
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; <…;
}
TimeZoneString = 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 time zone string (IANA identifier or offset like +03:00)"
})
/**
* Schema for `DateTime.TimeZone` values.
*
* **Details**
*
* Default JSON serializer:
*
* - encodes `DateTime.TimeZone` as a string (IANA identifier or offset like
* `+03:00`)
*
* @category DateTime
* @since 3.10.0
*/
export const const TimeZone: TimeZoneconst TimeZone: {
Rebuild: TimeZone;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<DateTime.TimeZone, readonly []>) => TimeZone;
annotateKey: (annotations: Annotations.Key<DateTime.TimeZone>) => TimeZone;
check: (checks_0: SchemaAST.Check<DateTime.TimeZone>, ...checks: Array<SchemaAST.Check<DateTime.TimeZone>>) => TimeZone;
rebuild: (ast: SchemaAST.Declaration) => TimeZone;
make: (input: DateTime.TimeZone, options?: MakeOptions) => DateTime.TimeZone;
makeOption: (input: DateTime.TimeZone, options?: MakeOptions) => Option_.Option<DateTime.TimeZone>;
makeEffect: (input: DateTime.TimeZone, options?: MakeOptions) => Effect.Effect<DateTime.TimeZone, 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
TimeZone
.
Schema for DateTime.TimeZone values.
Details
Default JSON serializer:
- encodes
DateTime.TimeZone as a string (IANA identifier or offset like
+03:00)
TimeZone: TimeZone = function declare<T, Iso = T>(
is: (u: unknown) => u is T,
annotations?:
| Annotations.Declaration<T>
| undefined
): declare<T, Iso>
Creates a schema for a non-parametric opaque type using a type-guard
function. The schema accepts any unknown value and succeeds when is returns
true, failing with an InvalidType issue otherwise.
When to use
Use when you are defining a schema for an opaque type with no type parameters
and validation can be expressed as a type guard.
Example (Defining a schema for a custom UserId branded type)
import { Schema } from "effect"
type UserId = string & { readonly _tag: "UserId" }
const isUserId = (u: unknown): u is UserId =>
typeof u === "string" && u.startsWith("user_")
const UserId = Schema.declare<UserId>(isUserId, {
title: "UserId",
description: "A user identifier starting with 'user_'"
})
declare(
import DateTimeDateTime.const isTimeZone: (
u: unknown
) => u is TimeZone
Checks whether a value is a TimeZone.
When to use
Use to narrow unknown input to any TimeZone before passing it to APIs that
accept either fixed-offset or named time zones.
isTimeZone,
{
Annotations.Declaration<TimeZone, readonly []>.typeConstructor?: {
readonly [key: string]: unknown;
readonly _tag: string;
} | undefined
typeConstructor: {
_tag: string_tag: "effect/DateTime.TimeZone"
},
Annotations.Declaration<TimeZone, readonly []>.generation?: {
readonly runtime: string;
readonly Type: string;
readonly Encoded?: string | undefined;
readonly importDeclaration?: string | undefined;
} | undefined
generation: {
runtime: stringruntime: `Schema.TimeZone`,
type Type: stringType: `DateTime.TimeZone`,
importDeclaration?: string | undefinedimportDeclaration: `import * as DateTime from "effect/DateTime"`
},
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: "DateTime.TimeZone",
Annotations.Declaration<TimeZone, 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<import DateTimeDateTime.type TimeZone = DateTime.TimeZone.Offset | DateTime.TimeZone.NamedRepresents a time zone used by DateTime.Zoned.
Details
A TimeZone is either a fixed offset from UTC or a named IANA time zone.
Companion namespace containing the public variant and protocol types for
TimeZone.
TimeZone>()(
const TimeZoneString: Stringconst TimeZoneString: {
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; <…;
}
TimeZoneString,
import SchemaTransformationSchemaTransformation.const timeZoneFromString: Transformation<
DateTime.TimeZone,
string
>
const timeZoneFromString: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => SchemaTransformation.Transformation<string, DateTime.TimeZone, never, never>;
compose: (other: SchemaTransformation.Transformation<T2, DateTime.TimeZone, RD2, RE2>) => SchemaTransformation.Transformation<T2, string, RD2, RE2>;
}
Decodes a string into a DateTime.TimeZone and encodes a time zone back to
its string representation.
When to use
Use when you need a schema transformation to accept either an IANA time-zone
identifier or an offset string and produce a general DateTime.TimeZone.
Details
Accepted decode inputs include valid IANA identifiers and offset strings such
as "+03:00". Decode fails with InvalidValue when the string cannot be
parsed as a time zone.
timeZoneFromString
),
Annotations.Declaration<TimeZone, readonly []>.toArbitrary?: Annotations.ToArbitrary.Declaration<DateTime.TimeZone, readonly []> | undefinedtoArbitrary: () => (fc: typeof FastCheckfc) =>
fc: typeof FastCheckfc.oneof(
fc: typeof FastCheckfc.integer({ min: numbermin: -12 * 60 * 60 * 1000, max: numbermax: 14 * 60 * 60 * 1000 }).map((n: anyn) => import DateTimeDateTime.const zoneMakeOffset: (
offset: number
) => DateTime.TimeZone.Offset
Create a fixed offset time zone.
Details
The offset is specified in milliseconds from UTC. Positive values are
ahead of UTC, negative values are behind UTC.
Example (Creating fixed-offset time zones)
import { DateTime } from "effect"
// Create a time zone with +3 hours offset
const zone = DateTime.zoneMakeOffset(3 * 60 * 60 * 1000)
const dt = DateTime.makeZonedUnsafe("2024-01-01T12:00:00Z", {
timeZone: zone
})
zoneMakeOffset(n: anyn)),
fc: typeof FastCheckfc.constantFrom(
...["UTC", "Europe/London", "America/New_York", "Asia/Tokyo", "Australia/Sydney"].Array<string>.map<DateTime.TimeZone.Named>(callbackfn: (value: string, index: number, array: string[]) => DateTime.TimeZone.Named, thisArg?: any): DateTime.TimeZone.Named[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(
import DateTimeDateTime.const zoneMakeNamedUnsafe: (
zoneId: string
) => DateTime.TimeZone.Named
Attempts to create a named time zone from an IANA time zone identifier.
When to use
Use when the IANA zone id is trusted and invalid zones should throw instead
of returning Option.none or failing in Effect.
Details
If the time zone is invalid, an IllegalArgumentError will be thrown.
Example (Creating named time zones unsafely)
import { DateTime } from "effect"
const londonZone = DateTime.zoneMakeNamedUnsafe("Europe/London")
console.log(DateTime.zoneToString(londonZone)) // "Europe/London"
const tokyoZone = DateTime.zoneMakeNamedUnsafe("Asia/Tokyo")
console.log(DateTime.zoneToString(tokyoZone)) // "Asia/Tokyo"
// This would throw an IllegalArgumentError:
// DateTime.zoneMakeNamedUnsafe("Invalid/Zone")
zoneMakeNamedUnsafe
)
)
),
Annotations.Declaration<TimeZone, readonly []>.toFormatter?: Annotations.ToFormatter.Declaration<DateTime.TimeZone, readonly []> | undefinedtoFormatter: () => (tz: DateTime.TimeZonetz) => import DateTimeDateTime.const zoneToString: (
self: TimeZone
) => string
Formats a TimeZone as a string.
Example (Formatting time zones)
import { DateTime } from "effect"
// Outputs "+03:00"
DateTime.zoneToString(DateTime.zoneMakeOffset(3 * 60 * 60 * 1000))
// Outputs "Europe/London"
DateTime.zoneToString(DateTime.zoneMakeNamedUnsafe("Europe/London"))
zoneToString(tz: DateTime.TimeZonetz),
Annotations.Declaration<TimeZone, readonly []>.toEquivalence?: Annotations.ToEquivalence.Declaration<DateTime.TimeZone, readonly []> | undefinedtoEquivalence: () => (a: DateTime.TimeZonea, b: DateTime.TimeZoneb) => import DateTimeDateTime.const zoneToString: (
self: TimeZone
) => string
Formats a TimeZone as a string.
Example (Formatting time zones)
import { DateTime } from "effect"
// Outputs "+03:00"
DateTime.zoneToString(DateTime.zoneMakeOffset(3 * 60 * 60 * 1000))
// Outputs "Europe/London"
DateTime.zoneToString(DateTime.zoneMakeNamedUnsafe("Europe/London"))
zoneToString(a: DateTime.TimeZonea) === import DateTimeDateTime.const zoneToString: (
self: TimeZone
) => string
Formats a TimeZone as a string.
Example (Formatting time zones)
import { DateTime } from "effect"
// Outputs "+03:00"
DateTime.zoneToString(DateTime.zoneMakeOffset(3 * 60 * 60 * 1000))
// Outputs "Europe/London"
DateTime.zoneToString(DateTime.zoneMakeNamedUnsafe("Europe/London"))
zoneToString(b: DateTime.TimeZoneb)
}
)