@cloudsnorkel/cdk-github-runners 0.14.23 → 0.15.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 (139) hide show
  1. package/.jsii +5397 -252
  2. package/API.md +1048 -24
  3. package/README.md +52 -0
  4. package/assets/delete-failed-runner.lambda/index.js +105 -9
  5. package/assets/idle-runner-repear.lambda/index.js +136 -14
  6. package/assets/image-builders/aws-image-builder/delete-resources.lambda/index.js +1 -1
  7. package/assets/image-builders/build-image.lambda/index.js +1 -1
  8. package/assets/providers/ami-root-device.lambda/index.js +1 -1
  9. package/assets/setup.lambda/index.html +7 -7
  10. package/assets/setup.lambda/index.js +101 -8
  11. package/assets/status.lambda/index.js +104 -8
  12. package/assets/token-retriever.lambda/index.js +104 -8
  13. package/assets/warm-runner-manager.lambda/index.js +5892 -0
  14. package/assets/webhook-handler.lambda/index.js +109 -11
  15. package/assets/webhook-redelivery.lambda/index.js +122 -24
  16. package/lib/access.js +1 -1
  17. package/lib/delete-failed-runner.lambda.js +2 -2
  18. package/lib/idle-runner-repear.lambda.js +33 -7
  19. package/lib/image-builders/api.js +1 -1
  20. package/lib/image-builders/aws-image-builder/base-image.d.ts +13 -0
  21. package/lib/image-builders/aws-image-builder/base-image.js +36 -3
  22. package/lib/image-builders/aws-image-builder/builder.js +4 -4
  23. package/lib/image-builders/aws-image-builder/delete-resources.lambda.js +2 -2
  24. package/lib/image-builders/aws-image-builder/deprecated/ami.js +1 -1
  25. package/lib/image-builders/aws-image-builder/deprecated/container.js +1 -1
  26. package/lib/image-builders/aws-image-builder/deprecated/linux-components.js +1 -1
  27. package/lib/image-builders/aws-image-builder/deprecated/windows-components.js +1 -1
  28. package/lib/image-builders/build-image.lambda.js +2 -2
  29. package/lib/image-builders/codebuild-deprecated.js +1 -1
  30. package/lib/image-builders/components.js +3 -3
  31. package/lib/image-builders/static.js +1 -1
  32. package/lib/index.d.ts +1 -0
  33. package/lib/index.js +2 -1
  34. package/lib/lambda-github.d.ts +1 -1
  35. package/lib/lambda-github.js +3 -2
  36. package/lib/lambda-helpers.js +4 -4
  37. package/lib/providers/ami-root-device.lambda.js +2 -2
  38. package/lib/providers/codebuild.d.ts +16 -0
  39. package/lib/providers/codebuild.js +16 -5
  40. package/lib/providers/common.js +3 -3
  41. package/lib/providers/composite.js +1 -1
  42. package/lib/providers/ec2.d.ts +5 -0
  43. package/lib/providers/ec2.js +42 -29
  44. package/lib/providers/ecs.d.ts +17 -0
  45. package/lib/providers/ecs.js +43 -38
  46. package/lib/providers/fargate.js +10 -32
  47. package/lib/providers/lambda.js +2 -2
  48. package/lib/runner.d.ts +25 -2
  49. package/lib/runner.js +119 -17
  50. package/lib/secrets.js +1 -1
  51. package/lib/setup.lambda.js +2 -2
  52. package/lib/utils.d.ts +10 -1
  53. package/lib/utils.js +15 -1
  54. package/lib/warm-runner-manager-function.d.ts +18 -0
  55. package/lib/warm-runner-manager-function.js +24 -0
  56. package/lib/warm-runner-manager.lambda.d.ts +41 -0
  57. package/lib/warm-runner-manager.lambda.js +487 -0
  58. package/lib/warm-runner.d.ts +147 -0
  59. package/lib/warm-runner.js +210 -0
  60. package/lib/webhook-handler.lambda.js +5 -3
  61. package/lib/webhook-redelivery.lambda.js +17 -16
  62. package/lib/webhook.d.ts +4 -0
  63. package/lib/webhook.js +2 -1
  64. package/node_modules/cron-parser/LICENSE +21 -0
  65. package/node_modules/cron-parser/README.md +408 -0
  66. package/node_modules/cron-parser/dist/CronDate.js +518 -0
  67. package/node_modules/cron-parser/dist/CronExpression.js +520 -0
  68. package/node_modules/cron-parser/dist/CronExpressionParser.js +382 -0
  69. package/node_modules/cron-parser/dist/CronFieldCollection.js +371 -0
  70. package/node_modules/cron-parser/dist/CronFileParser.js +109 -0
  71. package/node_modules/cron-parser/dist/fields/CronDayOfMonth.js +44 -0
  72. package/node_modules/cron-parser/dist/fields/CronDayOfWeek.js +51 -0
  73. package/node_modules/cron-parser/dist/fields/CronField.js +214 -0
  74. package/node_modules/cron-parser/dist/fields/CronHour.js +40 -0
  75. package/node_modules/cron-parser/dist/fields/CronMinute.js +40 -0
  76. package/node_modules/cron-parser/dist/fields/CronMonth.js +44 -0
  77. package/node_modules/cron-parser/dist/fields/CronSecond.js +40 -0
  78. package/node_modules/cron-parser/dist/fields/index.js +24 -0
  79. package/node_modules/cron-parser/dist/fields/types.js +2 -0
  80. package/node_modules/cron-parser/dist/index.js +31 -0
  81. package/node_modules/cron-parser/dist/types/CronDate.d.ts +288 -0
  82. package/node_modules/cron-parser/dist/types/CronExpression.d.ts +118 -0
  83. package/node_modules/cron-parser/dist/types/CronExpressionParser.d.ts +70 -0
  84. package/node_modules/cron-parser/dist/types/CronFieldCollection.d.ts +153 -0
  85. package/node_modules/cron-parser/dist/types/CronFileParser.d.ts +30 -0
  86. package/node_modules/cron-parser/dist/types/fields/CronDayOfMonth.d.ts +25 -0
  87. package/node_modules/cron-parser/dist/types/fields/CronDayOfWeek.d.ts +30 -0
  88. package/node_modules/cron-parser/dist/types/fields/CronField.d.ts +130 -0
  89. package/node_modules/cron-parser/dist/types/fields/CronHour.d.ts +23 -0
  90. package/node_modules/cron-parser/dist/types/fields/CronMinute.d.ts +23 -0
  91. package/node_modules/cron-parser/dist/types/fields/CronMonth.d.ts +24 -0
  92. package/node_modules/cron-parser/dist/types/fields/CronSecond.d.ts +23 -0
  93. package/node_modules/cron-parser/dist/types/fields/index.d.ts +8 -0
  94. package/node_modules/cron-parser/dist/types/fields/types.d.ts +18 -0
  95. package/node_modules/cron-parser/dist/types/index.d.ts +8 -0
  96. package/node_modules/cron-parser/dist/types/utils/random.d.ts +10 -0
  97. package/node_modules/cron-parser/dist/utils/random.js +38 -0
  98. package/node_modules/cron-parser/package.json +117 -0
  99. package/node_modules/luxon/LICENSE.md +7 -0
  100. package/node_modules/luxon/README.md +55 -0
  101. package/node_modules/luxon/build/amd/luxon.js +8741 -0
  102. package/node_modules/luxon/build/amd/luxon.js.map +1 -0
  103. package/node_modules/luxon/build/cjs-browser/luxon.js +8739 -0
  104. package/node_modules/luxon/build/cjs-browser/luxon.js.map +1 -0
  105. package/node_modules/luxon/build/es6/luxon.mjs +8133 -0
  106. package/node_modules/luxon/build/es6/luxon.mjs.map +1 -0
  107. package/node_modules/luxon/build/global/luxon.js +8744 -0
  108. package/node_modules/luxon/build/global/luxon.js.map +1 -0
  109. package/node_modules/luxon/build/global/luxon.min.js +1 -0
  110. package/node_modules/luxon/build/global/luxon.min.js.map +1 -0
  111. package/node_modules/luxon/build/node/luxon.js +7792 -0
  112. package/node_modules/luxon/build/node/luxon.js.map +1 -0
  113. package/node_modules/luxon/package.json +87 -0
  114. package/node_modules/luxon/src/datetime.js +2603 -0
  115. package/node_modules/luxon/src/duration.js +1009 -0
  116. package/node_modules/luxon/src/errors.js +61 -0
  117. package/node_modules/luxon/src/impl/conversions.js +206 -0
  118. package/node_modules/luxon/src/impl/diff.js +95 -0
  119. package/node_modules/luxon/src/impl/digits.js +94 -0
  120. package/node_modules/luxon/src/impl/english.js +233 -0
  121. package/node_modules/luxon/src/impl/formats.js +176 -0
  122. package/node_modules/luxon/src/impl/formatter.js +434 -0
  123. package/node_modules/luxon/src/impl/invalid.js +14 -0
  124. package/node_modules/luxon/src/impl/locale.js +569 -0
  125. package/node_modules/luxon/src/impl/regexParser.js +335 -0
  126. package/node_modules/luxon/src/impl/tokenParser.js +505 -0
  127. package/node_modules/luxon/src/impl/util.js +330 -0
  128. package/node_modules/luxon/src/impl/zoneUtil.js +34 -0
  129. package/node_modules/luxon/src/info.js +205 -0
  130. package/node_modules/luxon/src/interval.js +669 -0
  131. package/node_modules/luxon/src/luxon.js +26 -0
  132. package/node_modules/luxon/src/package.json +4 -0
  133. package/node_modules/luxon/src/settings.js +180 -0
  134. package/node_modules/luxon/src/zone.js +97 -0
  135. package/node_modules/luxon/src/zones/IANAZone.js +235 -0
  136. package/node_modules/luxon/src/zones/fixedOffsetZone.js +150 -0
  137. package/node_modules/luxon/src/zones/invalidZone.js +53 -0
  138. package/node_modules/luxon/src/zones/systemZone.js +61 -0
  139. package/package.json +33 -24
