effect 3.10.19 → 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.
Files changed (167) hide show
  1. package/dist/cjs/BigDecimal.js +125 -24
  2. package/dist/cjs/BigDecimal.js.map +1 -1
  3. package/dist/cjs/Channel.js +44 -4
  4. package/dist/cjs/Channel.js.map +1 -1
  5. package/dist/cjs/Config.js +8 -1
  6. package/dist/cjs/Config.js.map +1 -1
  7. package/dist/cjs/Context.js +26 -1
  8. package/dist/cjs/Context.js.map +1 -1
  9. package/dist/cjs/Cron.js +75 -67
  10. package/dist/cjs/Cron.js.map +1 -1
  11. package/dist/cjs/DateTime.js +114 -664
  12. package/dist/cjs/DateTime.js.map +1 -1
  13. package/dist/cjs/Effect.js +82 -4
  14. package/dist/cjs/Effect.js.map +1 -1
  15. package/dist/cjs/Inspectable.js +8 -4
  16. package/dist/cjs/Inspectable.js.map +1 -1
  17. package/dist/cjs/JSONSchema.js.map +1 -1
  18. package/dist/cjs/Micro.js +1099 -1072
  19. package/dist/cjs/Micro.js.map +1 -1
  20. package/dist/cjs/STM.js.map +1 -1
  21. package/dist/cjs/Schema.js +57 -8
  22. package/dist/cjs/Schema.js.map +1 -1
  23. package/dist/cjs/Sink.js +9 -1
  24. package/dist/cjs/Sink.js.map +1 -1
  25. package/dist/cjs/Stream.js +25 -7
  26. package/dist/cjs/Stream.js.map +1 -1
  27. package/dist/cjs/Utils.js +7 -1
  28. package/dist/cjs/Utils.js.map +1 -1
  29. package/dist/cjs/internal/channel/channelExecutor.js +5 -9
  30. package/dist/cjs/internal/channel/channelExecutor.js.map +1 -1
  31. package/dist/cjs/internal/channel.js +156 -130
  32. package/dist/cjs/internal/channel.js.map +1 -1
  33. package/dist/cjs/internal/config.js +13 -4
  34. package/dist/cjs/internal/config.js.map +1 -1
  35. package/dist/cjs/internal/context.js +46 -3
  36. package/dist/cjs/internal/context.js.map +1 -1
  37. package/dist/cjs/internal/dateTime.js +747 -0
  38. package/dist/cjs/internal/dateTime.js.map +1 -0
  39. package/dist/cjs/internal/fiberRuntime.js +34 -11
  40. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  41. package/dist/cjs/internal/groupBy.js +9 -3
  42. package/dist/cjs/internal/groupBy.js.map +1 -1
  43. package/dist/cjs/internal/layer.js +1 -1
  44. package/dist/cjs/internal/layer.js.map +1 -1
  45. package/dist/cjs/internal/mailbox.js +1 -1
  46. package/dist/cjs/internal/mailbox.js.map +1 -1
  47. package/dist/cjs/internal/sink.js +25 -21
  48. package/dist/cjs/internal/sink.js.map +1 -1
  49. package/dist/cjs/internal/stream.js +70 -71
  50. package/dist/cjs/internal/stream.js.map +1 -1
  51. package/dist/cjs/internal/version.js +1 -1
  52. package/dist/cjs/internal/version.js.map +1 -1
  53. package/dist/dts/BigDecimal.d.ts +56 -1
  54. package/dist/dts/BigDecimal.d.ts.map +1 -1
  55. package/dist/dts/Channel.d.ts +66 -5
  56. package/dist/dts/Channel.d.ts.map +1 -1
  57. package/dist/dts/Config.d.ts +23 -1
  58. package/dist/dts/Config.d.ts.map +1 -1
  59. package/dist/dts/Context.d.ts +111 -0
  60. package/dist/dts/Context.d.ts.map +1 -1
  61. package/dist/dts/Cron.d.ts +15 -6
  62. package/dist/dts/Cron.d.ts.map +1 -1
  63. package/dist/dts/DateTime.d.ts +40 -49
  64. package/dist/dts/DateTime.d.ts.map +1 -1
  65. package/dist/dts/Effect.d.ts +88 -1
  66. package/dist/dts/Effect.d.ts.map +1 -1
  67. package/dist/dts/Inspectable.d.ts.map +1 -1
  68. package/dist/dts/JSONSchema.d.ts +1 -0
  69. package/dist/dts/JSONSchema.d.ts.map +1 -1
  70. package/dist/dts/Micro.d.ts +875 -872
  71. package/dist/dts/Micro.d.ts.map +1 -1
  72. package/dist/dts/STM.d.ts +2 -0
  73. package/dist/dts/STM.d.ts.map +1 -1
  74. package/dist/dts/Schema.d.ts +32 -0
  75. package/dist/dts/Schema.d.ts.map +1 -1
  76. package/dist/dts/Sink.d.ts +8 -0
  77. package/dist/dts/Sink.d.ts.map +1 -1
  78. package/dist/dts/Stream.d.ts +50 -32
  79. package/dist/dts/Stream.d.ts.map +1 -1
  80. package/dist/dts/Utils.d.ts +4 -0
  81. package/dist/dts/Utils.d.ts.map +1 -1
  82. package/dist/dts/internal/context.d.ts +1 -1
  83. package/dist/dts/internal/context.d.ts.map +1 -1
  84. package/dist/dts/internal/dateTime.d.ts +2 -0
  85. package/dist/dts/internal/dateTime.d.ts.map +1 -0
  86. package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
  87. package/dist/dts/internal/stream.d.ts.map +1 -1
  88. package/dist/esm/BigDecimal.js +119 -20
  89. package/dist/esm/BigDecimal.js.map +1 -1
  90. package/dist/esm/Channel.js +42 -2
  91. package/dist/esm/Channel.js.map +1 -1
  92. package/dist/esm/Config.js +7 -0
  93. package/dist/esm/Config.js.map +1 -1
  94. package/dist/esm/Context.js +25 -0
  95. package/dist/esm/Context.js.map +1 -1
  96. package/dist/esm/Cron.js +75 -67
  97. package/dist/esm/Cron.js.map +1 -1
  98. package/dist/esm/DateTime.js +112 -627
  99. package/dist/esm/DateTime.js.map +1 -1
  100. package/dist/esm/Effect.js +77 -0
  101. package/dist/esm/Effect.js.map +1 -1
  102. package/dist/esm/Inspectable.js +8 -4
  103. package/dist/esm/Inspectable.js.map +1 -1
  104. package/dist/esm/JSONSchema.js.map +1 -1
  105. package/dist/esm/Micro.js +1077 -1047
  106. package/dist/esm/Micro.js.map +1 -1
  107. package/dist/esm/STM.js.map +1 -1
  108. package/dist/esm/Schema.js +54 -0
  109. package/dist/esm/Schema.js.map +1 -1
  110. package/dist/esm/Sink.js +8 -0
  111. package/dist/esm/Sink.js.map +1 -1
  112. package/dist/esm/Stream.js +23 -5
  113. package/dist/esm/Stream.js.map +1 -1
  114. package/dist/esm/Utils.js +5 -0
  115. package/dist/esm/Utils.js.map +1 -1
  116. package/dist/esm/internal/channel/channelExecutor.js +5 -7
  117. package/dist/esm/internal/channel/channelExecutor.js.map +1 -1
  118. package/dist/esm/internal/channel.js +152 -129
  119. package/dist/esm/internal/channel.js.map +1 -1
  120. package/dist/esm/internal/config.js +11 -3
  121. package/dist/esm/internal/config.js.map +1 -1
  122. package/dist/esm/internal/context.js +42 -2
  123. package/dist/esm/internal/context.js.map +1 -1
  124. package/dist/esm/internal/dateTime.js +704 -0
  125. package/dist/esm/internal/dateTime.js.map +1 -0
  126. package/dist/esm/internal/fiberRuntime.js +31 -9
  127. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  128. package/dist/esm/internal/groupBy.js +9 -3
  129. package/dist/esm/internal/groupBy.js.map +1 -1
  130. package/dist/esm/internal/layer.js +1 -1
  131. package/dist/esm/internal/layer.js.map +1 -1
  132. package/dist/esm/internal/mailbox.js +1 -1
  133. package/dist/esm/internal/mailbox.js.map +1 -1
  134. package/dist/esm/internal/sink.js +23 -20
  135. package/dist/esm/internal/sink.js.map +1 -1
  136. package/dist/esm/internal/stream.js +66 -69
  137. package/dist/esm/internal/stream.js.map +1 -1
  138. package/dist/esm/internal/version.js +1 -1
  139. package/dist/esm/internal/version.js.map +1 -1
  140. package/package.json +1 -1
  141. package/src/BigDecimal.ts +131 -21
  142. package/src/Channel.ts +81 -5
  143. package/src/Config.ts +24 -1
  144. package/src/Context.ts +119 -0
  145. package/src/Cron.ts +85 -68
  146. package/src/DateTime.ts +155 -757
  147. package/src/Effect.ts +340 -1
  148. package/src/Inspectable.ts +11 -7
  149. package/src/JSONSchema.ts +1 -0
  150. package/src/Micro.ts +2005 -1757
  151. package/src/STM.ts +2 -0
  152. package/src/Schema.ts +60 -0
  153. package/src/Sink.ts +11 -0
  154. package/src/Stream.ts +55 -44
  155. package/src/Utils.ts +8 -0
  156. package/src/internal/channel/channelExecutor.ts +37 -33
  157. package/src/internal/channel.ts +504 -467
  158. package/src/internal/config.ts +18 -6
  159. package/src/internal/context.ts +56 -4
  160. package/src/internal/dateTime.ts +1126 -0
  161. package/src/internal/fiberRuntime.ts +35 -16
  162. package/src/internal/groupBy.ts +13 -22
  163. package/src/internal/layer.ts +5 -8
  164. package/src/internal/mailbox.ts +6 -4
  165. package/src/internal/sink.ts +55 -35
  166. package/src/internal/stream.ts +299 -299
  167. 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 Equal from "./Equal.js"
