Effect.Effect<Zoned, never, CurrentTimeZone>Gets the current time as a DateTime.Zoned, using the CurrentTimeZone.
Example (Getting the current time in the current zone)
import { DateTime, Effect } from "effect"
Effect.gen(function*() {
// will use the "Europe/London" time zone
const now = yield* DateTime.nowInCurrentZone
}).pipe(DateTime.withCurrentZoneNamed("Europe/London"))export const const nowInCurrentZone: Effect.Effect<
Zoned,
never,
CurrentTimeZone
>
const nowInCurrentZone: {
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;
}
Gets the current time as a DateTime.Zoned, using the CurrentTimeZone.
Example (Getting the current time in the current zone)
import { DateTime, Effect } from "effect"
Effect.gen(function*() {
// will use the "Europe/London" time zone
const now = yield* DateTime.nowInCurrentZone
}).pipe(DateTime.withCurrentZoneNamed("Europe/London"))
nowInCurrentZone: import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<Zoned, never, 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 EffectEffect.const flatMap: {
<A, B, E1, R1>(
f: (a: A) => Effect<B, E1, R1>
): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E1 | E, R1 | R>
<A, E, R, B, E1, R1>(
self: Effect<A, E, R>,
f: (a: A) => Effect<B, E1, R1>
): Effect<B, E | E1, R | R1>
}
flatMap(const now: Effect.Effect<Utc>const now: {
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;
}
Gets the current time using the Clock service and convert it to a DateTime.
Example (Getting the current DateTime)
import { DateTime, Effect } from "effect"
Effect.gen(function*() {
const now = yield* DateTime.nowAsDate
console.log(now instanceof Date) // true
})
now, const setZoneCurrent: (
self: DateTime
) => Effect.Effect<Zoned, never, CurrentTimeZone>
Sets the time zone of a DateTime to the current time zone, which is
determined by the CurrentTimeZone service.
Example (Setting the current time zone)
import { DateTime, Effect } from "effect"
Effect.gen(function*() {
const now = yield* DateTime.now
// set the time zone to "Europe/London"
const zoned = yield* DateTime.setZoneCurrent(now)
}).pipe(DateTime.withCurrentZoneNamed("Europe/London"))
setZoneCurrent)