effect 3.10.18 → 3.11.0
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/dist/cjs/Array.js +206 -0
- package/dist/cjs/Array.js.map +1 -1
- package/dist/cjs/BigDecimal.js +181 -24
- package/dist/cjs/BigDecimal.js.map +1 -1
- package/dist/cjs/BigInt.js +54 -0
- package/dist/cjs/BigInt.js.map +1 -1
- package/dist/cjs/Boolean.js +24 -0
- package/dist/cjs/Boolean.js.map +1 -1
- package/dist/cjs/Brand.js +4 -0
- package/dist/cjs/Brand.js.map +1 -1
- package/dist/cjs/Channel.js +44 -4
- package/dist/cjs/Channel.js.map +1 -1
- package/dist/cjs/Chunk.js +8 -0
- package/dist/cjs/Chunk.js.map +1 -1
- package/dist/cjs/Config.js +10 -1
- package/dist/cjs/Config.js.map +1 -1
- package/dist/cjs/Context.js +50 -1
- package/dist/cjs/Context.js.map +1 -1
- package/dist/cjs/Cron.js +81 -67
- package/dist/cjs/Cron.js.map +1 -1
- package/dist/cjs/Data.js +14 -0
- package/dist/cjs/Data.js.map +1 -1
- package/dist/cjs/DateTime.js +178 -664
- package/dist/cjs/DateTime.js.map +1 -1
- package/dist/cjs/Duration.js +2 -0
- package/dist/cjs/Duration.js.map +1 -1
- package/dist/cjs/Effect.js +296 -4
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/Either.js +38 -2
- package/dist/cjs/Either.js.map +1 -1
- package/dist/cjs/FiberHandle.js +6 -0
- package/dist/cjs/FiberHandle.js.map +1 -1
- package/dist/cjs/FiberMap.js +6 -0
- package/dist/cjs/FiberMap.js.map +1 -1
- package/dist/cjs/FiberSet.js +6 -0
- package/dist/cjs/FiberSet.js.map +1 -1
- package/dist/cjs/Function.js +34 -0
- package/dist/cjs/Function.js.map +1 -1
- package/dist/cjs/GlobalValue.js +2 -0
- package/dist/cjs/GlobalValue.js.map +1 -1
- package/dist/cjs/HashMap.js.map +1 -1
- package/dist/cjs/Inspectable.js +8 -4
- package/dist/cjs/Inspectable.js.map +1 -1
- package/dist/cjs/Iterable.js +18 -0
- package/dist/cjs/Iterable.js.map +1 -1
- package/dist/cjs/JSONSchema.js.map +1 -1
- package/dist/cjs/List.js +4 -0
- package/dist/cjs/List.js.map +1 -1
- package/dist/cjs/Logger.js +26 -0
- package/dist/cjs/Logger.js.map +1 -1
- package/dist/cjs/Mailbox.js +2 -0
- package/dist/cjs/Mailbox.js.map +1 -1
- package/dist/cjs/ManagedRuntime.js +2 -0
- package/dist/cjs/ManagedRuntime.js.map +1 -1
- package/dist/cjs/Metric.js +10 -0
- package/dist/cjs/Metric.js.map +1 -1
- package/dist/cjs/Micro.js +1104 -1069
- package/dist/cjs/Micro.js.map +1 -1
- package/dist/cjs/Number.js +44 -0
- package/dist/cjs/Number.js.map +1 -1
- package/dist/cjs/Option.js +70 -0
- package/dist/cjs/Option.js.map +1 -1
- package/dist/cjs/Order.js +2 -0
- package/dist/cjs/Order.js.map +1 -1
- package/dist/cjs/Ordering.js +4 -0
- package/dist/cjs/Ordering.js.map +1 -1
- package/dist/cjs/Predicate.js +68 -0
- package/dist/cjs/Predicate.js.map +1 -1
- package/dist/cjs/Random.js +4 -0
- package/dist/cjs/Random.js.map +1 -1
- package/dist/cjs/RateLimiter.js +4 -0
- package/dist/cjs/RateLimiter.js.map +1 -1
- package/dist/cjs/RcMap.js +2 -0
- package/dist/cjs/RcMap.js.map +1 -1
- package/dist/cjs/RcRef.js +2 -0
- package/dist/cjs/RcRef.js.map +1 -1
- package/dist/cjs/Record.js +56 -0
- package/dist/cjs/Record.js.map +1 -1
- package/dist/cjs/Redacted.js +8 -0
- package/dist/cjs/Redacted.js.map +1 -1
- package/dist/cjs/RegExp.js +4 -0
- package/dist/cjs/RegExp.js.map +1 -1
- package/dist/cjs/Request.js +4 -0
- package/dist/cjs/Request.js.map +1 -1
- package/dist/cjs/RequestResolver.js +2 -0
- package/dist/cjs/RequestResolver.js.map +1 -1
- package/dist/cjs/Runtime.js +6 -0
- package/dist/cjs/Runtime.js.map +1 -1
- package/dist/cjs/STM.js.map +1 -1
- package/dist/cjs/Schema.js +91 -8
- package/dist/cjs/Schema.js.map +1 -1
- package/dist/cjs/Sink.js +9 -1
- package/dist/cjs/Sink.js.map +1 -1
- package/dist/cjs/Stream.js +179 -7
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/String.js +62 -0
- package/dist/cjs/String.js.map +1 -1
- package/dist/cjs/Struct.js +12 -0
- package/dist/cjs/Struct.js.map +1 -1
- package/dist/cjs/Symbol.js +2 -0
- package/dist/cjs/Symbol.js.map +1 -1
- package/dist/cjs/Trie.js +56 -0
- package/dist/cjs/Trie.js.map +1 -1
- package/dist/cjs/Tuple.js +18 -0
- package/dist/cjs/Tuple.js.map +1 -1
- package/dist/cjs/Utils.js +7 -1
- package/dist/cjs/Utils.js.map +1 -1
- package/dist/cjs/internal/channel/channelExecutor.js +5 -9
- package/dist/cjs/internal/channel/channelExecutor.js.map +1 -1
- package/dist/cjs/internal/channel.js +156 -130
- package/dist/cjs/internal/channel.js.map +1 -1
- package/dist/cjs/internal/config.js +13 -4
- package/dist/cjs/internal/config.js.map +1 -1
- package/dist/cjs/internal/context.js +46 -3
- package/dist/cjs/internal/context.js.map +1 -1
- package/dist/cjs/internal/dateTime.js +747 -0
- package/dist/cjs/internal/dateTime.js.map +1 -0
- package/dist/cjs/internal/fiberRuntime.js +34 -11
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/groupBy.js +9 -3
- package/dist/cjs/internal/groupBy.js.map +1 -1
- package/dist/cjs/internal/layer.js +1 -1
- package/dist/cjs/internal/layer.js.map +1 -1
- package/dist/cjs/internal/mailbox.js +1 -1
- package/dist/cjs/internal/mailbox.js.map +1 -1
- package/dist/cjs/internal/sink.js +25 -21
- package/dist/cjs/internal/sink.js.map +1 -1
- package/dist/cjs/internal/stream.js +70 -71
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/cjs/internal/version.js.map +1 -1
- package/dist/dts/Array.d.ts +534 -0
- package/dist/dts/Array.d.ts.map +1 -1
- package/dist/dts/BigDecimal.d.ts +172 -1
- package/dist/dts/BigDecimal.d.ts.map +1 -1
- package/dist/dts/BigInt.d.ts +114 -0
- package/dist/dts/BigInt.d.ts.map +1 -1
- package/dist/dts/Boolean.d.ts +56 -0
- package/dist/dts/Boolean.d.ts.map +1 -1
- package/dist/dts/Brand.d.ts +6 -0
- package/dist/dts/Brand.d.ts.map +1 -1
- package/dist/dts/Channel.d.ts +66 -5
- package/dist/dts/Channel.d.ts.map +1 -1
- package/dist/dts/Chunk.d.ts +30 -0
- package/dist/dts/Chunk.d.ts.map +1 -1
- package/dist/dts/Config.d.ts +25 -1
- package/dist/dts/Config.d.ts.map +1 -1
- package/dist/dts/Context.d.ts +155 -0
- package/dist/dts/Context.d.ts.map +1 -1
- package/dist/dts/Cron.d.ts +21 -6
- package/dist/dts/Cron.d.ts.map +1 -1
- package/dist/dts/Data.d.ts +26 -0
- package/dist/dts/Data.d.ts.map +1 -1
- package/dist/dts/DateTime.d.ts +192 -49
- package/dist/dts/DateTime.d.ts.map +1 -1
- package/dist/dts/Duration.d.ts +2 -0
- package/dist/dts/Duration.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +658 -1
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/Either.d.ts +84 -2
- package/dist/dts/Either.d.ts.map +1 -1
- package/dist/dts/FiberHandle.d.ts +6 -0
- package/dist/dts/FiberHandle.d.ts.map +1 -1
- package/dist/dts/FiberMap.d.ts +6 -0
- package/dist/dts/FiberMap.d.ts.map +1 -1
- package/dist/dts/FiberSet.d.ts +6 -0
- package/dist/dts/FiberSet.d.ts.map +1 -1
- package/dist/dts/Function.d.ts +50 -0
- package/dist/dts/Function.d.ts.map +1 -1
- package/dist/dts/GlobalValue.d.ts +2 -0
- package/dist/dts/GlobalValue.d.ts.map +1 -1
- package/dist/dts/HashMap.d.ts +6 -0
- package/dist/dts/HashMap.d.ts.map +1 -1
- package/dist/dts/Inspectable.d.ts.map +1 -1
- package/dist/dts/Iterable.d.ts +26 -0
- package/dist/dts/Iterable.d.ts.map +1 -1
- package/dist/dts/JSONSchema.d.ts +1 -0
- package/dist/dts/JSONSchema.d.ts.map +1 -1
- package/dist/dts/List.d.ts +20 -0
- package/dist/dts/List.d.ts.map +1 -1
- package/dist/dts/Logger.d.ts +34 -0
- package/dist/dts/Logger.d.ts.map +1 -1
- package/dist/dts/Mailbox.d.ts +2 -0
- package/dist/dts/Mailbox.d.ts.map +1 -1
- package/dist/dts/ManagedRuntime.d.ts +2 -0
- package/dist/dts/ManagedRuntime.d.ts.map +1 -1
- package/dist/dts/Metric.d.ts +18 -0
- package/dist/dts/Metric.d.ts.map +1 -1
- package/dist/dts/Micro.d.ts +880 -863
- package/dist/dts/Micro.d.ts.map +1 -1
- package/dist/dts/Number.d.ts +104 -0
- package/dist/dts/Number.d.ts.map +1 -1
- package/dist/dts/Option.d.ts +142 -0
- package/dist/dts/Option.d.ts.map +1 -1
- package/dist/dts/Order.d.ts +2 -0
- package/dist/dts/Order.d.ts.map +1 -1
- package/dist/dts/Ordering.d.ts +8 -0
- package/dist/dts/Ordering.d.ts.map +1 -1
- package/dist/dts/Predicate.d.ts +104 -0
- package/dist/dts/Predicate.d.ts.map +1 -1
- package/dist/dts/Random.d.ts +4 -0
- package/dist/dts/Random.d.ts.map +1 -1
- package/dist/dts/RateLimiter.d.ts +4 -0
- package/dist/dts/RateLimiter.d.ts.map +1 -1
- package/dist/dts/RcMap.d.ts +6 -0
- package/dist/dts/RcMap.d.ts.map +1 -1
- package/dist/dts/RcRef.d.ts +2 -0
- package/dist/dts/RcRef.d.ts.map +1 -1
- package/dist/dts/Record.d.ts +136 -0
- package/dist/dts/Record.d.ts.map +1 -1
- package/dist/dts/Redacted.d.ts +8 -0
- package/dist/dts/Redacted.d.ts.map +1 -1
- package/dist/dts/RegExp.d.ts +4 -0
- package/dist/dts/RegExp.d.ts.map +1 -1
- package/dist/dts/Request.d.ts +4 -0
- package/dist/dts/Request.d.ts.map +1 -1
- package/dist/dts/RequestResolver.d.ts +6 -0
- package/dist/dts/RequestResolver.d.ts.map +1 -1
- package/dist/dts/Runtime.d.ts +18 -0
- package/dist/dts/Runtime.d.ts.map +1 -1
- package/dist/dts/STM.d.ts +2 -0
- package/dist/dts/STM.d.ts.map +1 -1
- package/dist/dts/Schema.d.ts +90 -0
- package/dist/dts/Schema.d.ts.map +1 -1
- package/dist/dts/Sink.d.ts +8 -0
- package/dist/dts/Sink.d.ts.map +1 -1
- package/dist/dts/Stream.d.ts +394 -32
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/String.d.ts +94 -0
- package/dist/dts/String.d.ts.map +1 -1
- package/dist/dts/Struct.d.ts +24 -0
- package/dist/dts/Struct.d.ts.map +1 -1
- package/dist/dts/Symbol.d.ts +2 -0
- package/dist/dts/Symbol.d.ts.map +1 -1
- package/dist/dts/Trie.d.ts +132 -0
- package/dist/dts/Trie.d.ts.map +1 -1
- package/dist/dts/Tuple.d.ts +42 -0
- package/dist/dts/Tuple.d.ts.map +1 -1
- package/dist/dts/Types.d.ts +24 -0
- package/dist/dts/Types.d.ts.map +1 -1
- package/dist/dts/Utils.d.ts +4 -0
- package/dist/dts/Utils.d.ts.map +1 -1
- package/dist/dts/internal/context.d.ts +1 -1
- package/dist/dts/internal/context.d.ts.map +1 -1
- package/dist/dts/internal/dateTime.d.ts +2 -0
- package/dist/dts/internal/dateTime.d.ts.map +1 -0
- package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/Array.js +208 -0
- package/dist/esm/Array.js.map +1 -1
- package/dist/esm/BigDecimal.js +175 -20
- package/dist/esm/BigDecimal.js.map +1 -1
- package/dist/esm/BigInt.js +54 -0
- package/dist/esm/BigInt.js.map +1 -1
- package/dist/esm/Boolean.js +24 -0
- package/dist/esm/Boolean.js.map +1 -1
- package/dist/esm/Brand.js +4 -0
- package/dist/esm/Brand.js.map +1 -1
- package/dist/esm/Channel.js +42 -2
- package/dist/esm/Channel.js.map +1 -1
- package/dist/esm/Chunk.js +8 -0
- package/dist/esm/Chunk.js.map +1 -1
- package/dist/esm/Config.js +9 -0
- package/dist/esm/Config.js.map +1 -1
- package/dist/esm/Context.js +49 -0
- package/dist/esm/Context.js.map +1 -1
- package/dist/esm/Cron.js +81 -67
- package/dist/esm/Cron.js.map +1 -1
- package/dist/esm/Data.js +16 -0
- package/dist/esm/Data.js.map +1 -1
- package/dist/esm/DateTime.js +176 -627
- package/dist/esm/DateTime.js.map +1 -1
- package/dist/esm/Duration.js +2 -0
- package/dist/esm/Duration.js.map +1 -1
- package/dist/esm/Effect.js +297 -0
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/Either.js +40 -2
- package/dist/esm/Either.js.map +1 -1
- package/dist/esm/FiberHandle.js +6 -0
- package/dist/esm/FiberHandle.js.map +1 -1
- package/dist/esm/FiberMap.js +6 -0
- package/dist/esm/FiberMap.js.map +1 -1
- package/dist/esm/FiberSet.js +6 -0
- package/dist/esm/FiberSet.js.map +1 -1
- package/dist/esm/Function.js +34 -0
- package/dist/esm/Function.js.map +1 -1
- package/dist/esm/GlobalValue.js +2 -0
- package/dist/esm/GlobalValue.js.map +1 -1
- package/dist/esm/HashMap.js.map +1 -1
- package/dist/esm/Inspectable.js +8 -4
- package/dist/esm/Inspectable.js.map +1 -1
- package/dist/esm/Iterable.js +18 -0
- package/dist/esm/Iterable.js.map +1 -1
- package/dist/esm/JSONSchema.js.map +1 -1
- package/dist/esm/List.js +4 -0
- package/dist/esm/List.js.map +1 -1
- package/dist/esm/Logger.js +26 -0
- package/dist/esm/Logger.js.map +1 -1
- package/dist/esm/Mailbox.js +2 -0
- package/dist/esm/Mailbox.js.map +1 -1
- package/dist/esm/ManagedRuntime.js +2 -0
- package/dist/esm/ManagedRuntime.js.map +1 -1
- package/dist/esm/Metric.js +10 -0
- package/dist/esm/Metric.js.map +1 -1
- package/dist/esm/Micro.js +1077 -1037
- package/dist/esm/Micro.js.map +1 -1
- package/dist/esm/Number.js +44 -0
- package/dist/esm/Number.js.map +1 -1
- package/dist/esm/Option.js +72 -0
- package/dist/esm/Option.js.map +1 -1
- package/dist/esm/Order.js +2 -0
- package/dist/esm/Order.js.map +1 -1
- package/dist/esm/Ordering.js +4 -0
- package/dist/esm/Ordering.js.map +1 -1
- package/dist/esm/Predicate.js +68 -0
- package/dist/esm/Predicate.js.map +1 -1
- package/dist/esm/Random.js +4 -0
- package/dist/esm/Random.js.map +1 -1
- package/dist/esm/RateLimiter.js +4 -0
- package/dist/esm/RateLimiter.js.map +1 -1
- package/dist/esm/RcMap.js +2 -0
- package/dist/esm/RcMap.js.map +1 -1
- package/dist/esm/RcRef.js +2 -0
- package/dist/esm/RcRef.js.map +1 -1
- package/dist/esm/Record.js +56 -0
- package/dist/esm/Record.js.map +1 -1
- package/dist/esm/Redacted.js +8 -0
- package/dist/esm/Redacted.js.map +1 -1
- package/dist/esm/RegExp.js +4 -0
- package/dist/esm/RegExp.js.map +1 -1
- package/dist/esm/Request.js +4 -0
- package/dist/esm/Request.js.map +1 -1
- package/dist/esm/RequestResolver.js +2 -0
- package/dist/esm/RequestResolver.js.map +1 -1
- package/dist/esm/Runtime.js +6 -0
- package/dist/esm/Runtime.js.map +1 -1
- package/dist/esm/STM.js.map +1 -1
- package/dist/esm/Schema.js +88 -0
- package/dist/esm/Schema.js.map +1 -1
- package/dist/esm/Sink.js +8 -0
- package/dist/esm/Sink.js.map +1 -1
- package/dist/esm/Stream.js +183 -5
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/String.js +62 -0
- package/dist/esm/String.js.map +1 -1
- package/dist/esm/Struct.js +12 -0
- package/dist/esm/Struct.js.map +1 -1
- package/dist/esm/Symbol.js +2 -0
- package/dist/esm/Symbol.js.map +1 -1
- package/dist/esm/Trie.js +56 -0
- package/dist/esm/Trie.js.map +1 -1
- package/dist/esm/Tuple.js +22 -0
- package/dist/esm/Tuple.js.map +1 -1
- package/dist/esm/Utils.js +5 -0
- package/dist/esm/Utils.js.map +1 -1
- package/dist/esm/internal/channel/channelExecutor.js +5 -7
- package/dist/esm/internal/channel/channelExecutor.js.map +1 -1
- package/dist/esm/internal/channel.js +152 -129
- package/dist/esm/internal/channel.js.map +1 -1
- package/dist/esm/internal/config.js +11 -3
- package/dist/esm/internal/config.js.map +1 -1
- package/dist/esm/internal/context.js +42 -2
- package/dist/esm/internal/context.js.map +1 -1
- package/dist/esm/internal/dateTime.js +704 -0
- package/dist/esm/internal/dateTime.js.map +1 -0
- package/dist/esm/internal/fiberRuntime.js +31 -9
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/groupBy.js +9 -3
- package/dist/esm/internal/groupBy.js.map +1 -1
- package/dist/esm/internal/layer.js +1 -1
- package/dist/esm/internal/layer.js.map +1 -1
- package/dist/esm/internal/mailbox.js +1 -1
- package/dist/esm/internal/mailbox.js.map +1 -1
- package/dist/esm/internal/sink.js +23 -20
- package/dist/esm/internal/sink.js.map +1 -1
- package/dist/esm/internal/stream.js +66 -69
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/dist/esm/internal/version.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +534 -0
- package/src/BigDecimal.ts +247 -21
- package/src/BigInt.ts +114 -0
- package/src/Boolean.ts +56 -0
- package/src/Brand.ts +6 -0
- package/src/Channel.ts +81 -5
- package/src/Chunk.ts +32 -0
- package/src/Config.ts +26 -1
- package/src/Context.ts +163 -0
- package/src/Cron.ts +91 -68
- package/src/Data.ts +26 -0
- package/src/DateTime.ts +307 -757
- package/src/Duration.ts +2 -0
- package/src/Effect.ts +910 -1
- package/src/Either.ts +84 -2
- package/src/FiberHandle.ts +6 -0
- package/src/FiberMap.ts +6 -0
- package/src/FiberSet.ts +6 -0
- package/src/Function.ts +50 -0
- package/src/GlobalValue.ts +2 -0
- package/src/HashMap.ts +6 -0
- package/src/Inspectable.ts +11 -7
- package/src/Iterable.ts +26 -0
- package/src/JSONSchema.ts +1 -0
- package/src/List.ts +24 -0
- package/src/Logger.ts +34 -0
- package/src/Mailbox.ts +2 -0
- package/src/ManagedRuntime.ts +2 -0
- package/src/Metric.ts +18 -0
- package/src/Micro.ts +2007 -1745
- package/src/Number.ts +104 -0
- package/src/Option.ts +142 -0
- package/src/Order.ts +2 -0
- package/src/Ordering.ts +8 -0
- package/src/Predicate.ts +104 -0
- package/src/Random.ts +4 -0
- package/src/RateLimiter.ts +4 -0
- package/src/RcMap.ts +6 -0
- package/src/RcRef.ts +2 -0
- package/src/Record.ts +136 -0
- package/src/Redacted.ts +8 -0
- package/src/RegExp.ts +4 -0
- package/src/Request.ts +4 -0
- package/src/RequestResolver.ts +6 -0
- package/src/Runtime.ts +18 -0
- package/src/STM.ts +2 -0
- package/src/Schema.ts +124 -0
- package/src/Sink.ts +11 -0
- package/src/Stream.ts +399 -44
- package/src/String.ts +94 -0
- package/src/Struct.ts +24 -0
- package/src/Symbol.ts +2 -0
- package/src/Trie.ts +132 -0
- package/src/Tuple.ts +42 -0
- package/src/Types.ts +24 -0
- package/src/Utils.ts +8 -0
- package/src/internal/channel/channelExecutor.ts +37 -33
- package/src/internal/channel.ts +504 -467
- package/src/internal/config.ts +18 -6
- package/src/internal/context.ts +56 -4
- package/src/internal/dateTime.ts +1126 -0
- package/src/internal/fiberRuntime.ts +35 -16
- package/src/internal/groupBy.ts +13 -22
- package/src/internal/layer.ts +5 -8
- package/src/internal/mailbox.ts +6 -4
- package/src/internal/sink.ts +55 -35
- package/src/internal/stream.ts +299 -299
- package/src/internal/version.ts +1 -1
package/dist/esm/DateTime.js
CHANGED
|
@@ -1,124 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @since 3.6.0
|
|
3
|
-
*/
|
|
4
|
-
import { IllegalArgumentException } from "./Cause.js";
|
|
5
|
-
import * as Clock from "./Clock.js";
|
|
6
1
|
import * as Context from "./Context.js";
|
|
7
|
-
import * as Duration from "./Duration.js";
|
|
8
2
|
import * as Effect from "./Effect.js";
|
|
9
|
-
import
|
|
10
|
-
import * as
|
|
11
|
-
import * as Equivalence_ from "./Equivalence.js";
|
|
12
|
-
import { dual, pipe } from "./Function.js";
|
|
13
|
-
import { globalValue } from "./GlobalValue.js";
|
|
14
|
-
import * as Hash from "./Hash.js";
|
|
15
|
-
import * as Inspectable from "./Inspectable.js";
|
|
3
|
+
import { dual } from "./Function.js";
|
|
4
|
+
import * as Internal from "./internal/dateTime.js";
|
|
16
5
|
import * as Layer from "./Layer.js";
|
|
17
|
-
import * as Option from "./Option.js";
|
|
18
|
-
import * as order from "./Order.js";
|
|
19
|
-
import { pipeArguments } from "./Pipeable.js";
|
|
20
|
-
import * as Predicate from "./Predicate.js";
|
|
21
6
|
/**
|
|
22
7
|
* @since 3.6.0
|
|
23
8
|
* @category type ids
|
|
24
9
|
*/
|
|
25
|
-
export const TypeId =
|
|
10
|
+
export const TypeId = Internal.TypeId;
|
|
26
11
|
/**
|
|
27
12
|
* @since 3.6.0
|
|
28
13
|
* @category type ids
|
|
29
14
|
*/
|
|
30
|
-
export const TimeZoneTypeId =
|
|
31
|
-
const Proto = {
|
|
32
|
-
[TypeId]: TypeId,
|
|
33
|
-
pipe() {
|
|
34
|
-
return pipeArguments(this, arguments);
|
|
35
|
-
},
|
|
36
|
-
[Inspectable.NodeInspectSymbol]() {
|
|
37
|
-
return this.toString();
|
|
38
|
-
},
|
|
39
|
-
toJSON() {
|
|
40
|
-
return toDateUtc(this).toJSON();
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const ProtoUtc = {
|
|
44
|
-
...Proto,
|
|
45
|
-
_tag: "Utc",
|
|
46
|
-
[Hash.symbol]() {
|
|
47
|
-
return Hash.cached(this, Hash.number(this.epochMillis));
|
|
48
|
-
},
|
|
49
|
-
[Equal.symbol](that) {
|
|
50
|
-
return isDateTime(that) && that._tag === "Utc" && this.epochMillis === that.epochMillis;
|
|
51
|
-
},
|
|
52
|
-
toString() {
|
|
53
|
-
return `DateTime.Utc(${toDateUtc(this).toJSON()})`;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const ProtoZoned = {
|
|
57
|
-
...Proto,
|
|
58
|
-
_tag: "Zoned",
|
|
59
|
-
[Hash.symbol]() {
|
|
60
|
-
return pipe(Hash.number(this.epochMillis), Hash.combine(Hash.hash(this.zone)), Hash.cached(this));
|
|
61
|
-
},
|
|
62
|
-
[Equal.symbol](that) {
|
|
63
|
-
return isDateTime(that) && that._tag === "Zoned" && this.epochMillis === that.epochMillis && Equal.equals(this.zone, that.zone);
|
|
64
|
-
},
|
|
65
|
-
toString() {
|
|
66
|
-
return `DateTime.Zoned(${formatIsoZoned(this)})`;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
const ProtoTimeZone = {
|
|
70
|
-
[TimeZoneTypeId]: TimeZoneTypeId,
|
|
71
|
-
[Inspectable.NodeInspectSymbol]() {
|
|
72
|
-
return this.toString();
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const ProtoTimeZoneNamed = {
|
|
76
|
-
...ProtoTimeZone,
|
|
77
|
-
_tag: "Named",
|
|
78
|
-
[Hash.symbol]() {
|
|
79
|
-
return Hash.cached(this, Hash.string(`Named:${this.id}`));
|
|
80
|
-
},
|
|
81
|
-
[Equal.symbol](that) {
|
|
82
|
-
return isTimeZone(that) && that._tag === "Named" && this.id === that.id;
|
|
83
|
-
},
|
|
84
|
-
toString() {
|
|
85
|
-
return `TimeZone.Named(${this.id})`;
|
|
86
|
-
},
|
|
87
|
-
toJSON() {
|
|
88
|
-
return {
|
|
89
|
-
_id: "TimeZone",
|
|
90
|
-
_tag: "Named",
|
|
91
|
-
id: this.id
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
const ProtoTimeZoneOffset = {
|
|
96
|
-
...ProtoTimeZone,
|
|
97
|
-
_tag: "Offset",
|
|
98
|
-
[Hash.symbol]() {
|
|
99
|
-
return Hash.cached(this, Hash.string(`Offset:${this.offset}`));
|
|
100
|
-
},
|
|
101
|
-
[Equal.symbol](that) {
|
|
102
|
-
return isTimeZone(that) && that._tag === "Offset" && this.offset === that.offset;
|
|
103
|
-
},
|
|
104
|
-
toString() {
|
|
105
|
-
return `TimeZone.Offset(${offsetToString(this.offset)})`;
|
|
106
|
-
},
|
|
107
|
-
toJSON() {
|
|
108
|
-
return {
|
|
109
|
-
_id: "TimeZone",
|
|
110
|
-
_tag: "Offset",
|
|
111
|
-
offset: this.offset
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
const makeZonedProto = (epochMillis, zone, partsUtc) => {
|
|
116
|
-
const self = Object.create(ProtoZoned);
|
|
117
|
-
self.epochMillis = epochMillis;
|
|
118
|
-
self.zone = zone;
|
|
119
|
-
self.partsUtc = partsUtc;
|
|
120
|
-
return self;
|
|
121
|
-
};
|
|
15
|
+
export const TimeZoneTypeId = Internal.TimeZoneTypeId;
|
|
122
16
|
// =============================================================================
|
|
123
17
|
// guards
|
|
124
18
|
// =============================================================================
|
|
@@ -126,33 +20,32 @@ const makeZonedProto = (epochMillis, zone, partsUtc) => {
|
|
|
126
20
|
* @since 3.6.0
|
|
127
21
|
* @category guards
|
|
128
22
|
*/
|
|
129
|
-
export const isDateTime =
|
|
130
|
-
const isDateTimeArgs = args => isDateTime(args[0]);
|
|
23
|
+
export const isDateTime = Internal.isDateTime;
|
|
131
24
|
/**
|
|
132
25
|
* @since 3.6.0
|
|
133
26
|
* @category guards
|
|
134
27
|
*/
|
|
135
|
-
export const isTimeZone =
|
|
28
|
+
export const isTimeZone = Internal.isTimeZone;
|
|
136
29
|
/**
|
|
137
30
|
* @since 3.6.0
|
|
138
31
|
* @category guards
|
|
139
32
|
*/
|
|
140
|
-
export const isTimeZoneOffset =
|
|
33
|
+
export const isTimeZoneOffset = Internal.isTimeZoneOffset;
|
|
141
34
|
/**
|
|
142
35
|
* @since 3.6.0
|
|
143
36
|
* @category guards
|
|
144
37
|
*/
|
|
145
|
-
export const isTimeZoneNamed =
|
|
38
|
+
export const isTimeZoneNamed = Internal.isTimeZoneNamed;
|
|
146
39
|
/**
|
|
147
40
|
* @since 3.6.0
|
|
148
41
|
* @category guards
|
|
149
42
|
*/
|
|
150
|
-
export const isUtc =
|
|
43
|
+
export const isUtc = Internal.isUtc;
|
|
151
44
|
/**
|
|
152
45
|
* @since 3.6.0
|
|
153
46
|
* @category guards
|
|
154
47
|
*/
|
|
155
|
-
export const isZoned =
|
|
48
|
+
export const isZoned = Internal.isZoned;
|
|
156
49
|
// =============================================================================
|
|
157
50
|
// instances
|
|
158
51
|
// =============================================================================
|
|
@@ -160,24 +53,19 @@ export const isZoned = self => self._tag === "Zoned";
|
|
|
160
53
|
* @since 3.6.0
|
|
161
54
|
* @category instances
|
|
162
55
|
*/
|
|
163
|
-
export const Equivalence =
|
|
56
|
+
export const Equivalence = Internal.Equivalence;
|
|
164
57
|
/**
|
|
165
58
|
* @since 3.6.0
|
|
166
59
|
* @category instances
|
|
167
60
|
*/
|
|
168
|
-
export const Order =
|
|
61
|
+
export const Order = Internal.Order;
|
|
169
62
|
/**
|
|
170
63
|
* @since 3.6.0
|
|
171
64
|
*/
|
|
172
|
-
export const clamp =
|
|
65
|
+
export const clamp = Internal.clamp;
|
|
173
66
|
// =============================================================================
|
|
174
67
|
// constructors
|
|
175
68
|
// =============================================================================
|
|
176
|
-
const makeUtc = epochMillis => {
|
|
177
|
-
const self = Object.create(ProtoUtc);
|
|
178
|
-
self.epochMillis = epochMillis;
|
|
179
|
-
return self;
|
|
180
|
-
};
|
|
181
69
|
/**
|
|
182
70
|
* Create a `DateTime` from a `Date`.
|
|
183
71
|
*
|
|
@@ -186,13 +74,7 @@ const makeUtc = epochMillis => {
|
|
|
186
74
|
* @since 3.6.0
|
|
187
75
|
* @category constructors
|
|
188
76
|
*/
|
|
189
|
-
export const unsafeFromDate =
|
|
190
|
-
const epochMillis = date.getTime();
|
|
191
|
-
if (Number.isNaN(epochMillis)) {
|
|
192
|
-
throw new IllegalArgumentException("Invalid date");
|
|
193
|
-
}
|
|
194
|
-
return makeUtc(epochMillis);
|
|
195
|
-
};
|
|
77
|
+
export const unsafeFromDate = Internal.unsafeFromDate;
|
|
196
78
|
/**
|
|
197
79
|
* Create a `DateTime` from one of the following:
|
|
198
80
|
*
|
|
@@ -205,6 +87,7 @@ export const unsafeFromDate = date => {
|
|
|
205
87
|
* @since 3.6.0
|
|
206
88
|
* @category constructors
|
|
207
89
|
* @example
|
|
90
|
+
* ```ts
|
|
208
91
|
* import { DateTime } from "effect"
|
|
209
92
|
*
|
|
210
93
|
* // from Date
|
|
@@ -215,19 +98,9 @@ export const unsafeFromDate = date => {
|
|
|
215
98
|
*
|
|
216
99
|
* // from string
|
|
217
100
|
* DateTime.unsafeMake("2024-01-01")
|
|
101
|
+
* ```
|
|
218
102
|
*/
|
|
219
|
-
export const unsafeMake =
|
|
220
|
-
if (isDateTime(input)) {
|
|
221
|
-
return input;
|
|
222
|
-
} else if (input instanceof Date) {
|
|
223
|
-
return unsafeFromDate(input);
|
|
224
|
-
} else if (typeof input === "object") {
|
|
225
|
-
const date = new Date(0);
|
|
226
|
-
setPartsDate(date, input);
|
|
227
|
-
return unsafeFromDate(date);
|
|
228
|
-
}
|
|
229
|
-
return unsafeFromDate(new Date(input));
|
|
230
|
-
};
|
|
103
|
+
export const unsafeMake = Internal.unsafeMake;
|
|
231
104
|
/**
|
|
232
105
|
* Create a `DateTime.Zoned` using `DateTime.unsafeMake` and a time zone.
|
|
233
106
|
*
|
|
@@ -238,35 +111,13 @@ export const unsafeMake = input => {
|
|
|
238
111
|
* @since 3.6.0
|
|
239
112
|
* @category constructors
|
|
240
113
|
* @example
|
|
114
|
+
* ```ts
|
|
241
115
|
* import { DateTime } from "effect"
|
|
242
116
|
*
|
|
243
117
|
* DateTime.unsafeMakeZoned(new Date(), { timeZone: "Europe/London" })
|
|
118
|
+
* ```
|
|
244
119
|
*/
|
|
245
|
-
export const unsafeMakeZoned =
|
|
246
|
-
if (options?.timeZone === undefined && isDateTime(input) && isZoned(input)) {
|
|
247
|
-
return input;
|
|
248
|
-
}
|
|
249
|
-
const self = unsafeMake(input);
|
|
250
|
-
let zone;
|
|
251
|
-
if (options?.timeZone === undefined) {
|
|
252
|
-
const offset = new Date(self.epochMillis).getTimezoneOffset() * -60 * 1000;
|
|
253
|
-
zone = zoneMakeOffset(offset);
|
|
254
|
-
} else if (isTimeZone(options?.timeZone)) {
|
|
255
|
-
zone = options.timeZone;
|
|
256
|
-
} else if (typeof options?.timeZone === "number") {
|
|
257
|
-
zone = zoneMakeOffset(options.timeZone);
|
|
258
|
-
} else {
|
|
259
|
-
const parsedZone = zoneFromString(options.timeZone);
|
|
260
|
-
if (Option.isNone(parsedZone)) {
|
|
261
|
-
throw new IllegalArgumentException(`Invalid time zone: ${options.timeZone}`);
|
|
262
|
-
}
|
|
263
|
-
zone = parsedZone.value;
|
|
264
|
-
}
|
|
265
|
-
if (options?.adjustForTimeZone !== true) {
|
|
266
|
-
return makeZonedProto(self.epochMillis, zone, self.partsUtc);
|
|
267
|
-
}
|
|
268
|
-
return makeZonedFromAdjusted(self.epochMillis, zone);
|
|
269
|
-
};
|
|
120
|
+
export const unsafeMakeZoned = Internal.unsafeMakeZoned;
|
|
270
121
|
/**
|
|
271
122
|
* Create a `DateTime.Zoned` using `DateTime.make` and a time zone.
|
|
272
123
|
*
|
|
@@ -277,11 +128,13 @@ export const unsafeMakeZoned = (input, options) => {
|
|
|
277
128
|
* @since 3.6.0
|
|
278
129
|
* @category constructors
|
|
279
130
|
* @example
|
|
131
|
+
* ```ts
|
|
280
132
|
* import { DateTime } from "effect"
|
|
281
133
|
*
|
|
282
134
|
* DateTime.makeZoned(new Date(), { timeZone: "Europe/London" })
|
|
135
|
+
* ```
|
|
283
136
|
*/
|
|
284
|
-
export const makeZoned =
|
|
137
|
+
export const makeZoned = Internal.makeZoned;
|
|
285
138
|
/**
|
|
286
139
|
* Create a `DateTime` from one of the following:
|
|
287
140
|
*
|
|
@@ -296,6 +149,7 @@ export const makeZoned = /*#__PURE__*/Option.liftThrowable(unsafeMakeZoned);
|
|
|
296
149
|
* @since 3.6.0
|
|
297
150
|
* @category constructors
|
|
298
151
|
* @example
|
|
152
|
+
* ```ts
|
|
299
153
|
* import { DateTime } from "effect"
|
|
300
154
|
*
|
|
301
155
|
* // from Date
|
|
@@ -306,9 +160,9 @@ export const makeZoned = /*#__PURE__*/Option.liftThrowable(unsafeMakeZoned);
|
|
|
306
160
|
*
|
|
307
161
|
* // from string
|
|
308
162
|
* DateTime.make("2024-01-01")
|
|
163
|
+
* ```
|
|
309
164
|
*/
|
|
310
|
-
export const make =
|
|
311
|
-
const zonedStringRegex = /^(.{17,35})\[(.+)\]$/;
|
|
165
|
+
export const make = Internal.make;
|
|
312
166
|
/**
|
|
313
167
|
* Create a `DateTime.Zoned` from a string.
|
|
314
168
|
*
|
|
@@ -317,39 +171,29 @@ const zonedStringRegex = /^(.{17,35})\[(.+)\]$/;
|
|
|
317
171
|
* @since 3.6.0
|
|
318
172
|
* @category constructors
|
|
319
173
|
*/
|
|
320
|
-
export const makeZonedFromString =
|
|
321
|
-
const match = zonedStringRegex.exec(input);
|
|
322
|
-
if (match === null) {
|
|
323
|
-
const offset = parseOffset(input);
|
|
324
|
-
return offset !== null ? makeZoned(input, {
|
|
325
|
-
timeZone: offset
|
|
326
|
-
}) : Option.none();
|
|
327
|
-
}
|
|
328
|
-
const [, isoString, timeZone] = match;
|
|
329
|
-
return makeZoned(isoString, {
|
|
330
|
-
timeZone
|
|
331
|
-
});
|
|
332
|
-
};
|
|
174
|
+
export const makeZonedFromString = Internal.makeZonedFromString;
|
|
333
175
|
/**
|
|
334
176
|
* Get the current time using the `Clock` service and convert it to a `DateTime`.
|
|
335
177
|
*
|
|
336
178
|
* @since 3.6.0
|
|
337
179
|
* @category constructors
|
|
338
180
|
* @example
|
|
181
|
+
* ```ts
|
|
339
182
|
* import { DateTime, Effect } from "effect"
|
|
340
183
|
*
|
|
341
184
|
* Effect.gen(function* () {
|
|
342
185
|
* const now = yield* DateTime.now
|
|
343
186
|
* })
|
|
187
|
+
* ```
|
|
344
188
|
*/
|
|
345
|
-
export const now =
|
|
189
|
+
export const now = Internal.now;
|
|
346
190
|
/**
|
|
347
191
|
* Get the current time using `Date.now`.
|
|
348
192
|
*
|
|
349
193
|
* @since 3.6.0
|
|
350
194
|
* @category constructors
|
|
351
195
|
*/
|
|
352
|
-
export const unsafeNow =
|
|
196
|
+
export const unsafeNow = Internal.unsafeNow;
|
|
353
197
|
// =============================================================================
|
|
354
198
|
// time zones
|
|
355
199
|
// =============================================================================
|
|
@@ -359,6 +203,7 @@ export const unsafeNow = () => makeUtc(Date.now());
|
|
|
359
203
|
* @since 3.6.0
|
|
360
204
|
* @category time zones
|
|
361
205
|
* @example
|
|
206
|
+
* ```ts
|
|
362
207
|
* import { DateTime, Effect } from "effect"
|
|
363
208
|
*
|
|
364
209
|
* Effect.gen(function* () {
|
|
@@ -368,8 +213,9 @@ export const unsafeNow = () => makeUtc(Date.now());
|
|
|
368
213
|
* // set the time zone
|
|
369
214
|
* const zoned: DateTime.Zoned = DateTime.setZone(now, zone)
|
|
370
215
|
* })
|
|
216
|
+
* ```
|
|
371
217
|
*/
|
|
372
|
-
export const setZone =
|
|
218
|
+
export const setZone = Internal.setZone;
|
|
373
219
|
/**
|
|
374
220
|
* Add a fixed offset time zone to a `DateTime`.
|
|
375
221
|
*
|
|
@@ -378,6 +224,7 @@ export const setZone = /*#__PURE__*/dual(isDateTimeArgs, (self, zone, options) =
|
|
|
378
224
|
* @since 3.6.0
|
|
379
225
|
* @category time zones
|
|
380
226
|
* @example
|
|
227
|
+
* ```ts
|
|
381
228
|
* import { DateTime, Effect } from "effect"
|
|
382
229
|
*
|
|
383
230
|
* Effect.gen(function* () {
|
|
@@ -386,31 +233,9 @@ export const setZone = /*#__PURE__*/dual(isDateTimeArgs, (self, zone, options) =
|
|
|
386
233
|
* // set the offset time zone in milliseconds
|
|
387
234
|
* const zoned: DateTime.Zoned = DateTime.setZoneOffset(now, 3 * 60 * 60 * 1000)
|
|
388
235
|
* })
|
|
236
|
+
* ```
|
|
389
237
|
*/
|
|
390
|
-
export const setZoneOffset =
|
|
391
|
-
const validZoneCache = /*#__PURE__*/globalValue("effect/DateTime/validZoneCache", () => new Map());
|
|
392
|
-
const formatOptions = {
|
|
393
|
-
day: "numeric",
|
|
394
|
-
month: "numeric",
|
|
395
|
-
year: "numeric",
|
|
396
|
-
hour: "numeric",
|
|
397
|
-
minute: "numeric",
|
|
398
|
-
second: "numeric",
|
|
399
|
-
timeZoneName: "longOffset",
|
|
400
|
-
fractionalSecondDigits: 3,
|
|
401
|
-
hourCycle: "h23"
|
|
402
|
-
};
|
|
403
|
-
const zoneMakeIntl = format => {
|
|
404
|
-
const zoneId = format.resolvedOptions().timeZone;
|
|
405
|
-
if (validZoneCache.has(zoneId)) {
|
|
406
|
-
return validZoneCache.get(zoneId);
|
|
407
|
-
}
|
|
408
|
-
const zone = Object.create(ProtoTimeZoneNamed);
|
|
409
|
-
zone.id = zoneId;
|
|
410
|
-
zone.format = format;
|
|
411
|
-
validZoneCache.set(zoneId, zone);
|
|
412
|
-
return zone;
|
|
413
|
-
};
|
|
238
|
+
export const setZoneOffset = Internal.setZoneOffset;
|
|
414
239
|
/**
|
|
415
240
|
* Attempt to create a named time zone from a IANA time zone identifier.
|
|
416
241
|
*
|
|
@@ -419,30 +244,14 @@ const zoneMakeIntl = format => {
|
|
|
419
244
|
* @since 3.6.0
|
|
420
245
|
* @category time zones
|
|
421
246
|
*/
|
|
422
|
-
export const zoneUnsafeMakeNamed =
|
|
423
|
-
if (validZoneCache.has(zoneId)) {
|
|
424
|
-
return validZoneCache.get(zoneId);
|
|
425
|
-
}
|
|
426
|
-
try {
|
|
427
|
-
return zoneMakeIntl(new Intl.DateTimeFormat("en-US", {
|
|
428
|
-
...formatOptions,
|
|
429
|
-
timeZone: zoneId
|
|
430
|
-
}));
|
|
431
|
-
} catch (_) {
|
|
432
|
-
throw new IllegalArgumentException(`Invalid time zone: ${zoneId}`);
|
|
433
|
-
}
|
|
434
|
-
};
|
|
247
|
+
export const zoneUnsafeMakeNamed = Internal.zoneUnsafeMakeNamed;
|
|
435
248
|
/**
|
|
436
249
|
* Create a fixed offset time zone.
|
|
437
250
|
*
|
|
438
251
|
* @since 3.6.0
|
|
439
252
|
* @category time zones
|
|
440
253
|
*/
|
|
441
|
-
export const zoneMakeOffset =
|
|
442
|
-
const zone = Object.create(ProtoTimeZoneOffset);
|
|
443
|
-
zone.offset = offset;
|
|
444
|
-
return zone;
|
|
445
|
-
};
|
|
254
|
+
export const zoneMakeOffset = Internal.zoneMakeOffset;
|
|
446
255
|
/**
|
|
447
256
|
* Create a named time zone from a IANA time zone identifier. If the time zone
|
|
448
257
|
* is invalid, `None` will be returned.
|
|
@@ -450,7 +259,7 @@ export const zoneMakeOffset = offset => {
|
|
|
450
259
|
* @since 3.6.0
|
|
451
260
|
* @category time zones
|
|
452
261
|
*/
|
|
453
|
-
export const zoneMakeNamed =
|
|
262
|
+
export const zoneMakeNamed = Internal.zoneMakeNamed;
|
|
454
263
|
/**
|
|
455
264
|
* Create a named time zone from a IANA time zone identifier. If the time zone
|
|
456
265
|
* is invalid, it will fail with an `IllegalArgumentException`.
|
|
@@ -458,37 +267,28 @@ export const zoneMakeNamed = /*#__PURE__*/Option.liftThrowable(zoneUnsafeMakeNam
|
|
|
458
267
|
* @since 3.6.0
|
|
459
268
|
* @category time zones
|
|
460
269
|
*/
|
|
461
|
-
export const zoneMakeNamedEffect =
|
|
462
|
-
try: () => zoneUnsafeMakeNamed(zoneId),
|
|
463
|
-
catch: e => e
|
|
464
|
-
});
|
|
270
|
+
export const zoneMakeNamedEffect = Internal.zoneMakeNamedEffect;
|
|
465
271
|
/**
|
|
466
272
|
* Create a named time zone from the system's local time zone.
|
|
467
273
|
*
|
|
468
274
|
* @since 3.6.0
|
|
469
275
|
* @category time zones
|
|
470
276
|
*/
|
|
471
|
-
export const zoneMakeLocal =
|
|
472
|
-
const offsetZoneRegex = /^(?:GMT|[+-])/;
|
|
277
|
+
export const zoneMakeLocal = Internal.zoneMakeLocal;
|
|
473
278
|
/**
|
|
474
279
|
* Try parse a TimeZone from a string
|
|
475
280
|
*
|
|
476
281
|
* @since 3.6.0
|
|
477
282
|
* @category time zones
|
|
478
283
|
*/
|
|
479
|
-
export const zoneFromString =
|
|
480
|
-
if (offsetZoneRegex.test(zone)) {
|
|
481
|
-
const offset = parseOffset(zone);
|
|
482
|
-
return offset === null ? Option.none() : Option.some(zoneMakeOffset(offset));
|
|
483
|
-
}
|
|
484
|
-
return zoneMakeNamed(zone);
|
|
485
|
-
};
|
|
284
|
+
export const zoneFromString = Internal.zoneFromString;
|
|
486
285
|
/**
|
|
487
286
|
* Format a `TimeZone` as a string.
|
|
488
287
|
*
|
|
489
288
|
* @since 3.6.0
|
|
490
289
|
* @category time zones
|
|
491
290
|
* @example
|
|
291
|
+
* ```ts
|
|
492
292
|
* import { DateTime, Effect } from "effect"
|
|
493
293
|
*
|
|
494
294
|
* // Outputs "+03:00"
|
|
@@ -496,13 +296,9 @@ export const zoneFromString = zone => {
|
|
|
496
296
|
*
|
|
497
297
|
* // Outputs "Europe/London"
|
|
498
298
|
* DateTime.zoneToString(DateTime.zoneUnsafeMakeNamed("Europe/London"))
|
|
299
|
+
* ```
|
|
499
300
|
*/
|
|
500
|
-
export const zoneToString =
|
|
501
|
-
if (self._tag === "Offset") {
|
|
502
|
-
return offsetToString(self.offset);
|
|
503
|
-
}
|
|
504
|
-
return self.id;
|
|
505
|
-
};
|
|
301
|
+
export const zoneToString = Internal.zoneToString;
|
|
506
302
|
/**
|
|
507
303
|
* Set the time zone of a `DateTime` from an IANA time zone identifier. If the
|
|
508
304
|
* time zone is invalid, `None` will be returned.
|
|
@@ -510,6 +306,7 @@ export const zoneToString = self => {
|
|
|
510
306
|
* @since 3.6.0
|
|
511
307
|
* @category time zones
|
|
512
308
|
* @example
|
|
309
|
+
* ```ts
|
|
513
310
|
* import { DateTime, Effect } from "effect"
|
|
514
311
|
*
|
|
515
312
|
* Effect.gen(function* () {
|
|
@@ -517,8 +314,9 @@ export const zoneToString = self => {
|
|
|
517
314
|
* // set the time zone, returns an Option
|
|
518
315
|
* DateTime.setZoneNamed(now, "Europe/London")
|
|
519
316
|
* })
|
|
317
|
+
* ```
|
|
520
318
|
*/
|
|
521
|
-
export const setZoneNamed =
|
|
319
|
+
export const setZoneNamed = Internal.setZoneNamed;
|
|
522
320
|
/**
|
|
523
321
|
* Set the time zone of a `DateTime` from an IANA time zone identifier. If the
|
|
524
322
|
* time zone is invalid, an `IllegalArgumentException` will be thrown.
|
|
@@ -526,6 +324,7 @@ export const setZoneNamed = /*#__PURE__*/dual(isDateTimeArgs, (self, zoneId, opt
|
|
|
526
324
|
* @since 3.6.0
|
|
527
325
|
* @category time zones
|
|
528
326
|
* @example
|
|
327
|
+
* ```ts
|
|
529
328
|
* import { DateTime, Effect } from "effect"
|
|
530
329
|
*
|
|
531
330
|
* Effect.gen(function* () {
|
|
@@ -533,8 +332,9 @@ export const setZoneNamed = /*#__PURE__*/dual(isDateTimeArgs, (self, zoneId, opt
|
|
|
533
332
|
* // set the time zone
|
|
534
333
|
* DateTime.unsafeSetZoneNamed(now, "Europe/London")
|
|
535
334
|
* })
|
|
335
|
+
* ```
|
|
536
336
|
*/
|
|
537
|
-
export const unsafeSetZoneNamed =
|
|
337
|
+
export const unsafeSetZoneNamed = Internal.unsafeSetZoneNamed;
|
|
538
338
|
// =============================================================================
|
|
539
339
|
// comparisons
|
|
540
340
|
// =============================================================================
|
|
@@ -547,6 +347,7 @@ export const unsafeSetZoneNamed = /*#__PURE__*/dual(isDateTimeArgs, (self, zoneI
|
|
|
547
347
|
* @since 3.6.0
|
|
548
348
|
* @category comparisons
|
|
549
349
|
* @example
|
|
350
|
+
* ```ts
|
|
550
351
|
* import { DateTime, Effect } from "effect"
|
|
551
352
|
*
|
|
552
353
|
* Effect.gen(function* () {
|
|
@@ -556,8 +357,9 @@ export const unsafeSetZoneNamed = /*#__PURE__*/dual(isDateTimeArgs, (self, zoneI
|
|
|
556
357
|
* // returns 60000
|
|
557
358
|
* DateTime.distance(now, other)
|
|
558
359
|
* })
|
|
360
|
+
* ```
|
|
559
361
|
*/
|
|
560
|
-
export const distance =
|
|
362
|
+
export const distance = Internal.distance;
|
|
561
363
|
/**
|
|
562
364
|
* Calulate the difference between two `DateTime` values.
|
|
563
365
|
*
|
|
@@ -570,6 +372,7 @@ export const distance = /*#__PURE__*/dual(2, (self, other) => toEpochMillis(othe
|
|
|
570
372
|
* @since 3.6.0
|
|
571
373
|
* @category comparisons
|
|
572
374
|
* @example
|
|
375
|
+
* ```ts
|
|
573
376
|
* import { DateTime, Effect } from "effect"
|
|
574
377
|
*
|
|
575
378
|
* Effect.gen(function* () {
|
|
@@ -582,17 +385,16 @@ export const distance = /*#__PURE__*/dual(2, (self, other) => toEpochMillis(othe
|
|
|
582
385
|
* // returns Either.left(Duration.minutes(1))
|
|
583
386
|
* DateTime.distanceDurationEither(other, now)
|
|
584
387
|
* })
|
|
388
|
+
* ```
|
|
585
389
|
*/
|
|
586
|
-
export const distanceDurationEither =
|
|
587
|
-
const diffMillis = distance(self, other);
|
|
588
|
-
return diffMillis > 0 ? Either.right(Duration.millis(diffMillis)) : Either.left(Duration.millis(-diffMillis));
|
|
589
|
-
});
|
|
390
|
+
export const distanceDurationEither = Internal.distanceDurationEither;
|
|
590
391
|
/**
|
|
591
392
|
* Calulate the distance between two `DateTime` values.
|
|
592
393
|
*
|
|
593
394
|
* @since 3.6.0
|
|
594
395
|
* @category comparisons
|
|
595
396
|
* @example
|
|
397
|
+
* ```ts
|
|
596
398
|
* import { DateTime, Effect } from "effect"
|
|
597
399
|
*
|
|
598
400
|
* Effect.gen(function* () {
|
|
@@ -602,63 +404,64 @@ export const distanceDurationEither = /*#__PURE__*/dual(2, (self, other) => {
|
|
|
602
404
|
* // returns Duration.minutes(1)
|
|
603
405
|
* DateTime.distanceDuration(now, other)
|
|
604
406
|
* })
|
|
407
|
+
* ```
|
|
605
408
|
*/
|
|
606
|
-
export const distanceDuration =
|
|
409
|
+
export const distanceDuration = Internal.distanceDuration;
|
|
607
410
|
/**
|
|
608
411
|
* @since 3.6.0
|
|
609
412
|
* @category comparisons
|
|
610
413
|
*/
|
|
611
|
-
export const min =
|
|
414
|
+
export const min = Internal.min;
|
|
612
415
|
/**
|
|
613
416
|
* @since 3.6.0
|
|
614
417
|
* @category comparisons
|
|
615
418
|
*/
|
|
616
|
-
export const max =
|
|
419
|
+
export const max = Internal.max;
|
|
617
420
|
/**
|
|
618
421
|
* @since 3.6.0
|
|
619
422
|
* @category comparisons
|
|
620
423
|
*/
|
|
621
|
-
export const greaterThan =
|
|
424
|
+
export const greaterThan = Internal.greaterThan;
|
|
622
425
|
/**
|
|
623
426
|
* @since 3.6.0
|
|
624
427
|
* @category comparisons
|
|
625
428
|
*/
|
|
626
|
-
export const greaterThanOrEqualTo =
|
|
429
|
+
export const greaterThanOrEqualTo = Internal.greaterThanOrEqualTo;
|
|
627
430
|
/**
|
|
628
431
|
* @since 3.6.0
|
|
629
432
|
* @category comparisons
|
|
630
433
|
*/
|
|
631
|
-
export const lessThan =
|
|
434
|
+
export const lessThan = Internal.lessThan;
|
|
632
435
|
/**
|
|
633
436
|
* @since 3.6.0
|
|
634
437
|
* @category comparisons
|
|
635
438
|
*/
|
|
636
|
-
export const lessThanOrEqualTo =
|
|
439
|
+
export const lessThanOrEqualTo = Internal.lessThanOrEqualTo;
|
|
637
440
|
/**
|
|
638
441
|
* @since 3.6.0
|
|
639
442
|
* @category comparisons
|
|
640
443
|
*/
|
|
641
|
-
export const between =
|
|
444
|
+
export const between = Internal.between;
|
|
642
445
|
/**
|
|
643
446
|
* @since 3.6.0
|
|
644
447
|
* @category comparisons
|
|
645
448
|
*/
|
|
646
|
-
export const isFuture =
|
|
449
|
+
export const isFuture = Internal.isFuture;
|
|
647
450
|
/**
|
|
648
451
|
* @since 3.6.0
|
|
649
452
|
* @category comparisons
|
|
650
453
|
*/
|
|
651
|
-
export const unsafeIsFuture =
|
|
454
|
+
export const unsafeIsFuture = Internal.unsafeIsFuture;
|
|
652
455
|
/**
|
|
653
456
|
* @since 3.6.0
|
|
654
457
|
* @category comparisons
|
|
655
458
|
*/
|
|
656
|
-
export const isPast =
|
|
459
|
+
export const isPast = Internal.isPast;
|
|
657
460
|
/**
|
|
658
461
|
* @since 3.6.0
|
|
659
462
|
* @category comparisons
|
|
660
463
|
*/
|
|
661
|
-
export const unsafeIsPast =
|
|
464
|
+
export const unsafeIsPast = Internal.unsafeIsPast;
|
|
662
465
|
// =============================================================================
|
|
663
466
|
// conversions
|
|
664
467
|
// =============================================================================
|
|
@@ -668,44 +471,21 @@ export const unsafeIsPast = self => greaterThan(unsafeNow(), self);
|
|
|
668
471
|
* @since 3.6.0
|
|
669
472
|
* @category conversions
|
|
670
473
|
*/
|
|
671
|
-
export const toDateUtc =
|
|
474
|
+
export const toDateUtc = Internal.toDateUtc;
|
|
672
475
|
/**
|
|
673
476
|
* Convert a `DateTime` to a `Date`, applying the time zone first.
|
|
674
477
|
*
|
|
675
478
|
* @since 3.6.0
|
|
676
479
|
* @category conversions
|
|
677
480
|
*/
|
|
678
|
-
export const toDate =
|
|
679
|
-
if (self._tag === "Utc") {
|
|
680
|
-
return new Date(self.epochMillis);
|
|
681
|
-
} else if (self.zone._tag === "Offset") {
|
|
682
|
-
return new Date(self.epochMillis + self.zone.offset);
|
|
683
|
-
} else if (self.adjustedEpochMillis !== undefined) {
|
|
684
|
-
return new Date(self.adjustedEpochMillis);
|
|
685
|
-
}
|
|
686
|
-
const parts = self.zone.format.formatToParts(self.epochMillis).filter(_ => _.type !== "literal");
|
|
687
|
-
const date = new Date(0);
|
|
688
|
-
date.setUTCFullYear(Number(parts[2].value), Number(parts[0].value) - 1, Number(parts[1].value));
|
|
689
|
-
date.setUTCHours(Number(parts[3].value), Number(parts[4].value), Number(parts[5].value), Number(parts[6].value));
|
|
690
|
-
self.adjustedEpochMillis = date.getTime();
|
|
691
|
-
return date;
|
|
692
|
-
};
|
|
481
|
+
export const toDate = Internal.toDate;
|
|
693
482
|
/**
|
|
694
483
|
* Calculate the time zone offset of a `DateTime.Zoned` in milliseconds.
|
|
695
484
|
*
|
|
696
485
|
* @since 3.6.0
|
|
697
486
|
* @category conversions
|
|
698
487
|
*/
|
|
699
|
-
export const zonedOffset =
|
|
700
|
-
const date = toDate(self);
|
|
701
|
-
return date.getTime() - toEpochMillis(self);
|
|
702
|
-
};
|
|
703
|
-
const offsetToString = offset => {
|
|
704
|
-
const abs = Math.abs(offset);
|
|
705
|
-
const hours = Math.floor(abs / (60 * 60 * 1000));
|
|
706
|
-
const minutes = Math.round(abs % (60 * 60 * 1000) / (60 * 1000));
|
|
707
|
-
return `${offset < 0 ? "-" : "+"}${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
|
|
708
|
-
};
|
|
488
|
+
export const zonedOffset = Internal.zonedOffset;
|
|
709
489
|
/**
|
|
710
490
|
* Calculate the time zone offset of a `DateTime` in milliseconds.
|
|
711
491
|
*
|
|
@@ -714,14 +494,14 @@ const offsetToString = offset => {
|
|
|
714
494
|
* @since 3.6.0
|
|
715
495
|
* @category conversions
|
|
716
496
|
*/
|
|
717
|
-
export const zonedOffsetIso =
|
|
497
|
+
export const zonedOffsetIso = Internal.zonedOffsetIso;
|
|
718
498
|
/**
|
|
719
499
|
* Get the milliseconds since the Unix epoch of a `DateTime`.
|
|
720
500
|
*
|
|
721
501
|
* @since 3.6.0
|
|
722
502
|
* @category conversions
|
|
723
503
|
*/
|
|
724
|
-
export const toEpochMillis =
|
|
504
|
+
export const toEpochMillis = Internal.toEpochMillis;
|
|
725
505
|
/**
|
|
726
506
|
* Remove the time aspect of a `DateTime`, first adjusting for the time
|
|
727
507
|
* zone. It will return a `DateTime.Utc` only containing the date.
|
|
@@ -729,6 +509,7 @@ export const toEpochMillis = self => self.epochMillis;
|
|
|
729
509
|
* @since 3.6.0
|
|
730
510
|
* @category conversions
|
|
731
511
|
* @example
|
|
512
|
+
* ```ts
|
|
732
513
|
* import { DateTime } from "effect"
|
|
733
514
|
*
|
|
734
515
|
* // returns "2024-01-01T00:00:00Z"
|
|
@@ -739,24 +520,12 @@ export const toEpochMillis = self => self.epochMillis;
|
|
|
739
520
|
* DateTime.removeTime,
|
|
740
521
|
* DateTime.formatIso
|
|
741
522
|
* )
|
|
523
|
+
* ```
|
|
742
524
|
*/
|
|
743
|
-
export const removeTime =
|
|
744
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
745
|
-
return makeUtc(date.getTime());
|
|
746
|
-
});
|
|
525
|
+
export const removeTime = Internal.removeTime;
|
|
747
526
|
// =============================================================================
|
|
748
527
|
// parts
|
|
749
528
|
// =============================================================================
|
|
750
|
-
const dateToParts = date => ({
|
|
751
|
-
millis: date.getUTCMilliseconds(),
|
|
752
|
-
seconds: date.getUTCSeconds(),
|
|
753
|
-
minutes: date.getUTCMinutes(),
|
|
754
|
-
hours: date.getUTCHours(),
|
|
755
|
-
day: date.getUTCDate(),
|
|
756
|
-
weekDay: date.getUTCDay(),
|
|
757
|
-
month: date.getUTCMonth() + 1,
|
|
758
|
-
year: date.getUTCFullYear()
|
|
759
|
-
});
|
|
760
529
|
/**
|
|
761
530
|
* Get the different parts of a `DateTime` as an object.
|
|
762
531
|
*
|
|
@@ -765,15 +534,7 @@ const dateToParts = date => ({
|
|
|
765
534
|
* @since 3.6.0
|
|
766
535
|
* @category parts
|
|
767
536
|
*/
|
|
768
|
-
export const toParts =
|
|
769
|
-
if (self._tag === "Utc") {
|
|
770
|
-
return toPartsUtc(self);
|
|
771
|
-
} else if (self.partsAdjusted !== undefined) {
|
|
772
|
-
return self.partsAdjusted;
|
|
773
|
-
}
|
|
774
|
-
self.partsAdjusted = withDate(self, dateToParts);
|
|
775
|
-
return self.partsAdjusted;
|
|
776
|
-
};
|
|
537
|
+
export const toParts = Internal.toParts;
|
|
777
538
|
/**
|
|
778
539
|
* Get the different parts of a `DateTime` as an object.
|
|
779
540
|
*
|
|
@@ -782,13 +543,7 @@ export const toParts = self => {
|
|
|
782
543
|
* @since 3.6.0
|
|
783
544
|
* @category parts
|
|
784
545
|
*/
|
|
785
|
-
export const toPartsUtc =
|
|
786
|
-
if (self.partsUtc !== undefined) {
|
|
787
|
-
return self.partsUtc;
|
|
788
|
-
}
|
|
789
|
-
self.partsUtc = withDateUtc(self, dateToParts);
|
|
790
|
-
return self.partsUtc;
|
|
791
|
-
};
|
|
546
|
+
export const toPartsUtc = Internal.toPartsUtc;
|
|
792
547
|
/**
|
|
793
548
|
* Get a part of a `DateTime` as a number.
|
|
794
549
|
*
|
|
@@ -797,13 +552,15 @@ export const toPartsUtc = self => {
|
|
|
797
552
|
* @since 3.6.0
|
|
798
553
|
* @category parts
|
|
799
554
|
* @example
|
|
555
|
+
* ```ts
|
|
800
556
|
* import { DateTime } from "effect"
|
|
801
557
|
*
|
|
802
558
|
* const now = DateTime.unsafeMake({ year: 2024 })
|
|
803
559
|
* const year = DateTime.getPartUtc(now, "year")
|
|
804
560
|
* assert.strictEqual(year, 2024)
|
|
561
|
+
* ```
|
|
805
562
|
*/
|
|
806
|
-
export const getPartUtc =
|
|
563
|
+
export const getPartUtc = Internal.getPartUtc;
|
|
807
564
|
/**
|
|
808
565
|
* Get a part of a `DateTime` as a number.
|
|
809
566
|
*
|
|
@@ -812,40 +569,15 @@ export const getPartUtc = /*#__PURE__*/dual(2, (self, part) => toPartsUtc(self)[
|
|
|
812
569
|
* @since 3.6.0
|
|
813
570
|
* @category parts
|
|
814
571
|
* @example
|
|
572
|
+
* ```ts
|
|
815
573
|
* import { DateTime } from "effect"
|
|
816
574
|
*
|
|
817
575
|
* const now = DateTime.unsafeMakeZoned({ year: 2024 }, { timeZone: "Europe/London" })
|
|
818
576
|
* const year = DateTime.getPart(now, "year")
|
|
819
577
|
* assert.strictEqual(year, 2024)
|
|
578
|
+
* ```
|
|
820
579
|
*/
|
|
821
|
-
export const getPart =
|
|
822
|
-
const setPartsDate = (date, parts) => {
|
|
823
|
-
if (parts.year !== undefined) {
|
|
824
|
-
date.setUTCFullYear(parts.year);
|
|
825
|
-
}
|
|
826
|
-
if (parts.month !== undefined) {
|
|
827
|
-
date.setUTCMonth(parts.month - 1);
|
|
828
|
-
}
|
|
829
|
-
if (parts.day !== undefined) {
|
|
830
|
-
date.setUTCDate(parts.day);
|
|
831
|
-
}
|
|
832
|
-
if (parts.weekDay !== undefined) {
|
|
833
|
-
const diff = parts.weekDay - date.getUTCDay();
|
|
834
|
-
date.setUTCDate(date.getUTCDate() + diff);
|
|
835
|
-
}
|
|
836
|
-
if (parts.hours !== undefined) {
|
|
837
|
-
date.setUTCHours(parts.hours);
|
|
838
|
-
}
|
|
839
|
-
if (parts.minutes !== undefined) {
|
|
840
|
-
date.setUTCMinutes(parts.minutes);
|
|
841
|
-
}
|
|
842
|
-
if (parts.seconds !== undefined) {
|
|
843
|
-
date.setUTCSeconds(parts.seconds);
|
|
844
|
-
}
|
|
845
|
-
if (parts.millis !== undefined) {
|
|
846
|
-
date.setUTCMilliseconds(parts.millis);
|
|
847
|
-
}
|
|
848
|
-
};
|
|
580
|
+
export const getPart = Internal.getPart;
|
|
849
581
|
/**
|
|
850
582
|
* Set the different parts of a `DateTime` as an object.
|
|
851
583
|
*
|
|
@@ -854,21 +586,21 @@ const setPartsDate = (date, parts) => {
|
|
|
854
586
|
* @since 3.6.0
|
|
855
587
|
* @category parts
|
|
856
588
|
*/
|
|
857
|
-
export const setParts =
|
|
589
|
+
export const setParts = Internal.setParts;
|
|
858
590
|
/**
|
|
859
591
|
* Set the different parts of a `DateTime` as an object.
|
|
860
592
|
*
|
|
861
593
|
* @since 3.6.0
|
|
862
594
|
* @category parts
|
|
863
595
|
*/
|
|
864
|
-
export const setPartsUtc =
|
|
596
|
+
export const setPartsUtc = Internal.setPartsUtc;
|
|
865
597
|
// =============================================================================
|
|
866
598
|
// current time zone
|
|
867
599
|
// =============================================================================
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
*/
|
|
600
|
+
// =============================================================================
|
|
601
|
+
// current time zone
|
|
602
|
+
// =============================================================================
|
|
603
|
+
/** @internal */
|
|
872
604
|
export class CurrentTimeZone extends /*#__PURE__*/Context.Tag("effect/DateTime/CurrentTimeZone")() {}
|
|
873
605
|
/**
|
|
874
606
|
* Set the time zone of a `DateTime` to the current time zone, which is
|
|
@@ -877,6 +609,7 @@ export class CurrentTimeZone extends /*#__PURE__*/Context.Tag("effect/DateTime/C
|
|
|
877
609
|
* @since 3.6.0
|
|
878
610
|
* @category current time zone
|
|
879
611
|
* @example
|
|
612
|
+
* ```ts
|
|
880
613
|
* import { DateTime, Effect } from "effect"
|
|
881
614
|
*
|
|
882
615
|
* Effect.gen(function* () {
|
|
@@ -885,6 +618,7 @@ export class CurrentTimeZone extends /*#__PURE__*/Context.Tag("effect/DateTime/C
|
|
|
885
618
|
* // set the time zone to "Europe/London"
|
|
886
619
|
* const zoned = yield* DateTime.setZoneCurrent(now)
|
|
887
620
|
* }).pipe(DateTime.withCurrentZoneNamed("Europe/London"))
|
|
621
|
+
* ```
|
|
888
622
|
*/
|
|
889
623
|
export const setZoneCurrent = self => Effect.map(CurrentTimeZone, zone => setZone(self, zone));
|
|
890
624
|
/**
|
|
@@ -893,6 +627,7 @@ export const setZoneCurrent = self => Effect.map(CurrentTimeZone, zone => setZon
|
|
|
893
627
|
* @since 3.6.0
|
|
894
628
|
* @category current time zone
|
|
895
629
|
* @example
|
|
630
|
+
* ```ts
|
|
896
631
|
* import { DateTime, Effect } from "effect"
|
|
897
632
|
*
|
|
898
633
|
* const zone = DateTime.zoneUnsafeMakeNamed("Europe/London")
|
|
@@ -900,6 +635,7 @@ export const setZoneCurrent = self => Effect.map(CurrentTimeZone, zone => setZon
|
|
|
900
635
|
* Effect.gen(function* () {
|
|
901
636
|
* const now = yield* DateTime.nowInCurrentZone
|
|
902
637
|
* }).pipe(DateTime.withCurrentZone(zone))
|
|
638
|
+
* ```
|
|
903
639
|
*/
|
|
904
640
|
export const withCurrentZone = /*#__PURE__*/dual(2, (effect, zone) => Effect.provideService(effect, CurrentTimeZone, zone));
|
|
905
641
|
/**
|
|
@@ -909,12 +645,14 @@ export const withCurrentZone = /*#__PURE__*/dual(2, (effect, zone) => Effect.pro
|
|
|
909
645
|
* @since 3.6.0
|
|
910
646
|
* @category current time zone
|
|
911
647
|
* @example
|
|
648
|
+
* ```ts
|
|
912
649
|
* import { DateTime, Effect } from "effect"
|
|
913
650
|
*
|
|
914
651
|
* Effect.gen(function* () {
|
|
915
652
|
* // will use the system's local time zone
|
|
916
653
|
* const now = yield* DateTime.nowInCurrentZone
|
|
917
654
|
* }).pipe(DateTime.withCurrentZoneLocal)
|
|
655
|
+
* ```
|
|
918
656
|
*/
|
|
919
657
|
export const withCurrentZoneLocal = effect => Effect.provideServiceEffect(effect, CurrentTimeZone, Effect.sync(zoneMakeLocal));
|
|
920
658
|
/**
|
|
@@ -923,12 +661,14 @@ export const withCurrentZoneLocal = effect => Effect.provideServiceEffect(effect
|
|
|
923
661
|
* @since 3.6.0
|
|
924
662
|
* @category current time zone
|
|
925
663
|
* @example
|
|
664
|
+
* ```ts
|
|
926
665
|
* import { DateTime, Effect } from "effect"
|
|
927
666
|
*
|
|
928
667
|
* Effect.gen(function* () {
|
|
929
668
|
* // will use the system's local time zone
|
|
930
669
|
* const now = yield* DateTime.nowInCurrentZone
|
|
931
670
|
* }).pipe(DateTime.withCurrentZoneOffset(3 * 60 * 60 * 1000))
|
|
671
|
+
* ```
|
|
932
672
|
*/
|
|
933
673
|
export const withCurrentZoneOffset = /*#__PURE__*/dual(2, (effect, offset) => Effect.provideService(effect, CurrentTimeZone, zoneMakeOffset(offset)));
|
|
934
674
|
/**
|
|
@@ -940,12 +680,14 @@ export const withCurrentZoneOffset = /*#__PURE__*/dual(2, (effect, offset) => Ef
|
|
|
940
680
|
* @since 3.6.0
|
|
941
681
|
* @category current time zone
|
|
942
682
|
* @example
|
|
683
|
+
* ```ts
|
|
943
684
|
* import { DateTime, Effect } from "effect"
|
|
944
685
|
*
|
|
945
686
|
* Effect.gen(function* () {
|
|
946
687
|
* // will use the "Europe/London" time zone
|
|
947
688
|
* const now = yield* DateTime.nowInCurrentZone
|
|
948
689
|
* }).pipe(DateTime.withCurrentZoneNamed("Europe/London"))
|
|
690
|
+
* ```
|
|
949
691
|
*/
|
|
950
692
|
export const withCurrentZoneNamed = /*#__PURE__*/dual(2, (effect, zone) => Effect.provideServiceEffect(effect, CurrentTimeZone, zoneMakeNamedEffect(zone)));
|
|
951
693
|
/**
|
|
@@ -954,70 +696,19 @@ export const withCurrentZoneNamed = /*#__PURE__*/dual(2, (effect, zone) => Effec
|
|
|
954
696
|
* @since 3.6.0
|
|
955
697
|
* @category current time zone
|
|
956
698
|
* @example
|
|
699
|
+
* ```ts
|
|
957
700
|
* import { DateTime, Effect } from "effect"
|
|
958
701
|
*
|
|
959
702
|
* Effect.gen(function* () {
|
|
960
703
|
* // will use the "Europe/London" time zone
|
|
961
704
|
* const now = yield* DateTime.nowInCurrentZone
|
|
962
705
|
* }).pipe(DateTime.withCurrentZoneNamed("Europe/London"))
|
|
706
|
+
* ```
|
|
963
707
|
*/
|
|
964
708
|
export const nowInCurrentZone = /*#__PURE__*/Effect.flatMap(now, setZoneCurrent);
|
|
965
|
-
/**
|
|
966
|
-
* Create a Layer from the given time zone.
|
|
967
|
-
*
|
|
968
|
-
* @since 3.6.0
|
|
969
|
-
* @category current time zone
|
|
970
|
-
*/
|
|
971
|
-
export const layerCurrentZone = zone => Layer.succeed(CurrentTimeZone, zone);
|
|
972
|
-
/**
|
|
973
|
-
* Create a Layer from the given time zone offset.
|
|
974
|
-
*
|
|
975
|
-
* @since 3.6.0
|
|
976
|
-
* @category current time zone
|
|
977
|
-
*/
|
|
978
|
-
export const layerCurrentZoneOffset = offset => Layer.succeed(CurrentTimeZone, zoneMakeOffset(offset));
|
|
979
|
-
/**
|
|
980
|
-
* Create a Layer from the given IANA time zone identifier.
|
|
981
|
-
*
|
|
982
|
-
* @since 3.6.0
|
|
983
|
-
* @category current time zone
|
|
984
|
-
*/
|
|
985
|
-
export const layerCurrentZoneNamed = zoneId => Layer.effect(CurrentTimeZone, zoneMakeNamedEffect(zoneId));
|
|
986
|
-
/**
|
|
987
|
-
* Create a Layer from the systems local time zone.
|
|
988
|
-
*
|
|
989
|
-
* @since 3.6.0
|
|
990
|
-
* @category current time zone
|
|
991
|
-
*/
|
|
992
|
-
export const layerCurrentZoneLocal = /*#__PURE__*/Layer.sync(CurrentTimeZone, zoneMakeLocal);
|
|
993
709
|
// =============================================================================
|
|
994
710
|
// mapping
|
|
995
711
|
// =============================================================================
|
|
996
|
-
const makeZonedFromAdjusted = (adjustedMillis, zone) => {
|
|
997
|
-
const offset = zone._tag === "Offset" ? zone.offset : calculateNamedOffset(adjustedMillis, zone);
|
|
998
|
-
return makeZonedProto(adjustedMillis - offset, zone);
|
|
999
|
-
};
|
|
1000
|
-
const offsetRegex = /([+-])(\d{2}):(\d{2})$/;
|
|
1001
|
-
const parseOffset = offset => {
|
|
1002
|
-
const match = offsetRegex.exec(offset);
|
|
1003
|
-
if (match === null) {
|
|
1004
|
-
return null;
|
|
1005
|
-
}
|
|
1006
|
-
const [, sign, hours, minutes] = match;
|
|
1007
|
-
return (sign === "+" ? 1 : -1) * (Number(hours) * 60 + Number(minutes)) * 60 * 1000;
|
|
1008
|
-
};
|
|
1009
|
-
const calculateNamedOffset = (adjustedMillis, zone) => {
|
|
1010
|
-
const offset = zone.format.formatToParts(adjustedMillis).find(_ => _.type === "timeZoneName")?.value ?? "";
|
|
1011
|
-
if (offset === "GMT") {
|
|
1012
|
-
return 0;
|
|
1013
|
-
}
|
|
1014
|
-
const result = parseOffset(offset);
|
|
1015
|
-
if (result === null) {
|
|
1016
|
-
// fallback to using the adjusted date
|
|
1017
|
-
return zonedOffset(makeZonedProto(adjustedMillis, zone));
|
|
1018
|
-
}
|
|
1019
|
-
return result;
|
|
1020
|
-
};
|
|
1021
712
|
/**
|
|
1022
713
|
* Modify a `DateTime` by applying a function to a cloned `Date` instance.
|
|
1023
714
|
*
|
|
@@ -1027,28 +718,14 @@ const calculateNamedOffset = (adjustedMillis, zone) => {
|
|
|
1027
718
|
* @since 3.6.0
|
|
1028
719
|
* @category mapping
|
|
1029
720
|
*/
|
|
1030
|
-
export const mutate =
|
|
1031
|
-
if (self._tag === "Utc") {
|
|
1032
|
-
const date = toDateUtc(self);
|
|
1033
|
-
f(date);
|
|
1034
|
-
return makeUtc(date.getTime());
|
|
1035
|
-
}
|
|
1036
|
-
const adjustedDate = toDate(self);
|
|
1037
|
-
const newAdjustedDate = new Date(adjustedDate.getTime());
|
|
1038
|
-
f(newAdjustedDate);
|
|
1039
|
-
return makeZonedFromAdjusted(newAdjustedDate.getTime(), self.zone);
|
|
1040
|
-
});
|
|
721
|
+
export const mutate = Internal.mutate;
|
|
1041
722
|
/**
|
|
1042
723
|
* Modify a `DateTime` by applying a function to a cloned UTC `Date` instance.
|
|
1043
724
|
*
|
|
1044
725
|
* @since 3.6.0
|
|
1045
726
|
* @category mapping
|
|
1046
727
|
*/
|
|
1047
|
-
export const mutateUtc =
|
|
1048
|
-
const date = new Date(millis);
|
|
1049
|
-
f(date);
|
|
1050
|
-
return date.getTime();
|
|
1051
|
-
}));
|
|
728
|
+
export const mutateUtc = Internal.mutateUtc;
|
|
1052
729
|
/**
|
|
1053
730
|
* Transform a `DateTime` by applying a function to the number of milliseconds
|
|
1054
731
|
* since the Unix epoch.
|
|
@@ -1056,17 +733,16 @@ export const mutateUtc = /*#__PURE__*/dual(2, (self, f) => mapEpochMillis(self,
|
|
|
1056
733
|
* @since 3.6.0
|
|
1057
734
|
* @category mapping
|
|
1058
735
|
* @example
|
|
736
|
+
* ```ts
|
|
1059
737
|
* import { DateTime } from "effect"
|
|
1060
738
|
*
|
|
1061
739
|
* // add 10 milliseconds
|
|
1062
740
|
* DateTime.unsafeMake(0).pipe(
|
|
1063
741
|
* DateTime.mapEpochMillis((millis) => millis + 10)
|
|
1064
742
|
* )
|
|
743
|
+
* ```
|
|
1065
744
|
*/
|
|
1066
|
-
export const mapEpochMillis =
|
|
1067
|
-
const millis = f(toEpochMillis(self));
|
|
1068
|
-
return self._tag === "Utc" ? makeUtc(millis) : makeZonedProto(millis, self.zone);
|
|
1069
|
-
});
|
|
745
|
+
export const mapEpochMillis = Internal.mapEpochMillis;
|
|
1070
746
|
/**
|
|
1071
747
|
* Using the time zone adjusted `Date`, apply a function to the `Date` and
|
|
1072
748
|
* return the result.
|
|
@@ -1074,14 +750,16 @@ export const mapEpochMillis = /*#__PURE__*/dual(2, (self, f) => {
|
|
|
1074
750
|
* @since 3.6.0
|
|
1075
751
|
* @category mapping
|
|
1076
752
|
* @example
|
|
753
|
+
* ```ts
|
|
1077
754
|
* import { DateTime } from "effect"
|
|
1078
755
|
*
|
|
1079
756
|
* // get the time zone adjusted date in milliseconds
|
|
1080
757
|
* DateTime.unsafeMakeZoned(0, { timeZone: "Europe/London" }).pipe(
|
|
1081
758
|
* DateTime.withDate((date) => date.getTime())
|
|
1082
759
|
* )
|
|
760
|
+
* ```
|
|
1083
761
|
*/
|
|
1084
|
-
export const withDate =
|
|
762
|
+
export const withDate = Internal.withDate;
|
|
1085
763
|
/**
|
|
1086
764
|
* Using the time zone adjusted `Date`, apply a function to the `Date` and
|
|
1087
765
|
* return the result.
|
|
@@ -1089,19 +767,21 @@ export const withDate = /*#__PURE__*/dual(2, (self, f) => f(toDate(self)));
|
|
|
1089
767
|
* @since 3.6.0
|
|
1090
768
|
* @category mapping
|
|
1091
769
|
* @example
|
|
770
|
+
* ```ts
|
|
1092
771
|
* import { DateTime } from "effect"
|
|
1093
772
|
*
|
|
1094
773
|
* // get the date in milliseconds
|
|
1095
774
|
* DateTime.unsafeMake(0).pipe(
|
|
1096
775
|
* DateTime.withDateUtc((date) => date.getTime())
|
|
1097
776
|
* )
|
|
777
|
+
* ```
|
|
1098
778
|
*/
|
|
1099
|
-
export const withDateUtc =
|
|
779
|
+
export const withDateUtc = Internal.withDateUtc;
|
|
1100
780
|
/**
|
|
1101
781
|
* @since 3.6.0
|
|
1102
782
|
* @category mapping
|
|
1103
783
|
*/
|
|
1104
|
-
export const match =
|
|
784
|
+
export const match = Internal.match;
|
|
1105
785
|
// =============================================================================
|
|
1106
786
|
// math
|
|
1107
787
|
// =============================================================================
|
|
@@ -1111,31 +791,32 @@ export const match = /*#__PURE__*/dual(2, (self, options) => self._tag === "Utc"
|
|
|
1111
791
|
* @since 3.6.0
|
|
1112
792
|
* @category math
|
|
1113
793
|
* @example
|
|
794
|
+
* ```ts
|
|
1114
795
|
* import { DateTime } from "effect"
|
|
1115
796
|
*
|
|
1116
797
|
* // add 5 minutes
|
|
1117
798
|
* DateTime.unsafeMake(0).pipe(
|
|
1118
799
|
* DateTime.addDuration("5 minutes")
|
|
1119
800
|
* )
|
|
801
|
+
* ```
|
|
1120
802
|
*/
|
|
1121
|
-
export const addDuration =
|
|
803
|
+
export const addDuration = Internal.addDuration;
|
|
1122
804
|
/**
|
|
1123
805
|
* Subtract the given `Duration` from a `DateTime`.
|
|
1124
806
|
*
|
|
1125
807
|
* @since 3.6.0
|
|
1126
808
|
* @category math
|
|
1127
809
|
* @example
|
|
810
|
+
* ```ts
|
|
1128
811
|
* import { DateTime } from "effect"
|
|
1129
812
|
*
|
|
1130
813
|
* // subtract 5 minutes
|
|
1131
814
|
* DateTime.unsafeMake(0).pipe(
|
|
1132
815
|
* DateTime.subtractDuration("5 minutes")
|
|
1133
816
|
* )
|
|
817
|
+
* ```
|
|
1134
818
|
*/
|
|
1135
|
-
export const subtractDuration =
|
|
1136
|
-
const addMillis = (date, amount) => {
|
|
1137
|
-
date.setTime(date.getTime() + amount);
|
|
1138
|
-
};
|
|
819
|
+
export const subtractDuration = Internal.subtractDuration;
|
|
1139
820
|
/**
|
|
1140
821
|
* Add the given `amount` of `unit`'s to a `DateTime`.
|
|
1141
822
|
*
|
|
@@ -1145,113 +826,32 @@ const addMillis = (date, amount) => {
|
|
|
1145
826
|
* @since 3.6.0
|
|
1146
827
|
* @category math
|
|
1147
828
|
* @example
|
|
829
|
+
* ```ts
|
|
1148
830
|
* import { DateTime } from "effect"
|
|
1149
831
|
*
|
|
1150
832
|
* // add 5 minutes
|
|
1151
833
|
* DateTime.unsafeMake(0).pipe(
|
|
1152
834
|
* DateTime.add({ minutes: 5 })
|
|
1153
835
|
* )
|
|
836
|
+
* ```
|
|
1154
837
|
*/
|
|
1155
|
-
export const add =
|
|
1156
|
-
if (parts.millis) {
|
|
1157
|
-
addMillis(date, parts.millis);
|
|
1158
|
-
}
|
|
1159
|
-
if (parts.seconds) {
|
|
1160
|
-
addMillis(date, parts.seconds * 1000);
|
|
1161
|
-
}
|
|
1162
|
-
if (parts.minutes) {
|
|
1163
|
-
addMillis(date, parts.minutes * 60 * 1000);
|
|
1164
|
-
}
|
|
1165
|
-
if (parts.hours) {
|
|
1166
|
-
addMillis(date, parts.hours * 60 * 60 * 1000);
|
|
1167
|
-
}
|
|
1168
|
-
if (parts.days) {
|
|
1169
|
-
date.setUTCDate(date.getUTCDate() + parts.days);
|
|
1170
|
-
}
|
|
1171
|
-
if (parts.weeks) {
|
|
1172
|
-
date.setUTCDate(date.getUTCDate() + parts.weeks * 7);
|
|
1173
|
-
}
|
|
1174
|
-
if (parts.months) {
|
|
1175
|
-
const day = date.getUTCDate();
|
|
1176
|
-
date.setUTCMonth(date.getUTCMonth() + parts.months + 1, 0);
|
|
1177
|
-
if (day < date.getUTCDate()) {
|
|
1178
|
-
date.setUTCDate(day);
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
if (parts.years) {
|
|
1182
|
-
const day = date.getUTCDate();
|
|
1183
|
-
const month = date.getUTCMonth();
|
|
1184
|
-
date.setUTCFullYear(date.getUTCFullYear() + parts.years, month + 1, 0);
|
|
1185
|
-
if (day < date.getUTCDate()) {
|
|
1186
|
-
date.setUTCDate(day);
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
}));
|
|
838
|
+
export const add = Internal.add;
|
|
1190
839
|
/**
|
|
1191
840
|
* Subtract the given `amount` of `unit`'s from a `DateTime`.
|
|
1192
841
|
*
|
|
1193
842
|
* @since 3.6.0
|
|
1194
843
|
* @category math
|
|
1195
844
|
* @example
|
|
845
|
+
* ```ts
|
|
1196
846
|
* import { DateTime } from "effect"
|
|
1197
847
|
*
|
|
1198
848
|
* // subtract 5 minutes
|
|
1199
849
|
* DateTime.unsafeMake(0).pipe(
|
|
1200
850
|
* DateTime.subtract({ minutes: 5 })
|
|
1201
851
|
* )
|
|
852
|
+
* ```
|
|
1202
853
|
*/
|
|
1203
|
-
export const subtract =
|
|
1204
|
-
const newParts = {};
|
|
1205
|
-
for (const key in parts) {
|
|
1206
|
-
newParts[key] = -1 * parts[key];
|
|
1207
|
-
}
|
|
1208
|
-
return add(self, newParts);
|
|
1209
|
-
});
|
|
1210
|
-
function startOfDate(date, part, options) {
|
|
1211
|
-
switch (part) {
|
|
1212
|
-
case "second":
|
|
1213
|
-
{
|
|
1214
|
-
date.setUTCMilliseconds(0);
|
|
1215
|
-
break;
|
|
1216
|
-
}
|
|
1217
|
-
case "minute":
|
|
1218
|
-
{
|
|
1219
|
-
date.setUTCSeconds(0, 0);
|
|
1220
|
-
break;
|
|
1221
|
-
}
|
|
1222
|
-
case "hour":
|
|
1223
|
-
{
|
|
1224
|
-
date.setUTCMinutes(0, 0, 0);
|
|
1225
|
-
break;
|
|
1226
|
-
}
|
|
1227
|
-
case "day":
|
|
1228
|
-
{
|
|
1229
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
1230
|
-
break;
|
|
1231
|
-
}
|
|
1232
|
-
case "week":
|
|
1233
|
-
{
|
|
1234
|
-
const weekStartsOn = options?.weekStartsOn ?? 0;
|
|
1235
|
-
const day = date.getUTCDay();
|
|
1236
|
-
const diff = (day - weekStartsOn + 7) % 7;
|
|
1237
|
-
date.setUTCDate(date.getUTCDate() - diff);
|
|
1238
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
1239
|
-
break;
|
|
1240
|
-
}
|
|
1241
|
-
case "month":
|
|
1242
|
-
{
|
|
1243
|
-
date.setUTCDate(1);
|
|
1244
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
1245
|
-
break;
|
|
1246
|
-
}
|
|
1247
|
-
case "year":
|
|
1248
|
-
{
|
|
1249
|
-
date.setUTCMonth(0, 1);
|
|
1250
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
1251
|
-
break;
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
854
|
+
export const subtract = Internal.subtract;
|
|
1255
855
|
/**
|
|
1256
856
|
* Converts a `DateTime` to the start of the given `part`.
|
|
1257
857
|
*
|
|
@@ -1261,6 +861,7 @@ function startOfDate(date, part, options) {
|
|
|
1261
861
|
* @since 3.6.0
|
|
1262
862
|
* @category math
|
|
1263
863
|
* @example
|
|
864
|
+
* ```ts
|
|
1264
865
|
* import { DateTime } from "effect"
|
|
1265
866
|
*
|
|
1266
867
|
* // returns "2024-01-01T00:00:00Z"
|
|
@@ -1268,53 +869,9 @@ function startOfDate(date, part, options) {
|
|
|
1268
869
|
* DateTime.startOf("day"),
|
|
1269
870
|
* DateTime.formatIso
|
|
1270
871
|
* )
|
|
872
|
+
* ```
|
|
1271
873
|
*/
|
|
1272
|
-
export const startOf =
|
|
1273
|
-
function endOfDate(date, part, options) {
|
|
1274
|
-
switch (part) {
|
|
1275
|
-
case "second":
|
|
1276
|
-
{
|
|
1277
|
-
date.setUTCMilliseconds(999);
|
|
1278
|
-
break;
|
|
1279
|
-
}
|
|
1280
|
-
case "minute":
|
|
1281
|
-
{
|
|
1282
|
-
date.setUTCSeconds(59, 999);
|
|
1283
|
-
break;
|
|
1284
|
-
}
|
|
1285
|
-
case "hour":
|
|
1286
|
-
{
|
|
1287
|
-
date.setUTCMinutes(59, 59, 999);
|
|
1288
|
-
break;
|
|
1289
|
-
}
|
|
1290
|
-
case "day":
|
|
1291
|
-
{
|
|
1292
|
-
date.setUTCHours(23, 59, 59, 999);
|
|
1293
|
-
break;
|
|
1294
|
-
}
|
|
1295
|
-
case "week":
|
|
1296
|
-
{
|
|
1297
|
-
const weekStartsOn = options?.weekStartsOn ?? 0;
|
|
1298
|
-
const day = date.getUTCDay();
|
|
1299
|
-
const diff = (day - weekStartsOn + 7) % 7;
|
|
1300
|
-
date.setUTCDate(date.getUTCDate() - diff + 6);
|
|
1301
|
-
date.setUTCHours(23, 59, 59, 999);
|
|
1302
|
-
break;
|
|
1303
|
-
}
|
|
1304
|
-
case "month":
|
|
1305
|
-
{
|
|
1306
|
-
date.setUTCMonth(date.getUTCMonth() + 1, 0);
|
|
1307
|
-
date.setUTCHours(23, 59, 59, 999);
|
|
1308
|
-
break;
|
|
1309
|
-
}
|
|
1310
|
-
case "year":
|
|
1311
|
-
{
|
|
1312
|
-
date.setUTCMonth(11, 31);
|
|
1313
|
-
date.setUTCHours(23, 59, 59, 999);
|
|
1314
|
-
break;
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
874
|
+
export const startOf = Internal.startOf;
|
|
1318
875
|
/**
|
|
1319
876
|
* Converts a `DateTime` to the end of the given `part`.
|
|
1320
877
|
*
|
|
@@ -1324,6 +881,7 @@ function endOfDate(date, part, options) {
|
|
|
1324
881
|
* @since 3.6.0
|
|
1325
882
|
* @category math
|
|
1326
883
|
* @example
|
|
884
|
+
* ```ts
|
|
1327
885
|
* import { DateTime } from "effect"
|
|
1328
886
|
*
|
|
1329
887
|
* // returns "2024-01-01T23:59:59.999Z"
|
|
@@ -1331,8 +889,9 @@ function endOfDate(date, part, options) {
|
|
|
1331
889
|
* DateTime.endOf("day"),
|
|
1332
890
|
* DateTime.formatIso
|
|
1333
891
|
* )
|
|
892
|
+
* ```
|
|
1334
893
|
*/
|
|
1335
|
-
export const endOf =
|
|
894
|
+
export const endOf = Internal.endOf;
|
|
1336
895
|
/**
|
|
1337
896
|
* Converts a `DateTime` to the nearest given `part`.
|
|
1338
897
|
*
|
|
@@ -1342,6 +901,7 @@ export const endOf = /*#__PURE__*/dual(isDateTimeArgs, (self, part, options) =>
|
|
|
1342
901
|
* @since 3.6.0
|
|
1343
902
|
* @category math
|
|
1344
903
|
* @example
|
|
904
|
+
* ```ts
|
|
1345
905
|
* import { DateTime } from "effect"
|
|
1346
906
|
*
|
|
1347
907
|
* // returns "2024-01-02T00:00:00Z"
|
|
@@ -1349,33 +909,12 @@ export const endOf = /*#__PURE__*/dual(isDateTimeArgs, (self, part, options) =>
|
|
|
1349
909
|
* DateTime.nearest("day"),
|
|
1350
910
|
* DateTime.formatIso
|
|
1351
911
|
* )
|
|
912
|
+
* ```
|
|
1352
913
|
*/
|
|
1353
|
-
export const nearest =
|
|
1354
|
-
if (part === "milli") return;
|
|
1355
|
-
const millis = date.getTime();
|
|
1356
|
-
const start = new Date(millis);
|
|
1357
|
-
startOfDate(start, part, options);
|
|
1358
|
-
const startMillis = start.getTime();
|
|
1359
|
-
const end = new Date(millis);
|
|
1360
|
-
endOfDate(end, part, options);
|
|
1361
|
-
const endMillis = end.getTime() + 1;
|
|
1362
|
-
const diffStart = millis - startMillis;
|
|
1363
|
-
const diffEnd = endMillis - millis;
|
|
1364
|
-
if (diffStart < diffEnd) {
|
|
1365
|
-
date.setTime(startMillis);
|
|
1366
|
-
} else {
|
|
1367
|
-
date.setTime(endMillis);
|
|
1368
|
-
}
|
|
1369
|
-
}));
|
|
914
|
+
export const nearest = Internal.nearest;
|
|
1370
915
|
// =============================================================================
|
|
1371
916
|
// formatting
|
|
1372
917
|
// =============================================================================
|
|
1373
|
-
const intlTimeZone = self => {
|
|
1374
|
-
if (self._tag === "Named") {
|
|
1375
|
-
return self.id;
|
|
1376
|
-
}
|
|
1377
|
-
return offsetToString(self.offset);
|
|
1378
|
-
};
|
|
1379
918
|
/**
|
|
1380
919
|
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
1381
920
|
*
|
|
@@ -1387,19 +926,7 @@ const intlTimeZone = self => {
|
|
|
1387
926
|
* @since 3.6.0
|
|
1388
927
|
* @category formatting
|
|
1389
928
|
*/
|
|
1390
|
-
export const format =
|
|
1391
|
-
try {
|
|
1392
|
-
return new Intl.DateTimeFormat(options?.locale, {
|
|
1393
|
-
timeZone: self._tag === "Utc" ? "UTC" : intlTimeZone(self.zone),
|
|
1394
|
-
...options
|
|
1395
|
-
}).format(self.epochMillis);
|
|
1396
|
-
} catch (_) {
|
|
1397
|
-
return new Intl.DateTimeFormat(options?.locale, {
|
|
1398
|
-
timeZone: "UTC",
|
|
1399
|
-
...options
|
|
1400
|
-
}).format(toDate(self));
|
|
1401
|
-
}
|
|
1402
|
-
});
|
|
929
|
+
export const format = Internal.format;
|
|
1403
930
|
/**
|
|
1404
931
|
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
1405
932
|
*
|
|
@@ -1408,7 +935,7 @@ export const format = /*#__PURE__*/dual(isDateTimeArgs, (self, options) => {
|
|
|
1408
935
|
* @since 3.6.0
|
|
1409
936
|
* @category formatting
|
|
1410
937
|
*/
|
|
1411
|
-
export const formatLocal =
|
|
938
|
+
export const formatLocal = Internal.formatLocal;
|
|
1412
939
|
/**
|
|
1413
940
|
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
1414
941
|
*
|
|
@@ -1417,48 +944,42 @@ export const formatLocal = /*#__PURE__*/dual(isDateTimeArgs, (self, options) =>
|
|
|
1417
944
|
* @since 3.6.0
|
|
1418
945
|
* @category formatting
|
|
1419
946
|
*/
|
|
1420
|
-
export const formatUtc =
|
|
1421
|
-
...options,
|
|
1422
|
-
timeZone: "UTC"
|
|
1423
|
-
}).format(self.epochMillis));
|
|
947
|
+
export const formatUtc = Internal.formatUtc;
|
|
1424
948
|
/**
|
|
1425
949
|
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
1426
950
|
*
|
|
1427
951
|
* @since 3.6.0
|
|
1428
952
|
* @category formatting
|
|
1429
953
|
*/
|
|
1430
|
-
export const formatIntl =
|
|
954
|
+
export const formatIntl = Internal.formatIntl;
|
|
1431
955
|
/**
|
|
1432
956
|
* Format a `DateTime` as a UTC ISO string.
|
|
1433
957
|
*
|
|
1434
958
|
* @since 3.6.0
|
|
1435
959
|
* @category formatting
|
|
1436
960
|
*/
|
|
1437
|
-
export const formatIso =
|
|
961
|
+
export const formatIso = Internal.formatIso;
|
|
1438
962
|
/**
|
|
1439
963
|
* Format a `DateTime` as a time zone adjusted ISO date string.
|
|
1440
964
|
*
|
|
1441
965
|
* @since 3.6.0
|
|
1442
966
|
* @category formatting
|
|
1443
967
|
*/
|
|
1444
|
-
export const formatIsoDate =
|
|
968
|
+
export const formatIsoDate = Internal.formatIsoDate;
|
|
1445
969
|
/**
|
|
1446
970
|
* Format a `DateTime` as a UTC ISO date string.
|
|
1447
971
|
*
|
|
1448
972
|
* @since 3.6.0
|
|
1449
973
|
* @category formatting
|
|
1450
974
|
*/
|
|
1451
|
-
export const formatIsoDateUtc =
|
|
975
|
+
export const formatIsoDateUtc = Internal.formatIsoDateUtc;
|
|
1452
976
|
/**
|
|
1453
977
|
* Format a `DateTime.Zoned` as a ISO string with an offset.
|
|
1454
978
|
*
|
|
1455
979
|
* @since 3.6.0
|
|
1456
980
|
* @category formatting
|
|
1457
981
|
*/
|
|
1458
|
-
export const formatIsoOffset =
|
|
1459
|
-
const date = toDate(self);
|
|
1460
|
-
return self._tag === "Utc" ? date.toISOString() : `${date.toISOString().slice(0, -1)}${zonedOffsetIso(self)}`;
|
|
1461
|
-
};
|
|
982
|
+
export const formatIsoOffset = Internal.formatIsoOffset;
|
|
1462
983
|
/**
|
|
1463
984
|
* Format a `DateTime.Zoned` as a string.
|
|
1464
985
|
*
|
|
@@ -1467,5 +988,33 @@ export const formatIsoOffset = self => {
|
|
|
1467
988
|
* @since 3.6.0
|
|
1468
989
|
* @category formatting
|
|
1469
990
|
*/
|
|
1470
|
-
export const formatIsoZoned =
|
|
991
|
+
export const formatIsoZoned = Internal.formatIsoZoned;
|
|
992
|
+
/**
|
|
993
|
+
* Create a Layer from the given time zone.
|
|
994
|
+
*
|
|
995
|
+
* @since 3.6.0
|
|
996
|
+
* @category current time zone
|
|
997
|
+
*/
|
|
998
|
+
export const layerCurrentZone = zone => Layer.succeed(CurrentTimeZone, zone);
|
|
999
|
+
/**
|
|
1000
|
+
* Create a Layer from the given time zone offset.
|
|
1001
|
+
*
|
|
1002
|
+
* @since 3.6.0
|
|
1003
|
+
* @category current time zone
|
|
1004
|
+
*/
|
|
1005
|
+
export const layerCurrentZoneOffset = offset => Layer.succeed(CurrentTimeZone, Internal.zoneMakeOffset(offset));
|
|
1006
|
+
/**
|
|
1007
|
+
* Create a Layer from the given IANA time zone identifier.
|
|
1008
|
+
*
|
|
1009
|
+
* @since 3.6.0
|
|
1010
|
+
* @category current time zone
|
|
1011
|
+
*/
|
|
1012
|
+
export const layerCurrentZoneNamed = zoneId => Layer.effect(CurrentTimeZone, Internal.zoneMakeNamedEffect(zoneId));
|
|
1013
|
+
/**
|
|
1014
|
+
* Create a Layer from the systems local time zone.
|
|
1015
|
+
*
|
|
1016
|
+
* @since 3.6.0
|
|
1017
|
+
* @category current time zone
|
|
1018
|
+
*/
|
|
1019
|
+
export const layerCurrentZoneLocal = /*#__PURE__*/Layer.sync(CurrentTimeZone, zoneMakeLocal);
|
|
1471
1020
|
//# sourceMappingURL=DateTime.js.map
|