11
- import * as Equivalence_ from "./Equivalence.js"
12
- import type { LazyArg } from "./Function.js"
13
- import { dual, pipe } from "./Function.js"
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 { type Pipeable, pipeArguments } from "./Pipeable.js"
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 = Symbol.for("effect/DateTime")
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.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 = Symbol.for("effect/DateTime/TimeZone")
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.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 = (u: unknown): u is DateTime => Predicate.hasProperty(u, TypeId)
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 = (u: unknown): u is TimeZone => Predicate.hasProperty(u, TimeZoneTypeId)
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 = (u: unknown): u is TimeZone.Offset => isTimeZone(u) && u._tag === "Offset"
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 = (u: unknown): u is TimeZone.Named => isTimeZone(u) && u._tag === "Named"
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 = (self: DateTime): self is Utc => self._tag === "Utc"
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 = (self: DateTime): self is Zoned => self._tag === "Zoned"
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: Equivalence_.Equivalence<DateTime> = Equivalence_.make((a, b) =>
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> = order.make((self, that) =>
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
- } = order.clamp(Order)
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 = (date: Date): Utc => {
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:
@@ -455,18 +328,7 @@ export const unsafeFromDate = (date: Date): Utc => {
455
328
  * DateTime.unsafeMake("2024-01-01")
456
329
  * ```
457
330
  */
458
- export const unsafeMake = <A extends DateTime.Input>(input: A): DateTime.PreserveZone<A> => {
459
- if (isDateTime(input)) {
460
- return input as DateTime.PreserveZone<A>
461
- } else if (input instanceof Date) {
462
- return unsafeFromDate(input) as DateTime.PreserveZone<A>
463
- } else if (typeof input === "object") {
464
- const date = new Date(0)
465
- setPartsDate(date, input)
466
- return unsafeFromDate(date) as DateTime.PreserveZone<A>
467
- }
468
- return unsafeFromDate(new Date(input)) as DateTime.PreserveZone<A>
469
- }
331
+ export const unsafeMake: <A extends DateTime.Input>(input: A) => DateTime.PreserveZone<A> = Internal.unsafeMake
470
332
 
471
333
  /**
472
334
  * Create a `DateTime.Zoned` using `DateTime.unsafeMake` and a time zone.
@@ -484,34 +346,10 @@ export const unsafeMake = <A extends DateTime.Input>(input: A): DateTime.Preserv
484
346
  * DateTime.unsafeMakeZoned(new Date(), { timeZone: "Europe/London" })
485
347
  * ```
486
348
  */
487
- export const unsafeMakeZoned = (input: DateTime.Input, options?: {
349
+ export const unsafeMakeZoned: (input: DateTime.Input, options?: {
488
350
  readonly timeZone?: number | string | TimeZone | undefined
489
351
  readonly adjustForTimeZone?: boolean | undefined
490
- }): Zoned => {
491
- if (options?.timeZone === undefined && isDateTime(input) && isZoned(input)) {
492
- return input
493
- }
494
- const self = unsafeMake(input)
495
- let zone: TimeZone
496
- if (options?.timeZone === undefined) {
497
- const offset = new Date(self.epochMillis).getTimezoneOffset() * -60 * 1000
498
- zone = zoneMakeOffset(offset)
499
- } else if (isTimeZone(options?.timeZone)) {
500
- zone = options.timeZone
501
- } else if (typeof options?.timeZone === "number") {
502
- zone = zoneMakeOffset(options.timeZone)
503
- } else {
504
- const parsedZone = zoneFromString(options.timeZone)
505
- if (Option.isNone(parsedZone)) {
506
- throw new IllegalArgumentException(`Invalid time zone: ${options.timeZone}`)
507
- }
508
- zone = parsedZone.value
509
- }
510
- if (options?.adjustForTimeZone !== true) {
511
- return makeZonedProto(self.epochMillis, zone, self.partsUtc)
512
- }
513
- return makeZonedFromAdjusted(self.epochMillis, zone)
514
- }
352
+ }) => Zoned = Internal.unsafeMakeZoned
515
353
 
516
354
  /**
517
355
  * Create a `DateTime.Zoned` using `DateTime.make` and a time zone.
@@ -535,7 +373,7 @@ export const makeZoned: (
535
373
  readonly timeZone?: number | string | TimeZone | undefined
536
374
  readonly adjustForTimeZone?: boolean | undefined
537
375
  }
538
- ) => Option.Option<Zoned> = Option.liftThrowable(unsafeMakeZoned)
376
+ ) => Option.Option<Zoned> = Internal.makeZoned
539
377
 
540
378
  /**
541
379
  * Create a `DateTime` from one of the following:
@@ -564,10 +402,7 @@ export const makeZoned: (
564
402
  * DateTime.make("2024-01-01")
565
403
  * ```
566
404
  */
567
- export const make: <A extends DateTime.Input>(input: A) => Option.Option<DateTime.PreserveZone<A>> = Option
568
- .liftThrowable(unsafeMake)
569
-
570
- const zonedStringRegex = /^(.{17,35})\[(.+)\]$/
405
+ export const make: <A extends DateTime.Input>(input: A) => Option.Option<DateTime.PreserveZone<A>> = Internal.make
571
406
 
572
407
  /**
573
408
  * Create a `DateTime.Zoned` from a string.
@@ -577,15 +412,7 @@ const zonedStringRegex = /^(.{17,35})\[(.+)\]$/
577
412
  * @since 3.6.0
578
413
  * @category constructors
579
414
  */
580
- export const makeZonedFromString = (input: string): Option.Option<Zoned> => {
581
- const match = zonedStringRegex.exec(input)
582
- if (match === null) {
583
- const offset = parseOffset(input)
584
- return offset !== null ? makeZoned(input, { timeZone: offset }) : Option.none()
585
- }
586
- const [, isoString, timeZone] = match
587
- return makeZoned(isoString, { timeZone })
588
- }
415
+ export const makeZonedFromString: (input: string) => Option.Option<Zoned> = Internal.makeZonedFromString
589
416
 
590
417
  /**
591
418
  * Get the current time using the `Clock` service and convert it to a `DateTime`.
@@ -601,7 +428,7 @@ export const makeZonedFromString = (input: string): Option.Option<Zoned> => {
601
428
  * })
602
429
  * ```
603
430
  */
604
- export const now: Effect.Effect<Utc> = Effect.map(Clock.currentTimeMillis, makeUtc)
431
+ export const now: Effect.Effect<Utc> = Internal.now
605
432
 
606
433
  /**
607
434
  * Get the current time using `Date.now`.
@@ -609,7 +436,7 @@ export const now: Effect.Effect<Utc> = Effect.map(Clock.currentTimeMillis, makeU
609
436
  * @since 3.6.0
610
437
  * @category constructors
611
438
  */
612
- export const unsafeNow: LazyArg<Utc> = () => makeUtc(Date.now())
439
+ export const unsafeNow: LazyArg<Utc> = Internal.unsafeNow
613
440
 
614
441
  // =============================================================================
615
442
  // time zones
@@ -691,12 +518,7 @@ export const setZone: {
691
518
  readonly adjustForTimeZone?: boolean | undefined
692
519
  }
693
520
  ): Zoned
694
- } = dual(isDateTimeArgs, (self: DateTime, zone: TimeZone, options?: {
695
- readonly adjustForTimeZone?: boolean | undefined
696
- }): Zoned =>
697
- options?.adjustForTimeZone === true
698
- ? makeZonedFromAdjusted(self.epochMillis, zone)
699
- : makeZonedProto(self.epochMillis, zone, self.partsUtc))
521
+ } = Internal.setZone
700
522
 