@@ -0,0 +1,669 @@
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. This is the first instant which is not part of the interval
193
+ * (Interval is half-open).
194
+ * @type {DateTime}
195
+ */
196
+ get end() {
197
+ return this.isValid ? this.e : null;
198
+ }
199
+
200
+ /**
201
+ * Returns the last DateTime included in the interval (since end is not part of the interval)
202
+ * @type {DateTime}
203
+ */
204
+ get lastDateTime() {
205
+ return this.isValid ? (this.e ? this.e.minus(1) : null) : null;
206
+ }
207
+
208
+ /**
209
+ * Returns whether this Interval's end is at least its start, meaning that the Interval isn't 'backwards'.
210
+ * @type {boolean}
211
+ */
212
+ get isValid() {
213
+ return this.invalidReason === null;
214
+ }
215
+
216
+ /**
217
+ * Returns an error code if this Interval is invalid, or null if the Interval is valid
218
+ * @type {string}
219
+ */
220
+ get invalidReason() {
221
+ return this.invalid ? this.invalid.reason : null;
222
+ }
223
+
224
+ /**
225
+ * Returns an explanation of why this Interval became invalid, or null if the Interval is valid
226
+ * @type {string}
227
+ */
228
+ get invalidExplanation() {
229
+ return this.invalid ? this.invalid.explanation : null;
230
+ }
231
+
232
+ /**
233
+ * Returns the length of the Interval in the specified unit.
234
+ * @param {string} unit - the unit (such as 'hours' or 'days') to return the length in.
235
+ * @return {number}
236
+ */
237
+ length(unit = "milliseconds") {
238
+ return this.isValid ? this.toDuration(...[unit]).get(unit) : NaN;
239
+ }
240
+
241
+ /**
242
+ * Returns the count of minutes, hours, days, months, or years included in the Interval, even in part.
243
+ * Unlike {@link Interval#length} this counts sections of the calendar, not periods of time, e.g. specifying 'day'
244
+ * asks 'what dates are included in this interval?', not 'how many days long is this interval?'
245
+ * @param {string} [unit='milliseconds'] - the unit of time to count.
246
+ * @param {Object} opts - options
247
+ * @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
248
+ * @return {number}
249
+ */
250
+ count(unit = "milliseconds", opts) {
251
+ if (!this.isValid) return NaN;
252
+ const start = this.start.startOf(unit, opts);
253
+ let end;
254
+ if (opts?.useLocaleWeeks) {
255
+ end = this.end.reconfigure({ locale: start.locale });
256
+ } else {
257
+ end = this.end;
258
+ }
259
+ end = end.startOf(unit, opts);
260
+ return Math.floor(end.diff(start, unit).get(unit)) + (end.valueOf() !== this.end.valueOf());
261
+ }
262
+
263
+ /**
264
+ * Returns whether this Interval's start and end are both in the same unit of time
265
+ * @param {string} unit - the unit of time to check sameness on
266
+ * @return {boolean}
267
+ */
268
+ hasSame(unit) {
269
+ return this.isValid ? this.isEmpty() || this.e.minus(1).hasSame(this.s, unit) : false;
270
+ }
271
+
272
+ /**
273
+ * Return whether this Interval has the same start and end DateTimes.
274
+ * @return {boolean}
275
+ */
276
+ isEmpty() {
277
+ return this.s.valueOf() === this.e.valueOf();
278
+ }
279
+
280
+ /**
281
+ * Return whether this Interval's start is after the specified DateTime.
282
+ * @param {DateTime} dateTime
283
+ * @return {boolean}
284
+ */
285
+ isAfter(dateTime) {
286
+ if (!this.isValid) return false;
287
+ return this.s > dateTime;
288
+ }
289
+
290
+ /**
291
+ * Return whether this Interval's end is before the specified DateTime.
292
+ * @param {DateTime} dateTime
293
+ * @return {boolean}
294
+ */
295
+ isBefore(dateTime) {
296
+ if (!this.isValid) return false;
297
+ return this.e <= dateTime;
298
+ }
299
+
300
+ /**
301
+ * Return whether this Interval contains the specified DateTime.
302
+ * @param {DateTime} dateTime
303
+ * @return {boolean}
304
+ */
305
+ contains(dateTime) {
306
+ if (!this.isValid) return false;
307
+ return this.s <= dateTime && this.e > dateTime;
308
+ }
309
+
310
+ /**
311
+ * "Sets" the start and/or end dates. Returns a newly-constructed Interval.
312
+ * @param {Object} values - the values to set
313
+ * @param {DateTime} values.start - the starting DateTime
314
+ * @param {DateTime} values.end - the ending DateTime
315
+ * @return {Interval}
316
+ */
317
+ set({ start, end } = {}) {
318
+ if (!this.isValid) return this;
319
+ return Interval.fromDateTimes(start || this.s, end || this.e);
320
+ }
321
+
322
+ /**
323
+ * Split this Interval at each of the specified DateTimes
324
+ * @param {...DateTime} dateTimes - the unit of time to count.
325
+ * @return {Array}
326
+ */
327
+ splitAt(...dateTimes) {
328
+ if (!this.isValid) return [];
329
+ const sorted = dateTimes
330
+ .map(friendlyDateTime)
331
+ .filter((d) => this.contains(d))
332
+ .sort((a, b) => a.toMillis() - b.toMillis()),
333
+ results = [];
334
+ let { s } = this,
335
+ i = 0;
336
+
337
+ while (s < this.e) {
338
+ const added = sorted[i] || this.e,
339
+ next = +added > +this.e ? this.e : added;
340
+ results.push(Interval.fromDateTimes(s, next));
341
+ s = next;
342
+ i += 1;
343
+ }
344
+
345
+ return results;
346
+ }
347
+
348
+ /**
349
+ * Split this Interval into smaller Intervals, each of the specified length.
350
+ * Left over time is grouped into a smaller interval
351
+ * @param {Duration|Object|number} duration - The length of each resulting interval.
352
+ * @return {Array}
353
+ */
354
+ splitBy(duration) {
355
+ const dur = Duration.fromDurationLike(duration);
356
+
357
+ if (!this.isValid || !dur.isValid || dur.as("milliseconds") === 0) {
358
+ return [];
359
+ }
360
+
361
+ let { s } = this,
362
+ idx = 1,
363
+ next;
364
+
365
+ const results = [];
366
+ while (s < this.e) {
367
+ const added = this.start.plus(dur.mapUnits((x) => x * idx));
368
+ next = +added > +this.e ? this.e : added;
369
+ results.push(Interval.fromDateTimes(s, next));
370
+ s = next;
371
+ idx += 1;
372
+ }
373
+
374
+ return results;
375
+ }
376
+
377
+ /**
378
+ * Split this Interval into the specified number of smaller intervals.
379
+ * @param {number} numberOfParts - The number of Intervals to divide the Interval into.
380
+ * @return {Array}
381
+ */
382
+ divideEqually(numberOfParts) {
383
+ if (!this.isValid) return [];
384
+ return this.splitBy(this.length() / numberOfParts).slice(0, numberOfParts);
385
+ }
386
+
387
+ /**
388
+ * Return whether this Interval overlaps with the specified Interval
389
+ * @param {Interval} other
390
+ * @return {boolean}
391
+ */
392
+ overlaps(other) {
393
+ return this.e > other.s && this.s < other.e;
394
+ }
395
+
396
+ /**
397
+ * Return whether this Interval's end is adjacent to the specified Interval's start.
398
+ * @param {Interval} other
399
+ * @return {boolean}
400
+ */
401
+ abutsStart(other) {
402
+ if (!this.isValid) return false;
403
+ return +this.e === +other.s;
404
+ }
405
+
406
+ /**
407
+ * Return whether this Interval's start is adjacent to the specified Interval's end.
408
+ * @param {Interval} other
409
+ * @return {boolean}
410
+ */
411
+ abutsEnd(other) {
412
+ if (!this.isValid) return false;
413
+ return +other.e === +this.s;
414
+ }
415
+
416
+ /**
417
+ * 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.
418
+ * @param {Interval} other
419
+ * @return {boolean}
420
+ */
421
+ engulfs(other) {
422
+ if (!this.isValid) return false;
423
+ return this.s <= other.s && this.e >= other.e;
424
+ }
425
+
426
+ /**
427
+ * Return whether this Interval has the same start and end as the specified Interval.
428
+ * @param {Interval} other
429
+ * @return {boolean}
430
+ */
431
+ equals(other) {
432
+ if (!this.isValid || !other.isValid) {
433
+ return false;
434
+ }
435
+
436
+ return this.s.equals(other.s) && this.e.equals(other.e);
437
+ }
438
+
439
+ /**
440
+ * Return an Interval representing the intersection of this Interval and the specified Interval.
441
+ * Specifically, the resulting Interval has the maximum start time and the minimum end time of the two Intervals.
442
+ * Returns null if the intersection is empty, meaning, the intervals don't intersect.
443
+ * @param {Interval} other
444
+ * @return {Interval}
445
+ */
446
+ intersection(other) {
447
+ if (!this.isValid) return this;
448
+ const s = this.s > other.s ? this.s : other.s,
449
+ e = this.e < other.e ? this.e : other.e;
450
+
451
+ if (s >= e) {
452
+ return null;
453
+ } else {
454
+ return Interval.fromDateTimes(s, e);
455
+ }
456
+ }
457
+
458
+ /**
459
+ * Return an Interval representing the union of this Interval and the specified Interval.
460
+ * Specifically, the resulting Interval has the minimum start time and the maximum end time of the two Intervals.
461
+ * @param {Interval} other
462
+ * @return {Interval}
463
+ */
464
+ union(other) {
465
+ if (!this.isValid) return this;
466
+ const s = this.s < other.s ? this.s : other.s,
467
+ e = this.e > other.e ? this.e : other.e;
468
+ return Interval.fromDateTimes(s, e);
469
+ }
470
+
471
+ /**
472
+ * Merge an array of Intervals into an equivalent minimal set of Intervals.
473
+ * Combines overlapping and adjacent Intervals.
474
+ * The resulting array will contain the Intervals in ascending order, that is, starting with the earliest Interval
475
+ * and ending with the latest.
476
+ *
477
+ * @param {Array} intervals
478
+ * @return {Array}
479
+ */
480
+ static merge(intervals) {
481
+ const [found, final] = intervals
482
+ .sort((a, b) => a.s - b.s)
483
+ .reduce(
484
+ ([sofar, current], item) => {
485
+ if (!current) {
486
+ return [sofar, item];
487
+ } else if (current.overlaps(item) || current.abutsStart(item)) {
488
+ return [sofar, current.union(item)];
489
+ } else {
490
+ return [sofar.concat([current]), item];
491
+ }
492
+ },
493
+ [[], null]
494
+ );
495
+ if (final) {
496
+ found.push(final);
497
+ }
498
+ return found;
499
+ }
500
+
501
+ /**
502
+ * Return an array of Intervals representing the spans of time that only appear in one of the specified Intervals.
503
+ * @param {Array} intervals
504
+ * @return {Array}
505
+ */
506
+ static xor(intervals) {
507
+ let start = null,
508
+ currentCount = 0;
509
+ const results = [],
510
+ ends = intervals.map((i) => [
511
+ { time: i.s, type: "s" },
512
+ { time: i.e, type: "e" },
513
+ ]),
514
+ flattened = Array.prototype.concat(...ends),
515
+ arr = flattened.sort((a, b) => a.time - b.time);
516
+
517
+ for (const i of arr) {
518
+ currentCount += i.type === "s" ? 1 : -1;
519
+
520
+ if (currentCount === 1) {
521
+ start = i.time;
522
+ } else {
523
+ if (start && +start !== +i.time) {
524
+ results.push(Interval.fromDateTimes(start, i.time));
525
+ }
526
+
527
+ start = null;
528
+ }
529
+ }
530
+
531
+ return Interval.merge(results);
532
+ }
533
+
534
+ /**
535
+ * Return an Interval representing the span of time in this Interval that doesn't overlap with any of the specified Intervals.
536
+ * @param {...Interval} intervals
537
+ * @return {Array}
538
+ */
539
+ difference(...intervals) {
540
+ return Interval.xor([this].concat(intervals))
541
+ .map((i) => this.intersection(i))
542
+ .filter((i) => i && !i.isEmpty());
543
+ }
544
+
545
+ /**
546
+ * Returns a string representation of this Interval appropriate for debugging.
547
+ * @return {string}
548
+ */
549
+ toString() {
550
+ if (!this.isValid) return INVALID;
551
+ return `[${this.s.toISO()} – ${this.e.toISO()})`;
552
+ }
553
+
554
+ /**
555
+ * Returns a string representation of this Interval appropriate for the REPL.
556
+ * @return {string}
557
+ */
558
+ [Symbol.for("nodejs.util.inspect.custom")]() {
559
+ if (this.isValid) {
560
+ return `Interval { start: ${this.s.toISO()}, end: ${this.e.toISO()} }`;
561
+ } else {
562
+ return `Interval { Invalid, reason: ${this.invalidReason} }`;
563
+ }
564
+ }
565
+
566
+ /**
567
+ * Returns a localized string representing this Interval. Accepts the same options as the
568
+ * Intl.DateTimeFormat constructor and any presets defined by Luxon, such as
569
+ * {@link DateTime.DATE_FULL} or {@link DateTime.TIME_SIMPLE}. The exact behavior of this method
570
+ * is browser-specific, but in general it will return an appropriate representation of the
571
+ * Interval in the assigned locale. Defaults to the system's locale if no locale has been
572
+ * specified.
573
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
574
+ * @param {Object} [formatOpts=DateTime.DATE_SHORT] - Either a DateTime preset or
575
+ * Intl.DateTimeFormat constructor options.
576
+ * @param {Object} opts - Options to override the configuration of the start DateTime.
577
+ * @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(); //=> 11/7/2022 – 11/8/2022
578
+ * @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(DateTime.DATE_FULL); //=> November 7 – 8, 2022
579
+ * @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(DateTime.DATE_FULL, { locale: 'fr-FR' }); //=> 7–8 novembre 2022
580
+ * @example Interval.fromISO('2022-11-07T17:00Z/2022-11-07T19:00Z').toLocaleString(DateTime.TIME_SIMPLE); //=> 6:00 – 8:00 PM
581
+ * @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
582
+ * @return {string}
583
+ */
584
+ toLocaleString(formatOpts = Formats.DATE_SHORT, opts = {}) {
585
+ return this.isValid
586
+ ? Formatter.create(this.s.loc.clone(opts), formatOpts).formatInterval(this)
587
+ : INVALID;
588
+ }
589
+
590
+ /**
591
+ * Returns an ISO 8601-compliant string representation of this Interval.
592
+ * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
593
+ * @param {Object} opts - The same options as {@link DateTime#toISO}
594
+ * @return {string}
595
+ */
596
+ toISO(opts) {
597
+ if (!this.isValid) return INVALID;
598
+ return `${this.s.toISO(opts)}/${this.e.toISO(opts)}`;
599
+ }
600
+
601
+ /**
602
+ * Returns an ISO 8601-compliant string representation of date of this Interval.
603
+ * The time components are ignored.
604
+ * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
605
+ * @return {string}
606
+ */
607
+ toISODate() {
608
+ if (!this.isValid) return INVALID;
609
+ return `${this.s.toISODate()}/${this.e.toISODate()}`;
610
+ }
611
+
612
+ /**
613
+ * Returns an ISO 8601-compliant string representation of time of this Interval.
614
+ * The date components are ignored.
615
+ * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
616
+ * @param {Object} opts - The same options as {@link DateTime#toISO}
617
+ * @return {string}
618
+ */
619
+ toISOTime(opts) {
620
+ if (!this.isValid) return INVALID;
621
+ return `${this.s.toISOTime(opts)}/${this.e.toISOTime(opts)}`;
622
+ }
623
+
624
+ /**
625
+ * Returns a string representation of this Interval formatted according to the specified format
626
+ * string. **You may not want this.** See {@link Interval#toLocaleString} for a more flexible
627
+ * formatting tool.
628
+ * @param {string} dateFormat - The format string. This string formats the start and end time.
629
+ * See {@link DateTime#toFormat} for details.
630
+ * @param {Object} opts - Options.
631
+ * @param {string} [opts.separator = ' – '] - A separator to place between the start and end
632
+ * representations.
633
+ * @return {string}
634
+ */
635
+ toFormat(dateFormat, { separator = " – " } = {}) {
636
+ if (!this.isValid) return INVALID;
637
+ return `${this.s.toFormat(dateFormat)}${separator}${this.e.toFormat(dateFormat)}`;
638
+ }
639
+
640
+ /**
641
+ * Return a Duration representing the time spanned by this interval.
642
+ * @param {string|string[]} [unit=['milliseconds']] - the unit or units (such as 'hours' or 'days') to include in the duration.
643
+ * @param {Object} opts - options that affect the creation of the Duration
644
+ * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
645
+ * @example Interval.fromDateTimes(dt1, dt2).toDuration().toObject() //=> { milliseconds: 88489257 }
646
+ * @example Interval.fromDateTimes(dt1, dt2).toDuration('days').toObject() //=> { days: 1.0241812152777778 }
647
+ * @example Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes']).toObject() //=> { hours: 24, minutes: 34.82095 }
648
+ * @example Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes', 'seconds']).toObject() //=> { hours: 24, minutes: 34, seconds: 49.257 }
649
+ * @example Interval.fromDateTimes(dt1, dt2).toDuration('seconds').toObject() //=> { seconds: 88489.257 }
650
+ * @return {Duration}
651
+ */
652
+ toDuration(unit, opts) {
653
+ if (!this.isValid) {
654
+ return Duration.invalid(this.invalidReason);
655
+ }
656
+ return this.e.diff(this.s, unit, opts);
657
+ }
658
+
659
+ /**
660
+ * Run mapFn on the interval start and end, returning a new Interval from the resulting DateTimes
661
+ * @param {function} mapFn
662
+ * @return {Interval}
663
+ * @example Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.toUTC())
664
+ * @example Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.plus({ hours: 2 }))
665
+ */
666
+ mapEndpoints(mapFn) {
667
+ return Interval.fromDateTimes(mapFn(this.s), mapFn(this.e));
668
+ }
669
+ }
@@ -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.7.2";
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.7.2"
4
+ }