@clayroach/effect 3.19.14-source-capture.8 → 3.19.14-source-trace.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SourceLocation/package.json +6 -0
- package/dist/cjs/Effect.js +2 -28
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/FiberRef.js +12 -1
- package/dist/cjs/FiberRef.js.map +1 -1
- package/dist/cjs/Layer.js +2 -24
- package/dist/cjs/Layer.js.map +1 -1
- package/dist/cjs/RuntimeFlags.js +1 -29
- package/dist/cjs/RuntimeFlags.js.map +1 -1
- package/dist/cjs/SourceLocation.js +60 -0
- package/dist/cjs/SourceLocation.js.map +1 -0
- package/dist/cjs/Tracer.js +1 -15
- package/dist/cjs/Tracer.js.map +1 -1
- package/dist/cjs/Utils.js +1 -1
- package/dist/cjs/Utils.js.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/clock.js +1 -1
- package/dist/cjs/internal/clock.js.map +1 -1
- package/dist/cjs/internal/core.js +17 -50
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/effect/circular.js +18 -30
- package/dist/cjs/internal/effect/circular.js.map +1 -1
- package/dist/cjs/internal/fiberRuntime.js +16 -65
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/layer/circular.js +1 -5
- package/dist/cjs/internal/layer/circular.js.map +1 -1
- package/dist/cjs/internal/layer.js +1 -3
- package/dist/cjs/internal/layer.js.map +1 -1
- package/dist/cjs/internal/logger.js +25 -2
- package/dist/cjs/internal/logger.js.map +1 -1
- package/dist/cjs/internal/runtimeFlags.js +2 -11
- package/dist/cjs/internal/runtimeFlags.js.map +1 -1
- package/dist/cjs/internal/tracer.js +1 -114
- package/dist/cjs/internal/tracer.js.map +1 -1
- package/dist/dts/Config.d.ts +2 -2
- package/dist/dts/Config.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +8 -29
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/FiberRef.d.ts +12 -0
- package/dist/dts/FiberRef.d.ts.map +1 -1
- package/dist/dts/Layer.d.ts +0 -22
- package/dist/dts/Layer.d.ts.map +1 -1
- package/dist/dts/RuntimeFlags.d.ts +0 -28
- package/dist/dts/RuntimeFlags.d.ts.map +1 -1
- package/dist/dts/SourceLocation.d.ts +88 -0
- package/dist/dts/SourceLocation.d.ts.map +1 -0
- package/dist/dts/Tracer.d.ts +0 -15
- package/dist/dts/Tracer.d.ts.map +1 -1
- package/dist/dts/index.d.ts +6 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/core.d.ts.map +1 -1
- package/dist/dts/internal/layer.d.ts.map +1 -1
- package/dist/dts/internal/runtimeFlags.d.ts.map +1 -1
- package/dist/esm/Effect.js +0 -26
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/FiberRef.js +11 -0
- package/dist/esm/FiberRef.js.map +1 -1
- package/dist/esm/Layer.js +0 -22
- package/dist/esm/Layer.js.map +1 -1
- package/dist/esm/RuntimeFlags.js +0 -28
- package/dist/esm/RuntimeFlags.js.map +1 -1
- package/dist/esm/SourceLocation.js +51 -0
- package/dist/esm/SourceLocation.js.map +1 -0
- package/dist/esm/Tracer.js +0 -14
- package/dist/esm/Tracer.js.map +1 -1
- package/dist/esm/Utils.js +1 -1
- package/dist/esm/Utils.js.map +1 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/clock.js +1 -1
- package/dist/esm/internal/clock.js.map +1 -1
- package/dist/esm/internal/core.js +12 -45
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/effect/circular.js +18 -30
- package/dist/esm/internal/effect/circular.js.map +1 -1
- package/dist/esm/internal/fiberRuntime.js +13 -60
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/layer/circular.js +0 -4
- package/dist/esm/internal/layer/circular.js.map +1 -1
- package/dist/esm/internal/layer.js +0 -2
- package/dist/esm/internal/layer.js.map +1 -1
- package/dist/esm/internal/logger.js +25 -2
- package/dist/esm/internal/logger.js.map +1 -1
- package/dist/esm/internal/runtimeFlags.js +1 -9
- package/dist/esm/internal/runtimeFlags.js.map +1 -1
- package/dist/esm/internal/tracer.js +0 -111
- package/dist/esm/internal/tracer.js.map +1 -1
- package/package.json +12 -1
- package/src/Arbitrary.ts +1101 -0
- package/src/Array.ts +3589 -0
- package/src/BigDecimal.ts +1349 -0
- package/src/BigInt.ts +643 -0
- package/src/Boolean.ts +287 -0
- package/src/Brand.ts +360 -0
- package/src/Cache.ts +281 -0
- package/src/Cause.ts +1555 -0
- package/src/Channel.ts +2355 -0
- package/src/ChildExecutorDecision.ts +146 -0
- package/src/Chunk.ts +1495 -0
- package/src/Clock.ts +111 -0
- package/src/Config.ts +542 -0
- package/src/ConfigError.ts +270 -0
- package/src/ConfigProvider.ts +333 -0
- package/src/ConfigProviderPathPatch.ts +100 -0
- package/src/Console.ts +226 -0
- package/src/Context.ts +585 -0
- package/src/Cron.ts +706 -0
- package/src/Data.ts +596 -0
- package/src/DateTime.ts +1686 -0
- package/src/DefaultServices.ts +34 -0
- package/src/Deferred.ts +301 -0
- package/src/Differ.ts +450 -0
- package/src/Duration.ts +1000 -0
- package/src/Effect.ts +14817 -0
- package/src/Effectable.ts +107 -0
- package/src/Either.ts +1040 -0
- package/src/Encoding.ts +195 -0
- package/src/Equal.ts +98 -0
- package/src/Equivalence.ts +235 -0
- package/src/ExecutionPlan.ts +308 -0
- package/src/ExecutionStrategy.ts +119 -0
- package/src/Exit.ts +467 -0
- package/src/FastCheck.ts +9 -0
- package/src/Fiber.ts +744 -0
- package/src/FiberHandle.ts +540 -0
- package/src/FiberId.ts +195 -0
- package/src/FiberMap.ts +656 -0
- package/src/FiberRef.ts +444 -0
- package/src/FiberRefs.ts +204 -0
- package/src/FiberRefsPatch.ts +105 -0
- package/src/FiberSet.ts +491 -0
- package/src/FiberStatus.ts +108 -0
- package/src/Function.ts +1222 -0
- package/src/GlobalValue.ts +53 -0
- package/src/Graph.ts +3732 -0
- package/src/GroupBy.ts +103 -0
- package/src/HKT.ts +45 -0
- package/src/Hash.ts +195 -0
- package/src/HashMap.ts +519 -0
- package/src/HashRing.ts +317 -0
- package/src/HashSet.ts +2346 -0
- package/src/Inspectable.ts +287 -0
- package/src/Iterable.ts +1119 -0
- package/src/JSONSchema.ts +1044 -0
- package/src/KeyedPool.ts +167 -0
- package/src/Layer.ts +1228 -0
- package/src/LayerMap.ts +436 -0
- package/src/List.ts +977 -0
- package/src/LogLevel.ts +285 -0
- package/src/LogSpan.ts +25 -0
- package/src/Logger.ts +702 -0
- package/src/Mailbox.ts +268 -0
- package/src/ManagedRuntime.ts +180 -0
- package/src/Match.ts +1477 -0
- package/src/MergeDecision.ts +95 -0
- package/src/MergeState.ts +172 -0
- package/src/MergeStrategy.ts +107 -0
- package/src/Metric.ts +780 -0
- package/src/MetricBoundaries.ts +69 -0
- package/src/MetricHook.ts +151 -0
- package/src/MetricKey.ts +224 -0
- package/src/MetricKeyType.ts +262 -0
- package/src/MetricLabel.ts +47 -0
- package/src/MetricPair.ts +71 -0
- package/src/MetricPolling.ts +148 -0
- package/src/MetricRegistry.ts +48 -0
- package/src/MetricState.ts +257 -0
- package/src/Micro.ts +4405 -0
- package/src/ModuleVersion.ts +18 -0
- package/src/MutableHashMap.ts +411 -0
- package/src/MutableHashSet.ts +706 -0
- package/src/MutableList.ts +297 -0
- package/src/MutableQueue.ts +227 -0
- package/src/MutableRef.ts +202 -0
- package/src/NonEmptyIterable.ts +32 -0
- package/src/Number.ts +1071 -0
- package/src/Option.ts +2170 -0
- package/src/Order.ts +373 -0
- package/src/Ordering.ts +111 -0
- package/src/ParseResult.ts +2031 -0
- package/src/PartitionedSemaphore.ts +200 -0
- package/src/Pipeable.ts +566 -0
- package/src/Pool.ts +204 -0
- package/src/Predicate.ts +1405 -0
- package/src/Pretty.ts +205 -0
- package/src/PrimaryKey.ts +23 -0
- package/src/PubSub.ts +182 -0
- package/src/Queue.ts +644 -0
- package/src/Random.ts +204 -0
- package/src/RateLimiter.ts +138 -0
- package/src/RcMap.ts +141 -0
- package/src/RcRef.ts +122 -0
- package/src/Readable.ts +93 -0
- package/src/Record.ts +1274 -0
- package/src/RedBlackTree.ts +421 -0
- package/src/Redacted.ts +144 -0
- package/src/Ref.ts +180 -0
- package/src/RegExp.ts +38 -0
- package/src/Reloadable.ts +127 -0
- package/src/Request.ts +347 -0
- package/src/RequestBlock.ts +118 -0
- package/src/RequestResolver.ts +366 -0
- package/src/Resource.ts +119 -0
- package/src/Runtime.ts +383 -0
- package/src/RuntimeFlags.ts +336 -0
- package/src/RuntimeFlagsPatch.ts +183 -0
- package/src/STM.ts +2045 -0
- package/src/Schedule.ts +2219 -0
- package/src/ScheduleDecision.ts +62 -0
- package/src/ScheduleInterval.ts +151 -0
- package/src/ScheduleIntervals.ts +122 -0
- package/src/Scheduler.ts +353 -0
- package/src/Schema.ts +10914 -0
- package/src/SchemaAST.ts +3043 -0
- package/src/Scope.ts +204 -0
- package/src/ScopedCache.ts +151 -0
- package/src/ScopedRef.ts +117 -0
- package/src/Secret.ts +88 -0
- package/src/SingleProducerAsyncInput.ts +67 -0
- package/src/Sink.ts +1461 -0
- package/src/SortedMap.ts +287 -0
- package/src/SortedSet.ts +390 -0
- package/src/SourceLocation.ts +108 -0
- package/src/Stream.ts +6468 -0
- package/src/StreamEmit.ts +136 -0
- package/src/StreamHaltStrategy.ts +123 -0
- package/src/Streamable.ts +45 -0
- package/src/String.ts +778 -0
- package/src/Struct.ts +243 -0
- package/src/Subscribable.ts +100 -0
- package/src/SubscriptionRef.ts +298 -0
- package/src/Supervisor.ts +240 -0
- package/src/Symbol.ts +29 -0
- package/src/SynchronizedRef.ts +270 -0
- package/src/TArray.ts +495 -0
- package/src/TDeferred.ts +100 -0
- package/src/TMap.ts +515 -0
- package/src/TPriorityQueue.ts +223 -0
- package/src/TPubSub.ts +200 -0
- package/src/TQueue.ts +432 -0
- package/src/TRandom.ts +129 -0
- package/src/TReentrantLock.ts +224 -0
- package/src/TRef.ts +178 -0
- package/src/TSemaphore.ts +129 -0
- package/src/TSet.ts +365 -0
- package/src/TSubscriptionRef.ts +192 -0
- package/src/Take.ts +258 -0
- package/src/TestAnnotation.ts +158 -0
- package/src/TestAnnotationMap.ts +119 -0
- package/src/TestAnnotations.ts +117 -0
- package/src/TestClock.ts +556 -0
- package/src/TestConfig.ts +47 -0
- package/src/TestContext.ts +36 -0
- package/src/TestLive.ts +53 -0
- package/src/TestServices.ts +390 -0
- package/src/TestSized.ts +55 -0
- package/src/Tracer.ts +182 -0
- package/src/Trie.ts +840 -0
- package/src/Tuple.ts +305 -0
- package/src/Types.ts +353 -0
- package/src/Unify.ts +113 -0
- package/src/UpstreamPullRequest.ts +117 -0
- package/src/UpstreamPullStrategy.ts +121 -0
- package/src/Utils.ts +809 -0
- package/src/index.ts +1568 -0
- package/src/internal/array.ts +8 -0
- package/src/internal/blockedRequests.ts +520 -0
- package/src/internal/cache.ts +733 -0
- package/src/internal/cause.ts +1050 -0
- package/src/internal/channel/channelExecutor.ts +1200 -0
- package/src/internal/channel/channelState.ts +134 -0
- package/src/internal/channel/childExecutorDecision.ts +96 -0
- package/src/internal/channel/continuation.ts +200 -0
- package/src/internal/channel/mergeDecision.ts +113 -0
- package/src/internal/channel/mergeState.ts +120 -0
- package/src/internal/channel/mergeStrategy.ts +72 -0
- package/src/internal/channel/singleProducerAsyncInput.ts +259 -0
- package/src/internal/channel/subexecutor.ts +229 -0
- package/src/internal/channel/upstreamPullRequest.ts +84 -0
- package/src/internal/channel/upstreamPullStrategy.ts +87 -0
- package/src/internal/channel.ts +2603 -0
- package/src/internal/clock.ts +95 -0
- package/src/internal/completedRequestMap.ts +9 -0
- package/src/internal/concurrency.ts +54 -0
- package/src/internal/config.ts +716 -0
- package/src/internal/configError.ts +304 -0
- package/src/internal/configProvider/pathPatch.ts +97 -0
- package/src/internal/configProvider.ts +799 -0
- package/src/internal/console.ts +153 -0
- package/src/internal/context.ts +337 -0
- package/src/internal/core-effect.ts +2293 -0
- package/src/internal/core-stream.ts +998 -0
- package/src/internal/core.ts +3189 -0
- package/src/internal/data.ts +36 -0
- package/src/internal/dataSource.ts +327 -0
- package/src/internal/dateTime.ts +1277 -0
- package/src/internal/defaultServices/console.ts +100 -0
- package/src/internal/defaultServices.ts +163 -0
- package/src/internal/deferred.ts +46 -0
- package/src/internal/differ/chunkPatch.ts +211 -0
- package/src/internal/differ/contextPatch.ts +232 -0
- package/src/internal/differ/hashMapPatch.ts +220 -0
- package/src/internal/differ/hashSetPatch.ts +176 -0
- package/src/internal/differ/orPatch.ts +311 -0
- package/src/internal/differ/readonlyArrayPatch.ts +210 -0
- package/src/internal/differ.ts +200 -0
- package/src/internal/doNotation.ts +80 -0
- package/src/internal/effect/circular.ts +895 -0
- package/src/internal/effectable.ts +131 -0
- package/src/internal/either.ts +110 -0
- package/src/internal/encoding/base64.ts +286 -0
- package/src/internal/encoding/base64Url.ts +29 -0
- package/src/internal/encoding/common.ts +51 -0
- package/src/internal/encoding/hex.ts +315 -0
- package/src/internal/errors.ts +7 -0
- package/src/internal/executionPlan.ts +114 -0
- package/src/internal/executionStrategy.ts +74 -0
- package/src/internal/fiber.ts +388 -0
- package/src/internal/fiberId.ts +267 -0
- package/src/internal/fiberMessage.ts +82 -0
- package/src/internal/fiberRefs/patch.ts +144 -0
- package/src/internal/fiberRefs.ts +297 -0
- package/src/internal/fiberRuntime.ts +3842 -0
- package/src/internal/fiberScope.ts +71 -0
- package/src/internal/fiberStatus.ts +119 -0
- package/src/internal/groupBy.ts +530 -0
- package/src/internal/hashMap/array.ts +49 -0
- package/src/internal/hashMap/bitwise.ts +32 -0
- package/src/internal/hashMap/config.ts +14 -0
- package/src/internal/hashMap/keySet.ts +8 -0
- package/src/internal/hashMap/node.ts +391 -0
- package/src/internal/hashMap.ts +586 -0
- package/src/internal/hashSet.ts +323 -0
- package/src/internal/keyedPool.ts +244 -0
- package/src/internal/layer/circular.ts +214 -0
- package/src/internal/layer.ts +1483 -0
- package/src/internal/logSpan.ts +20 -0
- package/src/internal/logger-circular.ts +24 -0
- package/src/internal/logger.ts +522 -0
- package/src/internal/mailbox.ts +561 -0
- package/src/internal/managedRuntime/circular.ts +6 -0
- package/src/internal/managedRuntime.ts +134 -0
- package/src/internal/matcher.ts +652 -0
- package/src/internal/metric/boundaries.ts +75 -0
- package/src/internal/metric/hook.ts +483 -0
- package/src/internal/metric/key.ts +167 -0
- package/src/internal/metric/keyType.ts +238 -0
- package/src/internal/metric/label.ts +41 -0
- package/src/internal/metric/pair.ts +48 -0
- package/src/internal/metric/polling.ts +149 -0
- package/src/internal/metric/registry.ts +187 -0
- package/src/internal/metric/state.ts +290 -0
- package/src/internal/metric.ts +577 -0
- package/src/internal/opCodes/cause.ts +35 -0
- package/src/internal/opCodes/channel.ts +83 -0
- package/src/internal/opCodes/channelChildExecutorDecision.ts +17 -0
- package/src/internal/opCodes/channelMergeDecision.ts +11 -0
- package/src/internal/opCodes/channelMergeState.ts +17 -0
- package/src/internal/opCodes/channelMergeStrategy.ts +11 -0
- package/src/internal/opCodes/channelState.ts +23 -0
- package/src/internal/opCodes/channelUpstreamPullRequest.ts +11 -0
- package/src/internal/opCodes/channelUpstreamPullStrategy.ts +11 -0
- package/src/internal/opCodes/config.ts +65 -0
- package/src/internal/opCodes/configError.ts +35 -0
- package/src/internal/opCodes/continuation.ts +11 -0
- package/src/internal/opCodes/deferred.ts +11 -0
- package/src/internal/opCodes/effect.ts +89 -0
- package/src/internal/opCodes/layer.ts +59 -0
- package/src/internal/opCodes/streamHaltStrategy.ts +23 -0
- package/src/internal/option.ts +80 -0
- package/src/internal/pool.ts +432 -0
- package/src/internal/pubsub.ts +1762 -0
- package/src/internal/query.ts +204 -0
- package/src/internal/queue.ts +766 -0
- package/src/internal/random.ts +161 -0
- package/src/internal/rateLimiter.ts +93 -0
- package/src/internal/rcMap.ts +285 -0
- package/src/internal/rcRef.ts +192 -0
- package/src/internal/redBlackTree/iterator.ts +200 -0
- package/src/internal/redBlackTree/node.ts +68 -0
- package/src/internal/redBlackTree.ts +1245 -0
- package/src/internal/redacted.ts +73 -0
- package/src/internal/ref.ts +171 -0
- package/src/internal/reloadable.ts +140 -0
- package/src/internal/request.ts +177 -0
- package/src/internal/resource.ts +76 -0
- package/src/internal/ringBuffer.ts +68 -0
- package/src/internal/runtime.ts +558 -0
- package/src/internal/runtimeFlags.ts +178 -0
- package/src/internal/runtimeFlagsPatch.ts +103 -0
- package/src/internal/schedule/decision.ts +47 -0
- package/src/internal/schedule/interval.ts +101 -0
- package/src/internal/schedule/intervals.ts +180 -0
- package/src/internal/schedule.ts +2199 -0
- package/src/internal/schema/errors.ts +191 -0
- package/src/internal/schema/schemaId.ts +106 -0
- package/src/internal/schema/util.ts +50 -0
- package/src/internal/scopedCache.ts +644 -0
- package/src/internal/scopedRef.ts +118 -0
- package/src/internal/secret.ts +89 -0
- package/src/internal/singleShotGen.ts +35 -0
- package/src/internal/sink.ts +2120 -0
- package/src/internal/stack.ts +10 -0
- package/src/internal/stm/core.ts +817 -0
- package/src/internal/stm/entry.ts +59 -0
- package/src/internal/stm/journal.ts +123 -0
- package/src/internal/stm/opCodes/stm.ts +71 -0
- package/src/internal/stm/opCodes/stmState.ts +17 -0
- package/src/internal/stm/opCodes/strategy.ts +17 -0
- package/src/internal/stm/opCodes/tExit.ts +29 -0
- package/src/internal/stm/opCodes/tryCommit.ts +11 -0
- package/src/internal/stm/stm.ts +1453 -0
- package/src/internal/stm/stmState.ts +136 -0
- package/src/internal/stm/tArray.ts +550 -0
- package/src/internal/stm/tDeferred.ts +81 -0
- package/src/internal/stm/tExit.ts +190 -0
- package/src/internal/stm/tMap.ts +824 -0
- package/src/internal/stm/tPriorityQueue.ts +267 -0
- package/src/internal/stm/tPubSub.ts +551 -0
- package/src/internal/stm/tQueue.ts +393 -0
- package/src/internal/stm/tRandom.ts +140 -0
- package/src/internal/stm/tReentrantLock.ts +352 -0
- package/src/internal/stm/tRef.ts +195 -0
- package/src/internal/stm/tSemaphore.ts +113 -0
- package/src/internal/stm/tSet.ts +259 -0
- package/src/internal/stm/tSubscriptionRef.ts +286 -0
- package/src/internal/stm/tryCommit.ts +34 -0
- package/src/internal/stm/txnId.ts +14 -0
- package/src/internal/stm/versioned.ts +4 -0
- package/src/internal/stream/debounceState.ts +57 -0
- package/src/internal/stream/emit.ts +123 -0
- package/src/internal/stream/haltStrategy.ts +94 -0
- package/src/internal/stream/handoff.ts +187 -0
- package/src/internal/stream/handoffSignal.ts +59 -0
- package/src/internal/stream/pull.ts +34 -0
- package/src/internal/stream/sinkEndReason.ts +30 -0
- package/src/internal/stream/zipAllState.ts +88 -0
- package/src/internal/stream/zipChunksState.ts +56 -0
- package/src/internal/stream.ts +8801 -0
- package/src/internal/string-utils.ts +107 -0
- package/src/internal/subscriptionRef.ts +138 -0
- package/src/internal/supervisor/patch.ts +190 -0
- package/src/internal/supervisor.ts +303 -0
- package/src/internal/synchronizedRef.ts +114 -0
- package/src/internal/take.ts +199 -0
- package/src/internal/testing/sleep.ts +27 -0
- package/src/internal/testing/suspendedWarningData.ts +85 -0
- package/src/internal/testing/warningData.ts +94 -0
- package/src/internal/tracer.ts +150 -0
- package/src/internal/trie.ts +722 -0
- package/src/internal/version.ts +7 -0
package/src/DateTime.ts
ADDED
|
@@ -0,0 +1,1686 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 3.6.0
|
|
3
|
+
*/
|
|
4
|
+
import type { IllegalArgumentException } from "./Cause.js"
|
|
5
|
+
import * as Context from "./Context.js"
|
|
6
|
+
import type * as Duration from "./Duration.js"
|
|
7
|
+
import * as Effect from "./Effect.js"
|
|
8
|
+
import type * as Either from "./Either.js"
|
|
9
|
+
import type * as equivalence from "./Equivalence.js"
|
|
10
|
+
import { dual, type LazyArg } from "./Function.js"
|
|
11
|
+
import type { Inspectable } from "./Inspectable.js"
|
|
12
|
+
import * as Internal from "./internal/dateTime.js"
|
|
13
|
+
import * as Layer from "./Layer.js"
|
|
14
|
+
import type * as Option from "./Option.js"
|
|
15
|
+
import type * as order from "./Order.js"
|
|
16
|
+
import type { Pipeable } from "./Pipeable.js"
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @since 3.6.0
|
|
20
|
+
* @category type ids
|
|
21
|
+
*/
|
|
22
|
+
export const TypeId: unique symbol = Internal.TypeId
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @since 3.6.0
|
|
26
|
+
* @category type ids
|
|
27
|
+
*/
|
|
28
|
+
export type TypeId = typeof TypeId
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A `DateTime` represents a point in time. It can optionally have a time zone
|
|
32
|
+
* associated with it.
|
|
33
|
+
*
|
|
34
|
+
* @since 3.6.0
|
|
35
|
+
* @category models
|
|
36
|
+
*/
|
|
37
|
+
export type DateTime = Utc | Zoned
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @since 3.6.0
|
|
41
|
+
* @category models
|
|
42
|
+
*/
|
|
43
|
+
export interface Utc extends DateTime.Proto {
|
|
44
|
+
readonly _tag: "Utc"
|
|
45
|
+
readonly epochMillis: number
|
|
46
|
+
partsUtc: DateTime.PartsWithWeekday | undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @since 3.6.0
|
|
51
|
+
* @category models
|
|
52
|
+
*/
|
|
53
|
+
export interface Zoned extends DateTime.Proto {
|
|
54
|
+
readonly _tag: "Zoned"
|
|
55
|
+
readonly epochMillis: number
|
|
56
|
+
readonly zone: TimeZone
|
|
57
|
+
adjustedEpochMillis: number | undefined
|
|
58
|
+
partsAdjusted: DateTime.PartsWithWeekday | undefined
|
|
59
|
+
partsUtc: DateTime.PartsWithWeekday | undefined
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @since 3.6.0
|
|
64
|
+
* @category models
|
|
65
|
+
*/
|
|
66
|
+
export declare namespace DateTime {
|
|
67
|
+
/**
|
|
68
|
+
* @since 3.6.0
|
|
69
|
+
* @category models
|
|
70
|
+
*/
|
|
71
|
+
export type Input = DateTime | Partial<Parts> | Date | number | string
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @since 3.6.0
|
|
75
|
+
* @category models
|
|
76
|
+
*/
|
|
77
|
+
export type PreserveZone<A extends DateTime.Input> = A extends Zoned ? Zoned : Utc
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @since 3.6.0
|
|
81
|
+
* @category models
|
|
82
|
+
*/
|
|
83
|
+
export type Unit = UnitSingular | UnitPlural
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @since 3.6.0
|
|
87
|
+
* @category models
|
|
88
|
+
*/
|
|
89
|
+
export type UnitSingular =
|
|
90
|
+
| "milli"
|
|
91
|
+
| "second"
|
|
92
|
+
| "minute"
|
|
93
|
+
| "hour"
|
|
94
|
+
| "day"
|
|
95
|
+
| "week"
|
|
96
|
+
| "month"
|
|
97
|
+
| "year"
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @since 3.6.0
|
|
101
|
+
* @category models
|
|
102
|
+
*/
|
|
103
|
+
export type UnitPlural =
|
|
104
|
+
| "millis"
|
|
105
|
+
| "seconds"
|
|
106
|
+
| "minutes"
|
|
107
|
+
| "hours"
|
|
108
|
+
| "days"
|
|
109
|
+
| "weeks"
|
|
110
|
+
| "months"
|
|
111
|
+
| "years"
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @since 3.6.0
|
|
115
|
+
* @category models
|
|
116
|
+
*/
|
|
117
|
+
export interface PartsWithWeekday {
|
|
118
|
+
readonly millis: number
|
|
119
|
+
readonly seconds: number
|
|
120
|
+
readonly minutes: number
|
|
121
|
+
readonly hours: number
|
|
122
|
+
readonly day: number
|
|
123
|
+
readonly weekDay: number
|
|
124
|
+
readonly month: number
|
|
125
|
+
readonly year: number
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @since 3.6.0
|
|
130
|
+
* @category models
|
|
131
|
+
*/
|
|
132
|
+
export interface Parts {
|
|
133
|
+
readonly millis: number
|
|
134
|
+
readonly seconds: number
|
|
135
|
+
readonly minutes: number
|
|
136
|
+
readonly hours: number
|
|
137
|
+
readonly day: number
|
|
138
|
+
readonly month: number
|
|
139
|
+
readonly year: number
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @since 3.6.0
|
|
144
|
+
* @category models
|
|
145
|
+
*/
|
|
146
|
+
export interface PartsForMath {
|
|
147
|
+
readonly millis: number
|
|
148
|
+
readonly seconds: number
|
|
149
|
+
readonly minutes: number
|
|
150
|
+
readonly hours: number
|
|
151
|
+
readonly days: number
|
|
152
|
+
readonly weeks: number
|
|
153
|
+
readonly months: number
|
|
154
|
+
readonly years: number
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @since 3.6.0
|
|
159
|
+
* @category models
|
|
160
|
+
*/
|
|
161
|
+
export interface Proto extends Pipeable, Inspectable {
|
|
162
|
+
readonly [TypeId]: TypeId
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @since 3.6.0
|
|
168
|
+
* @category type ids
|
|
169
|
+
*/
|
|
170
|
+
export const TimeZoneTypeId: unique symbol = Internal.TimeZoneTypeId
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @since 3.6.0
|
|
174
|
+
* @category type ids
|
|
175
|
+
*/
|
|
176
|
+
export type TimeZoneTypeId = typeof TimeZoneTypeId
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @since 3.6.0
|
|
180
|
+
* @category models
|
|
181
|
+
*/
|
|
182
|
+
export type TimeZone = TimeZone.Offset | TimeZone.Named
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @since 3.6.0
|
|
186
|
+
* @category models
|
|
187
|
+
*/
|
|
188
|
+
export declare namespace TimeZone {
|
|
189
|
+
/**
|
|
190
|
+
* @since 3.6.0
|
|
191
|
+
* @category models
|
|
192
|
+
*/
|
|
193
|
+
export interface Proto extends Inspectable {
|
|
194
|
+
readonly [TimeZoneTypeId]: TimeZoneTypeId
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @since 3.6.0
|
|
199
|
+
* @category models
|
|
200
|
+
*/
|
|
201
|
+
export interface Offset extends Proto {
|
|
202
|
+
readonly _tag: "Offset"
|
|
203
|
+
readonly offset: number
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @since 3.6.0
|
|
208
|
+
* @category models
|
|
209
|
+
*/
|
|
210
|
+
export interface Named extends Proto {
|
|
211
|
+
readonly _tag: "Named"
|
|
212
|
+
readonly id: string
|
|
213
|
+
/** @internal */
|
|
214
|
+
readonly format: Intl.DateTimeFormat
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* A `Disambiguation` is used to resolve ambiguities when a `DateTime` is
|
|
220
|
+
* ambiguous, such as during a daylight saving time transition.
|
|
221
|
+
*
|
|
222
|
+
* For more information, see the [Temporal documentation](https://tc39.es/proposal-temporal/docs/timezone.html#ambiguity-due-to-dst-or-other-time-zone-offset-changes)
|
|
223
|
+
*
|
|
224
|
+
* - `"compatible"`: (default) Behavior matching Temporal API and legacy JavaScript Date and moment.js.
|
|
225
|
+
* For repeated times, chooses the earlier occurrence. For gap times, chooses the later interpretation.
|
|
226
|
+
*
|
|
227
|
+
* - `"earlier"`: For repeated times, always choose the earlier occurrence.
|
|
228
|
+
* For gap times, choose the time before the gap.
|
|
229
|
+
*
|
|
230
|
+
* - `"later"`: For repeated times, always choose the later occurrence.
|
|
231
|
+
* For gap times, choose the time after the gap.
|
|
232
|
+
*
|
|
233
|
+
* - `"reject"`: Throw an `RangeError` when encountering ambiguous or non-existent times.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* import { DateTime } from "effect"
|
|
238
|
+
*
|
|
239
|
+
* // Fall-back example: 01:30 on Nov 2, 2025 in New York happens twice
|
|
240
|
+
* const ambiguousTime = { year: 2025, month: 11, day: 2, hours: 1, minutes: 30 }
|
|
241
|
+
* const timeZone = DateTime.zoneUnsafeMakeNamed("America/New_York")
|
|
242
|
+
*
|
|
243
|
+
* DateTime.makeZoned(ambiguousTime, { timeZone, adjustForTimeZone: true, disambiguation: "earlier" })
|
|
244
|
+
* // Earlier occurrence (DST time): 2025-11-02T05:30:00.000Z
|
|
245
|
+
*
|
|
246
|
+
* DateTime.makeZoned(ambiguousTime, { timeZone, adjustForTimeZone: true, disambiguation: "later" })
|
|
247
|
+
* // Later occurrence (standard time): 2025-11-02T06:30:00.000Z
|
|
248
|
+
*
|
|
249
|
+
* // Gap example: 02:30 on Mar 9, 2025 in New York doesn't exist
|
|
250
|
+
* const gapTime = { year: 2025, month: 3, day: 9, hours: 2, minutes: 30 }
|
|
251
|
+
*
|
|
252
|
+
* DateTime.makeZoned(gapTime, { timeZone, adjustForTimeZone: true, disambiguation: "earlier" })
|
|
253
|
+
* // Time before gap: 2025-03-09T06:30:00.000Z (01:30 EST)
|
|
254
|
+
*
|
|
255
|
+
* DateTime.makeZoned(gapTime, { timeZone, adjustForTimeZone: true, disambiguation: "later" })
|
|
256
|
+
* // Time after gap: 2025-03-09T07:30:00.000Z (03:30 EDT)
|
|
257
|
+
* ```
|
|
258
|
+
*
|
|
259
|
+
* @since 3.18.0
|
|
260
|
+
* @category models
|
|
261
|
+
*/
|
|
262
|
+
export type Disambiguation = "compatible" | "earlier" | "later" | "reject"
|
|
263
|
+
|
|
264
|
+
// =============================================================================
|
|
265
|
+
// guards
|
|
266
|
+
// =============================================================================
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @since 3.6.0
|
|
270
|
+
* @category guards
|
|
271
|
+
*/
|
|
272
|
+
export const isDateTime: (u: unknown) => u is DateTime = Internal.isDateTime
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* @since 3.6.0
|
|
276
|
+
* @category guards
|
|
277
|
+
*/
|
|
278
|
+
export const isTimeZone: (u: unknown) => u is TimeZone = Internal.isTimeZone
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* @since 3.6.0
|
|
282
|
+
* @category guards
|
|
283
|
+
*/
|
|
284
|
+
export const isTimeZoneOffset: (u: unknown) => u is TimeZone.Offset = Internal.isTimeZoneOffset
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* @since 3.6.0
|
|
288
|
+
* @category guards
|
|
289
|
+
*/
|
|
290
|
+
export const isTimeZoneNamed: (u: unknown) => u is TimeZone.Named = Internal.isTimeZoneNamed
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @since 3.6.0
|
|
294
|
+
* @category guards
|
|
295
|
+
*/
|
|
296
|
+
export const isUtc: (self: DateTime) => self is Utc = Internal.isUtc
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* @since 3.6.0
|
|
300
|
+
* @category guards
|
|
301
|
+
*/
|
|
302
|
+
export const isZoned: (self: DateTime) => self is Zoned = Internal.isZoned
|
|
303
|
+
|
|
304
|
+
// =============================================================================
|
|
305
|
+
// instances
|
|
306
|
+
// =============================================================================
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* @since 3.6.0
|
|
310
|
+
* @category instances
|
|
311
|
+
*/
|
|
312
|
+
export const Equivalence: equivalence.Equivalence<DateTime> = Internal.Equivalence
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* @since 3.6.0
|
|
316
|
+
* @category instances
|
|
317
|
+
*/
|
|
318
|
+
export const Order: order.Order<DateTime> = Internal.Order
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* @since 3.6.0
|
|
322
|
+
*/
|
|
323
|
+
export const clamp: {
|
|
324
|
+
<Min extends DateTime, Max extends DateTime>(
|
|
325
|
+
options: { readonly minimum: Min; readonly maximum: Max }
|
|
326
|
+
): <A extends DateTime>(self: A) => A | Min | Max
|
|
327
|
+
<A extends DateTime, Min extends DateTime, Max extends DateTime>(
|
|
328
|
+
self: A,
|
|
329
|
+
options: { readonly minimum: Min; readonly maximum: Max }
|
|
330
|
+
): A | Min | Max
|
|
331
|
+
} = Internal.clamp
|
|
332
|
+
|
|
333
|
+
// =============================================================================
|
|
334
|
+
// constructors
|
|
335
|
+
// =============================================================================
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Create a `DateTime` from a `Date`.
|
|
339
|
+
*
|
|
340
|
+
* If the `Date` is invalid, an `IllegalArgumentException` will be thrown.
|
|
341
|
+
*
|
|
342
|
+
* @since 3.6.0
|
|
343
|
+
* @category constructors
|
|
344
|
+
*/
|
|
345
|
+
export const unsafeFromDate: (date: Date) => Utc = Internal.unsafeFromDate
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Create a `DateTime` from one of the following:
|
|
349
|
+
*
|
|
350
|
+
* - A `DateTime`
|
|
351
|
+
* - A `Date` instance (invalid dates will throw an `IllegalArgumentException`)
|
|
352
|
+
* - The `number` of milliseconds since the Unix epoch
|
|
353
|
+
* - An object with the parts of a date
|
|
354
|
+
* - A `string` that can be parsed by `Date.parse`
|
|
355
|
+
*
|
|
356
|
+
* @since 3.6.0
|
|
357
|
+
* @category constructors
|
|
358
|
+
* @example
|
|
359
|
+
* ```ts
|
|
360
|
+
* import { DateTime } from "effect"
|
|
361
|
+
*
|
|
362
|
+
* // from Date
|
|
363
|
+
* DateTime.unsafeMake(new Date())
|
|
364
|
+
*
|
|
365
|
+
* // from parts
|
|
366
|
+
* DateTime.unsafeMake({ year: 2024 })
|
|
367
|
+
*
|
|
368
|
+
* // from string
|
|
369
|
+
* DateTime.unsafeMake("2024-01-01")
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
export const unsafeMake: <A extends DateTime.Input>(input: A) => DateTime.PreserveZone<A> = Internal.unsafeMake
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Create a `DateTime.Zoned` using `DateTime.unsafeMake` and a time zone.
|
|
376
|
+
*
|
|
377
|
+
* The input is treated as UTC and then the time zone is attached, unless
|
|
378
|
+
* `adjustForTimeZone` is set to `true`. In that case, the input is treated as
|
|
379
|
+
* already in the time zone.
|
|
380
|
+
*
|
|
381
|
+
* When `adjustForTimeZone` is true and ambiguous times occur during DST transitions,
|
|
382
|
+
* the `disambiguation` option controls how to resolve the ambiguity:
|
|
383
|
+
* - `compatible` (default): Choose earlier time for repeated times, later for gaps
|
|
384
|
+
* - `earlier`: Always choose the earlier of two possible times
|
|
385
|
+
* - `later`: Always choose the later of two possible times
|
|
386
|
+
* - `reject`: Throw an error when ambiguous times are encountered
|
|
387
|
+
*
|
|
388
|
+
* @since 3.6.0
|
|
389
|
+
* @category constructors
|
|
390
|
+
* @example
|
|
391
|
+
* ```ts
|
|
392
|
+
* import { DateTime } from "effect"
|
|
393
|
+
*
|
|
394
|
+
* DateTime.unsafeMakeZoned(new Date(), { timeZone: "Europe/London" })
|
|
395
|
+
* ```
|
|
396
|
+
*/
|
|
397
|
+
export const unsafeMakeZoned: (input: DateTime.Input, options?: {
|
|
398
|
+
readonly timeZone?: number | string | TimeZone | undefined
|
|
399
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
400
|
+
readonly disambiguation?: Disambiguation | undefined
|
|
401
|
+
}) => Zoned = Internal.unsafeMakeZoned
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Create a `DateTime.Zoned` using `DateTime.make` and a time zone.
|
|
405
|
+
*
|
|
406
|
+
* The input is treated as UTC and then the time zone is attached, unless
|
|
407
|
+
* `adjustForTimeZone` is set to `true`. In that case, the input is treated as
|
|
408
|
+
* already in the time zone.
|
|
409
|
+
*
|
|
410
|
+
* When `adjustForTimeZone` is true and ambiguous times occur during DST transitions,
|
|
411
|
+
* the `disambiguation` option controls how to resolve the ambiguity:
|
|
412
|
+
* - `compatible` (default): Choose earlier time for repeated times, later for gaps
|
|
413
|
+
* - `earlier`: Always choose the earlier of two possible times
|
|
414
|
+
* - `later`: Always choose the later of two possible times
|
|
415
|
+
* - `reject`: Throw an error when ambiguous times are encountered
|
|
416
|
+
*
|
|
417
|
+
* If the date time input or time zone is invalid, `None` will be returned.
|
|
418
|
+
*
|
|
419
|
+
* @since 3.6.0
|
|
420
|
+
* @category constructors
|
|
421
|
+
* @example
|
|
422
|
+
* ```ts
|
|
423
|
+
* import { DateTime } from "effect"
|
|
424
|
+
*
|
|
425
|
+
* DateTime.makeZoned(new Date(), { timeZone: "Europe/London" })
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
428
|
+
export const makeZoned: (
|
|
429
|
+
input: DateTime.Input,
|
|
430
|
+
options?: {
|
|
431
|
+
readonly timeZone?: number | string | TimeZone | undefined
|
|
432
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
433
|
+
readonly disambiguation?: Disambiguation | undefined
|
|
434
|
+
}
|
|
435
|
+
) => Option.Option<Zoned> = Internal.makeZoned
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Create a `DateTime` from one of the following:
|
|
439
|
+
*
|
|
440
|
+
* - A `DateTime`
|
|
441
|
+
* - A `Date` instance (invalid dates will throw an `IllegalArgumentException`)
|
|
442
|
+
* - The `number` of milliseconds since the Unix epoch
|
|
443
|
+
* - An object with the parts of a date
|
|
444
|
+
* - A `string` that can be parsed by `Date.parse`
|
|
445
|
+
*
|
|
446
|
+
* If the input is invalid, `None` will be returned.
|
|
447
|
+
*
|
|
448
|
+
* @since 3.6.0
|
|
449
|
+
* @category constructors
|
|
450
|
+
* @example
|
|
451
|
+
* ```ts
|
|
452
|
+
* import { DateTime } from "effect"
|
|
453
|
+
*
|
|
454
|
+
* // from Date
|
|
455
|
+
* DateTime.make(new Date())
|
|
456
|
+
*
|
|
457
|
+
* // from parts
|
|
458
|
+
* DateTime.make({ year: 2024 })
|
|
459
|
+
*
|
|
460
|
+
* // from string
|
|
461
|
+
* DateTime.make("2024-01-01")
|
|
462
|
+
* ```
|
|
463
|
+
*/
|
|
464
|
+
export const make: <A extends DateTime.Input>(input: A) => Option.Option<DateTime.PreserveZone<A>> = Internal.make
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Create a `DateTime.Zoned` from a string.
|
|
468
|
+
*
|
|
469
|
+
* It uses the format: `YYYY-MM-DDTHH:mm:ss.sss+HH:MM[Time/Zone]`.
|
|
470
|
+
*
|
|
471
|
+
* @since 3.6.0
|
|
472
|
+
* @category constructors
|
|
473
|
+
*/
|
|
474
|
+
export const makeZonedFromString: (input: string) => Option.Option<Zoned> = Internal.makeZonedFromString
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Get the current time using the `Clock` service and convert it to a `DateTime`.
|
|
478
|
+
*
|
|
479
|
+
* @since 3.6.0
|
|
480
|
+
* @category constructors
|
|
481
|
+
* @example
|
|
482
|
+
* ```ts
|
|
483
|
+
* import { DateTime, Effect } from "effect"
|
|
484
|
+
*
|
|
485
|
+
* Effect.gen(function* () {
|
|
486
|
+
* const now = yield* DateTime.now
|
|
487
|
+
* })
|
|
488
|
+
* ```
|
|
489
|
+
*/
|
|
490
|
+
export const now: Effect.Effect<Utc> = Internal.now
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Get the current time using the `Clock` service.
|
|
494
|
+
*
|
|
495
|
+
* @since 3.14.0
|
|
496
|
+
* @category constructors
|
|
497
|
+
* @example
|
|
498
|
+
* ```ts
|
|
499
|
+
* import { DateTime, Effect } from "effect"
|
|
500
|
+
*
|
|
501
|
+
* Effect.gen(function* () {
|
|
502
|
+
* const now = yield* DateTime.nowAsDate
|
|
503
|
+
* })
|
|
504
|
+
* ```
|
|
505
|
+
*/
|
|
506
|
+
export const nowAsDate: Effect.Effect<Date> = Internal.nowAsDate
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Get the current time using `Date.now`.
|
|
510
|
+
*
|
|
511
|
+
* @since 3.6.0
|
|
512
|
+
* @category constructors
|
|
513
|
+
*/
|
|
514
|
+
export const unsafeNow: LazyArg<Utc> = Internal.unsafeNow
|
|
515
|
+
|
|
516
|
+
// =============================================================================
|
|
517
|
+
// time zones
|
|
518
|
+
// =============================================================================
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* For a `DateTime` returns a new `DateTime.Utc`.
|
|
522
|
+
*
|
|
523
|
+
* @since 3.13.0
|
|
524
|
+
* @category time zones
|
|
525
|
+
* @example
|
|
526
|
+
* ```ts
|
|
527
|
+
* import { DateTime } from "effect"
|
|
528
|
+
*
|
|
529
|
+
* const now = DateTime.unsafeMakeZoned({ year: 2024 }, { timeZone: "Europe/London" })
|
|
530
|
+
*
|
|
531
|
+
* // set as UTC
|
|
532
|
+
* const utc: DateTime.Utc = DateTime.toUtc(now)
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
export const toUtc: (self: DateTime) => Utc = Internal.toUtc
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Set the time zone of a `DateTime`, returning a new `DateTime.Zoned`.
|
|
539
|
+
*
|
|
540
|
+
* @since 3.6.0
|
|
541
|
+
* @category time zones
|
|
542
|
+
* @example
|
|
543
|
+
* ```ts
|
|
544
|
+
* import { DateTime, Effect } from "effect"
|
|
545
|
+
*
|
|
546
|
+
* Effect.gen(function* () {
|
|
547
|
+
* const now = yield* DateTime.now
|
|
548
|
+
* const zone = DateTime.zoneUnsafeMakeNamed("Europe/London")
|
|
549
|
+
*
|
|
550
|
+
* // set the time zone
|
|
551
|
+
* const zoned: DateTime.Zoned = DateTime.setZone(now, zone)
|
|
552
|
+
* })
|
|
553
|
+
* ```
|
|
554
|
+
*/
|
|
555
|
+
export const setZone: {
|
|
556
|
+
(zone: TimeZone, options?: {
|
|
557
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
558
|
+
readonly disambiguation?: Disambiguation | undefined
|
|
559
|
+
}): (self: DateTime) => Zoned
|
|
560
|
+
(self: DateTime, zone: TimeZone, options?: {
|
|
561
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
562
|
+
readonly disambiguation?: Disambiguation | undefined
|
|
563
|
+
}): Zoned
|
|
564
|
+
} = Internal.setZone
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Add a fixed offset time zone to a `DateTime`.
|
|
568
|
+
*
|
|
569
|
+
* The offset is in milliseconds.
|
|
570
|
+
*
|
|
571
|
+
* @since 3.6.0
|
|
572
|
+
* @category time zones
|
|
573
|
+
* @example
|
|
574
|
+
* ```ts
|
|
575
|
+
* import { DateTime, Effect } from "effect"
|
|
576
|
+
*
|
|
577
|
+
* Effect.gen(function* () {
|
|
578
|
+
* const now = yield* DateTime.now
|
|
579
|
+
*
|
|
580
|
+
* // set the offset time zone in milliseconds
|
|
581
|
+
* const zoned: DateTime.Zoned = DateTime.setZoneOffset(now, 3 * 60 * 60 * 1000)
|
|
582
|
+
* })
|
|
583
|
+
* ```
|
|
584
|
+
*/
|
|
585
|
+
export const setZoneOffset: {
|
|
586
|
+
(offset: number, options?: {
|
|
587
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
588
|
+
readonly disambiguation?: Disambiguation | undefined
|
|
589
|
+
}): (self: DateTime) => Zoned
|
|
590
|
+
(self: DateTime, offset: number, options?: {
|
|
591
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
592
|
+
readonly disambiguation?: Disambiguation | undefined
|
|
593
|
+
}): Zoned
|
|
594
|
+
} = Internal.setZoneOffset
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Attempt to create a named time zone from a IANA time zone identifier.
|
|
598
|
+
*
|
|
599
|
+
* If the time zone is invalid, an `IllegalArgumentException` will be thrown.
|
|
600
|
+
*
|
|
601
|
+
* @since 3.6.0
|
|
602
|
+
* @category time zones
|
|
603
|
+
*/
|
|
604
|
+
export const zoneUnsafeMakeNamed: (zoneId: string) => TimeZone.Named = Internal.zoneUnsafeMakeNamed
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Create a fixed offset time zone.
|
|
608
|
+
*
|
|
609
|
+
* @since 3.6.0
|
|
610
|
+
* @category time zones
|
|
611
|
+
*/
|
|
612
|
+
export const zoneMakeOffset: (offset: number) => TimeZone.Offset = Internal.zoneMakeOffset
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Create a named time zone from a IANA time zone identifier. If the time zone
|
|
616
|
+
* is invalid, `None` will be returned.
|
|
617
|
+
*
|
|
618
|
+
* @since 3.6.0
|
|
619
|
+
* @category time zones
|
|
620
|
+
*/
|
|
621
|
+
export const zoneMakeNamed: (zoneId: string) => Option.Option<TimeZone.Named> = Internal.zoneMakeNamed
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Create a named time zone from a IANA time zone identifier. If the time zone
|
|
625
|
+
* is invalid, it will fail with an `IllegalArgumentException`.
|
|
626
|
+
*
|
|
627
|
+
* @since 3.6.0
|
|
628
|
+
* @category time zones
|
|
629
|
+
*/
|
|
630
|
+
export const zoneMakeNamedEffect: (zoneId: string) => Effect.Effect<TimeZone.Named, IllegalArgumentException> =
|
|
631
|
+
Internal.zoneMakeNamedEffect
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Create a named time zone from the system's local time zone.
|
|
635
|
+
*
|
|
636
|
+
* @since 3.6.0
|
|
637
|
+
* @category time zones
|
|
638
|
+
*/
|
|
639
|
+
export const zoneMakeLocal: () => TimeZone.Named = Internal.zoneMakeLocal
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Try parse a TimeZone from a string
|
|
643
|
+
*
|
|
644
|
+
* @since 3.6.0
|
|
645
|
+
* @category time zones
|
|
646
|
+
*/
|
|
647
|
+
export const zoneFromString: (zone: string) => Option.Option<TimeZone> = Internal.zoneFromString
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Format a `TimeZone` as a string.
|
|
651
|
+
*
|
|
652
|
+
* @since 3.6.0
|
|
653
|
+
* @category time zones
|
|
654
|
+
* @example
|
|
655
|
+
* ```ts
|
|
656
|
+
* import { DateTime, Effect } from "effect"
|
|
657
|
+
*
|
|
658
|
+
* // Outputs "+03:00"
|
|
659
|
+
* DateTime.zoneToString(DateTime.zoneMakeOffset(3 * 60 * 60 * 1000))
|
|
660
|
+
*
|
|
661
|
+
* // Outputs "Europe/London"
|
|
662
|
+
* DateTime.zoneToString(DateTime.zoneUnsafeMakeNamed("Europe/London"))
|
|
663
|
+
* ```
|
|
664
|
+
*/
|
|
665
|
+
export const zoneToString: (self: TimeZone) => string = Internal.zoneToString
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Set the time zone of a `DateTime` from an IANA time zone identifier. If the
|
|
669
|
+
* time zone is invalid, `None` will be returned.
|
|
670
|
+
*
|
|
671
|
+
* @since 3.6.0
|
|
672
|
+
* @category time zones
|
|
673
|
+
* @example
|
|
674
|
+
* ```ts
|
|
675
|
+
* import { DateTime, Effect } from "effect"
|
|
676
|
+
*
|
|
677
|
+
* Effect.gen(function* () {
|
|
678
|
+
* const now = yield* DateTime.now
|
|
679
|
+
* // set the time zone, returns an Option
|
|
680
|
+
* DateTime.setZoneNamed(now, "Europe/London")
|
|
681
|
+
* })
|
|
682
|
+
* ```
|
|
683
|
+
*/
|
|
684
|
+
export const setZoneNamed: {
|
|
685
|
+
(zoneId: string, options?: {
|
|
686
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
687
|
+
readonly disambiguation?: Disambiguation | undefined
|
|
688
|
+
}): (self: DateTime) => Option.Option<Zoned>
|
|
689
|
+
(self: DateTime, zoneId: string, options?: {
|
|
690
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
691
|
+
readonly disambiguation?: Disambiguation | undefined
|
|
692
|
+
}): Option.Option<Zoned>
|
|
693
|
+
} = Internal.setZoneNamed
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Set the time zone of a `DateTime` from an IANA time zone identifier. If the
|
|
697
|
+
* time zone is invalid, an `IllegalArgumentException` will be thrown.
|
|
698
|
+
*
|
|
699
|
+
* @since 3.6.0
|
|
700
|
+
* @category time zones
|
|
701
|
+
* @example
|
|
702
|
+
* ```ts
|
|
703
|
+
* import { DateTime, Effect } from "effect"
|
|
704
|
+
*
|
|
705
|
+
* Effect.gen(function* () {
|
|
706
|
+
* const now = yield* DateTime.now
|
|
707
|
+
* // set the time zone
|
|
708
|
+
* DateTime.unsafeSetZoneNamed(now, "Europe/London")
|
|
709
|
+
* })
|
|
710
|
+
* ```
|
|
711
|
+
*/
|
|
712
|
+
export const unsafeSetZoneNamed: {
|
|
713
|
+
(zoneId: string, options?: {
|
|
714
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
715
|
+
readonly disambiguation?: Disambiguation | undefined
|
|
716
|
+
}): (self: DateTime) => Zoned
|
|
717
|
+
(self: DateTime, zoneId: string, options?: {
|
|
718
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
719
|
+
readonly disambiguation?: Disambiguation | undefined
|
|
720
|
+
}): Zoned
|
|
721
|
+
} = Internal.unsafeSetZoneNamed
|
|
722
|
+
|
|
723
|
+
// =============================================================================
|
|
724
|
+
// comparisons
|
|
725
|
+
// =============================================================================
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Calulate the difference between two `DateTime` values, returning the number
|
|
729
|
+
* of milliseconds the `other` DateTime is from `self`.
|
|
730
|
+
*
|
|
731
|
+
* If `other` is *after* `self`, the result will be a positive number.
|
|
732
|
+
*
|
|
733
|
+
* @since 3.6.0
|
|
734
|
+
* @category comparisons
|
|
735
|
+
* @example
|
|
736
|
+
* ```ts
|
|
737
|
+
* import { DateTime, Effect } from "effect"
|
|
738
|
+
*
|
|
739
|
+
* Effect.gen(function* () {
|
|
740
|
+
* const now = yield* DateTime.now
|
|
741
|
+
* const other = DateTime.add(now, { minutes: 1 })
|
|
742
|
+
*
|
|
743
|
+
* // returns 60000
|
|
744
|
+
* DateTime.distance(now, other)
|
|
745
|
+
* })
|
|
746
|
+
* ```
|
|
747
|
+
*/
|
|
748
|
+
export const distance: {
|
|
749
|
+
(other: DateTime): (self: DateTime) => number
|
|
750
|
+
(self: DateTime, other: DateTime): number
|
|
751
|
+
} = Internal.distance
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Calulate the difference between two `DateTime` values.
|
|
755
|
+
*
|
|
756
|
+
* If the `other` DateTime is before `self`, the result will be a negative
|
|
757
|
+
* `Duration`, returned as a `Left`.
|
|
758
|
+
*
|
|
759
|
+
* If the `other` DateTime is after `self`, the result will be a positive
|
|
760
|
+
* `Duration`, returned as a `Right`.
|
|
761
|
+
*
|
|
762
|
+
* @since 3.6.0
|
|
763
|
+
* @category comparisons
|
|
764
|
+
* @example
|
|
765
|
+
* ```ts
|
|
766
|
+
* import { DateTime, Effect } from "effect"
|
|
767
|
+
*
|
|
768
|
+
* Effect.gen(function* () {
|
|
769
|
+
* const now = yield* DateTime.now
|
|
770
|
+
* const other = DateTime.add(now, { minutes: 1 })
|
|
771
|
+
*
|
|
772
|
+
* // returns Either.right(Duration.minutes(1))
|
|
773
|
+
* DateTime.distanceDurationEither(now, other)
|
|
774
|
+
*
|
|
775
|
+
* // returns Either.left(Duration.minutes(1))
|
|
776
|
+
* DateTime.distanceDurationEither(other, now)
|
|
777
|
+
* })
|
|
778
|
+
* ```
|
|
779
|
+
*/
|
|
780
|
+
export const distanceDurationEither: {
|
|
781
|
+
(other: DateTime): (self: DateTime) => Either.Either<Duration.Duration, Duration.Duration>
|
|
782
|
+
(self: DateTime, other: DateTime): Either.Either<Duration.Duration, Duration.Duration>
|
|
783
|
+
} = Internal.distanceDurationEither
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* Calulate the distance between two `DateTime` values.
|
|
787
|
+
*
|
|
788
|
+
* @since 3.6.0
|
|
789
|
+
* @category comparisons
|
|
790
|
+
* @example
|
|
791
|
+
* ```ts
|
|
792
|
+
* import { DateTime, Effect } from "effect"
|
|
793
|
+
*
|
|
794
|
+
* Effect.gen(function* () {
|
|
795
|
+
* const now = yield* DateTime.now
|
|
796
|
+
* const other = DateTime.add(now, { minutes: 1 })
|
|
797
|
+
*
|
|
798
|
+
* // returns Duration.minutes(1)
|
|
799
|
+
* DateTime.distanceDuration(now, other)
|
|
800
|
+
* })
|
|
801
|
+
* ```
|
|
802
|
+
*/
|
|
803
|
+
export const distanceDuration: {
|
|
804
|
+
(other: DateTime): (self: DateTime) => Duration.Duration
|
|
805
|
+
(self: DateTime, other: DateTime): Duration.Duration
|
|
806
|
+
} = Internal.distanceDuration
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* @since 3.6.0
|
|
810
|
+
* @category comparisons
|
|
811
|
+
*/
|
|
812
|
+
export const min: {
|
|
813
|
+
<That extends DateTime>(that: That): <Self extends DateTime>(self: Self) => Self | That
|
|
814
|
+
<Self extends DateTime, That extends DateTime>(self: Self, that: That): Self | That
|
|
815
|
+
} = Internal.min
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* @since 3.6.0
|
|
819
|
+
* @category comparisons
|
|
820
|
+
*/
|
|
821
|
+
export const max: {
|
|
822
|
+
<That extends DateTime>(that: That): <Self extends DateTime>(self: Self) => Self | That
|
|
823
|
+
<Self extends DateTime, That extends DateTime>(self: Self, that: That): Self | That
|
|
824
|
+
} = Internal.max
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* @since 3.6.0
|
|
828
|
+
* @category comparisons
|
|
829
|
+
*/
|
|
830
|
+
export const greaterThan: {
|
|
831
|
+
(that: DateTime): (self: DateTime) => boolean
|
|
832
|
+
(self: DateTime, that: DateTime): boolean
|
|
833
|
+
} = Internal.greaterThan
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* @since 3.6.0
|
|
837
|
+
* @category comparisons
|
|
838
|
+
*/
|
|
839
|
+
export const greaterThanOrEqualTo: {
|
|
840
|
+
(that: DateTime): (self: DateTime) => boolean
|
|
841
|
+
(self: DateTime, that: DateTime): boolean
|
|
842
|
+
} = Internal.greaterThanOrEqualTo
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* @since 3.6.0
|
|
846
|
+
* @category comparisons
|
|
847
|
+
*/
|
|
848
|
+
export const lessThan: {
|
|
849
|
+
(that: DateTime): (self: DateTime) => boolean
|
|
850
|
+
(self: DateTime, that: DateTime): boolean
|
|
851
|
+
} = Internal.lessThan
|
|
852
|
+
|
|
853
|
+
/**
|
|
854
|
+
* @since 3.6.0
|
|
855
|
+
* @category comparisons
|
|
856
|
+
*/
|
|
857
|
+
export const lessThanOrEqualTo: {
|
|
858
|
+
(that: DateTime): (self: DateTime) => boolean
|
|
859
|
+
(self: DateTime, that: DateTime): boolean
|
|
860
|
+
} = Internal.lessThanOrEqualTo
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* @since 3.6.0
|
|
864
|
+
* @category comparisons
|
|
865
|
+
*/
|
|
866
|
+
export const between: {
|
|
867
|
+
(options: { minimum: DateTime; maximum: DateTime }): (self: DateTime) => boolean
|
|
868
|
+
(self: DateTime, options: { minimum: DateTime; maximum: DateTime }): boolean
|
|
869
|
+
} = Internal.between
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* @since 3.6.0
|
|
873
|
+
* @category comparisons
|
|
874
|
+
*/
|
|
875
|
+
export const isFuture: (self: DateTime) => Effect.Effect<boolean> = Internal.isFuture
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* @since 3.6.0
|
|
879
|
+
* @category comparisons
|
|
880
|
+
*/
|
|
881
|
+
export const unsafeIsFuture: (self: DateTime) => boolean = Internal.unsafeIsFuture
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* @since 3.6.0
|
|
885
|
+
* @category comparisons
|
|
886
|
+
*/
|
|
887
|
+
export const isPast: (self: DateTime) => Effect.Effect<boolean> = Internal.isPast
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* @since 3.6.0
|
|
891
|
+
* @category comparisons
|
|
892
|
+
*/
|
|
893
|
+
export const unsafeIsPast: (self: DateTime) => boolean = Internal.unsafeIsPast
|
|
894
|
+
|
|
895
|
+
// =============================================================================
|
|
896
|
+
// conversions
|
|
897
|
+
// =============================================================================
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* Get the UTC `Date` of a `DateTime`.
|
|
901
|
+
*
|
|
902
|
+
* @since 3.6.0
|
|
903
|
+
* @category conversions
|
|
904
|
+
*/
|
|
905
|
+
export const toDateUtc: (self: DateTime) => Date = Internal.toDateUtc
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* Convert a `DateTime` to a `Date`, applying the time zone first.
|
|
909
|
+
*
|
|
910
|
+
* @since 3.6.0
|
|
911
|
+
* @category conversions
|
|
912
|
+
*/
|
|
913
|
+
export const toDate: (self: DateTime) => Date = Internal.toDate
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* Calculate the time zone offset of a `DateTime.Zoned` in milliseconds.
|
|
917
|
+
*
|
|
918
|
+
* @since 3.6.0
|
|
919
|
+
* @category conversions
|
|
920
|
+
*/
|
|
921
|
+
export const zonedOffset: (self: Zoned) => number = Internal.zonedOffset
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* Calculate the time zone offset of a `DateTime` in milliseconds.
|
|
925
|
+
*
|
|
926
|
+
* The offset is formatted as "±HH:MM".
|
|
927
|
+
*
|
|
928
|
+
* @since 3.6.0
|
|
929
|
+
* @category conversions
|
|
930
|
+
*/
|
|
931
|
+
export const zonedOffsetIso: (self: Zoned) => string = Internal.zonedOffsetIso
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Get the milliseconds since the Unix epoch of a `DateTime`.
|
|
935
|
+
*
|
|
936
|
+
* @since 3.6.0
|
|
937
|
+
* @category conversions
|
|
938
|
+
*/
|
|
939
|
+
export const toEpochMillis: (self: DateTime) => number = Internal.toEpochMillis
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* Remove the time aspect of a `DateTime`, first adjusting for the time
|
|
943
|
+
* zone. It will return a `DateTime.Utc` only containing the date.
|
|
944
|
+
*
|
|
945
|
+
* @since 3.6.0
|
|
946
|
+
* @category conversions
|
|
947
|
+
* @example
|
|
948
|
+
* ```ts
|
|
949
|
+
* import { DateTime } from "effect"
|
|
950
|
+
*
|
|
951
|
+
* // returns "2024-01-01T00:00:00Z"
|
|
952
|
+
* DateTime.unsafeMakeZoned("2024-01-01T05:00:00Z", {
|
|
953
|
+
* timeZone: "Pacific/Auckland",
|
|
954
|
+
* adjustForTimeZone: true
|
|
955
|
+
* }).pipe(
|
|
956
|
+
* DateTime.removeTime,
|
|
957
|
+
* DateTime.formatIso
|
|
958
|
+
* )
|
|
959
|
+
* ```
|
|
960
|
+
*/
|
|
961
|
+
export const removeTime: (self: DateTime) => Utc = Internal.removeTime
|
|
962
|
+
|
|
963
|
+
// =============================================================================
|
|
964
|
+
// parts
|
|
965
|
+
// =============================================================================
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* Get the different parts of a `DateTime` as an object.
|
|
969
|
+
*
|
|
970
|
+
* The parts will be time zone adjusted.
|
|
971
|
+
*
|
|
972
|
+
* @since 3.6.0
|
|
973
|
+
* @category parts
|
|
974
|
+
*/
|
|
975
|
+
export const toParts: (self: DateTime) => DateTime.PartsWithWeekday = Internal.toParts
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* Get the different parts of a `DateTime` as an object.
|
|
979
|
+
*
|
|
980
|
+
* The parts will be in UTC.
|
|
981
|
+
*
|
|
982
|
+
* @since 3.6.0
|
|
983
|
+
* @category parts
|
|
984
|
+
*/
|
|
985
|
+
export const toPartsUtc: (self: DateTime) => DateTime.PartsWithWeekday = Internal.toPartsUtc
|
|
986
|
+
|
|
987
|
+
/**
|
|
988
|
+
* Get a part of a `DateTime` as a number.
|
|
989
|
+
*
|
|
990
|
+
* The part will be in the UTC time zone.
|
|
991
|
+
*
|
|
992
|
+
* @since 3.6.0
|
|
993
|
+
* @category parts
|
|
994
|
+
* @example
|
|
995
|
+
* ```ts
|
|
996
|
+
* import * as assert from "node:assert"
|
|
997
|
+
* import { DateTime } from "effect"
|
|
998
|
+
*
|
|
999
|
+
* const now = DateTime.unsafeMake({ year: 2024 })
|
|
1000
|
+
* const year = DateTime.getPartUtc(now, "year")
|
|
1001
|
+
* assert.strictEqual(year, 2024)
|
|
1002
|
+
* ```
|
|
1003
|
+
*/
|
|
1004
|
+
export const getPartUtc: {
|
|
1005
|
+
(part: keyof DateTime.PartsWithWeekday): (self: DateTime) => number
|
|
1006
|
+
(self: DateTime, part: keyof DateTime.PartsWithWeekday): number
|
|
1007
|
+
} = Internal.getPartUtc
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* Get a part of a `DateTime` as a number.
|
|
1011
|
+
*
|
|
1012
|
+
* The part will be time zone adjusted.
|
|
1013
|
+
*
|
|
1014
|
+
* @since 3.6.0
|
|
1015
|
+
* @category parts
|
|
1016
|
+
* @example
|
|
1017
|
+
* ```ts
|
|
1018
|
+
* import * as assert from "node:assert"
|
|
1019
|
+
* import { DateTime } from "effect"
|
|
1020
|
+
*
|
|
1021
|
+
* const now = DateTime.unsafeMakeZoned({ year: 2024 }, { timeZone: "Europe/London" })
|
|
1022
|
+
* const year = DateTime.getPart(now, "year")
|
|
1023
|
+
* assert.strictEqual(year, 2024)
|
|
1024
|
+
* ```
|
|
1025
|
+
*/
|
|
1026
|
+
export const getPart: {
|
|
1027
|
+
(part: keyof DateTime.PartsWithWeekday): (self: DateTime) => number
|
|
1028
|
+
(self: DateTime, part: keyof DateTime.PartsWithWeekday): number
|
|
1029
|
+
} = Internal.getPart
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* Set the different parts of a `DateTime` as an object.
|
|
1033
|
+
*
|
|
1034
|
+
* The Date will be time zone adjusted.
|
|
1035
|
+
*
|
|
1036
|
+
* @since 3.6.0
|
|
1037
|
+
* @category parts
|
|
1038
|
+
*/
|
|
1039
|
+
export const setParts: {
|
|
1040
|
+
(parts: Partial<DateTime.PartsWithWeekday>): <A extends DateTime>(self: A) => A
|
|
1041
|
+
<A extends DateTime>(self: A, parts: Partial<DateTime.PartsWithWeekday>): A
|
|
1042
|
+
} = Internal.setParts
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* Set the different parts of a `DateTime` as an object.
|
|
1046
|
+
*
|
|
1047
|
+
* @since 3.6.0
|
|
1048
|
+
* @category parts
|
|
1049
|
+
*/
|
|
1050
|
+
export const setPartsUtc: {
|
|
1051
|
+
(parts: Partial<DateTime.PartsWithWeekday>): <A extends DateTime>(self: A) => A
|
|
1052
|
+
<A extends DateTime>(self: A, parts: Partial<DateTime.PartsWithWeekday>): A
|
|
1053
|
+
} = Internal.setPartsUtc
|
|
1054
|
+
|
|
1055
|
+
// =============================================================================
|
|
1056
|
+
// current time zone
|
|
1057
|
+
// =============================================================================
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* @since 3.11.0
|
|
1061
|
+
* @category current time zone
|
|
1062
|
+
*/
|
|
1063
|
+
export class CurrentTimeZone extends Context.Tag("effect/DateTime/CurrentTimeZone")<CurrentTimeZone, TimeZone>() {}
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* Set the time zone of a `DateTime` to the current time zone, which is
|
|
1067
|
+
* determined by the `CurrentTimeZone` service.
|
|
1068
|
+
*
|
|
1069
|
+
* @since 3.6.0
|
|
1070
|
+
* @category current time zone
|
|
1071
|
+
* @example
|
|
1072
|
+
* ```ts
|
|
1073
|
+
* import { DateTime, Effect } from "effect"
|
|
1074
|
+
*
|
|
1075
|
+
* Effect.gen(function* () {
|
|
1076
|
+
* const now = yield* DateTime.now
|
|
1077
|
+
*
|
|
1078
|
+
* // set the time zone to "Europe/London"
|
|
1079
|
+
* const zoned = yield* DateTime.setZoneCurrent(now)
|
|
1080
|
+
* }).pipe(DateTime.withCurrentZoneNamed("Europe/London"))
|
|
1081
|
+
* ```
|
|
1082
|
+
*/
|
|
1083
|
+
export const setZoneCurrent = (self: DateTime): Effect.Effect<Zoned, never, CurrentTimeZone> =>
|
|
1084
|
+
Effect.map(CurrentTimeZone, (zone) => setZone(self, zone))
|
|
1085
|
+
|
|
1086
|
+
/**
|
|
1087
|
+
* Provide the `CurrentTimeZone` to an effect.
|
|
1088
|
+
*
|
|
1089
|
+
* @since 3.6.0
|
|
1090
|
+
* @category current time zone
|
|
1091
|
+
* @example
|
|
1092
|
+
* ```ts
|
|
1093
|
+
* import { DateTime, Effect } from "effect"
|
|
1094
|
+
*
|
|
1095
|
+
* const zone = DateTime.zoneUnsafeMakeNamed("Europe/London")
|
|
1096
|
+
*
|
|
1097
|
+
* Effect.gen(function* () {
|
|
1098
|
+
* const now = yield* DateTime.nowInCurrentZone
|
|
1099
|
+
* }).pipe(DateTime.withCurrentZone(zone))
|
|
1100
|
+
* ```
|
|
1101
|
+
*/
|
|
1102
|
+
export const withCurrentZone: {
|
|
1103
|
+
(
|
|
1104
|
+
zone: TimeZone
|
|
1105
|
+
): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, CurrentTimeZone>>
|
|
1106
|
+
<A, E, R>(effect: Effect.Effect<A, E, R>, zone: TimeZone): Effect.Effect<A, E, Exclude<R, CurrentTimeZone>>
|
|
1107
|
+
} = dual(
|
|
1108
|
+
2,
|
|
1109
|
+
<A, E, R>(
|
|
1110
|
+
effect: Effect.Effect<A, E, R>,
|
|
1111
|
+
zone: TimeZone
|
|
1112
|
+
): Effect.Effect<A, E, Exclude<R, CurrentTimeZone>> => Effect.provideService(effect, CurrentTimeZone, zone)
|
|
1113
|
+
)
|
|
1114
|
+
|
|
1115
|
+
/**
|
|
1116
|
+
* Provide the `CurrentTimeZone` to an effect, using the system's local time
|
|
1117
|
+
* zone.
|
|
1118
|
+
*
|
|
1119
|
+
* @since 3.6.0
|
|
1120
|
+
* @category current time zone
|
|
1121
|
+
* @example
|
|
1122
|
+
* ```ts
|
|
1123
|
+
* import { DateTime, Effect } from "effect"
|
|
1124
|
+
*
|
|
1125
|
+
* Effect.gen(function* () {
|
|
1126
|
+
* // will use the system's local time zone
|
|
1127
|
+
* const now = yield* DateTime.nowInCurrentZone
|
|
1128
|
+
* }).pipe(DateTime.withCurrentZoneLocal)
|
|
1129
|
+
* ```
|
|
1130
|
+
*/
|
|
1131
|
+
export const withCurrentZoneLocal = <A, E, R>(
|
|
1132
|
+
effect: Effect.Effect<A, E, R>
|
|
1133
|
+
): Effect.Effect<A, E, Exclude<R, CurrentTimeZone>> =>
|
|
1134
|
+
Effect.provideServiceEffect(effect, CurrentTimeZone, Effect.sync(zoneMakeLocal))
|
|
1135
|
+
|
|
1136
|
+
/**
|
|
1137
|
+
* Provide the `CurrentTimeZone` to an effect, using a offset.
|
|
1138
|
+
*
|
|
1139
|
+
* @since 3.6.0
|
|
1140
|
+
* @category current time zone
|
|
1141
|
+
* @example
|
|
1142
|
+
* ```ts
|
|
1143
|
+
* import { DateTime, Effect } from "effect"
|
|
1144
|
+
*
|
|
1145
|
+
* Effect.gen(function* () {
|
|
1146
|
+
* // will use the system's local time zone
|
|
1147
|
+
* const now = yield* DateTime.nowInCurrentZone
|
|
1148
|
+
* }).pipe(DateTime.withCurrentZoneOffset(3 * 60 * 60 * 1000))
|
|
1149
|
+
* ```
|
|
1150
|
+
*/
|
|
1151
|
+
export const withCurrentZoneOffset: {
|
|
1152
|
+
(offset: number): <A, E, R>(
|
|
1153
|
+
effect: Effect.Effect<A, E, R>
|
|
1154
|
+
) => Effect.Effect<A, E, Exclude<R, CurrentTimeZone>>
|
|
1155
|
+
<A, E, R>(effect: Effect.Effect<A, E, R>, offset: number): Effect.Effect<A, E, Exclude<R, CurrentTimeZone>>
|
|
1156
|
+
} = dual(
|
|
1157
|
+
2,
|
|
1158
|
+
<A, E, R>(effect: Effect.Effect<A, E, R>, offset: number): Effect.Effect<A, E, Exclude<R, CurrentTimeZone>> =>
|
|
1159
|
+
Effect.provideService(effect, CurrentTimeZone, zoneMakeOffset(offset))
|
|
1160
|
+
)
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* Provide the `CurrentTimeZone` to an effect using an IANA time zone
|
|
1164
|
+
* identifier.
|
|
1165
|
+
*
|
|
1166
|
+
* If the time zone is invalid, it will fail with an `IllegalArgumentException`.
|
|
1167
|
+
*
|
|
1168
|
+
* @since 3.6.0
|
|
1169
|
+
* @category current time zone
|
|
1170
|
+
* @example
|
|
1171
|
+
* ```ts
|
|
1172
|
+
* import { DateTime, Effect } from "effect"
|
|
1173
|
+
*
|
|
1174
|
+
* Effect.gen(function* () {
|
|
1175
|
+
* // will use the "Europe/London" time zone
|
|
1176
|
+
* const now = yield* DateTime.nowInCurrentZone
|
|
1177
|
+
* }).pipe(DateTime.withCurrentZoneNamed("Europe/London"))
|
|
1178
|
+
* ```
|
|
1179
|
+
*/
|
|
1180
|
+
export const withCurrentZoneNamed: {
|
|
1181
|
+
(zone: string): <A, E, R>(
|
|
1182
|
+
effect: Effect.Effect<A, E, R>
|
|
1183
|
+
) => Effect.Effect<A, E | IllegalArgumentException, Exclude<R, CurrentTimeZone>>
|
|
1184
|
+
<A, E, R>(
|
|
1185
|
+
effect: Effect.Effect<A, E, R>,
|
|
1186
|
+
zone: string
|
|
1187
|
+
): Effect.Effect<A, E | IllegalArgumentException, Exclude<R, CurrentTimeZone>>
|
|
1188
|
+
} = dual(
|
|
1189
|
+
2,
|
|
1190
|
+
<A, E, R>(
|
|
1191
|
+
effect: Effect.Effect<A, E, R>,
|
|
1192
|
+
zone: string
|
|
1193
|
+
): Effect.Effect<A, E | IllegalArgumentException, Exclude<R, CurrentTimeZone>> =>
|
|
1194
|
+
Effect.provideServiceEffect(effect, CurrentTimeZone, zoneMakeNamedEffect(zone))
|
|
1195
|
+
)
|
|
1196
|
+
|
|
1197
|
+
/**
|
|
1198
|
+
* Get the current time as a `DateTime.Zoned`, using the `CurrentTimeZone`.
|
|
1199
|
+
*
|
|
1200
|
+
* @since 3.6.0
|
|
1201
|
+
* @category current time zone
|
|
1202
|
+
* @example
|
|
1203
|
+
* ```ts
|
|
1204
|
+
* import { DateTime, Effect } from "effect"
|
|
1205
|
+
*
|
|
1206
|
+
* Effect.gen(function* () {
|
|
1207
|
+
* // will use the "Europe/London" time zone
|
|
1208
|
+
* const now = yield* DateTime.nowInCurrentZone
|
|
1209
|
+
* }).pipe(DateTime.withCurrentZoneNamed("Europe/London"))
|
|
1210
|
+
* ```
|
|
1211
|
+
*/
|
|
1212
|
+
export const nowInCurrentZone: Effect.Effect<Zoned, never, CurrentTimeZone> = Effect.flatMap(now, setZoneCurrent)
|
|
1213
|
+
|
|
1214
|
+
// =============================================================================
|
|
1215
|
+
// mapping
|
|
1216
|
+
// =============================================================================
|
|
1217
|
+
|
|
1218
|
+
/**
|
|
1219
|
+
* Modify a `DateTime` by applying a function to a cloned `Date` instance.
|
|
1220
|
+
*
|
|
1221
|
+
* The `Date` will first have the time zone applied if possible, and then be
|
|
1222
|
+
* converted back to a `DateTime` within the same time zone.
|
|
1223
|
+
*
|
|
1224
|
+
* Supports `disambiguation` when the new wall clock time is ambiguous.
|
|
1225
|
+
*
|
|
1226
|
+
* @since 3.6.0
|
|
1227
|
+
* @category mapping
|
|
1228
|
+
*/
|
|
1229
|
+
export const mutate: {
|
|
1230
|
+
(
|
|
1231
|
+
f: (date: Date) => void,
|
|
1232
|
+
options?: {
|
|
1233
|
+
readonly disambiguation?: Disambiguation | undefined
|
|
1234
|
+
}
|
|
1235
|
+
): <A extends DateTime>(self: A) => A
|
|
1236
|
+
<A extends DateTime>(
|
|
1237
|
+
self: A,
|
|
1238
|
+
f: (date: Date) => void,
|
|
1239
|
+
options?: {
|
|
1240
|
+
readonly disambiguation?: Disambiguation | undefined
|
|
1241
|
+
}
|
|
1242
|
+
): A
|
|
1243
|
+
} = Internal.mutate
|
|
1244
|
+
|
|
1245
|
+
/**
|
|
1246
|
+
* Modify a `DateTime` by applying a function to a cloned UTC `Date` instance.
|
|
1247
|
+
*
|
|
1248
|
+
* @since 3.6.0
|
|
1249
|
+
* @category mapping
|
|
1250
|
+
*/
|
|
1251
|
+
export const mutateUtc: {
|
|
1252
|
+
(f: (date: Date) => void): <A extends DateTime>(self: A) => A
|
|
1253
|
+
<A extends DateTime>(self: A, f: (date: Date) => void): A
|
|
1254
|
+
} = Internal.mutateUtc
|
|
1255
|
+
|
|
1256
|
+
/**
|
|
1257
|
+
* Transform a `DateTime` by applying a function to the number of milliseconds
|
|
1258
|
+
* since the Unix epoch.
|
|
1259
|
+
*
|
|
1260
|
+
* @since 3.6.0
|
|
1261
|
+
* @category mapping
|
|
1262
|
+
* @example
|
|
1263
|
+
* ```ts
|
|
1264
|
+
* import { DateTime } from "effect"
|
|
1265
|
+
*
|
|
1266
|
+
* // add 10 milliseconds
|
|
1267
|
+
* DateTime.unsafeMake(0).pipe(
|
|
1268
|
+
* DateTime.mapEpochMillis((millis) => millis + 10)
|
|
1269
|
+
* )
|
|
1270
|
+
* ```
|
|
1271
|
+
*/
|
|
1272
|
+
export const mapEpochMillis: {
|
|
1273
|
+
(f: (millis: number) => number): <A extends DateTime>(self: A) => A
|
|
1274
|
+
<A extends DateTime>(self: A, f: (millis: number) => number): A
|
|
1275
|
+
} = Internal.mapEpochMillis
|
|
1276
|
+
|
|
1277
|
+
/**
|
|
1278
|
+
* Using the time zone adjusted `Date`, apply a function to the `Date` and
|
|
1279
|
+
* return the result.
|
|
1280
|
+
*
|
|
1281
|
+
* @since 3.6.0
|
|
1282
|
+
* @category mapping
|
|
1283
|
+
* @example
|
|
1284
|
+
* ```ts
|
|
1285
|
+
* import { DateTime } from "effect"
|
|
1286
|
+
*
|
|
1287
|
+
* // get the time zone adjusted date in milliseconds
|
|
1288
|
+
* DateTime.unsafeMakeZoned(0, { timeZone: "Europe/London" }).pipe(
|
|
1289
|
+
* DateTime.withDate((date) => date.getTime())
|
|
1290
|
+
* )
|
|
1291
|
+
* ```
|
|
1292
|
+
*/
|
|
1293
|
+
export const withDate: {
|
|
1294
|
+
<A>(f: (date: Date) => A): (self: DateTime) => A
|
|
1295
|
+
<A>(self: DateTime, f: (date: Date) => A): A
|
|
1296
|
+
} = Internal.withDate
|
|
1297
|
+
|
|
1298
|
+
/**
|
|
1299
|
+
* Using the time zone adjusted `Date`, apply a function to the `Date` and
|
|
1300
|
+
* return the result.
|
|
1301
|
+
*
|
|
1302
|
+
* @since 3.6.0
|
|
1303
|
+
* @category mapping
|
|
1304
|
+
* @example
|
|
1305
|
+
* ```ts
|
|
1306
|
+
* import { DateTime } from "effect"
|
|
1307
|
+
*
|
|
1308
|
+
* // get the date in milliseconds
|
|
1309
|
+
* DateTime.unsafeMake(0).pipe(
|
|
1310
|
+
* DateTime.withDateUtc((date) => date.getTime())
|
|
1311
|
+
* )
|
|
1312
|
+
* ```
|
|
1313
|
+
*/
|
|
1314
|
+
export const withDateUtc: {
|
|
1315
|
+
<A>(f: (date: Date) => A): (self: DateTime) => A
|
|
1316
|
+
<A>(self: DateTime, f: (date: Date) => A): A
|
|
1317
|
+
} = Internal.withDateUtc
|
|
1318
|
+
|
|
1319
|
+
/**
|
|
1320
|
+
* @since 3.6.0
|
|
1321
|
+
* @category mapping
|
|
1322
|
+
*/
|
|
1323
|
+
export const match: {
|
|
1324
|
+
<A, B>(options: {
|
|
1325
|
+
readonly onUtc: (_: Utc) => A
|
|
1326
|
+
readonly onZoned: (_: Zoned) => B
|
|
1327
|
+
}): (self: DateTime) => A | B
|
|
1328
|
+
<A, B>(self: DateTime, options: {
|
|
1329
|
+
readonly onUtc: (_: Utc) => A
|
|
1330
|
+
readonly onZoned: (_: Zoned) => B
|
|
1331
|
+
}): A | B
|
|
1332
|
+
} = Internal.match
|
|
1333
|
+
|
|
1334
|
+
// =============================================================================
|
|
1335
|
+
// math
|
|
1336
|
+
// =============================================================================
|
|
1337
|
+
|
|
1338
|
+
/**
|
|
1339
|
+
* Add the given `Duration` to a `DateTime`.
|
|
1340
|
+
*
|
|
1341
|
+
* @since 3.6.0
|
|
1342
|
+
* @category math
|
|
1343
|
+
* @example
|
|
1344
|
+
* ```ts
|
|
1345
|
+
* import { DateTime } from "effect"
|
|
1346
|
+
*
|
|
1347
|
+
* // add 5 minutes
|
|
1348
|
+
* DateTime.unsafeMake(0).pipe(
|
|
1349
|
+
* DateTime.addDuration("5 minutes")
|
|
1350
|
+
* )
|
|
1351
|
+
* ```
|
|
1352
|
+
*/
|
|
1353
|
+
export const addDuration: {
|
|
1354
|
+
(duration: Duration.DurationInput): <A extends DateTime>(self: A) => A
|
|
1355
|
+
<A extends DateTime>(self: A, duration: Duration.DurationInput): A
|
|
1356
|
+
} = Internal.addDuration
|
|
1357
|
+
|
|
1358
|
+
/**
|
|
1359
|
+
* Subtract the given `Duration` from a `DateTime`.
|
|
1360
|
+
*
|
|
1361
|
+
* @since 3.6.0
|
|
1362
|
+
* @category math
|
|
1363
|
+
* @example
|
|
1364
|
+
* ```ts
|
|
1365
|
+
* import { DateTime } from "effect"
|
|
1366
|
+
*
|
|
1367
|
+
* // subtract 5 minutes
|
|
1368
|
+
* DateTime.unsafeMake(0).pipe(
|
|
1369
|
+
* DateTime.subtractDuration("5 minutes")
|
|
1370
|
+
* )
|
|
1371
|
+
* ```
|
|
1372
|
+
*/
|
|
1373
|
+
export const subtractDuration: {
|
|
1374
|
+
(duration: Duration.DurationInput): <A extends DateTime>(self: A) => A
|
|
1375
|
+
<A extends DateTime>(self: A, duration: Duration.DurationInput): A
|
|
1376
|
+
} = Internal.subtractDuration
|
|
1377
|
+
|
|
1378
|
+
/**
|
|
1379
|
+
* Add the given `amount` of `unit`'s to a `DateTime`.
|
|
1380
|
+
*
|
|
1381
|
+
* The time zone is taken into account when adding days, weeks, months, and
|
|
1382
|
+
* years.
|
|
1383
|
+
*
|
|
1384
|
+
* @since 3.6.0
|
|
1385
|
+
* @category math
|
|
1386
|
+
* @example
|
|
1387
|
+
* ```ts
|
|
1388
|
+
* import { DateTime } from "effect"
|
|
1389
|
+
*
|
|
1390
|
+
* // add 5 minutes
|
|
1391
|
+
* DateTime.unsafeMake(0).pipe(
|
|
1392
|
+
* DateTime.add({ minutes: 5 })
|
|
1393
|
+
* )
|
|
1394
|
+
* ```
|
|
1395
|
+
*/
|
|
1396
|
+
export const add: {
|
|
1397
|
+
(parts: Partial<DateTime.PartsForMath>): <A extends DateTime>(self: A) => A
|
|
1398
|
+
<A extends DateTime>(self: A, parts: Partial<DateTime.PartsForMath>): A
|
|
1399
|
+
} = Internal.add
|
|
1400
|
+
|
|
1401
|
+
/**
|
|
1402
|
+
* Subtract the given `amount` of `unit`'s from a `DateTime`.
|
|
1403
|
+
*
|
|
1404
|
+
* @since 3.6.0
|
|
1405
|
+
* @category math
|
|
1406
|
+
* @example
|
|
1407
|
+
* ```ts
|
|
1408
|
+
* import { DateTime } from "effect"
|
|
1409
|
+
*
|
|
1410
|
+
* // subtract 5 minutes
|
|
1411
|
+
* DateTime.unsafeMake(0).pipe(
|
|
1412
|
+
* DateTime.subtract({ minutes: 5 })
|
|
1413
|
+
* )
|
|
1414
|
+
* ```
|
|
1415
|
+
*/
|
|
1416
|
+
export const subtract: {
|
|
1417
|
+
(parts: Partial<DateTime.PartsForMath>): <A extends DateTime>(self: A) => A
|
|
1418
|
+
<A extends DateTime>(self: A, parts: Partial<DateTime.PartsForMath>): A
|
|
1419
|
+
} = Internal.subtract
|
|
1420
|
+
|
|
1421
|
+
/**
|
|
1422
|
+
* Converts a `DateTime` to the start of the given `part`.
|
|
1423
|
+
*
|
|
1424
|
+
* If the part is `week`, the `weekStartsOn` option can be used to specify the
|
|
1425
|
+
* day of the week that the week starts on. The default is 0 (Sunday).
|
|
1426
|
+
*
|
|
1427
|
+
* @since 3.6.0
|
|
1428
|
+
* @category math
|
|
1429
|
+
* @example
|
|
1430
|
+
* ```ts
|
|
1431
|
+
* import { DateTime } from "effect"
|
|
1432
|
+
*
|
|
1433
|
+
* // returns "2024-01-01T00:00:00Z"
|
|
1434
|
+
* DateTime.unsafeMake("2024-01-01T12:00:00Z").pipe(
|
|
1435
|
+
* DateTime.startOf("day"),
|
|
1436
|
+
* DateTime.formatIso
|
|
1437
|
+
* )
|
|
1438
|
+
* ```
|
|
1439
|
+
*/
|
|
1440
|
+
export const startOf: {
|
|
1441
|
+
(
|
|
1442
|
+
part: DateTime.UnitSingular,
|
|
1443
|
+
options?: { readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined }
|
|
1444
|
+
): <A extends DateTime>(self: A) => A
|
|
1445
|
+
<A extends DateTime>(
|
|
1446
|
+
self: A,
|
|
1447
|
+
part: DateTime.UnitSingular,
|
|
1448
|
+
options?: { readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined }
|
|
1449
|
+
): A
|
|
1450
|
+
} = Internal.startOf
|
|
1451
|
+
|
|
1452
|
+
/**
|
|
1453
|
+
* Converts a `DateTime` to the end of the given `part`.
|
|
1454
|
+
*
|
|
1455
|
+
* If the part is `week`, the `weekStartsOn` option can be used to specify the
|
|
1456
|
+
* day of the week that the week starts on. The default is 0 (Sunday).
|
|
1457
|
+
*
|
|
1458
|
+
* @since 3.6.0
|
|
1459
|
+
* @category math
|
|
1460
|
+
* @example
|
|
1461
|
+
* ```ts
|
|
1462
|
+
* import { DateTime } from "effect"
|
|
1463
|
+
*
|
|
1464
|
+
* // returns "2024-01-01T23:59:59.999Z"
|
|
1465
|
+
* DateTime.unsafeMake("2024-01-01T12:00:00Z").pipe(
|
|
1466
|
+
* DateTime.endOf("day"),
|
|
1467
|
+
* DateTime.formatIso
|
|
1468
|
+
* )
|
|
1469
|
+
* ```
|
|
1470
|
+
*/
|
|
1471
|
+
export const endOf: {
|
|
1472
|
+
(
|
|
1473
|
+
part: DateTime.UnitSingular,
|
|
1474
|
+
options?: { readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined }
|
|
1475
|
+
): <A extends DateTime>(self: A) => A
|
|
1476
|
+
<A extends DateTime>(
|
|
1477
|
+
self: A,
|
|
1478
|
+
part: DateTime.UnitSingular,
|
|
1479
|
+
options?: { readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined }
|
|
1480
|
+
): A
|
|
1481
|
+
} = Internal.endOf
|
|
1482
|
+
|
|
1483
|
+
/**
|
|
1484
|
+
* Converts a `DateTime` to the nearest given `part`.
|
|
1485
|
+
*
|
|
1486
|
+
* If the part is `week`, the `weekStartsOn` option can be used to specify the
|
|
1487
|
+
* day of the week that the week starts on. The default is 0 (Sunday).
|
|
1488
|
+
*
|
|
1489
|
+
* @since 3.6.0
|
|
1490
|
+
* @category math
|
|
1491
|
+
* @example
|
|
1492
|
+
* ```ts
|
|
1493
|
+
* import { DateTime } from "effect"
|
|
1494
|
+
*
|
|
1495
|
+
* // returns "2024-01-02T00:00:00Z"
|
|
1496
|
+
* DateTime.unsafeMake("2024-01-01T12:01:00Z").pipe(
|
|
1497
|
+
* DateTime.nearest("day"),
|
|
1498
|
+
* DateTime.formatIso
|
|
1499
|
+
* )
|
|
1500
|
+
* ```
|
|
1501
|
+
*/
|
|
1502
|
+
export const nearest: {
|
|
1503
|
+
(
|
|
1504
|
+
part: DateTime.UnitSingular,
|
|
1505
|
+
options?: { readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined }
|
|
1506
|
+
): <A extends DateTime>(self: A) => A
|
|
1507
|
+
<A extends DateTime>(
|
|
1508
|
+
self: A,
|
|
1509
|
+
part: DateTime.UnitSingular,
|
|
1510
|
+
options?: { readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined }
|
|
1511
|
+
): A
|
|
1512
|
+
} = Internal.nearest
|
|
1513
|
+
|
|
1514
|
+
// =============================================================================
|
|
1515
|
+
// formatting
|
|
1516
|
+
// =============================================================================
|
|
1517
|
+
|
|
1518
|
+
/**
|
|
1519
|
+
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
1520
|
+
*
|
|
1521
|
+
* The `timeZone` option is set to the offset of the time zone.
|
|
1522
|
+
*
|
|
1523
|
+
* Note: On Node versions < 22, fixed "Offset" zones will set the time zone to
|
|
1524
|
+
* "UTC" and use the adjusted `Date`.
|
|
1525
|
+
*
|
|
1526
|
+
* @since 3.6.0
|
|
1527
|
+
* @category formatting
|
|
1528
|
+
*/
|
|
1529
|
+
export const format: {
|
|
1530
|
+
(
|
|
1531
|
+
options?:
|
|
1532
|
+
| Intl.DateTimeFormatOptions & {
|
|
1533
|
+
readonly locale?: Intl.LocalesArgument
|
|
1534
|
+
}
|
|
1535
|
+
| undefined
|
|
1536
|
+
): (self: DateTime) => string
|
|
1537
|
+
(
|
|
1538
|
+
self: DateTime,
|
|
1539
|
+
options?:
|
|
1540
|
+
| Intl.DateTimeFormatOptions & {
|
|
1541
|
+
readonly locale?: Intl.LocalesArgument
|
|
1542
|
+
}
|
|
1543
|
+
| undefined
|
|
1544
|
+
): string
|
|
1545
|
+
} = Internal.format
|
|
1546
|
+
|
|
1547
|
+
/**
|
|
1548
|
+
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
1549
|
+
*
|
|
1550
|
+
* It will use the system's local time zone & locale.
|
|
1551
|
+
*
|
|
1552
|
+
* @since 3.6.0
|
|
1553
|
+
* @category formatting
|
|
1554
|
+
*/
|
|
1555
|
+
export const formatLocal: {
|
|
1556
|
+
(
|
|
1557
|
+
options?:
|
|
1558
|
+
| Intl.DateTimeFormatOptions & {
|
|
1559
|
+
readonly locale?: Intl.LocalesArgument
|
|
1560
|
+
}
|
|
1561
|
+
| undefined
|
|
1562
|
+
): (self: DateTime) => string
|
|
1563
|
+
(
|
|
1564
|
+
self: DateTime,
|
|
1565
|
+
options?:
|
|
1566
|
+
| Intl.DateTimeFormatOptions & {
|
|
1567
|
+
readonly locale?: Intl.LocalesArgument
|
|
1568
|
+
}
|
|
1569
|
+
| undefined
|
|
1570
|
+
): string
|
|
1571
|
+
} = Internal.formatLocal
|
|
1572
|
+
|
|
1573
|
+
/**
|
|
1574
|
+
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
1575
|
+
*
|
|
1576
|
+
* This forces the time zone to be UTC.
|
|
1577
|
+
*
|
|
1578
|
+
* @since 3.6.0
|
|
1579
|
+
* @category formatting
|
|
1580
|
+
*/
|
|
1581
|
+
export const formatUtc: {
|
|
1582
|
+
(
|
|
1583
|
+
options?:
|
|
1584
|
+
| Intl.DateTimeFormatOptions & {
|
|
1585
|
+
readonly locale?: Intl.LocalesArgument
|
|
1586
|
+
}
|
|
1587
|
+
| undefined
|
|
1588
|
+
): (self: DateTime) => string
|
|
1589
|
+
(
|
|
1590
|
+
self: DateTime,
|
|
1591
|
+
options?:
|
|
1592
|
+
| Intl.DateTimeFormatOptions & {
|
|
1593
|
+
readonly locale?: Intl.LocalesArgument
|
|
1594
|
+
}
|
|
1595
|
+
| undefined
|
|
1596
|
+
): string
|
|
1597
|
+
} = Internal.formatUtc
|
|
1598
|
+
|
|
1599
|
+
/**
|
|
1600
|
+
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
1601
|
+
*
|
|
1602
|
+
* @since 3.6.0
|
|
1603
|
+
* @category formatting
|
|
1604
|
+
*/
|
|
1605
|
+
export const formatIntl: {
|
|
1606
|
+
(format: Intl.DateTimeFormat): (self: DateTime) => string
|
|
1607
|
+
(self: DateTime, format: Intl.DateTimeFormat): string
|
|
1608
|
+
} = Internal.formatIntl
|
|
1609
|
+
|
|
1610
|
+
/**
|
|
1611
|
+
* Format a `DateTime` as a UTC ISO string.
|
|
1612
|
+
*
|
|
1613
|
+
* @since 3.6.0
|
|
1614
|
+
* @category formatting
|
|
1615
|
+
*/
|
|
1616
|
+
export const formatIso: (self: DateTime) => string = Internal.formatIso
|
|
1617
|
+
|
|
1618
|
+
/**
|
|
1619
|
+
* Format a `DateTime` as a time zone adjusted ISO date string.
|
|
1620
|
+
*
|
|
1621
|
+
* @since 3.6.0
|
|
1622
|
+
* @category formatting
|
|
1623
|
+
*/
|
|
1624
|
+
export const formatIsoDate: (self: DateTime) => string = Internal.formatIsoDate
|
|
1625
|
+
|
|
1626
|
+
/**
|
|
1627
|
+
* Format a `DateTime` as a UTC ISO date string.
|
|
1628
|
+
*
|
|
1629
|
+
* @since 3.6.0
|
|
1630
|
+
* @category formatting
|
|
1631
|
+
*/
|
|
1632
|
+
export const formatIsoDateUtc: (self: DateTime) => string = Internal.formatIsoDateUtc
|
|
1633
|
+
|
|
1634
|
+
/**
|
|
1635
|
+
* Format a `DateTime.Zoned` as a ISO string with an offset.
|
|
1636
|
+
*
|
|
1637
|
+
* @since 3.6.0
|
|
1638
|
+
* @category formatting
|
|
1639
|
+
*/
|
|
1640
|
+
export const formatIsoOffset: (self: DateTime) => string = Internal.formatIsoOffset
|
|
1641
|
+
|
|
1642
|
+
/**
|
|
1643
|
+
* Format a `DateTime.Zoned` as a string.
|
|
1644
|
+
*
|
|
1645
|
+
* It uses the format: `YYYY-MM-DDTHH:mm:ss.sss+HH:MM[Time/Zone]`.
|
|
1646
|
+
*
|
|
1647
|
+
* @since 3.6.0
|
|
1648
|
+
* @category formatting
|
|
1649
|
+
*/
|
|
1650
|
+
export const formatIsoZoned: (self: Zoned) => string = Internal.formatIsoZoned
|
|
1651
|
+
|
|
1652
|
+
/**
|
|
1653
|
+
* Create a Layer from the given time zone.
|
|
1654
|
+
*
|
|
1655
|
+
* @since 3.6.0
|
|
1656
|
+
* @category current time zone
|
|
1657
|
+
*/
|
|
1658
|
+
export const layerCurrentZone = (zone: TimeZone): Layer.Layer<CurrentTimeZone> => Layer.succeed(CurrentTimeZone, zone)
|
|
1659
|
+
|
|
1660
|
+
/**
|
|
1661
|
+
* Create a Layer from the given time zone offset.
|
|
1662
|
+
*
|
|
1663
|
+
* @since 3.6.0
|
|
1664
|
+
* @category current time zone
|
|
1665
|
+
*/
|
|
1666
|
+
export const layerCurrentZoneOffset = (offset: number): Layer.Layer<CurrentTimeZone> =>
|
|
1667
|
+
Layer.succeed(CurrentTimeZone, Internal.zoneMakeOffset(offset))
|
|
1668
|
+
|
|
1669
|
+
/**
|
|
1670
|
+
* Create a Layer from the given IANA time zone identifier.
|
|
1671
|
+
*
|
|
1672
|
+
* @since 3.6.0
|
|
1673
|
+
* @category current time zone
|
|
1674
|
+
*/
|
|
1675
|
+
export const layerCurrentZoneNamed = (
|
|
1676
|
+
zoneId: string
|
|
1677
|
+
): Layer.Layer<CurrentTimeZone, IllegalArgumentException> =>
|
|
1678
|
+
Layer.effect(CurrentTimeZone, Internal.zoneMakeNamedEffect(zoneId))
|
|
1679
|
+
|
|
1680
|
+
/**
|
|
1681
|
+
* Create a Layer from the systems local time zone.
|
|
1682
|
+
*
|
|
1683
|
+
* @since 3.6.0
|
|
1684
|
+
* @category current time zone
|
|
1685
|
+
*/
|
|
1686
|
+
export const layerCurrentZoneLocal: Layer.Layer<CurrentTimeZone> = Layer.sync(CurrentTimeZone, zoneMakeLocal)
|