701
523
  /**
702
524
  * Add a fixed offset time zone to a `DateTime`.
@@ -769,35 +591,7 @@ export const setZoneOffset: {
769
591
  readonly adjustForTimeZone?: boolean | undefined
770
592
  }
771
593
  ): Zoned
772
- } = dual(isDateTimeArgs, (self: DateTime, offset: number, options?: {
773
- readonly adjustForTimeZone?: boolean | undefined
774
- }): Zoned => setZone(self, zoneMakeOffset(offset), options))
775
-
776
- const validZoneCache = globalValue("effect/DateTime/validZoneCache", () => new Map<string, TimeZone.Named>())
777
-
778
- const formatOptions: Intl.DateTimeFormatOptions = {
779
- day: "numeric",
780
- month: "numeric",
781
- year: "numeric",
782
- hour: "numeric",
783
- minute: "numeric",
784
- second: "numeric",
785
- timeZoneName: "longOffset",
786
- fractionalSecondDigits: 3,
787
- hourCycle: "h23"
788
- }
789
-
790
- const zoneMakeIntl = (format: Intl.DateTimeFormat): TimeZone.Named => {
791
- const zoneId = format.resolvedOptions().timeZone
792
- if (validZoneCache.has(zoneId)) {
793
- return validZoneCache.get(zoneId)!
794
- }
795
- const zone = Object.create(ProtoTimeZoneNamed)
796
- zone.id = zoneId
797
- zone.format = format
798
- validZoneCache.set(zoneId, zone)
799
- return zone
800
- }
594
+ } = Internal.setZoneOffset
801
595
 
802
596
  /**
803
597
  * Attempt to create a named time zone from a IANA time zone identifier.
@@ -807,21 +601,7 @@ const zoneMakeIntl = (format: Intl.DateTimeFormat): TimeZone.Named => {
807
601
  * @since 3.6.0
808
602
  * @category time zones
809
603
  */
810
- export const zoneUnsafeMakeNamed = (zoneId: string): TimeZone.Named => {
811
- if (validZoneCache.has(zoneId)) {
812
- return validZoneCache.get(zoneId)!
813
- }
814
- try {
815
- return zoneMakeIntl(
816
- new Intl.DateTimeFormat("en-US", {
817
- ...formatOptions,
818
- timeZone: zoneId
819
- })
820
- )
821
- } catch (_) {
822
- throw new IllegalArgumentException(`Invalid time zone: ${zoneId}`)
823
- }
824
- }
604
+ export const zoneUnsafeMakeNamed: (zoneId: string) => TimeZone.Named = Internal.zoneUnsafeMakeNamed
825
605
 
826
606
  /**
827
607
  * Create a fixed offset time zone.
@@ -829,11 +609,7 @@ export const zoneUnsafeMakeNamed = (zoneId: string): TimeZone.Named => {
829
609
  * @since 3.6.0
830
610
  * @category time zones
831
611
  */
832
- export const zoneMakeOffset = (offset: number): TimeZone.Offset => {
833
- const zone = Object.create(ProtoTimeZoneOffset)
834
- zone.offset = offset
835
- return zone
836
- }
612
+ export const zoneMakeOffset: (offset: number) => TimeZone.Offset = Internal.zoneMakeOffset
837
613
 
838
614
  /**
839
615
  * Create a named time zone from a IANA time zone identifier. If the time zone
@@ -842,9 +618,7 @@ export const zoneMakeOffset = (offset: number): TimeZone.Offset => {
842
618
  * @since 3.6.0
843
619
  * @category time zones
844
620
  */
845
- export const zoneMakeNamed: (zoneId: string) => Option.Option<TimeZone.Named> = Option.liftThrowable(
846
- zoneUnsafeMakeNamed
847
- )
621
+ export const zoneMakeNamed: (zoneId: string) => Option.Option<TimeZone.Named> = Internal.zoneMakeNamed
848
622
 
849
623
  /**
850
624
  * Create a named time zone from a IANA time zone identifier. If the time zone
@@ -853,11 +627,8 @@ export const zoneMakeNamed: (zoneId: string) => Option.Option<TimeZone.Named> =
853
627
  * @since 3.6.0
854
628
  * @category time zones
855
629
  */
856
- export const zoneMakeNamedEffect = (zoneId: string): Effect.Effect<TimeZone.Named, IllegalArgumentException> =>
857
- Effect.try({
858
- try: () => zoneUnsafeMakeNamed(zoneId),
859
- catch: (e) => e as IllegalArgumentException
860
- })
630
+ export const zoneMakeNamedEffect: (zoneId: string) => Effect.Effect<TimeZone.Named, IllegalArgumentException> =
631
+ Internal.zoneMakeNamedEffect
861
632
 
862
633
  /**
863
634
  * Create a named time zone from the system's local time zone.
@@ -865,9 +636,7 @@ export const zoneMakeNamedEffect = (zoneId: string): Effect.Effect<TimeZone.Name
865
636
  * @since 3.6.0
866
637
  * @category time zones
867
638
  */
868
- export const zoneMakeLocal = (): TimeZone.Named => zoneMakeIntl(new Intl.DateTimeFormat("en-US", formatOptions))
869
-
870
- const offsetZoneRegex = /^(?:GMT|[+-])/
639
+ export const zoneMakeLocal: () => TimeZone.Named = Internal.zoneMakeLocal
871
640
 
872
641
  /**
873
642
  * Try parse a TimeZone from a string
@@ -875,13 +644,7 @@ const offsetZoneRegex = /^(?:GMT|[+-])/
875
644
  * @since 3.6.0
876
645
  * @category time zones
877
646
  */
878
- export const zoneFromString = (zone: string): Option.Option<TimeZone> => {
879
- if (offsetZoneRegex.test(zone)) {
880
- const offset = parseOffset(zone)
881
- return offset === null ? Option.none() : Option.some(zoneMakeOffset(offset))
882
- }
883
- return zoneMakeNamed(zone)
884
- }
647
+ export const zoneFromString: (zone: string) => Option.Option<TimeZone> = Internal.zoneFromString
885
648
 
886
649
  /**
887
650
  * Format a `TimeZone` as a string.
@@ -899,12 +662,7 @@ export const zoneFromString = (zone: string): Option.Option<TimeZone> => {
899
662
  * DateTime.zoneToString(DateTime.zoneUnsafeMakeNamed("Europe/London"))
900
663
  * ```
901
664
  */
902
- export const zoneToString = (self: TimeZone): string => {
903
- if (self._tag === "Offset") {
904
- return offsetToString(self.offset)
905
- }
906
- return self.id
907
- }
665
+ export const zoneToString: (self: TimeZone) => string = Internal.zoneToString
908
666
 
909
667
  /**
910
668
  * Set the time zone of a `DateTime` from an IANA time zone identifier. If the
@@ -971,12 +729,7 @@ export const setZoneNamed: {
971
729
  readonly adjustForTimeZone?: boolean | undefined
972
730
  }
973
731
  ): Option.Option<Zoned>
974
- } = dual(
975
- isDateTimeArgs,
976
- (self: DateTime, zoneId: string, options?: {
977
- readonly adjustForTimeZone?: boolean | undefined
978
- }): Option.Option<Zoned> => Option.map(zoneMakeNamed(zoneId), (zone) => setZone(self, zone, options))
979
- )
732
+ } = Internal.setZoneNamed
980
733
 
981
734
  /**
982
735
  * Set the time zone of a `DateTime` from an IANA time zone identifier. If the
@@ -1043,9 +796,7 @@ export const unsafeSetZoneNamed: {
1043
796
  readonly adjustForTimeZone?: boolean | undefined
1044
797
  }
1045
798
  ): Zoned
1046
- } = dual(isDateTimeArgs, (self: DateTime, zoneId: string, options?: {
1047
- readonly adjustForTimeZone?: boolean | undefined
1048
- }): Zoned => setZone(self, zoneUnsafeMakeNamed(zoneId), options))
799
+ } = Internal.unsafeSetZoneNamed
1049
800
 
1050
801
  // =============================================================================
1051
802
  // comparisons
@@ -1125,7 +876,7 @@ export const distance: {
1125
876
  * ```
1126
877
  */
