@clayroach/effect 3.19.14-source-capture.7 → 3.19.14-source-capture.8

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