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,665 @@
1
+ import DateTime, { friendlyDateTime } from "./datetime.js";
2
+ import Duration from "./duration.js";
3
+ import Settings from "./settings.js";
4
+ import { InvalidArgumentError, InvalidIntervalError } from "./errors.js";
5
+ import Invalid from "./impl/invalid.js";
6
+ import Formatter from "./impl/formatter.js";
7
+ import * as Formats from "./impl/formats.js";
8
+
9
+ const INVALID = "Invalid Interval";
10
+
11
+ // checks if the start is equal to or before the end
12
+ function validateStartEnd(start, end) {
13
+ if (!start || !start.isValid) {
14
+ return Interval.invalid("missing or invalid start");
15
+ } else if (!end || !end.isValid) {
16
+ return Interval.invalid("missing or invalid end");
17
+ } else if (end < start) {
18
+ return Interval.invalid(
19
+ "end before start",
20
+ `The end of an interval must be after its start, but you had start=${start.toISO()} and end=${end.toISO()}`
21
+ );
22
+ } else {
23
+ return null;
24
+ }
25
+ }
26
+
27
+ /**
28
+ * An Interval object represents a half-open interval of time, where each endpoint is a {@link DateTime}. Conceptually, it's a container for those two endpoints, accompanied by methods for creating, parsing, interrogating, comparing, transforming, and formatting them.
29
+ *
30
+ * Here is a brief overview of the most commonly used methods and getters in Interval:
31
+ *
32
+ * * **Creation** To create an Interval, use {@link Interval.fromDateTimes}, {@link Interval.after}, {@link Interval.before}, or {@link Interval.fromISO}.
33
+ * * **Accessors** Use {@link Interval#start} and {@link Interval#end} to get the start and end.
34
+ * * **Interrogation** To analyze the Interval, use {@link Interval#count}, {@link Interval#length}, {@link Interval#hasSame}, {@link Interval#contains}, {@link Interval#isAfter}, or {@link Interval#isBefore}.
35
+ * * **Transformation** To create other Intervals out of this one, use {@link Interval#set}, {@link Interval#splitAt}, {@link Interval#splitBy}, {@link Interval#divideEqually}, {@link Interval.merge}, {@link Interval.xor}, {@link Interval#union}, {@link Interval#intersection}, or {@link Interval#difference}.
36
+ * * **Comparison** To compare this Interval to another one, use {@link Interval#equals}, {@link Interval#overlaps}, {@link Interval#abutsStart}, {@link Interval#abutsEnd}, {@link Interval#engulfs}
37
+ * * **Output** To convert the Interval into other representations, see {@link Interval#toString}, {@link Interval#toLocaleString}, {@link Interval#toISO}, {@link Interval#toISODate}, {@link Interval#toISOTime}, {@link Interval#toFormat}, and {@link Interval#toDuration}.
38
+ */
39
+ export default class Interval {
40
+ /**
41
+ * @private
42
+ */
43
+ constructor(config) {
44
+ /**
45
+ * @access private
46
+ */
47
+ this.s = config.start;
48
+ /**
49
+ * @access private
50
+ */
51
+ this.e = config.end;
52
+ /**
53
+ * @access private
54
+ */
55
+ this.invalid = config.invalid || null;
56
+ /**
57
+ * @access private
58
+ */
59
+ this.isLuxonInterval = true;
60
+ }
61
+
62
+ /**
63
+ * Create an invalid Interval.
64
+ * @param {string} reason - simple string of why this Interval is invalid. Should not contain parameters or anything else data-dependent
65
+ * @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information
66
+ * @return {Interval}
67
+ */
68
+ static invalid(reason, explanation = null) {
69
+ if (!reason) {
70
+ throw new InvalidArgumentError("need to specify a reason the Interval is invalid");
71
+ }
72
+
73
+ const invalid = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
74
+
75
+ if (Settings.throwOnInvalid) {
76
+ throw new InvalidIntervalError(invalid);
77
+ } else {
78
+ return new Interval({ invalid });
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Create an Interval from a start DateTime and an end DateTime. Inclusive of the start but not the end.
84
+ * @param {DateTime|Date|Object} start
85
+ * @param {DateTime|Date|Object} end
86
+ * @return {Interval}
87
+ */
88
+ static fromDateTimes(start, end) {
89
+ const builtStart = friendlyDateTime(start),
90
+ builtEnd = friendlyDateTime(end);
91
+
92
+ const validateError = validateStartEnd(builtStart, builtEnd);
93
+
94
+ if (validateError == null) {
95
+ return new Interval({
96
+ start: builtStart,
97
+ end: builtEnd,
98
+ });
99
+ } else {
100
+ return validateError;
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Create an Interval from a start DateTime and a Duration to extend to.
106
+ * @param {DateTime|Date|Object} start
107
+ * @param {Duration|Object|number} duration - the length of the Interval.
108
+ * @return {Interval}
109
+ */
110
+ static after(start, duration) {
111
+ const dur = Duration.fromDurationLike(duration),
112
+ dt = friendlyDateTime(start);
113
+ return Interval.fromDateTimes(dt, dt.plus(dur));
114
+ }
115
+
116
+ /**
117
+ * Create an Interval from an end DateTime and a Duration to extend backwards to.
118
+ * @param {DateTime|Date|Object} end
119
+ * @param {Duration|Object|number} duration - the length of the Interval.
120
+ * @return {Interval}
121
+ */
122
+ static before(end, duration) {
123
+ const dur = Duration.fromDurationLike(duration),
124
+ dt = friendlyDateTime(end);
125
+ return Interval.fromDateTimes(dt.minus(dur), dt);
126
+ }
127
+
128
+ /**
129
+ * Create an Interval from an ISO 8601 string.
130
+ * Accepts `<start>/<end>`, `<start>/<duration>`, and `<duration>/<end>` formats.
131
+ * @param {string} text - the ISO string to parse
132
+ * @param {Object} [opts] - options to pass {@link DateTime#fromISO} and optionally {@link Duration#fromISO}
133
+ * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
134
+ * @return {Interval}
135
+ */
136
+ static fromISO(text, opts) {
137
+ const [s, e] = (text || "").split("/", 2);
138
+ if (s && e) {
139
+ let start, startIsValid;
140
+ try {
141
+ start = DateTime.fromISO(s, opts);
142
+ startIsValid = start.isValid;
143
+ } catch (e) {
144
+ startIsValid = false;
145
+ }
146
+
147
+ let end, endIsValid;
148
+ try {
149
+ end = DateTime.fromISO(e, opts);
150
+ endIsValid = end.isValid;
151
+ } catch (e) {
152
+ endIsValid = false;
153
+ }
154
+
155
+ if (startIsValid && endIsValid) {
156
+ return Interval.fromDateTimes(start, end);
157
+ }
158
+
159
+ if (startIsValid) {
160
+ const dur = Duration.fromISO(e, opts);
161
+ if (dur.isValid) {
162
+ return Interval.after(start, dur);
163
+ }
164
+ } else if (endIsValid) {
165
+ const dur = Duration.fromISO(s, opts);
166
+ if (dur.isValid) {
167
+ return Interval.before(end, dur);
168
+ }
169
+ }
170
+ }
171
+ return Interval.invalid("unparsable", `the input "${text}" can't be parsed as ISO 8601`);
172
+ }
173
+
174
+ /**
175
+ * Check if an object is an Interval. Works across context boundaries
176
+ * @param {object} o
177
+ * @return {boolean}
178
+ */
179
+ static isInterval(o) {
180
+ return (o && o.isLuxonInterval) || false;
181
+ }
182
+
183
+ /**
184
+ * Returns the start of the Interval
185
+ * @type {DateTime}
186
+ */
187
+ get start() {
188
+ return this.isValid ? this.s : null;
189
+ }
190
+
191
+ /**
192
+ * Returns the end of the Interval
193
+ * @type {DateTime}
194
+ */
195
+ get end() {
196
+ return this.isValid ? this.e : null;
197
+ }
198
+
199
+ /**
200
+ * Returns the last DateTime included in the interval (since end is not part of the interval)
201
+ * @type {DateTime}
202
+ */
203
+ get lastDateTime() {
204
+ return this.isValid ? (this.e ? this.e.minus(1) : null) : null;
205
+ }
206
+
207
+ /**
208
+ * Returns whether this Interval's end is at least its start, meaning that the Interval isn't 'backwards'.
209
+ * @type {boolean}
210
+ */
211
+ get isValid() {
212
+ return this.invalidReason === null;
213
+ }
214
+
215
+ /**
216
+ * Returns an error code if this Interval is invalid, or null if the Interval is valid
217
+ * @type {string}
218
+ */
219
+ get invalidReason() {
220
+ return this.invalid ? this.invalid.reason : null;
221
+ }
222
+
223
+ /**
224
+ * Returns an explanation of why this Interval became invalid, or null if the Interval is valid
225
+ * @type {string}
226
+ */
227
+ get invalidExplanation() {
228
+ return this.invalid ? this.invalid.explanation : null;
229
+ }
230
+
231
+ /**
232
+ * Returns the length of the Interval in the specified unit.
233
+ * @param {string} unit - the unit (such as 'hours' or 'days') to return the length in.
234
+ * @return {number}
235
+ */
236
+ length(unit = "milliseconds") {
237
+ return this.isValid ? this.toDuration(...[unit]).get(unit) : NaN;
238
+ }
239
+
240
+ /**
241
+ * Returns the count of minutes, hours, days, months, or years included in the Interval, even in part.
242
+ * Unlike {@link Interval#length} this counts sections of the calendar, not periods of time, e.g. specifying 'day'
243
+ * asks 'what dates are included in this interval?', not 'how many days long is this interval?'
244
+ * @param {string} [unit='milliseconds'] - the unit of time to count.
245
+ * @param {Object} opts - options
246
+ * @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week; this operation will always use the locale of the start DateTime
247
+ * @return {number}
248
+ */
249
+ count(unit = "milliseconds", opts) {
250
+ if (!this.isValid) return NaN;
251
+ const start = this.start.startOf(unit, opts);
252
+ let end;
253
+ if (opts?.useLocaleWeeks) {
254
+ end = this.end.reconfigure({ locale: start.locale });
255
+ } else {
256
+ end = this.end;
257
+ }
258
+ end = end.startOf(unit, opts);
259
+ return Math.floor(end.diff(start, unit).get(unit)) + (end.valueOf() !== this.end.valueOf());
260
+ }
261
+
262
+ /**
263
+ * Returns whether this Interval's start and end are both in the same unit of time
264
+ * @param {string} unit - the unit of time to check sameness on
265
+ * @return {boolean}
266
+ */
267
+ hasSame(unit) {
268
+ return this.isValid ? this.isEmpty() || this.e.minus(1).hasSame(this.s, unit) : false;
269
+ }
270
+
271
+ /**
272
+ * Return whether this Interval has the same start and end DateTimes.
273
+ * @return {boolean}
274
+ */
275
+ isEmpty() {
276
+ return this.s.valueOf() === this.e.valueOf();
277
+ }
278
+
279
+ /**
280
+ * Return whether this Interval's start is after the specified DateTime.
281
+ * @param {DateTime} dateTime
282
+ * @return {boolean}
283
+ */
284
+ isAfter(dateTime) {
285
+ if (!this.isValid) return false;
286
+ return this.s > dateTime;
287
+ }
288
+
289
+ /**
290
+ * Return whether this Interval's end is before the specified DateTime.
291
+ * @param {DateTime} dateTime
292
+ * @return {boolean}
293
+ */
294
+ isBefore(dateTime) {
295
+ if (!this.isValid) return false;
296
+ return this.e <= dateTime;
297
+ }
298
+
299
+ /**
300
+ * Return whether this Interval contains the specified DateTime.
301
+ * @param {DateTime} dateTime
302
+ * @return {boolean}
303
+ */
304
+ contains(dateTime) {
305
+ if (!this.isValid) return false;
306
+ return this.s <= dateTime && this.e > dateTime;
307
+ }
308
+
309
+ /**
310
+ * "Sets" the start and/or end dates. Returns a newly-constructed Interval.
311
+ * @param {Object} values - the values to set
312
+ * @param {DateTime} values.start - the starting DateTime
313
+ * @param {DateTime} values.end - the ending DateTime
314
+ * @return {Interval}
315
+ */
316
+ set({ start, end } = {}) {
317
+ if (!this.isValid) return this;
318
+ return Interval.fromDateTimes(start || this.s, end || this.e);
319
+ }
320
+
321
+ /**
322
+ * Split this Interval at each of the specified DateTimes
323
+ * @param {...DateTime} dateTimes - the unit of time to count.
324
+ * @return {Array}
325
+ */
326
+ splitAt(...dateTimes) {
327
+ if (!this.isValid) return [];
328
+ const sorted = dateTimes
329
+ .map(friendlyDateTime)
330
+ .filter((d) => this.contains(d))
331
+ .sort((a, b) => a.toMillis() - b.toMillis()),
332
+ results = [];
333
+ let { s } = this,
334
+ i = 0;
335
+
336
+ while (s < this.e) {
337
+ const added = sorted[i] || this.e,
338
+ next = +added > +this.e ? this.e : added;
339
+ results.push(Interval.fromDateTimes(s, next));
340
+ s = next;
341
+ i += 1;
342
+ }
343
+
344
+ return results;
345
+ }
346
+
347
+ /**
348
+ * Split this Interval into smaller Intervals, each of the specified length.
349
+ * Left over time is grouped into a smaller interval
350
+ * @param {Duration|Object|number} duration - The length of each resulting interval.
351
+ * @return {Array}
352
+ */
353
+ splitBy(duration) {
354
+ const dur = Duration.fromDurationLike(duration);
355
+
356
+ if (!this.isValid || !dur.isValid || dur.as("milliseconds") === 0) {
357
+ return [];
358
+ }
359
+
360
+ let { s } = this,
361
+ idx = 1,
362
+ next;
363
+
364
+ const results = [];
365
+ while (s < this.e) {
366
+ const added = this.start.plus(dur.mapUnits((x) => x * idx));
367
+ next = +added > +this.e ? this.e : added;
368
+ results.push(Interval.fromDateTimes(s, next));
369
+ s = next;
370
+ idx += 1;
371
+ }
372
+
373
+ return results;
374
+ }
375
+
376
+ /**
377
+ * Split this Interval into the specified number of smaller intervals.
378
+ * @param {number} numberOfParts - The number of Intervals to divide the Interval into.
379
+ * @return {Array}
380
+ */
381
+ divideEqually(numberOfParts) {
382
+ if (!this.isValid) return [];
383
+ return this.splitBy(this.length() / numberOfParts).slice(0, numberOfParts);
384
+ }
385
+
386
+ /**
387
+ * Return whether this Interval overlaps with the specified Interval
388
+ * @param {Interval} other
389
+ * @return {boolean}
390
+ */
391
+ overlaps(other) {
392
+ return this.e > other.s && this.s < other.e;
393
+ }
394
+
395
+ /**
396
+ * Return whether this Interval's end is adjacent to the specified Interval's start.
397
+ * @param {Interval} other
398
+ * @return {boolean}
399
+ */
400
+ abutsStart(other) {
401
+ if (!this.isValid) return false;
402
+ return +this.e === +other.s;
403
+ }
404
+
405
+ /**
406
+ * Return whether this Interval's start is adjacent to the specified Interval's end.
407
+ * @param {Interval} other
408
+ * @return {boolean}
409
+ */
410
+ abutsEnd(other) {
411
+ if (!this.isValid) return false;
412
+ return +other.e === +this.s;
413
+ }
414
+
415
+ /**
416
+ * Returns true if this Interval fully contains the specified Interval, specifically if the intersect (of this Interval and the other Interval) is equal to the other Interval; false otherwise.
417
+ * @param {Interval} other
418
+ * @return {boolean}
419
+ */
420
+ engulfs(other) {
421
+ if (!this.isValid) return false;
422
+ return this.s <= other.s && this.e >= other.e;
423
+ }
424
+
425
+ /**
426
+ * Return whether this Interval has the same start and end as the specified Interval.
427
+ * @param {Interval} other
428
+ * @return {boolean}
429
+ */
430
+ equals(other) {
431
+ if (!this.isValid || !other.isValid) {
432
+ return false;
433
+ }
434
+
435
+ return this.s.equals(other.s) && this.e.equals(other.e);
436
+ }
437
+
438
+ /**
439
+ * Return an Interval representing the intersection of this Interval and the specified Interval.
440
+ * Specifically, the resulting Interval has the maximum start time and the minimum end time of the two Intervals.
441
+ * Returns null if the intersection is empty, meaning, the intervals don't intersect.
442
+ * @param {Interval} other
443
+ * @return {Interval}
444
+ */
445
+ intersection(other) {
446
+ if (!this.isValid) return this;
447
+ const s = this.s > other.s ? this.s : other.s,
448
+ e = this.e < other.e ? this.e : other.e;
449
+
450
+ if (s >= e) {
451
+ return null;
452
+ } else {
453
+ return Interval.fromDateTimes(s, e);
454
+ }
455
+ }
456
+
457
+ /**
458
+ * Return an Interval representing the union of this Interval and the specified Interval.
459
+ * Specifically, the resulting Interval has the minimum start time and the maximum end time of the two Intervals.
460
+ * @param {Interval} other
461
+ * @return {Interval}
462
+ */
463
+ union(other) {
464
+ if (!this.isValid) return this;
465
+ const s = this.s < other.s ? this.s : other.s,
466
+ e = this.e > other.e ? this.e : other.e;
467
+ return Interval.fromDateTimes(s, e);
468
+ }
469
+
470
+ /**
471
+ * Merge an array of Intervals into a equivalent minimal set of Intervals.
472
+ * Combines overlapping and adjacent Intervals.
473
+ * @param {Array} intervals
474
+ * @return {Array}
475
+ */
476
+ static merge(intervals) {
477
+ const [found, final] = intervals
478
+ .sort((a, b) => a.s - b.s)
479
+ .reduce(
480
+ ([sofar, current], item) => {
481
+ if (!current) {
482
+ return [sofar, item];
483
+ } else if (current.overlaps(item) || current.abutsStart(item)) {
484
+ return [sofar, current.union(item)];
485
+ } else {
486
+ return [sofar.concat([current]), item];
487
+ }
488
+ },
489
+ [[], null]
490
+ );
491
+ if (final) {
492
+ found.push(final);
493
+ }
494
+ return found;
495
+ }
496
+
497
+ /**
498
+ * Return an array of Intervals representing the spans of time that only appear in one of the specified Intervals.
499
+ * @param {Array} intervals
500
+ * @return {Array}
501
+ */
502
+ static xor(intervals) {
503
+ let start = null,
504
+ currentCount = 0;
505
+ const results = [],
506
+ ends = intervals.map((i) => [
507
+ { time: i.s, type: "s" },
508
+ { time: i.e, type: "e" },
509
+ ]),
510
+ flattened = Array.prototype.concat(...ends),
511
+ arr = flattened.sort((a, b) => a.time - b.time);
512
+
513
+ for (const i of arr) {
514
+ currentCount += i.type === "s" ? 1 : -1;
515
+
516
+ if (currentCount === 1) {
517
+ start = i.time;
518
+ } else {
519
+ if (start && +start !== +i.time) {
520
+ results.push(Interval.fromDateTimes(start, i.time));
521
+ }
522
+
523
+ start = null;
524
+ }
525
+ }
526
+
527
+ return Interval.merge(results);
528
+ }
529
+
530
+ /**
531
+ * Return an Interval representing the span of time in this Interval that doesn't overlap with any of the specified Intervals.
532
+ * @param {...Interval} intervals
533
+ * @return {Array}
534
+ */
535
+ difference(...intervals) {
536
+ return Interval.xor([this].concat(intervals))
537
+ .map((i) => this.intersection(i))
538
+ .filter((i) => i && !i.isEmpty());
539
+ }
540
+
541
+ /**
542
+ * Returns a string representation of this Interval appropriate for debugging.
543
+ * @return {string}
544
+ */
545
+ toString() {
546
+ if (!this.isValid) return INVALID;
547
+ return `[${this.s.toISO()} – ${this.e.toISO()})`;
548
+ }
549
+
550
+ /**
551
+ * Returns a string representation of this Interval appropriate for the REPL.
552
+ * @return {string}
553
+ */
554
+ [Symbol.for("nodejs.util.inspect.custom")]() {
555
+ if (this.isValid) {
556
+ return `Interval { start: ${this.s.toISO()}, end: ${this.e.toISO()} }`;
557
+ } else {
558
+ return `Interval { Invalid, reason: ${this.invalidReason} }`;
559
+ }
560
+ }
561
+
562
+ /**
563
+ * Returns a localized string representing this Interval. Accepts the same options as the
564
+ * Intl.DateTimeFormat constructor and any presets defined by Luxon, such as
565
+ * {@link DateTime.DATE_FULL} or {@link DateTime.TIME_SIMPLE}. The exact behavior of this method
566
+ * is browser-specific, but in general it will return an appropriate representation of the
567
+ * Interval in the assigned locale. Defaults to the system's locale if no locale has been
568
+ * specified.
569
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
570
+ * @param {Object} [formatOpts=DateTime.DATE_SHORT] - Either a DateTime preset or
571
+ * Intl.DateTimeFormat constructor options.
572
+ * @param {Object} opts - Options to override the configuration of the start DateTime.
573
+ * @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(); //=> 11/7/2022 – 11/8/2022
574
+ * @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(DateTime.DATE_FULL); //=> November 7 – 8, 2022
575
+ * @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(DateTime.DATE_FULL, { locale: 'fr-FR' }); //=> 7–8 novembre 2022
576
+ * @example Interval.fromISO('2022-11-07T17:00Z/2022-11-07T19:00Z').toLocaleString(DateTime.TIME_SIMPLE); //=> 6:00 – 8:00 PM
577
+ * @example Interval.fromISO('2022-11-07T17:00Z/2022-11-07T19:00Z').toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> Mon, Nov 07, 6:00 – 8:00 p
578
+ * @return {string}
579
+ */
580
+ toLocaleString(formatOpts = Formats.DATE_SHORT, opts = {}) {
581
+ return this.isValid
582
+ ? Formatter.create(this.s.loc.clone(opts), formatOpts).formatInterval(this)
583
+ : INVALID;
584
+ }
585
+
586
+ /**
587
+ * Returns an ISO 8601-compliant string representation of this Interval.
588
+ * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
589
+ * @param {Object} opts - The same options as {@link DateTime#toISO}
590
+ * @return {string}
591
+ */
592
+ toISO(opts) {
593
+ if (!this.isValid) return INVALID;
594
+ return `${this.s.toISO(opts)}/${this.e.toISO(opts)}`;
595
+ }
596
+
597
+ /**
598
+ * Returns an ISO 8601-compliant string representation of date of this Interval.
599
+ * The time components are ignored.
600
+ * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
601
+ * @return {string}
602
+ */
603
+ toISODate() {
604
+ if (!this.isValid) return INVALID;
605
+ return `${this.s.toISODate()}/${this.e.toISODate()}`;
606
+ }
607
+
608
+ /**
609
+ * Returns an ISO 8601-compliant string representation of time of this Interval.
610
+ * The date components are ignored.
611
+ * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
612
+ * @param {Object} opts - The same options as {@link DateTime#toISO}
613
+ * @return {string}
614
+ */
615
+ toISOTime(opts) {
616
+ if (!this.isValid) return INVALID;
617
+ return `${this.s.toISOTime(opts)}/${this.e.toISOTime(opts)}`;
618
+ }
619
+
620
+ /**
621
+ * Returns a string representation of this Interval formatted according to the specified format
622
+ * string. **You may not want this.** See {@link Interval#toLocaleString} for a more flexible
623
+ * formatting tool.
624
+ * @param {string} dateFormat - The format string. This string formats the start and end time.
625
+ * See {@link DateTime#toFormat} for details.
626
+ * @param {Object} opts - Options.
627
+ * @param {string} [opts.separator = ' – '] - A separator to place between the start and end
628
+ * representations.
629
+ * @return {string}
630
+ */
631
+ toFormat(dateFormat, { separator = " – " } = {}) {
632
+ if (!this.isValid) return INVALID;
633
+ return `${this.s.toFormat(dateFormat)}${separator}${this.e.toFormat(dateFormat)}`;
634
+ }
635
+
636
+ /**
637
+ * Return a Duration representing the time spanned by this interval.
638
+ * @param {string|string[]} [unit=['milliseconds']] - the unit or units (such as 'hours' or 'days') to include in the duration.
639
+ * @param {Object} opts - options that affect the creation of the Duration
640
+ * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
641
+ * @example Interval.fromDateTimes(dt1, dt2).toDuration().toObject() //=> { milliseconds: 88489257 }
642
+ * @example Interval.fromDateTimes(dt1, dt2).toDuration('days').toObject() //=> { days: 1.0241812152777778 }
643
+ * @example Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes']).toObject() //=> { hours: 24, minutes: 34.82095 }
644
+ * @example Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes', 'seconds']).toObject() //=> { hours: 24, minutes: 34, seconds: 49.257 }
645
+ * @example Interval.fromDateTimes(dt1, dt2).toDuration('seconds').toObject() //=> { seconds: 88489.257 }
646
+ * @return {Duration}
647
+ */
648
+ toDuration(unit, opts) {
649
+ if (!this.isValid) {
650
+ return Duration.invalid(this.invalidReason);
651
+ }
652
+ return this.e.diff(this.s, unit, opts);
653
+ }
654
+
655
+ /**
656
+ * Run mapFn on the interval start and end, returning a new Interval from the resulting DateTimes
657
+ * @param {function} mapFn
658
+ * @return {Interval}
659
+ * @example Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.toUTC())
660
+ * @example Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.plus({ hours: 2 }))
661
+ */
662
+ mapEndpoints(mapFn) {
663
+ return Interval.fromDateTimes(mapFn(this.s), mapFn(this.e));
664
+ }
665
+ }
@@ -0,0 +1,26 @@
1
+ import DateTime from "./datetime.js";
2
+ import Duration from "./duration.js";
3
+ import Interval from "./interval.js";
4
+ import Info from "./info.js";
5
+ import Zone from "./zone.js";
6
+ import FixedOffsetZone from "./zones/fixedOffsetZone.js";
7
+ import IANAZone from "./zones/IANAZone.js";
8
+ import InvalidZone from "./zones/invalidZone.js";
9
+ import SystemZone from "./zones/systemZone.js";
10
+ import Settings from "./settings.js";
11
+
12
+ const VERSION = "3.6.0";
13
+
14
+ export {
15
+ VERSION,
16
+ DateTime,
17
+ Duration,
18
+ Interval,
19
+ Info,
20
+ Zone,
21
+ FixedOffsetZone,
22
+ IANAZone,
23
+ InvalidZone,
24
+ SystemZone,
25
+ Settings,
26
+ };
@@ -0,0 +1,4 @@
1
+ {
2
+ "type": "module",
3
+ "version": "3.6.0"
4
+ }