1127
878
  (self: DateTime, other: DateTime): number
1128
- } = dual(2, (self: DateTime, other: DateTime): number => toEpochMillis(other) - toEpochMillis(self))
879
+ } = Internal.distance
1129
880
 
1130
881
  /**
1131
882
  * Calulate the difference between two `DateTime` values.
@@ -1211,12 +962,7 @@ export const distanceDurationEither: {
1211
962
  * ```
1212
963
  */
1213
964
  (self: DateTime, other: DateTime): Either.Either<Duration.Duration, Duration.Duration>
1214
- } = dual(2, (self: DateTime, other: DateTime): Either.Either<Duration.Duration, Duration.Duration> => {
1215
- const diffMillis = distance(self, other)
1216
- return diffMillis > 0
1217
- ? Either.right(Duration.millis(diffMillis))
1218
- : Either.left(Duration.millis(-diffMillis))
1219
- })
965
+ } = Internal.distanceDurationEither
1220
966
 
1221
967
  /**
1222
968
  * Calulate the distance between two `DateTime` values.
@@ -1275,10 +1021,7 @@ export const distanceDuration: {
1275
1021
  * ```
1276
1022
  */
1277
1023
  (self: DateTime, other: DateTime): Duration.Duration
1278
- } = dual(
1279
- 2,
1280
- (self: DateTime, other: DateTime): Duration.Duration => Duration.millis(Math.abs(distance(self, other)))
1281
- )
1024
+ } = Internal.distanceDuration
1282
1025
 
1283
1026
  /**
1284
1027
  * @since 3.6.0
@@ -1295,7 +1038,7 @@ export const min: {
1295
1038
  * @category comparisons
1296
1039
  */
1297
1040
  (self: DateTime, that: DateTime): DateTime
1298
- } = order.min(Order)
1041
+ } = Internal.min
1299
1042
 
1300
1043
  /**
1301
1044
  * @since 3.6.0
@@ -1312,7 +1055,7 @@ export const max: {
1312
1055
  * @category comparisons
1313
1056
  */
1314
1057
  (self: DateTime, that: DateTime): DateTime
1315
- } = order.max(Order)
1058
+ } = Internal.max
1316
1059
 
1317
1060
  /**
1318
1061
  * @since 3.6.0
@@ -1329,7 +1072,7 @@ export const greaterThan: {
1329
1072
  * @category comparisons
1330
1073
  */
1331
1074
  (self: DateTime, that: DateTime): boolean
1332
- } = order.greaterThan(Order)
1075
+ } = Internal.greaterThan
1333
1076
 
1334
1077
  /**
1335
1078
  * @since 3.6.0
@@ -1346,7 +1089,7 @@ export const greaterThanOrEqualTo: {
1346
1089
  * @category comparisons
1347
1090
  */
1348
1091
  (self: DateTime, that: DateTime): boolean
1349
- } = order.greaterThanOrEqualTo(Order)
1092
+ } = Internal.greaterThanOrEqualTo
1350
1093
 
1351
1094
  /**
1352
1095
  * @since 3.6.0
@@ -1363,7 +1106,7 @@ export const lessThan: {
1363
1106
  * @category comparisons
1364
1107
  */
1365
1108
  (self: DateTime, that: DateTime): boolean
1366
- } = order.lessThan(Order)
1109
+ } = Internal.lessThan
1367
1110
 
1368
1111
  /**
1369
1112
  * @since 3.6.0
@@ -1380,7 +1123,7 @@ export const lessThanOrEqualTo: {
1380
1123
  * @category comparisons
1381
1124
  */
1382
1125
  (self: DateTime, that: DateTime): boolean
1383
- } = order.lessThanOrEqualTo(Order)
1126
+ } = Internal.lessThanOrEqualTo
1384
1127
 
1385
1128
  /**
1386
1129
  * @since 3.6.0
@@ -1397,31 +1140,31 @@ export const between: {
1397
1140
  * @category comparisons
1398
1141
  */
1399
1142
  (self: DateTime, options: { minimum: DateTime; maximum: DateTime }): boolean
1400
- } = order.between(Order)
1143
+ } = Internal.between
1401
1144
 
1402
1145
  /**
1403
1146
  * @since 3.6.0
1404
1147
  * @category comparisons
1405
1148
  */
1406
- export const isFuture = (self: DateTime): Effect.Effect<boolean> => Effect.map(now, lessThan(self))
1149
+ export const isFuture: (self: DateTime) => Effect.Effect<boolean> = Internal.isFuture
1407
1150
 
1408
1151
  /**
1409
1152
  * @since 3.6.0
1410
1153
  * @category comparisons
1411
1154
  */
1412
- export const unsafeIsFuture = (self: DateTime): boolean => lessThan(unsafeNow(), self)
1155
+ export const unsafeIsFuture: (self: DateTime) => boolean = Internal.unsafeIsFuture
1413
1156
 
1414
1157
  /**
1415
1158
  * @since 3.6.0
1416
1159
  * @category comparisons
1417
1160
  */
1418
- export const isPast = (self: DateTime): Effect.Effect<boolean> => Effect.map(now, greaterThan(self))
1161
+ export const isPast: (self: DateTime) => Effect.Effect<boolean> = Internal.isPast
1419
1162
 
1420
1163
  /**
1421
1164
  * @since 3.6.0
1422
1165
  * @category comparisons
1423
1166
  */
1424
- export const unsafeIsPast = (self: DateTime): boolean => greaterThan(unsafeNow(), self)
1167
+ export const unsafeIsPast: (self: DateTime) => boolean = Internal.unsafeIsPast
1425
1168
 
1426
1169
  // =============================================================================
1427
1170
  // conversions
