feelin 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.rspec +2 -0
  4. data/CHANGELOG.md +10 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +43 -0
  8. data/feelin.gemspec +22 -0
  9. data/lib/feelin/js/node_modules/.package-lock.json +67 -0
  10. data/lib/feelin/js/node_modules/@lezer/common/LICENSE +21 -0
  11. data/lib/feelin/js/node_modules/@lezer/common/README.md +14 -0
  12. data/lib/feelin/js/node_modules/@lezer/common/dist/index.cjs +2181 -0
  13. data/lib/feelin/js/node_modules/@lezer/common/dist/index.d.cts +1137 -0
  14. data/lib/feelin/js/node_modules/@lezer/common/dist/index.d.ts +1137 -0
  15. data/lib/feelin/js/node_modules/@lezer/common/dist/index.js +2168 -0
  16. data/lib/feelin/js/node_modules/@lezer/common/package.json +32 -0
  17. data/lib/feelin/js/node_modules/@lezer/highlight/LICENSE +21 -0
  18. data/lib/feelin/js/node_modules/@lezer/highlight/README.md +14 -0
  19. data/lib/feelin/js/node_modules/@lezer/highlight/dist/index.cjs +915 -0
  20. data/lib/feelin/js/node_modules/@lezer/highlight/dist/index.d.cts +621 -0
  21. data/lib/feelin/js/node_modules/@lezer/highlight/dist/index.d.ts +623 -0
  22. data/lib/feelin/js/node_modules/@lezer/highlight/dist/index.js +904 -0
  23. data/lib/feelin/js/node_modules/@lezer/highlight/package.json +31 -0
  24. data/lib/feelin/js/node_modules/@lezer/lr/LICENSE +21 -0
  25. data/lib/feelin/js/node_modules/@lezer/lr/README.md +25 -0
  26. data/lib/feelin/js/node_modules/@lezer/lr/dist/constants.d.ts +45 -0
  27. data/lib/feelin/js/node_modules/@lezer/lr/dist/constants.js +5 -0
  28. data/lib/feelin/js/node_modules/@lezer/lr/dist/index.cjs +1890 -0
  29. data/lib/feelin/js/node_modules/@lezer/lr/dist/index.d.cts +303 -0
  30. data/lib/feelin/js/node_modules/@lezer/lr/dist/index.d.ts +303 -0
  31. data/lib/feelin/js/node_modules/@lezer/lr/dist/index.js +1883 -0
  32. data/lib/feelin/js/node_modules/@lezer/lr/package.json +32 -0
  33. data/lib/feelin/js/node_modules/feelin/LICENSE +21 -0
  34. data/lib/feelin/js/node_modules/feelin/README.md +65 -0
  35. data/lib/feelin/js/node_modules/feelin/dist/builtins.d.ts +355 -0
  36. data/lib/feelin/js/node_modules/feelin/dist/index.cjs +2072 -0
  37. data/lib/feelin/js/node_modules/feelin/dist/index.cjs.map +1 -0
  38. data/lib/feelin/js/node_modules/feelin/dist/index.d.ts +3 -0
  39. data/lib/feelin/js/node_modules/feelin/dist/index.esm.js +2063 -0
  40. data/lib/feelin/js/node_modules/feelin/dist/index.esm.js.map +1 -0
  41. data/lib/feelin/js/node_modules/feelin/dist/interpreter.d.ts +26 -0
  42. data/lib/feelin/js/node_modules/feelin/dist/parser.d.ts +4 -0
  43. data/lib/feelin/js/node_modules/feelin/dist/temporal.d.ts +6 -0
  44. data/lib/feelin/js/node_modules/feelin/dist/types.d.ts +35 -0
  45. data/lib/feelin/js/node_modules/feelin/dist/utils.d.ts +12 -0
  46. data/lib/feelin/js/node_modules/feelin/package.json +63 -0
  47. data/lib/feelin/js/node_modules/lezer-feel/LICENSE +21 -0
  48. data/lib/feelin/js/node_modules/lezer-feel/README.md +94 -0
  49. data/lib/feelin/js/node_modules/lezer-feel/dist/index.cjs +1328 -0
  50. data/lib/feelin/js/node_modules/lezer-feel/dist/index.cjs.map +1 -0
  51. data/lib/feelin/js/node_modules/lezer-feel/dist/index.d.ts +32 -0
  52. data/lib/feelin/js/node_modules/lezer-feel/dist/index.js +1323 -0
  53. data/lib/feelin/js/node_modules/lezer-feel/dist/index.js.map +1 -0
  54. data/lib/feelin/js/node_modules/lezer-feel/package.json +61 -0
  55. data/lib/feelin/js/node_modules/luxon/LICENSE.md +7 -0
  56. data/lib/feelin/js/node_modules/luxon/README.md +55 -0
  57. data/lib/feelin/js/node_modules/luxon/build/amd/luxon.js +8623 -0
  58. data/lib/feelin/js/node_modules/luxon/build/amd/luxon.js.map +1 -0
  59. data/lib/feelin/js/node_modules/luxon/build/cjs-browser/luxon.js +8621 -0
  60. data/lib/feelin/js/node_modules/luxon/build/cjs-browser/luxon.js.map +1 -0
  61. data/lib/feelin/js/node_modules/luxon/build/es6/luxon.js +8011 -0
  62. data/lib/feelin/js/node_modules/luxon/build/es6/luxon.js.map +1 -0
  63. data/lib/feelin/js/node_modules/luxon/build/global/luxon.js +8626 -0
  64. data/lib/feelin/js/node_modules/luxon/build/global/luxon.js.map +1 -0
  65. data/lib/feelin/js/node_modules/luxon/build/global/luxon.min.js +1 -0
  66. data/lib/feelin/js/node_modules/luxon/build/global/luxon.min.js.map +1 -0
  67. data/lib/feelin/js/node_modules/luxon/build/node/luxon.js +7679 -0
  68. data/lib/feelin/js/node_modules/luxon/build/node/luxon.js.map +1 -0
  69. data/lib/feelin/js/node_modules/luxon/package.json +87 -0
  70. data/lib/feelin/js/node_modules/luxon/src/datetime.js +2566 -0
  71. data/lib/feelin/js/node_modules/luxon/src/duration.js +990 -0
  72. data/lib/feelin/js/node_modules/luxon/src/errors.js +61 -0
  73. data/lib/feelin/js/node_modules/luxon/src/impl/conversions.js +206 -0
  74. data/lib/feelin/js/node_modules/luxon/src/impl/diff.js +95 -0
  75. data/lib/feelin/js/node_modules/luxon/src/impl/digits.js +90 -0
  76. data/lib/feelin/js/node_modules/luxon/src/impl/english.js +233 -0
  77. data/lib/feelin/js/node_modules/luxon/src/impl/formats.js +176 -0
  78. data/lib/feelin/js/node_modules/luxon/src/impl/formatter.js +409 -0
  79. data/lib/feelin/js/node_modules/luxon/src/impl/invalid.js +14 -0
  80. data/lib/feelin/js/node_modules/luxon/src/impl/locale.js +554 -0
  81. data/lib/feelin/js/node_modules/luxon/src/impl/regexParser.js +335 -0
  82. data/lib/feelin/js/node_modules/luxon/src/impl/tokenParser.js +505 -0
  83. data/lib/feelin/js/node_modules/luxon/src/impl/util.js +316 -0
  84. data/lib/feelin/js/node_modules/luxon/src/impl/zoneUtil.js +34 -0
  85. data/lib/feelin/js/node_modules/luxon/src/info.js +205 -0
  86. data/lib/feelin/js/node_modules/luxon/src/interval.js +665 -0
  87. data/lib/feelin/js/node_modules/luxon/src/luxon.js +26 -0
  88. data/lib/feelin/js/node_modules/luxon/src/package.json +4 -0
  89. data/lib/feelin/js/node_modules/luxon/src/settings.js +180 -0
  90. data/lib/feelin/js/node_modules/luxon/src/zone.js +97 -0
  91. data/lib/feelin/js/node_modules/luxon/src/zones/IANAZone.js +231 -0
  92. data/lib/feelin/js/node_modules/luxon/src/zones/fixedOffsetZone.js +150 -0
  93. data/lib/feelin/js/node_modules/luxon/src/zones/invalidZone.js +53 -0
  94. data/lib/feelin/js/node_modules/luxon/src/zones/systemZone.js +61 -0
  95. data/lib/feelin/js/node_modules/min-dash/LICENSE +21 -0
  96. data/lib/feelin/js/node_modules/min-dash/README.md +38 -0
  97. data/lib/feelin/js/node_modules/min-dash/dist/array.d.ts +12 -0
  98. data/lib/feelin/js/node_modules/min-dash/dist/collection.d.ts +174 -0
  99. data/lib/feelin/js/node_modules/min-dash/dist/fn.d.ts +37 -0
  100. data/lib/feelin/js/node_modules/min-dash/dist/index.cjs +910 -0
  101. data/lib/feelin/js/node_modules/min-dash/dist/index.d.ts +5 -0
  102. data/lib/feelin/js/node_modules/min-dash/dist/index.esm.js +872 -0
  103. data/lib/feelin/js/node_modules/min-dash/dist/lang.d.ts +29 -0
  104. data/lib/feelin/js/node_modules/min-dash/dist/min-dash.js +916 -0
  105. data/lib/feelin/js/node_modules/min-dash/dist/min-dash.min.js +1 -0
  106. data/lib/feelin/js/node_modules/min-dash/dist/object.d.ts +112 -0
  107. data/lib/feelin/js/node_modules/min-dash/package.json +72 -0
  108. data/lib/feelin/js/package-lock.json +72 -0
  109. data/lib/feelin/js/package.json +5 -0
  110. data/lib/feelin/version.rb +3 -0
  111. data/lib/feelin.rb +63 -0
  112. data/spec/feelin/feelin_spec.rb +38 -0
  113. data/spec/spec_helper.rb +2 -0
  114. metadata +198 -0
