(zoneId: string): Layer.Layer<CurrentTimeZone, IllegalArgumentError>Create a Layer from the given IANA time zone identifier.
Details
This layer provides the CurrentTimeZone service with a named time zone.
If the time zone identifier is invalid, the layer will fail.
Example (Providing named time zone layers)
import { DateTime, Effect } from "effect"
const layer = DateTime.layerCurrentZoneNamed("Europe/London")
const program = Effect.gen(function*() {
const now = yield* DateTime.nowInCurrentZone
return DateTime.formatIsoZoned(now)
})
Effect.provide(program, layer)export const const layerCurrentZoneNamed: (
zoneId: string
) => Layer.Layer<
CurrentTimeZone,
IllegalArgumentError
>
Create a Layer from the given IANA time zone identifier.
Details
This layer provides the CurrentTimeZone service with a named time zone.
If the time zone identifier is invalid, the layer will fail.
Example (Providing named time zone layers)
import { DateTime, Effect } from "effect"
const layer = DateTime.layerCurrentZoneNamed("Europe/London")
const program = Effect.gen(function*() {
const now = yield* DateTime.nowInCurrentZone
return DateTime.formatIsoZoned(now)
})
Effect.provide(program, layer)
layerCurrentZoneNamed: (zoneId: stringzoneId: string) => import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<
class CurrentTimeZoneclass CurrentTimeZone {
Service: Service;
key: Identifier;
}
Context service that supplies the ambient TimeZone for APIs that work in
the current zone, such as DateTime.setZoneCurrent and
DateTime.nowInCurrentZone.
Details
Provide it with DateTime.withCurrentZone, one of the withCurrentZone*
helpers, or one of the layerCurrentZone* layers.
Example (Accessing the current time zone service)
import { DateTime, Effect } from "effect"
const program = Effect.gen(function*() {
// Access the current time zone service
const zone = yield* DateTime.CurrentTimeZone
console.log(DateTime.zoneToString(zone))
})
// Provide a time zone
const layer = DateTime.layerCurrentZoneNamed("Europe/London")
Effect.provide(program, layer)
CurrentTimeZone,
import IllegalArgumentErrorIllegalArgumentError
> = flow<[zoneId: string], Effect.Effect<TimeZone.Named, IllegalArgumentError, never>, Layer.Layer<CurrentTimeZone, IllegalArgumentError, never>>(ab: (zoneId: string) => Effect.Effect<TimeZone.Named, IllegalArgumentError, never>, bc: (b: Effect.Effect<TimeZone.Named, IllegalArgumentError, never>) => Layer.Layer<CurrentTimeZone, IllegalArgumentError, never>): (zoneId: string) => Layer.Layer<CurrentTimeZone, IllegalArgumentError, never> (+8 overloads)Performs left-to-right function composition.
When to use
Use to build a reusable function from a left-to-right sequence of
transformations.
Details
The first function may have any arity. Every following function must be
unary.
Example (Composing functions left to right)
import { flow } from "effect"
import * as assert from "node:assert"
const len = (s: string): number => s.length
const double = (n: number): number => n * 2
const f = flow(len, double)
assert.strictEqual(f("aaa"), 6)
flow(import InternalInternal.const zoneMakeNamedEffect: (
zoneId: string
) => Effect.Effect<
TimeZone.Named,
IllegalArgumentError
>
zoneMakeNamedEffect, import LayerLayer.const effect: {
<I, S>(service: Context.Key<I, S>): <E, R>(
effect: Effect<S, E, R>
) => Layer<I, E, Exclude<R, Scope.Scope>>
<I, S, E, R>(
service: Context.Key<I, S>,
effect: Effect<Types.NoInfer<S>, E, R>
): Layer<I, E, Exclude<R, Scope.Scope>>
}
effect(class CurrentTimeZoneclass CurrentTimeZone {
key: Identifier;
of: (this: void, self: TimeZone) => TimeZone;
context: (self: TimeZone) => Context.Context<CurrentTimeZone>;
use: (f: (service: TimeZone) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, CurrentTimeZone | R>;
useSync: (f: (service: TimeZone) => A) => Effect.Effect<A, never, CurrentTimeZone>;
Identifier: Identifier;
Service: Shape;
stack: string | undefined;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
Context service that supplies the ambient TimeZone for APIs that work in
the current zone, such as DateTime.setZoneCurrent and
DateTime.nowInCurrentZone.
Details
Provide it with DateTime.withCurrentZone, one of the withCurrentZone*
helpers, or one of the layerCurrentZone* layers.
Example (Accessing the current time zone service)
import { DateTime, Effect } from "effect"
const program = Effect.gen(function*() {
// Access the current time zone service
const zone = yield* DateTime.CurrentTimeZone
console.log(DateTime.zoneToString(zone))
})
// Provide a time zone
const layer = DateTime.layerCurrentZoneNamed("Europe/London")
Effect.provide(program, layer)
CurrentTimeZone))