@@ -1433,7 +1176,7 @@ export const unsafeIsPast = (self: DateTime): boolean => greaterThan(unsafeNow()
1433
1176
  * @since 3.6.0
1434
1177
  * @category conversions
1435
1178
  */
1436
- export const toDateUtc = (self: DateTime): Date => new Date(self.epochMillis)
1179
+ export const toDateUtc: (self: DateTime) => Date = Internal.toDateUtc
1437
1180
 
1438
1181
  /**
1439
1182
  * Convert a `DateTime` to a `Date`, applying the time zone first.
@@ -1441,30 +1184,7 @@ export const toDateUtc = (self: DateTime): Date => new Date(self.epochMillis)
1441
1184
  * @since 3.6.0
1442
1185
  * @category conversions
1443
1186
  */
1444
- export const toDate = (self: DateTime): Date => {
1445
- if (self._tag === "Utc") {
1446
- return new Date(self.epochMillis)
1447
- } else if (self.zone._tag === "Offset") {
1448
- return new Date(self.epochMillis + self.zone.offset)
1449
- } else if (self.adjustedEpochMillis !== undefined) {
1450
- return new Date(self.adjustedEpochMillis)
1451
- }
1452
- const parts = self.zone.format.formatToParts(self.epochMillis).filter((_) => _.type !== "literal")
1453
- const date = new Date(0)
1454
- date.setUTCFullYear(
1455
- Number(parts[2].value),
1456
- Number(parts[0].value) - 1,
1457
- Number(parts[1].value)
1458
- )
1459
- date.setUTCHours(
1460
- Number(parts[3].value),
1461
- Number(parts[4].value),
1462
- Number(parts[5].value),
1463
- Number(parts[6].value)
1464
- )
1465
- self.adjustedEpochMillis = date.getTime()
1466
- return date
1467
- }
1187
+ export const toDate: (self: DateTime) => Date = Internal.toDate
1468
1188
 
1469
1189
  /**
1470
1190
  * Calculate the time zone offset of a `DateTime.Zoned` in milliseconds.
@@ -1472,17 +1192,7 @@ export const toDate = (self: DateTime): Date => {
1472
1192
  * @since 3.6.0
1473
1193
  * @category conversions
1474
1194
  */
1475
- export const zonedOffset = (self: Zoned): number => {
1476
- const date = toDate(self)
1477
- return date.getTime() - toEpochMillis(self)
1478
- }
1479
-
1480
- const offsetToString = (offset: number): string => {
1481
- const abs = Math.abs(offset)
1482
- const hours = Math.floor(abs / (60 * 60 * 1000))
1483
- const minutes = Math.round((abs % (60 * 60 * 1000)) / (60 * 1000))
1484
- return `${offset < 0 ? "-" : "+"}${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`
1485
- }
1195
+ export const zonedOffset: (self: Zoned) => number = Internal.zonedOffset
1486
1196
 
1487
1197
  /**
1488
1198
  * Calculate the time zone offset of a `DateTime` in milliseconds.
@@ -1492,7 +1202,7 @@ const offsetToString = (offset: number): string => {
1492
1202
  * @since 3.6.0
1493
1203
  * @category conversions
1494
1204
  */
1495
- export const zonedOffsetIso = (self: Zoned): string => offsetToString(zonedOffset(self))
1205
+ export const zonedOffsetIso: (self: Zoned) => string = Internal.zonedOffsetIso
1496
1206
 
1497
1207
  /**
1498
1208
  * Get the milliseconds since the Unix epoch of a `DateTime`.
@@ -1500,7 +1210,7 @@ export const zonedOffsetIso = (self: Zoned): string => offsetToString(zonedOffse
1500
1210
  * @since 3.6.0
1501
1211
  * @category conversions
1502
1212
  */
1503
- export const toEpochMillis = (self: DateTime): number => self.epochMillis
1213
+ export const toEpochMillis: (self: DateTime) => number = Internal.toEpochMillis
1504
1214
 
1505
1215
  /**
1506
1216
  * Remove the time aspect of a `DateTime`, first adjusting for the time
@@ -1522,27 +1232,12 @@ export const toEpochMillis = (self: DateTime): number => self.epochMillis
1522
1232
  * )
1523
1233
  * ```
1524
1234
  */
1525
- export const removeTime = (self: DateTime): Utc =>
1526
- withDate(self, (date) => {
1527
- date.setUTCHours(0, 0, 0, 0)
1528
- return makeUtc(date.getTime())
1529
- })
1235
+ export const removeTime: (self: DateTime) => Utc = Internal.removeTime
1530
1236
 
1531
1237
  // =============================================================================
1532
1238
  // parts
1533
1239
  // =============================================================================
1534
1240
 
1535
- const dateToParts = (date: Date): DateTime.PartsWithWeekday => ({
1536
- millis: date.getUTCMilliseconds(),
1537
- seconds: date.getUTCSeconds(),
1538
- minutes: date.getUTCMinutes(),
1539
- hours: date.getUTCHours(),
1540
- day: date.getUTCDate(),
1541
- weekDay: date.getUTCDay(),
1542
- month: date.getUTCMonth() + 1,
1543
- year: date.getUTCFullYear()
1544
- })
1545
-
1546
1241
  /**
1547
1242
  * Get the different parts of a `DateTime` as an object.
1548
1243
  *
@@ -1551,15 +1246,7 @@ const dateToParts = (date: Date): DateTime.PartsWithWeekday => ({
1551
1246
  * @since 3.6.0
1552
1247
  * @category parts
1553
1248
  */
1554
- export const toParts = (self: DateTime): DateTime.PartsWithWeekday => {
1555
- if (self._tag === "Utc") {
1556
- return toPartsUtc(self)
1557
- } else if (self.partsAdjusted !== undefined) {
1558
- return self.partsAdjusted
1559
- }
1560
- self.partsAdjusted = withDate(self, dateToParts)
1561
- return self.partsAdjusted
1562
- }
1249
+ export const toParts: (self: DateTime) => DateTime.PartsWithWeekday = Internal.toParts
1563
1250
 
1564
1251
  /**
1565
1252
  * Get the different parts of a `DateTime` as an object.
@@ -1569,13 +1256,7 @@ export const toParts = (self: DateTime): DateTime.PartsWithWeekday => {
1569
1256
  * @since 3.6.0
1570
1257
  * @category parts
1571
1258
  */
1572
- export const toPartsUtc = (self: DateTime): DateTime.PartsWithWeekday => {
1573
- if (self.partsUtc !== undefined) {
1574
- return self.partsUtc
1575
- }
1576
- self.partsUtc = withDateUtc(self, dateToParts)
1577
- return self.partsUtc
1578
- }
1259
+ export const toPartsUtc: (self: DateTime) => DateTime.PartsWithWeekday = Internal.toPartsUtc
1579
1260
 
1580
1261
  /**
1581
1262
  * Get a part of a `DateTime` as a number.
@@ -1628,7 +1309,7 @@ export const getPartUtc: {
1628
1309
  * ```
1629
1310
  */
1630
1311
  (self: DateTime, part: keyof DateTime.PartsWithWeekday): number
1631
- } = dual(2, (self: DateTime, part: keyof DateTime.PartsWithWeekday): number => toPartsUtc(self)[part])
1312
+ } = Internal.getPartUtc
1632
1313
 
1633
1314
  /**
1634
1315
  * Get a part of a `DateTime` as a number.
@@ -1681,35 +1362,7 @@ export const getPart: {
1681
1362
  * ```
1682
1363
  */
1683
1364
  (self: DateTime, part: keyof DateTime.PartsWithWeekday): number
1684
- } = dual(2, (self: DateTime, part: keyof DateTime.PartsWithWeekday): number => toParts(self)[part])
1685
-
1686
- const setPartsDate = (date: Date, parts: Partial<DateTime.PartsWithWeekday>): void => {
1687
- if (parts.year !== undefined) {
1688
- date.setUTCFullYear(parts.year)
1689
- }
1690
- if (parts.month !== undefined) {
1691
- date.setUTCMonth(parts.month - 1)
1692
- }
1693
- if (parts.day !== undefined) {
1694
- date.setUTCDate(parts.day)
1695
- }
1696
- if (parts.weekDay !== undefined) {
1697
- const diff = parts.weekDay - date.getUTCDay()
1698
- date.setUTCDate(date.getUTCDate() + diff)
1699
- }
1700
- if (parts.hours !== undefined) {
1701
- date.setUTCHours(parts.hours)
1702
- }
1703
- if (parts.minutes !== undefined) {
1704
- date.setUTCMinutes(parts.minutes)
1705
- }
1706
- if (parts.seconds !== undefined) {
1707
- date.setUTCSeconds(parts.seconds)
1708
- }
1709
- if (parts.millis !== undefined) {
1710
- date.setUTCMilliseconds(parts.millis)
1711
- }
1712
- }
1365
+ } = Internal.getPart
1713
1366
 
1714
1367
  /**
1715
1368
  * Set the different parts of a `DateTime` as an object.
@@ -1738,11 +1391,7 @@ export const setParts: {
1738
1391
  * @category parts
1739
1392
  */
1740
1393
  <A extends DateTime>(self: A, parts: Partial<DateTime.PartsWithWeekday>): DateTime.PreserveZone<A>
1741
- } = dual(
1742
- 2,
1743
- (self: DateTime, parts: Partial<DateTime.PartsWithWeekday>): DateTime =>
1744
- mutate(self, (date) => setPartsDate(date, parts))
1745
- )
1394
+ } = Internal.setParts
1746
1395
 
1747
1396
  /**
1748
1397
  * Set the different parts of a `DateTime` as an object.
@@ -1765,24 +1414,18 @@ export const setPartsUtc: {
1765
1414
  * @category parts
1766
1415
  */
1767
1416
  <A extends DateTime>(self: A, parts: Partial<DateTime.PartsWithWeekday>): DateTime.PreserveZone<A>
1768
- } = dual(
1769
- 2,
1770
- (self: DateTime, parts: Partial<DateTime.PartsWithWeekday>): DateTime =>
1771
- mutateUtc(self, (date) => setPartsDate(date, parts))
1772
- )
1417
+ } = Internal.setPartsUtc
1773
1418
 
1774
1419
  // =============================================================================
1775
1420
  // current time zone
1776
1421
  // =============================================================================
1777
1422
 
1778
- /**
1779
- * @since 3.6.0
1780
- * @category current time zone
1781
- */
1782
- export class CurrentTimeZone extends Context.Tag("effect/DateTime/CurrentTimeZone")<
1783
- CurrentTimeZone,
1784
- TimeZone
1785
- >() {}
1423
+ // =============================================================================
1424
+ // current time zone
1425
+ // =============================================================================
1426
+
1427
+ /** @internal */
1428
+ export class CurrentTimeZone extends Context.Tag("effect/DateTime/CurrentTimeZone")<CurrentTimeZone, TimeZone>() {}
1786
1429
 