@@ -0,0 +1,2566 @@
1
+ import Duration from "./duration.js";
2
+ import Interval from "./interval.js";
3
+ import Settings from "./settings.js";
4
+ import Info from "./info.js";
5
+ import Formatter from "./impl/formatter.js";
6
+ import FixedOffsetZone from "./zones/fixedOffsetZone.js";
7
+ import Locale from "./impl/locale.js";
8
+ import {
9
+ isUndefined,
10
+ maybeArray,
11
+ isDate,
12
+ isNumber,
13
+ bestBy,
14
+ daysInMonth,
15
+ daysInYear,
16
+ isLeapYear,
17
+ weeksInWeekYear,
18
+ normalizeObject,
19
+ roundTo,
20
+ objToLocalTS,
21
+ padStart,
22
+ } from "./impl/util.js";
23
+ import { normalizeZone } from "./impl/zoneUtil.js";
24
+ import diff from "./impl/diff.js";
25
+ import { parseRFC2822Date, parseISODate, parseHTTPDate, parseSQL } from "./impl/regexParser.js";
26
+ import {
27
+ parseFromTokens,
28
+ explainFromTokens,
29
+ formatOptsToTokens,
30
+ expandMacroTokens,
31
+ TokenParser,
32
+ } from "./impl/tokenParser.js";
33
+ import {
34
+ gregorianToWeek,
35
+ weekToGregorian,
36
+ gregorianToOrdinal,
37
+ ordinalToGregorian,
38
+ hasInvalidGregorianData,
39
+ hasInvalidWeekData,
40
+ hasInvalidOrdinalData,
41
+ hasInvalidTimeData,
42
+ usesLocalWeekValues,
43
+ isoWeekdayToLocal,
44
+ } from "./impl/conversions.js";
45
+ import * as Formats from "./impl/formats.js";
46
+ import {
47
+ InvalidArgumentError,
48
+ ConflictingSpecificationError,
49
+ InvalidUnitError,
50
+ InvalidDateTimeError,
51
+ } from "./errors.js";
52
+ import Invalid from "./impl/invalid.js";
53
+
54
+ const INVALID = "Invalid DateTime";
55
+ const MAX_DATE = 8.64e15;
56
+
57
+ function unsupportedZone(zone) {
58
+ return new Invalid("unsupported zone", `the zone "${zone.name}" is not supported`);
59
+ }
60
+
61
+ // we cache week data on the DT object and this intermediates the cache
62
+ /**
63
+ * @param {DateTime} dt
64
+ */
65
+ function possiblyCachedWeekData(dt) {
66
+ if (dt.weekData === null) {
67
+ dt.weekData = gregorianToWeek(dt.c);
68
+ }
69
+ return dt.weekData;
70
+ }
71
+
72
+ /**
73
+ * @param {DateTime} dt
74
+ */
75
+ function possiblyCachedLocalWeekData(dt) {
76
+ if (dt.localWeekData === null) {
77
+ dt.localWeekData = gregorianToWeek(
78
+ dt.c,
79
+ dt.loc.getMinDaysInFirstWeek(),
80
+ dt.loc.getStartOfWeek()
81
+ );
82
+ }
83
+ return dt.localWeekData;
84
+ }
85
+
86
+ // clone really means, "make a new object with these modifications". all "setters" really use this
87
+ // to create a new object while only changing some of the properties
88
+ function clone(inst, alts) {
89
+ const current = {
90
+ ts: inst.ts,
91
+ zone: inst.zone,
92
+ c: inst.c,
93
+ o: inst.o,
94
+ loc: inst.loc,
95
+ invalid: inst.invalid,
96
+ };
97
+ return new DateTime({ ...current, ...alts, old: current });
98
+ }
99
+
100
+ // find the right offset a given local time. The o input is our guess, which determines which
101
+ // offset we'll pick in ambiguous cases (e.g. there are two 3 AMs b/c Fallback DST)
102
+ function fixOffset(localTS, o, tz) {
103
+ // Our UTC time is just a guess because our offset is just a guess
104
+ let utcGuess = localTS - o * 60 * 1000;
105
+
106
+ // Test whether the zone matches the offset for this ts
107
+ const o2 = tz.offset(utcGuess);
108
+
109
+ // If so, offset didn't change and we're done
110
+ if (o === o2) {
111
+ return [utcGuess, o];
112
+ }
113
+
114
+ // If not, change the ts by the difference in the offset
115
+ utcGuess -= (o2 - o) * 60 * 1000;
116
+
117
+ // If that gives us the local time we want, we're done
118
+ const o3 = tz.offset(utcGuess);
119
+ if (o2 === o3) {
120
+ return [utcGuess, o2];
121
+ }
122
+
123
+ // If it's different, we're in a hole time. The offset has changed, but the we don't adjust the time
124
+ return [localTS - Math.min(o2, o3) * 60 * 1000, Math.max(o2, o3)];
125
+ }
126
+
127
+ // convert an epoch timestamp into a calendar object with the given offset
128
+ function tsToObj(ts, offset) {
129
+ ts += offset * 60 * 1000;
130
+
131
+ const d = new Date(ts);
132
+
133
+ return {
134
+ year: d.getUTCFullYear(),
135
+ month: d.getUTCMonth() + 1,
136
+ day: d.getUTCDate(),
137
+ hour: d.getUTCHours(),
138
+ minute: d.getUTCMinutes(),
139
+ second: d.getUTCSeconds(),
140
+ millisecond: d.getUTCMilliseconds(),
141
+ };
142
+ }
143
+
144
+ // convert a calendar object to a epoch timestamp
145
+ function objToTS(obj, offset, zone) {
146
+ return fixOffset(objToLocalTS(obj), offset, zone);
147
+ }
148
+
149
+ // create a new DT instance by adding a duration, adjusting for DSTs
150
+ function adjustTime(inst, dur) {
151
+ const oPre = inst.o,
152
+ year = inst.c.year + Math.trunc(dur.years),
153
+ month = inst.c.month + Math.trunc(dur.months) + Math.trunc(dur.quarters) * 3,
154
+ c = {
155
+ ...inst.c,
156
+ year,
157
+ month,
158
+ day:
159
+ Math.min(inst.c.day, daysInMonth(year, month)) +
160
+ Math.trunc(dur.days) +
161
+ Math.trunc(dur.weeks) * 7,
162
+ },
163
+ millisToAdd = Duration.fromObject({
164
+ years: dur.years - Math.trunc(dur.years),
165
+ quarters: dur.quarters - Math.trunc(dur.quarters),
166
+ months: dur.months - Math.trunc(dur.months),
167
+ weeks: dur.weeks - Math.trunc(dur.weeks),
168
+ days: dur.days - Math.trunc(dur.days),
169
+ hours: dur.hours,
170
+ minutes: dur.minutes,
171
+ seconds: dur.seconds,
172
+ milliseconds: dur.milliseconds,
173
+ }).as("milliseconds"),
174
+ localTS = objToLocalTS(c);
175
+
176
+ let [ts, o] = fixOffset(localTS, oPre, inst.zone);
177
+
178
+ if (millisToAdd !== 0) {
179
+ ts += millisToAdd;
180
+ // that could have changed the offset by going over a DST, but we want to keep the ts the same
181
+ o = inst.zone.offset(ts);
182
+ }
183
+
184
+ return { ts, o };
185
+ }
186
+
187
+ // helper useful in turning the results of parsing into real dates
188
+ // by handling the zone options
189
+ function parseDataToDateTime(parsed, parsedZone, opts, format, text, specificOffset) {
190
+ const { setZone, zone } = opts;
191
+ if ((parsed && Object.keys(parsed).length !== 0) || parsedZone) {
192
+ const interpretationZone = parsedZone || zone,
193
+ inst = DateTime.fromObject(parsed, {
194
+ ...opts,
195
+ zone: interpretationZone,
196
+ specificOffset,
197
+ });
198
+ return setZone ? inst : inst.setZone(zone);
199
+ } else {
200
+ return DateTime.invalid(
201
+ new Invalid("unparsable", `the input "${text}" can't be parsed as ${format}`)
202
+ );
203
+ }
204
+ }
205
+
206
+ // if you want to output a technical format (e.g. RFC 2822), this helper
207
+ // helps handle the details
208
+ function toTechFormat(dt, format, allowZ = true) {
209
+ return dt.isValid
210
+ ? Formatter.create(Locale.create("en-US"), {
211
+ allowZ,
212
+ forceSimple: true,
213
+ }).formatDateTimeFromString(dt, format)
214
+ : null;
215
+ }
216
+
217
+ function toISODate(o, extended) {
218
+ const longFormat = o.c.year > 9999 || o.c.year < 0;
219
+ let c = "";
220
+ if (longFormat && o.c.year >= 0) c += "+";
221
+ c += padStart(o.c.year, longFormat ? 6 : 4);
222
+
223
+ if (extended) {
224
+ c += "-";
225
+ c += padStart(o.c.month);
226
+ c += "-";
227
+ c += padStart(o.c.day);
228
+ } else {
229
+ c += padStart(o.c.month);
230
+ c += padStart(o.c.day);
231
+ }
232
+ return c;
233
+ }
234
+
235
+ function toISOTime(
236
+ o,
237
+ extended,
238
+ suppressSeconds,
239
+ suppressMilliseconds,
240
+ includeOffset,
241
+ extendedZone
242
+ ) {
243
+ let c = padStart(o.c.hour);
244
+ if (extended) {
245
+ c += ":";
246
+ c += padStart(o.c.minute);
247
+ if (o.c.millisecond !== 0 || o.c.second !== 0 || !suppressSeconds) {
248
+ c += ":";
249
+ }
250
+ } else {
251
+ c += padStart(o.c.minute);
252
+ }
253
+
254
+ if (o.c.millisecond !== 0 || o.c.second !== 0 || !suppressSeconds) {
255
+ c += padStart(o.c.second);
256
+
257
+ if (o.c.millisecond !== 0 || !suppressMilliseconds) {
258
+ c += ".";
259
+ c += padStart(o.c.millisecond, 3);
260
+ }
261
+ }
262
+
263
+ if (includeOffset) {
264
+ if (o.isOffsetFixed && o.offset === 0 && !extendedZone) {
265
+ c += "Z";
266
+ } else if (o.o < 0) {
267
+ c += "-";
268
+ c += padStart(Math.trunc(-o.o / 60));
269
+ c += ":";
270
+ c += padStart(Math.trunc(-o.o % 60));
271
+ } else {
272
+ c += "+";
273
+ c += padStart(Math.trunc(o.o / 60));
274
+ c += ":";
275
+ c += padStart(Math.trunc(o.o % 60));
276
+ }
277
+ }
278
+
279
+ if (extendedZone) {
280
+ c += "[" + o.zone.ianaName + "]";
281
+ }
282
+ return c;
283
+ }
284
+
285
+ // defaults for unspecified units in the supported calendars
286
+ const defaultUnitValues = {
287
+ month: 1,
288
+ day: 1,
289
+ hour: 0,
290
+ minute: 0,
291
+ second: 0,
292
+ millisecond: 0,
293
+ },
294
+ defaultWeekUnitValues = {
295
+ weekNumber: 1,
296
+ weekday: 1,
297
+ hour: 0,
298
+ minute: 0,
299
+ second: 0,
300
+ millisecond: 0,
301
+ },
302
+ defaultOrdinalUnitValues = {
303
+ ordinal: 1,
304
+ hour: 0,
305
+ minute: 0,
306
+ second: 0,
307
+ millisecond: 0,
308
+ };
309
+
310
+ // Units in the supported calendars, sorted by bigness
311
+ const orderedUnits = ["year", "month", "day", "hour", "minute", "second", "millisecond"],
312
+ orderedWeekUnits = [
313
+ "weekYear",
314
+ "weekNumber",
315
+ "weekday",
316
+ "hour",
317
+ "minute",
318
+ "second",
319
+ "millisecond",
320
+ ],
321
+ orderedOrdinalUnits = ["year", "ordinal", "hour", "minute", "second", "millisecond"];
322
+
323
+ // standardize case and plurality in units
324
+ function normalizeUnit(unit) {
325
+ const normalized = {
326
+ year: "year",
327
+ years: "year",
328
+ month: "month",
329
+ months: "month",
330
+ day: "day",
331
+ days: "day",
332
+ hour: "hour",
333
+ hours: "hour",
334
+ minute: "minute",
335
+ minutes: "minute",
336
+ quarter: "quarter",
337
+ quarters: "quarter",
338
+ second: "second",
339
+ seconds: "second",
340
+ millisecond: "millisecond",
341
+ milliseconds: "millisecond",
342
+ weekday: "weekday",
343
+ weekdays: "weekday",
344
+ weeknumber: "weekNumber",
345
+ weeksnumber: "weekNumber",
346
+ weeknumbers: "weekNumber",
347
+ weekyear: "weekYear",
348
+ weekyears: "weekYear",
349
+ ordinal: "ordinal",
350
+ }[unit.toLowerCase()];
351
+
352
+ if (!normalized) throw new InvalidUnitError(unit);
353
+
354
+ return normalized;
355
+ }
356
+
357
+ function normalizeUnitWithLocalWeeks(unit) {
358
+ switch (unit.toLowerCase()) {
359
+ case "localweekday":
360
+ case "localweekdays":
361
+ return "localWeekday";
362
+ case "localweeknumber":
363
+ case "localweeknumbers":
364
+ return "localWeekNumber";
365
+ case "localweekyear":
366
+ case "localweekyears":
367
+ return "localWeekYear";
368
+ default:
369
+ return normalizeUnit(unit);
370
+ }
371
+ }
372
+
373
+ // cache offsets for zones based on the current timestamp when this function is
374
+ // first called. When we are handling a datetime from components like (year,
375
+ // month, day, hour) in a time zone, we need a guess about what the timezone
376
+ // offset is so that we can convert into a UTC timestamp. One way is to find the
377
+ // offset of now in the zone. The actual date may have a different offset (for
378
+ // example, if we handle a date in June while we're in December in a zone that
379
+ // observes DST), but we can check and adjust that.
380
+ //
381
+ // When handling many dates, calculating the offset for now every time is
382
+ // expensive. It's just a guess, so we can cache the offset to use even if we
383
+ // are right on a time change boundary (we'll just correct in the other
384
+ // direction). Using a timestamp from first read is a slight optimization for
385
+ // handling dates close to the current date, since those dates will usually be
386
+ // in the same offset (we could set the timestamp statically, instead). We use a
387
+ // single timestamp for all zones to make things a bit more predictable.
388
+ //
389
+ // This is safe for quickDT (used by local() and utc()) because we don't fill in
390
+ // higher-order units from tsNow (as we do in fromObject, this requires that
391
+ // offset is calculated from tsNow).
392
+ /**
393
+ * @param {Zone} zone
394
+ * @return {number}
395
+ */
396
+ function guessOffsetForZone(zone) {
397
+ if (zoneOffsetTs === undefined) {
398
+ zoneOffsetTs = Settings.now();
399
+ }
400
+
401
+ // Do not cache anything but IANA zones, because it is not safe to do so.
402
+ // Guessing an offset which is not present in the zone can cause wrong results from fixOffset
403
+ if (zone.type !== "iana") {
404
+ return zone.offset(zoneOffsetTs);
405
+ }
406
+ const zoneName = zone.name;
407
+ if (!zoneOffsetGuessCache[zoneName]) {
408
+ zoneOffsetGuessCache[zoneName] = zone.offset(zoneOffsetTs);
409
+ }
410
+ return zoneOffsetGuessCache[zoneName];
411
+ }
412
+
413
+ // this is a dumbed down version of fromObject() that runs about 60% faster
414
+ // but doesn't do any validation, makes a bunch of assumptions about what units
415
+ // are present, and so on.
416
+ function quickDT(obj, opts) {
417
+ const zone = normalizeZone(opts.zone, Settings.defaultZone);
418
+ if (!zone.isValid) {
419
+ return DateTime.invalid(unsupportedZone(zone));
420
+ }
421
+
422
+ const loc = Locale.fromObject(opts);
423
+
424
+ let ts, o;
425
+
426
+ // assume we have the higher-order units
427
+ if (!isUndefined(obj.year)) {
428
+ for (const u of orderedUnits) {
429
+ if (isUndefined(obj[u])) {
430
+ obj[u] = defaultUnitValues[u];
431
+ }
432
+ }
433
+
434
+ const invalid = hasInvalidGregorianData(obj) || hasInvalidTimeData(obj);
435
+ if (invalid) {
436
+ return DateTime.invalid(invalid);
437
+ }
438
+
439
+ const offsetProvis = guessOffsetForZone(zone);
440
+ [ts, o] = objToTS(obj, offsetProvis, zone);
441
+ } else {
442
+ ts = Settings.now();
443
+ }
444
+
445
+ return new DateTime({ ts, zone, loc, o });
446
+ }
447
+
448
+ function diffRelative(start, end, opts) {
449
+ const round = isUndefined(opts.round) ? true : opts.round,
450
+ format = (c, unit) => {
451
+ c = roundTo(c, round || opts.calendary ? 0 : 2, true);
452
+ const formatter = end.loc.clone(opts).relFormatter(opts);
453
+ return formatter.format(c, unit);
454
+ },
455
+ differ = (unit) => {
456
+ if (opts.calendary) {
457
+ if (!end.hasSame(start, unit)) {
458
+ return end.startOf(unit).diff(start.startOf(unit), unit).get(unit);
459
+ } else return 0;
460
+ } else {
461
+ return end.diff(start, unit).get(unit);
462
+ }
463
+ };
464
+
465
+ if (opts.unit) {
466
+ return format(differ(opts.unit), opts.unit);
467
+ }
468
+
469
+ for (const unit of opts.units) {
470
+ const count = differ(unit);
471
+ if (Math.abs(count) >= 1) {
472
+ return format(count, unit);
473
+ }
474
+ }
475
+ return format(start > end ? -0 : 0, opts.units[opts.units.length - 1]);
476
+ }
477
+
478
+ function lastOpts(argList) {
479
+ let opts = {},
480
+ args;
481
+ if (argList.length > 0 && typeof argList[argList.length - 1] === "object") {
482
+ opts = argList[argList.length - 1];
483
+ args = Array.from(argList).slice(0, argList.length - 1);
484
+ } else {
485
+ args = Array.from(argList);
486
+ }
487
+ return [opts, args];
488
+ }
489
+
490
+ /**
491
+ * Timestamp to use for cached zone offset guesses (exposed for test)
492
+ */
493
+ let zoneOffsetTs;
494
+ /**
495
+ * Cache for zone offset guesses (exposed for test).
496
+ *
497
+ * This optimizes quickDT via guessOffsetForZone to avoid repeated calls of
498
+ * zone.offset().
499
+ */
500
+ let zoneOffsetGuessCache = {};
501
+
502
+ /**
503
+ * A DateTime is an immutable data structure representing a specific date and time and accompanying methods. It contains class and instance methods for creating, parsing, interrogating, transforming, and formatting them.
504
+ *
505
+ * A DateTime comprises of:
506
+ * * A timestamp. Each DateTime instance refers to a specific millisecond of the Unix epoch.
507
+ * * A time zone. Each instance is considered in the context of a specific zone (by default the local system's zone).
508
+ * * Configuration properties that effect how output strings are formatted, such as `locale`, `numberingSystem`, and `outputCalendar`.
509
+ *
510
+ * Here is a brief overview of the most commonly used functionality it provides:
511
+ *
512
+ * * **Creation**: To create a DateTime from its components, use one of its factory class methods: {@link DateTime.local}, {@link DateTime.utc}, and (most flexibly) {@link DateTime.fromObject}. To create one from a standard string format, use {@link DateTime.fromISO}, {@link DateTime.fromHTTP}, and {@link DateTime.fromRFC2822}. To create one from a custom string format, use {@link DateTime.fromFormat}. To create one from a native JS date, use {@link DateTime.fromJSDate}.
513
+ * * **Gregorian calendar and time**: To examine the Gregorian properties of a DateTime individually (i.e as opposed to collectively through {@link DateTime#toObject}), use the {@link DateTime#year}, {@link DateTime#month},
514
+ * {@link DateTime#day}, {@link DateTime#hour}, {@link DateTime#minute}, {@link DateTime#second}, {@link DateTime#millisecond} accessors.
515
+ * * **Week calendar**: For ISO week calendar attributes, see the {@link DateTime#weekYear}, {@link DateTime#weekNumber}, and {@link DateTime#weekday} accessors.
516
+ * * **Configuration** See the {@link DateTime#locale} and {@link DateTime#numberingSystem} accessors.
517
+ * * **Transformation**: To transform the DateTime into other DateTimes, use {@link DateTime#set}, {@link DateTime#reconfigure}, {@link DateTime#setZone}, {@link DateTime#setLocale}, {@link DateTime.plus}, {@link DateTime#minus}, {@link DateTime#endOf}, {@link DateTime#startOf}, {@link DateTime#toUTC}, and {@link DateTime#toLocal}.
518
+ * * **Output**: To convert the DateTime to other representations, use the {@link DateTime#toRelative}, {@link DateTime#toRelativeCalendar}, {@link DateTime#toJSON}, {@link DateTime#toISO}, {@link DateTime#toHTTP}, {@link DateTime#toObject}, {@link DateTime#toRFC2822}, {@link DateTime#toString}, {@link DateTime#toLocaleString}, {@link DateTime#toFormat}, {@link DateTime#toMillis} and {@link DateTime#toJSDate}.
519
+ *
520
+ * There's plenty others documented below. In addition, for more information on subtler topics like internationalization, time zones, alternative calendars, validity, and so on, see the external documentation.
521
+ */
522
+ export default class DateTime {
523
+ /**
524
+ * @access private
525
+ */
526
+ constructor(config) {
527
+ const zone = config.zone || Settings.defaultZone;
528
+
529
+ let invalid =
530
+ config.invalid ||
531
+ (Number.isNaN(config.ts) ? new Invalid("invalid input") : null) ||
532
+ (!zone.isValid ? unsupportedZone(zone) : null);
533
+ /**
534
+ * @access private
535
+ */
536
+ this.ts = isUndefined(config.ts) ? Settings.now() : config.ts;
537
+
538
+ let c = null,
539
+ o = null;
540
+ if (!invalid) {
541
+ const unchanged = config.old && config.old.ts === this.ts && config.old.zone.equals(zone);
542
+
543
+ if (unchanged) {
544
+ [c, o] = [config.old.c, config.old.o];
545
+ } else {
546
+ // If an offset has been passed and we have not been called from
547
+ // clone(), we can trust it and avoid the offset calculation.
548
+ const ot = isNumber(config.o) && !config.old ? config.o : zone.offset(this.ts);
549
+ c = tsToObj(this.ts, ot);
550
+ invalid = Number.isNaN(c.year) ? new Invalid("invalid input") : null;
551
+ c = invalid ? null : c;
552
+ o = invalid ? null : ot;
553
+ }
554
+ }
555
+
556
+ /**
557
+ * @access private
558
+ */
559
+ this._zone = zone;
560
+ /**
561
+ * @access private
562
+ */
563
+ this.loc = config.loc || Locale.create();
564
+ /**
565
+ * @access private
566
+ */
567
+ this.invalid = invalid;
568
+ /**
569
+ * @access private
570
+ */
571
+ this.weekData = null;
572
+ /**
573
+ * @access private
574
+ */
575
+ this.localWeekData = null;
576
+ /**
577
+ * @access private
578
+ */
579
+ this.c = c;
580
+ /**
581
+ * @access private
582
+ */
583
+ this.o = o;
584
+ /**
585
+ * @access private
586
+ */
587
+ this.isLuxonDateTime = true;
588
+ }
589
+
590
+ // CONSTRUCT
591
+
592
+ /**
593
+ * Create a DateTime for the current instant, in the system's time zone.
594
+ *
595
+ * Use Settings to override these default values if needed.
596
+ * @example DateTime.now().toISO() //~> now in the ISO format
597
+ * @return {DateTime}
598
+ */
599
+ static now() {
600
+ return new DateTime({});
601
+ }
602
+
603
+ /**
604
+ * Create a local DateTime
605
+ * @param {number} [year] - The calendar year. If omitted (as in, call `local()` with no arguments), the current time will be used
606
+ * @param {number} [month=1] - The month, 1-indexed
607
+ * @param {number} [day=1] - The day of the month, 1-indexed
608
+ * @param {number} [hour=0] - The hour of the day, in 24-hour time
609
+ * @param {number} [minute=0] - The minute of the hour, meaning a number between 0 and 59
610
+ * @param {number} [second=0] - The second of the minute, meaning a number between 0 and 59
611
+ * @param {number} [millisecond=0] - The millisecond of the second, meaning a number between 0 and 999
612
+ * @example DateTime.local() //~> now
613
+ * @example DateTime.local({ zone: "America/New_York" }) //~> now, in US east coast time
614
+ * @example DateTime.local(2017) //~> 2017-01-01T00:00:00
615
+ * @example DateTime.local(2017, 3) //~> 2017-03-01T00:00:00
616
+ * @example DateTime.local(2017, 3, 12, { locale: "fr" }) //~> 2017-03-12T00:00:00, with a French locale
617
+ * @example DateTime.local(2017, 3, 12, 5) //~> 2017-03-12T05:00:00
618
+ * @example DateTime.local(2017, 3, 12, 5, { zone: "utc" }) //~> 2017-03-12T05:00:00, in UTC
619
+ * @example DateTime.local(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00
620
+ * @example DateTime.local(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10
621
+ * @example DateTime.local(2017, 3, 12, 5, 45, 10, 765) //~> 2017-03-12T05:45:10.765
622
+ * @return {DateTime}
623
+ */
624
+ static local() {
625
+ const [opts, args] = lastOpts(arguments),
626
+ [year, month, day, hour, minute, second, millisecond] = args;
627
+ return quickDT({ year, month, day, hour, minute, second, millisecond }, opts);
628
+ }
629
+
630
+ /**
631
+ * Create a DateTime in UTC
632
+ * @param {number} [year] - The calendar year. If omitted (as in, call `utc()` with no arguments), the current time will be used
633
+ * @param {number} [month=1] - The month, 1-indexed
634
+ * @param {number} [day=1] - The day of the month
635
+ * @param {number} [hour=0] - The hour of the day, in 24-hour time
636
+ * @param {number} [minute=0] - The minute of the hour, meaning a number between 0 and 59
637
+ * @param {number} [second=0] - The second of the minute, meaning a number between 0 and 59
638
+ * @param {number} [millisecond=0] - The millisecond of the second, meaning a number between 0 and 999
639
+ * @param {Object} options - configuration options for the DateTime
640
+ * @param {string} [options.locale] - a locale to set on the resulting DateTime instance
641
+ * @param {string} [options.outputCalendar] - the output calendar to set on the resulting DateTime instance
642
+ * @param {string} [options.numberingSystem] - the numbering system to set on the resulting DateTime instance
643
+ * @param {string} [options.weekSettings] - the week settings to set on the resulting DateTime instance
644
+ * @example DateTime.utc() //~> now
645
+ * @example DateTime.utc(2017) //~> 2017-01-01T00:00:00Z
646
+ * @example DateTime.utc(2017, 3) //~> 2017-03-01T00:00:00Z
647
+ * @example DateTime.utc(2017, 3, 12) //~> 2017-03-12T00:00:00Z
648
+ * @example DateTime.utc(2017, 3, 12, 5) //~> 2017-03-12T05:00:00Z
649
+ * @example DateTime.utc(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00Z
650
+ * @example DateTime.utc(2017, 3, 12, 5, 45, { locale: "fr" }) //~> 2017-03-12T05:45:00Z with a French locale
651
+ * @example DateTime.utc(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10Z
652
+ * @example DateTime.utc(2017, 3, 12, 5, 45, 10, 765, { locale: "fr" }) //~> 2017-03-12T05:45:10.765Z with a French locale
653
+ * @return {DateTime}
654
+ */
655
+ static utc() {
656
+ const [opts, args] = lastOpts(arguments),
657
+ [year, month, day, hour, minute, second, millisecond] = args;
658
+
659
+ opts.zone = FixedOffsetZone.utcInstance;
660
+ return quickDT({ year, month, day, hour, minute, second, millisecond }, opts);
661
+ }
662
+
663
+ /**
664
+ * Create a DateTime from a JavaScript Date object. Uses the default zone.
665
+ * @param {Date} date - a JavaScript Date object
666
+ * @param {Object} options - configuration options for the DateTime
667
+ * @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into
668
+ * @return {DateTime}
669
+ */
670
+ static fromJSDate(date, options = {}) {
671
+ const ts = isDate(date) ? date.valueOf() : NaN;
672
+ if (Number.isNaN(ts)) {
673
+ return DateTime.invalid("invalid input");
674
+ }
675
+
676
+ const zoneToUse = normalizeZone(options.zone, Settings.defaultZone);
677
+ if (!zoneToUse.isValid) {
678
+ return DateTime.invalid(unsupportedZone(zoneToUse));
679
+ }
680
+
681
+ return new DateTime({
682
+ ts: ts,
683
+ zone: zoneToUse,
684
+ loc: Locale.fromObject(options),
685
+ });
686
+ }
687
+
688
+ /**
689
+ * Create a DateTime from a number of milliseconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.
690
+ * @param {number} milliseconds - a number of milliseconds since 1970 UTC
691
+ * @param {Object} options - configuration options for the DateTime
692
+ * @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into
693
+ * @param {string} [options.locale] - a locale to set on the resulting DateTime instance
694
+ * @param {string} options.outputCalendar - the output calendar to set on the resulting DateTime instance
695
+ * @param {string} options.numberingSystem - the numbering system to set on the resulting DateTime instance
696
+ * @param {string} options.weekSettings - the week settings to set on the resulting DateTime instance
697
+ * @return {DateTime}
698
+ */
699
+ static fromMillis(milliseconds, options = {}) {
700
+ if (!isNumber(milliseconds)) {
701
+ throw new InvalidArgumentError(
702
+ `fromMillis requires a numerical input, but received a ${typeof milliseconds} with value ${milliseconds}`
703
+ );
704
+ } else if (milliseconds < -MAX_DATE || milliseconds > MAX_DATE) {
705
+ // this isn't perfect because we can still end up out of range because of additional shifting, but it's a start
706
+ return DateTime.invalid("Timestamp out of range");
707
+ } else {
708
+ return new DateTime({
709
+ ts: milliseconds,
710
+ zone: normalizeZone(options.zone, Settings.defaultZone),
711
+ loc: Locale.fromObject(options),
712
+ });
713
+ }
714
+ }
715
+
716
+ /**
717
+ * Create a DateTime from a number of seconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.
718
+ * @param {number} seconds - a number of seconds since 1970 UTC
719
+ * @param {Object} options - configuration options for the DateTime
720
+ * @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into
721
+ * @param {string} [options.locale] - a locale to set on the resulting DateTime instance
722
+ * @param {string} options.outputCalendar - the output calendar to set on the resulting DateTime instance
723
+ * @param {string} options.numberingSystem - the numbering system to set on the resulting DateTime instance
724
+ * @param {string} options.weekSettings - the week settings to set on the resulting DateTime instance
725
+ * @return {DateTime}
726
+ */
727
+ static fromSeconds(seconds, options = {}) {
728
+ if (!isNumber(seconds)) {
729
+ throw new InvalidArgumentError("fromSeconds requires a numerical input");
730
+ } else {
731
+ return new DateTime({
732
+ ts: seconds * 1000,
733
+ zone: normalizeZone(options.zone, Settings.defaultZone),
734
+ loc: Locale.fromObject(options),
735
+ });
736
+ }
737
+ }
738
+
739
+ /**
740
+ * Create a DateTime from a JavaScript object with keys like 'year' and 'hour' with reasonable defaults.
741
+ * @param {Object} obj - the object to create the DateTime from
742
+ * @param {number} obj.year - a year, such as 1987
743
+ * @param {number} obj.month - a month, 1-12
744
+ * @param {number} obj.day - a day of the month, 1-31, depending on the month
745
+ * @param {number} obj.ordinal - day of the year, 1-365 or 366
746
+ * @param {number} obj.weekYear - an ISO week year
747
+ * @param {number} obj.weekNumber - an ISO week number, between 1 and 52 or 53, depending on the year
748
+ * @param {number} obj.weekday - an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday
749
+ * @param {number} obj.localWeekYear - a week year, according to the locale
750
+ * @param {number} obj.localWeekNumber - a week number, between 1 and 52 or 53, depending on the year, according to the locale
751
+ * @param {number} obj.localWeekday - a weekday, 1-7, where 1 is the first and 7 is the last day of the week, according to the locale
752
+ * @param {number} obj.hour - hour of the day, 0-23
753
+ * @param {number} obj.minute - minute of the hour, 0-59
754
+ * @param {number} obj.second - second of the minute, 0-59
755
+ * @param {number} obj.millisecond - millisecond of the second, 0-999
756
+ * @param {Object} opts - options for creating this DateTime
757
+ * @param {string|Zone} [opts.zone='local'] - interpret the numbers in the context of a particular zone. Can take any value taken as the first argument to setZone()
758
+ * @param {string} [opts.locale='system\'s locale'] - a locale to set on the resulting DateTime instance
759
+ * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
760
+ * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance
761
+ * @param {string} opts.weekSettings - the week settings to set on the resulting DateTime instance
762
+ * @example DateTime.fromObject({ year: 1982, month: 5, day: 25}).toISODate() //=> '1982-05-25'
763
+ * @example DateTime.fromObject({ year: 1982 }).toISODate() //=> '1982-01-01'
764
+ * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }) //~> today at 10:26:06
765
+ * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'utc' }),
766
+ * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'local' })
767
+ * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'America/New_York' })
768
+ * @example DateTime.fromObject({ weekYear: 2016, weekNumber: 2, weekday: 3 }).toISODate() //=> '2016-01-13'
769
+ * @example DateTime.fromObject({ localWeekYear: 2022, localWeekNumber: 1, localWeekday: 1 }, { locale: "en-US" }).toISODate() //=> '2021-12-26'
770
+ * @return {DateTime}
771
+ */
772
+ static fromObject(obj, opts = {}) {
773
+ obj = obj || {};
774
+ const zoneToUse = normalizeZone(opts.zone, Settings.defaultZone);
775
+ if (!zoneToUse.isValid) {
776
+ return DateTime.invalid(unsupportedZone(zoneToUse));
777
+ }
778
+
779
+ const loc = Locale.fromObject(opts);
780
+ const normalized = normalizeObject(obj, normalizeUnitWithLocalWeeks);
781
+ const { minDaysInFirstWeek, startOfWeek } = usesLocalWeekValues(normalized, loc);
782
+
783
+ const tsNow = Settings.now(),
784
+ offsetProvis = !isUndefined(opts.specificOffset)
785
+ ? opts.specificOffset
786
+ : zoneToUse.offset(tsNow),
787
+ containsOrdinal = !isUndefined(normalized.ordinal),
788
+ containsGregorYear = !isUndefined(normalized.year),
789
+ containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
790
+ containsGregor = containsGregorYear || containsGregorMD,
791
+ definiteWeekDef = normalized.weekYear || normalized.weekNumber;
792
+
793
+ // cases:
794
+ // just a weekday -> this week's instance of that weekday, no worries
795
+ // (gregorian data or ordinal) + (weekYear or weekNumber) -> error
796
+ // (gregorian month or day) + ordinal -> error
797
+ // otherwise just use weeks or ordinals or gregorian, depending on what's specified
798
+
799
+ if ((containsGregor || containsOrdinal) && definiteWeekDef) {
800
+ throw new ConflictingSpecificationError(
801
+ "Can't mix weekYear/weekNumber units with year/month/day or ordinals"
802
+ );
803
+ }
804
+
805
+ if (containsGregorMD && containsOrdinal) {
806
+ throw new ConflictingSpecificationError("Can't mix ordinal dates with month/day");
807
+ }
808
+
809
+ const useWeekData = definiteWeekDef || (normalized.weekday && !containsGregor);
810
+
811
+ // configure ourselves to deal with gregorian dates or week stuff
812
+ let units,
813
+ defaultValues,
814
+ objNow = tsToObj(tsNow, offsetProvis);
815
+ if (useWeekData) {
816
+ units = orderedWeekUnits;
817
+ defaultValues = defaultWeekUnitValues;
818
+ objNow = gregorianToWeek(objNow, minDaysInFirstWeek, startOfWeek);
819
+ } else if (containsOrdinal) {
820
+ units = orderedOrdinalUnits;
821
+ defaultValues = defaultOrdinalUnitValues;
822
+ objNow = gregorianToOrdinal(objNow);
823
+ } else {
824
+ units = orderedUnits;
825
+ defaultValues = defaultUnitValues;
826
+ }
827
+
828
+ // set default values for missing stuff
829
+ let foundFirst = false;
830
+ for (const u of units) {
831
+ const v = normalized[u];
832
+ if (!isUndefined(v)) {
833
+ foundFirst = true;
834
+ } else if (foundFirst) {
835
+ normalized[u] = defaultValues[u];
836
+ } else {
837
+ normalized[u] = objNow[u];
838
+ }
839
+ }
840
+
841
+ // make sure the values we have are in range
842
+ const higherOrderInvalid = useWeekData
843
+ ? hasInvalidWeekData(normalized, minDaysInFirstWeek, startOfWeek)
844
+ : containsOrdinal
845
+ ? hasInvalidOrdinalData(normalized)
846
+ : hasInvalidGregorianData(normalized),
847
+ invalid = higherOrderInvalid || hasInvalidTimeData(normalized);
848
+
849
+ if (invalid) {
850
+ return DateTime.invalid(invalid);
851
+ }
852
+
853
+ // compute the actual time
854
+ const gregorian = useWeekData
855
+ ? weekToGregorian(normalized, minDaysInFirstWeek, startOfWeek)
856
+ : containsOrdinal
857
+ ? ordinalToGregorian(normalized)
858
+ : normalized,
859
+ [tsFinal, offsetFinal] = objToTS(gregorian, offsetProvis, zoneToUse),
860
+ inst = new DateTime({
861
+ ts: tsFinal,
862
+ zone: zoneToUse,
863
+ o: offsetFinal,
864
+ loc,
865
+ });
866
+
867
+ // gregorian data + weekday serves only to validate
868
+ if (normalized.weekday && containsGregor && obj.weekday !== inst.weekday) {
869
+ return DateTime.invalid(
870
+ "mismatched weekday",
871
+ `you can't specify both a weekday of ${normalized.weekday} and a date of ${inst.toISO()}`
872
+ );
873
+ }
874
+
875
+ if (!inst.isValid) {
876
+ return DateTime.invalid(inst.invalid);
877
+ }
878
+
879
+ return inst;
880
+ }
881
+
882
+ /**
883
+ * Create a DateTime from an ISO 8601 string
884
+ * @param {string} text - the ISO string
885
+ * @param {Object} opts - options to affect the creation
886
+ * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the time to this zone
887
+ * @param {boolean} [opts.setZone=false] - override the zone with a fixed-offset zone specified in the string itself, if it specifies one
888
+ * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
889
+ * @param {string} [opts.outputCalendar] - the output calendar to set on the resulting DateTime instance
890
+ * @param {string} [opts.numberingSystem] - the numbering system to set on the resulting DateTime instance
891
+ * @param {string} [opts.weekSettings] - the week settings to set on the resulting DateTime instance
892
+ * @example DateTime.fromISO('2016-05-25T09:08:34.123')
893
+ * @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00')
894
+ * @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00', {setZone: true})
895
+ * @example DateTime.fromISO('2016-05-25T09:08:34.123', {zone: 'utc'})
896
+ * @example DateTime.fromISO('2016-W05-4')
897
+ * @return {DateTime}
898
+ */
899
+ static fromISO(text, opts = {}) {
900
+ const [vals, parsedZone] = parseISODate(text);
901
+ return parseDataToDateTime(vals, parsedZone, opts, "ISO 8601", text);
902
+ }
903
+
904
+ /**
905
+ * Create a DateTime from an RFC 2822 string
906
+ * @param {string} text - the RFC 2822 string
907
+ * @param {Object} opts - options to affect the creation
908
+ * @param {string|Zone} [opts.zone='local'] - convert the time to this zone. Since the offset is always specified in the string itself, this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in.
909
+ * @param {boolean} [opts.setZone=false] - override the zone with a fixed-offset zone specified in the string itself, if it specifies one
910
+ * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
911
+ * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
912
+ * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance
913
+ * @param {string} opts.weekSettings - the week settings to set on the resulting DateTime instance
914
+ * @example DateTime.fromRFC2822('25 Nov 2016 13:23:12 GMT')
915
+ * @example DateTime.fromRFC2822('Fri, 25 Nov 2016 13:23:12 +0600')
916
+ * @example DateTime.fromRFC2822('25 Nov 2016 13:23 Z')
917
+ * @return {DateTime}
918
+ */
919
+ static fromRFC2822(text, opts = {}) {
920
+ const [vals, parsedZone] = parseRFC2822Date(text);
921
+ return parseDataToDateTime(vals, parsedZone, opts, "RFC 2822", text);
922
+ }
923
+
924
+ /**
925
+ * Create a DateTime from an HTTP header date
926
+ * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
927
+ * @param {string} text - the HTTP header date
928
+ * @param {Object} opts - options to affect the creation
929
+ * @param {string|Zone} [opts.zone='local'] - convert the time to this zone. Since HTTP dates are always in UTC, this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in.
930
+ * @param {boolean} [opts.setZone=false] - override the zone with the fixed-offset zone specified in the string. For HTTP dates, this is always UTC, so this option is equivalent to setting the `zone` option to 'utc', but this option is included for consistency with similar methods.
931
+ * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
932
+ * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
933
+ * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance
934
+ * @param {string} opts.weekSettings - the week settings to set on the resulting DateTime instance
935
+ * @example DateTime.fromHTTP('Sun, 06 Nov 1994 08:49:37 GMT')
936
+ * @example DateTime.fromHTTP('Sunday, 06-Nov-94 08:49:37 GMT')
937
+ * @example DateTime.fromHTTP('Sun Nov 6 08:49:37 1994')
938
+ * @return {DateTime}
939
+ */
940
+ static fromHTTP(text, opts = {}) {
941
+ const [vals, parsedZone] = parseHTTPDate(text);
942
+ return parseDataToDateTime(vals, parsedZone, opts, "HTTP", opts);
943
+ }
944
+
945
+ /**
946
+ * Create a DateTime from an input string and format string.
947
+ * Defaults to en-US if no locale has been specified, regardless of the system's locale. For a table of tokens and their interpretations, see [here](https://moment.github.io/luxon/#/parsing?id=table-of-tokens).
948
+ * @param {string} text - the string to parse
949
+ * @param {string} fmt - the format the string is expected to be in (see the link below for the formats)
950
+ * @param {Object} opts - options to affect the creation
951
+ * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone
952
+ * @param {boolean} [opts.setZone=false] - override the zone with a zone specified in the string itself, if it specifies one
953
+ * @param {string} [opts.locale='en-US'] - a locale string to use when parsing. Will also set the DateTime to this locale
954
+ * @param {string} opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system
955
+ * @param {string} opts.weekSettings - the week settings to set on the resulting DateTime instance
956
+ * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
957
+ * @return {DateTime}
958
+ */
959
+ static fromFormat(text, fmt, opts = {}) {
960
+ if (isUndefined(text) || isUndefined(fmt)) {
961
+ throw new InvalidArgumentError("fromFormat requires an input string and a format");
962
+ }
963
+
964
+ const { locale = null, numberingSystem = null } = opts,
965
+ localeToUse = Locale.fromOpts({
966
+ locale,
967
+ numberingSystem,
968
+ defaultToEN: true,
969
+ }),
970
+ [vals, parsedZone, specificOffset, invalid] = parseFromTokens(localeToUse, text, fmt);
971
+ if (invalid) {
972
+ return DateTime.invalid(invalid);
973
+ } else {
974
+ return parseDataToDateTime(vals, parsedZone, opts, `format ${fmt}`, text, specificOffset);
975
+ }
976
+ }
977
+
978
+ /**
979
+ * @deprecated use fromFormat instead
980
+ */
981
+ static fromString(text, fmt, opts = {}) {
982
+ return DateTime.fromFormat(text, fmt, opts);
983
+ }
984
+
985
+ /**
986
+ * Create a DateTime from a SQL date, time, or datetime
987
+ * Defaults to en-US if no locale has been specified, regardless of the system's locale
988
+ * @param {string} text - the string to parse
989
+ * @param {Object} opts - options to affect the creation
990
+ * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone
991
+ * @param {boolean} [opts.setZone=false] - override the zone with a zone specified in the string itself, if it specifies one
992
+ * @param {string} [opts.locale='en-US'] - a locale string to use when parsing. Will also set the DateTime to this locale
993
+ * @param {string} opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system
994
+ * @param {string} opts.weekSettings - the week settings to set on the resulting DateTime instance
995
+ * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
996
+ * @example DateTime.fromSQL('2017-05-15')
997
+ * @example DateTime.fromSQL('2017-05-15 09:12:34')
998
+ * @example DateTime.fromSQL('2017-05-15 09:12:34.342')
999
+ * @example DateTime.fromSQL('2017-05-15 09:12:34.342+06:00')
1000
+ * @example DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles')
1001
+ * @example DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles', { setZone: true })
1002
+ * @example DateTime.fromSQL('2017-05-15 09:12:34.342', { zone: 'America/Los_Angeles' })
1003
+ * @example DateTime.fromSQL('09:12:34.342')
1004
+ * @return {DateTime}
1005
+ */
1006
+ static fromSQL(text, opts = {}) {
1007
+ const [vals, parsedZone] = parseSQL(text);
1008
+ return parseDataToDateTime(vals, parsedZone, opts, "SQL", text);
1009
+ }
1010
+
1011
+ /**
1012
+ * Create an invalid DateTime.
1013
+ * @param {string} reason - simple string of why this DateTime is invalid. Should not contain parameters or anything else data-dependent.
1014
+ * @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information
1015
+ * @return {DateTime}
1016
+ */
1017
+ static invalid(reason, explanation = null) {
1018
+ if (!reason) {
1019
+ throw new InvalidArgumentError("need to specify a reason the DateTime is invalid");
1020
+ }
1021
+
1022
+ const invalid = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
1023
+
1024
+ if (Settings.throwOnInvalid) {
1025
+ throw new InvalidDateTimeError(invalid);
1026
+ } else {
1027
+ return new DateTime({ invalid });
1028
+ }
1029
+ }
1030
+
1031
+ /**
1032
+ * Check if an object is an instance of DateTime. Works across context boundaries
1033
+ * @param {object} o
1034
+ * @return {boolean}
1035
+ */
1036
+ static isDateTime(o) {
1037
+ return (o && o.isLuxonDateTime) || false;
1038
+ }
1039
+
1040
+ /**
1041
+ * Produce the format string for a set of options
1042
+ * @param formatOpts
1043
+ * @param localeOpts
1044
+ * @returns {string}
1045
+ */
1046
+ static parseFormatForOpts(formatOpts, localeOpts = {}) {
1047
+ const tokenList = formatOptsToTokens(formatOpts, Locale.fromObject(localeOpts));
1048
+ return !tokenList ? null : tokenList.map((t) => (t ? t.val : null)).join("");
1049
+ }
1050
+
1051
+ /**
1052
+ * Produce the the fully expanded format token for the locale
1053
+ * Does NOT quote characters, so quoted tokens will not round trip correctly
1054
+ * @param fmt
1055
+ * @param localeOpts
1056
+ * @returns {string}
1057
+ */
1058
+ static expandFormat(fmt, localeOpts = {}) {
1059
+ const expanded = expandMacroTokens(Formatter.parseFormat(fmt), Locale.fromObject(localeOpts));
1060
+ return expanded.map((t) => t.val).join("");
1061
+ }
1062
+
1063
+ static resetCache() {
1064
+ zoneOffsetTs = undefined;
1065
+ zoneOffsetGuessCache = {};
1066
+ }
1067
+
1068
+ // INFO
1069
+
1070
+ /**
1071
+ * Get the value of unit.
1072
+ * @param {string} unit - a unit such as 'minute' or 'day'
1073
+ * @example DateTime.local(2017, 7, 4).get('month'); //=> 7
1074
+ * @example DateTime.local(2017, 7, 4).get('day'); //=> 4
1075
+ * @return {number}
1076
+ */
1077
+ get(unit) {
1078
+ return this[unit];
1079
+ }
1080
+
1081
+ /**
1082
+ * Returns whether the DateTime is valid. Invalid DateTimes occur when:
1083
+ * * The DateTime was created from invalid calendar information, such as the 13th month or February 30
1084
+ * * The DateTime was created by an operation on another invalid date
1085
+ * @type {boolean}
1086
+ */
1087
+ get isValid() {
1088
+ return this.invalid === null;
1089
+ }
1090
+
1091
+ /**
1092
+ * Returns an error code if this DateTime is invalid, or null if the DateTime is valid
1093
+ * @type {string}
1094
+ */
1095
+ get invalidReason() {
1096
+ return this.invalid ? this.invalid.reason : null;
1097
+ }
1098
+
1099
+ /**
1100
+ * Returns an explanation of why this DateTime became invalid, or null if the DateTime is valid
1101
+ * @type {string}
1102
+ */
1103
+ get invalidExplanation() {
1104
+ return this.invalid ? this.invalid.explanation : null;
1105
+ }
1106
+
1107
+ /**
1108
+ * Get the locale of a DateTime, such 'en-GB'. The locale is used when formatting the DateTime
1109
+ *
1110
+ * @type {string}
1111
+ */
1112
+ get locale() {
1113
+ return this.isValid ? this.loc.locale : null;
1114
+ }
1115
+
1116
+ /**
1117
+ * Get the numbering system of a DateTime, such 'beng'. The numbering system is used when formatting the DateTime
1118
+ *
1119
+ * @type {string}
1120
+ */
1121
+ get numberingSystem() {
1122
+ return this.isValid ? this.loc.numberingSystem : null;
1123
+ }
1124
+
1125
+ /**
1126
+ * Get the output calendar of a DateTime, such 'islamic'. The output calendar is used when formatting the DateTime
1127
+ *
1128
+ * @type {string}
1129
+ */
1130
+ get outputCalendar() {
1131
+ return this.isValid ? this.loc.outputCalendar : null;
1132
+ }
1133
+
1134
+ /**
1135
+ * Get the time zone associated with this DateTime.
1136
+ * @type {Zone}
1137
+ */
1138
+ get zone() {
1139
+ return this._zone;
1140
+ }
1141
+
1142
+ /**
1143
+ * Get the name of the time zone.
1144
+ * @type {string}
1145
+ */
1146
+ get zoneName() {
1147
+ return this.isValid ? this.zone.name : null;
1148
+ }
1149
+
1150
+ /**
1151
+ * Get the year
1152
+ * @example DateTime.local(2017, 5, 25).year //=> 2017
1153
+ * @type {number}
1154
+ */
1155
+ get year() {
1156
+ return this.isValid ? this.c.year : NaN;
1157
+ }
1158
+
1159
+ /**
1160
+ * Get the quarter
1161
+ * @example DateTime.local(2017, 5, 25).quarter //=> 2
1162
+ * @type {number}
1163
+ */
1164
+ get quarter() {
1165
+ return this.isValid ? Math.ceil(this.c.month / 3) : NaN;
1166
+ }
1167
+
1168
+ /**
1169
+ * Get the month (1-12).
1170
+ * @example DateTime.local(2017, 5, 25).month //=> 5
1171
+ * @type {number}
1172
+ */
1173
+ get month() {
1174
+ return this.isValid ? this.c.month : NaN;
1175
+ }
1176
+
1177
+ /**
1178
+ * Get the day of the month (1-30ish).
1179
+ * @example DateTime.local(2017, 5, 25).day //=> 25
1180
+ * @type {number}
1181
+ */
1182
+ get day() {
1183
+ return this.isValid ? this.c.day : NaN;
1184
+ }
1185
+
1186
+ /**
1187
+ * Get the hour of the day (0-23).
1188
+ * @example DateTime.local(2017, 5, 25, 9).hour //=> 9
1189
+ * @type {number}
1190
+ */
1191
+ get hour() {
1192
+ return this.isValid ? this.c.hour : NaN;
1193
+ }
1194
+
1195
+ /**
1196
+ * Get the minute of the hour (0-59).
1197
+ * @example DateTime.local(2017, 5, 25, 9, 30).minute //=> 30
1198
+ * @type {number}
1199
+ */
1200
+ get minute() {
1201
+ return this.isValid ? this.c.minute : NaN;
1202
+ }
1203
+
1204
+ /**
1205
+ * Get the second of the minute (0-59).
1206
+ * @example DateTime.local(2017, 5, 25, 9, 30, 52).second //=> 52
1207
+ * @type {number}
1208
+ */
1209
+ get second() {
1210
+ return this.isValid ? this.c.second : NaN;
1211
+ }
1212
+
1213
+ /**
1214
+ * Get the millisecond of the second (0-999).
1215
+ * @example DateTime.local(2017, 5, 25, 9, 30, 52, 654).millisecond //=> 654
1216
+ * @type {number}
1217
+ */
1218
+ get millisecond() {
1219
+ return this.isValid ? this.c.millisecond : NaN;
1220
+ }
1221
+
1222
+ /**
1223
+ * Get the week year
1224
+ * @see https://en.wikipedia.org/wiki/ISO_week_date
1225
+ * @example DateTime.local(2014, 12, 31).weekYear //=> 2015
1226
+ * @type {number}
1227
+ */
1228
+ get weekYear() {
1229
+ return this.isValid ? possiblyCachedWeekData(this).weekYear : NaN;
1230
+ }
1231
+
1232
+ /**
1233
+ * Get the week number of the week year (1-52ish).
1234
+ * @see https://en.wikipedia.org/wiki/ISO_week_date
1235
+ * @example DateTime.local(2017, 5, 25).weekNumber //=> 21
1236
+ * @type {number}
1237
+ */
1238
+ get weekNumber() {
1239
+ return this.isValid ? possiblyCachedWeekData(this).weekNumber : NaN;
1240
+ }
1241
+
1242
+ /**
1243
+ * Get the day of the week.
1244
+ * 1 is Monday and 7 is Sunday
1245
+ * @see https://en.wikipedia.org/wiki/ISO_week_date
1246
+ * @example DateTime.local(2014, 11, 31).weekday //=> 4
1247
+ * @type {number}
1248
+ */
1249
+ get weekday() {
1250
+ return this.isValid ? possiblyCachedWeekData(this).weekday : NaN;
1251
+ }
1252
+
1253
+ /**
1254
+ * Returns true if this date is on a weekend according to the locale, false otherwise
1255
+ * @returns {boolean}
1256
+ */
1257
+ get isWeekend() {
1258
+ return this.isValid && this.loc.getWeekendDays().includes(this.weekday);
1259
+ }
1260
+
1261
+ /**
1262
+ * Get the day of the week according to the locale.
1263
+ * 1 is the first day of the week and 7 is the last day of the week.
1264
+ * If the locale assigns Sunday as the first day of the week, then a date which is a Sunday will return 1,
1265
+ * @returns {number}
1266
+ */
1267
+ get localWeekday() {
1268
+ return this.isValid ? possiblyCachedLocalWeekData(this).weekday : NaN;
1269
+ }
1270
+
1271
+ /**
1272
+ * Get the week number of the week year according to the locale. Different locales assign week numbers differently,
1273
+ * because the week can start on different days of the week (see localWeekday) and because a different number of days
1274
+ * is required for a week to count as the first week of a year.
1275
+ * @returns {number}
1276
+ */
1277
+ get localWeekNumber() {
1278
+ return this.isValid ? possiblyCachedLocalWeekData(this).weekNumber : NaN;
1279
+ }
1280
+
1281
+ /**
1282
+ * Get the week year according to the locale. Different locales assign week numbers (and therefor week years)
1283
+ * differently, see localWeekNumber.
1284
+ * @returns {number}
1285
+ */
1286
+ get localWeekYear() {
1287
+ return this.isValid ? possiblyCachedLocalWeekData(this).weekYear : NaN;
1288
+ }
1289
+
1290
+ /**
1291
+ * Get the ordinal (meaning the day of the year)
1292
+ * @example DateTime.local(2017, 5, 25).ordinal //=> 145
1293
+ * @type {number|DateTime}
1294
+ */
1295
+ get ordinal() {
1296
+ return this.isValid ? gregorianToOrdinal(this.c).ordinal : NaN;
1297
+ }
1298
+
1299
+ /**
1300
+ * Get the human readable short month name, such as 'Oct'.
1301
+ * Defaults to the system's locale if no locale has been specified
1302
+ * @example DateTime.local(2017, 10, 30).monthShort //=> Oct
1303
+ * @type {string}
1304
+ */
1305
+ get monthShort() {
1306
+ return this.isValid ? Info.months("short", { locObj: this.loc })[this.month - 1] : null;
1307
+ }
1308
+
1309
+ /**
1310
+ * Get the human readable long month name, such as 'October'.
1311
+ * Defaults to the system's locale if no locale has been specified
1312
+ * @example DateTime.local(2017, 10, 30).monthLong //=> October
1313
+ * @type {string}
1314
+ */
1315
+ get monthLong() {
1316
+ return this.isValid ? Info.months("long", { locObj: this.loc })[this.month - 1] : null;
1317
+ }
1318
+
1319
+ /**
1320
+ * Get the human readable short weekday, such as 'Mon'.
1321
+ * Defaults to the system's locale if no locale has been specified
1322
+ * @example DateTime.local(2017, 10, 30).weekdayShort //=> Mon
1323
+ * @type {string}
1324
+ */
1325
+ get weekdayShort() {
1326
+ return this.isValid ? Info.weekdays("short", { locObj: this.loc })[this.weekday - 1] : null;
1327
+ }
1328
+
1329
+ /**
1330
+ * Get the human readable long weekday, such as 'Monday'.
1331
+ * Defaults to the system's locale if no locale has been specified
1332
+ * @example DateTime.local(2017, 10, 30).weekdayLong //=> Monday
1333
+ * @type {string}
1334
+ */
1335
+ get weekdayLong() {
1336
+ return this.isValid ? Info.weekdays("long", { locObj: this.loc })[this.weekday - 1] : null;
1337
+ }
1338
+
1339
+ /**
1340
+ * Get the UTC offset of this DateTime in minutes
1341
+ * @example DateTime.now().offset //=> -240
1342
+ * @example DateTime.utc().offset //=> 0
1343
+ * @type {number}
1344
+ */
1345
+ get offset() {
1346
+ return this.isValid ? +this.o : NaN;
1347
+ }
1348
+
1349
+ /**
1350
+ * Get the short human name for the zone's current offset, for example "EST" or "EDT".
1351
+ * Defaults to the system's locale if no locale has been specified
1352
+ * @type {string}
1353
+ */
1354
+ get offsetNameShort() {
1355
+ if (this.isValid) {
1356
+ return this.zone.offsetName(this.ts, {
1357
+ format: "short",
1358
+ locale: this.locale,
1359
+ });
1360
+ } else {
1361
+ return null;
1362
+ }
1363
+ }
1364
+
1365
+ /**
1366
+ * Get the long human name for the zone's current offset, for example "Eastern Standard Time" or "Eastern Daylight Time".
1367
+ * Defaults to the system's locale if no locale has been specified
1368
+ * @type {string}
1369
+ */
1370
+ get offsetNameLong() {
1371
+ if (this.isValid) {
1372
+ return this.zone.offsetName(this.ts, {
1373
+ format: "long",
1374
+ locale: this.locale,
1375
+ });
1376
+ } else {
1377
+ return null;
1378
+ }
1379
+ }
1380
+
1381
+ /**
1382
+ * Get whether this zone's offset ever changes, as in a DST.
1383
+ * @type {boolean}
1384
+ */
1385
+ get isOffsetFixed() {
1386
+ return this.isValid ? this.zone.isUniversal : null;
1387
+ }
1388
+
1389
+ /**
1390
+ * Get whether the DateTime is in a DST.
1391
+ * @type {boolean}
1392
+ */
1393
+ get isInDST() {
1394
+ if (this.isOffsetFixed) {
1395
+ return false;
1396
+ } else {
1397
+ return (
1398
+ this.offset > this.set({ month: 1, day: 1 }).offset ||
1399
+ this.offset > this.set({ month: 5 }).offset
1400
+ );
1401
+ }
1402
+ }
1403
+
1404
+ /**
1405
+ * Get those DateTimes which have the same local time as this DateTime, but a different offset from UTC
1406
+ * in this DateTime's zone. During DST changes local time can be ambiguous, for example
1407
+ * `2023-10-29T02:30:00` in `Europe/Berlin` can have offset `+01:00` or `+02:00`.
1408
+ * This method will return both possible DateTimes if this DateTime's local time is ambiguous.
1409
+ * @returns {DateTime[]}
1410
+ */
1411
+ getPossibleOffsets() {
1412
+ if (!this.isValid || this.isOffsetFixed) {
1413
+ return [this];
1414
+ }
1415
+ const dayMs = 86400000;
1416
+ const minuteMs = 60000;
1417
+ const localTS = objToLocalTS(this.c);
1418
+ const oEarlier = this.zone.offset(localTS - dayMs);
1419
+ const oLater = this.zone.offset(localTS + dayMs);
1420
+
1421
+ const o1 = this.zone.offset(localTS - oEarlier * minuteMs);
1422
+ const o2 = this.zone.offset(localTS - oLater * minuteMs);
1423
+ if (o1 === o2) {
1424
+ return [this];
1425
+ }
1426
+ const ts1 = localTS - o1 * minuteMs;
1427
+ const ts2 = localTS - o2 * minuteMs;
1428
+ const c1 = tsToObj(ts1, o1);
1429
+ const c2 = tsToObj(ts2, o2);
1430
+ if (
1431
+ c1.hour === c2.hour &&
1432
+ c1.minute === c2.minute &&
1433
+ c1.second === c2.second &&
1434
+ c1.millisecond === c2.millisecond
1435
+ ) {
1436
+ return [clone(this, { ts: ts1 }), clone(this, { ts: ts2 })];
1437
+ }
1438
+ return [this];
1439
+ }
1440
+
1441
+ /**
1442
+ * Returns true if this DateTime is in a leap year, false otherwise
1443
+ * @example DateTime.local(2016).isInLeapYear //=> true
1444
+ * @example DateTime.local(2013).isInLeapYear //=> false
1445
+ * @type {boolean}
1446
+ */
1447
+ get isInLeapYear() {
1448
+ return isLeapYear(this.year);
1449
+ }
1450
+
1451
+ /**
1452
+ * Returns the number of days in this DateTime's month
1453
+ * @example DateTime.local(2016, 2).daysInMonth //=> 29
1454
+ * @example DateTime.local(2016, 3).daysInMonth //=> 31
1455
+ * @type {number}
1456
+ */
1457
+ get daysInMonth() {
1458
+ return daysInMonth(this.year, this.month);
1459
+ }
1460
+
1461
+ /**
1462
+ * Returns the number of days in this DateTime's year
1463
+ * @example DateTime.local(2016).daysInYear //=> 366
1464
+ * @example DateTime.local(2013).daysInYear //=> 365
1465
+ * @type {number}
1466
+ */
1467
+ get daysInYear() {
1468
+ return this.isValid ? daysInYear(this.year) : NaN;
1469
+ }
1470
+
1471
+ /**
1472
+ * Returns the number of weeks in this DateTime's year
1473
+ * @see https://en.wikipedia.org/wiki/ISO_week_date
1474
+ * @example DateTime.local(2004).weeksInWeekYear //=> 53
1475
+ * @example DateTime.local(2013).weeksInWeekYear //=> 52
1476
+ * @type {number}
1477
+ */
1478
+ get weeksInWeekYear() {
1479
+ return this.isValid ? weeksInWeekYear(this.weekYear) : NaN;
1480
+ }
1481
+
1482
+ /**
1483
+ * Returns the number of weeks in this DateTime's local week year
1484
+ * @example DateTime.local(2020, 6, {locale: 'en-US'}).weeksInLocalWeekYear //=> 52
1485
+ * @example DateTime.local(2020, 6, {locale: 'de-DE'}).weeksInLocalWeekYear //=> 53
1486
+ * @type {number}
1487
+ */
1488
+ get weeksInLocalWeekYear() {
1489
+ return this.isValid
1490
+ ? weeksInWeekYear(
1491
+ this.localWeekYear,
1492
+ this.loc.getMinDaysInFirstWeek(),
1493
+ this.loc.getStartOfWeek()
1494
+ )
1495
+ : NaN;
1496
+ }
1497
+
1498
+ /**
1499
+ * Returns the resolved Intl options for this DateTime.
1500
+ * This is useful in understanding the behavior of formatting methods
1501
+ * @param {Object} opts - the same options as toLocaleString
1502
+ * @return {Object}
1503
+ */
1504
+ resolvedLocaleOptions(opts = {}) {
1505
+ const { locale, numberingSystem, calendar } = Formatter.create(
1506
+ this.loc.clone(opts),
1507
+ opts
1508
+ ).resolvedOptions(this);
1509
+ return { locale, numberingSystem, outputCalendar: calendar };
1510
+ }
1511
+
1512
+ // TRANSFORM
1513
+
1514
+ /**
1515
+ * "Set" the DateTime's zone to UTC. Returns a newly-constructed DateTime.
1516
+ *
1517
+ * Equivalent to {@link DateTime#setZone}('utc')
1518
+ * @param {number} [offset=0] - optionally, an offset from UTC in minutes
1519
+ * @param {Object} [opts={}] - options to pass to `setZone()`
1520
+ * @return {DateTime}
1521
+ */
1522
+ toUTC(offset = 0, opts = {}) {
1523
+ return this.setZone(FixedOffsetZone.instance(offset), opts);
1524
+ }
1525
+
1526
+ /**
1527
+ * "Set" the DateTime's zone to the host's local zone. Returns a newly-constructed DateTime.
1528
+ *
1529
+ * Equivalent to `setZone('local')`
1530
+ * @return {DateTime}
1531
+ */
1532
+ toLocal() {
1533
+ return this.setZone(Settings.defaultZone);
1534
+ }
1535
+
1536
+ /**
1537
+ * "Set" the DateTime's zone to specified zone. Returns a newly-constructed DateTime.
1538
+ *
1539
+ * By default, the setter keeps the underlying time the same (as in, the same timestamp), but the new instance will report different local times and consider DSTs when making computations, as with {@link DateTime#plus}. You may wish to use {@link DateTime#toLocal} and {@link DateTime#toUTC} which provide simple convenience wrappers for commonly used zones.
1540
+ * @param {string|Zone} [zone='local'] - a zone identifier. As a string, that can be any IANA zone supported by the host environment, or a fixed-offset name of the form 'UTC+3', or the strings 'local' or 'utc'. You may also supply an instance of a {@link DateTime#Zone} class.
1541
+ * @param {Object} opts - options
1542
+ * @param {boolean} [opts.keepLocalTime=false] - If true, adjust the underlying time so that the local time stays the same, but in the target zone. You should rarely need this.
1543
+ * @return {DateTime}
1544
+ */
1545
+ setZone(zone, { keepLocalTime = false, keepCalendarTime = false } = {}) {
1546
+ zone = normalizeZone(zone, Settings.defaultZone);
1547
+ if (zone.equals(this.zone)) {
1548
+ return this;
1549
+ } else if (!zone.isValid) {
1550
+ return DateTime.invalid(unsupportedZone(zone));
1551
+ } else {
1552
+ let newTS = this.ts;
1553
+ if (keepLocalTime || keepCalendarTime) {
1554
+ const offsetGuess = zone.offset(this.ts);
1555
+ const asObj = this.toObject();
1556
+ [newTS] = objToTS(asObj, offsetGuess, zone);
1557
+ }
1558
+ return clone(this, { ts: newTS, zone });
1559
+ }
1560
+ }
1561
+
1562
+ /**
1563
+ * "Set" the locale, numberingSystem, or outputCalendar. Returns a newly-constructed DateTime.
1564
+ * @param {Object} properties - the properties to set
1565
+ * @example DateTime.local(2017, 5, 25).reconfigure({ locale: 'en-GB' })
1566
+ * @return {DateTime}
1567
+ */
1568
+ reconfigure({ locale, numberingSystem, outputCalendar } = {}) {
1569
+ const loc = this.loc.clone({ locale, numberingSystem, outputCalendar });
1570
+ return clone(this, { loc });
1571
+ }
1572
+
1573
+ /**
1574
+ * "Set" the locale. Returns a newly-constructed DateTime.
1575
+ * Just a convenient alias for reconfigure({ locale })
1576
+ * @example DateTime.local(2017, 5, 25).setLocale('en-GB')
1577
+ * @return {DateTime}
1578
+ */
1579
+ setLocale(locale) {
1580
+ return this.reconfigure({ locale });
1581
+ }
1582
+
1583
+ /**
1584
+ * "Set" the values of specified units. Returns a newly-constructed DateTime.
1585
+ * You can only set units with this method; for "setting" metadata, see {@link DateTime#reconfigure} and {@link DateTime#setZone}.
1586
+ *
1587
+ * This method also supports setting locale-based week units, i.e. `localWeekday`, `localWeekNumber` and `localWeekYear`.
1588
+ * They cannot be mixed with ISO-week units like `weekday`.
1589
+ * @param {Object} values - a mapping of units to numbers
1590
+ * @example dt.set({ year: 2017 })
1591
+ * @example dt.set({ hour: 8, minute: 30 })
1592
+ * @example dt.set({ weekday: 5 })
1593
+ * @example dt.set({ year: 2005, ordinal: 234 })
1594
+ * @return {DateTime}
1595
+ */
1596
+ set(values) {
1597
+ if (!this.isValid) return this;
1598
+
1599
+ const normalized = normalizeObject(values, normalizeUnitWithLocalWeeks);
1600
+ const { minDaysInFirstWeek, startOfWeek } = usesLocalWeekValues(normalized, this.loc);
1601
+
1602
+ const settingWeekStuff =
1603
+ !isUndefined(normalized.weekYear) ||
1604
+ !isUndefined(normalized.weekNumber) ||
1605
+ !isUndefined(normalized.weekday),
1606
+ containsOrdinal = !isUndefined(normalized.ordinal),
1607
+ containsGregorYear = !isUndefined(normalized.year),
1608
+ containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
1609
+ containsGregor = containsGregorYear || containsGregorMD,
1610
+ definiteWeekDef = normalized.weekYear || normalized.weekNumber;
1611
+
1612
+ if ((containsGregor || containsOrdinal) && definiteWeekDef) {
1613
+ throw new ConflictingSpecificationError(
1614
+ "Can't mix weekYear/weekNumber units with year/month/day or ordinals"
1615
+ );
1616
+ }
1617
+
1618
+ if (containsGregorMD && containsOrdinal) {
1619
+ throw new ConflictingSpecificationError("Can't mix ordinal dates with month/day");
1620
+ }
1621
+
1622
+ let mixed;
1623
+ if (settingWeekStuff) {
1624
+ mixed = weekToGregorian(
1625
+ { ...gregorianToWeek(this.c, minDaysInFirstWeek, startOfWeek), ...normalized },
1626
+ minDaysInFirstWeek,
1627
+ startOfWeek
1628
+ );
1629
+ } else if (!isUndefined(normalized.ordinal)) {
1630
+ mixed = ordinalToGregorian({ ...gregorianToOrdinal(this.c), ...normalized });
1631
+ } else {
1632
+ mixed = { ...this.toObject(), ...normalized };
1633
+
1634
+ // if we didn't set the day but we ended up on an overflow date,
1635
+ // use the last day of the right month
1636
+ if (isUndefined(normalized.day)) {
1637
+ mixed.day = Math.min(daysInMonth(mixed.year, mixed.month), mixed.day);
1638
+ }
1639
+ }
1640
+
1641
+ const [ts, o] = objToTS(mixed, this.o, this.zone);
1642
+ return clone(this, { ts, o });
1643
+ }
1644
+
1645
+ /**
1646
+ * Add a period of time to this DateTime and return the resulting DateTime
1647
+ *
1648
+ * Adding hours, minutes, seconds, or milliseconds increases the timestamp by the right number of milliseconds. Adding days, months, or years shifts the calendar, accounting for DSTs and leap years along the way. Thus, `dt.plus({ hours: 24 })` may result in a different time than `dt.plus({ days: 1 })` if there's a DST shift in between.
1649
+ * @param {Duration|Object|number} duration - The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
1650
+ * @example DateTime.now().plus(123) //~> in 123 milliseconds
1651
+ * @example DateTime.now().plus({ minutes: 15 }) //~> in 15 minutes
1652
+ * @example DateTime.now().plus({ days: 1 }) //~> this time tomorrow
1653
+ * @example DateTime.now().plus({ days: -1 }) //~> this time yesterday
1654
+ * @example DateTime.now().plus({ hours: 3, minutes: 13 }) //~> in 3 hr, 13 min
1655
+ * @example DateTime.now().plus(Duration.fromObject({ hours: 3, minutes: 13 })) //~> in 3 hr, 13 min
1656
+ * @return {DateTime}
1657
+ */
1658
+ plus(duration) {
1659
+ if (!this.isValid) return this;
1660
+ const dur = Duration.fromDurationLike(duration);
1661
+ return clone(this, adjustTime(this, dur));
1662
+ }
1663
+
1664
+ /**
1665
+ * Subtract a period of time to this DateTime and return the resulting DateTime
1666
+ * See {@link DateTime#plus}
1667
+ * @param {Duration|Object|number} duration - The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
1668
+ @return {DateTime}
1669
+ */
1670
+ minus(duration) {
1671
+ if (!this.isValid) return this;
1672
+ const dur = Duration.fromDurationLike(duration).negate();
1673
+ return clone(this, adjustTime(this, dur));
1674
+ }
1675
+
1676
+ /**
1677
+ * "Set" this DateTime to the beginning of a unit of time.
1678
+ * @param {string} unit - The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
1679
+ * @param {Object} opts - options
1680
+ * @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week
1681
+ * @example DateTime.local(2014, 3, 3).startOf('month').toISODate(); //=> '2014-03-01'
1682
+ * @example DateTime.local(2014, 3, 3).startOf('year').toISODate(); //=> '2014-01-01'
1683
+ * @example DateTime.local(2014, 3, 3).startOf('week').toISODate(); //=> '2014-03-03', weeks always start on Mondays
1684
+ * @example DateTime.local(2014, 3, 3, 5, 30).startOf('day').toISOTime(); //=> '00:00.000-05:00'
1685
+ * @example DateTime.local(2014, 3, 3, 5, 30).startOf('hour').toISOTime(); //=> '05:00:00.000-05:00'
1686
+ * @return {DateTime}
1687
+ */
1688
+ startOf(unit, { useLocaleWeeks = false } = {}) {
1689
+ if (!this.isValid) return this;
1690
+
1691
+ const o = {},
1692
+ normalizedUnit = Duration.normalizeUnit(unit);
1693
+ switch (normalizedUnit) {
1694
+ case "years":
1695
+ o.month = 1;
1696
+ // falls through
1697
+ case "quarters":
1698
+ case "months":
1699
+ o.day = 1;
1700
+ // falls through
1701
+ case "weeks":
1702
+ case "days":
1703
+ o.hour = 0;
1704
+ // falls through
1705
+ case "hours":
1706
+ o.minute = 0;
1707
+ // falls through
1708
+ case "minutes":
1709
+ o.second = 0;
1710
+ // falls through
1711
+ case "seconds":
1712
+ o.millisecond = 0;
1713
+ break;
1714
+ case "milliseconds":
1715
+ break;
1716
+ // no default, invalid units throw in normalizeUnit()
1717
+ }
1718
+
1719
+ if (normalizedUnit === "weeks") {
1720
+ if (useLocaleWeeks) {
1721
+ const startOfWeek = this.loc.getStartOfWeek();
1722
+ const { weekday } = this;
1723
+ if (weekday < startOfWeek) {
1724
+ o.weekNumber = this.weekNumber - 1;
1725
+ }
1726
+ o.weekday = startOfWeek;
1727
+ } else {
1728
+ o.weekday = 1;
1729
+ }
1730
+ }
1731
+
1732
+ if (normalizedUnit === "quarters") {
1733
+ const q = Math.ceil(this.month / 3);
1734
+ o.month = (q - 1) * 3 + 1;
1735
+ }
1736
+
1737
+ return this.set(o);
1738
+ }
1739
+
1740
+ /**
1741
+ * "Set" this DateTime to the end (meaning the last millisecond) of a unit of time
1742
+ * @param {string} unit - The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
1743
+ * @param {Object} opts - options
1744
+ * @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week
1745
+ * @example DateTime.local(2014, 3, 3).endOf('month').toISO(); //=> '2014-03-31T23:59:59.999-05:00'
1746
+ * @example DateTime.local(2014, 3, 3).endOf('year').toISO(); //=> '2014-12-31T23:59:59.999-05:00'
1747
+ * @example DateTime.local(2014, 3, 3).endOf('week').toISO(); // => '2014-03-09T23:59:59.999-05:00', weeks start on Mondays
1748
+ * @example DateTime.local(2014, 3, 3, 5, 30).endOf('day').toISO(); //=> '2014-03-03T23:59:59.999-05:00'
1749
+ * @example DateTime.local(2014, 3, 3, 5, 30).endOf('hour').toISO(); //=> '2014-03-03T05:59:59.999-05:00'
1750
+ * @return {DateTime}
1751
+ */
1752
+ endOf(unit, opts) {
1753
+ return this.isValid
1754
+ ? this.plus({ [unit]: 1 })
1755
+ .startOf(unit, opts)
1756
+ .minus(1)
1757
+ : this;
1758
+ }
1759
+
1760
+ // OUTPUT
1761
+
1762
+ /**
1763
+ * Returns a string representation of this DateTime formatted according to the specified format string.
1764
+ * **You may not want this.** See {@link DateTime#toLocaleString} for a more flexible formatting tool. For a table of tokens and their interpretations, see [here](https://moment.github.io/luxon/#/formatting?id=table-of-tokens).
1765
+ * Defaults to en-US if no locale has been specified, regardless of the system's locale.
1766
+ * @param {string} fmt - the format string
1767
+ * @param {Object} opts - opts to override the configuration options on this DateTime
1768
+ * @example DateTime.now().toFormat('yyyy LLL dd') //=> '2017 Apr 22'
1769
+ * @example DateTime.now().setLocale('fr').toFormat('yyyy LLL dd') //=> '2017 avr. 22'
1770
+ * @example DateTime.now().toFormat('yyyy LLL dd', { locale: "fr" }) //=> '2017 avr. 22'
1771
+ * @example DateTime.now().toFormat("HH 'hours and' mm 'minutes'") //=> '20 hours and 55 minutes'
1772
+ * @return {string}
1773
+ */
1774
+ toFormat(fmt, opts = {}) {
1775
+ return this.isValid
1776
+ ? Formatter.create(this.loc.redefaultToEN(opts)).formatDateTimeFromString(this, fmt)
1777
+ : INVALID;
1778
+ }
1779
+
1780
+ /**
1781
+ * Returns a localized string representing this date. Accepts the same options as the Intl.DateTimeFormat constructor and any presets defined by Luxon, such as `DateTime.DATE_FULL` or `DateTime.TIME_SIMPLE`.
1782
+ * The exact behavior of this method is browser-specific, but in general it will return an appropriate representation
1783
+ * of the DateTime in the assigned locale.
1784
+ * Defaults to the system's locale if no locale has been specified
1785
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
1786
+ * @param formatOpts {Object} - Intl.DateTimeFormat constructor options and configuration options
1787
+ * @param {Object} opts - opts to override the configuration options on this DateTime
1788
+ * @example DateTime.now().toLocaleString(); //=> 4/20/2017
1789
+ * @example DateTime.now().setLocale('en-gb').toLocaleString(); //=> '20/04/2017'
1790
+ * @example DateTime.now().toLocaleString(DateTime.DATE_FULL); //=> 'April 20, 2017'
1791
+ * @example DateTime.now().toLocaleString(DateTime.DATE_FULL, { locale: 'fr' }); //=> '28 août 2022'
1792
+ * @example DateTime.now().toLocaleString(DateTime.TIME_SIMPLE); //=> '11:32 AM'
1793
+ * @example DateTime.now().toLocaleString(DateTime.DATETIME_SHORT); //=> '4/20/2017, 11:32 AM'
1794
+ * @example DateTime.now().toLocaleString({ weekday: 'long', month: 'long', day: '2-digit' }); //=> 'Thursday, April 20'
1795
+ * @example DateTime.now().toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> 'Thu, Apr 20, 11:27 AM'
1796
+ * @example DateTime.now().toLocaleString({ hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }); //=> '11:32'
1797
+ * @return {string}
1798
+ */
1799
+ toLocaleString(formatOpts = Formats.DATE_SHORT, opts = {}) {
1800
+ return this.isValid
1801
+ ? Formatter.create(this.loc.clone(opts), formatOpts).formatDateTime(this)
1802
+ : INVALID;
1803
+ }
1804
+
1805
+ /**
1806
+ * Returns an array of format "parts", meaning individual tokens along with metadata. This is allows callers to post-process individual sections of the formatted output.
1807
+ * Defaults to the system's locale if no locale has been specified
1808
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts
1809
+ * @param opts {Object} - Intl.DateTimeFormat constructor options, same as `toLocaleString`.
1810
+ * @example DateTime.now().toLocaleParts(); //=> [
1811
+ * //=> { type: 'day', value: '25' },
1812
+ * //=> { type: 'literal', value: '/' },
1813
+ * //=> { type: 'month', value: '05' },
1814
+ * //=> { type: 'literal', value: '/' },
1815
+ * //=> { type: 'year', value: '1982' }
1816
+ * //=> ]
1817
+ */
1818
+ toLocaleParts(opts = {}) {
1819
+ return this.isValid
1820
+ ? Formatter.create(this.loc.clone(opts), opts).formatDateTimeParts(this)
1821
+ : [];
1822
+ }
1823
+
1824
+ /**
1825
+ * Returns an ISO 8601-compliant string representation of this DateTime
1826
+ * @param {Object} opts - options
1827
+ * @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0
1828
+ * @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0
1829
+ * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
1830
+ * @param {boolean} [opts.extendedZone=false] - add the time zone format extension
1831
+ * @param {string} [opts.format='extended'] - choose between the basic and extended format
1832
+ * @example DateTime.utc(1983, 5, 25).toISO() //=> '1982-05-25T00:00:00.000Z'
1833
+ * @example DateTime.now().toISO() //=> '2017-04-22T20:47:05.335-04:00'
1834
+ * @example DateTime.now().toISO({ includeOffset: false }) //=> '2017-04-22T20:47:05.335'
1835
+ * @example DateTime.now().toISO({ format: 'basic' }) //=> '20170422T204705.335-0400'
1836
+ * @return {string|null}
1837
+ */
1838
+ toISO({
1839
+ format = "extended",
1840
+ suppressSeconds = false,
1841
+ suppressMilliseconds = false,
1842
+ includeOffset = true,
1843
+ extendedZone = false,
1844
+ } = {}) {
1845
+ if (!this.isValid) {
1846
+ return null;
1847
+ }
1848
+
1849
+ const ext = format === "extended";
1850
+
1851
+ let c = toISODate(this, ext);
1852
+ c += "T";
1853
+ c += toISOTime(this, ext, suppressSeconds, suppressMilliseconds, includeOffset, extendedZone);
1854
+ return c;
1855
+ }
1856
+
1857
+ /**
1858
+ * Returns an ISO 8601-compliant string representation of this DateTime's date component
1859
+ * @param {Object} opts - options
1860
+ * @param {string} [opts.format='extended'] - choose between the basic and extended format
1861
+ * @example DateTime.utc(1982, 5, 25).toISODate() //=> '1982-05-25'
1862
+ * @example DateTime.utc(1982, 5, 25).toISODate({ format: 'basic' }) //=> '19820525'
1863
+ * @return {string|null}
1864
+ */
1865
+ toISODate({ format = "extended" } = {}) {
1866
+ if (!this.isValid) {
1867
+ return null;
1868
+ }
1869
+
1870
+ return toISODate(this, format === "extended");
1871
+ }
1872
+
1873
+ /**
1874
+ * Returns an ISO 8601-compliant string representation of this DateTime's week date
1875
+ * @example DateTime.utc(1982, 5, 25).toISOWeekDate() //=> '1982-W21-2'
1876
+ * @return {string}
1877
+ */
1878
+ toISOWeekDate() {
1879
+ return toTechFormat(this, "kkkk-'W'WW-c");
1880
+ }
1881
+
1882
+ /**
1883
+ * Returns an ISO 8601-compliant string representation of this DateTime's time component
1884
+ * @param {Object} opts - options
1885
+ * @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0
1886
+ * @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0
1887
+ * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
1888
+ * @param {boolean} [opts.extendedZone=true] - add the time zone format extension
1889
+ * @param {boolean} [opts.includePrefix=false] - include the `T` prefix
1890
+ * @param {string} [opts.format='extended'] - choose between the basic and extended format
1891
+ * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime() //=> '07:34:19.361Z'
1892
+ * @example DateTime.utc().set({ hour: 7, minute: 34, seconds: 0, milliseconds: 0 }).toISOTime({ suppressSeconds: true }) //=> '07:34Z'
1893
+ * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ format: 'basic' }) //=> '073419.361Z'
1894
+ * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ includePrefix: true }) //=> 'T07:34:19.361Z'
1895
+ * @return {string}
1896
+ */
1897
+ toISOTime({
1898
+ suppressMilliseconds = false,
1899
+ suppressSeconds = false,
1900
+ includeOffset = true,
1901
+ includePrefix = false,
1902
+ extendedZone = false,
1903
+ format = "extended",
1904
+ } = {}) {
1905
+ if (!this.isValid) {
1906
+ return null;
1907
+ }
1908
+
1909
+ let c = includePrefix ? "T" : "";
1910
+ return (
1911
+ c +
1912
+ toISOTime(
1913
+ this,
1914
+ format === "extended",
1915
+ suppressSeconds,
1916
+ suppressMilliseconds,
1917
+ includeOffset,
1918
+ extendedZone
1919
+ )
1920
+ );
1921
+ }
1922
+
1923
+ /**
1924
+ * Returns an RFC 2822-compatible string representation of this DateTime
1925
+ * @example DateTime.utc(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 +0000'
1926
+ * @example DateTime.local(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 -0400'
1927
+ * @return {string}
1928
+ */
1929
+ toRFC2822() {
1930
+ return toTechFormat(this, "EEE, dd LLL yyyy HH:mm:ss ZZZ", false);
1931
+ }
1932
+
1933
+ /**
1934
+ * Returns a string representation of this DateTime appropriate for use in HTTP headers. The output is always expressed in GMT.
1935
+ * Specifically, the string conforms to RFC 1123.
1936
+ * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
1937
+ * @example DateTime.utc(2014, 7, 13).toHTTP() //=> 'Sun, 13 Jul 2014 00:00:00 GMT'
1938
+ * @example DateTime.utc(2014, 7, 13, 19).toHTTP() //=> 'Sun, 13 Jul 2014 19:00:00 GMT'
1939
+ * @return {string}
1940
+ */
1941
+ toHTTP() {
1942
+ return toTechFormat(this.toUTC(), "EEE, dd LLL yyyy HH:mm:ss 'GMT'");
1943
+ }
1944
+
1945
+ /**
1946
+ * Returns a string representation of this DateTime appropriate for use in SQL Date
1947
+ * @example DateTime.utc(2014, 7, 13).toSQLDate() //=> '2014-07-13'
1948
+ * @return {string|null}
1949
+ */
1950
+ toSQLDate() {
1951
+ if (!this.isValid) {
1952
+ return null;
1953
+ }
1954
+ return toISODate(this, true);
1955
+ }
1956
+
1957
+ /**
1958
+ * Returns a string representation of this DateTime appropriate for use in SQL Time
1959
+ * @param {Object} opts - options
1960
+ * @param {boolean} [opts.includeZone=false] - include the zone, such as 'America/New_York'. Overrides includeOffset.
1961
+ * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
1962
+ * @param {boolean} [opts.includeOffsetSpace=true] - include the space between the time and the offset, such as '05:15:16.345 -04:00'
1963
+ * @example DateTime.utc().toSQL() //=> '05:15:16.345'
1964
+ * @example DateTime.now().toSQL() //=> '05:15:16.345 -04:00'
1965
+ * @example DateTime.now().toSQL({ includeOffset: false }) //=> '05:15:16.345'
1966
+ * @example DateTime.now().toSQL({ includeZone: false }) //=> '05:15:16.345 America/New_York'
1967
+ * @return {string}
1968
+ */
1969
+ toSQLTime({ includeOffset = true, includeZone = false, includeOffsetSpace = true } = {}) {
1970
+ let fmt = "HH:mm:ss.SSS";
1971
+
1972
+ if (includeZone || includeOffset) {
1973
+ if (includeOffsetSpace) {
1974
+ fmt += " ";
1975
+ }
1976
+ if (includeZone) {
1977
+ fmt += "z";
1978
+ } else if (includeOffset) {
1979
+ fmt += "ZZ";
1980
+ }
1981
+ }
1982
+
1983
+ return toTechFormat(this, fmt, true);
1984
+ }
1985
+
1986
+ /**
1987
+ * Returns a string representation of this DateTime appropriate for use in SQL DateTime
1988
+ * @param {Object} opts - options
1989
+ * @param {boolean} [opts.includeZone=false] - include the zone, such as 'America/New_York'. Overrides includeOffset.
1990
+ * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
1991
+ * @param {boolean} [opts.includeOffsetSpace=true] - include the space between the time and the offset, such as '05:15:16.345 -04:00'
1992
+ * @example DateTime.utc(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 Z'
1993
+ * @example DateTime.local(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 -04:00'
1994
+ * @example DateTime.local(2014, 7, 13).toSQL({ includeOffset: false }) //=> '2014-07-13 00:00:00.000'
1995
+ * @example DateTime.local(2014, 7, 13).toSQL({ includeZone: true }) //=> '2014-07-13 00:00:00.000 America/New_York'
1996
+ * @return {string}
1997
+ */
1998
+ toSQL(opts = {}) {
1999
+ if (!this.isValid) {
2000
+ return null;
2001
+ }
2002
+
2003
+ return `${this.toSQLDate()} ${this.toSQLTime(opts)}`;
2004
+ }
2005
+
2006
+ /**
2007
+ * Returns a string representation of this DateTime appropriate for debugging
2008
+ * @return {string}
2009
+ */
2010
+ toString() {
2011
+ return this.isValid ? this.toISO() : INVALID;
2012
+ }
2013
+
2014
+ /**
2015
+ * Returns a string representation of this DateTime appropriate for the REPL.
2016
+ * @return {string}
2017
+ */
2018
+ [Symbol.for("nodejs.util.inspect.custom")]() {
2019
+ if (this.isValid) {
2020
+ return `DateTime { ts: ${this.toISO()}, zone: ${this.zone.name}, locale: ${this.locale} }`;
2021
+ } else {
2022
+ return `DateTime { Invalid, reason: ${this.invalidReason} }`;
2023
+ }
2024
+ }
2025
+
2026
+ /**
2027
+ * Returns the epoch milliseconds of this DateTime. Alias of {@link DateTime#toMillis}
2028
+ * @return {number}
2029
+ */
2030
+ valueOf() {
2031
+ return this.toMillis();
2032
+ }
2033
+
2034
+ /**
2035
+ * Returns the epoch milliseconds of this DateTime.
2036
+ * @return {number}
2037
+ */
2038
+ toMillis() {
2039
+ return this.isValid ? this.ts : NaN;
2040
+ }
2041
+
2042
+ /**
2043
+ * Returns the epoch seconds (including milliseconds in the fractional part) of this DateTime.
2044
+ * @return {number}
2045
+ */
2046
+ toSeconds() {
2047
+ return this.isValid ? this.ts / 1000 : NaN;
2048
+ }
2049
+
2050
+ /**
2051
+ * Returns the epoch seconds (as a whole number) of this DateTime.
2052
+ * @return {number}
2053
+ */
2054
+ toUnixInteger() {
2055
+ return this.isValid ? Math.floor(this.ts / 1000) : NaN;
2056
+ }
2057
+
2058
+ /**
2059
+ * Returns an ISO 8601 representation of this DateTime appropriate for use in JSON.
2060
+ * @return {string}
2061
+ */
2062
+ toJSON() {
2063
+ return this.toISO();
2064
+ }
2065
+
2066
+ /**
2067
+ * Returns a BSON serializable equivalent to this DateTime.
2068
+ * @return {Date}
2069
+ */
2070
+ toBSON() {
2071
+ return this.toJSDate();
2072
+ }
2073
+
2074
+ /**
2075
+ * Returns a JavaScript object with this DateTime's year, month, day, and so on.
2076
+ * @param opts - options for generating the object
2077
+ * @param {boolean} [opts.includeConfig=false] - include configuration attributes in the output
2078
+ * @example DateTime.now().toObject() //=> { year: 2017, month: 4, day: 22, hour: 20, minute: 49, second: 42, millisecond: 268 }
2079
+ * @return {Object}
2080
+ */
2081
+ toObject(opts = {}) {
2082
+ if (!this.isValid) return {};
2083
+
2084
+ const base = { ...this.c };
2085
+
2086
+ if (opts.includeConfig) {
2087
+ base.outputCalendar = this.outputCalendar;
2088
+ base.numberingSystem = this.loc.numberingSystem;
2089
+ base.locale = this.loc.locale;
2090
+ }
2091
+ return base;
2092
+ }
2093
+
2094
+ /**
2095
+ * Returns a JavaScript Date equivalent to this DateTime.
2096
+ * @return {Date}
2097
+ */
2098
+ toJSDate() {
2099
+ return new Date(this.isValid ? this.ts : NaN);
2100
+ }
2101
+
2102
+ // COMPARE
2103
+
2104
+ /**
2105
+ * Return the difference between two DateTimes as a Duration.
2106
+ * @param {DateTime} otherDateTime - the DateTime to compare this one to
2107
+ * @param {string|string[]} [unit=['milliseconds']] - the unit or array of units (such as 'hours' or 'days') to include in the duration.
2108
+ * @param {Object} opts - options that affect the creation of the Duration
2109
+ * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
2110
+ * @example
2111
+ * var i1 = DateTime.fromISO('1982-05-25T09:45'),
2112
+ * i2 = DateTime.fromISO('1983-10-14T10:30');
2113
+ * i2.diff(i1).toObject() //=> { milliseconds: 43807500000 }
2114
+ * i2.diff(i1, 'hours').toObject() //=> { hours: 12168.75 }
2115
+ * i2.diff(i1, ['months', 'days']).toObject() //=> { months: 16, days: 19.03125 }
2116
+ * i2.diff(i1, ['months', 'days', 'hours']).toObject() //=> { months: 16, days: 19, hours: 0.75 }
2117
+ * @return {Duration}
2118
+ */
2119
+ diff(otherDateTime, unit = "milliseconds", opts = {}) {
2120
+ if (!this.isValid || !otherDateTime.isValid) {
2121
+ return Duration.invalid("created by diffing an invalid DateTime");
2122
+ }
2123
+
2124
+ const durOpts = { locale: this.locale, numberingSystem: this.numberingSystem, ...opts };
2125
+
2126
+ const units = maybeArray(unit).map(Duration.normalizeUnit),
2127
+ otherIsLater = otherDateTime.valueOf() > this.valueOf(),
2128
+ earlier = otherIsLater ? this : otherDateTime,
2129
+ later = otherIsLater ? otherDateTime : this,
2130
+ diffed = diff(earlier, later, units, durOpts);
2131
+
2132
+ return otherIsLater ? diffed.negate() : diffed;
2133
+ }
2134
+
2135
+ /**
2136
+ * Return the difference between this DateTime and right now.
2137
+ * See {@link DateTime#diff}
2138
+ * @param {string|string[]} [unit=['milliseconds']] - the unit or units units (such as 'hours' or 'days') to include in the duration
2139
+ * @param {Object} opts - options that affect the creation of the Duration
2140
+ * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
2141
+ * @return {Duration}
2142
+ */
2143
+ diffNow(unit = "milliseconds", opts = {}) {
2144
+ return this.diff(DateTime.now(), unit, opts);
2145
+ }
2146
+
2147
+ /**
2148
+ * Return an Interval spanning between this DateTime and another DateTime
2149
+ * @param {DateTime} otherDateTime - the other end point of the Interval
2150
+ * @return {Interval|DateTime}
2151
+ */
2152
+ until(otherDateTime) {
2153
+ return this.isValid ? Interval.fromDateTimes(this, otherDateTime) : this;
2154
+ }
2155
+
2156
+ /**
2157
+ * Return whether this DateTime is in the same unit of time as another DateTime.
2158
+ * Higher-order units must also be identical for this function to return `true`.
2159
+ * Note that time zones are **ignored** in this comparison, which compares the **local** calendar time. Use {@link DateTime#setZone} to convert one of the dates if needed.
2160
+ * @param {DateTime} otherDateTime - the other DateTime
2161
+ * @param {string} unit - the unit of time to check sameness on
2162
+ * @param {Object} opts - options
2163
+ * @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week; only the locale of this DateTime is used
2164
+ * @example DateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day
2165
+ * @return {boolean}
2166
+ */
2167
+ hasSame(otherDateTime, unit, opts) {
2168
+ if (!this.isValid) return false;
2169
+
2170
+ const inputMs = otherDateTime.valueOf();
2171
+ const adjustedToZone = this.setZone(otherDateTime.zone, { keepLocalTime: true });
2172
+ return (
2173
+ adjustedToZone.startOf(unit, opts) <= inputMs && inputMs <= adjustedToZone.endOf(unit, opts)
2174
+ );
2175
+ }
2176
+
2177
+ /**
2178
+ * Equality check
2179
+ * Two DateTimes are equal if and only if they represent the same millisecond, have the same zone and location, and are both valid.
2180
+ * To compare just the millisecond values, use `+dt1 === +dt2`.
2181
+ * @param {DateTime} other - the other DateTime
2182
+ * @return {boolean}
2183
+ */
2184
+ equals(other) {
2185
+ return (
2186
+ this.isValid &&
2187
+ other.isValid &&
2188
+ this.valueOf() === other.valueOf() &&
2189
+ this.zone.equals(other.zone) &&
2190
+ this.loc.equals(other.loc)
2191
+ );
2192
+ }
2193
+
2194
+ /**
2195
+ * Returns a string representation of a this time relative to now, such as "in two days". Can only internationalize if your
2196
+ * platform supports Intl.RelativeTimeFormat. Rounds down by default.
2197
+ * @param {Object} options - options that affect the output
2198
+ * @param {DateTime} [options.base=DateTime.now()] - the DateTime to use as the basis to which this time is compared. Defaults to now.
2199
+ * @param {string} [options.style="long"] - the style of units, must be "long", "short", or "narrow"
2200
+ * @param {string|string[]} options.unit - use a specific unit or array of units; if omitted, or an array, the method will pick the best unit. Use an array or one of "years", "quarters", "months", "weeks", "days", "hours", "minutes", or "seconds"
2201
+ * @param {boolean} [options.round=true] - whether to round the numbers in the output.
2202
+ * @param {number} [options.padding=0] - padding in milliseconds. This allows you to round up the result if it fits inside the threshold. Don't use in combination with {round: false} because the decimal output will include the padding.
2203
+ * @param {string} options.locale - override the locale of this DateTime
2204
+ * @param {string} options.numberingSystem - override the numberingSystem of this DateTime. The Intl system may choose not to honor this
2205
+ * @example DateTime.now().plus({ days: 1 }).toRelative() //=> "in 1 day"
2206
+ * @example DateTime.now().setLocale("es").toRelative({ days: 1 }) //=> "dentro de 1 día"
2207
+ * @example DateTime.now().plus({ days: 1 }).toRelative({ locale: "fr" }) //=> "dans 23 heures"
2208
+ * @example DateTime.now().minus({ days: 2 }).toRelative() //=> "2 days ago"
2209
+ * @example DateTime.now().minus({ days: 2 }).toRelative({ unit: "hours" }) //=> "48 hours ago"
2210
+ * @example DateTime.now().minus({ hours: 36 }).toRelative({ round: false }) //=> "1.5 days ago"
2211
+ */
2212
+ toRelative(options = {}) {
2213
+ if (!this.isValid) return null;
2214
+ const base = options.base || DateTime.fromObject({}, { zone: this.zone }),
2215
+ padding = options.padding ? (this < base ? -options.padding : options.padding) : 0;
2216
+ let units = ["years", "months", "days", "hours", "minutes", "seconds"];
2217
+ let unit = options.unit;
2218
+ if (Array.isArray(options.unit)) {
2219
+ units = options.unit;
2220
+ unit = undefined;
2221
+ }
2222
+ return diffRelative(base, this.plus(padding), {
2223
+ ...options,
2224
+ numeric: "always",
2225
+ units,
2226
+ unit,
2227
+ });
2228
+ }
2229
+
2230
+ /**
2231
+ * Returns a string representation of this date relative to today, such as "yesterday" or "next month".
2232
+ * Only internationalizes on platforms that supports Intl.RelativeTimeFormat.
2233
+ * @param {Object} options - options that affect the output
2234
+ * @param {DateTime} [options.base=DateTime.now()] - the DateTime to use as the basis to which this time is compared. Defaults to now.
2235
+ * @param {string} options.locale - override the locale of this DateTime
2236
+ * @param {string} options.unit - use a specific unit; if omitted, the method will pick the unit. Use one of "years", "quarters", "months", "weeks", or "days"
2237
+ * @param {string} options.numberingSystem - override the numberingSystem of this DateTime. The Intl system may choose not to honor this
2238
+ * @example DateTime.now().plus({ days: 1 }).toRelativeCalendar() //=> "tomorrow"
2239
+ * @example DateTime.now().setLocale("es").plus({ days: 1 }).toRelative() //=> ""mañana"
2240
+ * @example DateTime.now().plus({ days: 1 }).toRelativeCalendar({ locale: "fr" }) //=> "demain"
2241
+ * @example DateTime.now().minus({ days: 2 }).toRelativeCalendar() //=> "2 days ago"
2242
+ */
2243
+ toRelativeCalendar(options = {}) {
2244
+ if (!this.isValid) return null;
2245
+
2246
+ return diffRelative(options.base || DateTime.fromObject({}, { zone: this.zone }), this, {
2247
+ ...options,
2248
+ numeric: "auto",
2249
+ units: ["years", "months", "days"],
2250
+ calendary: true,
2251
+ });
2252
+ }
2253
+
2254
+ /**
2255
+ * Return the min of several date times
2256
+ * @param {...DateTime} dateTimes - the DateTimes from which to choose the minimum
2257
+ * @return {DateTime} the min DateTime, or undefined if called with no argument
2258
+ */
2259
+ static min(...dateTimes) {
2260
+ if (!dateTimes.every(DateTime.isDateTime)) {
2261
+ throw new InvalidArgumentError("min requires all arguments be DateTimes");
2262
+ }
2263
+ return bestBy(dateTimes, (i) => i.valueOf(), Math.min);
2264
+ }
2265
+
2266
+ /**
2267
+ * Return the max of several date times
2268
+ * @param {...DateTime} dateTimes - the DateTimes from which to choose the maximum
2269
+ * @return {DateTime} the max DateTime, or undefined if called with no argument
2270
+ */
2271
+ static max(...dateTimes) {
2272
+ if (!dateTimes.every(DateTime.isDateTime)) {
2273
+ throw new InvalidArgumentError("max requires all arguments be DateTimes");
2274
+ }
2275
+ return bestBy(dateTimes, (i) => i.valueOf(), Math.max);
2276
+ }
2277
+
2278
+ // MISC
2279
+
2280
+ /**
2281
+ * Explain how a string would be parsed by fromFormat()
2282
+ * @param {string} text - the string to parse
2283
+ * @param {string} fmt - the format the string is expected to be in (see description)
2284
+ * @param {Object} options - options taken by fromFormat()
2285
+ * @return {Object}
2286
+ */
2287
+ static fromFormatExplain(text, fmt, options = {}) {
2288
+ const { locale = null, numberingSystem = null } = options,
2289
+ localeToUse = Locale.fromOpts({
2290
+ locale,
2291
+ numberingSystem,
2292
+ defaultToEN: true,
2293
+ });
2294
+ return explainFromTokens(localeToUse, text, fmt);
2295
+ }
2296
+
2297
+ /**
2298
+ * @deprecated use fromFormatExplain instead
2299
+ */
2300
+ static fromStringExplain(text, fmt, options = {}) {
2301
+ return DateTime.fromFormatExplain(text, fmt, options);
2302
+ }
2303
+
2304
+ /**
2305
+ * Build a parser for `fmt` using the given locale. This parser can be passed
2306
+ * to {@link DateTime.fromFormatParser} to a parse a date in this format. This
2307
+ * can be used to optimize cases where many dates need to be parsed in a
2308
+ * specific format.
2309
+ *
2310
+ * @param {String} fmt - the format the string is expected to be in (see
2311
+ * description)
2312
+ * @param {Object} options - options used to set locale and numberingSystem
2313
+ * for parser
2314
+ * @returns {TokenParser} - opaque object to be used
2315
+ */
2316
+ static buildFormatParser(fmt, options = {}) {
2317
+ const { locale = null, numberingSystem = null } = options,
2318
+ localeToUse = Locale.fromOpts({
2319
+ locale,
2320
+ numberingSystem,
2321
+ defaultToEN: true,
2322
+ });
2323
+ return new TokenParser(localeToUse, fmt);
2324
+ }
2325
+
2326
+ /**
2327
+ * Create a DateTime from an input string and format parser.
2328
+ *
2329
+ * The format parser must have been created with the same locale as this call.
2330
+ *
2331
+ * @param {String} text - the string to parse
2332
+ * @param {TokenParser} formatParser - parser from {@link DateTime.buildFormatParser}
2333
+ * @param {Object} opts - options taken by fromFormat()
2334
+ * @returns {DateTime}
2335
+ */
2336
+ static fromFormatParser(text, formatParser, opts = {}) {
2337
+ if (isUndefined(text) || isUndefined(formatParser)) {
2338
+ throw new InvalidArgumentError(
2339
+ "fromFormatParser requires an input string and a format parser"
2340
+ );
2341
+ }
2342
+ const { locale = null, numberingSystem = null } = opts,
2343
+ localeToUse = Locale.fromOpts({
2344
+ locale,
2345
+ numberingSystem,
2346
+ defaultToEN: true,
2347
+ });
2348
+
2349
+ if (!localeToUse.equals(formatParser.locale)) {
2350
+ throw new InvalidArgumentError(
2351
+ `fromFormatParser called with a locale of ${localeToUse}, ` +
2352
+ `but the format parser was created for ${formatParser.locale}`
2353
+ );
2354
+ }
2355
+
2356
+ const { result, zone, specificOffset, invalidReason } = formatParser.explainFromTokens(text);
2357
+
2358
+ if (invalidReason) {
2359
+ return DateTime.invalid(invalidReason);
2360
+ } else {
2361
+ return parseDataToDateTime(
2362
+ result,
2363
+ zone,
2364
+ opts,
2365
+ `format ${formatParser.format}`,
2366
+ text,
2367
+ specificOffset
2368
+ );
2369
+ }
2370
+ }
2371
+
2372
+ // FORMAT PRESETS
2373
+
2374
+ /**
2375
+ * {@link DateTime#toLocaleString} format like 10/14/1983
2376
+ * @type {Object}
2377
+ */
2378
+ static get DATE_SHORT() {
2379
+ return Formats.DATE_SHORT;
2380
+ }
2381
+
2382
+ /**
2383
+ * {@link DateTime#toLocaleString} format like 'Oct 14, 1983'
2384
+ * @type {Object}
2385
+ */
2386
+ static get DATE_MED() {
2387
+ return Formats.DATE_MED;
2388
+ }
2389
+
2390
+ /**
2391
+ * {@link DateTime#toLocaleString} format like 'Fri, Oct 14, 1983'
2392
+ * @type {Object}
2393
+ */
2394
+ static get DATE_MED_WITH_WEEKDAY() {
2395
+ return Formats.DATE_MED_WITH_WEEKDAY;
2396
+ }
2397
+
2398
+ /**
2399
+ * {@link DateTime#toLocaleString} format like 'October 14, 1983'
2400
+ * @type {Object}
2401
+ */
2402
+ static get DATE_FULL() {
2403
+ return Formats.DATE_FULL;
2404
+ }
2405
+
2406
+ /**
2407
+ * {@link DateTime#toLocaleString} format like 'Tuesday, October 14, 1983'
2408
+ * @type {Object}
2409
+ */
2410
+ static get DATE_HUGE() {
2411
+ return Formats.DATE_HUGE;
2412
+ }
2413
+
2414
+ /**
2415
+ * {@link DateTime#toLocaleString} format like '09:30 AM'. Only 12-hour if the locale is.
2416
+ * @type {Object}
2417
+ */
2418
+ static get TIME_SIMPLE() {
2419
+ return Formats.TIME_SIMPLE;
2420
+ }
2421
+
2422
+ /**
2423
+ * {@link DateTime#toLocaleString} format like '09:30:23 AM'. Only 12-hour if the locale is.
2424
+ * @type {Object}
2425
+ */
2426
+ static get TIME_WITH_SECONDS() {
2427
+ return Formats.TIME_WITH_SECONDS;
2428
+ }
2429
+
2430
+ /**
2431
+ * {@link DateTime#toLocaleString} format like '09:30:23 AM EDT'. Only 12-hour if the locale is.
2432
+ * @type {Object}
2433
+ */
2434
+ static get TIME_WITH_SHORT_OFFSET() {
2435
+ return Formats.TIME_WITH_SHORT_OFFSET;
2436
+ }
2437
+
2438
+ /**
2439
+ * {@link DateTime#toLocaleString} format like '09:30:23 AM Eastern Daylight Time'. Only 12-hour if the locale is.
2440
+ * @type {Object}
2441
+ */
2442
+ static get TIME_WITH_LONG_OFFSET() {
2443
+ return Formats.TIME_WITH_LONG_OFFSET;
2444
+ }
2445
+
2446
+ /**
2447
+ * {@link DateTime#toLocaleString} format like '09:30', always 24-hour.
2448
+ * @type {Object}
2449
+ */
2450
+ static get TIME_24_SIMPLE() {
2451
+ return Formats.TIME_24_SIMPLE;
2452
+ }
2453
+
2454
+ /**
2455
+ * {@link DateTime#toLocaleString} format like '09:30:23', always 24-hour.
2456
+ * @type {Object}
2457
+ */
2458
+ static get TIME_24_WITH_SECONDS() {
2459
+ return Formats.TIME_24_WITH_SECONDS;
2460
+ }
2461
+
2462
+ /**
2463
+ * {@link DateTime#toLocaleString} format like '09:30:23 EDT', always 24-hour.
2464
+ * @type {Object}
2465
+ */
2466
+ static get TIME_24_WITH_SHORT_OFFSET() {
2467
+ return Formats.TIME_24_WITH_SHORT_OFFSET;
2468
+ }
2469
+
2470
+ /**
2471
+ * {@link DateTime#toLocaleString} format like '09:30:23 Eastern Daylight Time', always 24-hour.
2472
+ * @type {Object}
2473
+ */
2474
+ static get TIME_24_WITH_LONG_OFFSET() {
2475
+ return Formats.TIME_24_WITH_LONG_OFFSET;
2476
+ }
2477
+
2478
+ /**
2479
+ * {@link DateTime#toLocaleString} format like '10/14/1983, 9:30 AM'. Only 12-hour if the locale is.
2480
+ * @type {Object}
2481
+ */
2482
+ static get DATETIME_SHORT() {
2483
+ return Formats.DATETIME_SHORT;
2484
+ }
2485
+
2486
+ /**
2487
+ * {@link DateTime#toLocaleString} format like '10/14/1983, 9:30:33 AM'. Only 12-hour if the locale is.
2488
+ * @type {Object}
2489
+ */
2490
+ static get DATETIME_SHORT_WITH_SECONDS() {
2491
+ return Formats.DATETIME_SHORT_WITH_SECONDS;
2492
+ }
2493
+
2494
+ /**
2495
+ * {@link DateTime#toLocaleString} format like 'Oct 14, 1983, 9:30 AM'. Only 12-hour if the locale is.
2496
+ * @type {Object}
2497
+ */
2498
+ static get DATETIME_MED() {
2499
+ return Formats.DATETIME_MED;
2500
+ }
2501
+
2502
+ /**
2503
+ * {@link DateTime#toLocaleString} format like 'Oct 14, 1983, 9:30:33 AM'. Only 12-hour if the locale is.
2504
+ * @type {Object}
2505
+ */
2506
+ static get DATETIME_MED_WITH_SECONDS() {
2507
+ return Formats.DATETIME_MED_WITH_SECONDS;
2508
+ }
2509
+
2510
+ /**
2511
+ * {@link DateTime#toLocaleString} format like 'Fri, 14 Oct 1983, 9:30 AM'. Only 12-hour if the locale is.
2512
+ * @type {Object}
2513
+ */
2514
+ static get DATETIME_MED_WITH_WEEKDAY() {
2515
+ return Formats.DATETIME_MED_WITH_WEEKDAY;
2516
+ }
2517
+
2518
+ /**
2519
+ * {@link DateTime#toLocaleString} format like 'October 14, 1983, 9:30 AM EDT'. Only 12-hour if the locale is.
2520
+ * @type {Object}
2521
+ */
2522
+ static get DATETIME_FULL() {
2523
+ return Formats.DATETIME_FULL;
2524
+ }
2525
+
2526
+ /**
2527
+ * {@link DateTime#toLocaleString} format like 'October 14, 1983, 9:30:33 AM EDT'. Only 12-hour if the locale is.
2528
+ * @type {Object}
2529
+ */
2530
+ static get DATETIME_FULL_WITH_SECONDS() {
2531
+ return Formats.DATETIME_FULL_WITH_SECONDS;
2532
+ }
2533
+
2534
+ /**
2535
+ * {@link DateTime#toLocaleString} format like 'Friday, October 14, 1983, 9:30 AM Eastern Daylight Time'. Only 12-hour if the locale is.
2536
+ * @type {Object}
2537
+ */
2538
+ static get DATETIME_HUGE() {
2539
+ return Formats.DATETIME_HUGE;
2540
+ }
2541
+
2542
+ /**
2543
+ * {@link DateTime#toLocaleString} format like 'Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Time'. Only 12-hour if the locale is.
2544
+ * @type {Object}
2545
+ */
2546
+ static get DATETIME_HUGE_WITH_SECONDS() {
2547
+ return Formats.DATETIME_HUGE_WITH_SECONDS;
2548
+ }
2549
+ }
2550
+
2551
+ /**
2552
+ * @private
2553
+ */
2554
+ export function friendlyDateTime(dateTimeish) {
2555
+ if (DateTime.isDateTime(dateTimeish)) {
2556
+ return dateTimeish;
2557
+ } else if (dateTimeish && dateTimeish.valueOf && isNumber(dateTimeish.valueOf())) {
2558
+ return DateTime.fromJSDate(dateTimeish);
2559
+ } else if (dateTimeish && typeof dateTimeish === "object") {
2560
+ return DateTime.fromObject(dateTimeish);
2561
+ } else {
2562
+ throw new InvalidArgumentError(
2563
+ `Unknown datetime argument: ${dateTimeish}, of type ${typeof dateTimeish}`
2564
+ );
2565
+ }
2566
+ }