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.
- package/dist/cjs/BigDecimal.js +125 -24
- package/dist/cjs/BigDecimal.js.map +1 -1
- package/dist/cjs/Channel.js +44 -4
- package/dist/cjs/Channel.js.map +1 -1
- package/dist/cjs/Config.js +8 -1
- package/dist/cjs/Config.js.map +1 -1
- package/dist/cjs/Context.js +26 -1
- package/dist/cjs/Context.js.map +1 -1
- package/dist/cjs/Cron.js +75 -67
- package/dist/cjs/Cron.js.map +1 -1
- package/dist/cjs/DateTime.js +114 -664
- package/dist/cjs/DateTime.js.map +1 -1
- package/dist/cjs/Effect.js +82 -4
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/Inspectable.js +8 -4
- package/dist/cjs/Inspectable.js.map +1 -1
- package/dist/cjs/JSONSchema.js.map +1 -1
- package/dist/cjs/Micro.js +1099 -1072
- package/dist/cjs/Micro.js.map +1 -1
- package/dist/cjs/STM.js.map +1 -1
- package/dist/cjs/Schema.js +57 -8
- package/dist/cjs/Schema.js.map +1 -1
- package/dist/cjs/Sink.js +9 -1
- package/dist/cjs/Sink.js.map +1 -1
- package/dist/cjs/Stream.js +25 -7
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/Utils.js +7 -1
- package/dist/cjs/Utils.js.map +1 -1
- package/dist/cjs/internal/channel/channelExecutor.js +5 -9
- package/dist/cjs/internal/channel/channelExecutor.js.map +1 -1
- package/dist/cjs/internal/channel.js +156 -130
- package/dist/cjs/internal/channel.js.map +1 -1
- package/dist/cjs/internal/config.js +13 -4
- package/dist/cjs/internal/config.js.map +1 -1
- package/dist/cjs/internal/context.js +46 -3
- package/dist/cjs/internal/context.js.map +1 -1
- package/dist/cjs/internal/dateTime.js +747 -0
- package/dist/cjs/internal/dateTime.js.map +1 -0
- package/dist/cjs/internal/fiberRuntime.js +34 -11
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/groupBy.js +9 -3
- package/dist/cjs/internal/groupBy.js.map +1 -1
- package/dist/cjs/internal/layer.js +1 -1
- package/dist/cjs/internal/layer.js.map +1 -1
- package/dist/cjs/internal/mailbox.js +1 -1
- package/dist/cjs/internal/mailbox.js.map +1 -1
- package/dist/cjs/internal/sink.js +25 -21
- package/dist/cjs/internal/sink.js.map +1 -1
- package/dist/cjs/internal/stream.js +70 -71
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/cjs/internal/version.js.map +1 -1
- package/dist/dts/BigDecimal.d.ts +56 -1
- package/dist/dts/BigDecimal.d.ts.map +1 -1
- package/dist/dts/Channel.d.ts +66 -5
- package/dist/dts/Channel.d.ts.map +1 -1
- package/dist/dts/Config.d.ts +23 -1
- package/dist/dts/Config.d.ts.map +1 -1
- package/dist/dts/Context.d.ts +111 -0
- package/dist/dts/Context.d.ts.map +1 -1
- package/dist/dts/Cron.d.ts +15 -6
- package/dist/dts/Cron.d.ts.map +1 -1
- package/dist/dts/DateTime.d.ts +40 -49
- package/dist/dts/DateTime.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +88 -1
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/Inspectable.d.ts.map +1 -1
- package/dist/dts/JSONSchema.d.ts +1 -0
- package/dist/dts/JSONSchema.d.ts.map +1 -1
- package/dist/dts/Micro.d.ts +875 -872
- package/dist/dts/Micro.d.ts.map +1 -1
- package/dist/dts/STM.d.ts +2 -0
- package/dist/dts/STM.d.ts.map +1 -1
- package/dist/dts/Schema.d.ts +32 -0
- package/dist/dts/Schema.d.ts.map +1 -1
- package/dist/dts/Sink.d.ts +8 -0
- package/dist/dts/Sink.d.ts.map +1 -1
- package/dist/dts/Stream.d.ts +50 -32
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/Utils.d.ts +4 -0
- package/dist/dts/Utils.d.ts.map +1 -1
- package/dist/dts/internal/context.d.ts +1 -1
- package/dist/dts/internal/context.d.ts.map +1 -1
- package/dist/dts/internal/dateTime.d.ts +2 -0
- package/dist/dts/internal/dateTime.d.ts.map +1 -0
- package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/BigDecimal.js +119 -20
- package/dist/esm/BigDecimal.js.map +1 -1
- package/dist/esm/Channel.js +42 -2
- package/dist/esm/Channel.js.map +1 -1
- package/dist/esm/Config.js +7 -0
- package/dist/esm/Config.js.map +1 -1
- package/dist/esm/Context.js +25 -0
- package/dist/esm/Context.js.map +1 -1
- package/dist/esm/Cron.js +75 -67
- package/dist/esm/Cron.js.map +1 -1
- package/dist/esm/DateTime.js +112 -627
- package/dist/esm/DateTime.js.map +1 -1
- package/dist/esm/Effect.js +77 -0
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/Inspectable.js +8 -4
- package/dist/esm/Inspectable.js.map +1 -1
- package/dist/esm/JSONSchema.js.map +1 -1
- package/dist/esm/Micro.js +1077 -1047
- package/dist/esm/Micro.js.map +1 -1
- package/dist/esm/STM.js.map +1 -1
- package/dist/esm/Schema.js +54 -0
- package/dist/esm/Schema.js.map +1 -1
- package/dist/esm/Sink.js +8 -0
- package/dist/esm/Sink.js.map +1 -1
- package/dist/esm/Stream.js +23 -5
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/Utils.js +5 -0
- package/dist/esm/Utils.js.map +1 -1
- package/dist/esm/internal/channel/channelExecutor.js +5 -7
- package/dist/esm/internal/channel/channelExecutor.js.map +1 -1
- package/dist/esm/internal/channel.js +152 -129
- package/dist/esm/internal/channel.js.map +1 -1
- package/dist/esm/internal/config.js +11 -3
- package/dist/esm/internal/config.js.map +1 -1
- package/dist/esm/internal/context.js +42 -2
- package/dist/esm/internal/context.js.map +1 -1
- package/dist/esm/internal/dateTime.js +704 -0
- package/dist/esm/internal/dateTime.js.map +1 -0
- package/dist/esm/internal/fiberRuntime.js +31 -9
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/groupBy.js +9 -3
- package/dist/esm/internal/groupBy.js.map +1 -1
- package/dist/esm/internal/layer.js +1 -1
- package/dist/esm/internal/layer.js.map +1 -1
- package/dist/esm/internal/mailbox.js +1 -1
- package/dist/esm/internal/mailbox.js.map +1 -1
- package/dist/esm/internal/sink.js +23 -20
- package/dist/esm/internal/sink.js.map +1 -1
- package/dist/esm/internal/stream.js +66 -69
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/dist/esm/internal/version.js.map +1 -1
- package/package.json +1 -1
- package/src/BigDecimal.ts +131 -21
- package/src/Channel.ts +81 -5
- package/src/Config.ts +24 -1
- package/src/Context.ts +119 -0
- package/src/Cron.ts +85 -68
- package/src/DateTime.ts +155 -757
- package/src/Effect.ts +340 -1
- package/src/Inspectable.ts +11 -7
- package/src/JSONSchema.ts +1 -0
- package/src/Micro.ts +2005 -1757
- package/src/STM.ts +2 -0
- package/src/Schema.ts +60 -0
- package/src/Sink.ts +11 -0
- package/src/Stream.ts +55 -44
- package/src/Utils.ts +8 -0
- package/src/internal/channel/channelExecutor.ts +37 -33
- package/src/internal/channel.ts +504 -467
- package/src/internal/config.ts +18 -6
- package/src/internal/context.ts +56 -4
- package/src/internal/dateTime.ts +1126 -0
- package/src/internal/fiberRuntime.ts +35 -16
- package/src/internal/groupBy.ts +13 -22
- package/src/internal/layer.ts +5 -8
- package/src/internal/mailbox.ts +6 -4
- package/src/internal/sink.ts +55 -35
- package/src/internal/stream.ts +299 -299
- package/src/internal/version.ts +1 -1
package/dist/cjs/DateTime.js
CHANGED
|
@@ -4,130 +4,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.zonedOffsetIso = exports.zonedOffset = exports.zoneUnsafeMakeNamed = exports.zoneToString = exports.zoneMakeOffset = exports.zoneMakeNamedEffect = exports.zoneMakeNamed = exports.zoneMakeLocal = exports.zoneFromString = exports.withDateUtc = exports.withDate = exports.withCurrentZoneOffset = exports.withCurrentZoneNamed = exports.withCurrentZoneLocal = exports.withCurrentZone = exports.unsafeSetZoneNamed = exports.unsafeNow = exports.unsafeMakeZoned = exports.unsafeMake = exports.unsafeIsPast = exports.unsafeIsFuture = exports.unsafeFromDate = exports.toPartsUtc = exports.toParts = exports.toEpochMillis = exports.toDateUtc = exports.toDate = exports.subtractDuration = exports.subtract = exports.startOf = exports.setZoneOffset = exports.setZoneNamed = exports.setZoneCurrent = exports.setZone = exports.setPartsUtc = exports.setParts = exports.removeTime = exports.nowInCurrentZone = exports.now = exports.nearest = exports.mutateUtc = exports.mutate = exports.min = exports.max = exports.match = exports.mapEpochMillis = exports.makeZonedFromString = exports.makeZoned = exports.make = exports.lessThanOrEqualTo = exports.lessThan = exports.layerCurrentZoneOffset = exports.layerCurrentZoneNamed = exports.layerCurrentZoneLocal = exports.layerCurrentZone = exports.isZoned = exports.isUtc = exports.isTimeZoneOffset = exports.isTimeZoneNamed = exports.isTimeZone = exports.isPast = exports.isFuture = exports.isDateTime = exports.greaterThanOrEqualTo = exports.greaterThan = exports.getPartUtc = exports.getPart = exports.formatUtc = exports.formatLocal = exports.formatIsoZoned = exports.formatIsoOffset = exports.formatIsoDateUtc = exports.formatIsoDate = exports.formatIso = exports.formatIntl = exports.format = exports.endOf = exports.distanceDurationEither = exports.distanceDuration = exports.distance = exports.clamp = exports.between = exports.addDuration = exports.add = exports.TypeId = exports.TimeZoneTypeId = exports.Order = exports.Equivalence = exports.CurrentTimeZone = void 0;
|
|
7
|
-
var _Cause = require("./Cause.js");
|
|
8
|
-
var Clock = _interopRequireWildcard(require("./Clock.js"));
|
|
9
7
|
var Context = _interopRequireWildcard(require("./Context.js"));
|
|
10
|
-
var Duration = _interopRequireWildcard(require("./Duration.js"));
|
|
11
8
|
var Effect = _interopRequireWildcard(require("./Effect.js"));
|
|
12
|
-
var Either = _interopRequireWildcard(require("./Either.js"));
|
|
13
|
-
var Equal = _interopRequireWildcard(require("./Equal.js"));
|
|
14
|
-
var Equivalence_ = _interopRequireWildcard(require("./Equivalence.js"));
|
|
15
9
|
var _Function = require("./Function.js");
|
|
16
|
-
var
|
|
17
|
-
var Hash = _interopRequireWildcard(require("./Hash.js"));
|
|
18
|
-
var Inspectable = _interopRequireWildcard(require("./Inspectable.js"));
|
|
10
|
+
var Internal = _interopRequireWildcard(require("./internal/dateTime.js"));
|
|
19
11
|
var Layer = _interopRequireWildcard(require("./Layer.js"));
|
|
20
|
-
var Option = _interopRequireWildcard(require("./Option.js"));
|
|
21
|
-
var order = _interopRequireWildcard(require("./Order.js"));
|
|
22
|
-
var _Pipeable = require("./Pipeable.js");
|
|
23
|
-
var Predicate = _interopRequireWildcard(require("./Predicate.js"));
|
|
24
12
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
25
13
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
26
|
-
/**
|
|
27
|
-
* @since 3.6.0
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
14
|
/**
|
|
31
15
|
* @since 3.6.0
|
|
32
16
|
* @category type ids
|
|
33
17
|
*/
|
|
34
|
-
const TypeId = exports.TypeId =
|
|
18
|
+
const TypeId = exports.TypeId = Internal.TypeId;
|
|
35
19
|
/**
|
|
36
20
|
* @since 3.6.0
|
|
37
21
|
* @category type ids
|
|
38
22
|
*/
|
|
39
|
-
const TimeZoneTypeId = exports.TimeZoneTypeId =
|
|
40
|
-
const Proto = {
|
|
41
|
-
[TypeId]: TypeId,
|
|
42
|
-
pipe() {
|
|
43
|
-
return (0, _Pipeable.pipeArguments)(this, arguments);
|
|
44
|
-
},
|
|
45
|
-
[Inspectable.NodeInspectSymbol]() {
|
|
46
|
-
return this.toString();
|
|
47
|
-
},
|
|
48
|
-
toJSON() {
|
|
49
|
-
return toDateUtc(this).toJSON();
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const ProtoUtc = {
|
|
53
|
-
...Proto,
|
|
54
|
-
_tag: "Utc",
|
|
55
|
-
[Hash.symbol]() {
|
|
56
|
-
return Hash.cached(this, Hash.number(this.epochMillis));
|
|
57
|
-
},
|
|
58
|
-
[Equal.symbol](that) {
|
|
59
|
-
return isDateTime(that) && that._tag === "Utc" && this.epochMillis === that.epochMillis;
|
|
60
|
-
},
|
|
61
|
-
toString() {
|
|
62
|
-
return `DateTime.Utc(${toDateUtc(this).toJSON()})`;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
const ProtoZoned = {
|
|
66
|
-
...Proto,
|
|
67
|
-
_tag: "Zoned",
|
|
68
|
-
[Hash.symbol]() {
|
|
69
|
-
return (0, _Function.pipe)(Hash.number(this.epochMillis), Hash.combine(Hash.hash(this.zone)), Hash.cached(this));
|
|
70
|
-
},
|
|
71
|
-
[Equal.symbol](that) {
|
|
72
|
-
return isDateTime(that) && that._tag === "Zoned" && this.epochMillis === that.epochMillis && Equal.equals(this.zone, that.zone);
|
|
73
|
-
},
|
|
74
|
-
toString() {
|
|
75
|
-
return `DateTime.Zoned(${formatIsoZoned(this)})`;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const ProtoTimeZone = {
|
|
79
|
-
[TimeZoneTypeId]: TimeZoneTypeId,
|
|
80
|
-
[Inspectable.NodeInspectSymbol]() {
|
|
81
|
-
return this.toString();
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
const ProtoTimeZoneNamed = {
|
|
85
|
-
...ProtoTimeZone,
|
|
86
|
-
_tag: "Named",
|
|
87
|
-
[Hash.symbol]() {
|
|
88
|
-
return Hash.cached(this, Hash.string(`Named:${this.id}`));
|
|
89
|
-
},
|
|
90
|
-
[Equal.symbol](that) {
|
|
91
|
-
return isTimeZone(that) && that._tag === "Named" && this.id === that.id;
|
|
92
|
-
},
|
|
93
|
-
toString() {
|
|
94
|
-
return `TimeZone.Named(${this.id})`;
|
|
95
|
-
},
|
|
96
|
-
toJSON() {
|
|
97
|
-
return {
|
|
98
|
-
_id: "TimeZone",
|
|
99
|
-
_tag: "Named",
|
|
100
|
-
id: this.id
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
const ProtoTimeZoneOffset = {
|
|
105
|
-
...ProtoTimeZone,
|
|
106
|
-
_tag: "Offset",
|
|
107
|
-
[Hash.symbol]() {
|
|
108
|
-
return Hash.cached(this, Hash.string(`Offset:${this.offset}`));
|
|
109
|
-
},
|
|
110
|
-
[Equal.symbol](that) {
|
|
111
|
-
return isTimeZone(that) && that._tag === "Offset" && this.offset === that.offset;
|
|
112
|
-
},
|
|
113
|
-
toString() {
|
|
114
|
-
return `TimeZone.Offset(${offsetToString(this.offset)})`;
|
|
115
|
-
},
|
|
116
|
-
toJSON() {
|
|
117
|
-
return {
|
|
118
|
-
_id: "TimeZone",
|
|
119
|
-
_tag: "Offset",
|
|
120
|
-
offset: this.offset
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
const makeZonedProto = (epochMillis, zone, partsUtc) => {
|
|
125
|
-
const self = Object.create(ProtoZoned);
|
|
126
|
-
self.epochMillis = epochMillis;
|
|
127
|
-
self.zone = zone;
|
|
128
|
-
self.partsUtc = partsUtc;
|
|
129
|
-
return self;
|
|
130
|
-
};
|
|
23
|
+
const TimeZoneTypeId = exports.TimeZoneTypeId = Internal.TimeZoneTypeId;
|
|
131
24
|
// =============================================================================
|
|
132
25
|
// guards
|
|
133
26
|
// =============================================================================
|
|
@@ -135,38 +28,32 @@ const makeZonedProto = (epochMillis, zone, partsUtc) => {
|
|
|
135
28
|
* @since 3.6.0
|
|
136
29
|
* @category guards
|
|
137
30
|
*/
|
|
138
|
-
const isDateTime =
|
|
139
|
-
exports.isDateTime = isDateTime;
|
|
140
|
-
const isDateTimeArgs = args => isDateTime(args[0]);
|
|
31
|
+
const isDateTime = exports.isDateTime = Internal.isDateTime;
|
|
141
32
|
/**
|
|
142
33
|
* @since 3.6.0
|
|
143
34
|
* @category guards
|
|
144
35
|
*/
|
|
145
|
-
const isTimeZone =
|
|
36
|
+
const isTimeZone = exports.isTimeZone = Internal.isTimeZone;
|
|
146
37
|
/**
|
|
147
38
|
* @since 3.6.0
|
|
148
39
|
* @category guards
|
|
149
40
|
*/
|
|
150
|
-
exports.
|
|
151
|
-
const isTimeZoneOffset = u => isTimeZone(u) && u._tag === "Offset";
|
|
41
|
+
const isTimeZoneOffset = exports.isTimeZoneOffset = Internal.isTimeZoneOffset;
|
|
152
42
|
/**
|
|
153
43
|
* @since 3.6.0
|
|
154
44
|
* @category guards
|
|
155
45
|
*/
|
|
156
|
-
exports.
|
|
157
|
-
const isTimeZoneNamed = u => isTimeZone(u) && u._tag === "Named";
|
|
46
|
+
const isTimeZoneNamed = exports.isTimeZoneNamed = Internal.isTimeZoneNamed;
|
|
158
47
|
/**
|
|
159
48
|
* @since 3.6.0
|
|
160
49
|
* @category guards
|
|
161
50
|
*/
|
|
162
|
-
exports.
|
|
163
|
-
const isUtc = self => self._tag === "Utc";
|
|
51
|
+
const isUtc = exports.isUtc = Internal.isUtc;
|
|
164
52
|
/**
|
|
165
53
|
* @since 3.6.0
|
|
166
54
|
* @category guards
|
|
167
55
|
*/
|
|
168
|
-
exports.
|
|
169
|
-
const isZoned = self => self._tag === "Zoned";
|
|
56
|
+
const isZoned = exports.isZoned = Internal.isZoned;
|
|
170
57
|
// =============================================================================
|
|
171
58
|
// instances
|
|
172
59
|
// =============================================================================
|
|
@@ -174,25 +61,19 @@ const isZoned = self => self._tag === "Zoned";
|
|
|
174
61
|
* @since 3.6.0
|
|
175
62
|
* @category instances
|
|
176
63
|
*/
|
|
177
|
-
exports.
|
|
178
|
-
const Equivalence = exports.Equivalence = /*#__PURE__*/Equivalence_.make((a, b) => a.epochMillis === b.epochMillis);
|
|
64
|
+
const Equivalence = exports.Equivalence = Internal.Equivalence;
|
|
179
65
|
/**
|
|
180
66
|
* @since 3.6.0
|
|
181
67
|
* @category instances
|
|
182
68
|
*/
|
|
183
|
-
const Order = exports.Order =
|
|
69
|
+
const Order = exports.Order = Internal.Order;
|
|
184
70
|
/**
|
|
185
71
|
* @since 3.6.0
|
|
186
72
|
*/
|
|
187
|
-
const clamp = exports.clamp =
|
|
73
|
+
const clamp = exports.clamp = Internal.clamp;
|
|
188
74
|
// =============================================================================
|
|
189
75
|
// constructors
|
|
190
76
|
// =============================================================================
|
|
191
|
-
const makeUtc = epochMillis => {
|
|
192
|
-
const self = Object.create(ProtoUtc);
|
|
193
|
-
self.epochMillis = epochMillis;
|
|
194
|
-
return self;
|
|
195
|
-
};
|
|
196
77
|
/**
|
|
197
78
|
* Create a `DateTime` from a `Date`.
|
|
198
79
|
*
|
|
@@ -201,13 +82,7 @@ const makeUtc = epochMillis => {
|
|
|
201
82
|
* @since 3.6.0
|
|
202
83
|
* @category constructors
|
|
203
84
|
*/
|
|
204
|
-
const unsafeFromDate =
|
|
205
|
-
const epochMillis = date.getTime();
|
|
206
|
-
if (Number.isNaN(epochMillis)) {
|
|
207
|
-
throw new _Cause.IllegalArgumentException("Invalid date");
|
|
208
|
-
}
|
|
209
|
-
return makeUtc(epochMillis);
|
|
210
|
-
};
|
|
85
|
+
const unsafeFromDate = exports.unsafeFromDate = Internal.unsafeFromDate;
|
|
211
86
|
/**
|
|
212
87
|
* Create a `DateTime` from one of the following:
|
|
213
88
|
*
|
|
@@ -233,19 +108,7 @@ const unsafeFromDate = date => {
|
|
|
233
108
|
* DateTime.unsafeMake("2024-01-01")
|
|
234
109
|
* ```
|
|
235
110
|
*/
|
|
236
|
-
exports.
|
|
237
|
-
const unsafeMake = input => {
|
|
238
|
-
if (isDateTime(input)) {
|
|
239
|
-
return input;
|
|
240
|
-
} else if (input instanceof Date) {
|
|
241
|
-
return unsafeFromDate(input);
|
|
242
|
-
} else if (typeof input === "object") {
|
|
243
|
-
const date = new Date(0);
|
|
244
|
-
setPartsDate(date, input);
|
|
245
|
-
return unsafeFromDate(date);
|
|
246
|
-
}
|
|
247
|
-
return unsafeFromDate(new Date(input));
|
|
248
|
-
};
|
|
111
|
+
const unsafeMake = exports.unsafeMake = Internal.unsafeMake;
|
|
249
112
|
/**
|
|
250
113
|
* Create a `DateTime.Zoned` using `DateTime.unsafeMake` and a time zone.
|
|
251
114
|
*
|
|
@@ -262,32 +125,7 @@ const unsafeMake = input => {
|
|
|
262
125
|
* DateTime.unsafeMakeZoned(new Date(), { timeZone: "Europe/London" })
|
|
263
126
|
* ```
|
|
264
127
|
*/
|
|
265
|
-
exports.
|
|
266
|
-
const unsafeMakeZoned = (input, options) => {
|
|
267
|
-
if (options?.timeZone === undefined && isDateTime(input) && isZoned(input)) {
|
|
268
|
-
return input;
|
|
269
|
-
}
|
|
270
|
-
const self = unsafeMake(input);
|
|
271
|
-
let zone;
|
|
272
|
-
if (options?.timeZone === undefined) {
|
|
273
|
-
const offset = new Date(self.epochMillis).getTimezoneOffset() * -60 * 1000;
|
|
274
|
-
zone = zoneMakeOffset(offset);
|
|
275
|
-
} else if (isTimeZone(options?.timeZone)) {
|
|
276
|
-
zone = options.timeZone;
|
|
277
|
-
} else if (typeof options?.timeZone === "number") {
|
|
278
|
-
zone = zoneMakeOffset(options.timeZone);
|
|
279
|
-
} else {
|
|
280
|
-
const parsedZone = zoneFromString(options.timeZone);
|
|
281
|
-
if (Option.isNone(parsedZone)) {
|
|
282
|
-
throw new _Cause.IllegalArgumentException(`Invalid time zone: ${options.timeZone}`);
|
|
283
|
-
}
|
|
284
|
-
zone = parsedZone.value;
|
|
285
|
-
}
|
|
286
|
-
if (options?.adjustForTimeZone !== true) {
|
|
287
|
-
return makeZonedProto(self.epochMillis, zone, self.partsUtc);
|
|
288
|
-
}
|
|
289
|
-
return makeZonedFromAdjusted(self.epochMillis, zone);
|
|
290
|
-
};
|
|
128
|
+
const unsafeMakeZoned = exports.unsafeMakeZoned = Internal.unsafeMakeZoned;
|
|
291
129
|
/**
|
|
292
130
|
* Create a `DateTime.Zoned` using `DateTime.make` and a time zone.
|
|
293
131
|
*
|
|
@@ -304,8 +142,7 @@ const unsafeMakeZoned = (input, options) => {
|
|
|
304
142
|
* DateTime.makeZoned(new Date(), { timeZone: "Europe/London" })
|
|
305
143
|
* ```
|
|
306
144
|
*/
|
|
307
|
-
exports.
|
|
308
|
-
const makeZoned = exports.makeZoned = /*#__PURE__*/Option.liftThrowable(unsafeMakeZoned);
|
|
145
|
+
const makeZoned = exports.makeZoned = Internal.makeZoned;
|
|
309
146
|
/**
|
|
310
147
|
* Create a `DateTime` from one of the following:
|
|
311
148
|
*
|
|
@@ -333,8 +170,7 @@ const makeZoned = exports.makeZoned = /*#__PURE__*/Option.liftThrowable(unsafeMa
|
|
|
333
170
|
* DateTime.make("2024-01-01")
|
|
334
171
|
* ```
|
|
335
172
|
*/
|
|
336
|
-
const make = exports.make =
|
|
337
|
-
const zonedStringRegex = /^(.{17,35})\[(.+)\]$/;
|
|
173
|
+
const make = exports.make = Internal.make;
|
|
338
174
|
/**
|
|
339
175
|
* Create a `DateTime.Zoned` from a string.
|
|
340
176
|
*
|
|
@@ -343,19 +179,7 @@ const zonedStringRegex = /^(.{17,35})\[(.+)\]$/;
|
|
|
343
179
|
* @since 3.6.0
|
|
344
180
|
* @category constructors
|
|
345
181
|
*/
|
|
346
|
-
const makeZonedFromString =
|
|
347
|
-
const match = zonedStringRegex.exec(input);
|
|
348
|
-
if (match === null) {
|
|
349
|
-
const offset = parseOffset(input);
|
|
350
|
-
return offset !== null ? makeZoned(input, {
|
|
351
|
-
timeZone: offset
|
|
352
|
-
}) : Option.none();
|
|
353
|
-
}
|
|
354
|
-
const [, isoString, timeZone] = match;
|
|
355
|
-
return makeZoned(isoString, {
|
|
356
|
-
timeZone
|
|
357
|
-
});
|
|
358
|
-
};
|
|
182
|
+
const makeZonedFromString = exports.makeZonedFromString = Internal.makeZonedFromString;
|
|
359
183
|
/**
|
|
360
184
|
* Get the current time using the `Clock` service and convert it to a `DateTime`.
|
|
361
185
|
*
|
|
@@ -370,15 +194,14 @@ const makeZonedFromString = input => {
|
|
|
370
194
|
* })
|
|
371
195
|
* ```
|
|
372
196
|
*/
|
|
373
|
-
exports.
|
|
374
|
-
const now = exports.now = /*#__PURE__*/Effect.map(Clock.currentTimeMillis, makeUtc);
|
|
197
|
+
const now = exports.now = Internal.now;
|
|
375
198
|
/**
|
|
376
199
|
* Get the current time using `Date.now`.
|
|
377
200
|
*
|
|
378
201
|
* @since 3.6.0
|
|
379
202
|
* @category constructors
|
|
380
203
|
*/
|
|
381
|
-
const unsafeNow =
|
|
204
|
+
const unsafeNow = exports.unsafeNow = Internal.unsafeNow;
|
|
382
205
|
// =============================================================================
|
|
383
206
|
// time zones
|
|
384
207
|
// =============================================================================
|
|
@@ -400,8 +223,7 @@ const unsafeNow = () => makeUtc(Date.now());
|
|
|
400
223
|
* })
|
|
401
224
|
* ```
|
|
402
225
|
*/
|
|
403
|
-
exports.
|
|
404
|
-
const setZone = exports.setZone = /*#__PURE__*/(0, _Function.dual)(isDateTimeArgs, (self, zone, options) => options?.adjustForTimeZone === true ? makeZonedFromAdjusted(self.epochMillis, zone) : makeZonedProto(self.epochMillis, zone, self.partsUtc));
|
|
226
|
+
const setZone = exports.setZone = Internal.setZone;
|
|
405
227
|
/**
|
|
406
228
|
* Add a fixed offset time zone to a `DateTime`.
|
|
407
229
|
*
|
|
@@ -421,30 +243,7 @@ const setZone = exports.setZone = /*#__PURE__*/(0, _Function.dual)(isDateTimeArg
|
|
|
421
243
|
* })
|
|
422
244
|
* ```
|
|
423
245
|
*/
|
|
424
|
-
const setZoneOffset = exports.setZoneOffset =
|
|
425
|
-
const validZoneCache = /*#__PURE__*/(0, _GlobalValue.globalValue)("effect/DateTime/validZoneCache", () => new Map());
|
|
426
|
-
const formatOptions = {
|
|
427
|
-
day: "numeric",
|
|
428
|
-
month: "numeric",
|
|
429
|
-
year: "numeric",
|
|
430
|
-
hour: "numeric",
|
|
431
|
-
minute: "numeric",
|
|
432
|
-
second: "numeric",
|
|
433
|
-
timeZoneName: "longOffset",
|
|
434
|
-
fractionalSecondDigits: 3,
|
|
435
|
-
hourCycle: "h23"
|
|
436
|
-
};
|
|
437
|
-
const zoneMakeIntl = format => {
|
|
438
|
-
const zoneId = format.resolvedOptions().timeZone;
|
|
439
|
-
if (validZoneCache.has(zoneId)) {
|
|
440
|
-
return validZoneCache.get(zoneId);
|
|
441
|
-
}
|
|
442
|
-
const zone = Object.create(ProtoTimeZoneNamed);
|
|
443
|
-
zone.id = zoneId;
|
|
444
|
-
zone.format = format;
|
|
445
|
-
validZoneCache.set(zoneId, zone);
|
|
446
|
-
return zone;
|
|
447
|
-
};
|
|
246
|
+
const setZoneOffset = exports.setZoneOffset = Internal.setZoneOffset;
|
|
448
247
|
/**
|
|
449
248
|
* Attempt to create a named time zone from a IANA time zone identifier.
|
|
450
249
|
*
|
|
@@ -453,31 +252,14 @@ const zoneMakeIntl = format => {
|
|
|
453
252
|
* @since 3.6.0
|
|
454
253
|
* @category time zones
|
|
455
254
|
*/
|
|
456
|
-
const zoneUnsafeMakeNamed =
|
|
457
|
-
if (validZoneCache.has(zoneId)) {
|
|
458
|
-
return validZoneCache.get(zoneId);
|
|
459
|
-
}
|
|
460
|
-
try {
|
|
461
|
-
return zoneMakeIntl(new Intl.DateTimeFormat("en-US", {
|
|
462
|
-
...formatOptions,
|
|
463
|
-
timeZone: zoneId
|
|
464
|
-
}));
|
|
465
|
-
} catch (_) {
|
|
466
|
-
throw new _Cause.IllegalArgumentException(`Invalid time zone: ${zoneId}`);
|
|
467
|
-
}
|
|
468
|
-
};
|
|
255
|
+
const zoneUnsafeMakeNamed = exports.zoneUnsafeMakeNamed = Internal.zoneUnsafeMakeNamed;
|
|
469
256
|
/**
|
|
470
257
|
* Create a fixed offset time zone.
|
|
471
258
|
*
|
|
472
259
|
* @since 3.6.0
|
|
473
260
|
* @category time zones
|
|
474
261
|
*/
|
|
475
|
-
exports.
|
|
476
|
-
const zoneMakeOffset = offset => {
|
|
477
|
-
const zone = Object.create(ProtoTimeZoneOffset);
|
|
478
|
-
zone.offset = offset;
|
|
479
|
-
return zone;
|
|
480
|
-
};
|
|
262
|
+
const zoneMakeOffset = exports.zoneMakeOffset = Internal.zoneMakeOffset;
|
|
481
263
|
/**
|
|
482
264
|
* Create a named time zone from a IANA time zone identifier. If the time zone
|
|
483
265
|
* is invalid, `None` will be returned.
|
|
@@ -485,8 +267,7 @@ const zoneMakeOffset = offset => {
|
|
|
485
267
|
* @since 3.6.0
|
|
486
268
|
* @category time zones
|
|
487
269
|
*/
|
|
488
|
-
exports.
|
|
489
|
-
const zoneMakeNamed = exports.zoneMakeNamed = /*#__PURE__*/Option.liftThrowable(zoneUnsafeMakeNamed);
|
|
270
|
+
const zoneMakeNamed = exports.zoneMakeNamed = Internal.zoneMakeNamed;
|
|
490
271
|
/**
|
|
491
272
|
* Create a named time zone from a IANA time zone identifier. If the time zone
|
|
492
273
|
* is invalid, it will fail with an `IllegalArgumentException`.
|
|
@@ -494,33 +275,21 @@ const zoneMakeNamed = exports.zoneMakeNamed = /*#__PURE__*/Option.liftThrowable(
|
|
|
494
275
|
* @since 3.6.0
|
|
495
276
|
* @category time zones
|
|
496
277
|
*/
|
|
497
|
-
const zoneMakeNamedEffect =
|
|
498
|
-
try: () => zoneUnsafeMakeNamed(zoneId),
|
|
499
|
-
catch: e => e
|
|
500
|
-
});
|
|
278
|
+
const zoneMakeNamedEffect = exports.zoneMakeNamedEffect = Internal.zoneMakeNamedEffect;
|
|
501
279
|
/**
|
|
502
280
|
* Create a named time zone from the system's local time zone.
|
|
503
281
|
*
|
|
504
282
|
* @since 3.6.0
|
|
505
283
|
* @category time zones
|
|
506
284
|
*/
|
|
507
|
-
exports.
|
|
508
|
-
const zoneMakeLocal = () => zoneMakeIntl(new Intl.DateTimeFormat("en-US", formatOptions));
|
|
509
|
-
exports.zoneMakeLocal = zoneMakeLocal;
|
|
510
|
-
const offsetZoneRegex = /^(?:GMT|[+-])/;
|
|
285
|
+
const zoneMakeLocal = exports.zoneMakeLocal = Internal.zoneMakeLocal;
|
|
511
286
|
/**
|
|
512
287
|
* Try parse a TimeZone from a string
|
|
513
288
|
*
|
|
514
289
|
* @since 3.6.0
|
|
515
290
|
* @category time zones
|
|
516
291
|
*/
|
|
517
|
-
const zoneFromString =
|
|
518
|
-
if (offsetZoneRegex.test(zone)) {
|
|
519
|
-
const offset = parseOffset(zone);
|
|
520
|
-
return offset === null ? Option.none() : Option.some(zoneMakeOffset(offset));
|
|
521
|
-
}
|
|
522
|
-
return zoneMakeNamed(zone);
|
|
523
|
-
};
|
|
292
|
+
const zoneFromString = exports.zoneFromString = Internal.zoneFromString;
|
|
524
293
|
/**
|
|
525
294
|
* Format a `TimeZone` as a string.
|
|
526
295
|
*
|
|
@@ -537,13 +306,7 @@ const zoneFromString = zone => {
|
|
|
537
306
|
* DateTime.zoneToString(DateTime.zoneUnsafeMakeNamed("Europe/London"))
|
|
538
307
|
* ```
|
|
539
308
|
*/
|
|
540
|
-
exports.
|
|
541
|
-
const zoneToString = self => {
|
|
542
|
-
if (self._tag === "Offset") {
|
|
543
|
-
return offsetToString(self.offset);
|
|
544
|
-
}
|
|
545
|
-
return self.id;
|
|
546
|
-
};
|
|
309
|
+
const zoneToString = exports.zoneToString = Internal.zoneToString;
|
|
547
310
|
/**
|
|
548
311
|
* Set the time zone of a `DateTime` from an IANA time zone identifier. If the
|
|
549
312
|
* time zone is invalid, `None` will be returned.
|
|
@@ -561,8 +324,7 @@ const zoneToString = self => {
|
|
|
561
324
|
* })
|
|
562
325
|
* ```
|
|
563
326
|
*/
|
|
564
|
-
exports.
|
|
565
|
-
const setZoneNamed = exports.setZoneNamed = /*#__PURE__*/(0, _Function.dual)(isDateTimeArgs, (self, zoneId, options) => Option.map(zoneMakeNamed(zoneId), zone => setZone(self, zone, options)));
|
|
327
|
+
const setZoneNamed = exports.setZoneNamed = Internal.setZoneNamed;
|
|
566
328
|
/**
|
|
567
329
|
* Set the time zone of a `DateTime` from an IANA time zone identifier. If the
|
|
568
330
|
* time zone is invalid, an `IllegalArgumentException` will be thrown.
|
|
@@ -580,7 +342,7 @@ const setZoneNamed = exports.setZoneNamed = /*#__PURE__*/(0, _Function.dual)(isD
|
|
|
580
342
|
* })
|
|
581
343
|
* ```
|
|
582
344
|
*/
|
|
583
|
-
const unsafeSetZoneNamed = exports.unsafeSetZoneNamed =
|
|
345
|
+
const unsafeSetZoneNamed = exports.unsafeSetZoneNamed = Internal.unsafeSetZoneNamed;
|
|
584
346
|
// =============================================================================
|
|
585
347
|
// comparisons
|
|
586
348
|
// =============================================================================
|
|
@@ -605,7 +367,7 @@ const unsafeSetZoneNamed = exports.unsafeSetZoneNamed = /*#__PURE__*/(0, _Functi
|
|
|
605
367
|
* })
|
|
606
368
|
* ```
|
|
607
369
|
*/
|
|
608
|
-
const distance = exports.distance =
|
|
370
|
+
const distance = exports.distance = Internal.distance;
|
|
609
371
|
/**
|
|
610
372
|
* Calulate the difference between two `DateTime` values.
|
|
611
373
|
*
|
|
@@ -633,10 +395,7 @@ const distance = exports.distance = /*#__PURE__*/(0, _Function.dual)(2, (self, o
|
|
|
633
395
|
* })
|
|
634
396
|
* ```
|
|
635
397
|
*/
|
|
636
|
-
const distanceDurationEither = exports.distanceDurationEither =
|
|
637
|
-
const diffMillis = distance(self, other);
|
|
638
|
-
return diffMillis > 0 ? Either.right(Duration.millis(diffMillis)) : Either.left(Duration.millis(-diffMillis));
|
|
639
|
-
});
|
|
398
|
+
const distanceDurationEither = exports.distanceDurationEither = Internal.distanceDurationEither;
|
|
640
399
|
/**
|
|
641
400
|
* Calulate the distance between two `DateTime` values.
|
|
642
401
|
*
|
|
@@ -655,65 +414,62 @@ const distanceDurationEither = exports.distanceDurationEither = /*#__PURE__*/(0,
|
|
|
655
414
|
* })
|
|
656
415
|
* ```
|
|
657
416
|
*/
|
|
658
|
-
const distanceDuration = exports.distanceDuration =
|
|
417
|
+
const distanceDuration = exports.distanceDuration = Internal.distanceDuration;
|
|
659
418
|
/**
|
|
660
419
|
* @since 3.6.0
|
|
661
420
|
* @category comparisons
|
|
662
421
|
*/
|
|
663
|
-
const min = exports.min =
|
|
422
|
+
const min = exports.min = Internal.min;
|
|
664
423
|
/**
|
|
665
424
|
* @since 3.6.0
|
|
666
425
|
* @category comparisons
|
|
667
426
|
*/
|
|
668
|
-
const max = exports.max =
|
|
427
|
+
const max = exports.max = Internal.max;
|
|
669
428
|
/**
|
|
670
429
|
* @since 3.6.0
|
|
671
430
|
* @category comparisons
|
|
672
431
|
*/
|
|
673
|
-
const greaterThan = exports.greaterThan =
|
|
432
|
+
const greaterThan = exports.greaterThan = Internal.greaterThan;
|
|
674
433
|
/**
|
|
675
434
|
* @since 3.6.0
|
|
676
435
|
* @category comparisons
|
|
677
436
|
*/
|
|
678
|
-
const greaterThanOrEqualTo = exports.greaterThanOrEqualTo =
|
|
437
|
+
const greaterThanOrEqualTo = exports.greaterThanOrEqualTo = Internal.greaterThanOrEqualTo;
|
|
679
438
|
/**
|
|
680
439
|
* @since 3.6.0
|
|
681
440
|
* @category comparisons
|
|
682
441
|
*/
|
|
683
|
-
const lessThan = exports.lessThan =
|
|
442
|
+
const lessThan = exports.lessThan = Internal.lessThan;
|
|
684
443
|
/**
|
|
685
444
|
* @since 3.6.0
|
|
686
445
|
* @category comparisons
|
|
687
446
|
*/
|
|
688
|
-
const lessThanOrEqualTo = exports.lessThanOrEqualTo =
|
|
447
|
+
const lessThanOrEqualTo = exports.lessThanOrEqualTo = Internal.lessThanOrEqualTo;
|
|
689
448
|
/**
|
|
690
449
|
* @since 3.6.0
|
|
691
450
|
* @category comparisons
|
|
692
451
|
*/
|
|
693
|
-
const between = exports.between =
|
|
452
|
+
const between = exports.between = Internal.between;
|
|
694
453
|
/**
|
|
695
454
|
* @since 3.6.0
|
|
696
455
|
* @category comparisons
|
|
697
456
|
*/
|
|
698
|
-
const isFuture =
|
|
457
|
+
const isFuture = exports.isFuture = Internal.isFuture;
|
|
699
458
|
/**
|
|
700
459
|
* @since 3.6.0
|
|
701
460
|
* @category comparisons
|
|
702
461
|
*/
|
|
703
|
-
exports.
|
|
704
|
-
const unsafeIsFuture = self => lessThan(unsafeNow(), self);
|
|
462
|
+
const unsafeIsFuture = exports.unsafeIsFuture = Internal.unsafeIsFuture;
|
|
705
463
|
/**
|
|
706
464
|
* @since 3.6.0
|
|
707
465
|
* @category comparisons
|
|
708
466
|
*/
|
|
709
|
-
exports.
|
|
710
|
-
const isPast = self => Effect.map(now, greaterThan(self));
|
|
467
|
+
const isPast = exports.isPast = Internal.isPast;
|
|
711
468
|
/**
|
|
712
469
|
* @since 3.6.0
|
|
713
470
|
* @category comparisons
|
|
714
471
|
*/
|
|
715
|
-
exports.
|
|
716
|
-
const unsafeIsPast = self => greaterThan(unsafeNow(), self);
|
|
472
|
+
const unsafeIsPast = exports.unsafeIsPast = Internal.unsafeIsPast;
|
|
717
473
|
// =============================================================================
|
|
718
474
|
// conversions
|
|
719
475
|
// =============================================================================
|
|
@@ -723,48 +479,21 @@ const unsafeIsPast = self => greaterThan(unsafeNow(), self);
|
|
|
723
479
|
* @since 3.6.0
|
|
724
480
|
* @category conversions
|
|
725
481
|
*/
|
|
726
|
-
exports.
|
|
727
|
-
const toDateUtc = self => new Date(self.epochMillis);
|
|
482
|
+
const toDateUtc = exports.toDateUtc = Internal.toDateUtc;
|
|
728
483
|
/**
|
|
729
484
|
* Convert a `DateTime` to a `Date`, applying the time zone first.
|
|
730
485
|
*
|
|
731
486
|
* @since 3.6.0
|
|
732
487
|
* @category conversions
|
|
733
488
|
*/
|
|
734
|
-
exports.
|
|
735
|
-
const toDate = self => {
|
|
736
|
-
if (self._tag === "Utc") {
|
|
737
|
-
return new Date(self.epochMillis);
|
|
738
|
-
} else if (self.zone._tag === "Offset") {
|
|
739
|
-
return new Date(self.epochMillis + self.zone.offset);
|
|
740
|
-
} else if (self.adjustedEpochMillis !== undefined) {
|
|
741
|
-
return new Date(self.adjustedEpochMillis);
|
|
742
|
-
}
|
|
743
|
-
const parts = self.zone.format.formatToParts(self.epochMillis).filter(_ => _.type !== "literal");
|
|
744
|
-
const date = new Date(0);
|
|
745
|
-
date.setUTCFullYear(Number(parts[2].value), Number(parts[0].value) - 1, Number(parts[1].value));
|
|
746
|
-
date.setUTCHours(Number(parts[3].value), Number(parts[4].value), Number(parts[5].value), Number(parts[6].value));
|
|
747
|
-
self.adjustedEpochMillis = date.getTime();
|
|
748
|
-
return date;
|
|
749
|
-
};
|
|
489
|
+
const toDate = exports.toDate = Internal.toDate;
|
|
750
490
|
/**
|
|
751
491
|
* Calculate the time zone offset of a `DateTime.Zoned` in milliseconds.
|
|
752
492
|
*
|
|
753
493
|
* @since 3.6.0
|
|
754
494
|
* @category conversions
|
|
755
495
|
*/
|
|
756
|
-
exports.
|
|
757
|
-
const zonedOffset = self => {
|
|
758
|
-
const date = toDate(self);
|
|
759
|
-
return date.getTime() - toEpochMillis(self);
|
|
760
|
-
};
|
|
761
|
-
exports.zonedOffset = zonedOffset;
|
|
762
|
-
const offsetToString = offset => {
|
|
763
|
-
const abs = Math.abs(offset);
|
|
764
|
-
const hours = Math.floor(abs / (60 * 60 * 1000));
|
|
765
|
-
const minutes = Math.round(abs % (60 * 60 * 1000) / (60 * 1000));
|
|
766
|
-
return `${offset < 0 ? "-" : "+"}${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
|
|
767
|
-
};
|
|
496
|
+
const zonedOffset = exports.zonedOffset = Internal.zonedOffset;
|
|
768
497
|
/**
|
|
769
498
|
* Calculate the time zone offset of a `DateTime` in milliseconds.
|
|
770
499
|
*
|
|
@@ -773,15 +502,14 @@ const offsetToString = offset => {
|
|
|
773
502
|
* @since 3.6.0
|
|
774
503
|
* @category conversions
|
|
775
504
|
*/
|
|
776
|
-
const zonedOffsetIso =
|
|
505
|
+
const zonedOffsetIso = exports.zonedOffsetIso = Internal.zonedOffsetIso;
|
|
777
506
|
/**
|
|
778
507
|
* Get the milliseconds since the Unix epoch of a `DateTime`.
|
|
779
508
|
*
|
|
780
509
|
* @since 3.6.0
|
|
781
510
|
* @category conversions
|
|
782
511
|
*/
|
|
783
|
-
exports.
|
|
784
|
-
const toEpochMillis = self => self.epochMillis;
|
|
512
|
+
const toEpochMillis = exports.toEpochMillis = Internal.toEpochMillis;
|
|
785
513
|
/**
|
|
786
514
|
* Remove the time aspect of a `DateTime`, first adjusting for the time
|
|
787
515
|
* zone. It will return a `DateTime.Utc` only containing the date.
|
|
@@ -802,25 +530,10 @@ const toEpochMillis = self => self.epochMillis;
|
|
|
802
530
|
* )
|
|
803
531
|
* ```
|
|
804
532
|
*/
|
|
805
|
-
exports.
|
|
806
|
-
const removeTime = self => withDate(self, date => {
|
|
807
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
808
|
-
return makeUtc(date.getTime());
|
|
809
|
-
});
|
|
533
|
+
const removeTime = exports.removeTime = Internal.removeTime;
|
|
810
534
|
// =============================================================================
|
|
811
535
|
// parts
|
|
812
536
|
// =============================================================================
|
|
813
|
-
exports.removeTime = removeTime;
|
|
814
|
-
const dateToParts = date => ({
|
|
815
|
-
millis: date.getUTCMilliseconds(),
|
|
816
|
-
seconds: date.getUTCSeconds(),
|
|
817
|
-
minutes: date.getUTCMinutes(),
|
|
818
|
-
hours: date.getUTCHours(),
|
|
819
|
-
day: date.getUTCDate(),
|
|
820
|
-
weekDay: date.getUTCDay(),
|
|
821
|
-
month: date.getUTCMonth() + 1,
|
|
822
|
-
year: date.getUTCFullYear()
|
|
823
|
-
});
|
|
824
537
|
/**
|
|
825
538
|
* Get the different parts of a `DateTime` as an object.
|
|
826
539
|
*
|
|
@@ -829,15 +542,7 @@ const dateToParts = date => ({
|
|
|
829
542
|
* @since 3.6.0
|
|
830
543
|
* @category parts
|
|
831
544
|
*/
|
|
832
|
-
const toParts =
|
|
833
|
-
if (self._tag === "Utc") {
|
|
834
|
-
return toPartsUtc(self);
|
|
835
|
-
} else if (self.partsAdjusted !== undefined) {
|
|
836
|
-
return self.partsAdjusted;
|
|
837
|
-
}
|
|
838
|
-
self.partsAdjusted = withDate(self, dateToParts);
|
|
839
|
-
return self.partsAdjusted;
|
|
840
|
-
};
|
|
545
|
+
const toParts = exports.toParts = Internal.toParts;
|
|
841
546
|
/**
|
|
842
547
|
* Get the different parts of a `DateTime` as an object.
|
|
843
548
|
*
|
|
@@ -846,14 +551,7 @@ const toParts = self => {
|
|
|
846
551
|
* @since 3.6.0
|
|
847
552
|
* @category parts
|
|
848
553
|
*/
|
|
849
|
-
exports.
|
|
850
|
-
const toPartsUtc = self => {
|
|
851
|
-
if (self.partsUtc !== undefined) {
|
|
852
|
-
return self.partsUtc;
|
|
853
|
-
}
|
|
854
|
-
self.partsUtc = withDateUtc(self, dateToParts);
|
|
855
|
-
return self.partsUtc;
|
|
856
|
-
};
|
|
554
|
+
const toPartsUtc = exports.toPartsUtc = Internal.toPartsUtc;
|
|
857
555
|
/**
|
|
858
556
|
* Get a part of a `DateTime` as a number.
|
|
859
557
|
*
|
|
@@ -870,8 +568,7 @@ const toPartsUtc = self => {
|
|
|
870
568
|
* assert.strictEqual(year, 2024)
|
|
871
569
|
* ```
|
|
872
570
|
*/
|
|
873
|
-
exports.
|
|
874
|
-
const getPartUtc = exports.getPartUtc = /*#__PURE__*/(0, _Function.dual)(2, (self, part) => toPartsUtc(self)[part]);
|
|
571
|
+
const getPartUtc = exports.getPartUtc = Internal.getPartUtc;
|
|
875
572
|
/**
|
|
876
573
|
* Get a part of a `DateTime` as a number.
|
|
877
574
|
*
|
|
@@ -888,34 +585,7 @@ const getPartUtc = exports.getPartUtc = /*#__PURE__*/(0, _Function.dual)(2, (sel
|
|
|
888
585
|
* assert.strictEqual(year, 2024)
|
|
889
586
|
* ```
|
|
890
587
|
*/
|
|
891
|
-
const getPart = exports.getPart =
|
|
892
|
-
const setPartsDate = (date, parts) => {
|
|
893
|
-
if (parts.year !== undefined) {
|
|
894
|
-
date.setUTCFullYear(parts.year);
|
|
895
|
-
}
|
|
896
|
-
if (parts.month !== undefined) {
|
|
897
|
-
date.setUTCMonth(parts.month - 1);
|
|
898
|
-
}
|
|
899
|
-
if (parts.day !== undefined) {
|
|
900
|
-
date.setUTCDate(parts.day);
|
|
901
|
-
}
|
|
902
|
-
if (parts.weekDay !== undefined) {
|
|
903
|
-
const diff = parts.weekDay - date.getUTCDay();
|
|
904
|
-
date.setUTCDate(date.getUTCDate() + diff);
|
|
905
|
-
}
|
|
906
|
-
if (parts.hours !== undefined) {
|
|
907
|
-
date.setUTCHours(parts.hours);
|
|
908
|
-
}
|
|
909
|
-
if (parts.minutes !== undefined) {
|
|
910
|
-
date.setUTCMinutes(parts.minutes);
|
|
911
|
-
}
|
|
912
|
-
if (parts.seconds !== undefined) {
|
|
913
|
-
date.setUTCSeconds(parts.seconds);
|
|
914
|
-
}
|
|
915
|
-
if (parts.millis !== undefined) {
|
|
916
|
-
date.setUTCMilliseconds(parts.millis);
|
|
917
|
-
}
|
|
918
|
-
};
|
|
588
|
+
const getPart = exports.getPart = Internal.getPart;
|
|
919
589
|
/**
|
|
920
590
|
* Set the different parts of a `DateTime` as an object.
|
|
921
591
|
*
|
|
@@ -924,21 +594,21 @@ const setPartsDate = (date, parts) => {
|
|
|
924
594
|
* @since 3.6.0
|
|
925
595
|
* @category parts
|
|
926
596
|
*/
|
|
927
|
-
const setParts = exports.setParts =
|
|
597
|
+
const setParts = exports.setParts = Internal.setParts;
|
|
928
598
|
/**
|
|
929
599
|
* Set the different parts of a `DateTime` as an object.
|
|
930
600
|
*
|
|
931
601
|
* @since 3.6.0
|
|
932
602
|
* @category parts
|
|
933
603
|
*/
|
|
934
|
-
const setPartsUtc = exports.setPartsUtc =
|
|
604
|
+
const setPartsUtc = exports.setPartsUtc = Internal.setPartsUtc;
|
|
935
605
|
// =============================================================================
|
|
936
606
|
// current time zone
|
|
937
607
|
// =============================================================================
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
*/
|
|
608
|
+
// =============================================================================
|
|
609
|
+
// current time zone
|
|
610
|
+
// =============================================================================
|
|
611
|
+
/** @internal */
|
|
942
612
|
class CurrentTimeZone extends /*#__PURE__*/Context.Tag("effect/DateTime/CurrentTimeZone")() {}
|
|
943
613
|
/**
|
|
944
614
|
* Set the time zone of a `DateTime` to the current time zone, which is
|
|
@@ -1047,65 +717,9 @@ const withCurrentZoneNamed = exports.withCurrentZoneNamed = /*#__PURE__*/(0, _Fu
|
|
|
1047
717
|
* ```
|
|
1048
718
|
*/
|
|
1049
719
|
const nowInCurrentZone = exports.nowInCurrentZone = /*#__PURE__*/Effect.flatMap(now, setZoneCurrent);
|
|
1050
|
-
/**
|
|
1051
|
-
* Create a Layer from the given time zone.
|
|
1052
|
-
*
|
|
1053
|
-
* @since 3.6.0
|
|
1054
|
-
* @category current time zone
|
|
1055
|
-
*/
|
|
1056
|
-
const layerCurrentZone = zone => Layer.succeed(CurrentTimeZone, zone);
|
|
1057
|
-
/**
|
|
1058
|
-
* Create a Layer from the given time zone offset.
|
|
1059
|
-
*
|
|
1060
|
-
* @since 3.6.0
|
|
1061
|
-
* @category current time zone
|
|
1062
|
-
*/
|
|
1063
|
-
exports.layerCurrentZone = layerCurrentZone;
|
|
1064
|
-
const layerCurrentZoneOffset = offset => Layer.succeed(CurrentTimeZone, zoneMakeOffset(offset));
|
|
1065
|
-
/**
|
|
1066
|
-
* Create a Layer from the given IANA time zone identifier.
|
|
1067
|
-
*
|
|
1068
|
-
* @since 3.6.0
|
|
1069
|
-
* @category current time zone
|
|
1070
|
-
*/
|
|
1071
|
-
exports.layerCurrentZoneOffset = layerCurrentZoneOffset;
|
|
1072
|
-
const layerCurrentZoneNamed = zoneId => Layer.effect(CurrentTimeZone, zoneMakeNamedEffect(zoneId));
|
|
1073
|
-
/**
|
|
1074
|
-
* Create a Layer from the systems local time zone.
|
|
1075
|
-
*
|
|
1076
|
-
* @since 3.6.0
|
|
1077
|
-
* @category current time zone
|
|
1078
|
-
*/
|
|
1079
|
-
exports.layerCurrentZoneNamed = layerCurrentZoneNamed;
|
|
1080
|
-
const layerCurrentZoneLocal = exports.layerCurrentZoneLocal = /*#__PURE__*/Layer.sync(CurrentTimeZone, zoneMakeLocal);
|
|
1081
720
|
// =============================================================================
|
|
1082
721
|
// mapping
|
|
1083
722
|
// =============================================================================
|
|
1084
|
-
const makeZonedFromAdjusted = (adjustedMillis, zone) => {
|
|
1085
|
-
const offset = zone._tag === "Offset" ? zone.offset : calculateNamedOffset(adjustedMillis, zone);
|
|
1086
|
-
return makeZonedProto(adjustedMillis - offset, zone);
|
|
1087
|
-
};
|
|
1088
|
-
const offsetRegex = /([+-])(\d{2}):(\d{2})$/;
|
|
1089
|
-
const parseOffset = offset => {
|
|
1090
|
-
const match = offsetRegex.exec(offset);
|
|
1091
|
-
if (match === null) {
|
|
1092
|
-
return null;
|
|
1093
|
-
}
|
|
1094
|
-
const [, sign, hours, minutes] = match;
|
|
1095
|
-
return (sign === "+" ? 1 : -1) * (Number(hours) * 60 + Number(minutes)) * 60 * 1000;
|
|
1096
|
-
};
|
|
1097
|
-
const calculateNamedOffset = (adjustedMillis, zone) => {
|
|
1098
|
-
const offset = zone.format.formatToParts(adjustedMillis).find(_ => _.type === "timeZoneName")?.value ?? "";
|
|
1099
|
-
if (offset === "GMT") {
|
|
1100
|
-
return 0;
|
|
1101
|
-
}
|
|
1102
|
-
const result = parseOffset(offset);
|
|
1103
|
-
if (result === null) {
|
|
1104
|
-
// fallback to using the adjusted date
|
|
1105
|
-
return zonedOffset(makeZonedProto(adjustedMillis, zone));
|
|
1106
|
-
}
|
|
1107
|
-
return result;
|
|
1108
|
-
};
|
|
1109
723
|
/**
|
|
1110
724
|
* Modify a `DateTime` by applying a function to a cloned `Date` instance.
|
|
1111
725
|
*
|
|
@@ -1115,28 +729,14 @@ const calculateNamedOffset = (adjustedMillis, zone) => {
|
|
|
1115
729
|
* @since 3.6.0
|
|
1116
730
|
* @category mapping
|
|
1117
731
|
*/
|
|
1118
|
-
const mutate = exports.mutate =
|
|
1119
|
-
if (self._tag === "Utc") {
|
|
1120
|
-
const date = toDateUtc(self);
|
|
1121
|
-
f(date);
|
|
1122
|
-
return makeUtc(date.getTime());
|
|
1123
|
-
}
|
|
1124
|
-
const adjustedDate = toDate(self);
|
|
1125
|
-
const newAdjustedDate = new Date(adjustedDate.getTime());
|
|
1126
|
-
f(newAdjustedDate);
|
|
1127
|
-
return makeZonedFromAdjusted(newAdjustedDate.getTime(), self.zone);
|
|
1128
|
-
});
|
|
732
|
+
const mutate = exports.mutate = Internal.mutate;
|
|
1129
733
|
/**
|
|
1130
734
|
* Modify a `DateTime` by applying a function to a cloned UTC `Date` instance.
|
|
1131
735
|
*
|
|
1132
736
|
* @since 3.6.0
|
|
1133
737
|
* @category mapping
|
|
1134
738
|
*/
|
|
1135
|
-
const mutateUtc = exports.mutateUtc =
|
|
1136
|
-
const date = new Date(millis);
|
|
1137
|
-
f(date);
|
|
1138
|
-
return date.getTime();
|
|
1139
|
-
}));
|
|
739
|
+
const mutateUtc = exports.mutateUtc = Internal.mutateUtc;
|
|
1140
740
|
/**
|
|
1141
741
|
* Transform a `DateTime` by applying a function to the number of milliseconds
|
|
1142
742
|
* since the Unix epoch.
|
|
@@ -1153,10 +753,7 @@ const mutateUtc = exports.mutateUtc = /*#__PURE__*/(0, _Function.dual)(2, (self,
|
|
|
1153
753
|
* )
|
|
1154
754
|
* ```
|
|
1155
755
|
*/
|
|
1156
|
-
const mapEpochMillis = exports.mapEpochMillis =
|
|
1157
|
-
const millis = f(toEpochMillis(self));
|
|
1158
|
-
return self._tag === "Utc" ? makeUtc(millis) : makeZonedProto(millis, self.zone);
|
|
1159
|
-
});
|
|
756
|
+
const mapEpochMillis = exports.mapEpochMillis = Internal.mapEpochMillis;
|
|
1160
757
|
/**
|
|
1161
758
|
* Using the time zone adjusted `Date`, apply a function to the `Date` and
|
|
1162
759
|
* return the result.
|
|
@@ -1173,7 +770,7 @@ const mapEpochMillis = exports.mapEpochMillis = /*#__PURE__*/(0, _Function.dual)
|
|
|
1173
770
|
* )
|
|
1174
771
|
* ```
|
|
1175
772
|
*/
|
|
1176
|
-
const withDate = exports.withDate =
|
|
773
|
+
const withDate = exports.withDate = Internal.withDate;
|
|
1177
774
|
/**
|
|
1178
775
|
* Using the time zone adjusted `Date`, apply a function to the `Date` and
|
|
1179
776
|
* return the result.
|
|
@@ -1190,12 +787,12 @@ const withDate = exports.withDate = /*#__PURE__*/(0, _Function.dual)(2, (self, f
|
|
|
1190
787
|
* )
|
|
1191
788
|
* ```
|
|
1192
789
|
*/
|
|
1193
|
-
const withDateUtc = exports.withDateUtc =
|
|
790
|
+
const withDateUtc = exports.withDateUtc = Internal.withDateUtc;
|
|
1194
791
|
/**
|
|
1195
792
|
* @since 3.6.0
|
|
1196
793
|
* @category mapping
|
|
1197
794
|
*/
|
|
1198
|
-
const match = exports.match =
|
|
795
|
+
const match = exports.match = Internal.match;
|
|
1199
796
|
// =============================================================================
|
|
1200
797
|
// math
|
|
1201
798
|
// =============================================================================
|
|
@@ -1214,7 +811,7 @@ const match = exports.match = /*#__PURE__*/(0, _Function.dual)(2, (self, options
|
|
|
1214
811
|
* )
|
|
1215
812
|
* ```
|
|
1216
813
|
*/
|
|
1217
|
-
const addDuration = exports.addDuration =
|
|
814
|
+
const addDuration = exports.addDuration = Internal.addDuration;
|
|
1218
815
|
/**
|
|
1219
816
|
* Subtract the given `Duration` from a `DateTime`.
|
|
1220
817
|
*
|
|
@@ -1230,10 +827,7 @@ const addDuration = exports.addDuration = /*#__PURE__*/(0, _Function.dual)(2, (s
|
|
|
1230
827
|
* )
|
|
1231
828
|
* ```
|
|
1232
829
|
*/
|
|
1233
|
-
const subtractDuration = exports.subtractDuration =
|
|
1234
|
-
const addMillis = (date, amount) => {
|
|
1235
|
-
date.setTime(date.getTime() + amount);
|
|
1236
|
-
};
|
|
830
|
+
const subtractDuration = exports.subtractDuration = Internal.subtractDuration;
|
|
1237
831
|
/**
|
|
1238
832
|
* Add the given `amount` of `unit`'s to a `DateTime`.
|
|
1239
833
|
*
|
|
@@ -1252,41 +846,7 @@ const addMillis = (date, amount) => {
|
|
|
1252
846
|
* )
|
|
1253
847
|
* ```
|
|
1254
848
|
*/
|
|
1255
|
-
const add = exports.add =
|
|
1256
|
-
if (parts.millis) {
|
|
1257
|
-
addMillis(date, parts.millis);
|
|
1258
|
-
}
|
|
1259
|
-
if (parts.seconds) {
|
|
1260
|
-
addMillis(date, parts.seconds * 1000);
|
|
1261
|
-
}
|
|
1262
|
-
if (parts.minutes) {
|
|
1263
|
-
addMillis(date, parts.minutes * 60 * 1000);
|
|
1264
|
-
}
|
|
1265
|
-
if (parts.hours) {
|
|
1266
|
-
addMillis(date, parts.hours * 60 * 60 * 1000);
|
|
1267
|
-
}
|
|
1268
|
-
if (parts.days) {
|
|
1269
|
-
date.setUTCDate(date.getUTCDate() + parts.days);
|
|
1270
|
-
}
|
|
1271
|
-
if (parts.weeks) {
|
|
1272
|
-
date.setUTCDate(date.getUTCDate() + parts.weeks * 7);
|
|
1273
|
-
}
|
|
1274
|
-
if (parts.months) {
|
|
1275
|
-
const day = date.getUTCDate();
|
|
1276
|
-
date.setUTCMonth(date.getUTCMonth() + parts.months + 1, 0);
|
|
1277
|
-
if (day < date.getUTCDate()) {
|
|
1278
|
-
date.setUTCDate(day);
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
if (parts.years) {
|
|
1282
|
-
const day = date.getUTCDate();
|
|
1283
|
-
const month = date.getUTCMonth();
|
|
1284
|
-
date.setUTCFullYear(date.getUTCFullYear() + parts.years, month + 1, 0);
|
|
1285
|
-
if (day < date.getUTCDate()) {
|
|
1286
|
-
date.setUTCDate(day);
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
}));
|
|
849
|
+
const add = exports.add = Internal.add;
|
|
1290
850
|
/**
|
|
1291
851
|
* Subtract the given `amount` of `unit`'s from a `DateTime`.
|
|
1292
852
|
*
|
|
@@ -1302,58 +862,7 @@ const add = exports.add = /*#__PURE__*/(0, _Function.dual)(2, (self, parts) => m
|
|
|
1302
862
|
* )
|
|
1303
863
|
* ```
|
|
1304
864
|
*/
|
|
1305
|
-
const subtract = exports.subtract =
|
|
1306
|
-
const newParts = {};
|
|
1307
|
-
for (const key in parts) {
|
|
1308
|
-
newParts[key] = -1 * parts[key];
|
|
1309
|
-
}
|
|
1310
|
-
return add(self, newParts);
|
|
1311
|
-
});
|
|
1312
|
-
function startOfDate(date, part, options) {
|
|
1313
|
-
switch (part) {
|
|
1314
|
-
case "second":
|
|
1315
|
-
{
|
|
1316
|
-
date.setUTCMilliseconds(0);
|
|
1317
|
-
break;
|
|
1318
|
-
}
|
|
1319
|
-
case "minute":
|
|
1320
|
-
{
|
|
1321
|
-
date.setUTCSeconds(0, 0);
|
|
1322
|
-
break;
|
|
1323
|
-
}
|
|
1324
|
-
case "hour":
|
|
1325
|
-
{
|
|
1326
|
-
date.setUTCMinutes(0, 0, 0);
|
|
1327
|
-
break;
|
|
1328
|
-
}
|
|
1329
|
-
case "day":
|
|
1330
|
-
{
|
|
1331
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
1332
|
-
break;
|
|
1333
|
-
}
|
|
1334
|
-
case "week":
|
|
1335
|
-
{
|
|
1336
|
-
const weekStartsOn = options?.weekStartsOn ?? 0;
|
|
1337
|
-
const day = date.getUTCDay();
|
|
1338
|
-
const diff = (day - weekStartsOn + 7) % 7;
|
|
1339
|
-
date.setUTCDate(date.getUTCDate() - diff);
|
|
1340
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
1341
|
-
break;
|
|
1342
|
-
}
|
|
1343
|
-
case "month":
|
|
1344
|
-
{
|
|
1345
|
-
date.setUTCDate(1);
|
|
1346
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
1347
|
-
break;
|
|
1348
|
-
}
|
|
1349
|
-
case "year":
|
|
1350
|
-
{
|
|
1351
|
-
date.setUTCMonth(0, 1);
|
|
1352
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
1353
|
-
break;
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
865
|
+
const subtract = exports.subtract = Internal.subtract;
|
|
1357
866
|
/**
|
|
1358
867
|
* Converts a `DateTime` to the start of the given `part`.
|
|
1359
868
|
*
|
|
@@ -1373,52 +882,7 @@ function startOfDate(date, part, options) {
|
|
|
1373
882
|
* )
|
|
1374
883
|
* ```
|
|
1375
884
|
*/
|
|
1376
|
-
const startOf = exports.startOf =
|
|
1377
|
-
function endOfDate(date, part, options) {
|
|
1378
|
-
switch (part) {
|
|
1379
|
-
case "second":
|
|
1380
|
-
{
|
|
1381
|
-
date.setUTCMilliseconds(999);
|
|
1382
|
-
break;
|
|
1383
|
-
}
|
|
1384
|
-
case "minute":
|
|
1385
|
-
{
|
|
1386
|
-
date.setUTCSeconds(59, 999);
|
|
1387
|
-
break;
|
|
1388
|
-
}
|
|
1389
|
-
case "hour":
|
|
1390
|
-
{
|
|
1391
|
-
date.setUTCMinutes(59, 59, 999);
|
|
1392
|
-
break;
|
|
1393
|
-
}
|
|
1394
|
-
case "day":
|
|
1395
|
-
{
|
|
1396
|
-
date.setUTCHours(23, 59, 59, 999);
|
|
1397
|
-
break;
|
|
1398
|
-
}
|
|
1399
|
-
case "week":
|
|
1400
|
-
{
|
|
1401
|
-
const weekStartsOn = options?.weekStartsOn ?? 0;
|
|
1402
|
-
const day = date.getUTCDay();
|
|
1403
|
-
const diff = (day - weekStartsOn + 7) % 7;
|
|
1404
|
-
date.setUTCDate(date.getUTCDate() - diff + 6);
|
|
1405
|
-
date.setUTCHours(23, 59, 59, 999);
|
|
1406
|
-
break;
|
|
1407
|
-
}
|
|
1408
|
-
case "month":
|
|
1409
|
-
{
|
|
1410
|
-
date.setUTCMonth(date.getUTCMonth() + 1, 0);
|
|
1411
|
-
date.setUTCHours(23, 59, 59, 999);
|
|
1412
|
-
break;
|
|
1413
|
-
}
|
|
1414
|
-
case "year":
|
|
1415
|
-
{
|
|
1416
|
-
date.setUTCMonth(11, 31);
|
|
1417
|
-
date.setUTCHours(23, 59, 59, 999);
|
|
1418
|
-
break;
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
}
|
|
885
|
+
const startOf = exports.startOf = Internal.startOf;
|
|
1422
886
|
/**
|
|
1423
887
|
* Converts a `DateTime` to the end of the given `part`.
|
|
1424
888
|
*
|
|
@@ -1438,7 +902,7 @@ function endOfDate(date, part, options) {
|
|
|
1438
902
|
* )
|
|
1439
903
|
* ```
|
|
1440
904
|
*/
|
|
1441
|
-
const endOf = exports.endOf =
|
|
905
|
+
const endOf = exports.endOf = Internal.endOf;
|
|
1442
906
|
/**
|
|
1443
907
|
* Converts a `DateTime` to the nearest given `part`.
|
|
1444
908
|
*
|
|
@@ -1458,32 +922,10 @@ const endOf = exports.endOf = /*#__PURE__*/(0, _Function.dual)(isDateTimeArgs, (
|
|
|
1458
922
|
* )
|
|
1459
923
|
* ```
|
|
1460
924
|
*/
|
|
1461
|
-
const nearest = exports.nearest =
|
|
1462
|
-
if (part === "milli") return;
|
|
1463
|
-
const millis = date.getTime();
|
|
1464
|
-
const start = new Date(millis);
|
|
1465
|
-
startOfDate(start, part, options);
|
|
1466
|
-
const startMillis = start.getTime();
|
|
1467
|
-
const end = new Date(millis);
|
|
1468
|
-
endOfDate(end, part, options);
|
|
1469
|
-
const endMillis = end.getTime() + 1;
|
|
1470
|
-
const diffStart = millis - startMillis;
|
|
1471
|
-
const diffEnd = endMillis - millis;
|
|
1472
|
-
if (diffStart < diffEnd) {
|
|
1473
|
-
date.setTime(startMillis);
|
|
1474
|
-
} else {
|
|
1475
|
-
date.setTime(endMillis);
|
|
1476
|
-
}
|
|
1477
|
-
}));
|
|
925
|
+
const nearest = exports.nearest = Internal.nearest;
|
|
1478
926
|
// =============================================================================
|
|
1479
927
|
// formatting
|
|
1480
928
|
// =============================================================================
|
|
1481
|
-
const intlTimeZone = self => {
|
|
1482
|
-
if (self._tag === "Named") {
|
|
1483
|
-
return self.id;
|
|
1484
|
-
}
|
|
1485
|
-
return offsetToString(self.offset);
|
|
1486
|
-
};
|
|
1487
929
|
/**
|
|
1488
930
|
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
1489
931
|
*
|
|
@@ -1495,19 +937,7 @@ const intlTimeZone = self => {
|
|
|
1495
937
|
* @since 3.6.0
|
|
1496
938
|
* @category formatting
|
|
1497
939
|
*/
|
|
1498
|
-
const format = exports.format =
|
|
1499
|
-
try {
|
|
1500
|
-
return new Intl.DateTimeFormat(options?.locale, {
|
|
1501
|
-
timeZone: self._tag === "Utc" ? "UTC" : intlTimeZone(self.zone),
|
|
1502
|
-
...options
|
|
1503
|
-
}).format(self.epochMillis);
|
|
1504
|
-
} catch (_) {
|
|
1505
|
-
return new Intl.DateTimeFormat(options?.locale, {
|
|
1506
|
-
timeZone: "UTC",
|
|
1507
|
-
...options
|
|
1508
|
-
}).format(toDate(self));
|
|
1509
|
-
}
|
|
1510
|
-
});
|
|
940
|
+
const format = exports.format = Internal.format;
|
|
1511
941
|
/**
|
|
1512
942
|
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
1513
943
|
*
|
|
@@ -1516,7 +946,7 @@ const format = exports.format = /*#__PURE__*/(0, _Function.dual)(isDateTimeArgs,
|
|
|
1516
946
|
* @since 3.6.0
|
|
1517
947
|
* @category formatting
|
|
1518
948
|
*/
|
|
1519
|
-
const formatLocal = exports.formatLocal =
|
|
949
|
+
const formatLocal = exports.formatLocal = Internal.formatLocal;
|
|
1520
950
|
/**
|
|
1521
951
|
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
1522
952
|
*
|
|
@@ -1525,51 +955,42 @@ const formatLocal = exports.formatLocal = /*#__PURE__*/(0, _Function.dual)(isDat
|
|
|
1525
955
|
* @since 3.6.0
|
|
1526
956
|
* @category formatting
|
|
1527
957
|
*/
|
|
1528
|
-
const formatUtc = exports.formatUtc =
|
|
1529
|
-
...options,
|
|
1530
|
-
timeZone: "UTC"
|
|
1531
|
-
}).format(self.epochMillis));
|
|
958
|
+
const formatUtc = exports.formatUtc = Internal.formatUtc;
|
|
1532
959
|
/**
|
|
1533
960
|
* Format a `DateTime` as a string using the `DateTimeFormat` API.
|
|
1534
961
|
*
|
|
1535
962
|
* @since 3.6.0
|
|
1536
963
|
* @category formatting
|
|
1537
964
|
*/
|
|
1538
|
-
const formatIntl = exports.formatIntl =
|
|
965
|
+
const formatIntl = exports.formatIntl = Internal.formatIntl;
|
|
1539
966
|
/**
|
|
1540
967
|
* Format a `DateTime` as a UTC ISO string.
|
|
1541
968
|
*
|
|
1542
969
|
* @since 3.6.0
|
|
1543
970
|
* @category formatting
|
|
1544
971
|
*/
|
|
1545
|
-
const formatIso =
|
|
972
|
+
const formatIso = exports.formatIso = Internal.formatIso;
|
|
1546
973
|
/**
|
|
1547
974
|
* Format a `DateTime` as a time zone adjusted ISO date string.
|
|
1548
975
|
*
|
|
1549
976
|
* @since 3.6.0
|
|
1550
977
|
* @category formatting
|
|
1551
978
|
*/
|
|
1552
|
-
exports.
|
|
1553
|
-
const formatIsoDate = self => toDate(self).toISOString().slice(0, 10);
|
|
979
|
+
const formatIsoDate = exports.formatIsoDate = Internal.formatIsoDate;
|
|
1554
980
|
/**
|
|
1555
981
|
* Format a `DateTime` as a UTC ISO date string.
|
|
1556
982
|
*
|
|
1557
983
|
* @since 3.6.0
|
|
1558
984
|
* @category formatting
|
|
1559
985
|
*/
|
|
1560
|
-
exports.
|
|
1561
|
-
const formatIsoDateUtc = self => toDateUtc(self).toISOString().slice(0, 10);
|
|
986
|
+
const formatIsoDateUtc = exports.formatIsoDateUtc = Internal.formatIsoDateUtc;
|
|
1562
987
|
/**
|
|
1563
988
|
* Format a `DateTime.Zoned` as a ISO string with an offset.
|
|
1564
989
|
*
|
|
1565
990
|
* @since 3.6.0
|
|
1566
991
|
* @category formatting
|
|
1567
992
|
*/
|
|
1568
|
-
exports.
|
|
1569
|
-
const formatIsoOffset = self => {
|
|
1570
|
-
const date = toDate(self);
|
|
1571
|
-
return self._tag === "Utc" ? date.toISOString() : `${date.toISOString().slice(0, -1)}${zonedOffsetIso(self)}`;
|
|
1572
|
-
};
|
|
993
|
+
const formatIsoOffset = exports.formatIsoOffset = Internal.formatIsoOffset;
|
|
1573
994
|
/**
|
|
1574
995
|
* Format a `DateTime.Zoned` as a string.
|
|
1575
996
|
*
|
|
@@ -1578,7 +999,36 @@ const formatIsoOffset = self => {
|
|
|
1578
999
|
* @since 3.6.0
|
|
1579
1000
|
* @category formatting
|
|
1580
1001
|
*/
|
|
1581
|
-
exports.
|
|
1582
|
-
|
|
1583
|
-
|
|
1002
|
+
const formatIsoZoned = exports.formatIsoZoned = Internal.formatIsoZoned;
|
|
1003
|
+
/**
|
|
1004
|
+
* Create a Layer from the given time zone.
|
|
1005
|
+
*
|
|
1006
|
+
* @since 3.6.0
|
|
1007
|
+
* @category current time zone
|
|
1008
|
+
*/
|
|
1009
|
+
const layerCurrentZone = zone => Layer.succeed(CurrentTimeZone, zone);
|
|
1010
|
+
/**
|
|
1011
|
+
* Create a Layer from the given time zone offset.
|
|
1012
|
+
*
|
|
1013
|
+
* @since 3.6.0
|
|
1014
|
+
* @category current time zone
|
|
1015
|
+
*/
|
|
1016
|
+
exports.layerCurrentZone = layerCurrentZone;
|
|
1017
|
+
const layerCurrentZoneOffset = offset => Layer.succeed(CurrentTimeZone, Internal.zoneMakeOffset(offset));
|
|
1018
|
+
/**
|
|
1019
|
+
* Create a Layer from the given IANA time zone identifier.
|
|
1020
|
+
*
|
|
1021
|
+
* @since 3.6.0
|
|
1022
|
+
* @category current time zone
|
|
1023
|
+
*/
|
|
1024
|
+
exports.layerCurrentZoneOffset = layerCurrentZoneOffset;
|
|
1025
|
+
const layerCurrentZoneNamed = zoneId => Layer.effect(CurrentTimeZone, Internal.zoneMakeNamedEffect(zoneId));
|
|
1026
|
+
/**
|
|
1027
|
+
* Create a Layer from the systems local time zone.
|
|
1028
|
+
*
|
|
1029
|
+
* @since 3.6.0
|
|
1030
|
+
* @category current time zone
|
|
1031
|
+
*/
|
|
1032
|
+
exports.layerCurrentZoneNamed = layerCurrentZoneNamed;
|
|
1033
|
+
const layerCurrentZoneLocal = exports.layerCurrentZoneLocal = /*#__PURE__*/Layer.sync(CurrentTimeZone, zoneMakeLocal);
|
|
1584
1034
|
//# sourceMappingURL=DateTime.js.map
|