@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
|
@@ -0,0 +1,1277 @@
|
|
|
1
|
+
import { IllegalArgumentException } from "../Cause.js"
|
|
2
|
+
import * as Clock from "../Clock.js"
|
|
3
|
+
import type * as DateTime from "../DateTime.js"
|
|
4
|
+
import * as Duration from "../Duration.js"
|
|
5
|
+
import type * as Effect from "../Effect.js"
|
|
6
|
+
import * as Either from "../Either.js"
|
|
7
|
+
import * as Equal from "../Equal.js"
|
|
8
|
+
import * as equivalence from "../Equivalence.js"
|
|
9
|
+
import type { LazyArg } from "../Function.js"
|
|
10
|
+
import { dual, pipe } from "../Function.js"
|
|
11
|
+
import { globalValue } from "../GlobalValue.js"
|
|
12
|
+
import * as Hash from "../Hash.js"
|
|
13
|
+
import * as Inspectable from "../Inspectable.js"
|
|
14
|
+
import * as Option from "../Option.js"
|
|
15
|
+
import * as order from "../Order.js"
|
|
16
|
+
import { pipeArguments } from "../Pipeable.js"
|
|
17
|
+
import * as Predicate from "../Predicate.js"
|
|
18
|
+
import type { Mutable } from "../Types.js"
|
|
19
|
+
import * as internalEffect from "./core-effect.js"
|
|
20
|
+
import * as core from "./core.js"
|
|
21
|
+
|
|
22
|
+
/** @internal */
|
|
23
|
+
export const TypeId: DateTime.TypeId = Symbol.for("effect/DateTime") as DateTime.TypeId
|
|
24
|
+
|
|
25
|
+
/** @internal */
|
|
26
|
+
export const TimeZoneTypeId: DateTime.TimeZoneTypeId = Symbol.for("effect/DateTime/TimeZone") as DateTime.TimeZoneTypeId
|
|
27
|
+
|
|
28
|
+
const Proto = {
|
|
29
|
+
[TypeId]: TypeId,
|
|
30
|
+
pipe() {
|
|
31
|
+
return pipeArguments(this, arguments)
|
|
32
|
+
},
|
|
33
|
+
[Inspectable.NodeInspectSymbol](this: DateTime.DateTime) {
|
|
34
|
+
return this.toString()
|
|
35
|
+
},
|
|
36
|
+
toJSON(this: DateTime.DateTime) {
|
|
37
|
+
return toDateUtc(this).toJSON()
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const ProtoUtc = {
|
|
42
|
+
...Proto,
|
|
43
|
+
_tag: "Utc",
|
|
44
|
+
[Hash.symbol](this: DateTime.Utc) {
|
|
45
|
+
return Hash.cached(this, Hash.number(this.epochMillis))
|
|
46
|
+
},
|
|
47
|
+
[Equal.symbol](this: DateTime.Utc, that: unknown) {
|
|
48
|
+
return isDateTime(that) && that._tag === "Utc" && this.epochMillis === that.epochMillis
|
|
49
|
+
},
|
|
50
|
+
toString(this: DateTime.Utc) {
|
|
51
|
+
return `DateTime.Utc(${toDateUtc(this).toJSON()})`
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const ProtoZoned = {
|
|
56
|
+
...Proto,
|
|
57
|
+
_tag: "Zoned",
|
|
58
|
+
[Hash.symbol](this: DateTime.Zoned) {
|
|
59
|
+
return pipe(
|
|
60
|
+
Hash.number(this.epochMillis),
|
|
61
|
+
Hash.combine(Hash.hash(this.zone)),
|
|
62
|
+
Hash.cached(this)
|
|
63
|
+
)
|
|
64
|
+
},
|
|
65
|
+
[Equal.symbol](this: DateTime.Zoned, that: unknown) {
|
|
66
|
+
return isDateTime(that) && that._tag === "Zoned" && this.epochMillis === that.epochMillis &&
|
|
67
|
+
Equal.equals(this.zone, that.zone)
|
|
68
|
+
},
|
|
69
|
+
toString(this: DateTime.Zoned) {
|
|
70
|
+
return `DateTime.Zoned(${formatIsoZoned(this)})`
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const ProtoTimeZone = {
|
|
75
|
+
[TimeZoneTypeId]: TimeZoneTypeId,
|
|
76
|
+
[Inspectable.NodeInspectSymbol](this: DateTime.TimeZone) {
|
|
77
|
+
return this.toString()
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const ProtoTimeZoneNamed = {
|
|
82
|
+
...ProtoTimeZone,
|
|
83
|
+
_tag: "Named",
|
|
84
|
+
[Hash.symbol](this: DateTime.TimeZone.Named) {
|
|
85
|
+
return Hash.cached(this, Hash.string(`Named:${this.id}`))
|
|
86
|
+
},
|
|
87
|
+
[Equal.symbol](this: DateTime.TimeZone.Named, that: unknown) {
|
|
88
|
+
return isTimeZone(that) && that._tag === "Named" && this.id === that.id
|
|
89
|
+
},
|
|
90
|
+
toString(this: DateTime.TimeZone.Named) {
|
|
91
|
+
return `TimeZone.Named(${this.id})`
|
|
92
|
+
},
|
|
93
|
+
toJSON(this: DateTime.TimeZone.Named) {
|
|
94
|
+
return {
|
|
95
|
+
_id: "TimeZone",
|
|
96
|
+
_tag: "Named",
|
|
97
|
+
id: this.id
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const ProtoTimeZoneOffset = {
|
|
103
|
+
...ProtoTimeZone,
|
|
104
|
+
_tag: "Offset",
|
|
105
|
+
[Hash.symbol](this: DateTime.TimeZone.Offset) {
|
|
106
|
+
return Hash.cached(this, Hash.string(`Offset:${this.offset}`))
|
|
107
|
+
},
|
|
108
|
+
[Equal.symbol](this: DateTime.TimeZone.Offset, that: unknown) {
|
|
109
|
+
return isTimeZone(that) && that._tag === "Offset" && this.offset === that.offset
|
|
110
|
+
},
|
|
111
|
+
toString(this: DateTime.TimeZone.Offset) {
|
|
112
|
+
return `TimeZone.Offset(${offsetToString(this.offset)})`
|
|
113
|
+
},
|
|
114
|
+
toJSON(this: DateTime.TimeZone.Offset) {
|
|
115
|
+
return {
|
|
116
|
+
_id: "TimeZone",
|
|
117
|
+
_tag: "Offset",
|
|
118
|
+
offset: this.offset
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** @internal */
|
|
124
|
+
export const makeZonedProto = (
|
|
125
|
+
epochMillis: number,
|
|
126
|
+
zone: DateTime.TimeZone,
|
|
127
|
+
partsUtc?: DateTime.DateTime.PartsWithWeekday
|
|
128
|
+
): DateTime.Zoned => {
|
|
129
|
+
const self = Object.create(ProtoZoned)
|
|
130
|
+
self.epochMillis = epochMillis
|
|
131
|
+
self.zone = zone
|
|
132
|
+
Object.defineProperty(self, "partsUtc", {
|
|
133
|
+
value: partsUtc,
|
|
134
|
+
enumerable: false,
|
|
135
|
+
writable: true
|
|
136
|
+
})
|
|
137
|
+
Object.defineProperty(self, "adjustedEpochMillis", {
|
|
138
|
+
value: undefined,
|
|
139
|
+
enumerable: false,
|
|
140
|
+
writable: true
|
|
141
|
+
})
|
|
142
|
+
Object.defineProperty(self, "partsAdjusted", {
|
|
143
|
+
value: undefined,
|
|
144
|
+
enumerable: false,
|
|
145
|
+
writable: true
|
|
146
|
+
})
|
|
147
|
+
return self
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// =============================================================================
|
|
151
|
+
// guards
|
|
152
|
+
// =============================================================================
|
|
153
|
+
|
|
154
|
+
/** @internal */
|
|
155
|
+
export const isDateTime = (u: unknown): u is DateTime.DateTime => Predicate.hasProperty(u, TypeId)
|
|
156
|
+
|
|
157
|
+
const isDateTimeArgs = (args: IArguments) => isDateTime(args[0])
|
|
158
|
+
|
|
159
|
+
/** @internal */
|
|
160
|
+
export const isTimeZone = (u: unknown): u is DateTime.TimeZone => Predicate.hasProperty(u, TimeZoneTypeId)
|
|
161
|
+
|
|
162
|
+
/** @internal */
|
|
163
|
+
export const isTimeZoneOffset = (u: unknown): u is DateTime.TimeZone.Offset => isTimeZone(u) && u._tag === "Offset"
|
|
164
|
+
|
|
165
|
+
/** @internal */
|
|
166
|
+
export const isTimeZoneNamed = (u: unknown): u is DateTime.TimeZone.Named => isTimeZone(u) && u._tag === "Named"
|
|
167
|
+
|
|
168
|
+
/** @internal */
|
|
169
|
+
export const isUtc = (self: DateTime.DateTime): self is DateTime.Utc => self._tag === "Utc"
|
|
170
|
+
|
|
171
|
+
/** @internal */
|
|
172
|
+
export const isZoned = (self: DateTime.DateTime): self is DateTime.Zoned => self._tag === "Zoned"
|
|
173
|
+
|
|
174
|
+
// =============================================================================
|
|
175
|
+
// instances
|
|
176
|
+
// =============================================================================
|
|
177
|
+
|
|
178
|
+
/** @internal */
|
|
179
|
+
export const Equivalence: equivalence.Equivalence<DateTime.DateTime> = equivalence.make((a, b) =>
|
|
180
|
+
a.epochMillis === b.epochMillis
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
/** @internal */
|
|
184
|
+
export const Order: order.Order<DateTime.DateTime> = order.make((self, that) =>
|
|
185
|
+
self.epochMillis < that.epochMillis ? -1 : self.epochMillis > that.epochMillis ? 1 : 0
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
/** @internal */
|
|
189
|
+
export const clamp: {
|
|
190
|
+
<Min extends DateTime.DateTime, Max extends DateTime.DateTime>(
|
|
191
|
+
options: { readonly minimum: Min; readonly maximum: Max }
|
|
192
|
+
): <A extends DateTime.DateTime>(self: A) => A | Min | Max
|
|
193
|
+
<A extends DateTime.DateTime, Min extends DateTime.DateTime, Max extends DateTime.DateTime>(
|
|
194
|
+
self: A,
|
|
195
|
+
options: { readonly minimum: Min; readonly maximum: Max }
|
|
196
|
+
): A | Min | Max
|
|
197
|
+
} = order.clamp(Order)
|
|
198
|
+
|
|
199
|
+
// =============================================================================
|
|
200
|
+
// constructors
|
|
201
|
+
// =============================================================================
|
|
202
|
+
|
|
203
|
+
const makeUtc = (epochMillis: number): DateTime.Utc => {
|
|
204
|
+
const self = Object.create(ProtoUtc)
|
|
205
|
+
self.epochMillis = epochMillis
|
|
206
|
+
Object.defineProperty(self, "partsUtc", {
|
|
207
|
+
value: undefined,
|
|
208
|
+
enumerable: false,
|
|
209
|
+
writable: true
|
|
210
|
+
})
|
|
211
|
+
return self
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** @internal */
|
|
215
|
+
export const unsafeFromDate = (date: Date): DateTime.Utc => {
|
|
216
|
+
const epochMillis = date.getTime()
|
|
217
|
+
if (Number.isNaN(epochMillis)) {
|
|
218
|
+
throw new IllegalArgumentException("Invalid date")
|
|
219
|
+
}
|
|
220
|
+
return makeUtc(epochMillis)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** @internal */
|
|
224
|
+
export const unsafeMake = <A extends DateTime.DateTime.Input>(input: A): DateTime.DateTime.PreserveZone<A> => {
|
|
225
|
+
if (isDateTime(input)) {
|
|
226
|
+
return input as DateTime.DateTime.PreserveZone<A>
|
|
227
|
+
} else if (input instanceof Date) {
|
|
228
|
+
return unsafeFromDate(input) as DateTime.DateTime.PreserveZone<A>
|
|
229
|
+
} else if (typeof input === "object") {
|
|
230
|
+
const date = new Date(0)
|
|
231
|
+
setPartsDate(date, input)
|
|
232
|
+
return unsafeFromDate(date) as DateTime.DateTime.PreserveZone<A>
|
|
233
|
+
} else if (typeof input === "string" && !hasZone(input)) {
|
|
234
|
+
return unsafeFromDate(new Date(input + "Z")) as DateTime.DateTime.PreserveZone<A>
|
|
235
|
+
}
|
|
236
|
+
return unsafeFromDate(new Date(input)) as DateTime.DateTime.PreserveZone<A>
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const hasZone = (input: string): boolean => /Z|[+-]\d{2}$|[+-]\d{2}:?\d{2}$|\]$/.test(input)
|
|
240
|
+
|
|
241
|
+
const minEpochMillis = -8640000000000000 + (12 * 60 * 60 * 1000)
|
|
242
|
+
const maxEpochMillis = 8640000000000000 - (14 * 60 * 60 * 1000)
|
|
243
|
+
|
|
244
|
+
/** @internal */
|
|
245
|
+
export const unsafeMakeZoned = (input: DateTime.DateTime.Input, options?: {
|
|
246
|
+
readonly timeZone?: number | string | DateTime.TimeZone | undefined
|
|
247
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
248
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
249
|
+
}): DateTime.Zoned => {
|
|
250
|
+
if (options?.timeZone === undefined && isDateTime(input) && isZoned(input)) {
|
|
251
|
+
return input
|
|
252
|
+
}
|
|
253
|
+
const self = unsafeMake(input)
|
|
254
|
+
if (self.epochMillis < minEpochMillis || self.epochMillis > maxEpochMillis) {
|
|
255
|
+
throw new RangeError(`Epoch millis out of range: ${self.epochMillis}`)
|
|
256
|
+
}
|
|
257
|
+
let zone: DateTime.TimeZone
|
|
258
|
+
if (options?.timeZone === undefined) {
|
|
259
|
+
const offset = new Date(self.epochMillis).getTimezoneOffset() * -60 * 1000
|
|
260
|
+
zone = zoneMakeOffset(offset)
|
|
261
|
+
} else if (isTimeZone(options?.timeZone)) {
|
|
262
|
+
zone = options.timeZone
|
|
263
|
+
} else if (typeof options?.timeZone === "number") {
|
|
264
|
+
zone = zoneMakeOffset(options.timeZone)
|
|
265
|
+
} else {
|
|
266
|
+
const parsedZone = zoneFromString(options.timeZone)
|
|
267
|
+
if (Option.isNone(parsedZone)) {
|
|
268
|
+
throw new IllegalArgumentException(`Invalid time zone: ${options.timeZone}`)
|
|
269
|
+
}
|
|
270
|
+
zone = parsedZone.value
|
|
271
|
+
}
|
|
272
|
+
if (options?.adjustForTimeZone !== true) {
|
|
273
|
+
return makeZonedProto(self.epochMillis, zone, self.partsUtc)
|
|
274
|
+
}
|
|
275
|
+
return makeZonedFromAdjusted(self.epochMillis, zone, options?.disambiguation ?? "compatible")
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** @internal */
|
|
279
|
+
export const makeZoned: (
|
|
280
|
+
input: DateTime.DateTime.Input,
|
|
281
|
+
options?: {
|
|
282
|
+
readonly timeZone?: number | string | DateTime.TimeZone | undefined
|
|
283
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
284
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
285
|
+
}
|
|
286
|
+
) => Option.Option<DateTime.Zoned> = Option.liftThrowable(unsafeMakeZoned)
|
|
287
|
+
|
|
288
|
+
/** @internal */
|
|
289
|
+
export const make: <A extends DateTime.DateTime.Input>(input: A) => Option.Option<DateTime.DateTime.PreserveZone<A>> =
|
|
290
|
+
Option.liftThrowable(unsafeMake)
|
|
291
|
+
|
|
292
|
+
const zonedStringRegex = /^(.{17,35})\[(.+)\]$/
|
|
293
|
+
|
|
294
|
+
/** @internal */
|
|
295
|
+
export const makeZonedFromString = (input: string): Option.Option<DateTime.Zoned> => {
|
|
296
|
+
const match = zonedStringRegex.exec(input)
|
|
297
|
+
if (match === null) {
|
|
298
|
+
const offset = parseOffset(input)
|
|
299
|
+
return offset !== null ? makeZoned(input, { timeZone: offset }) : Option.none()
|
|
300
|
+
}
|
|
301
|
+
const [, isoString, timeZone] = match
|
|
302
|
+
return makeZoned(isoString, { timeZone })
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** @internal */
|
|
306
|
+
export const now: Effect.Effect<DateTime.Utc> = core.map(Clock.currentTimeMillis, makeUtc)
|
|
307
|
+
|
|
308
|
+
/** @internal */
|
|
309
|
+
export const nowAsDate: Effect.Effect<Date> = core.map(Clock.currentTimeMillis, (millis) => new Date(millis))
|
|
310
|
+
|
|
311
|
+
/** @internal */
|
|
312
|
+
export const unsafeNow: LazyArg<DateTime.Utc> = () => makeUtc(Date.now())
|
|
313
|
+
|
|
314
|
+
// =============================================================================
|
|
315
|
+
// time zones
|
|
316
|
+
// =============================================================================
|
|
317
|
+
|
|
318
|
+
/** @internal */
|
|
319
|
+
export const toUtc = (self: DateTime.DateTime): DateTime.Utc => makeUtc(self.epochMillis)
|
|
320
|
+
|
|
321
|
+
/** @internal */
|
|
322
|
+
export const setZone: {
|
|
323
|
+
(zone: DateTime.TimeZone, options?: {
|
|
324
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
325
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
326
|
+
}): (self: DateTime.DateTime) => DateTime.Zoned
|
|
327
|
+
(self: DateTime.DateTime, zone: DateTime.TimeZone, options?: {
|
|
328
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
329
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
330
|
+
}): DateTime.Zoned
|
|
331
|
+
} = dual(isDateTimeArgs, (self: DateTime.DateTime, zone: DateTime.TimeZone, options?: {
|
|
332
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
333
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
334
|
+
}): DateTime.Zoned =>
|
|
335
|
+
options?.adjustForTimeZone === true
|
|
336
|
+
? makeZonedFromAdjusted(self.epochMillis, zone, options?.disambiguation ?? "compatible")
|
|
337
|
+
: makeZonedProto(self.epochMillis, zone, self.partsUtc))
|
|
338
|
+
|
|
339
|
+
/** @internal */
|
|
340
|
+
export const setZoneOffset: {
|
|
341
|
+
(offset: number, options?: {
|
|
342
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
343
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
344
|
+
}): (self: DateTime.DateTime) => DateTime.Zoned
|
|
345
|
+
(self: DateTime.DateTime, offset: number, options?: {
|
|
346
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
347
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
348
|
+
}): DateTime.Zoned
|
|
349
|
+
} = dual(isDateTimeArgs, (self: DateTime.DateTime, offset: number, options?: {
|
|
350
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
351
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
352
|
+
}): DateTime.Zoned => setZone(self, zoneMakeOffset(offset), options))
|
|
353
|
+
|
|
354
|
+
const validZoneCache = globalValue("effect/DateTime/validZoneCache", () => new Map<string, DateTime.TimeZone.Named>())
|
|
355
|
+
|
|
356
|
+
const formatOptions: Intl.DateTimeFormatOptions = {
|
|
357
|
+
day: "numeric",
|
|
358
|
+
month: "numeric",
|
|
359
|
+
year: "numeric",
|
|
360
|
+
hour: "numeric",
|
|
361
|
+
minute: "numeric",
|
|
362
|
+
second: "numeric",
|
|
363
|
+
timeZoneName: "longOffset",
|
|
364
|
+
fractionalSecondDigits: 3,
|
|
365
|
+
hourCycle: "h23"
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const zoneMakeIntl = (format: Intl.DateTimeFormat): DateTime.TimeZone.Named => {
|
|
369
|
+
const zoneId = format.resolvedOptions().timeZone
|
|
370
|
+
if (validZoneCache.has(zoneId)) {
|
|
371
|
+
return validZoneCache.get(zoneId)!
|
|
372
|
+
}
|
|
373
|
+
const zone = Object.create(ProtoTimeZoneNamed)
|
|
374
|
+
zone.id = zoneId
|
|
375
|
+
zone.format = format
|
|
376
|
+
validZoneCache.set(zoneId, zone)
|
|
377
|
+
return zone
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** @internal */
|
|
381
|
+
export const zoneUnsafeMakeNamed = (zoneId: string): DateTime.TimeZone.Named => {
|
|
382
|
+
if (validZoneCache.has(zoneId)) {
|
|
383
|
+
return validZoneCache.get(zoneId)!
|
|
384
|
+
}
|
|
385
|
+
try {
|
|
386
|
+
return zoneMakeIntl(
|
|
387
|
+
new Intl.DateTimeFormat("en-US", {
|
|
388
|
+
...formatOptions,
|
|
389
|
+
timeZone: zoneId
|
|
390
|
+
})
|
|
391
|
+
)
|
|
392
|
+
} catch {
|
|
393
|
+
throw new IllegalArgumentException(`Invalid time zone: ${zoneId}`)
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** @internal */
|
|
398
|
+
export const zoneMakeOffset = (offset: number): DateTime.TimeZone.Offset => {
|
|
399
|
+
const zone = Object.create(ProtoTimeZoneOffset)
|
|
400
|
+
zone.offset = offset
|
|
401
|
+
return zone
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** @internal */
|
|
405
|
+
export const zoneMakeNamed: (zoneId: string) => Option.Option<DateTime.TimeZone.Named> = Option.liftThrowable(
|
|
406
|
+
zoneUnsafeMakeNamed
|
|
407
|
+
)
|
|
408
|
+
|
|
409
|
+
/** @internal */
|
|
410
|
+
export const zoneMakeNamedEffect = (zoneId: string): Effect.Effect<DateTime.TimeZone.Named, IllegalArgumentException> =>
|
|
411
|
+
internalEffect.try_({
|
|
412
|
+
try: () => zoneUnsafeMakeNamed(zoneId),
|
|
413
|
+
catch: (e) => e as IllegalArgumentException
|
|
414
|
+
})
|
|
415
|
+
|
|
416
|
+
/** @internal */
|
|
417
|
+
export const zoneMakeLocal = (): DateTime.TimeZone.Named =>
|
|
418
|
+
zoneMakeIntl(new Intl.DateTimeFormat("en-US", formatOptions))
|
|
419
|
+
|
|
420
|
+
const offsetZoneRegex = /^(?:GMT|[+-])/
|
|
421
|
+
|
|
422
|
+
/** @internal */
|
|
423
|
+
export const zoneFromString = (zone: string): Option.Option<DateTime.TimeZone> => {
|
|
424
|
+
if (offsetZoneRegex.test(zone)) {
|
|
425
|
+
const offset = parseOffset(zone)
|
|
426
|
+
return offset === null ? Option.none() : Option.some(zoneMakeOffset(offset))
|
|
427
|
+
}
|
|
428
|
+
return zoneMakeNamed(zone)
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/** @internal */
|
|
432
|
+
export const zoneToString = (self: DateTime.TimeZone): string => {
|
|
433
|
+
if (self._tag === "Offset") {
|
|
434
|
+
return offsetToString(self.offset)
|
|
435
|
+
}
|
|
436
|
+
return self.id
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** @internal */
|
|
440
|
+
export const setZoneNamed: {
|
|
441
|
+
(zoneId: string, options?: {
|
|
442
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
443
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
444
|
+
}): (self: DateTime.DateTime) => Option.Option<DateTime.Zoned>
|
|
445
|
+
(self: DateTime.DateTime, zoneId: string, options?: {
|
|
446
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
447
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
448
|
+
}): Option.Option<DateTime.Zoned>
|
|
449
|
+
} = dual(
|
|
450
|
+
isDateTimeArgs,
|
|
451
|
+
(self: DateTime.DateTime, zoneId: string, options?: {
|
|
452
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
453
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
454
|
+
}): Option.Option<DateTime.Zoned> => Option.map(zoneMakeNamed(zoneId), (zone) => setZone(self, zone, options))
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
/** @internal */
|
|
458
|
+
export const unsafeSetZoneNamed: {
|
|
459
|
+
(zoneId: string, options?: {
|
|
460
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
461
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
462
|
+
}): (self: DateTime.DateTime) => DateTime.Zoned
|
|
463
|
+
(self: DateTime.DateTime, zoneId: string, options?: {
|
|
464
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
465
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
466
|
+
}): DateTime.Zoned
|
|
467
|
+
} = dual(isDateTimeArgs, (self: DateTime.DateTime, zoneId: string, options?: {
|
|
468
|
+
readonly adjustForTimeZone?: boolean | undefined
|
|
469
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
470
|
+
}): DateTime.Zoned => setZone(self, zoneUnsafeMakeNamed(zoneId), options))
|
|
471
|
+
|
|
472
|
+
// =============================================================================
|
|
473
|
+
// comparisons
|
|
474
|
+
// =============================================================================
|
|
475
|
+
|
|
476
|
+
/** @internal */
|
|
477
|
+
export const distance: {
|
|
478
|
+
(other: DateTime.DateTime): (self: DateTime.DateTime) => number
|
|
479
|
+
(self: DateTime.DateTime, other: DateTime.DateTime): number
|
|
480
|
+
} = dual(2, (self: DateTime.DateTime, other: DateTime.DateTime): number => toEpochMillis(other) - toEpochMillis(self))
|
|
481
|
+
|
|
482
|
+
/** @internal */
|
|
483
|
+
export const distanceDurationEither: {
|
|
484
|
+
(other: DateTime.DateTime): (self: DateTime.DateTime) => Either.Either<Duration.Duration, Duration.Duration>
|
|
485
|
+
(self: DateTime.DateTime, other: DateTime.DateTime): Either.Either<Duration.Duration, Duration.Duration>
|
|
486
|
+
} = dual(
|
|
487
|
+
2,
|
|
488
|
+
(self: DateTime.DateTime, other: DateTime.DateTime): Either.Either<Duration.Duration, Duration.Duration> => {
|
|
489
|
+
const diffMillis = distance(self, other)
|
|
490
|
+
return diffMillis > 0
|
|
491
|
+
? Either.right(Duration.millis(diffMillis))
|
|
492
|
+
: Either.left(Duration.millis(-diffMillis))
|
|
493
|
+
}
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
/** @internal */
|
|
497
|
+
export const distanceDuration: {
|
|
498
|
+
(other: DateTime.DateTime): (self: DateTime.DateTime) => Duration.Duration
|
|
499
|
+
(self: DateTime.DateTime, other: DateTime.DateTime): Duration.Duration
|
|
500
|
+
} = dual(
|
|
501
|
+
2,
|
|
502
|
+
(self: DateTime.DateTime, other: DateTime.DateTime): Duration.Duration =>
|
|
503
|
+
Duration.millis(Math.abs(distance(self, other)))
|
|
504
|
+
)
|
|
505
|
+
|
|
506
|
+
/** @internal */
|
|
507
|
+
export const min: {
|
|
508
|
+
<That extends DateTime.DateTime>(that: That): <Self extends DateTime.DateTime>(self: Self) => Self | That
|
|
509
|
+
<Self extends DateTime.DateTime, That extends DateTime.DateTime>(self: Self, that: That): Self | That
|
|
510
|
+
} = order.min(Order)
|
|
511
|
+
|
|
512
|
+
/** @internal */
|
|
513
|
+
export const max: {
|
|
514
|
+
<That extends DateTime.DateTime>(that: That): <Self extends DateTime.DateTime>(self: Self) => Self | That
|
|
515
|
+
<Self extends DateTime.DateTime, That extends DateTime.DateTime>(self: Self, that: That): Self | That
|
|
516
|
+
} = order.max(Order)
|
|
517
|
+
|
|
518
|
+
/** @internal */
|
|
519
|
+
export const greaterThan: {
|
|
520
|
+
(that: DateTime.DateTime): (self: DateTime.DateTime) => boolean
|
|
521
|
+
(self: DateTime.DateTime, that: DateTime.DateTime): boolean
|
|
522
|
+
} = order.greaterThan(Order)
|
|
523
|
+
|
|
524
|
+
/** @internal */
|
|
525
|
+
export const greaterThanOrEqualTo: {
|
|
526
|
+
(that: DateTime.DateTime): (self: DateTime.DateTime) => boolean
|
|
527
|
+
(self: DateTime.DateTime, that: DateTime.DateTime): boolean
|
|
528
|
+
} = order.greaterThanOrEqualTo(Order)
|
|
529
|
+
|
|
530
|
+
/** @internal */
|
|
531
|
+
export const lessThan: {
|
|
532
|
+
(that: DateTime.DateTime): (self: DateTime.DateTime) => boolean
|
|
533
|
+
(self: DateTime.DateTime, that: DateTime.DateTime): boolean
|
|
534
|
+
} = order.lessThan(Order)
|
|
535
|
+
|
|
536
|
+
/** @internal */
|
|
537
|
+
export const lessThanOrEqualTo: {
|
|
538
|
+
(that: DateTime.DateTime): (self: DateTime.DateTime) => boolean
|
|
539
|
+
(self: DateTime.DateTime, that: DateTime.DateTime): boolean
|
|
540
|
+
} = order.lessThanOrEqualTo(Order)
|
|
541
|
+
|
|
542
|
+
/** @internal */
|
|
543
|
+
export const between: {
|
|
544
|
+
(options: { minimum: DateTime.DateTime; maximum: DateTime.DateTime }): (self: DateTime.DateTime) => boolean
|
|
545
|
+
(self: DateTime.DateTime, options: { minimum: DateTime.DateTime; maximum: DateTime.DateTime }): boolean
|
|
546
|
+
} = order.between(Order)
|
|
547
|
+
|
|
548
|
+
/** @internal */
|
|
549
|
+
export const isFuture = (self: DateTime.DateTime): Effect.Effect<boolean> => core.map(now, lessThan(self))
|
|
550
|
+
|
|
551
|
+
/** @internal */
|
|
552
|
+
export const unsafeIsFuture = (self: DateTime.DateTime): boolean => lessThan(unsafeNow(), self)
|
|
553
|
+
|
|
554
|
+
/** @internal */
|
|
555
|
+
export const isPast = (self: DateTime.DateTime): Effect.Effect<boolean> => core.map(now, greaterThan(self))
|
|
556
|
+
|
|
557
|
+
/** @internal */
|
|
558
|
+
export const unsafeIsPast = (self: DateTime.DateTime): boolean => greaterThan(unsafeNow(), self)
|
|
559
|
+
|
|
560
|
+
// =============================================================================
|
|
561
|
+
// conversions
|
|
562
|
+
// =============================================================================
|
|
563
|
+
|
|
564
|
+
/** @internal */
|
|
565
|
+
export const toDateUtc = (self: DateTime.DateTime): Date => new Date(self.epochMillis)
|
|
566
|
+
|
|
567
|
+
/** @internal */
|
|
568
|
+
export const toDate = (self: DateTime.DateTime): Date => {
|
|
569
|
+
if (self._tag === "Utc") {
|
|
570
|
+
return new Date(self.epochMillis)
|
|
571
|
+
} else if (self.zone._tag === "Offset") {
|
|
572
|
+
return new Date(self.epochMillis + self.zone.offset)
|
|
573
|
+
} else if (self.adjustedEpochMillis !== undefined) {
|
|
574
|
+
return new Date(self.adjustedEpochMillis)
|
|
575
|
+
}
|
|
576
|
+
const parts = self.zone.format.formatToParts(self.epochMillis).filter((_) => _.type !== "literal")
|
|
577
|
+
const date = new Date(0)
|
|
578
|
+
date.setUTCFullYear(
|
|
579
|
+
Number(parts[2].value),
|
|
580
|
+
Number(parts[0].value) - 1,
|
|
581
|
+
Number(parts[1].value)
|
|
582
|
+
)
|
|
583
|
+
date.setUTCHours(
|
|
584
|
+
Number(parts[3].value),
|
|
585
|
+
Number(parts[4].value),
|
|
586
|
+
Number(parts[5].value),
|
|
587
|
+
Number(parts[6].value)
|
|
588
|
+
)
|
|
589
|
+
self.adjustedEpochMillis = date.getTime()
|
|
590
|
+
return date
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/** @internal */
|
|
594
|
+
export const zonedOffset = (self: DateTime.Zoned): number => {
|
|
595
|
+
const date = toDate(self)
|
|
596
|
+
return date.getTime() - toEpochMillis(self)
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
const offsetToString = (offset: number): string => {
|
|
600
|
+
const abs = Math.abs(offset)
|
|
601
|
+
let hours = Math.floor(abs / (60 * 60 * 1000))
|
|
602
|
+
let minutes = Math.round((abs % (60 * 60 * 1000)) / (60 * 1000))
|
|
603
|
+
if (minutes === 60) {
|
|
604
|
+
hours += 1
|
|
605
|
+
minutes = 0
|
|
606
|
+
}
|
|
607
|
+
return `${offset < 0 ? "-" : "+"}${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/** @internal */
|
|
611
|
+
export const zonedOffsetIso = (self: DateTime.Zoned): string => offsetToString(zonedOffset(self))
|
|
612
|
+
|
|
613
|
+
/** @internal */
|
|
614
|
+
export const toEpochMillis = (self: DateTime.DateTime): number => self.epochMillis
|
|
615
|
+
|
|
616
|
+
/** @internal */
|
|
617
|
+
export const removeTime = (self: DateTime.DateTime): DateTime.Utc =>
|
|
618
|
+
withDate(self, (date) => {
|
|
619
|
+
date.setUTCHours(0, 0, 0, 0)
|
|
620
|
+
return makeUtc(date.getTime())
|
|
621
|
+
})
|
|
622
|
+
|
|
623
|
+
// =============================================================================
|
|
624
|
+
// parts
|
|
625
|
+
// =============================================================================
|
|
626
|
+
|
|
627
|
+
const dateToParts = (date: Date): DateTime.DateTime.PartsWithWeekday => ({
|
|
628
|
+
millis: date.getUTCMilliseconds(),
|
|
629
|
+
seconds: date.getUTCSeconds(),
|
|
630
|
+
minutes: date.getUTCMinutes(),
|
|
631
|
+
hours: date.getUTCHours(),
|
|
632
|
+
day: date.getUTCDate(),
|
|
633
|
+
weekDay: date.getUTCDay(),
|
|
634
|
+
month: date.getUTCMonth() + 1,
|
|
635
|
+
year: date.getUTCFullYear()
|
|
636
|
+
})
|
|
637
|
+
|
|
638
|
+
/** @internal */
|
|
639
|
+
export const toParts = (self: DateTime.DateTime): DateTime.DateTime.PartsWithWeekday => {
|
|
640
|
+
if (self._tag === "Utc") {
|
|
641
|
+
return toPartsUtc(self)
|
|
642
|
+
} else if (self.partsAdjusted !== undefined) {
|
|
643
|
+
return self.partsAdjusted
|
|
644
|
+
}
|
|
645
|
+
self.partsAdjusted = withDate(self, dateToParts)
|
|
646
|
+
return self.partsAdjusted
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/** @internal */
|
|
650
|
+
export const toPartsUtc = (self: DateTime.DateTime): DateTime.DateTime.PartsWithWeekday => {
|
|
651
|
+
if (self.partsUtc !== undefined) {
|
|
652
|
+
return self.partsUtc
|
|
653
|
+
}
|
|
654
|
+
self.partsUtc = withDateUtc(self, dateToParts)
|
|
655
|
+
return self.partsUtc
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/** @internal */
|
|
659
|
+
export const getPartUtc: {
|
|
660
|
+
(part: keyof DateTime.DateTime.PartsWithWeekday): (self: DateTime.DateTime) => number
|
|
661
|
+
(self: DateTime.DateTime, part: keyof DateTime.DateTime.PartsWithWeekday): number
|
|
662
|
+
} = dual(2, (self: DateTime.DateTime, part: keyof DateTime.DateTime.PartsWithWeekday): number => toPartsUtc(self)[part])
|
|
663
|
+
|
|
664
|
+
/** @internal */
|
|
665
|
+
export const getPart: {
|
|
666
|
+
(part: keyof DateTime.DateTime.PartsWithWeekday): (self: DateTime.DateTime) => number
|
|
667
|
+
(self: DateTime.DateTime, part: keyof DateTime.DateTime.PartsWithWeekday): number
|
|
668
|
+
} = dual(2, (self: DateTime.DateTime, part: keyof DateTime.DateTime.PartsWithWeekday): number => toParts(self)[part])
|
|
669
|
+
|
|
670
|
+
const setPartsDate = (date: Date, parts: Partial<DateTime.DateTime.PartsWithWeekday>): void => {
|
|
671
|
+
if (parts.year !== undefined) {
|
|
672
|
+
date.setUTCFullYear(parts.year)
|
|
673
|
+
}
|
|
674
|
+
if (parts.month !== undefined) {
|
|
675
|
+
date.setUTCMonth(parts.month - 1)
|
|
676
|
+
}
|
|
677
|
+
if (parts.day !== undefined) {
|
|
678
|
+
date.setUTCDate(parts.day)
|
|
679
|
+
}
|
|
680
|
+
if (parts.weekDay !== undefined) {
|
|
681
|
+
const diff = parts.weekDay - date.getUTCDay()
|
|
682
|
+
date.setUTCDate(date.getUTCDate() + diff)
|
|
683
|
+
}
|
|
684
|
+
if (parts.hours !== undefined) {
|
|
685
|
+
date.setUTCHours(parts.hours)
|
|
686
|
+
}
|
|
687
|
+
if (parts.minutes !== undefined) {
|
|
688
|
+
date.setUTCMinutes(parts.minutes)
|
|
689
|
+
}
|
|
690
|
+
if (parts.seconds !== undefined) {
|
|
691
|
+
date.setUTCSeconds(parts.seconds)
|
|
692
|
+
}
|
|
693
|
+
if (parts.millis !== undefined) {
|
|
694
|
+
date.setUTCMilliseconds(parts.millis)
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/** @internal */
|
|
699
|
+
export const setParts: {
|
|
700
|
+
(
|
|
701
|
+
parts: Partial<DateTime.DateTime.PartsWithWeekday>
|
|
702
|
+
): <A extends DateTime.DateTime>(self: A) => A
|
|
703
|
+
<A extends DateTime.DateTime>(
|
|
704
|
+
self: A,
|
|
705
|
+
parts: Partial<DateTime.DateTime.PartsWithWeekday>
|
|
706
|
+
): A
|
|
707
|
+
} = dual(
|
|
708
|
+
2,
|
|
709
|
+
(self: DateTime.DateTime, parts: Partial<DateTime.DateTime.PartsWithWeekday>): DateTime.DateTime =>
|
|
710
|
+
mutate(self, (date) => setPartsDate(date, parts))
|
|
711
|
+
)
|
|
712
|
+
|
|
713
|
+
/** @internal */
|
|
714
|
+
export const setPartsUtc: {
|
|
715
|
+
(
|
|
716
|
+
parts: Partial<DateTime.DateTime.PartsWithWeekday>
|
|
717
|
+
): <A extends DateTime.DateTime>(self: A) => A
|
|
718
|
+
<A extends DateTime.DateTime>(
|
|
719
|
+
self: A,
|
|
720
|
+
parts: Partial<DateTime.DateTime.PartsWithWeekday>
|
|
721
|
+
): A
|
|
722
|
+
} = dual(
|
|
723
|
+
2,
|
|
724
|
+
(self: DateTime.DateTime, parts: Partial<DateTime.DateTime.PartsWithWeekday>): DateTime.DateTime =>
|
|
725
|
+
mutateUtc(self, (date) => setPartsDate(date, parts))
|
|
726
|
+
)
|
|
727
|
+
|
|
728
|
+
// =============================================================================
|
|
729
|
+
// mapping
|
|
730
|
+
// =============================================================================
|
|
731
|
+
|
|
732
|
+
const constDayMillis = 24 * 60 * 60 * 1000
|
|
733
|
+
|
|
734
|
+
const makeZonedFromAdjusted = (
|
|
735
|
+
adjustedMillis: number,
|
|
736
|
+
zone: DateTime.TimeZone,
|
|
737
|
+
disambiguation: DateTime.Disambiguation
|
|
738
|
+
): DateTime.Zoned => {
|
|
739
|
+
if (zone._tag === "Offset") {
|
|
740
|
+
return makeZonedProto(adjustedMillis - zone.offset, zone)
|
|
741
|
+
}
|
|
742
|
+
const beforeOffset = calculateNamedOffset(
|
|
743
|
+
adjustedMillis - constDayMillis,
|
|
744
|
+
adjustedMillis,
|
|
745
|
+
zone
|
|
746
|
+
)
|
|
747
|
+
const afterOffset = calculateNamedOffset(
|
|
748
|
+
adjustedMillis + constDayMillis,
|
|
749
|
+
adjustedMillis,
|
|
750
|
+
zone
|
|
751
|
+
)
|
|
752
|
+
// If there is no transition, we can return early
|
|
753
|
+
if (beforeOffset === afterOffset) {
|
|
754
|
+
return makeZonedProto(adjustedMillis - beforeOffset, zone)
|
|
755
|
+
}
|
|
756
|
+
const isForwards = beforeOffset < afterOffset
|
|
757
|
+
const transitionMillis = beforeOffset - afterOffset
|
|
758
|
+
// If the transition is forwards, we only need to check if we should move the
|
|
759
|
+
// local wall clock time forward if it is inside the gap
|
|
760
|
+
if (isForwards) {
|
|
761
|
+
const currentAfterOffset = calculateNamedOffset(
|
|
762
|
+
adjustedMillis - afterOffset,
|
|
763
|
+
adjustedMillis,
|
|
764
|
+
zone
|
|
765
|
+
)
|
|
766
|
+
if (currentAfterOffset === afterOffset) {
|
|
767
|
+
return makeZonedProto(adjustedMillis - afterOffset, zone)
|
|
768
|
+
}
|
|
769
|
+
const before = makeZonedProto(adjustedMillis - beforeOffset, zone)
|
|
770
|
+
const beforeAdjustedMillis = toDate(before).getTime()
|
|
771
|
+
// If the wall clock time has changed, we are inside the gap
|
|
772
|
+
if (adjustedMillis !== beforeAdjustedMillis) {
|
|
773
|
+
switch (disambiguation) {
|
|
774
|
+
case "reject": {
|
|
775
|
+
const formatted = new Date(adjustedMillis).toISOString()
|
|
776
|
+
throw new RangeError(`Gap time: ${formatted} does not exist in time zone ${zone.id}`)
|
|
777
|
+
}
|
|
778
|
+
case "earlier":
|
|
779
|
+
return makeZonedProto(adjustedMillis - afterOffset, zone)
|
|
780
|
+
|
|
781
|
+
case "compatible":
|
|
782
|
+
case "later":
|
|
783
|
+
return before
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
// The wall clock time is in the earlier offset, so we use that
|
|
787
|
+
return before
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
const currentBeforeOffset = calculateNamedOffset(
|
|
791
|
+
adjustedMillis - beforeOffset,
|
|
792
|
+
adjustedMillis,
|
|
793
|
+
zone
|
|
794
|
+
)
|
|
795
|
+
// The wall clock time is in the earlier offset, so we use that
|
|
796
|
+
if (currentBeforeOffset === beforeOffset) {
|
|
797
|
+
if (disambiguation === "earlier" || disambiguation === "compatible") {
|
|
798
|
+
return makeZonedProto(adjustedMillis - beforeOffset, zone)
|
|
799
|
+
}
|
|
800
|
+
const laterOffset = calculateNamedOffset(
|
|
801
|
+
adjustedMillis - beforeOffset + transitionMillis,
|
|
802
|
+
adjustedMillis + transitionMillis,
|
|
803
|
+
zone
|
|
804
|
+
)
|
|
805
|
+
if (laterOffset === beforeOffset) {
|
|
806
|
+
return makeZonedProto(adjustedMillis - beforeOffset, zone)
|
|
807
|
+
}
|
|
808
|
+
// If the offset changed in this period, then we are inside the period where
|
|
809
|
+
// the wall clock time occurs twice, once in the earlier offset and once in
|
|
810
|
+
// the later offset.
|
|
811
|
+
if (disambiguation === "reject") {
|
|
812
|
+
const formatted = new Date(adjustedMillis).toISOString()
|
|
813
|
+
throw new RangeError(`Ambiguous time: ${formatted} occurs twice in time zone ${zone.id}`)
|
|
814
|
+
}
|
|
815
|
+
// If the disambiguation is "later", we return the later offset below
|
|
816
|
+
}
|
|
817
|
+
return makeZonedProto(adjustedMillis - afterOffset, zone)
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
const offsetRegex = /([+-])(\d{2}):(\d{2})$/
|
|
821
|
+
const parseOffset = (offset: string): number | null => {
|
|
822
|
+
const match = offsetRegex.exec(offset)
|
|
823
|
+
if (match === null) {
|
|
824
|
+
return null
|
|
825
|
+
}
|
|
826
|
+
const [, sign, hours, minutes] = match
|
|
827
|
+
return (sign === "+" ? 1 : -1) * (Number(hours) * 60 + Number(minutes)) * 60 * 1000
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
const calculateNamedOffset = (
|
|
831
|
+
utcMillis: number,
|
|
832
|
+
adjustedMillis: number,
|
|
833
|
+
zone: DateTime.TimeZone.Named
|
|
834
|
+
): number => {
|
|
835
|
+
const offset = zone.format.formatToParts(utcMillis).find((_) => _.type === "timeZoneName")?.value ?? ""
|
|
836
|
+
if (offset === "GMT") {
|
|
837
|
+
return 0
|
|
838
|
+
}
|
|
839
|
+
const result = parseOffset(offset)
|
|
840
|
+
if (result === null) {
|
|
841
|
+
// fallback to using the adjusted date
|
|
842
|
+
return zonedOffset(makeZonedProto(adjustedMillis, zone))
|
|
843
|
+
}
|
|
844
|
+
return result
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/** @internal */
|
|
848
|
+
export const mutate: {
|
|
849
|
+
(f: (date: Date) => void, options?: {
|
|
850
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
851
|
+
}): <A extends DateTime.DateTime>(self: A) => A
|
|
852
|
+
<A extends DateTime.DateTime>(self: A, f: (date: Date) => void, options?: {
|
|
853
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
854
|
+
}): A
|
|
855
|
+
} = dual(isDateTimeArgs, (self: DateTime.DateTime, f: (date: Date) => void, options?: {
|
|
856
|
+
readonly disambiguation?: DateTime.Disambiguation | undefined
|
|
857
|
+
}): DateTime.DateTime => {
|
|
858
|
+
if (self._tag === "Utc") {
|
|
859
|
+
const date = toDateUtc(self)
|
|
860
|
+
f(date)
|
|
861
|
+
return makeUtc(date.getTime())
|
|
862
|
+
}
|
|
863
|
+
const adjustedDate = toDate(self)
|
|
864
|
+
const newAdjustedDate = new Date(adjustedDate.getTime())
|
|
865
|
+
f(newAdjustedDate)
|
|
866
|
+
return makeZonedFromAdjusted(newAdjustedDate.getTime(), self.zone, options?.disambiguation ?? "compatible")
|
|
867
|
+
})
|
|
868
|
+
|
|
869
|
+
/** @internal */
|
|
870
|
+
export const mutateUtc: {
|
|
871
|
+
(f: (date: Date) => void): <A extends DateTime.DateTime>(self: A) => A
|
|
872
|
+
<A extends DateTime.DateTime>(self: A, f: (date: Date) => void): A
|
|
873
|
+
} = dual(2, (self: DateTime.DateTime, f: (date: Date) => void): DateTime.DateTime =>
|
|
874
|
+
mapEpochMillis(self, (millis) => {
|
|
875
|
+
const date = new Date(millis)
|
|
876
|
+
f(date)
|
|
877
|
+
return date.getTime()
|
|
878
|
+
}))
|
|
879
|
+
|
|
880
|
+
/** @internal */
|
|
881
|
+
export const mapEpochMillis: {
|
|
882
|
+
(f: (millis: number) => number): <A extends DateTime.DateTime>(self: A) => A
|
|
883
|
+
<A extends DateTime.DateTime>(self: A, f: (millis: number) => number): A
|
|
884
|
+
} = dual(2, (self: DateTime.DateTime, f: (millis: number) => number): DateTime.DateTime => {
|
|
885
|
+
const millis = f(toEpochMillis(self))
|
|
886
|
+
return self._tag === "Utc" ? makeUtc(millis) : makeZonedProto(millis, self.zone)
|
|
887
|
+
})
|
|
888
|
+
|
|
889
|
+
/** @internal */
|
|
890
|
+
export const withDate: {
|
|
891
|
+
<A>(f: (date: Date) => A): (self: DateTime.DateTime) => A
|
|
892
|
+
<A>(self: DateTime.DateTime, f: (date: Date) => A): A
|
|
893
|
+
} = dual(2, <A>(self: DateTime.DateTime, f: (date: Date) => A): A => f(toDate(self)))
|
|
894
|
+
|
|
895
|
+
/** @internal */
|
|
896
|
+
export const withDateUtc: {
|
|
897
|
+
<A>(f: (date: Date) => A): (self: DateTime.DateTime) => A
|
|
898
|
+
<A>(self: DateTime.DateTime, f: (date: Date) => A): A
|
|
899
|
+
} = dual(2, <A>(self: DateTime.DateTime, f: (date: Date) => A): A => f(toDateUtc(self)))
|
|
900
|
+
|
|
901
|
+
/** @internal */
|
|
902
|
+
export const match: {
|
|
903
|
+
<A, B>(options: {
|
|
904
|
+
readonly onUtc: (_: DateTime.Utc) => A
|
|
905
|
+
readonly onZoned: (_: DateTime.Zoned) => B
|
|
906
|
+
}): (self: DateTime.DateTime) => A | B
|
|
907
|
+
<A, B>(self: DateTime.DateTime, options: {
|
|
908
|
+
readonly onUtc: (_: DateTime.Utc) => A
|
|
909
|
+
readonly onZoned: (_: DateTime.Zoned) => B
|
|
910
|
+
}): A | B
|
|
911
|
+
} = dual(2, <A, B>(self: DateTime.DateTime, options: {
|
|
912
|
+
readonly onUtc: (_: DateTime.Utc) => A
|
|
913
|
+
readonly onZoned: (_: DateTime.Zoned) => B
|
|
914
|
+
}): A | B => self._tag === "Utc" ? options.onUtc(self) : options.onZoned(self))
|
|
915
|
+
|
|
916
|
+
// =============================================================================
|
|
917
|
+
// math
|
|
918
|
+
// =============================================================================
|
|
919
|
+
|
|
920
|
+
/** @internal */
|
|
921
|
+
export const addDuration: {
|
|
922
|
+
(duration: Duration.DurationInput): <A extends DateTime.DateTime>(self: A) => A
|
|
923
|
+
<A extends DateTime.DateTime>(self: A, duration: Duration.DurationInput): A
|
|
924
|
+
} = dual(
|
|
925
|
+
2,
|
|
926
|
+
(self: DateTime.DateTime, duration: Duration.DurationInput): DateTime.DateTime =>
|
|
927
|
+
mapEpochMillis(self, (millis) => millis + Duration.toMillis(duration))
|
|
928
|
+
)
|
|
929
|
+
|
|
930
|
+
/** @internal */
|
|
931
|
+
export const subtractDuration: {
|
|
932
|
+
(duration: Duration.DurationInput): <A extends DateTime.DateTime>(self: A) => A
|
|
933
|
+
<A extends DateTime.DateTime>(self: A, duration: Duration.DurationInput): A
|
|
934
|
+
} = dual(
|
|
935
|
+
2,
|
|
936
|
+
(self: DateTime.DateTime, duration: Duration.DurationInput): DateTime.DateTime =>
|
|
937
|
+
mapEpochMillis(self, (millis) => millis - Duration.toMillis(duration))
|
|
938
|
+
)
|
|
939
|
+
|
|
940
|
+
const addMillis = (date: Date, amount: number): void => {
|
|
941
|
+
date.setTime(date.getTime() + amount)
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/** @internal */
|
|
945
|
+
export const add: {
|
|
946
|
+
(
|
|
947
|
+
parts: Partial<DateTime.DateTime.PartsForMath>
|
|
948
|
+
): <A extends DateTime.DateTime>(self: A) => A
|
|
949
|
+
<A extends DateTime.DateTime>(
|
|
950
|
+
self: A,
|
|
951
|
+
parts: Partial<DateTime.DateTime.PartsForMath>
|
|
952
|
+
): A
|
|
953
|
+
} = dual(
|
|
954
|
+
2,
|
|
955
|
+
(self: DateTime.DateTime, parts: Partial<DateTime.DateTime.PartsForMath>): DateTime.DateTime =>
|
|
956
|
+
mutate(self, (date) => {
|
|
957
|
+
if (parts.millis) {
|
|
958
|
+
addMillis(date, parts.millis)
|
|
959
|
+
}
|
|
960
|
+
if (parts.seconds) {
|
|
961
|
+
addMillis(date, parts.seconds * 1000)
|
|
962
|
+
}
|
|
963
|
+
if (parts.minutes) {
|
|
964
|
+
addMillis(date, parts.minutes * 60 * 1000)
|
|
965
|
+
}
|
|
966
|
+
if (parts.hours) {
|
|
967
|
+
addMillis(date, parts.hours * 60 * 60 * 1000)
|
|
968
|
+
}
|
|
969
|
+
if (parts.days) {
|
|
970
|
+
date.setUTCDate(date.getUTCDate() + parts.days)
|
|
971
|
+
}
|
|
972
|
+
if (parts.weeks) {
|
|
973
|
+
date.setUTCDate(date.getUTCDate() + parts.weeks * 7)
|
|
974
|
+
}
|
|
975
|
+
if (parts.months) {
|
|
976
|
+
const day = date.getUTCDate()
|
|
977
|
+
date.setUTCMonth(date.getUTCMonth() + parts.months + 1, 0)
|
|
978
|
+
if (day < date.getUTCDate()) {
|
|
979
|
+
date.setUTCDate(day)
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
if (parts.years) {
|
|
983
|
+
const day = date.getUTCDate()
|
|
984
|
+
const month = date.getUTCMonth()
|
|
985
|
+
date.setUTCFullYear(
|
|
986
|
+
date.getUTCFullYear() + parts.years,
|
|
987
|
+
month + 1,
|
|
988
|
+
0
|
|
989
|
+
)
|
|
990
|
+
if (day < date.getUTCDate()) {
|
|
991
|
+
date.setUTCDate(day)
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
})
|
|
995
|
+
)
|
|
996
|
+
|
|
997
|
+
/** @internal */
|
|
998
|
+
export const subtract: {
|
|
999
|
+
(
|
|
1000
|
+
parts: Partial<DateTime.DateTime.PartsForMath>
|
|
1001
|
+
): <A extends DateTime.DateTime>(self: A) => A
|
|
1002
|
+
<A extends DateTime.DateTime>(
|
|
1003
|
+
self: A,
|
|
1004
|
+
parts: Partial<DateTime.DateTime.PartsForMath>
|
|
1005
|
+
): A
|
|
1006
|
+
} = dual(2, (self: DateTime.DateTime, parts: Partial<DateTime.DateTime.PartsForMath>): DateTime.DateTime => {
|
|
1007
|
+
const newParts = {} as Partial<Mutable<DateTime.DateTime.PartsForMath>>
|
|
1008
|
+
for (const key in parts) {
|
|
1009
|
+
newParts[key as keyof DateTime.DateTime.PartsForMath] = -1 * parts[key as keyof DateTime.DateTime.PartsForMath]!
|
|
1010
|
+
}
|
|
1011
|
+
return add(self, newParts)
|
|
1012
|
+
})
|
|
1013
|
+
|
|
1014
|
+
const startOfDate = (date: Date, part: DateTime.DateTime.UnitSingular, options?: {
|
|
1015
|
+
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
1016
|
+
}) => {
|
|
1017
|
+
switch (part) {
|
|
1018
|
+
case "second": {
|
|
1019
|
+
date.setUTCMilliseconds(0)
|
|
1020
|
+
break
|
|
1021
|
+
}
|
|
1022
|
+
case "minute": {
|
|
1023
|
+
date.setUTCSeconds(0, 0)
|
|
1024
|
+
break
|
|
1025
|
+
}
|
|
1026
|
+
case "hour": {
|
|
1027
|
+
date.setUTCMinutes(0, 0, 0)
|
|
1028
|
+
break
|
|
1029
|
+
}
|
|
1030
|
+
case "day": {
|
|
1031
|
+
date.setUTCHours(0, 0, 0, 0)
|
|
1032
|
+
break
|
|
1033
|
+
}
|
|
1034
|
+
case "week": {
|
|
1035
|
+
const weekStartsOn = options?.weekStartsOn ?? 0
|
|
1036
|
+
const day = date.getUTCDay()
|
|
1037
|
+
const diff = (day - weekStartsOn + 7) % 7
|
|
1038
|
+
date.setUTCDate(date.getUTCDate() - diff)
|
|
1039
|
+
date.setUTCHours(0, 0, 0, 0)
|
|
1040
|
+
break
|
|
1041
|
+
}
|
|
1042
|
+
case "month": {
|
|
1043
|
+
date.setUTCDate(1)
|
|
1044
|
+
date.setUTCHours(0, 0, 0, 0)
|
|
1045
|
+
break
|
|
1046
|
+
}
|
|
1047
|
+
case "year": {
|
|
1048
|
+
date.setUTCMonth(0, 1)
|
|
1049
|
+
date.setUTCHours(0, 0, 0, 0)
|
|
1050
|
+
break
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/** @internal */
|
|
1056
|
+
export const startOf: {
|
|
1057
|
+
(part: DateTime.DateTime.UnitSingular, options?: {
|
|
1058
|
+
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
1059
|
+
}): <A extends DateTime.DateTime>(self: A) => A
|
|
1060
|
+
<A extends DateTime.DateTime>(self: A, part: DateTime.DateTime.UnitSingular, options?: {
|
|
1061
|
+
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
1062
|
+
}): A
|
|
1063
|
+
} = dual(isDateTimeArgs, (self: DateTime.DateTime, part: DateTime.DateTime.UnitSingular, options?: {
|
|
1064
|
+
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
1065
|
+
}): DateTime.DateTime => mutate(self, (date) => startOfDate(date, part, options)))
|
|
1066
|
+
|
|
1067
|
+
const endOfDate = (date: Date, part: DateTime.DateTime.UnitSingular, options?: {
|
|
1068
|
+
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
1069
|
+
}) => {
|
|
1070
|
+
switch (part) {
|
|
1071
|
+
case "second": {
|
|
1072
|
+
date.setUTCMilliseconds(999)
|
|
1073
|
+
break
|
|
1074
|
+
}
|
|
1075
|
+
case "minute": {
|
|
1076
|
+
date.setUTCSeconds(59, 999)
|
|
1077
|
+
break
|
|
1078
|
+
}
|
|
1079
|
+
case "hour": {
|
|
1080
|
+
date.setUTCMinutes(59, 59, 999)
|
|
1081
|
+
break
|
|
1082
|
+
}
|
|
1083
|
+
case "day": {
|
|
1084
|
+
date.setUTCHours(23, 59, 59, 999)
|
|
1085
|
+
break
|
|
1086
|
+
}
|
|
1087
|
+
case "week": {
|
|
1088
|
+
const weekStartsOn = options?.weekStartsOn ?? 0
|
|
1089
|
+
const day = date.getUTCDay()
|
|
1090
|
+
const diff = (day - weekStartsOn + 7) % 7
|
|
1091
|
+
date.setUTCDate(date.getUTCDate() - diff + 6)
|
|
1092
|
+
date.setUTCHours(23, 59, 59, 999)
|
|
1093
|
+
break
|
|
1094
|
+
}
|
|
1095
|
+
case "month": {
|
|
1096
|
+
date.setUTCMonth(date.getUTCMonth() + 1, 0)
|
|
1097
|
+
date.setUTCHours(23, 59, 59, 999)
|
|
1098
|
+
break
|
|
1099
|
+
}
|
|
1100
|
+
case "year": {
|
|
1101
|
+
date.setUTCMonth(11, 31)
|
|
1102
|
+
date.setUTCHours(23, 59, 59, 999)
|
|
1103
|
+
break
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
/** @internal */
|
|
1109
|
+
export const endOf: {
|
|
1110
|
+
(part: DateTime.DateTime.UnitSingular, options?: {
|
|
1111
|
+
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
1112
|
+
}): <A extends DateTime.DateTime>(self: A) => A
|
|
1113
|
+
<A extends DateTime.DateTime>(self: A, part: DateTime.DateTime.UnitSingular, options?: {
|
|
1114
|
+
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
1115
|
+
}): A
|
|
1116
|
+
} = dual(isDateTimeArgs, (self: DateTime.DateTime, part: DateTime.DateTime.UnitSingular, options?: {
|
|
1117
|
+
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
1118
|
+
}): DateTime.DateTime => mutate(self, (date) => endOfDate(date, part, options)))
|
|
1119
|
+
|
|
1120
|
+
/** @internal */
|
|
1121
|
+
export const nearest: {
|
|
1122
|
+
(part: DateTime.DateTime.UnitSingular, options?: {
|
|
1123
|
+
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
1124
|
+
}): <A extends DateTime.DateTime>(self: A) => A
|
|
1125
|
+
<A extends DateTime.DateTime>(self: A, part: DateTime.DateTime.UnitSingular, options?: {
|
|
1126
|
+
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
1127
|
+
}): A
|
|
1128
|
+
} = dual(isDateTimeArgs, (self: DateTime.DateTime, part: DateTime.DateTime.UnitSingular, options?: {
|
|
1129
|
+
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
1130
|
+
}): DateTime.DateTime =>
|
|
1131
|
+
mutate(self, (date) => {
|
|
1132
|
+
if (part === "milli") return
|
|
1133
|
+
const millis = date.getTime()
|
|
1134
|
+
const start = new Date(millis)
|
|
1135
|
+
startOfDate(start, part, options)
|
|
1136
|
+
const startMillis = start.getTime()
|
|
1137
|
+
const end = new Date(millis)
|
|
1138
|
+
endOfDate(end, part, options)
|
|
1139
|
+
const endMillis = end.getTime() + 1
|
|
1140
|
+
const diffStart = millis - startMillis
|
|
1141
|
+
const diffEnd = endMillis - millis
|
|
1142
|
+
if (diffStart < diffEnd) {
|
|
1143
|
+
date.setTime(startMillis)
|
|
1144
|
+
} else {
|
|
1145
|
+
date.setTime(endMillis)
|
|
1146
|
+
}
|
|
1147
|
+
}))
|
|
1148
|
+
|
|
1149
|
+
// =============================================================================
|
|
1150
|
+
// formatting
|
|
1151
|
+
// =============================================================================
|
|
1152
|
+
|
|
1153
|
+
const intlTimeZone = (self: DateTime.TimeZone): string => {
|
|
1154
|
+
if (self._tag === "Named") {
|
|
1155
|
+
return self.id
|
|
1156
|
+
}
|
|
1157
|
+
return offsetToString(self.offset)
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/** @internal */
|
|
1161
|
+
export const format: {
|
|
1162
|
+
(
|
|
1163
|
+
options?:
|
|
1164
|
+
| Intl.DateTimeFormatOptions & {
|
|
1165
|
+
readonly locale?: Intl.LocalesArgument
|
|
1166
|
+
}
|
|
1167
|
+
| undefined
|
|
1168
|
+
): (self: DateTime.DateTime) => string
|
|
1169
|
+
(
|
|
1170
|
+
self: DateTime.DateTime,
|
|
1171
|
+
options?:
|
|
1172
|
+
| Intl.DateTimeFormatOptions & {
|
|
1173
|
+
readonly locale?: Intl.LocalesArgument
|
|
1174
|
+
}
|
|
1175
|
+
| undefined
|
|
1176
|
+
): string
|
|
1177
|
+
} = dual(isDateTimeArgs, (
|
|
1178
|
+
self: DateTime.DateTime,
|
|
1179
|
+
options?:
|
|
1180
|
+
| Intl.DateTimeFormatOptions & {
|
|
1181
|
+
readonly locale?: Intl.LocalesArgument
|
|
1182
|
+
}
|
|
1183
|
+
| undefined
|
|
1184
|
+
): string => {
|
|
1185
|
+
try {
|
|
1186
|
+
return new Intl.DateTimeFormat(options?.locale, {
|
|
1187
|
+
timeZone: self._tag === "Utc" ? "UTC" : intlTimeZone(self.zone),
|
|
1188
|
+
...options
|
|
1189
|
+
}).format(self.epochMillis)
|
|
1190
|
+
} catch {
|
|
1191
|
+
return new Intl.DateTimeFormat(options?.locale, {
|
|
1192
|
+
timeZone: "UTC",
|
|
1193
|
+
...options
|
|
1194
|
+
}).format(toDate(self))
|
|
1195
|
+
}
|
|
1196
|
+
})
|
|
1197
|
+
|
|
1198
|
+
/** @internal */
|
|
1199
|
+
export const formatLocal: {
|
|
1200
|
+
(
|
|
1201
|
+
options?:
|
|
1202
|
+
| Intl.DateTimeFormatOptions & {
|
|
1203
|
+
readonly locale?: Intl.LocalesArgument
|
|
1204
|
+
}
|
|
1205
|
+
| undefined
|
|
1206
|
+
): (self: DateTime.DateTime) => string
|
|
1207
|
+
(
|
|
1208
|
+
self: DateTime.DateTime,
|
|
1209
|
+
options?:
|
|
1210
|
+
| Intl.DateTimeFormatOptions & {
|
|
1211
|
+
readonly locale?: Intl.LocalesArgument
|
|
1212
|
+
}
|
|
1213
|
+
| undefined
|
|
1214
|
+
): string
|
|
1215
|
+
} = dual(isDateTimeArgs, (
|
|
1216
|
+
self: DateTime.DateTime,
|
|
1217
|
+
options?:
|
|
1218
|
+
| Intl.DateTimeFormatOptions & {
|
|
1219
|
+
readonly locale?: Intl.LocalesArgument
|
|
1220
|
+
}
|
|
1221
|
+
| undefined
|
|
1222
|
+
): string => new Intl.DateTimeFormat(options?.locale, options).format(self.epochMillis))
|
|
1223
|
+
|
|
1224
|
+
/** @internal */
|
|
1225
|
+
export const formatUtc: {
|
|
1226
|
+
(
|
|
1227
|
+
options?:
|
|
1228
|
+
| Intl.DateTimeFormatOptions & {
|
|
1229
|
+
readonly locale?: Intl.LocalesArgument
|
|
1230
|
+
}
|
|
1231
|
+
| undefined
|
|
1232
|
+
): (self: DateTime.DateTime) => string
|
|
1233
|
+
(
|
|
1234
|
+
self: DateTime.DateTime,
|
|
1235
|
+
options?:
|
|
1236
|
+
| Intl.DateTimeFormatOptions & {
|
|
1237
|
+
readonly locale?: Intl.LocalesArgument
|
|
1238
|
+
}
|
|
1239
|
+
| undefined
|
|
1240
|
+
): string
|
|
1241
|
+
} = dual(isDateTimeArgs, (
|
|
1242
|
+
self: DateTime.DateTime,
|
|
1243
|
+
options?:
|
|
1244
|
+
| Intl.DateTimeFormatOptions & {
|
|
1245
|
+
readonly locale?: Intl.LocalesArgument
|
|
1246
|
+
}
|
|
1247
|
+
| undefined
|
|
1248
|
+
): string =>
|
|
1249
|
+
new Intl.DateTimeFormat(options?.locale, {
|
|
1250
|
+
...options,
|
|
1251
|
+
timeZone: "UTC"
|
|
1252
|
+
}).format(self.epochMillis))
|
|
1253
|
+
|
|
1254
|
+
/** @internal */
|
|
1255
|
+
export const formatIntl: {
|
|
1256
|
+
(format: Intl.DateTimeFormat): (self: DateTime.DateTime) => string
|
|
1257
|
+
(self: DateTime.DateTime, format: Intl.DateTimeFormat): string
|
|
1258
|
+
} = dual(2, (self: DateTime.DateTime, format: Intl.DateTimeFormat): string => format.format(self.epochMillis))
|
|
1259
|
+
|
|
1260
|
+
/** @internal */
|
|
1261
|
+
export const formatIso = (self: DateTime.DateTime): string => toDateUtc(self).toISOString()
|
|
1262
|
+
|
|
1263
|
+
/** @internal */
|
|
1264
|
+
export const formatIsoDate = (self: DateTime.DateTime): string => toDate(self).toISOString().slice(0, 10)
|
|
1265
|
+
|
|
1266
|
+
/** @internal */
|
|
1267
|
+
export const formatIsoDateUtc = (self: DateTime.DateTime): string => toDateUtc(self).toISOString().slice(0, 10)
|
|
1268
|
+
|
|
1269
|
+
/** @internal */
|
|
1270
|
+
export const formatIsoOffset = (self: DateTime.DateTime): string => {
|
|
1271
|
+
const date = toDate(self)
|
|
1272
|
+
return self._tag === "Utc" ? date.toISOString() : `${date.toISOString().slice(0, -1)}${zonedOffsetIso(self)}`
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
/** @internal */
|
|
1276
|
+
export const formatIsoZoned = (self: DateTime.Zoned): string =>
|
|
1277
|
+
self.zone._tag === "Offset" ? formatIsoOffset(self) : `${formatIsoOffset(self)}[${self.zone.id}]`
|