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/src/DateTime.ts
CHANGED
|
@@ -1,31 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 3.6.0
|
|
3
3
|
*/
|
|
4
|
-
import { IllegalArgumentException } from "./Cause.js"
|
|
5
|
-
import * as Clock from "./Clock.js"
|
|
4
|
+
import type { IllegalArgumentException } from "./Cause.js"
|
|
6
5
|
import * as Context from "./Context.js"
|
|
7
|
-
import * as Duration from "./Duration.js"
|
|
6
|
+
import type * as Duration from "./Duration.js"
|
|
8
7
|
import * as Effect from "./Effect.js"
|
|
9
|
-
import * as Either from "./Either.js"
|
|
10
|
-
import * as
|
|
11
|
-
import
|
|
12
|
-
import type {
|
|
13
|
-
import
|
|
14
|
-
import { globalValue } from "./GlobalValue.js"
|
|
15
|
-
import * as Hash from "./Hash.js"
|
|
16
|
-
import * as Inspectable from "./Inspectable.js"
|
|
8
|
+
import type * as Either from "./Either.js"
|
|
9
|
+
import type * as equivalence from "./Equivalence.js"
|
|
10
|
+
import { dual, type LazyArg } from "./Function.js"
|
|
11
|
+
import type { Inspectable } from "./Inspectable.js"
|
|
12
|
+
import * as Internal from "./internal/dateTime.js"
|
|
17
13
|
import * as Layer from "./Layer.js"
|
|
18
|
-
import * as Option from "./Option.js"
|
|
19
|
-
import * as order from "./Order.js"
|
|
20
|
-
import {
|
|
21
|
-
import * as Predicate from "./Predicate.js"
|
|
22
|
-
import type { Mutable } from "./Types.js"
|
|
14
|
+
import type * as Option from "./Option.js"
|
|
15
|
+
import type * as order from "./Order.js"
|
|
16
|
+
import type { Pipeable } from "./Pipeable.js"
|
|
23
17
|
|
|
24
18
|
/**
|
|
25
19
|
* @since 3.6.0
|
|
26
20
|
* @category type ids
|
|
27
21
|
*/
|
|
28
|
-
export const TypeId: unique symbol =
|
|
22
|
+
export const TypeId: unique symbol = Internal.TypeId
|
|
29
23
|
|
|
30
24
|
/**
|
|
31
25
|
* @since 3.6.0
|
|
@@ -168,7 +162,7 @@ export declare namespace DateTime {
|
|
|
168
162
|
* @since 3.6.0
|
|
169
163
|
* @category models
|
|
170
164
|
*/
|
|
171
|
-
export interface Proto extends Pipeable, Inspectable
|
|
165
|
+
export interface Proto extends Pipeable, Inspectable {
|
|
172
166
|
readonly [TypeId]: TypeId
|
|
173
167
|
}
|
|
174
168
|
}
|
|
@@ -177,7 +171,7 @@ export declare namespace DateTime {
|
|
|
177
171
|
* @since 3.6.0
|
|
178
172
|
* @category type ids
|
|
179
173
|
*/
|
|
180
|
-
export const TimeZoneTypeId: unique symbol =
|
|
174
|
+
export const TimeZoneTypeId: unique symbol = Internal.TimeZoneTypeId
|
|
181
175
|
|
|
182
176
|
/**
|
|
183
177
|
* @since 3.6.0
|
|
@@ -200,7 +194,7 @@ export declare namespace TimeZone {
|
|
|
200
194
|
* @since 3.6.0
|
|
201
195
|
* @category models
|
|
202
196
|
*/
|
|
203
|
-
export interface Proto extends Inspectable
|
|
197
|
+
export interface Proto extends Inspectable {
|
|
204
198
|
readonly [TimeZoneTypeId]: TimeZoneTypeId
|
|
205
199
|
}
|
|
206
200
|
|
|
@@ -225,109 +219,6 @@ export declare namespace TimeZone {
|
|
|
225
219
|
}
|
|
226
220
|
}
|
|
227
221
|
|
|
228
|
-
const Proto = {
|
|
229
|
-
[TypeId]: TypeId,
|
|
230
|
-
pipe() {
|
|
231
|
-
return pipeArguments(this, arguments)
|
|
232
|
-
},
|
|
233
|
-
[Inspectable.NodeInspectSymbol](this: DateTime) {
|
|
234
|
-
return this.toString()
|
|
235
|
-
},
|
|
236
|
-
toJSON(this: DateTime) {
|
|
237
|
-
return toDateUtc(this).toJSON()
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const ProtoUtc = {
|
|
242
|
-
...Proto,
|
|
243
|
-
_tag: "Utc",
|
|
244
|
-
[Hash.symbol](this: Utc) {
|
|
245
|
-
return Hash.cached(this, Hash.number(this.epochMillis))
|
|
246
|
-
},
|
|
247
|
-
[Equal.symbol](this: Utc, that: unknown) {
|
|
248
|
-
return isDateTime(that) && that._tag === "Utc" && this.epochMillis === that.epochMillis
|
|
249
|
-
},
|
|
250
|
-
toString(this: Utc) {
|
|
251
|
-
return `DateTime.Utc(${toDateUtc(this).toJSON()})`
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const ProtoZoned = {
|
|
256
|
-
...Proto,
|
|
257
|
-
_tag: "Zoned",
|
|
258
|
-
[Hash.symbol](this: Zoned) {
|
|
259
|
-
return pipe(
|
|
260
|
-
Hash.number(this.epochMillis),
|
|
261
|
-
Hash.combine(Hash.hash(this.zone)),
|
|
262
|
-
Hash.cached(this)
|
|
263
|
-
)
|
|
264
|
-
},
|
|
265
|
-
[Equal.symbol](this: Zoned, that: unknown) {
|
|
266
|
-
return isDateTime(that) && that._tag === "Zoned" && this.epochMillis === that.epochMillis &&
|
|
267
|
-
Equal.equals(this.zone, that.zone)
|
|
268
|
-
},
|
|
269
|
-
toString(this: Zoned) {
|
|
270
|
-
return `DateTime.Zoned(${formatIsoZoned(this)})`
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const ProtoTimeZone = {
|
|
275
|
-
[TimeZoneTypeId]: TimeZoneTypeId,
|
|
276
|
-
[Inspectable.NodeInspectSymbol](this: TimeZone) {
|
|
277
|
-
return this.toString()
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const ProtoTimeZoneNamed = {
|
|
282
|
-
...ProtoTimeZone,
|
|
283
|
-
_tag: "Named",
|
|
284
|
-
[Hash.symbol](this: TimeZone.Named) {
|
|
285
|
-
return Hash.cached(this, Hash.string(`Named:${this.id}`))
|
|
286
|
-
},
|
|
287
|
-
[Equal.symbol](this: TimeZone.Named, that: unknown) {
|
|
288
|
-
return isTimeZone(that) && that._tag === "Named" && this.id === that.id
|
|
289
|
-
},
|
|
290
|
-
toString(this: TimeZone.Named) {
|
|
291
|
-
return `TimeZone.Named(${this.id})`
|
|
292
|
-
},
|
|
293
|
-
toJSON(this: TimeZone.Named) {
|
|
294
|
-
return {
|
|
295
|
-
_id: "TimeZone",
|
|
296
|
-
_tag: "Named",
|
|
297
|
-
id: this.id
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const ProtoTimeZoneOffset = {
|
|
303
|
-
...ProtoTimeZone,
|
|
304
|
-
_tag: "Offset",
|
|
305
|
-
[Hash.symbol](this: TimeZone.Offset) {
|
|
306
|
-
return Hash.cached(this, Hash.string(`Offset:${this.offset}`))
|
|
307
|
-
},
|
|
308
|
-
[Equal.symbol](this: TimeZone.Offset, that: unknown) {
|
|
309
|
-
return isTimeZone(that) && that._tag === "Offset" && this.offset === that.offset
|
|
310
|
-
},
|
|
311
|
-
toString(this: TimeZone.Offset) {
|
|
312
|
-
return `TimeZone.Offset(${offsetToString(this.offset)})`
|
|
313
|
-
},
|
|
314
|
-
toJSON(this: TimeZone.Offset) {
|
|
315
|
-
return {
|
|
316
|
-
_id: "TimeZone",
|
|
317
|
-
_tag: "Offset",
|
|
318
|
-
offset: this.offset
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
const makeZonedProto = (epochMillis: number, zone: TimeZone, partsUtc?: DateTime.PartsWithWeekday): Zoned => {
|
|
324
|
-
const self = Object.create(ProtoZoned)
|
|
325
|
-
self.epochMillis = epochMillis
|
|
326
|
-
self.zone = zone
|
|
327
|
-
self.partsUtc = partsUtc
|
|
328
|
-
return self
|
|
329
|
-
}
|
|
330
|
-
|
|
331
222
|
// =============================================================================
|
|
332
223
|
// guards
|
|
333
224
|
// =============================================================================
|
|
@@ -336,39 +227,37 @@ const makeZonedProto = (epochMillis: number, zone: TimeZone, partsUtc?: DateTime
|
|
|
336
227
|
* @since 3.6.0
|
|
337
228
|
* @category guards
|
|
338
229
|
*/
|
|
339
|
-
export const isDateTime
|
|
340
|
-
|
|
341
|
-
const isDateTimeArgs = (args: IArguments) => isDateTime(args[0])
|
|
230
|
+
export const isDateTime: (u: unknown) => u is DateTime = Internal.isDateTime
|
|
342
231
|
|
|
343
232
|
/**
|
|
344
233
|
* @since 3.6.0
|
|
345
234
|
* @category guards
|
|
346
235
|
*/
|
|
347
|
-
export const isTimeZone
|
|
236
|
+
export const isTimeZone: (u: unknown) => u is TimeZone = Internal.isTimeZone
|
|
348
237
|
|
|
349
238
|
/**
|
|
350
239
|
* @since 3.6.0
|
|
351
240
|
* @category guards
|
|
352
241
|
*/
|
|
353
|
-
export const isTimeZoneOffset
|
|
242
|
+
export const isTimeZoneOffset: (u: unknown) => u is TimeZone.Offset = Internal.isTimeZoneOffset
|
|
354
243
|
|
|
355
244
|
/**
|
|
356
245
|
* @since 3.6.0
|
|
357
246
|
* @category guards
|
|
358
247
|
*/
|
|
359
|
-
export const isTimeZoneNamed
|
|
248
|
+
export const isTimeZoneNamed: (u: unknown) => u is TimeZone.Named = Internal.isTimeZoneNamed
|
|
360
249
|
|
|
361
250
|
/**
|
|
362
251
|
* @since 3.6.0
|
|
363
252
|
* @category guards
|
|
364
253
|
*/
|
|
365
|
-
export const isUtc
|
|
254
|
+
export const isUtc: (self: DateTime) => self is Utc = Internal.isUtc
|
|
366
255
|
|
|
367
256
|
/**
|
|
368
257
|
* @since 3.6.0
|
|
369
258
|
* @category guards
|
|
370
259
|
*/
|
|
371
|
-
export const isZoned
|
|
260
|
+
export const isZoned: (self: DateTime) => self is Zoned = Internal.isZoned
|
|
372
261
|
|
|
373
262
|
// =============================================================================
|
|
374
263
|
// instances
|
|
@@ -378,17 +267,13 @@ export const isZoned = (self: DateTime): self is Zoned => self._tag === "Zoned"
|
|
|
378
267
|
* @since 3.6.0
|
|
379
268
|
* @category instances
|
|
380
269
|
*/
|
|
381
|
-
export const Equivalence:
|
|
382
|
-
a.epochMillis === b.epochMillis
|
|
383
|
-
)
|
|
270
|
+
export const Equivalence: equivalence.Equivalence<DateTime> = Internal.Equivalence
|
|
384
271
|
|
|
385
272
|
/**
|
|
386
273
|
* @since 3.6.0
|
|
387
274
|
* @category instances
|
|
388
275
|
*/
|
|
389
|
-
export const Order: order.Order<DateTime> =
|
|
390
|
-
self.epochMillis < that.epochMillis ? -1 : self.epochMillis > that.epochMillis ? 1 : 0
|
|
391
|
-
)
|
|
276
|
+
export const Order: order.Order<DateTime> = Internal.Order
|
|
392
277
|
|
|
393
278
|
/**
|
|
394
279
|
* @since 3.6.0
|
|
@@ -402,18 +287,12 @@ export const clamp: {
|
|
|
402
287
|
* @since 3.6.0
|
|
403
288
|
*/
|
|
404
289
|
(self: DateTime, options: { minimum: DateTime; maximum: DateTime }): DateTime
|
|
405
|
-
} =
|
|
290
|
+
} = Internal.clamp
|
|
406
291
|
|
|
407
292
|
// =============================================================================
|
|
408
293
|
// constructors
|
|
409
294
|
// =============================================================================
|
|
410
295
|
|
|
411
|
-
const makeUtc = (epochMillis: number): Utc => {
|
|
412
|
-
const self = Object.create(ProtoUtc)
|
|
413
|
-
self.epochMillis = epochMillis
|
|
414
|
-
return self
|
|
415
|
-
}
|
|
416
|
-
|
|
417
296
|
/**
|
|
418
297
|
* Create a `DateTime` from a `Date`.
|
|
419
298
|
*
|
|
@@ -422,13 +301,7 @@ const makeUtc = (epochMillis: number): Utc => {
|
|
|
422
301
|
* @since 3.6.0
|
|
423
302
|
* @category constructors
|
|
424
303
|
*/
|
|
425
|
-
export const unsafeFromDate
|
|
426
|
-
const epochMillis = date.getTime()
|
|
427
|
-
if (Number.isNaN(epochMillis)) {
|
|
428
|
-
throw new IllegalArgumentException("Invalid date")
|
|
429
|
-
}
|
|
430
|
-
return makeUtc(epochMillis)
|
|
431
|
-
}
|
|
304
|
+
export const unsafeFromDate: (date: Date) => Utc = Internal.unsafeFromDate
|
|
432
305
|
|
|
433
306
|
/**
|
|
434
307
|
* Create a `DateTime` from one of the following:
|
|
@@ -442,6 +315,7 @@ export const unsafeFromDate = (date: Date): Utc => {
|
|
|
442
315
|
* @since 3.6.0
|
|
443
316
|
* @category constructors
|
|
444
317
|
* @example
|
|
318
|
+
* ```ts
|
|
445
319
|
* import { DateTime } from "effect"
|
|
446
320
|
*
|
|
447
321
|
* // from Date
|
|
@@ -452,19 +326,9 @@ export const unsafeFromDate = (date: Date): Utc => {
|
|
|
452
326
|
*
|
|
453
327
|
* // from string
|
|
454
328
|
* DateTime.unsafeMake("2024-01-01")
|
|
329
|
+
* ```
|
|
455
330
|
*/
|
|
456
|
-
export const unsafeMake
|
|
457
|
-
if (isDateTime(input)) {
|
|
458
|
-
return input as DateTime.PreserveZone<A>
|
|
459
|
-
} else if (input instanceof Date) {
|
|
460
|
-
return unsafeFromDate(input) as DateTime.PreserveZone<A>
|
|
461
|
-
} else if (typeof input === "object") {
|
|
462
|
-
const date = new Date(0)
|
|
463
|
-
setPartsDate(date, input)
|
|
464
|
-
return unsafeFromDate(date) as DateTime.PreserveZone<A>
|
|
465
|
-
}
|
|
466
|
-
return unsafeFromDate(new Date(input)) as DateTime.PreserveZone<A>
|
|
467
|
-
}
|
|
331
|
+
export const unsafeMake: <A extends DateTime.Input>(input: A) => DateTime.PreserveZone<A> = Internal.unsafeMake
|
|
468
332
|
|
|
469
333
|
/**
|
|
470
334
|
* Create a `DateTime.Zoned` using `DateTime.unsafeMake` and a time zone.
|
|
@@ -476,38 +340,16 @@ export const unsafeMake = <A extends DateTime.Input>(input: A): DateTime.Preserv
|
|
|
476
340
|
* @since 3.6.0
|
|
477
341
|
* @category constructors
|
|
478
342
|
* @example
|
|
343
|
+
* ```ts
|
|
479
344
|
* import { DateTime } from "effect"
|
|
480
345
|
*
|
|
481
346
|
* DateTime.unsafeMakeZoned(new Date(), { timeZone: "Europe/London" })
|
|
347
|
+
* ```
|
|
482
348
|
*/
|
|
483
|
-
export const unsafeMakeZoned
|
|
349
|
+
export const unsafeMakeZoned: (input: DateTime.Input, options?: {
|
|
484
350
|
readonly timeZone?: number | string | TimeZone | undefined
|
|
485
351
|
readonly adjustForTimeZone?: boolean | undefined
|
|
486
|
-
})
|
|
487
|
-
if (options?.timeZone === undefined && isDateTime(input) && isZoned(input)) {
|
|
488
|
-
return input
|
|
489
|
-
}
|
|
490
|
-
const self = unsafeMake(input)
|
|
491
|
-
let zone: TimeZone
|
|
492
|
-
if (options?.timeZone === undefined) {
|
|
493
|
-
const offset = new Date(self.epochMillis).getTimezoneOffset() * -60 * 1000
|
|
494
|
-
zone = zoneMakeOffset(offset)
|
|
495
|
-
} else if (isTimeZone(options?.timeZone)) {
|
|
496
|
-
zone = options.timeZone
|
|
497
|
-
} else if (typeof options?.timeZone === "number") {
|
|
498
|
-
zone = zoneMakeOffset(options.timeZone)
|
|
499
|
-
} else {
|
|
500
|
-
const parsedZone = zoneFromString(options.timeZone)
|
|
501
|
-
if (Option.isNone(parsedZone)) {
|
|
502
|
-
throw new IllegalArgumentException(`Invalid time zone: ${options.timeZone}`)
|
|
503
|
-
}
|
|
504
|
-
zone = parsedZone.value
|
|
505
|
-
}
|
|
506
|
-
if (options?.adjustForTimeZone !== true) {
|
|
507
|
-
return makeZonedProto(self.epochMillis, zone, self.partsUtc)
|
|
508
|
-
}
|
|
509
|
-
return makeZonedFromAdjusted(self.epochMillis, zone)
|
|
510
|
-
}
|
|
352
|
+
}) => Zoned = Internal.unsafeMakeZoned
|
|
511
353
|
|
|
512
354
|
/**
|
|
513
355
|
* Create a `DateTime.Zoned` using `DateTime.make` and a time zone.
|
|
@@ -519,9 +361,11 @@ export const unsafeMakeZoned = (input: DateTime.Input, options?: {
|
|
|
519
361
|
* @since 3.6.0
|
|
520
362
|
* @category constructors
|
|
521
363
|
* @example
|
|
364
|
+
* ```ts
|
|
522
365
|
* import { DateTime } from "effect"
|
|
523
366
|
*
|
|
524
367
|
* DateTime.makeZoned(new Date(), { timeZone: "Europe/London" })
|
|
368
|
+
* ```
|
|
525
369
|
*/
|
|
526
370
|
export const makeZoned: (
|
|
527
371
|
input: DateTime.Input,
|
|
@@ -529,7 +373,7 @@ export const makeZoned: (
|
|
|
529
373
|
readonly timeZone?: number | string | TimeZone | undefined
|
|
530
374
|
readonly adjustForTimeZone?: boolean | undefined
|
|
531
375
|
}
|
|
532
|
-
) => Option.Option<Zoned> =
|
|
376
|
+
) => Option.Option<Zoned> = Internal.makeZoned
|
|
533
377
|
|
|
534
378
|
/**
|
|
535
379
|
* Create a `DateTime` from one of the following:
|
|
@@ -545,6 +389,7 @@ export const makeZoned: (
|
|
|
545
389
|
* @since 3.6.0
|
|
546
390
|
* @category constructors
|
|
547
391
|
* @example
|
|
392
|
+
* ```ts
|
|
548
393
|
* import { DateTime } from "effect"
|
|
549
394
|
*
|
|
550
395
|
* // from Date
|
|
@@ -555,11 +400,9 @@ export const makeZoned: (
|
|
|
555
400
|
*
|
|
556
401
|
* // from string
|
|
557
402
|
* DateTime.make("2024-01-01")
|
|
403
|
+
* ```
|
|
558
404
|
*/
|
|
559
|
-
export const make: <A extends DateTime.Input>(input: A) => Option.Option<DateTime.PreserveZone<A>> =
|
|
560
|
-
.liftThrowable(unsafeMake)
|
|
561
|
-
|
|
562
|
-
const zonedStringRegex = /^(.{17,35})\[(.+)\]$/
|
|
405
|
+
export const make: <A extends DateTime.Input>(input: A) => Option.Option<DateTime.PreserveZone<A>> = Internal.make
|
|
563
406
|
|
|
564
407
|
/**
|
|
565
408
|
* Create a `DateTime.Zoned` from a string.
|
|
@@ -569,15 +412,7 @@ const zonedStringRegex = /^(.{17,35})\[(.+)\]$/
|
|
|
569
412
|
* @since 3.6.0
|
|
570
413
|
* @category constructors
|
|
571
414
|
*/
|
|
572
|
-
export const makeZonedFromString
|
|
573
|
-
const match = zonedStringRegex.exec(input)
|
|
574
|
-
if (match === null) {
|
|
575
|
-
const offset = parseOffset(input)
|
|
576
|
-
return offset !== null ? makeZoned(input, { timeZone: offset }) : Option.none()
|
|
577
|
-
}
|
|
578
|
-
const [, isoString, timeZone] = match
|
|
579
|
-
return makeZoned(isoString, { timeZone })
|
|
580
|
-
}
|
|
415
|
+
export const makeZonedFromString: (input: string) => Option.Option<Zoned> = Internal.makeZonedFromString
|
|
581
416
|
|
|
582
417
|
/**
|
|
583
418
|
* Get the current time using the `Clock` service and convert it to a `DateTime`.
|
|
@@ -585,13 +420,15 @@ export const makeZonedFromString = (input: string): Option.Option<Zoned> => {
|
|
|
585
420
|
* @since 3.6.0
|
|
586
421
|
* @category constructors
|
|
587
422
|
* @example
|
|
423
|
+
* ```ts
|
|
588
424
|
* import { DateTime, Effect } from "effect"
|
|
589
425
|
*
|
|
590
426
|
* Effect.gen(function* () {
|
|
591
427
|
* const now = yield* DateTime.now
|
|
592
428
|
* })
|
|
429
|
+
* ```
|
|
593
430
|
*/
|
|
594
|
-
export const now: Effect.Effect<Utc> =
|
|
431
|
+
export const now: Effect.Effect<Utc> = Internal.now
|
|
595
432
|
|
|
596
433
|
/**
|
|
597
434
|
* Get the current time using `Date.now`.
|
|
@@ -599,7 +436,7 @@ export const now: Effect.Effect<Utc> = Effect.map(Clock.currentTimeMillis, makeU
|
|
|
599
436
|
* @since 3.6.0
|
|
600
437
|
* @category constructors
|
|
601
438
|
*/
|
|
602
|
-
export const unsafeNow: LazyArg<Utc> =
|
|
439
|
+
export const unsafeNow: LazyArg<Utc> = Internal.unsafeNow
|
|
603
440
|
|
|
604
441
|
// =============================================================================
|
|
605
442
|
// time zones
|
|
@@ -611,6 +448,7 @@ export const unsafeNow: LazyArg<Utc> = () => makeUtc(Date.now())
|
|
|
611
448
|
* @since 3.6.0
|
|
612
449
|
* @category time zones
|
|
613
450
|
* @example
|
|
451
|
+
* ```ts
|
|
614
452
|
* import { DateTime, Effect } from "effect"
|
|
615
453
|
*
|
|
616
454
|
* Effect.gen(function* () {
|
|
@@ -620,6 +458,7 @@ export const unsafeNow: LazyArg<Utc> = () => makeUtc(Date.now())
|
|
|
620
458
|
* // set the time zone
|
|
621
459
|
* const zoned: DateTime.Zoned = DateTime.setZone(now, zone)
|
|
622
460
|
* })
|
|
461
|
+
* ```
|
|
623
462
|
*/
|
|
624
463
|
export const setZone: {
|
|
625
464
|
// =============================================================================
|
|
@@ -632,6 +471,7 @@ export const setZone: {
|
|
|
632
471
|
* @since 3.6.0
|
|
633
472
|
* @category time zones
|
|
634
473
|
* @example
|
|
474
|
+
* ```ts
|
|
635
475
|
* import { DateTime, Effect } from "effect"
|
|
636
476
|
*
|
|
637
477
|
* Effect.gen(function* () {
|
|
@@ -641,6 +481,7 @@ export const setZone: {
|
|
|
641
481
|
* // set the time zone
|
|
642
482
|
* const zoned: DateTime.Zoned = DateTime.setZone(now, zone)
|
|
643
483
|
* })
|
|
484
|
+
* ```
|
|
644
485
|
*/
|
|
645
486
|
(
|
|
646
487
|
zone: TimeZone,
|
|
@@ -658,6 +499,7 @@ export const setZone: {
|
|
|
658
499
|
* @since 3.6.0
|
|
659
500
|
* @category time zones
|
|
660
501
|
* @example
|
|
502
|
+
* ```ts
|
|
661
503
|
* import { DateTime, Effect } from "effect"
|
|
662
504
|
*
|
|
663
505
|
* Effect.gen(function* () {
|
|
@@ -667,6 +509,7 @@ export const setZone: {
|
|
|
667
509
|
* // set the time zone
|
|
668
510
|
* const zoned: DateTime.Zoned = DateTime.setZone(now, zone)
|
|
669
511
|
* })
|
|
512
|
+
* ```
|
|
670
513
|
*/
|
|
671
514
|
(
|
|
672
515
|
self: DateTime,
|
|
@@ -675,12 +518,7 @@ export const setZone: {
|
|
|
675
518
|
readonly adjustForTimeZone?: boolean | undefined
|
|
676
519
|
}
|
|
677
520
|
): Zoned
|
|
678
|
-
} =
|
|
679
|
-
readonly adjustForTimeZone?: boolean | undefined
|
|
680
|
-
}): Zoned =>
|
|
681
|
-
options?.adjustForTimeZone === true
|
|
682
|
-
? makeZonedFromAdjusted(self.epochMillis, zone)
|
|
683
|
-
: makeZonedProto(self.epochMillis, zone, self.partsUtc))
|
|
521
|
+
} = Internal.setZone
|
|
684
522
|
|
|
685
523
|
/**
|
|
686
524
|
* Add a fixed offset time zone to a `DateTime`.
|
|
@@ -690,6 +528,7 @@ export const setZone: {
|
|
|
690
528
|
* @since 3.6.0
|
|
691
529
|
* @category time zones
|
|
692
530
|
* @example
|
|
531
|
+
* ```ts
|
|
693
532
|
* import { DateTime, Effect } from "effect"
|
|
694
533
|
*
|
|
695
534
|
* Effect.gen(function* () {
|
|
@@ -698,6 +537,7 @@ export const setZone: {
|
|
|
698
537
|
* // set the offset time zone in milliseconds
|
|
699
538
|
* const zoned: DateTime.Zoned = DateTime.setZoneOffset(now, 3 * 60 * 60 * 1000)
|
|
700
539
|
* })
|
|
540
|
+
* ```
|
|
701
541
|
*/
|
|
702
542
|
export const setZoneOffset: {
|
|
703
543
|
/**
|
|
@@ -708,6 +548,7 @@ export const setZoneOffset: {
|
|
|
708
548
|
* @since 3.6.0
|
|
709
549
|
* @category time zones
|
|
710
550
|
* @example
|
|
551
|
+
* ```ts
|
|
711
552
|
* import { DateTime, Effect } from "effect"
|
|
712
553
|
*
|
|
713
554
|
* Effect.gen(function* () {
|
|
@@ -716,6 +557,7 @@ export const setZoneOffset: {
|
|
|
716
557
|
* // set the offset time zone in milliseconds
|
|
717
558
|
* const zoned: DateTime.Zoned = DateTime.setZoneOffset(now, 3 * 60 * 60 * 1000)
|
|
718
559
|
* })
|
|
560
|
+
* ```
|
|
719
561
|
*/
|
|
720
562
|
(
|
|
721
563
|
offset: number,
|
|
@@ -731,6 +573,7 @@ export const setZoneOffset: {
|
|
|
731
573
|
* @since 3.6.0
|
|
732
574
|
* @category time zones
|
|
733
575
|
* @example
|
|
576
|
+
* ```ts
|
|
734
577
|
* import { DateTime, Effect } from "effect"
|
|
735
578
|
*
|
|
736
579
|
* Effect.gen(function* () {
|
|
@@ -739,6 +582,7 @@ export const setZoneOffset: {
|
|
|
739
582
|
* // set the offset time zone in milliseconds
|
|
740
583
|
* const zoned: DateTime.Zoned = DateTime.setZoneOffset(now, 3 * 60 * 60 * 1000)
|
|
741
584
|
* })
|
|
585
|
+
* ```
|
|
742
586
|
*/
|
|
743
587
|
(
|
|
744
588
|
self: DateTime,
|
|
@@ -747,35 +591,7 @@ export const setZoneOffset: {
|
|
|
747
591
|
readonly adjustForTimeZone?: boolean | undefined
|
|
748
592
|
}
|
|
749
593
|
): Zoned
|
|
750
|
-
} =
|
|
751
|
-
readonly adjustForTimeZone?: boolean | undefined
|
|
752
|
-
}): Zoned => setZone(self, zoneMakeOffset(offset), options))
|
|
753
|
-
|
|
754
|
-
const validZoneCache = globalValue("effect/DateTime/validZoneCache", () => new Map<string, TimeZone.Named>())
|
|
755
|
-
|
|
756
|
-
const formatOptions: Intl.DateTimeFormatOptions = {
|
|
757
|
-
day: "numeric",
|
|
758
|
-
month: "numeric",
|
|
759
|
-
year: "numeric",
|
|
760
|
-
hour: "numeric",
|
|
761
|
-
minute: "numeric",
|
|
762
|
-
second: "numeric",
|
|
763
|
-
timeZoneName: "longOffset",
|
|
764
|
-
fractionalSecondDigits: 3,
|
|
765
|
-
hourCycle: "h23"
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
const zoneMakeIntl = (format: Intl.DateTimeFormat): TimeZone.Named => {
|
|
769
|
-
const zoneId = format.resolvedOptions().timeZone
|
|
770
|
-
if (validZoneCache.has(zoneId)) {
|
|
771
|
-
return validZoneCache.get(zoneId)!
|
|
772
|
-
}
|
|
773
|
-
const zone = Object.create(ProtoTimeZoneNamed)
|
|
774
|
-
zone.id = zoneId
|
|
775
|
-
zone.format = format
|
|
776
|
-
validZoneCache.set(zoneId, zone)
|
|
777
|
-
return zone
|
|
778
|
-
}
|
|
594
|
+
} = Internal.setZoneOffset
|
|
779
595
|
|
|
780
596
|
/**
|
|
781
597
|
* Attempt to create a named time zone from a IANA time zone identifier.
|
|
@@ -785,21 +601,7 @@ const zoneMakeIntl = (format: Intl.DateTimeFormat): TimeZone.Named => {
|
|
|
785
601
|
* @since 3.6.0
|
|
786
602
|
* @category time zones
|
|
787
603
|
*/
|
|
788
|
-
export const zoneUnsafeMakeNamed
|
|
789
|
-
if (validZoneCache.has(zoneId)) {
|
|
790
|
-
return validZoneCache.get(zoneId)!
|
|
791
|
-
}
|
|
792
|
-
try {
|
|
793
|
-
return zoneMakeIntl(
|
|
794
|
-
new Intl.DateTimeFormat("en-US", {
|
|
795
|
-
...formatOptions,
|
|
796
|
-
timeZone: zoneId
|
|
797
|
-
})
|
|
798
|
-
)
|
|
799
|
-
} catch (_) {
|
|
800
|
-
throw new IllegalArgumentException(`Invalid time zone: ${zoneId}`)
|
|
801
|
-
}
|
|
802
|
-
}
|
|
604
|
+
export const zoneUnsafeMakeNamed: (zoneId: string) => TimeZone.Named = Internal.zoneUnsafeMakeNamed
|
|
803
605
|
|
|
804
606
|
/**
|
|
805
607
|
* Create a fixed offset time zone.
|
|
@@ -807,11 +609,7 @@ export const zoneUnsafeMakeNamed = (zoneId: string): TimeZone.Named => {
|
|
|
807
609
|
* @since 3.6.0
|
|
808
610
|
* @category time zones
|
|
809
611
|
*/
|
|
810
|
-
export const zoneMakeOffset
|
|
811
|
-
const zone = Object.create(ProtoTimeZoneOffset)
|
|
812
|
-
zone.offset = offset
|
|
813
|
-
return zone
|
|
814
|
-
}
|
|
612
|
+
export const zoneMakeOffset: (offset: number) => TimeZone.Offset = Internal.zoneMakeOffset
|
|
815
613
|
|
|
816
614
|
/**
|
|
817
615
|
* Create a named time zone from a IANA time zone identifier. If the time zone
|
|
@@ -820,9 +618,7 @@ export const zoneMakeOffset = (offset: number): TimeZone.Offset => {
|
|
|
820
618
|
* @since 3.6.0
|
|
821
619
|
* @category time zones
|
|
822
620
|
*/
|
|
823
|
-
export const zoneMakeNamed: (zoneId: string) => Option.Option<TimeZone.Named> =
|
|
824
|
-
zoneUnsafeMakeNamed
|
|
825
|
-
)
|
|
621
|
+
export const zoneMakeNamed: (zoneId: string) => Option.Option<TimeZone.Named> = Internal.zoneMakeNamed
|
|
826
622
|
|
|
827
623
|
/**
|
|
828
624
|
* Create a named time zone from a IANA time zone identifier. If the time zone
|
|
@@ -831,11 +627,8 @@ export const zoneMakeNamed: (zoneId: string) => Option.Option<TimeZone.Named> =
|
|
|
831
627
|
* @since 3.6.0
|
|
832
628
|
* @category time zones
|
|
833
629
|
*/
|
|
834
|
-
export const zoneMakeNamedEffect
|
|
835
|
-
|
|
836
|
-
try: () => zoneUnsafeMakeNamed(zoneId),
|
|
837
|
-
catch: (e) => e as IllegalArgumentException
|
|
838
|
-
})
|
|
630
|
+
export const zoneMakeNamedEffect: (zoneId: string) => Effect.Effect<TimeZone.Named, IllegalArgumentException> =
|
|
631
|
+
Internal.zoneMakeNamedEffect
|
|
839
632
|
|
|
840
633
|
/**
|
|
841
634
|
* Create a named time zone from the system's local time zone.
|
|
@@ -843,9 +636,7 @@ export const zoneMakeNamedEffect = (zoneId: string): Effect.Effect<TimeZone.Name
|
|
|
843
636
|
* @since 3.6.0
|
|
844
637
|
* @category time zones
|
|
845
638
|
*/
|
|
846
|
-
export const zoneMakeLocal
|
|
847
|
-
|
|
848
|
-
const offsetZoneRegex = /^(?:GMT|[+-])/
|
|
639
|
+
export const zoneMakeLocal: () => TimeZone.Named = Internal.zoneMakeLocal
|
|
849
640
|
|
|
850
641
|
/**
|
|
851
642
|
* Try parse a TimeZone from a string
|
|
@@ -853,13 +644,7 @@ const offsetZoneRegex = /^(?:GMT|[+-])/
|
|
|
853
644
|
* @since 3.6.0
|
|
854
645
|
* @category time zones
|
|
855
646
|
*/
|
|
856
|
-
export const zoneFromString
|
|
857
|
-
if (offsetZoneRegex.test(zone)) {
|
|
858
|
-
const offset = parseOffset(zone)
|
|
859
|
-
return offset === null ? Option.none() : Option.some(zoneMakeOffset(offset))
|
|
860
|
-
}
|
|
861
|
-
return zoneMakeNamed(zone)
|
|
862
|
-
}
|
|
647
|
+
export const zoneFromString: (zone: string) => Option.Option<TimeZone> = Internal.zoneFromString
|
|
863
648
|
|
|
864
649
|
/**
|
|
865
650
|
* Format a `TimeZone` as a string.
|
|
@@ -867,6 +652,7 @@ export const zoneFromString = (zone: string): Option.Option<TimeZone> => {
|
|
|
867
652
|
* @since 3.6.0
|
|
868
653
|
* @category time zones
|
|
869
654
|
* @example
|
|
655
|
+
* ```ts
|
|
870
656
|
* import { DateTime, Effect } from "effect"
|
|
871
657
|
*
|
|
872
658
|
* // Outputs "+03:00"
|
|
@@ -874,13 +660,9 @@ export const zoneFromString = (zone: string): Option.Option<TimeZone> => {
|
|
|
874
660
|
*
|
|
875
661
|
* // Outputs "Europe/London"
|
|
876
662
|
* DateTime.zoneToString(DateTime.zoneUnsafeMakeNamed("Europe/London"))
|
|
663
|
+
* ```
|
|
877
664
|
*/
|
|
878
|
-
export const zoneToString
|
|
879
|
-
if (self._tag === "Offset") {
|
|
880
|
-
return offsetToString(self.offset)
|
|
881
|
-
}
|
|
882
|
-
return self.id
|
|
883
|
-
}
|
|
665
|
+
export const zoneToString: (self: TimeZone) => string = Internal.zoneToString
|
|
884
666
|
|
|
885
667
|
/**
|
|
886
668
|
* Set the time zone of a `DateTime` from an IANA time zone identifier. If the
|
|
@@ -889,6 +671,7 @@ export const zoneToString = (self: TimeZone): string => {
|
|
|
889
671
|
* @since 3.6.0
|
|
890
672
|
* @category time zones
|
|
891
673
|
* @example
|
|
674
|
+
* ```ts
|
|
892
675
|
* import { DateTime, Effect } from "effect"
|
|
893
676
|
*
|
|
894
677
|
* Effect.gen(function* () {
|
|
@@ -896,6 +679,7 @@ export const zoneToString = (self: TimeZone): string => {
|
|
|
896
679
|
* // set the time zone, returns an Option
|
|
897
680
|
* DateTime.setZoneNamed(now, "Europe/London")
|
|
898
681
|
* })
|
|
682
|
+
* ```
|
|
899
683
|
*/
|
|
900
684
|
export const setZoneNamed: {
|
|
901
685
|
/**
|
|
@@ -905,6 +689,7 @@ export const setZoneNamed: {
|
|
|
905
689
|
* @since 3.6.0
|
|
906
690
|
* @category time zones
|
|
907
691
|
* @example
|
|
692
|
+
* ```ts
|
|
908
693
|
* import { DateTime, Effect } from "effect"
|
|
909
694
|
*
|
|
910
695
|
* Effect.gen(function* () {
|
|
@@ -912,6 +697,7 @@ export const setZoneNamed: {
|
|
|
912
697
|
* // set the time zone, returns an Option
|
|
913
698
|
* DateTime.setZoneNamed(now, "Europe/London")
|
|
914
699
|
* })
|
|
700
|
+
* ```
|
|
915
701
|
*/
|
|
916
702
|
(
|
|
917
703
|
zoneId: string,
|
|
@@ -926,6 +712,7 @@ export const setZoneNamed: {
|
|
|
926
712
|
* @since 3.6.0
|
|
927
713
|
* @category time zones
|
|
928
714
|
* @example
|
|
715
|
+
* ```ts
|
|
929
716
|
* import { DateTime, Effect } from "effect"
|
|
930
717
|
*
|
|
931
718
|
* Effect.gen(function* () {
|
|
@@ -933,6 +720,7 @@ export const setZoneNamed: {
|
|
|
933
720
|
* // set the time zone, returns an Option
|
|
934
721
|
* DateTime.setZoneNamed(now, "Europe/London")
|
|
935
722
|
* })
|
|
723
|
+
* ```
|
|
936
724
|
*/
|
|
937
725
|
(
|
|
938
726
|
self: DateTime,
|
|
@@ -941,12 +729,7 @@ export const setZoneNamed: {
|
|
|
941
729
|
readonly adjustForTimeZone?: boolean | undefined
|
|
942
730
|
}
|
|
943
731
|
): Option.Option<Zoned>
|
|
944
|
-
} =
|
|
945
|
-
isDateTimeArgs,
|
|
946
|
-
(self: DateTime, zoneId: string, options?: {
|
|
947
|
-
readonly adjustForTimeZone?: boolean | undefined
|
|
948
|
-
}): Option.Option<Zoned> => Option.map(zoneMakeNamed(zoneId), (zone) => setZone(self, zone, options))
|
|
949
|
-
)
|
|
732
|
+
} = Internal.setZoneNamed
|
|
950
733
|
|
|
951
734
|
/**
|
|
952
735
|
* Set the time zone of a `DateTime` from an IANA time zone identifier. If the
|
|
@@ -955,6 +738,7 @@ export const setZoneNamed: {
|
|
|
955
738
|
* @since 3.6.0
|
|
956
739
|
* @category time zones
|
|
957
740
|
* @example
|
|
741
|
+
* ```ts
|
|
958
742
|
* import { DateTime, Effect } from "effect"
|
|
959
743
|
*
|
|
960
744
|
* Effect.gen(function* () {
|
|
@@ -962,6 +746,7 @@ export const setZoneNamed: {
|
|
|
962
746
|
* // set the time zone
|
|
963
747
|
* DateTime.unsafeSetZoneNamed(now, "Europe/London")
|
|
964
748
|
* })
|
|
749
|
+
* ```
|
|
965
750
|
*/
|
|
966
751
|
export const unsafeSetZoneNamed: {
|
|
967
752
|
/**
|
|
@@ -971,6 +756,7 @@ export const unsafeSetZoneNamed: {
|
|
|
971
756
|
* @since 3.6.0
|
|
972
757
|
* @category time zones
|
|
973
758
|
* @example
|
|
759
|
+
* ```ts
|
|
974
760
|
* import { DateTime, Effect } from "effect"
|
|
975
761
|
*
|
|
976
762
|
* Effect.gen(function* () {
|
|
@@ -978,6 +764,7 @@ export const unsafeSetZoneNamed: {
|
|
|
978
764
|
* // set the time zone
|
|
979
765
|
* DateTime.unsafeSetZoneNamed(now, "Europe/London")
|
|
980
766
|
* })
|
|
767
|
+
* ```
|
|
981
768
|
*/
|
|
982
769
|
(
|
|
983
770
|
zoneId: string,
|
|
@@ -992,6 +779,7 @@ export const unsafeSetZoneNamed: {
|
|
|
992
779
|
* @since 3.6.0
|
|
993
780
|
* @category time zones
|
|
994
781
|
* @example
|
|
782
|
+
* ```ts
|
|
995
783
|
* import { DateTime, Effect } from "effect"
|
|
996
784
|
*
|
|
997
785
|
* Effect.gen(function* () {
|
|
@@ -999,6 +787,7 @@ export const unsafeSetZoneNamed: {
|
|
|
999
787
|
* // set the time zone
|
|
1000
788
|
* DateTime.unsafeSetZoneNamed(now, "Europe/London")
|
|
1001
789
|
* })
|
|
790
|
+
* ```
|
|
1002
791
|
*/
|
|
1003
792
|
(
|
|
1004
793
|
self: DateTime,
|
|
@@ -1007,9 +796,7 @@ export const unsafeSetZoneNamed: {
|
|
|
1007
796
|
readonly adjustForTimeZone?: boolean | undefined
|
|
1008
797
|
}
|
|
1009
798
|
): Zoned
|
|
1010
|
-
} =
|
|
1011
|
-
readonly adjustForTimeZone?: boolean | undefined
|
|
1012
|
-
}): Zoned => setZone(self, zoneUnsafeMakeNamed(zoneId), options))
|
|
799
|
+
} = Internal.unsafeSetZoneNamed
|
|
1013
800
|
|
|
1014
801
|
// =============================================================================
|
|
1015
802
|
// comparisons
|
|
@@ -1024,6 +811,7 @@ export const unsafeSetZoneNamed: {
|
|
|
1024
811
|
* @since 3.6.0
|
|
1025
812
|
* @category comparisons
|
|
1026
813
|
* @example
|
|
814
|
+
* ```ts
|
|
1027
815
|
* import { DateTime, Effect } from "effect"
|
|
1028
816
|
*
|
|
1029
817
|
* Effect.gen(function* () {
|
|
@@ -1033,6 +821,7 @@ export const unsafeSetZoneNamed: {
|
|
|
1033
821
|
* // returns 60000
|
|
1034
822
|
* DateTime.distance(now, other)
|
|
1035
823
|
* })
|
|
824
|
+
* ```
|
|
1036
825
|
*/
|
|
1037
826
|
export const distance: {
|
|
1038
827
|
// =============================================================================
|
|
@@ -1048,6 +837,7 @@ export const distance: {
|
|
|
1048
837
|
* @since 3.6.0
|
|
1049
838
|
* @category comparisons
|
|
1050
839
|
* @example
|
|
840
|
+
* ```ts
|
|
1051
841
|
* import { DateTime, Effect } from "effect"
|
|
1052
842
|
*
|
|
1053
843
|
* Effect.gen(function* () {
|
|
@@ -1057,6 +847,7 @@ export const distance: {
|
|
|
1057
847
|
* // returns 60000
|
|
1058
848
|
* DateTime.distance(now, other)
|
|
1059
849
|
* })
|
|
850
|
+
* ```
|
|
1060
851
|
*/
|
|
1061
852
|
(other: DateTime): (self: DateTime) => number
|
|
1062
853
|
// =============================================================================
|
|
@@ -1072,6 +863,7 @@ export const distance: {
|
|
|
1072
863
|
* @since 3.6.0
|
|
1073
864
|
* @category comparisons
|
|
1074
865
|
* @example
|
|
866
|
+
* ```ts
|
|
1075
867
|
* import { DateTime, Effect } from "effect"
|
|
1076
868
|
*
|
|
1077
869
|
* Effect.gen(function* () {
|
|
@@ -1081,9 +873,10 @@ export const distance: {
|
|
|
1081
873
|
* // returns 60000
|
|
1082
874
|
* DateTime.distance(now, other)
|
|
1083
875
|
* })
|
|
876
|
+
* ```
|
|
1084
877
|
*/
|
|
1085
878
|
(self: DateTime, other: DateTime): number
|
|
1086
|
-
} =
|
|
879
|
+
} = Internal.distance
|
|
1087
880
|
|
|
1088
881
|
/**
|
|
1089
882
|
* Calulate the difference between two `DateTime` values.
|
|
@@ -1097,6 +890,7 @@ export const distance: {
|
|
|
1097
890
|
* @since 3.6.0
|
|
1098
891
|
* @category comparisons
|
|
1099
892
|
* @example
|
|
893
|
+
* ```ts
|
|
1100
894
|
* import { DateTime, Effect } from "effect"
|
|
1101
895
|
*
|
|
1102
896
|
* Effect.gen(function* () {
|
|
@@ -1109,6 +903,7 @@ export const distance: {
|
|
|
1109
903
|
* // returns Either.left(Duration.minutes(1))
|
|
1110
904
|
* DateTime.distanceDurationEither(other, now)
|
|
1111
905
|
* })
|
|
906
|
+
* ```
|
|
1112
907
|
*/
|
|
1113
908
|
export const distanceDurationEither: {
|
|
1114
909
|
/**
|
|
@@ -1123,6 +918,7 @@ export const distanceDurationEither: {
|
|
|
1123
918
|
* @since 3.6.0
|
|
1124
919
|
* @category comparisons
|
|
1125
920
|
* @example
|
|
921
|
+
* ```ts
|
|
1126
922
|
* import { DateTime, Effect } from "effect"
|
|
1127
923
|
*
|
|
1128
924
|
* Effect.gen(function* () {
|
|
@@ -1135,6 +931,7 @@ export const distanceDurationEither: {
|
|
|
1135
931
|
* // returns Either.left(Duration.minutes(1))
|
|
1136
932
|
* DateTime.distanceDurationEither(other, now)
|
|
1137
933
|
* })
|
|
934
|
+
* ```
|
|
1138
935
|
*/
|
|
1139
936
|
(other: DateTime): (self: DateTime) => Either.Either<Duration.Duration, Duration.Duration>
|
|
1140
937
|
/**
|
|
@@ -1149,6 +946,7 @@ export const distanceDurationEither: {
|
|
|
1149
946
|
* @since 3.6.0
|
|
1150
947
|
* @category comparisons
|
|
1151
948
|
* @example
|
|
949
|
+
* ```ts
|
|
1152
950
|
* import { DateTime, Effect } from "effect"
|
|
1153
951
|
*
|
|
1154
952
|
* Effect.gen(function* () {
|
|
@@ -1161,14 +959,10 @@ export const distanceDurationEither: {
|
|
|
1161
959
|
* // returns Either.left(Duration.minutes(1))
|
|
1162
960
|
* DateTime.distanceDurationEither(other, now)
|
|
1163
961
|
* })
|
|
962
|
+
* ```
|
|
1164
963
|
*/
|
|
1165
964
|
(self: DateTime, other: DateTime): Either.Either<Duration.Duration, Duration.Duration>
|
|
1166
|
-
} =
|
|
1167
|
-
const diffMillis = distance(self, other)
|
|
1168
|
-
return diffMillis > 0
|
|
1169
|
-
? Either.right(Duration.millis(diffMillis))
|
|
1170
|
-
: Either.left(Duration.millis(-diffMillis))
|
|
1171
|
-
})
|
|
965
|
+
} = Internal.distanceDurationEither
|
|
1172
966
|
|
|
1173
967
|
/**
|
|
1174
968
|
* Calulate the distance between two `DateTime` values.
|
|
@@ -1176,6 +970,7 @@ export const distanceDurationEither: {
|
|
|
1176
970
|
* @since 3.6.0
|
|
1177
971
|
* @category comparisons
|
|
1178
972
|
* @example
|
|
973
|
+
* ```ts
|
|
1179
974
|
* import { DateTime, Effect } from "effect"
|
|
1180
975
|
*
|
|
1181
976
|
* Effect.gen(function* () {
|
|
@@ -1185,6 +980,7 @@ export const distanceDurationEither: {
|
|
|
1185
980
|
* // returns Duration.minutes(1)
|
|
1186
981
|
* DateTime.distanceDuration(now, other)
|
|
1187
982
|
* })
|
|
983
|
+
* ```
|
|
1188
984
|
*/
|
|
1189
985
|
export const distanceDuration: {
|
|
1190
986
|
/**
|
|
@@ -1193,6 +989,7 @@ export const distanceDuration: {
|
|
|
1193
989
|
* @since 3.6.0
|
|
1194
990
|
* @category comparisons
|
|
1195
991
|
* @example
|
|
992
|
+
* ```ts
|
|
1196
993
|
* import { DateTime, Effect } from "effect"
|
|
1197
994
|
*
|
|
1198
995
|
* Effect.gen(function* () {
|
|
@@ -1202,6 +999,7 @@ export const distanceDuration: {
|
|
|
1202
999
|
* // returns Duration.minutes(1)
|
|
1203
1000
|
* DateTime.distanceDuration(now, other)
|
|
1204
1001
|
* })
|
|
1002
|
+
* ```
|
|
1205
1003
|
*/
|
|
1206
1004
|
(other: DateTime): (self: DateTime) => Duration.Duration
|
|
1207
1005
|
/**
|
|
@@ -1210,6 +1008,7 @@ export const distanceDuration: {
|
|
|
1210
1008
|
* @since 3.6.0
|
|
1211
1009
|
* @category comparisons
|
|
1212
1010
|
* @example
|
|
1011
|
+
* ```ts
|
|
1213
1012
|
* import { DateTime, Effect } from "effect"
|
|
1214
1013
|
*
|
|
1215
1014
|
* Effect.gen(function* () {
|
|
@@ -1219,12 +1018,10 @@ export const distanceDuration: {
|
|
|
1219
1018
|
* // returns Duration.minutes(1)
|
|
1220
1019
|
* DateTime.distanceDuration(now, other)
|
|
1221
1020
|
* })
|
|
1021
|
+
* ```
|
|
1222
1022
|
*/
|
|
1223
1023
|
(self: DateTime, other: DateTime): Duration.Duration
|
|
1224
|
-
} =
|
|
1225
|
-
2,
|
|
1226
|
-
(self: DateTime, other: DateTime): Duration.Duration => Duration.millis(Math.abs(distance(self, other)))
|
|
1227
|
-
)
|
|
1024
|
+
} = Internal.distanceDuration
|
|
1228
1025
|
|
|
1229
1026
|
/**
|
|
1230
1027
|
* @since 3.6.0
|
|
@@ -1241,7 +1038,7 @@ export const min: {
|
|
|
1241
1038
|
* @category comparisons
|
|
1242
1039
|
*/
|
|
1243
1040
|
(self: DateTime, that: DateTime): DateTime
|
|
1244
|
-
} =
|
|
1041
|
+
} = Internal.min
|
|
1245
1042
|
|
|
1246
1043
|
/**
|
|
1247
1044
|
* @since 3.6.0
|
|
@@ -1258,7 +1055,7 @@ export const max: {
|
|
|
1258
1055
|
* @category comparisons
|
|
1259
1056
|
*/
|
|
1260
1057
|
(self: DateTime, that: DateTime): DateTime
|
|
1261
|
-
} =
|
|
1058
|
+
} = Internal.max
|
|
1262
1059
|
|
|
1263
1060
|
/**
|
|
1264
1061
|
* @since 3.6.0
|
|
@@ -1275,7 +1072,7 @@ export const greaterThan: {
|
|
|
1275
1072
|
* @category comparisons
|
|
1276
1073
|
*/
|
|
1277
1074
|
(self: DateTime, that: DateTime): boolean
|
|
1278
|
-
} =
|
|
1075
|
+
} = Internal.greaterThan
|
|
1279
1076
|
|
|
1280
1077
|
/**
|
|
1281
1078
|
* @since 3.6.0
|
|
@@ -1292,7 +1089,7 @@ export const greaterThanOrEqualTo: {
|
|
|
1292
1089
|
* @category comparisons
|
|
1293
1090
|
*/
|
|
1294
1091
|
(self: DateTime, that: DateTime): boolean
|
|
1295
|
-
} =
|
|
1092
|
+
} = Internal.greaterThanOrEqualTo
|
|
1296
1093
|
|
|
1297
1094
|
/**
|
|
1298
1095
|
* @since 3.6.0
|
|
@@ -1309,7 +1106,7 @@ export const lessThan: {
|
|
|
1309
1106
|
* @category comparisons
|
|
1310
1107
|
*/
|
|
1311
1108
|
(self: DateTime, that: DateTime): boolean
|
|
1312
|
-
} =
|
|
1109
|
+
} = Internal.lessThan
|
|
1313
1110
|
|
|
1314
1111
|
/**
|
|
1315
1112
|
* @since 3.6.0
|
|
@@ -1326,7 +1123,7 @@ export const lessThanOrEqualTo: {
|
|
|
1326
1123
|
* @category comparisons
|
|
1327
1124
|
*/
|
|
1328
1125
|
(self: DateTime, that: DateTime): boolean
|
|
1329
|
-
} =
|
|
1126
|
+
} = Internal.lessThanOrEqualTo
|
|
1330
1127
|
|
|
1331
1128
|
/**
|
|
1332
1129
|
* @since 3.6.0
|
|
@@ -1343,31 +1140,31 @@ export const between: {
|
|
|
1343
1140
|
* @category comparisons
|
|
1344
1141
|
*/
|
|
1345
1142
|
(self: DateTime, options: { minimum: DateTime; maximum: DateTime }): boolean
|
|
1346
|
-
} =
|
|
1143
|
+
} = Internal.between
|
|
1347
1144
|
|
|
1348
1145
|
/**
|
|
1349
1146
|
* @since 3.6.0
|
|
1350
1147
|
* @category comparisons
|
|
1351
1148
|
*/
|
|
1352
|
-
export const isFuture
|
|
1149
|
+
export const isFuture: (self: DateTime) => Effect.Effect<boolean> = Internal.isFuture
|
|
1353
1150
|
|
|
1354
1151
|
/**
|
|
1355
1152
|
* @since 3.6.0
|
|
1356
1153
|
* @category comparisons
|
|
1357
1154
|
*/
|
|
1358
|
-
export const unsafeIsFuture
|
|
1155
|
+
export const unsafeIsFuture: (self: DateTime) => boolean = Internal.unsafeIsFuture
|
|
1359
1156
|
|
|
1360
1157
|
/**
|
|
1361
1158
|
* @since 3.6.0
|
|
1362
1159
|
* @category comparisons
|
|
1363
1160
|
*/
|
|
1364
|
-
export const isPast
|
|
1161
|
+
export const isPast: (self: DateTime) => Effect.Effect<boolean> = Internal.isPast
|
|
1365
1162
|
|
|
1366
1163
|
/**
|
|
1367
1164
|
* @since 3.6.0
|
|
1368
1165
|
* @category comparisons
|
|
1369
1166
|
*/
|
|
1370
|
-
export const unsafeIsPast
|
|
1167
|
+
export const unsafeIsPast: (self: DateTime) => boolean = Internal.unsafeIsPast
|
|
1371
1168
|
|
|
1372
1169
|
// =============================================================================
|
|
1373
1170
|
// conversions
|
|
@@ -1379,7 +1176,7 @@ export const unsafeIsPast = (self: DateTime): boolean => greaterThan(unsafeNow()
|
|
|
1379
1176
|
* @since 3.6.0
|
|
1380
1177
|
* @category conversions
|
|
1381
1178
|
*/
|
|
1382
|
-
export const toDateUtc
|
|
1179
|
+
export const toDateUtc: (self: DateTime) => Date = Internal.toDateUtc
|
|
1383
1180
|
|
|
1384
1181
|
/**
|
|
1385
1182
|
* Convert a `DateTime` to a `Date`, applying the time zone first.
|
|
@@ -1387,30 +1184,7 @@ export const toDateUtc = (self: DateTime): Date => new Date(self.epochMillis)
|
|
|
1387
1184
|
* @since 3.6.0
|
|
1388
1185
|
* @category conversions
|
|
1389
1186
|
*/
|
|
1390
|
-
export const toDate
|
|
1391
|
-
if (self._tag === "Utc") {
|
|
1392
|
-
return new Date(self.epochMillis)
|
|
1393
|
-
} else if (self.zone._tag === "Offset") {
|
|
1394
|
-
return new Date(self.epochMillis + self.zone.offset)
|
|
1395
|
-
} else if (self.adjustedEpochMillis !== undefined) {
|
|
1396
|
-
return new Date(self.adjustedEpochMillis)
|
|
1397
|
-
}
|
|
1398
|
-
const parts = self.zone.format.formatToParts(self.epochMillis).filter((_) => _.type !== "literal")
|
|
1399
|
-
const date = new Date(0)
|
|
1400
|
-
date.setUTCFullYear(
|
|
1401
|
-
Number(parts[2].value),
|
|
1402
|
-
Number(parts[0].value) - 1,
|
|
1403
|
-
Number(parts[1].value)
|
|
1404
|
-
)
|
|
1405
|
-
date.setUTCHours(
|
|
1406
|
-
Number(parts[3].value),
|
|
1407
|
-
Number(parts[4].value),
|
|
1408
|
-
Number(parts[5].value),
|
|
1409
|
-
Number(parts[6].value)
|
|
1410
|
-
)
|
|
1411
|
-
self.adjustedEpochMillis = date.getTime()
|
|
1412
|
-
return date
|
|
1413
|
-
}
|
|
1187
|
+
export const toDate: (self: DateTime) => Date = Internal.toDate
|
|
1414
1188
|
|
|
1415
1189
|
/**
|
|
1416
1190
|
* Calculate the time zone offset of a `DateTime.Zoned` in milliseconds.
|
|
@@ -1418,17 +1192,7 @@ export const toDate = (self: DateTime): Date => {
|
|
|
1418
1192
|
* @since 3.6.0
|
|
1419
1193
|
* @category conversions
|
|
1420
1194
|
*/
|
|
1421
|
-
export const zonedOffset
|
|
1422
|
-
const date = toDate(self)
|
|
1423
|
-
return date.getTime() - toEpochMillis(self)
|
|
1424
|
-
}
|
|
1425
|
-
|
|
1426
|
-
const offsetToString = (offset: number): string => {
|
|
1427
|
-
const abs = Math.abs(offset)
|
|
1428
|
-
const hours = Math.floor(abs / (60 * 60 * 1000))
|
|
1429
|
-
const minutes = Math.round((abs % (60 * 60 * 1000)) / (60 * 1000))
|
|
1430
|
-
return `${offset < 0 ? "-" : "+"}${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`
|
|
1431
|
-
}
|
|
1195
|
+
export const zonedOffset: (self: Zoned) => number = Internal.zonedOffset
|
|
1432
1196
|
|
|
1433
1197
|
/**
|
|
1434
1198
|
* Calculate the time zone offset of a `DateTime` in milliseconds.
|
|
@@ -1438,7 +1202,7 @@ const offsetToString = (offset: number): string => {
|
|
|
1438
1202
|
* @since 3.6.0
|
|
1439
1203
|
* @category conversions
|
|
1440
1204
|
*/
|
|
1441
|
-
export const zonedOffsetIso
|
|
1205
|
+
export const zonedOffsetIso: (self: Zoned) => string = Internal.zonedOffsetIso
|
|
1442
1206
|
|
|
1443
1207
|
/**
|
|
1444
1208
|
* Get the milliseconds since the Unix epoch of a `DateTime`.
|
|
@@ -1446,7 +1210,7 @@ export const zonedOffsetIso = (self: Zoned): string => offsetToString(zonedOffse
|
|
|
1446
1210
|
* @since 3.6.0
|
|
1447
1211
|
* @category conversions
|
|
1448
1212
|
*/
|
|
1449
|
-
export const toEpochMillis
|
|
1213
|
+
export const toEpochMillis: (self: DateTime) => number = Internal.toEpochMillis
|
|
1450
1214
|
|
|
1451
1215
|
/**
|
|
1452
1216
|
* Remove the time aspect of a `DateTime`, first adjusting for the time
|
|
@@ -1455,6 +1219,7 @@ export const toEpochMillis = (self: DateTime): number => self.epochMillis
|
|
|
1455
1219
|
* @since 3.6.0
|
|
1456
1220
|
* @category conversions
|
|
1457
1221
|
* @example
|
|
1222
|
+
* ```ts
|
|
1458
1223
|
* import { DateTime } from "effect"
|
|
1459
1224
|
*
|
|
1460
1225
|
* // returns "2024-01-01T00:00:00Z"
|
|
@@ -1465,28 +1230,14 @@ export const toEpochMillis = (self: DateTime): number => self.epochMillis
|
|
|
1465
1230
|
* DateTime.removeTime,
|
|
1466
1231
|
* DateTime.formatIso
|
|
1467
1232
|
* )
|
|
1233
|
+
* ```
|
|
1468
1234
|
*/
|
|
1469
|
-
export const removeTime
|
|
1470
|
-
withDate(self, (date) => {
|
|
1471
|
-
date.setUTCHours(0, 0, 0, 0)
|
|
1472
|
-
return makeUtc(date.getTime())
|
|
1473
|
-
})
|
|
1235
|
+
export const removeTime: (self: DateTime) => Utc = Internal.removeTime
|
|
1474
1236
|
|
|
1475
1237
|
// =============================================================================
|
|
1476
1238
|
// parts
|
|
1477
1239
|
// =============================================================================
|
|
1478
1240
|
|
|
1479
|
-
const dateToParts = (date: Date): DateTime.PartsWithWeekday => ({
|
|
1480
|
-
millis: date.getUTCMilliseconds(),
|
|
1481
|
-
seconds: date.getUTCSeconds(),
|
|
1482
|
-
minutes: date.getUTCMinutes(),
|
|
1483
|
-
hours: date.getUTCHours(),
|
|
1484
|
-
day: date.getUTCDate(),
|
|
1485
|
-
weekDay: date.getUTCDay(),
|
|
1486
|
-
month: date.getUTCMonth() + 1,
|
|
1487
|
-
year: date.getUTCFullYear()
|
|
1488
|
-
})
|
|
1489
|
-
|
|
1490
1241
|
/**
|
|
1491
1242
|
* Get the different parts of a `DateTime` as an object.
|
|
1492
1243
|
*
|
|
@@ -1495,15 +1246,7 @@ const dateToParts = (date: Date): DateTime.PartsWithWeekday => ({
|
|
|
1495
1246
|
* @since 3.6.0
|
|
1496
1247
|
* @category parts
|
|
1497
1248
|
*/
|
|
1498
|
-
export const toParts
|
|
1499
|
-
if (self._tag === "Utc") {
|
|
1500
|
-
return toPartsUtc(self)
|
|
1501
|
-
} else if (self.partsAdjusted !== undefined) {
|
|
1502
|
-
return self.partsAdjusted
|
|
1503
|
-
}
|
|
1504
|
-
self.partsAdjusted = withDate(self, dateToParts)
|
|
1505
|
-
return self.partsAdjusted
|
|
1506
|
-
}
|
|
1249
|
+
export const toParts: (self: DateTime) => DateTime.PartsWithWeekday = Internal.toParts
|
|
1507
1250
|
|
|
1508
1251
|
/**
|
|
1509
1252
|
* Get the different parts of a `DateTime` as an object.
|
|
@@ -1513,13 +1256,7 @@ export const toParts = (self: DateTime): DateTime.PartsWithWeekday => {
|
|
|
1513
1256
|
* @since 3.6.0
|
|
1514
1257
|
* @category parts
|
|
1515
1258
|
*/
|
|
1516
|
-
export const toPartsUtc
|
|
1517
|
-
if (self.partsUtc !== undefined) {
|
|
1518
|
-
return self.partsUtc
|
|
1519
|
-
}
|
|
1520
|
-
self.partsUtc = withDateUtc(self, dateToParts)
|
|
1521
|
-
return self.partsUtc
|
|
1522
|
-
}
|
|
1259
|
+
export const toPartsUtc: (self: DateTime) => DateTime.PartsWithWeekday = Internal.toPartsUtc
|
|
1523
1260
|
|
|
1524
1261
|
/**
|
|
1525
1262
|
* Get a part of a `DateTime` as a number.
|
|
@@ -1529,11 +1266,13 @@ export const toPartsUtc = (self: DateTime): DateTime.PartsWithWeekday => {
|
|
|
1529
1266
|
* @since 3.6.0
|
|
1530
1267
|
* @category parts
|
|
1531
1268
|
* @example
|
|
1269
|
+
* ```ts
|
|
1532
1270
|
* import { DateTime } from "effect"
|
|
1533
1271
|
*
|
|
1534
1272
|
* const now = DateTime.unsafeMake({ year: 2024 })
|
|
1535
1273
|
* const year = DateTime.getPartUtc(now, "year")
|
|
1536
1274
|
* assert.strictEqual(year, 2024)
|
|
1275
|
+
* ```
|
|
1537
1276
|
*/
|
|
1538
1277
|
export const getPartUtc: {
|
|
1539
1278
|
/**
|
|
@@ -1544,11 +1283,13 @@ export const getPartUtc: {
|
|
|
1544
1283
|
* @since 3.6.0
|
|
1545
1284
|
* @category parts
|
|
1546
1285
|
* @example
|
|
1286
|
+
* ```ts
|
|
1547
1287
|
* import { DateTime } from "effect"
|
|
1548
1288
|
*
|
|
1549
1289
|
* const now = DateTime.unsafeMake({ year: 2024 })
|
|
1550
1290
|
* const year = DateTime.getPartUtc(now, "year")
|
|
1551
1291
|
* assert.strictEqual(year, 2024)
|
|
1292
|
+
* ```
|
|
1552
1293
|
*/
|
|
1553
1294
|
(part: keyof DateTime.PartsWithWeekday): (self: DateTime) => number
|
|
1554
1295
|
/**
|
|
@@ -1559,14 +1300,16 @@ export const getPartUtc: {
|
|
|
1559
1300
|
* @since 3.6.0
|
|
1560
1301
|
* @category parts
|
|
1561
1302
|
* @example
|
|
1303
|
+
* ```ts
|
|
1562
1304
|
* import { DateTime } from "effect"
|
|
1563
1305
|
*
|
|
1564
1306
|
* const now = DateTime.unsafeMake({ year: 2024 })
|
|
1565
1307
|
* const year = DateTime.getPartUtc(now, "year")
|
|
1566
1308
|
* assert.strictEqual(year, 2024)
|
|
1309
|
+
* ```
|
|
1567
1310
|
*/
|
|
1568
1311
|
(self: DateTime, part: keyof DateTime.PartsWithWeekday): number
|
|
1569
|
-
} =
|
|
1312
|
+
} = Internal.getPartUtc
|
|
1570
1313
|
|
|
1571
1314
|
/**
|
|
1572
1315
|
* Get a part of a `DateTime` as a number.
|
|
@@ -1576,11 +1319,13 @@ export const getPartUtc: {
|
|
|
1576
1319
|
* @since 3.6.0
|
|
1577
1320
|
* @category parts
|
|
1578
1321
|
* @example
|
|
1322
|
+
* ```ts
|
|
1579
1323
|
* import { DateTime } from "effect"
|
|
1580
1324
|
*
|
|
1581
1325
|
* const now = DateTime.unsafeMakeZoned({ year: 2024 }, { timeZone: "Europe/London" })
|
|
1582
1326
|
* const year = DateTime.getPart(now, "year")
|
|
1583
1327
|
* assert.strictEqual(year, 2024)
|
|
1328
|
+
* ```
|
|
1584
1329
|
*/
|
|
1585
1330
|
export const getPart: {
|
|
1586
1331
|
/**
|
|
@@ -1591,11 +1336,13 @@ export const getPart: {
|
|
|
1591
1336
|
* @since 3.6.0
|
|
1592
1337
|
* @category parts
|
|
1593
1338
|
* @example
|
|
1339
|
+
* ```ts
|
|
1594
1340
|
* import { DateTime } from "effect"
|
|
1595
1341
|
*
|
|
1596
1342
|
* const now = DateTime.unsafeMakeZoned({ year: 2024 }, { timeZone: "Europe/London" })
|
|
1597
1343
|
* const year = DateTime.getPart(now, "year")
|
|
1598
1344
|
* assert.strictEqual(year, 2024)
|
|
1345
|
+
* ```
|
|
1599
1346
|
*/
|
|
1600
1347
|
(part: keyof DateTime.PartsWithWeekday): (self: DateTime) => number
|
|
1601
1348
|
/**
|
|
@@ -1606,42 +1353,16 @@ export const getPart: {
|
|
|
1606
1353
|
* @since 3.6.0
|
|
1607
1354
|
* @category parts
|
|
1608
1355
|
* @example
|
|
1356
|
+
* ```ts
|
|
1609
1357
|
* import { DateTime } from "effect"
|
|
1610
1358
|
*
|
|
1611
1359
|
* const now = DateTime.unsafeMakeZoned({ year: 2024 }, { timeZone: "Europe/London" })
|
|
1612
1360
|
* const year = DateTime.getPart(now, "year")
|
|
1613
1361
|
* assert.strictEqual(year, 2024)
|
|
1362
|
+
* ```
|
|
1614
1363
|
*/
|
|
1615
1364
|
(self: DateTime, part: keyof DateTime.PartsWithWeekday): number
|
|
1616
|
-
} =
|
|
1617
|
-
|
|
1618
|
-
const setPartsDate = (date: Date, parts: Partial<DateTime.PartsWithWeekday>): void => {
|
|
1619
|
-
if (parts.year !== undefined) {
|
|
1620
|
-
date.setUTCFullYear(parts.year)
|
|
1621
|
-
}
|
|
1622
|
-
if (parts.month !== undefined) {
|
|
1623
|
-
date.setUTCMonth(parts.month - 1)
|
|
1624
|
-
}
|
|
1625
|
-
if (parts.day !== undefined) {
|
|
1626
|
-
date.setUTCDate(parts.day)
|
|
1627
|
-
}
|
|
1628
|
-
if (parts.weekDay !== undefined) {
|
|
1629
|
-
const diff = parts.weekDay - date.getUTCDay()
|
|
1630
|
-
date.setUTCDate(date.getUTCDate() + diff)
|
|
1631
|
-
}
|
|
1632
|
-
if (parts.hours !== undefined) {
|
|
1633
|
-
date.setUTCHours(parts.hours)
|
|
1634
|
-
}
|
|
1635
|
-
if (parts.minutes !== undefined) {
|
|
1636
|
-
date.setUTCMinutes(parts.minutes)
|
|
1637
|
-
}
|
|
1638
|
-
if (parts.seconds !== undefined) {
|
|
1639
|
-
date.setUTCSeconds(parts.seconds)
|
|
1640
|
-
}
|
|
1641
|
-
if (parts.millis !== undefined) {
|
|
1642
|
-
date.setUTCMilliseconds(parts.millis)
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1365
|
+
} = Internal.getPart
|
|
1645
1366
|
|
|
1646
1367
|
/**
|
|
1647
1368
|
* Set the different parts of a `DateTime` as an object.
|
|
@@ -1670,11 +1391,7 @@ export const setParts: {
|
|
|
1670
1391
|
* @category parts
|
|
1671
1392
|
*/
|
|
1672
1393
|
<A extends DateTime>(self: A, parts: Partial<DateTime.PartsWithWeekday>): DateTime.PreserveZone<A>
|
|
1673
|
-
} =
|
|
1674
|
-
2,
|
|
1675
|
-
(self: DateTime, parts: Partial<DateTime.PartsWithWeekday>): DateTime =>
|
|
1676
|
-
mutate(self, (date) => setPartsDate(date, parts))
|
|
1677
|
-
)
|
|
1394
|
+
} = Internal.setParts
|
|
1678
1395
|
|
|
1679
1396
|
/**
|
|
1680
1397
|
* Set the different parts of a `DateTime` as an object.
|
|
@@ -1697,24 +1414,18 @@ export const setPartsUtc: {
|
|
|
1697
1414
|
* @category parts
|
|
1698
1415
|
*/
|
|
1699
1416
|
<A extends DateTime>(self: A, parts: Partial<DateTime.PartsWithWeekday>): DateTime.PreserveZone<A>
|
|
1700
|
-
} =
|
|
1701
|
-
2,
|
|
1702
|
-
(self: DateTime, parts: Partial<DateTime.PartsWithWeekday>): DateTime =>
|
|
1703
|
-
mutateUtc(self, (date) => setPartsDate(date, parts))
|
|
1704
|
-
)
|
|
1417
|
+
} = Internal.setPartsUtc
|
|
1705
1418
|
|
|
1706
1419
|
// =============================================================================
|
|
1707
1420
|
// current time zone
|
|
1708
1421
|
// =============================================================================
|
|
1709
1422
|
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
TimeZone
|
|
1717
|
-
>() {}
|
|
1423
|
+
// =============================================================================
|
|
1424
|
+
// current time zone
|
|
1425
|
+
// =============================================================================
|
|
1426
|
+
|
|
1427
|
+
/** @internal */
|
|
1428
|
+
export class CurrentTimeZone extends Context.Tag("effect/DateTime/CurrentTimeZone")<CurrentTimeZone, TimeZone>() {}
|
|
1718
1429
|
|
|
1719
1430
|
/**
|
|
1720
1431
|
* Set the time zone of a `DateTime` to the current time zone, which is
|
|
@@ -1723,6 +1434,7 @@ export class CurrentTimeZone extends Context.Tag("effect/DateTime/CurrentTimeZon
|
|
|
1723
1434
|
* @since 3.6.0
|
|
1724
1435
|
* @category current time zone
|
|
1725
1436
|
* @example
|
|
1437
|
+
* ```ts
|
|
1726
1438
|
* import { DateTime, Effect } from "effect"
|
|
1727
1439
|
*
|
|
1728
1440
|
* Effect.gen(function* () {
|
|
@@ -1731,6 +1443,7 @@ export class CurrentTimeZone extends Context.Tag("effect/DateTime/CurrentTimeZon
|
|
|
1731
1443
|
* // set the time zone to "Europe/London"
|
|
1732
1444
|
* const zoned = yield* DateTime.setZoneCurrent(now)
|
|
1733
1445
|
* }).pipe(DateTime.withCurrentZoneNamed("Europe/London"))
|
|
1446
|
+
* ```
|
|
1734
1447
|
*/
|
|
1735
1448
|
export const setZoneCurrent = (self: DateTime): Effect.Effect<Zoned, never, CurrentTimeZone> =>
|
|
1736
1449
|
Effect.map(CurrentTimeZone, (zone) => setZone(self, zone))
|
|
@@ -1741,6 +1454,7 @@ export const setZoneCurrent = (self: DateTime): Effect.Effect<Zoned, never, Curr
|
|
|
1741
1454
|
* @since 3.6.0
|
|
1742
1455
|
* @category current time zone
|
|
1743
1456
|
* @example
|
|
1457
|
+
* ```ts
|
|
1744
1458
|
* import { DateTime, Effect } from "effect"
|
|
1745
1459
|
*
|
|
1746
1460
|
* const zone = DateTime.zoneUnsafeMakeNamed("Europe/London")
|
|
@@ -1748,6 +1462,7 @@ export const setZoneCurrent = (self: DateTime): Effect.Effect<Zoned, never, Curr
|
|
|
1748
1462
|
* Effect.gen(function* () {
|
|
1749
1463
|
* const now = yield* DateTime.nowInCurrentZone
|
|
1750
1464
|
* }).pipe(DateTime.withCurrentZone(zone))
|
|
1465
|
+
* ```
|
|
1751
1466
|
*/
|
|
1752
1467
|
export const withCurrentZone: {
|
|
1753
1468
|
/**
|
|
@@ -1756,6 +1471,7 @@ export const withCurrentZone: {
|
|
|
1756
1471
|
* @since 3.6.0
|
|
1757
1472
|
* @category current time zone
|
|
1758
1473
|
* @example
|
|
1474
|
+
* ```ts
|
|
1759
1475
|
* import { DateTime, Effect } from "effect"
|
|
1760
1476
|
*
|
|
1761
1477
|
* const zone = DateTime.zoneUnsafeMakeNamed("Europe/London")
|
|
@@ -1763,6 +1479,7 @@ export const withCurrentZone: {
|
|
|
1763
1479
|
* Effect.gen(function* () {
|
|
1764
1480
|
* const now = yield* DateTime.nowInCurrentZone
|
|
1765
1481
|
* }).pipe(DateTime.withCurrentZone(zone))
|
|
1482
|
+
* ```
|
|
1766
1483
|
*/
|
|
1767
1484
|
(zone: TimeZone): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, CurrentTimeZone>>
|
|
1768
1485
|
/**
|
|
@@ -1771,6 +1488,7 @@ export const withCurrentZone: {
|
|
|
1771
1488
|
* @since 3.6.0
|
|
1772
1489
|
* @category current time zone
|
|
1773
1490
|
* @example
|
|
1491
|
+
* ```ts
|
|
1774
1492
|
* import { DateTime, Effect } from "effect"
|
|
1775
1493
|
*
|
|
1776
1494
|
* const zone = DateTime.zoneUnsafeMakeNamed("Europe/London")
|
|
@@ -1778,12 +1496,15 @@ export const withCurrentZone: {
|
|
|
1778
1496
|
* Effect.gen(function* () {
|
|
1779
1497
|
* const now = yield* DateTime.nowInCurrentZone
|
|
1780
1498
|
* }).pipe(DateTime.withCurrentZone(zone))
|
|
1499
|
+
* ```
|
|
1781
1500
|
*/
|
|
1782
1501
|
<A, E, R>(effect: Effect.Effect<A, E, R>, zone: TimeZone): Effect.Effect<A, E, Exclude<R, CurrentTimeZone>>
|
|
1783
1502
|
} = dual(
|
|
1784
1503
|
2,
|
|
1785
|
-
<A, E, R>(
|
|
1786
|
-
Effect.
|
|
1504
|
+
<A, E, R>(
|
|
1505
|
+
effect: Effect.Effect<A, E, R>,
|
|
1506
|
+
zone: TimeZone
|
|
1507
|
+
): Effect.Effect<A, E, Exclude<R, CurrentTimeZone>> => Effect.provideService(effect, CurrentTimeZone, zone)
|
|
1787
1508
|
)
|
|
1788
1509
|
|
|
1789
1510
|
/**
|
|
@@ -1793,12 +1514,14 @@ export const withCurrentZone: {
|
|
|
1793
1514
|
* @since 3.6.0
|
|
1794
1515
|
* @category current time zone
|
|
1795
1516
|
* @example
|
|
1517
|
+
* ```ts
|
|
1796
1518
|
* import { DateTime, Effect } from "effect"
|
|
1797
1519
|
*
|
|
1798
1520
|
* Effect.gen(function* () {
|
|
1799
1521
|
* // will use the system's local time zone
|
|
1800
1522
|
* const now = yield* DateTime.nowInCurrentZone
|
|
1801
1523
|
* }).pipe(DateTime.withCurrentZoneLocal)
|
|
1524
|
+
* ```
|
|
1802
1525
|
*/
|
|
1803
1526
|
export const withCurrentZoneLocal = <A, E, R>(
|
|
1804
1527
|
effect: Effect.Effect<A, E, R>
|
|
@@ -1811,12 +1534,14 @@ export const withCurrentZoneLocal = <A, E, R>(
|
|
|
1811
1534
|
* @since 3.6.0
|
|
1812
1535
|
* @category current time zone
|
|
1813
1536
|
* @example
|
|
1537
|
+
* ```ts
|
|
1814
1538
|
* import { DateTime, Effect } from "effect"
|
|
1815
1539
|
*
|
|
1816
1540
|
* Effect.gen(function* () {
|
|
1817
1541
|
* // will use the system's local time zone
|
|
1818
1542
|
* const now = yield* DateTime.nowInCurrentZone
|
|
1819
1543
|
* }).pipe(DateTime.withCurrentZoneOffset(3 * 60 * 60 * 1000))
|
|
1544
|
+
* ```
|
|
1820
1545
|
*/
|
|
1821
1546
|
export const withCurrentZoneOffset: {
|
|
1822
1547
|
/**
|
|
@@ -1825,12 +1550,14 @@ export const withCurrentZoneOffset: {
|
|
|
1825
1550
|
* @since 3.6.0
|
|
1826
1551
|
* @category current time zone
|
|
1827
1552
|
* @example
|
|
1553
|
+
* ```ts
|
|
1828
1554
|
* import { DateTime, Effect } from "effect"
|
|
1829
1555
|
*
|
|
1830
1556
|
* Effect.gen(function* () {
|
|
1831
1557
|
* // will use the system's local time zone
|
|
1832
1558
|
* const now = yield* DateTime.nowInCurrentZone
|
|
1833
1559
|
* }).pipe(DateTime.withCurrentZoneOffset(3 * 60 * 60 * 1000))
|
|
1560
|
+
* ```
|
|
1834
1561
|
*/
|
|
1835
1562
|
(offset: number): <A, E, R>(
|
|
1836
1563
|
effect: Effect.Effect<A, E, R>
|
|
@@ -1841,12 +1568,14 @@ export const withCurrentZoneOffset: {
|
|
|
1841
1568
|
* @since 3.6.0
|
|
1842
1569
|
* @category current time zone
|
|
1843
1570
|
* @example
|
|
1571
|
+
* ```ts
|
|
1844
1572
|
* import { DateTime, Effect } from "effect"
|
|
1845
1573
|
*
|
|
1846
1574
|
* Effect.gen(function* () {
|
|
1847
1575
|
* // will use the system's local time zone
|
|
1848
1576
|
* const now = yield* DateTime.nowInCurrentZone
|
|
1849
1577
|
* }).pipe(DateTime.withCurrentZoneOffset(3 * 60 * 60 * 1000))
|
|
1578
|
+
* ```
|
|
1850
1579
|
*/
|
|
1851
1580
|
<A, E, R>(effect: Effect.Effect<A, E, R>, offset: number): Effect.Effect<A, E, Exclude<R, CurrentTimeZone>>
|
|
1852
1581
|
} = dual(
|
|
@@ -1864,12 +1593,14 @@ export const withCurrentZoneOffset: {
|
|
|
1864
1593
|
* @since 3.6.0
|
|
1865
1594
|
* @category current time zone
|
|
1866
1595
|
* @example
|
|
1596
|
+
* ```ts
|
|
1867
1597
|
* import { DateTime, Effect } from "effect"
|
|
1868
1598
|
*
|
|
1869
1599
|
* Effect.gen(function* () {
|
|
1870
1600
|
* // will use the "Europe/London" time zone
|
|
1871
1601
|
* const now = yield* DateTime.nowInCurrentZone
|
|
1872
1602
|
* }).pipe(DateTime.withCurrentZoneNamed("Europe/London"))
|
|
1603
|
+
* ```
|
|
1873
1604
|
*/
|
|
1874
1605
|
export const withCurrentZoneNamed: {
|
|
1875
1606
|
/**
|
|
@@ -1881,12 +1612,14 @@ export const withCurrentZoneNamed: {
|
|
|
1881
1612
|
* @since 3.6.0
|
|
1882
1613
|
* @category current time zone
|
|
1883
1614
|
* @example
|
|
1615
|
+
* ```ts
|
|
1884
1616
|
* import { DateTime, Effect } from "effect"
|
|
1885
1617
|
*
|
|
1886
1618
|
* Effect.gen(function* () {
|
|
1887
1619
|
* // will use the "Europe/London" time zone
|
|
1888
1620
|
* const now = yield* DateTime.nowInCurrentZone
|
|
1889
1621
|
* }).pipe(DateTime.withCurrentZoneNamed("Europe/London"))
|
|
1622
|
+
* ```
|
|
1890
1623
|
*/
|
|
1891
1624
|
(zone: string): <A, E, R>(
|
|
1892
1625
|
effect: Effect.Effect<A, E, R>
|
|
@@ -1900,12 +1633,14 @@ export const withCurrentZoneNamed: {
|
|
|
1900
1633
|
* @since 3.6.0
|
|
1901
1634
|
* @category current time zone
|
|
1902
1635
|
* @example
|
|
1636
|
+
* ```ts
|
|
1903
1637
|
* import { DateTime, Effect } from "effect"
|
|
1904
1638
|
*
|
|
1905
1639
|
* Effect.gen(function* () {
|
|
1906
1640
|
* // will use the "Europe/London" time zone
|
|
1907
1641
|
* const now = yield* DateTime.nowInCurrentZone
|
|
1908
1642
|
* }).pipe(DateTime.withCurrentZoneNamed("Europe/London"))
|
|
1643
|
+
* ```
|
|
1909
1644
|
*/
|
|
1910
1645
|
<A, E, R>(
|
|
1911
1646
|
effect: Effect.Effect<A, E, R>,
|
|
@@ -1926,87 +1661,21 @@ export const withCurrentZoneNamed: {
|
|
|
1926
1661
|
* @since 3.6.0
|
|
1927
1662
|
* @category current time zone
|
|
1928
1663
|
* @example
|
|
1664
|
+
* ```ts
|
|
1929
1665
|
* import { DateTime, Effect } from "effect"
|
|
1930
1666
|
*
|
|
1931
1667
|
* Effect.gen(function* () {
|
|
1932
1668
|
* // will use the "Europe/London" time zone
|
|
1933
1669
|
* const now = yield* DateTime.nowInCurrentZone
|
|
1934
1670
|
* }).pipe(DateTime.withCurrentZoneNamed("Europe/London"))
|
|
1671
|
+
* ```
|
|
1935
1672
|
*/
|
|
1936
|
-
export const nowInCurrentZone: Effect.Effect<Zoned, never, CurrentTimeZone> = Effect.flatMap(
|
|
1937
|
-
now,
|
|
1938
|
-
setZoneCurrent
|
|
1939
|
-
)
|
|
1940
|
-
|
|
1941
|
-
/**
|
|
1942
|
-
* Create a Layer from the given time zone.
|
|
1943
|
-
*
|
|
1944
|
-
* @since 3.6.0
|
|
1945
|
-
* @category current time zone
|
|
1946
|
-
*/
|
|
1947
|
-
export const layerCurrentZone = (zone: TimeZone): Layer.Layer<CurrentTimeZone> => Layer.succeed(CurrentTimeZone, zone)
|
|
1948
|
-
|
|
1949
|
-
/**
|
|
1950
|
-
* Create a Layer from the given time zone offset.
|
|
1951
|
-
*
|
|
1952
|
-
* @since 3.6.0
|
|
1953
|
-
* @category current time zone
|
|
1954
|
-
*/
|
|
1955
|
-
export const layerCurrentZoneOffset = (offset: number): Layer.Layer<CurrentTimeZone> =>
|
|
1956
|
-
Layer.succeed(CurrentTimeZone, zoneMakeOffset(offset))
|
|
1957
|
-
|
|
1958
|
-
/**
|
|
1959
|
-
* Create a Layer from the given IANA time zone identifier.
|
|
1960
|
-
*
|
|
1961
|
-
* @since 3.6.0
|
|
1962
|
-
* @category current time zone
|
|
1963
|
-
*/
|
|
1964
|
-
export const layerCurrentZoneNamed = (zoneId: string): Layer.Layer<CurrentTimeZone, IllegalArgumentException> =>
|
|
1965
|
-
Layer.effect(CurrentTimeZone, zoneMakeNamedEffect(zoneId))
|
|
1966
|
-
|
|
1967
|
-
/**
|
|
1968
|
-
* Create a Layer from the systems local time zone.
|
|
1969
|
-
*
|
|
1970
|
-
* @since 3.6.0
|
|
1971
|
-
* @category current time zone
|
|
1972
|
-
*/
|
|
1973
|
-
export const layerCurrentZoneLocal: Layer.Layer<CurrentTimeZone> = Layer.sync(
|
|
1974
|
-
CurrentTimeZone,
|
|
1975
|
-
zoneMakeLocal
|
|
1976
|
-
)
|
|
1673
|
+
export const nowInCurrentZone: Effect.Effect<Zoned, never, CurrentTimeZone> = Effect.flatMap(now, setZoneCurrent)
|
|
1977
1674
|
|
|
1978
1675
|
// =============================================================================
|
|
1979
1676
|
// mapping
|
|
1980
1677
|
// =============================================================================
|
|
1981
1678
|
|
|
1982
|
-
const makeZonedFromAdjusted = (adjustedMillis: number, zone: TimeZone): Zoned => {
|
|
1983
|
-
const offset = zone._tag === "Offset" ? zone.offset : calculateNamedOffset(adjustedMillis, zone)
|
|
1984
|
-
return makeZonedProto(adjustedMillis - offset, zone)
|
|
1985
|
-
}
|
|
1986
|
-
|
|
1987
|
-
const offsetRegex = /([+-])(\d{2}):(\d{2})$/
|
|
1988
|
-
const parseOffset = (offset: string): number | null => {
|
|
1989
|
-
const match = offsetRegex.exec(offset)
|
|
1990
|
-
if (match === null) {
|
|
1991
|
-
return null
|
|
1992
|
-
}
|
|
1993
|
-
const [, sign, hours, minutes] = match
|
|
1994
|
-
return (sign === "+" ? 1 : -1) * (Number(hours) * 60 + Number(minutes)) * 60 * 1000
|
|
1995
|
-
}
|
|
1996
|
-
|
|
1997
|
-
const calculateNamedOffset = (adjustedMillis: number, zone: TimeZone.Named): number => {
|
|
1998
|
-
const offset = zone.format.formatToParts(adjustedMillis).find((_) => _.type === "timeZoneName")?.value ?? ""
|
|
1999
|
-
if (offset === "GMT") {
|
|
2000
|
-
return 0
|
|
2001
|
-
}
|
|
2002
|
-
const result = parseOffset(offset)
|
|
2003
|
-
if (result === null) {
|
|
2004
|
-
// fallback to using the adjusted date
|
|
2005
|
-
return zonedOffset(makeZonedProto(adjustedMillis, zone))
|
|
2006
|
-
}
|
|
2007
|
-
return result
|
|
2008
|
-
}
|
|
2009
|
-
|
|
2010
1679
|
/**
|
|
2011
1680
|
* Modify a `DateTime` by applying a function to a cloned `Date` instance.
|
|
2012
1681
|
*
|
|
@@ -2017,6 +1686,10 @@ const calculateNamedOffset = (adjustedMillis: number, zone: TimeZone.Named): num
|
|
|
2017
1686
|
* @category mapping
|
|
2018
1687
|
*/
|
|
2019
1688
|
export const mutate: {
|
|
1689
|
+
// =============================================================================
|
|
1690
|
+
// mapping
|
|
1691
|
+
// =============================================================================
|
|
1692
|
+
|
|
2020
1693
|
/**
|
|
2021
1694
|
* Modify a `DateTime` by applying a function to a cloned `Date` instance.
|
|
2022
1695
|
*
|
|
@@ -2027,6 +1700,10 @@ export const mutate: {
|
|
|
2027
1700
|
* @category mapping
|
|
2028
1701
|
*/
|
|
2029
1702
|
(f: (date: Date) => void): <A extends DateTime>(self: A) => DateTime.PreserveZone<A>
|
|
1703
|
+
// =============================================================================
|
|
1704
|
+
// mapping
|
|
1705
|
+
// =============================================================================
|
|
1706
|
+
|
|
2030
1707
|
/**
|
|
2031
1708
|
* Modify a `DateTime` by applying a function to a cloned `Date` instance.
|
|
2032
1709
|
*
|
|
@@ -2037,17 +1714,7 @@ export const mutate: {
|
|
|
2037
1714
|
* @category mapping
|
|
2038
1715
|
*/
|
|
2039
1716
|
<A extends DateTime>(self: A, f: (date: Date) => void): DateTime.PreserveZone<A>
|
|
2040
|
-
} =
|
|
2041
|
-
if (self._tag === "Utc") {
|
|
2042
|
-
const date = toDateUtc(self)
|
|
2043
|
-
f(date)
|
|
2044
|
-
return makeUtc(date.getTime())
|
|
2045
|
-
}
|
|
2046
|
-
const adjustedDate = toDate(self)
|
|
2047
|
-
const newAdjustedDate = new Date(adjustedDate.getTime())
|
|
2048
|
-
f(newAdjustedDate)
|
|
2049
|
-
return makeZonedFromAdjusted(newAdjustedDate.getTime(), self.zone)
|
|
2050
|
-
})
|
|
1717
|
+
} = Internal.mutate
|
|
2051
1718
|
|
|
2052
1719
|
/**
|
|
2053
1720
|
* Modify a `DateTime` by applying a function to a cloned UTC `Date` instance.
|
|
@@ -2070,12 +1737,7 @@ export const mutateUtc: {
|
|
|
2070
1737
|
* @category mapping
|
|
2071
1738
|
*/
|
|
2072
1739
|
<A extends DateTime>(self: A, f: (date: Date) => void): DateTime.PreserveZone<A>
|
|
2073
|
-
} =
|
|
2074
|
-
mapEpochMillis(self, (millis) => {
|
|
2075
|
-
const date = new Date(millis)
|
|
2076
|
-
f(date)
|
|
2077
|
-
return date.getTime()
|
|
2078
|
-
}))
|
|
1740
|
+
} = Internal.mutateUtc
|
|
2079
1741
|
|
|
2080
1742
|
/**
|
|
2081
1743
|
* Transform a `DateTime` by applying a function to the number of milliseconds
|
|
@@ -2084,12 +1746,14 @@ export const mutateUtc: {
|
|
|
2084
1746
|
* @since 3.6.0
|
|
2085
1747
|
* @category mapping
|
|
2086
1748
|
* @example
|
|
1749
|
+
* ```ts
|
|
2087
1750
|
* import { DateTime } from "effect"
|
|
2088
1751
|
*
|
|
2089
1752
|
* // add 10 milliseconds
|
|
2090
1753
|
* DateTime.unsafeMake(0).pipe(
|
|
2091
1754
|
* DateTime.mapEpochMillis((millis) => millis + 10)
|
|
2092
1755
|
* )
|
|
1756
|
+
* ```
|
|
2093
1757
|
*/
|
|
2094
1758
|
export const mapEpochMillis: {
|
|
2095
1759
|
/**
|
|
@@ -2099,12 +1763,14 @@ export const mapEpochMillis: {
|
|
|
2099
1763
|
* @since 3.6.0
|
|
2100
1764
|
* @category mapping
|
|
2101
1765
|
* @example
|
|
1766
|
+
* ```ts
|
|
2102
1767
|
* import { DateTime } from "effect"
|
|
2103
1768
|
*
|
|
2104
1769
|
* // add 10 milliseconds
|
|
2105
1770
|
* DateTime.unsafeMake(0).pipe(
|
|
2106
1771
|
* DateTime.mapEpochMillis((millis) => millis + 10)
|
|
2107
1772
|
* )
|
|
1773
|
+
* ```
|
|
2108
1774
|
*/
|
|
2109
1775
|
(f: (millis: number) => number): <A extends DateTime>(self: A) => DateTime.PreserveZone<A>
|
|
2110
1776
|
/**
|
|
@@ -2114,18 +1780,17 @@ export const mapEpochMillis: {
|
|
|
2114
1780
|
* @since 3.6.0
|
|
2115
1781
|
* @category mapping
|
|
2116
1782
|
* @example
|
|
1783
|
+
* ```ts
|
|
2117
1784
|
* import { DateTime } from "effect"
|
|
2118
1785
|
*
|
|
2119
1786
|
* // add 10 milliseconds
|
|
2120
1787
|
* DateTime.unsafeMake(0).pipe(
|
|
2121
1788
|
* DateTime.mapEpochMillis((millis) => millis + 10)
|
|
2122
1789
|
* )
|
|
1790
|
+
* ```
|
|
2123
1791
|
*/
|
|
2124
1792
|
<A extends DateTime>(self: A, f: (millis: number) => number): DateTime.PreserveZone<A>
|
|
2125
|
-
} =
|
|
2126
|
-
const millis = f(toEpochMillis(self))
|
|
2127
|
-
return self._tag === "Utc" ? makeUtc(millis) : makeZonedProto(millis, self.zone)
|
|
2128
|
-
})
|
|
1793
|
+
} = Internal.mapEpochMillis
|
|
2129
1794
|
|
|
2130
1795
|
/**
|
|
2131
1796
|
* Using the time zone adjusted `Date`, apply a function to the `Date` and
|
|
@@ -2134,12 +1799,14 @@ export const mapEpochMillis: {
|
|
|
2134
1799
|
* @since 3.6.0
|
|
2135
1800
|
* @category mapping
|
|
2136
1801
|
* @example
|
|
1802
|
+
* ```ts
|
|
2137
1803
|
* import { DateTime } from "effect"
|
|
2138
1804
|
*
|
|
2139
1805
|
* // get the time zone adjusted date in milliseconds
|
|
2140
1806
|
* DateTime.unsafeMakeZoned(0, { timeZone: "Europe/London" }).pipe(
|
|
2141
1807
|
* DateTime.withDate((date) => date.getTime())
|
|
2142
1808
|
* )
|
|
1809
|
+
* ```
|
|
2143
1810
|
*/
|
|
2144
1811
|
export const withDate: {
|
|
2145
1812
|
/**
|
|
@@ -2149,12 +1816,14 @@ export const withDate: {
|
|
|
2149
1816
|
* @since 3.6.0
|
|
2150
1817
|
* @category mapping
|
|
2151
1818
|
* @example
|
|
1819
|
+
* ```ts
|
|
2152
1820
|
* import { DateTime } from "effect"
|
|
2153
1821
|
*
|
|
2154
1822
|
* // get the time zone adjusted date in milliseconds
|
|
2155
1823
|
* DateTime.unsafeMakeZoned(0, { timeZone: "Europe/London" }).pipe(
|
|
2156
1824
|
* DateTime.withDate((date) => date.getTime())
|
|
2157
1825
|
* )
|
|
1826
|
+
* ```
|
|
2158
1827
|
*/
|
|
2159
1828
|
<A>(f: (date: Date) => A): (self: DateTime) => A
|
|
2160
1829
|
/**
|
|
@@ -2164,15 +1833,17 @@ export const withDate: {
|
|
|
2164
1833
|
* @since 3.6.0
|
|
2165
1834
|
* @category mapping
|
|
2166
1835
|
* @example
|
|
1836
|
+
* ```ts
|
|
2167
1837
|
* import { DateTime } from "effect"
|
|
2168
1838
|
*
|
|
2169
1839
|
* // get the time zone adjusted date in milliseconds
|
|
2170
1840
|
* DateTime.unsafeMakeZoned(0, { timeZone: "Europe/London" }).pipe(
|
|
2171
1841
|
* DateTime.withDate((date) => date.getTime())
|
|
2172
1842
|
* )
|
|
1843
|
+
* ```
|
|
2173
1844
|
*/
|
|
2174
1845
|
<A>(self: DateTime, f: (date: Date) => A): A
|
|
2175
|
-
} =
|
|
1846
|
+
} = Internal.withDate
|
|
2176
1847
|
|
|
2177
1848
|
/**
|
|
2178
1849
|
* Using the time zone adjusted `Date`, apply a function to the `Date` and
|
|
@@ -2181,12 +1852,14 @@ export const withDate: {
|
|
|
2181
1852
|
* @since 3.6.0
|
|
2182
1853
|
* @category mapping
|
|
2183
1854
|
* @example
|
|
1855
|
+
* ```ts
|
|
2184
1856
|
* import { DateTime } from "effect"
|
|
2185
1857
|
*
|
|
2186
1858
|
* // get the date in milliseconds
|
|
2187
1859
|
* DateTime.unsafeMake(0).pipe(
|
|
2188
1860
|
* DateTime.withDateUtc((date) => date.getTime())
|
|
2189
1861
|
* )
|
|
1862
|
+
* ```
|
|
2190
1863
|
*/
|
|
2191
1864
|
export const withDateUtc: {
|
|
2192
1865
|
/**
|
|
@@ -2196,12 +1869,14 @@ export const withDateUtc: {
|
|
|
2196
1869
|
* @since 3.6.0
|
|
2197
1870
|
* @category mapping
|
|
2198
1871
|
* @example
|
|
1872
|
+
* ```ts
|
|
2199
1873
|
* import { DateTime } from "effect"
|
|
2200
1874
|
*
|
|
2201
1875
|
* // get the date in milliseconds
|
|
2202
1876
|
* DateTime.unsafeMake(0).pipe(
|
|
2203
1877
|
* DateTime.withDateUtc((date) => date.getTime())
|
|
2204
1878
|
* )
|
|
1879
|
+
* ```
|
|
2205
1880
|
*/
|
|
2206
1881
|
<A>(f: (date: Date) => A): (self: DateTime) => A
|
|
2207
1882
|
/**
|
|
@@ -2211,15 +1886,17 @@ export const withDateUtc: {
|
|
|
2211
1886
|
* @since 3.6.0
|
|
2212
1887
|
* @category mapping
|
|
2213
1888
|
* @example
|
|
1889
|
+
* ```ts
|
|
2214
1890
|
* import { DateTime } from "effect"
|
|
2215
1891
|
*
|
|
2216
1892
|
* // get the date in milliseconds
|
|
2217
1893
|
* DateTime.unsafeMake(0).pipe(
|
|
2218
1894
|
* DateTime.withDateUtc((date) => date.getTime())
|
|
2219
1895
|
* )
|
|
1896
|
+
* ```
|
|
2220
1897
|
*/
|
|
2221
1898
|
<A>(self: DateTime, f: (date: Date) => A): A
|
|
2222
|
-
} =
|
|
1899
|
+
} = Internal.withDateUtc
|
|
2223
1900
|
|
|
2224
1901
|
/**
|
|
2225
1902
|
* @since 3.6.0
|
|
@@ -2247,10 +1924,7 @@ export const match: {
|
|
|
2247
1924
|
readonly onZoned: (_: Zoned) => B
|
|
2248
1925
|
}
|
|
2249
1926
|
): A | B
|
|
2250
|
-
} =
|
|
2251
|
-
readonly onUtc: (_: Utc) => A
|
|
2252
|
-
readonly onZoned: (_: Zoned) => B
|
|
2253
|
-
}): A | B => self._tag === "Utc" ? options.onUtc(self) : options.onZoned(self))
|
|
1927
|
+
} = Internal.match
|
|
2254
1928
|
|
|
2255
1929
|
// =============================================================================
|
|
2256
1930
|
// math
|
|
@@ -2262,12 +1936,14 @@ export const match: {
|
|
|
2262
1936
|
* @since 3.6.0
|
|
2263
1937
|
* @category math
|
|
2264
1938
|
* @example
|
|
1939
|
+
* ```ts
|
|
2265
1940
|
* import { DateTime } from "effect"
|
|
2266
1941
|
*
|
|
2267
1942
|
* // add 5 minutes
|
|
2268
1943
|
* DateTime.unsafeMake(0).pipe(
|
|
2269
1944
|
* DateTime.addDuration("5 minutes")
|
|
2270
1945
|
* )
|
|
1946
|
+
* ```
|
|
2271
1947
|
*/
|
|
2272
1948
|
export const addDuration: {
|
|
2273
1949
|
// =============================================================================
|
|
@@ -2280,12 +1956,14 @@ export const addDuration: {
|
|
|
2280
1956
|
* @since 3.6.0
|
|
2281
1957
|
* @category math
|
|
2282
1958
|
* @example
|
|
1959
|
+
* ```ts
|
|
2283
1960
|
* import { DateTime } from "effect"
|
|
2284
1961
|
*
|
|
2285
1962
|
* // add 5 minutes
|
|
2286
1963
|
* DateTime.unsafeMake(0).pipe(
|
|
2287
1964
|
* DateTime.addDuration("5 minutes")
|
|
2288
1965
|
* )
|
|
1966
|
+
* ```
|
|
2289
1967
|
*/
|
|
2290
1968
|
(duration: Duration.DurationInput): <A extends DateTime>(self: A) => DateTime.PreserveZone<A>
|
|
2291
1969
|
// =============================================================================
|
|
@@ -2298,19 +1976,17 @@ export const addDuration: {
|
|
|
2298
1976
|
* @since 3.6.0
|
|
2299
1977
|
* @category math
|
|
2300
1978
|
* @example
|
|
1979
|
+
* ```ts
|
|
2301
1980
|
* import { DateTime } from "effect"
|
|
2302
1981
|
*
|
|
2303
1982
|
* // add 5 minutes
|
|
2304
1983
|
* DateTime.unsafeMake(0).pipe(
|
|
2305
1984
|
* DateTime.addDuration("5 minutes")
|
|
2306
1985
|
* )
|
|
1986
|
+
* ```
|
|
2307
1987
|
*/
|
|
2308
1988
|
<A extends DateTime>(self: A, duration: Duration.DurationInput): DateTime.PreserveZone<A>
|
|
2309
|
-
} =
|
|
2310
|
-
2,
|
|
2311
|
-
(self: DateTime, duration: Duration.DurationInput): DateTime =>
|
|
2312
|
-
mapEpochMillis(self, (millis) => millis + Duration.toMillis(duration))
|
|
2313
|
-
)
|
|
1989
|
+
} = Internal.addDuration
|
|
2314
1990
|
|
|
2315
1991
|
/**
|
|
2316
1992
|
* Subtract the given `Duration` from a `DateTime`.
|
|
@@ -2318,12 +1994,14 @@ export const addDuration: {
|
|
|
2318
1994
|
* @since 3.6.0
|
|
2319
1995
|
* @category math
|
|
2320
1996
|
* @example
|
|
1997
|
+
* ```ts
|
|
2321
1998
|
* import { DateTime } from "effect"
|
|
2322
1999
|
*
|
|
2323
2000
|
* // subtract 5 minutes
|
|
2324
2001
|
* DateTime.unsafeMake(0).pipe(
|
|
2325
2002
|
* DateTime.subtractDuration("5 minutes")
|
|
2326
2003
|
* )
|
|
2004
|
+
* ```
|
|
2327
2005
|
*/
|
|
2328
2006
|
export const subtractDuration: {
|
|
2329
2007
|
/**
|
|
@@ -2332,12 +2010,14 @@ export const subtractDuration: {
|
|
|
2332
2010
|
* @since 3.6.0
|
|
2333
2011
|
* @category math
|
|
2334
2012
|
* @example
|
|
2013
|
+
* ```ts
|
|
2335
2014
|
* import { DateTime } from "effect"
|
|
2336
2015
|
*
|
|
2337
2016
|
* // subtract 5 minutes
|
|
2338
2017
|
* DateTime.unsafeMake(0).pipe(
|
|
2339
2018
|
* DateTime.subtractDuration("5 minutes")
|
|
2340
2019
|
* )
|
|
2020
|
+
* ```
|
|
2341
2021
|
*/
|
|
2342
2022
|
(duration: Duration.DurationInput): <A extends DateTime>(self: A) => DateTime.PreserveZone<A>
|
|
2343
2023
|
/**
|
|
@@ -2346,23 +2026,17 @@ export const subtractDuration: {
|
|
|
2346
2026
|
* @since 3.6.0
|
|
2347
2027
|
* @category math
|
|
2348
2028
|
* @example
|
|
2029
|
+
* ```ts
|
|
2349
2030
|
* import { DateTime } from "effect"
|
|
2350
2031
|
*
|
|
2351
2032
|
* // subtract 5 minutes
|
|
2352
2033
|
* DateTime.unsafeMake(0).pipe(
|
|
2353
2034
|
* DateTime.subtractDuration("5 minutes")
|
|
2354
2035
|
* )
|
|
2036
|
+
* ```
|
|
2355
2037
|
*/
|
|
2356
2038
|
<A extends DateTime>(self: A, duration: Duration.DurationInput): DateTime.PreserveZone<A>
|
|
2357
|
-
} =
|
|
2358
|
-
2,
|
|
2359
|
-
(self: DateTime, duration: Duration.DurationInput): DateTime =>
|
|
2360
|
-
mapEpochMillis(self, (millis) => millis - Duration.toMillis(duration))
|
|
2361
|
-
)
|
|
2362
|
-
|
|
2363
|
-
const addMillis = (date: Date, amount: number): void => {
|
|
2364
|
-
date.setTime(date.getTime() + amount)
|
|
2365
|
-
}
|
|
2039
|
+
} = Internal.subtractDuration
|
|
2366
2040
|
|
|
2367
2041
|
/**
|
|
2368
2042
|
* Add the given `amount` of `unit`'s to a `DateTime`.
|
|
@@ -2373,12 +2047,14 @@ const addMillis = (date: Date, amount: number): void => {
|
|
|
2373
2047
|
* @since 3.6.0
|
|
2374
2048
|
* @category math
|
|
2375
2049
|
* @example
|
|
2050
|
+
* ```ts
|
|
2376
2051
|
* import { DateTime } from "effect"
|
|
2377
2052
|
*
|
|
2378
2053
|
* // add 5 minutes
|
|
2379
2054
|
* DateTime.unsafeMake(0).pipe(
|
|
2380
2055
|
* DateTime.add({ minutes: 5 })
|
|
2381
2056
|
* )
|
|
2057
|
+
* ```
|
|
2382
2058
|
*/
|
|
2383
2059
|
export const add: {
|
|
2384
2060
|
/**
|
|
@@ -2390,12 +2066,14 @@ export const add: {
|
|
|
2390
2066
|
* @since 3.6.0
|
|
2391
2067
|
* @category math
|
|
2392
2068
|
* @example
|
|
2069
|
+
* ```ts
|
|
2393
2070
|
* import { DateTime } from "effect"
|
|
2394
2071
|
*
|
|
2395
2072
|
* // add 5 minutes
|
|
2396
2073
|
* DateTime.unsafeMake(0).pipe(
|
|
2397
2074
|
* DateTime.add({ minutes: 5 })
|
|
2398
2075
|
* )
|
|
2076
|
+
* ```
|
|
2399
2077
|
*/
|
|
2400
2078
|
(parts: Partial<DateTime.PartsForMath>): <A extends DateTime>(self: A) => DateTime.PreserveZone<A>
|
|
2401
2079
|
/**
|
|
@@ -2407,54 +2085,17 @@ export const add: {
|
|
|
2407
2085
|
* @since 3.6.0
|
|
2408
2086
|
* @category math
|
|
2409
2087
|
* @example
|
|
2088
|
+
* ```ts
|
|
2410
2089
|
* import { DateTime } from "effect"
|
|
2411
2090
|
*
|
|
2412
2091
|
* // add 5 minutes
|
|
2413
2092
|
* DateTime.unsafeMake(0).pipe(
|
|
2414
2093
|
* DateTime.add({ minutes: 5 })
|
|
2415
2094
|
* )
|
|
2095
|
+
* ```
|
|
2416
2096
|
*/
|
|
2417
2097
|
<A extends DateTime>(self: A, parts: Partial<DateTime.PartsForMath>): DateTime.PreserveZone<A>
|
|
2418
|
-
} =
|
|
2419
|
-
mutate(self, (date) => {
|
|
2420
|
-
if (parts.millis) {
|
|
2421
|
-
addMillis(date, parts.millis)
|
|
2422
|
-
}
|
|
2423
|
-
if (parts.seconds) {
|
|
2424
|
-
addMillis(date, parts.seconds * 1000)
|
|
2425
|
-
}
|
|
2426
|
-
if (parts.minutes) {
|
|
2427
|
-
addMillis(date, parts.minutes * 60 * 1000)
|
|
2428
|
-
}
|
|
2429
|
-
if (parts.hours) {
|
|
2430
|
-
addMillis(date, parts.hours * 60 * 60 * 1000)
|
|
2431
|
-
}
|
|
2432
|
-
if (parts.days) {
|
|
2433
|
-
date.setUTCDate(date.getUTCDate() + parts.days)
|
|
2434
|
-
}
|
|
2435
|
-
if (parts.weeks) {
|
|
2436
|
-
date.setUTCDate(date.getUTCDate() + parts.weeks * 7)
|
|
2437
|
-
}
|
|
2438
|
-
if (parts.months) {
|
|
2439
|
-
const day = date.getUTCDate()
|
|
2440
|
-
date.setUTCMonth(date.getUTCMonth() + parts.months + 1, 0)
|
|
2441
|
-
if (day < date.getUTCDate()) {
|
|
2442
|
-
date.setUTCDate(day)
|
|
2443
|
-
}
|
|
2444
|
-
}
|
|
2445
|
-
if (parts.years) {
|
|
2446
|
-
const day = date.getUTCDate()
|
|
2447
|
-
const month = date.getUTCMonth()
|
|
2448
|
-
date.setUTCFullYear(
|
|
2449
|
-
date.getUTCFullYear() + parts.years,
|
|
2450
|
-
month + 1,
|
|
2451
|
-
0
|
|
2452
|
-
)
|
|
2453
|
-
if (day < date.getUTCDate()) {
|
|
2454
|
-
date.setUTCDate(day)
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
}))
|
|
2098
|
+
} = Internal.add
|
|
2458
2099
|
|
|
2459
2100
|
/**
|
|
2460
2101
|
* Subtract the given `amount` of `unit`'s from a `DateTime`.
|
|
@@ -2462,12 +2103,14 @@ export const add: {
|
|
|
2462
2103
|
* @since 3.6.0
|
|
2463
2104
|
* @category math
|
|
2464
2105
|
* @example
|
|
2106
|
+
* ```ts
|
|
2465
2107
|
* import { DateTime } from "effect"
|
|
2466
2108
|
*
|
|
2467
2109
|
* // subtract 5 minutes
|
|
2468
2110
|
* DateTime.unsafeMake(0).pipe(
|
|
2469
2111
|
* DateTime.subtract({ minutes: 5 })
|
|
2470
2112
|
* )
|
|
2113
|
+
* ```
|
|
2471
2114
|
*/
|
|
2472
2115
|
export const subtract: {
|
|
2473
2116
|
/**
|
|
@@ -2476,12 +2119,14 @@ export const subtract: {
|
|
|
2476
2119
|
* @since 3.6.0
|
|
2477
2120
|
* @category math
|
|
2478
2121
|
* @example
|
|
2122
|
+
* ```ts
|
|
2479
2123
|
* import { DateTime } from "effect"
|
|
2480
2124
|
*
|
|
2481
2125
|
* // subtract 5 minutes
|
|
2482
2126
|
* DateTime.unsafeMake(0).pipe(
|
|
2483
2127
|
* DateTime.subtract({ minutes: 5 })
|
|
2484
2128
|
* )
|
|
2129
|
+
* ```
|
|
2485
2130
|
*/
|
|
2486
2131
|
(parts: Partial<DateTime.PartsForMath>): <A extends DateTime>(self: A) => DateTime.PreserveZone<A>
|
|
2487
2132
|
/**
|
|
@@ -2490,62 +2135,17 @@ export const subtract: {
|
|
|
2490
2135
|
* @since 3.6.0
|
|
2491
2136
|
* @category math
|
|
2492
2137
|
* @example
|
|
2138
|
+
* ```ts
|
|
2493
2139
|
* import { DateTime } from "effect"
|
|
2494
2140
|
*
|
|
2495
2141
|
* // subtract 5 minutes
|
|
2496
2142
|
* DateTime.unsafeMake(0).pipe(
|
|
2497
2143
|
* DateTime.subtract({ minutes: 5 })
|
|
2498
2144
|
* )
|
|
2145
|
+
* ```
|
|
2499
2146
|
*/
|
|
2500
2147
|
<A extends DateTime>(self: A, parts: Partial<DateTime.PartsForMath>): DateTime.PreserveZone<A>
|
|
2501
|
-
} =
|
|
2502
|
-
const newParts = {} as Partial<Mutable<DateTime.PartsForMath>>
|
|
2503
|
-
for (const key in parts) {
|
|
2504
|
-
newParts[key as keyof DateTime.PartsForMath] = -1 * parts[key as keyof DateTime.PartsForMath]!
|
|
2505
|
-
}
|
|
2506
|
-
return add(self, newParts)
|
|
2507
|
-
})
|
|
2508
|
-
|
|
2509
|
-
function startOfDate(date: Date, part: DateTime.UnitSingular, options?: {
|
|
2510
|
-
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
2511
|
-
}) {
|
|
2512
|
-
switch (part) {
|
|
2513
|
-
case "second": {
|
|
2514
|
-
date.setUTCMilliseconds(0)
|
|
2515
|
-
break
|
|
2516
|
-
}
|
|
2517
|
-
case "minute": {
|
|
2518
|
-
date.setUTCSeconds(0, 0)
|
|
2519
|
-
break
|
|
2520
|
-
}
|
|
2521
|
-
case "hour": {
|
|
2522
|
-
date.setUTCMinutes(0, 0, 0)
|
|
2523
|
-
break
|
|
2524
|
-
}
|
|
2525
|
-
case "day": {
|
|
2526
|
-
date.setUTCHours(0, 0, 0, 0)
|
|
2527
|
-
break
|
|
2528
|
-
}
|
|
2529
|
-
case "week": {
|
|
2530
|
-
const weekStartsOn = options?.weekStartsOn ?? 0
|
|
2531
|
-
const day = date.getUTCDay()
|
|
2532
|
-
const diff = (day - weekStartsOn + 7) % 7
|
|
2533
|
-
date.setUTCDate(date.getUTCDate() - diff)
|
|
2534
|
-
date.setUTCHours(0, 0, 0, 0)
|
|
2535
|
-
break
|
|
2536
|
-
}
|
|
2537
|
-
case "month": {
|
|
2538
|
-
date.setUTCDate(1)
|
|
2539
|
-
date.setUTCHours(0, 0, 0, 0)
|
|
2540
|
-
break
|
|
2541
|
-
}
|
|
2542
|
-
case "year": {
|
|
2543
|
-
date.setUTCMonth(0, 1)
|
|
2544
|
-
date.setUTCHours(0, 0, 0, 0)
|
|
2545
|
-
break
|
|
2546
|
-
}
|
|
2547
|
-
}
|
|
2548
|
-
}
|
|
2148
|
+
} = Internal.subtract
|
|
2549
2149
|
|
|
2550
2150
|
/**
|
|
2551
2151
|
* Converts a `DateTime` to the start of the given `part`.
|
|
@@ -2556,6 +2156,7 @@ function startOfDate(date: Date, part: DateTime.UnitSingular, options?: {
|
|
|
2556
2156
|
* @since 3.6.0
|
|
2557
2157
|
* @category math
|
|
2558
2158
|
* @example
|
|
2159
|
+
* ```ts
|
|
2559
2160
|
* import { DateTime } from "effect"
|
|
2560
2161
|
*
|
|
2561
2162
|
* // returns "2024-01-01T00:00:00Z"
|
|
@@ -2563,6 +2164,7 @@ function startOfDate(date: Date, part: DateTime.UnitSingular, options?: {
|
|
|
2563
2164
|
* DateTime.startOf("day"),
|
|
2564
2165
|
* DateTime.formatIso
|
|
2565
2166
|
* )
|
|
2167
|
+
* ```
|
|
2566
2168
|
*/
|
|
2567
2169
|
export const startOf: {
|
|
2568
2170
|
/**
|
|
@@ -2574,6 +2176,7 @@ export const startOf: {
|
|
|
2574
2176
|
* @since 3.6.0
|
|
2575
2177
|
* @category math
|
|
2576
2178
|
* @example
|
|
2179
|
+
* ```ts
|
|
2577
2180
|
* import { DateTime } from "effect"
|
|
2578
2181
|
*
|
|
2579
2182
|
* // returns "2024-01-01T00:00:00Z"
|
|
@@ -2581,6 +2184,7 @@ export const startOf: {
|
|
|
2581
2184
|
* DateTime.startOf("day"),
|
|
2582
2185
|
* DateTime.formatIso
|
|
2583
2186
|
* )
|
|
2187
|
+
* ```
|
|
2584
2188
|
*/
|
|
2585
2189
|
(
|
|
2586
2190
|
part: DateTime.UnitSingular,
|
|
@@ -2597,6 +2201,7 @@ export const startOf: {
|
|
|
2597
2201
|
* @since 3.6.0
|
|
2598
2202
|
* @category math
|
|
2599
2203
|
* @example
|
|
2204
|
+
* ```ts
|
|
2600
2205
|
* import { DateTime } from "effect"
|
|
2601
2206
|
*
|
|
2602
2207
|
* // returns "2024-01-01T00:00:00Z"
|
|
@@ -2604,6 +2209,7 @@ export const startOf: {
|
|
|
2604
2209
|
* DateTime.startOf("day"),
|
|
2605
2210
|
* DateTime.formatIso
|
|
2606
2211
|
* )
|
|
2212
|
+
* ```
|
|
2607
2213
|
*/
|
|
2608
2214
|
<A extends DateTime>(
|
|
2609
2215
|
self: A,
|
|
@@ -2612,50 +2218,7 @@ export const startOf: {
|
|
|
2612
2218
|
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
2613
2219
|
}
|
|
2614
2220
|
): DateTime.PreserveZone<A>
|
|
2615
|
-
} =
|
|
2616
|
-
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
2617
|
-
}): DateTime => mutate(self, (date) => startOfDate(date, part, options)))
|
|
2618
|
-
|
|
2619
|
-
function endOfDate(date: Date, part: DateTime.UnitSingular, options?: {
|
|
2620
|
-
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
2621
|
-
}) {
|
|
2622
|
-
switch (part) {
|
|
2623
|
-
case "second": {
|
|
2624
|
-
date.setUTCMilliseconds(999)
|
|
2625
|
-
break
|
|
2626
|
-
}
|
|
2627
|
-
case "minute": {
|
|
2628
|
-
date.setUTCSeconds(59, 999)
|
|
2629
|
-
break
|
|
2630
|
-
}
|
|
2631
|
-
case "hour": {
|
|
2632
|
-
date.setUTCMinutes(59, 59, 999)
|
|
2633
|
-
break
|
|
2634
|
-
}
|
|
2635
|
-
case "day": {
|
|
2636
|
-
date.setUTCHours(23, 59, 59, 999)
|
|
2637
|
-
break
|
|
2638
|
-
}
|
|
2639
|
-
case "week": {
|
|
2640
|
-
const weekStartsOn = options?.weekStartsOn ?? 0
|
|
2641
|
-
const day = date.getUTCDay()
|
|
2642
|
-
const diff = (day - weekStartsOn + 7) % 7
|
|
2643
|
-
date.setUTCDate(date.getUTCDate() - diff + 6)
|
|
2644
|
-
date.setUTCHours(23, 59, 59, 999)
|
|
2645
|
-
break
|
|
2646
|
-
}
|
|
2647
|
-
case "month": {
|
|
2648
|
-
date.setUTCMonth(date.getUTCMonth() + 1, 0)
|
|
2649
|
-
date.setUTCHours(23, 59, 59, 999)
|
|
2650
|
-
break
|
|
2651
|
-
}
|
|
2652
|
-
case "year": {
|
|
2653
|
-
date.setUTCMonth(11, 31)
|
|
2654
|
-
date.setUTCHours(23, 59, 59, 999)
|
|
2655
|
-
break
|
|
2656
|
-
}
|
|
2657
|
-
}
|
|
2658
|
-
}
|
|
2221
|
+
} = Internal.startOf
|
|
2659
2222
|
|
|
2660
2223
|
/**
|
|
2661
2224
|
* Converts a `DateTime` to the end of the given `part`.
|
|
@@ -2666,6 +2229,7 @@ function endOfDate(date: Date, part: DateTime.UnitSingular, options?: {
|
|
|
2666
2229
|
* @since 3.6.0
|
|
2667
2230
|
* @category math
|
|
2668
2231
|
* @example
|
|
2232
|
+
* ```ts
|
|
2669
2233
|
* import { DateTime } from "effect"
|
|
2670
2234
|
*
|
|
2671
2235
|
* // returns "2024-01-01T23:59:59.999Z"
|
|
@@ -2673,6 +2237,7 @@ function endOfDate(date: Date, part: DateTime.UnitSingular, options?: {
|
|
|
2673
2237
|
* DateTime.endOf("day"),
|
|
2674
2238
|
* DateTime.formatIso
|
|
2675
2239
|
* )
|
|
2240
|
+
* ```
|
|
2676
2241
|
*/
|
|
2677
2242
|
export const endOf: {
|
|
2678
2243
|
/**
|
|
@@ -2684,6 +2249,7 @@ export const endOf: {
|
|
|
2684
2249
|
* @since 3.6.0
|
|
2685
2250
|
* @category math
|
|
2686
2251
|
* @example
|
|
2252
|
+
* ```ts
|
|
2687
2253
|
* import { DateTime } from "effect"
|
|
2688
2254
|
*
|
|
2689
2255
|
* // returns "2024-01-01T23:59:59.999Z"
|
|
@@ -2691,6 +2257,7 @@ export const endOf: {
|
|
|
2691
2257
|
* DateTime.endOf("day"),
|
|
2692
2258
|
* DateTime.formatIso
|
|
2693
2259
|
* )
|
|
2260
|
+
* ```
|
|
2694
2261
|
*/
|
|
2695
2262
|
(
|
|
2696
2263
|
part: DateTime.UnitSingular,
|
|
@@ -2707,6 +2274,7 @@ export const endOf: {
|
|
|
2707
2274
|
* @since 3.6.0
|
|
2708
2275
|
* @category math
|
|
2709
2276
|
* @example
|
|
2277
|
+
* ```ts
|
|
2710
2278
|
* import { DateTime } from "effect"
|
|
2711
2279
|
*
|
|
2712
2280
|
* // returns "2024-01-01T23:59:59.999Z"
|
|
@@ -2714,6 +2282,7 @@ export const endOf: {
|
|
|
2714
2282
|
* DateTime.endOf("day"),
|
|
2715
2283
|
* DateTime.formatIso
|
|
2716
2284
|
* )
|
|
2285
|
+
* ```
|
|
2717
2286
|
*/
|
|
2718
2287
|
<A extends DateTime>(
|
|
2719
2288
|
self: A,
|
|
@@ -2722,9 +2291,7 @@ export const endOf: {
|
|
|
2722
2291
|
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
2723
2292
|
}
|
|
2724
2293
|
): DateTime.PreserveZone<A>
|
|
2725
|
-
} =
|
|
2726
|
-
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
2727
|
-
}): DateTime => mutate(self, (date) => endOfDate(date, part, options)))
|
|
2294
|
+
} = Internal.endOf
|
|
2728
2295
|
|
|
2729
2296
|
/**
|
|
2730
2297
|
* Converts a `DateTime` to the nearest given `part`.
|
|
@@ -2735,6 +2302,7 @@ export const endOf: {
|
|
|
2735
2302
|
* @since 3.6.0
|
|
2736
2303
|
* @category math
|
|
2737
2304
|
* @example
|
|
2305
|
+
* ```ts
|
|
2738
2306
|
* import { DateTime } from "effect"
|
|
2739
2307
|
*
|
|
2740
2308
|
* // returns "2024-01-02T00:00:00Z"
|
|
@@ -2742,6 +2310,7 @@ export const endOf: {
|
|
|
2742
2310
|
* DateTime.nearest("day"),
|
|
2743
2311
|
* DateTime.formatIso
|
|
2744
2312
|
* )
|
|
2313
|
+
* ```
|
|
2745
2314
|
*/
|
|
2746
2315
|
export const nearest: {
|
|
2747
2316
|
/**
|
|
@@ -2753,6 +2322,7 @@ export const nearest: {
|
|
|
2753
2322
|
* @since 3.6.0
|
|
2754
2323
|
* @category math
|
|
2755
2324
|
* @example
|
|
2325
|
+
* ```ts
|
|
2756
2326
|
* import { DateTime } from "effect"
|
|
2757
2327
|
*
|
|
2758
2328
|
* // returns "2024-01-02T00:00:00Z"
|
|
@@ -2760,6 +2330,7 @@ export const nearest: {
|
|
|
2760
2330
|
* DateTime.nearest("day"),
|
|
2761
2331
|
* DateTime.formatIso
|
|
2762
2332
|
* )
|
|
2333
|
+
* ```
|
|
2763
2334
|
*/
|
|
2764
2335
|
(
|
|
2765
2336
|
part: DateTime.UnitSingular,
|
|
@@ -2776,6 +2347,7 @@ export const nearest: {
|
|
|
2776
2347
|
* @since 3.6.0
|
|
2777
2348
|
* @category math
|
|
2778
2349
|
* @example
|
|
2350
|
+
* ```ts
|
|
2779
2351
|
* import { DateTime } from "effect"
|
|
2780
2352
|
*
|
|
2781
2353
|
* // returns "2024-01-02T00:00:00Z"
|
|
@@ -2783,6 +2355,7 @@ export const nearest: {
|
|
|
2783
2355
|
* DateTime.nearest("day"),
|
|
2784
2356
|
* DateTime.formatIso
|
|
2785
2357
|
* )
|
|
2358
|
+
* ```
|
|
2786
2359
|
*/
|
|
2787
2360
|
<A extends DateTime>(
|
|
2788
2361
|
self: A,
|
|
@@ -2791,38 +2364,12 @@ export const nearest: {
|
|
|
2791
2364
|
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
2792
2365
|
}
|
|
2793
2366
|
): DateTime.PreserveZone<A>
|
|
2794
|
-
} =
|
|
2795
|
-
readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
2796
|
-
}): DateTime =>
|
|
2797
|
-
mutate(self, (date) => {
|
|
2798
|
-
if (part === "milli") return
|
|
2799
|
-
const millis = date.getTime()
|
|
2800
|
-
const start = new Date(millis)
|
|
2801
|
-
startOfDate(start, part, options)
|
|
2802
|
-
const startMillis = start.getTime()
|
|
2803
|
-
const end = new Date(millis)
|
|
2804
|
-
endOfDate(end, part, options)
|
|
2805
|
-
const endMillis = end.getTime() + 1
|
|
2806
|
-
const diffStart = millis - startMillis
|
|
2807
|
-
const diffEnd = endMillis - millis
|
|
2808
|
-
if (diffStart < diffEnd) {
|
|
2809
|
-
date.setTime(startMillis)
|
|
2810
|
-
} else {
|
|
2811
|
-
date.setTime(endMillis)
|
|
2812
|
-
}
|
|
2813
|
-
}))
|
|
2367
|
+
} = Internal.nearest
|
|
2814
2368
|
|
|
2815
2369
|
// =============================================================================
|
|
2816
2370
|
// formatting
|
|
2817
2371
|
// =============================================================================
|
|
2818
2372
|
|
|
2819
|
-
const intlTimeZone = (self: TimeZone): string => {
|
|
2820
|
-
if (self._tag === "Named") {
|
|
2821
|
-
return self.id
|
|
2822
|
-
}
|
|
2823
|
-
return offsetToString(self.offset)
|
|
2824
|
-
}
|
|
2825
|
-
|
|
2826
2373
|
/**
|
|
2827
2374
|
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
2828
2375
|
*
|
|
@@ -2835,6 +2382,10 @@ const intlTimeZone = (self: TimeZone): string => {
|
|
|
2835
2382
|
* @category formatting
|
|
2836
2383
|
*/
|
|
2837
2384
|
export const format: {
|
|
2385
|
+
// =============================================================================
|
|
2386
|
+
// formatting
|
|
2387
|
+
// =============================================================================
|
|
2388
|
+
|
|
2838
2389
|
/**
|
|
2839
2390
|
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
2840
2391
|
*
|
|
@@ -2853,6 +2404,10 @@ export const format: {
|
|
|
2853
2404
|
}
|
|
2854
2405
|
| undefined
|
|
2855
2406
|
): (self: DateTime) => string
|
|
2407
|
+
// =============================================================================
|
|
2408
|
+
// formatting
|
|
2409
|
+
// =============================================================================
|
|
2410
|
+
|
|
2856
2411
|
/**
|
|
2857
2412
|
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
2858
2413
|
*
|
|
@@ -2872,26 +2427,7 @@ export const format: {
|
|
|
2872
2427
|
}
|
|
2873
2428
|
| undefined
|
|
2874
2429
|
): string
|
|
2875
|
-
} =
|
|
2876
|
-
self: DateTime,
|
|
2877
|
-
options?:
|
|
2878
|
-
| Intl.DateTimeFormatOptions & {
|
|
2879
|
-
readonly locale?: string | undefined
|
|
2880
|
-
}
|
|
2881
|
-
| undefined
|
|
2882
|
-
): string => {
|
|
2883
|
-
try {
|
|
2884
|
-
return new Intl.DateTimeFormat(options?.locale, {
|
|
2885
|
-
timeZone: self._tag === "Utc" ? "UTC" : intlTimeZone(self.zone),
|
|
2886
|
-
...options
|
|
2887
|
-
}).format(self.epochMillis)
|
|
2888
|
-
} catch (_) {
|
|
2889
|
-
return new Intl.DateTimeFormat(options?.locale, {
|
|
2890
|
-
timeZone: "UTC",
|
|
2891
|
-
...options
|
|
2892
|
-
}).format(toDate(self))
|
|
2893
|
-
}
|
|
2894
|
-
})
|
|
2430
|
+
} = Internal.format
|
|
2895
2431
|
|
|
2896
2432
|
/**
|
|
2897
2433
|
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
@@ -2933,14 +2469,7 @@ export const formatLocal: {
|
|
|
2933
2469
|
}
|
|
2934
2470
|
| undefined
|
|
2935
2471
|
): string
|
|
2936
|
-
} =
|
|
2937
|
-
self: DateTime,
|
|
2938
|
-
options?:
|
|
2939
|
-
| Intl.DateTimeFormatOptions & {
|
|
2940
|
-
readonly locale?: string | undefined
|
|
2941
|
-
}
|
|
2942
|
-
| undefined
|
|
2943
|
-
): string => new Intl.DateTimeFormat(options?.locale, options).format(self.epochMillis))
|
|
2472
|
+
} = Internal.formatLocal
|
|
2944
2473
|
|
|
2945
2474
|
/**
|
|
2946
2475
|
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
@@ -2982,18 +2511,7 @@ export const formatUtc: {
|
|
|
2982
2511
|
}
|
|
2983
2512
|
| undefined
|
|
2984
2513
|
): string
|
|
2985
|
-
} =
|
|
2986
|
-
self: DateTime,
|
|
2987
|
-
options?:
|
|
2988
|
-
| Intl.DateTimeFormatOptions & {
|
|
2989
|
-
readonly locale?: string | undefined
|
|
2990
|
-
}
|
|
2991
|
-
| undefined
|
|
2992
|
-
): string =>
|
|
2993
|
-
new Intl.DateTimeFormat(options?.locale, {
|
|
2994
|
-
...options,
|
|
2995
|
-
timeZone: "UTC"
|
|
2996
|
-
}).format(self.epochMillis))
|
|
2514
|
+
} = Internal.formatUtc
|
|
2997
2515
|
|
|
2998
2516
|
/**
|
|
2999
2517
|
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
@@ -3016,7 +2534,7 @@ export const formatIntl: {
|
|
|
3016
2534
|
* @category formatting
|
|
3017
2535
|
*/
|
|
3018
2536
|
(self: DateTime, format: Intl.DateTimeFormat): string
|
|
3019
|
-
} =
|
|
2537
|
+
} = Internal.formatIntl
|
|
3020
2538
|
|
|
3021
2539
|
/**
|
|
3022
2540
|
* Format a `DateTime` as a UTC ISO string.
|
|
@@ -3024,7 +2542,7 @@ export const formatIntl: {
|
|
|
3024
2542
|
* @since 3.6.0
|
|
3025
2543
|
* @category formatting
|
|
3026
2544
|
*/
|
|
3027
|
-
export const formatIso
|
|
2545
|
+
export const formatIso: (self: DateTime) => string = Internal.formatIso
|
|
3028
2546
|
|
|
3029
2547
|
/**
|
|
3030
2548
|
* Format a `DateTime` as a time zone adjusted ISO date string.
|
|
@@ -3032,7 +2550,7 @@ export const formatIso = (self: DateTime): string => toDateUtc(self).toISOString
|
|
|
3032
2550
|
* @since 3.6.0
|
|
3033
2551
|
* @category formatting
|
|
3034
2552
|
*/
|
|
3035
|
-
export const formatIsoDate
|
|
2553
|
+
export const formatIsoDate: (self: DateTime) => string = Internal.formatIsoDate
|
|
3036
2554
|
|
|
3037
2555
|
/**
|
|
3038
2556
|
* Format a `DateTime` as a UTC ISO date string.
|
|
@@ -3040,7 +2558,7 @@ export const formatIsoDate = (self: DateTime): string => toDate(self).toISOStrin
|
|
|
3040
2558
|
* @since 3.6.0
|
|
3041
2559
|
* @category formatting
|
|
3042
2560
|
*/
|
|
3043
|
-
export const formatIsoDateUtc
|
|
2561
|
+
export const formatIsoDateUtc: (self: DateTime) => string = Internal.formatIsoDateUtc
|
|
3044
2562
|
|
|
3045
2563
|
/**
|
|
3046
2564
|
* Format a `DateTime.Zoned` as a ISO string with an offset.
|
|
@@ -3048,10 +2566,7 @@ export const formatIsoDateUtc = (self: DateTime): string => toDateUtc(self).toIS
|
|
|
3048
2566
|
* @since 3.6.0
|
|
3049
2567
|
* @category formatting
|
|
3050
2568
|
*/
|
|
3051
|
-
export const formatIsoOffset
|
|
3052
|
-
const date = toDate(self)
|
|
3053
|
-
return self._tag === "Utc" ? date.toISOString() : `${date.toISOString().slice(0, -1)}${zonedOffsetIso(self)}`
|
|
3054
|
-
}
|
|
2569
|
+
export const formatIsoOffset: (self: DateTime) => string = Internal.formatIsoOffset
|
|
3055
2570
|
|
|
3056
2571
|
/**
|
|
3057
2572
|
* Format a `DateTime.Zoned` as a string.
|
|
@@ -3061,5 +2576,40 @@ export const formatIsoOffset = (self: DateTime): string => {
|
|
|
3061
2576
|
* @since 3.6.0
|
|
3062
2577
|
* @category formatting
|
|
3063
2578
|
*/
|
|
3064
|
-
export const formatIsoZoned
|
|
3065
|
-
|
|
2579
|
+
export const formatIsoZoned: (self: Zoned) => string = Internal.formatIsoZoned
|
|
2580
|
+
|
|
2581
|
+
/**
|
|
2582
|
+
* Create a Layer from the given time zone.
|
|
2583
|
+
*
|
|
2584
|
+
* @since 3.6.0
|
|
2585
|
+
* @category current time zone
|
|
2586
|
+
*/
|
|
2587
|
+
export const layerCurrentZone = (zone: TimeZone): Layer.Layer<CurrentTimeZone> => Layer.succeed(CurrentTimeZone, zone)
|
|
2588
|
+
|
|
2589
|
+
/**
|
|
2590
|
+
* Create a Layer from the given time zone offset.
|
|
2591
|
+
*
|
|
2592
|
+
* @since 3.6.0
|
|
2593
|
+
* @category current time zone
|
|
2594
|
+
*/
|
|
2595
|
+
export const layerCurrentZoneOffset = (offset: number): Layer.Layer<CurrentTimeZone> =>
|
|
2596
|
+
Layer.succeed(CurrentTimeZone, Internal.zoneMakeOffset(offset))
|
|
2597
|
+
|
|
2598
|
+
/**
|
|
2599
|
+
* Create a Layer from the given IANA time zone identifier.
|
|
2600
|
+
*
|
|
2601
|
+
* @since 3.6.0
|
|
2602
|
+
* @category current time zone
|
|
2603
|
+
*/
|
|
2604
|
+
export const layerCurrentZoneNamed = (
|
|
2605
|
+
zoneId: string
|
|
2606
|
+
): Layer.Layer<CurrentTimeZone, IllegalArgumentException> =>
|
|
2607
|
+
Layer.effect(CurrentTimeZone, Internal.zoneMakeNamedEffect(zoneId))
|
|
2608
|
+
|
|
2609
|
+
/**
|
|
2610
|
+
* Create a Layer from the systems local time zone.
|
|
2611
|
+
*
|
|
2612
|
+
* @since 3.6.0
|
|
2613
|
+
* @category current time zone
|
|
2614
|
+
*/
|
|
2615
|
+
export const layerCurrentZoneLocal: Layer.Layer<CurrentTimeZone> = Layer.sync(CurrentTimeZone, zoneMakeLocal)
|