(offset: number): Layer.Layer<CurrentTimeZone>Create a Layer from the given time zone offset.
Details
This layer provides the CurrentTimeZone service with a fixed offset time zone.
Example (Providing fixed-offset time zone layers)
import { DateTime, Effect } from "effect"
// Create a layer for UTC+3
const layer = DateTime.layerCurrentZoneOffset(3 * 60 * 60 * 1000)
const program = Effect.gen(function*() {
const now = yield* DateTime.nowInCurrentZone
return DateTime.formatIsoZoned(now)
})
Effect.provide(program, layer)export const const layerCurrentZoneOffset: (
offset: number
) => Layer.Layer<CurrentTimeZone>
Create a Layer from the given time zone offset.
Details
This layer provides the CurrentTimeZone service with a fixed offset time zone.
Example (Providing fixed-offset time zone layers)
import { DateTime, Effect } from "effect"
// Create a layer for UTC+3
const layer = DateTime.layerCurrentZoneOffset(3 * 60 * 60 * 1000)
const program = Effect.gen(function*() {
const now = yield* DateTime.nowInCurrentZone
return DateTime.formatIsoZoned(now)
})
Effect.provide(program, layer)
layerCurrentZoneOffset = (offset: numberoffset: number): 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 LayerLayer.const succeed: {
<I, S>(service: Context.Key<I, S>): (
resource: S
) => Layer<I>
<I, S>(
service: Context.Key<I, S>,
resource: Types.NoInfer<S>
): Layer<I>
}
succeed(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)(import InternalInternal.const zoneMakeOffset: (
offset: number
) => TimeZone.Offset
zoneMakeOffset(offset: numberoffset))