1787
1430
  /**
1788
1431
  * Set the time zone of a `DateTime` to the current time zone, which is
@@ -1858,8 +1501,10 @@ export const withCurrentZone: {
1858
1501
  <A, E, R>(effect: Effect.Effect<A, E, R>, zone: TimeZone): Effect.Effect<A, E, Exclude<R, CurrentTimeZone>>
1859
1502
  } = dual(
1860
1503
  2,
1861
- <A, E, R>(effect: Effect.Effect<A, E, R>, zone: TimeZone): Effect.Effect<A, E, Exclude<R, CurrentTimeZone>> =>
1862
- Effect.provideService(effect, CurrentTimeZone, zone)
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)
1863
1508
  )
1864
1509
 
1865
1510
  /**
@@ -2025,80 +1670,12 @@ export const withCurrentZoneNamed: {
2025
1670
  * }).pipe(DateTime.withCurrentZoneNamed("Europe/London"))
2026
1671
  * ```
2027
1672
  */
2028
- export const nowInCurrentZone: Effect.Effect<Zoned, never, CurrentTimeZone> = Effect.flatMap(
2029
- now,
2030
- setZoneCurrent
2031
- )
2032
-
2033
- /**
2034
- * Create a Layer from the given time zone.
2035
- *
2036
- * @since 3.6.0
2037
- * @category current time zone
2038
- */
2039
- export const layerCurrentZone = (zone: TimeZone): Layer.Layer<CurrentTimeZone> => Layer.succeed(CurrentTimeZone, zone)
2040
-
2041
- /**
2042
- * Create a Layer from the given time zone offset.
2043
- *
2044
- * @since 3.6.0
2045
- * @category current time zone
2046
- */
2047
- export const layerCurrentZoneOffset = (offset: number): Layer.Layer<CurrentTimeZone> =>
2048
- Layer.succeed(CurrentTimeZone, zoneMakeOffset(offset))
2049
-
2050
- /**
2051
- * Create a Layer from the given IANA time zone identifier.
2052
- *
2053
- * @since 3.6.0
2054
- * @category current time zone
2055
- */
2056
- export const layerCurrentZoneNamed = (zoneId: string): Layer.Layer<CurrentTimeZone, IllegalArgumentException> =>
2057
- Layer.effect(CurrentTimeZone, zoneMakeNamedEffect(zoneId))
2058
-
2059
- /**
2060
- * Create a Layer from the systems local time zone.
2061
- *
2062
- * @since 3.6.0
2063
- * @category current time zone
2064
- */
2065
- export const layerCurrentZoneLocal: Layer.Layer<CurrentTimeZone> = Layer.sync(
2066
- CurrentTimeZone,
2067
- zoneMakeLocal
2068
- )
1673
+ export const nowInCurrentZone: Effect.Effect<Zoned, never, CurrentTimeZone> = Effect.flatMap(now, setZoneCurrent)
2069
1674
 
2070
1675
  // =============================================================================
2071
1676
  // mapping
2072
1677
  // =============================================================================
2073
1678
 
2074
- const makeZonedFromAdjusted = (adjustedMillis: number, zone: TimeZone): Zoned => {
2075
- const offset = zone._tag === "Offset" ? zone.offset : calculateNamedOffset(adjustedMillis, zone)
2076
- return makeZonedProto(adjustedMillis - offset, zone)
2077
- }
2078
-
2079
- const offsetRegex = /([+-])(\d{2}):(\d{2})$/
2080
- const parseOffset = (offset: string): number | null => {
2081
- const match = offsetRegex.exec(offset)
2082
- if (match === null) {
2083
- return null
2084
- }
2085
- const [, sign, hours, minutes] = match
2086
- return (sign === "+" ? 1 : -1) * (Number(hours) * 60 + Number(minutes)) * 60 * 1000
2087
- }
2088
-
2089
- const calculateNamedOffset = (adjustedMillis: number, zone: TimeZone.Named): number => {
2090
- const offset = zone.format.formatToParts(adjustedMillis).find((_) => _.type === "timeZoneName")?.value ?? ""
2091
- if (offset === "GMT") {
2092
- return 0
2093
- }
2094
- const result = parseOffset(offset)
2095
- if (result === null) {
2096
- // fallback to using the adjusted date
2097
- return zonedOffset(makeZonedProto(adjustedMillis, zone))
2098
- }
2099
- return result
2100
- }
2101
-
2102
1679
  /**
2103
1680
  * Modify a `DateTime` by applying a function to a cloned `Date` instance.
2104
1681
  *
@@ -2109,6 +1686,10 @@ const calculateNamedOffset = (adjustedMillis: number, zone: TimeZone.Named): num
2109
1686
  * @category mapping
2110
1687
  */
2111
1688
  export const mutate: {
1689
+ // =============================================================================
1690
+ // mapping
1691
+ // =============================================================================
1692
+
2112
1693
  /**
2113
1694
  * Modify a `DateTime` by applying a function to a cloned `Date` instance.
2114
1695
  *
@@ -2119,6 +1700,10 @@ export const mutate: {
2119
1700
  * @category mapping
2120
1701
  */
2121
1702
  (f: (date: Date) => void): <A extends DateTime>(self: A) => DateTime.PreserveZone<A>
1703
+ // =============================================================================
1704
+ // mapping
1705
+ // =============================================================================
1706
+
2122
1707
  /**
2123
1708
  * Modify a `DateTime` by applying a function to a cloned `Date` instance.
2124
1709
  *
@@ -2129,17 +1714,7 @@ export const mutate: {
2129
1714
  * @category mapping
2130
1715
  */
2131
1716
  <A extends DateTime>(self: A, f: (date: Date) => void): DateTime.PreserveZone<A>
2132
- } = dual(2, (self: DateTime, f: (date: Date) => void): DateTime => {
2133
- if (self._tag === "Utc") {
2134
- const date = toDateUtc(self)
2135
- f(date)
2136
- return makeUtc(date.getTime())
2137
- }
2138
- const adjustedDate = toDate(self)
2139
- const newAdjustedDate = new Date(adjustedDate.getTime())
2140
- f(newAdjustedDate)
2141
- return makeZonedFromAdjusted(newAdjustedDate.getTime(), self.zone)
2142
- })
1717
+ } = Internal.mutate
2143
1718
 
2144
1719
  /**
2145
1720
  * Modify a `DateTime` by applying a function to a cloned UTC `Date` instance.
@@ -2162,12 +1737,7 @@ export const mutateUtc: {
2162
1737
  * @category mapping
2163
1738
  */
2164
1739
  <A extends DateTime>(self: A, f: (date: Date) => void): DateTime.PreserveZone<A>
2165
- } = dual(2, (self: DateTime, f: (date: Date) => void): DateTime =>
2166
- mapEpochMillis(self, (millis) => {
2167
- const date = new Date(millis)
2168
- f(date)
2169
- return date.getTime()
2170
- }))
1740
+ } = Internal.mutateUtc
2171
1741
 
2172
1742
  /**
2173
1743
  * Transform a `DateTime` by applying a function to the number of milliseconds
@@ -2220,10 +1790,7 @@ export const mapEpochMillis: {
2220
1790
  * ```
2221
1791
  */
2222
1792
  <A extends DateTime>(self: A, f: (millis: number) => number): DateTime.PreserveZone<A>
2223
- } = dual(2, (self: DateTime, f: (millis: number) => number): DateTime => {
2224
- const millis = f(toEpochMillis(self))
2225
- return self._tag === "Utc" ? makeUtc(millis) : makeZonedProto(millis, self.zone)
2226
- })
1793
+ } = Internal.mapEpochMillis
2227
1794
 
2228
1795
  /**
2229
1796
  * Using the time zone adjusted `Date`, apply a function to the `Date` and
@@ -2276,7 +1843,7 @@ export const withDate: {
2276
1843
  * ```
2277
1844
  */
2278
1845
  <A>(self: DateTime, f: (date: Date) => A): A
2279
- } = dual(2, <A>(self: DateTime, f: (date: Date) => A): A => f(toDate(self)))
1846
+ } = Internal.withDate
2280
1847
 
2281
1848
  /**
2282
1849
  * Using the time zone adjusted `Date`, apply a function to the `Date` and
@@ -2329,7 +1896,7 @@ export const withDateUtc: {
2329
1896
  * ```
2330
1897
  */
2331
1898
  <A>(self: DateTime, f: (date: Date) => A): A
2332
- } = dual(2, <A>(self: DateTime, f: (date: Date) => A): A => f(toDateUtc(self)))
1899
+ } = Internal.withDateUtc
2333
1900
 
2334
1901
  /**
2335
1902
  * @since 3.6.0
@@ -2357,10 +1924,7 @@ export const match: {
2357
1924
  readonly onZoned: (_: Zoned) => B
2358
1925
  }
2359
1926
  ): A | B
2360
- } = dual(2, <A, B>(self: DateTime, options: {
2361
- readonly onUtc: (_: Utc) => A
2362
- readonly onZoned: (_: Zoned) => B
2363
- }): A | B => self._tag === "Utc" ? options.onUtc(self) : options.onZoned(self))
1927
+ } = Internal.match
2364
1928
 
2365
1929
  // =============================================================================
2366
1930
  // math
@@ -2422,11 +1986,7 @@ export const addDuration: {
2422
1986
  * ```
2423
1987
  */
2424
1988
  <A extends DateTime>(self: A, duration: Duration.DurationInput): DateTime.PreserveZone<A>
2425
- } = dual(
2426
- 2,
2427
- (self: DateTime, duration: Duration.DurationInput): DateTime =>
2428
- mapEpochMillis(self, (millis) => millis + Duration.toMillis(duration))
2429
- )
1989
+ } = Internal.addDuration
2430
1990
 
2431
1991
  /**
2432
1992
  * Subtract the given `Duration` from a `DateTime`.
@@ -2476,15 +2036,7 @@ export const subtractDuration: {
2476
2036
  * ```
2477
2037
  */
2478
2038
  <A extends DateTime>(self: A, duration: Duration.DurationInput): DateTime.PreserveZone<A>
2479
- } = dual(
2480
- 2,
2481
- (self: DateTime, duration: Duration.DurationInput): DateTime =>
2482
- mapEpochMillis(self, (millis) => millis - Duration.toMillis(duration))
2483
- )
2484
-
2485
- const addMillis = (date: Date, amount: number): void => {
2486
- date.setTime(date.getTime() + amount)
2487
- }
2039
+ } = Internal.subtractDuration
2488
2040
 
2489
2041
  /**
2490
2042
  * Add the given `amount` of `unit`'s to a `DateTime`.
@@ -2543,46 +2095,7 @@ export const add: {
2543
2095
  * ```
2544
2096
  */
2545
2097
  <A extends DateTime>(self: A, parts: Partial<DateTime.PartsForMath>): DateTime.PreserveZone<A>
2546
- } = dual(2, (self: DateTime, parts: Partial<DateTime.PartsForMath>): DateTime =>
2547
- mutate(self, (date) => {
2548
- if (parts.millis) {
2549
- addMillis(date, parts.millis)
2550
- }
2551
- if (parts.seconds) {
2552
- addMillis(date, parts.seconds * 1000)
2553
- }
2554
- if (parts.minutes) {
2555
- addMillis(date, parts.minutes * 60 * 1000)
2556
- }
2557
- if (parts.hours) {
2558
- addMillis(date, parts.hours * 60 * 60 * 1000)
2559
- }
2560
- if (parts.days) {
2561
- date.setUTCDate(date.getUTCDate() + parts.days)
2562
- }
2563
- if (parts.weeks) {
2564
- date.setUTCDate(date.getUTCDate() + parts.weeks * 7)
2565
- }
2566
- if (parts.months) {
2567
- const day = date.getUTCDate()
2568
- date.setUTCMonth(date.getUTCMonth() + parts.months + 1, 0)
2569
- if (day < date.getUTCDate()) {
2570
- date.setUTCDate(day)
2571
- }
2572
- }
2573
- if (parts.years) {
2574
- const day = date.getUTCDate()
2575
- const month = date.getUTCMonth()
2576
- date.setUTCFullYear(
2577
- date.getUTCFullYear() + parts.years,
2578
- month + 1,
2579
- 0
2580
- )
2581
- if (day < date.getUTCDate()) {
2582
- date.setUTCDate(day)
2583
- }
2584
- }
2585
- }))
2098
+ } = Internal.add
2586
2099
 
2587
2100
  /**
2588
2101
  * Subtract the given `amount` of `unit`'s from a `DateTime`.
@@ -2632,54 +2145,7 @@ export const subtract: {
2632
2145
  * ```
2633
2146
  */
2634
2147
  <A extends DateTime>(self: A, parts: Partial<DateTime.PartsForMath>): DateTime.PreserveZone<A>
2635
- } = dual(2, (self: DateTime, parts: Partial<DateTime.PartsForMath>): DateTime => {
2636
- const newParts = {} as Partial<Mutable<DateTime.PartsForMath>>
2637
- for (const key in parts) {
2638
- newParts[key as keyof DateTime.PartsForMath] = -1 * parts[key as keyof DateTime.PartsForMath]!
2639
- }
2640
- return add(self, newParts)
2641
- })
2642
-
2643
- function startOfDate(date: Date, part: DateTime.UnitSingular, options?: {
2644
- readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
2645
- }) {
2646
- switch (part) {
2647
- case "second": {
2648
- date.setUTCMilliseconds(0)
2649
- break
2650
- }
2651
- case "minute": {
2652
- date.setUTCSeconds(0, 0)
2653
- break
2654
- }
2655
- case "hour": {
2656
- date.setUTCMinutes(0, 0, 0)
2657
- break
2658
- }
2659
- case "day": {
2660
- date.setUTCHours(0, 0, 0, 0)
2661
- break
2662
- }
2663
- case "week": {
2664
- const weekStartsOn = options?.weekStartsOn ?? 0
2665
- const day = date.getUTCDay()
2666
- const diff = (day - weekStartsOn + 7) % 7
2667
- date.setUTCDate(date.getUTCDate() - diff)
2668
- date.setUTCHours(0, 0, 0, 0)
2669
- break
2670
- }
2671
- case "month": {
2672
- date.setUTCDate(1)
2673
- date.setUTCHours(0, 0, 0, 0)
2674
- break
2675
- }
2676
- case "year": {
2677
- date.setUTCMonth(0, 1)
2678
- date.setUTCHours(0, 0, 0, 0)
2679
- break
2680
- }
2681
- }
2682
- }
2148
+ } = Internal.subtract
2683
2149
 
2684
2150
  /**
2685
2151
  * Converts a `DateTime` to the start of the given `part`.
@@ -2752,50 +2218,7 @@ export const startOf: {
2752
2218
  readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
2753
2219
  }
2754
2220
  ): DateTime.PreserveZone<A>
2755
- } = dual(isDateTimeArgs, (self: DateTime, part: DateTime.UnitSingular, options?: {
2756
- readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
2757
- }): DateTime => mutate(self, (date) => startOfDate(date, part, options)))
2758
-
2759
- function endOfDate(date: Date, part: DateTime.UnitSingular, options?: {
2760
- readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
2761
- }) {
2762
- switch (part) {
2763
- case "second": {
2764
- date.setUTCMilliseconds(999)
2765
- break
2766
- }
2767
- case "minute": {
2768
- date.setUTCSeconds(59, 999)
2769
- break
2770
- }
2771
- case "hour": {
2772
- date.setUTCMinutes(59, 59, 999)
2773
- break
2774
- }
2775
- case "day": {
2776
- date.setUTCHours(23, 59, 59, 999)
2777
- break
2778
- }
2779
- case "week": {
2780
- const weekStartsOn = options?.weekStartsOn ?? 0
2781
- const day = date.getUTCDay()
2782
- const diff = (day - weekStartsOn + 7) % 7
2783
- date.setUTCDate(date.getUTCDate() - diff + 6)
2784
- date.setUTCHours(23, 59, 59, 999)
2785
- break
2786
- }
2787
- case "month": {
2788
- date.setUTCMonth(date.getUTCMonth() + 1, 0)
2789
- date.setUTCHours(23, 59, 59, 999)
2790
- break
2791
- }
2792
- case "year": {
2793
- date.setUTCMonth(11, 31)
2794
- date.setUTCHours(23, 59, 59, 999)
2795
- break
2796
- }
2797
- }
2798
- }
2221
+ } = Internal.startOf
2799
2222
 
2800
2223
  /**
2801
2224
  * Converts a `DateTime` to the end of the given `part`.
@@ -2868,9 +2291,7 @@ export const endOf: {
2868
2291
  readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
2869
2292
  }
2870
2293
  ): DateTime.PreserveZone<A>
2871
- } = dual(isDateTimeArgs, (self: DateTime, part: DateTime.UnitSingular, options?: {
2872
- readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
2873
- }): DateTime => mutate(self, (date) => endOfDate(date, part, options)))
2294
+ } = Internal.endOf
2874
2295
 
2875
2296
  /**
2876
2297
  * Converts a `DateTime` to the nearest given `part`.
@@ -2943,38 +2364,12 @@ export const nearest: {
2943
2364
  readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
2944
2365
  }
2945
2366
  ): DateTime.PreserveZone<A>
2946
- } = dual(isDateTimeArgs, (self: DateTime, part: DateTime.UnitSingular, options?: {
2947
- readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
2948
- }): DateTime =>
2949
- mutate(self, (date) => {
2950
- if (part === "milli") return
2951
- const millis = date.getTime()
2952
- const start = new Date(millis)
2953
- startOfDate(start, part, options)
2954
- const startMillis = start.getTime()
2955
- const end = new Date(millis)
2956
- endOfDate(end, part, options)
2957
- const endMillis = end.getTime() + 1
2958
- const diffStart = millis - startMillis
2959
- const diffEnd = endMillis - millis
2960
- if (diffStart < diffEnd) {
2961
- date.setTime(startMillis)
2962
- } else {
2963
- date.setTime(endMillis)
2964
- }
2965
- }))
2367
+ } = Internal.nearest
2966
2368
 
2967
2369
  // =============================================================================
2968
2370
  // formatting
2969
2371
  // =============================================================================
2970
2372
 
2971
- const intlTimeZone = (self: TimeZone): string => {
2972
- if (self._tag === "Named") {
2973
- return self.id
2974
- }
2975
- return offsetToString(self.offset)
2976
- }
2977
-
2978
2373
  /**
2979
2374
  * Format a `DateTime` as a string using the `DateTimeFormat` API.
2980
2375
  *
@@ -2987,6 +2382,10 @@ const intlTimeZone = (self: TimeZone): string => {
2987
2382
  * @category formatting
2988
2383
  */
2989
2384
  export const format: {
2385
+ // =============================================================================
2386
+ // formatting
2387
+ // =============================================================================
2388
+
2990
2389
  /**
2991
2390
  * Format a `DateTime` as a string using the `DateTimeFormat` API.
2992
2391
  *
@@ -3005,6 +2404,10 @@ export const format: {
3005
2404
  }
3006
2405
  | undefined
3007
2406
  ): (self: DateTime) => string
2407
+ // =============================================================================
2408
+ // formatting
2409
+ // =============================================================================
2410
+
3008
2411
  /**
3009
2412
  * Format a `DateTime` as a string using the `DateTimeFormat` API.
3010
2413
  *
@@ -3024,26 +2427,7 @@ export const format: {
3024
2427
  }
3025
2428
  | undefined
3026
2429
  ): string
3027
- } = dual(isDateTimeArgs, (
3028
- self: DateTime,
3029
- options?:
3030
- | Intl.DateTimeFormatOptions & {
3031
- readonly locale?: string | undefined
3032
- }
3033
- | undefined
3034
- ): string => {
3035
- try {
3036
- return new Intl.DateTimeFormat(options?.locale, {
3037
- timeZone: self._tag === "Utc" ? "UTC" : intlTimeZone(self.zone),
3038
- ...options
3039
- }).format(self.epochMillis)
3040
- } catch (_) {
3041
- return new Intl.DateTimeFormat(options?.locale, {
3042
- timeZone: "UTC",
3043
- ...options
3044
- }).format(toDate(self))
3045
- }
3046
- })
2430
+ } = Internal.format
3047
2431
 
3048
2432
  /**
3049
2433
  * Format a `DateTime` as a string using the `DateTimeFormat` API.
@@ -3085,14 +2469,7 @@ export const formatLocal: {
3085
2469
  }
3086
2470
  | undefined
3087
2471
  ): string
3088
- } = dual(isDateTimeArgs, (
3089
- self: DateTime,
3090
- options?:
3091
- | Intl.DateTimeFormatOptions & {
3092
- readonly locale?: string | undefined
3093
- }
3094
- | undefined
3095
- ): string => new Intl.DateTimeFormat(options?.locale, options).format(self.epochMillis))
2472
+ } = Internal.formatLocal
3096
2473
 
3097
2474
  /**
3098
2475
  * Format a `DateTime` as a string using the `DateTimeFormat` API.
@@ -3134,18 +2511,7 @@ export const formatUtc: {
3134
2511
  }
3135
2512
  | undefined
3136
2513
  ): string
3137
- } = dual(isDateTimeArgs, (
3138
- self: DateTime,
3139
- options?:
3140
- | Intl.DateTimeFormatOptions & {
3141
- readonly locale?: string | undefined
3142
- }
3143
- | undefined
3144
- ): string =>
3145
- new Intl.DateTimeFormat(options?.locale, {
3146
- ...options,
3147
- timeZone: "UTC"
3148
- }).format(self.epochMillis))
2514
+ } = Internal.formatUtc
3149
2515
 
3150
2516
  /**
3151
2517
  * Format a `DateTime` as a string using the `DateTimeFormat` API.
@@ -3168,7 +2534,7 @@ export const formatIntl: {
3168
2534
  * @category formatting
3169
2535
  */
3170
2536
  (self: DateTime, format: Intl.DateTimeFormat): string
3171
- } = dual(2, (self: DateTime, format: Intl.DateTimeFormat): string => format.format(self.epochMillis))
2537
+ } = Internal.formatIntl
3172
2538
 
3173
2539
  /**
3174
2540
  * Format a `DateTime` as a UTC ISO string.
@@ -3176,7 +2542,7 @@ export const formatIntl: {
3176
2542
  * @since 3.6.0
3177
2543
  * @category formatting
3178
2544
  */
3179
- export const formatIso = (self: DateTime): string => toDateUtc(self).toISOString()
2545
+ export const formatIso: (self: DateTime) => string = Internal.formatIso
3180
2546
 
3181
2547
  /**
3182
2548
  * Format a `DateTime` as a time zone adjusted ISO date string.
@@ -3184,7 +2550,7 @@ export const formatIso = (self: DateTime): string => toDateUtc(self).toISOString
3184
2550
  * @since 3.6.0
3185
2551
  * @category formatting
3186
2552
  */
3187
- export const formatIsoDate = (self: DateTime): string => toDate(self).toISOString().slice(0, 10)
2553
+ export const formatIsoDate: (self: DateTime) => string = Internal.formatIsoDate
3188
2554
 
3189
2555
  /**
3190
2556
  * Format a `DateTime` as a UTC ISO date string.
@@ -3192,7 +2558,7 @@ export const formatIsoDate = (self: DateTime): string => toDate(self).toISOStrin
3192
2558
  * @since 3.6.0
3193
2559
  * @category formatting
3194
2560
  */
3195
- export const formatIsoDateUtc = (self: DateTime): string => toDateUtc(self).toISOString().slice(0, 10)
2561
+ export const formatIsoDateUtc: (self: DateTime) => string = Internal.formatIsoDateUtc
3196
2562
 
3197
2563
  /**
3198
2564
  * Format a `DateTime.Zoned` as a ISO string with an offset.
@@ -3200,10 +2566,7 @@ export const formatIsoDateUtc = (self: DateTime): string => toDateUtc(self).toIS
3200
2566
  * @since 3.6.0
3201
2567
  * @category formatting
3202
2568
  */
3203
- export const formatIsoOffset = (self: DateTime): string => {
3204
- const date = toDate(self)
3205
- return self._tag === "Utc" ? date.toISOString() : `${date.toISOString().slice(0, -1)}${zonedOffsetIso(self)}`
3206
- }
2569
+ export const formatIsoOffset: (self: DateTime) => string = Internal.formatIsoOffset
3207
2570
 
3208
2571
  /**
3209
2572
  * Format a `DateTime.Zoned` as a string.
@@ -3213,5 +2576,40 @@ export const formatIsoOffset = (self: DateTime): string => {
3213
2576
  * @since 3.6.0
3214
2577
  * @category formatting
3215
2578
  */
3216
- export const formatIsoZoned = (self: Zoned): string =>
3217
- self.zone._tag === "Offset" ? formatIsoOffset(self) : `${formatIsoOffset(self)}[${self.zone.id}]`
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)