@nocobase/plugin-auth 0.17.0-alpha.7 → 0.18.0-alpha.2

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 (63) hide show
  1. package/dist/client/authenticator.d.ts +13 -0
  2. package/dist/client/basic/SignInForm.d.ts +9 -0
  3. package/dist/client/basic/SignUpForm.d.ts +13 -0
  4. package/dist/client/basic/index.d.ts +3 -0
  5. package/dist/client/index.d.ts +21 -0
  6. package/dist/client/index.js +12 -2
  7. package/dist/client/pages/AuthLayout.d.ts +2 -0
  8. package/dist/client/pages/SignInPage.d.ts +16 -0
  9. package/dist/client/pages/SignUpPage.d.ts +21 -0
  10. package/dist/client/pages/index.d.ts +3 -0
  11. package/dist/client/settings/Options.d.ts +3 -2
  12. package/dist/externalVersion.js +14 -12
  13. package/dist/locale/en-US.json +4 -1
  14. package/dist/locale/zh-CN.json +4 -1
  15. package/dist/node_modules/cron/LICENSE +0 -0
  16. package/dist/node_modules/cron/lib/cron.js +1 -1
  17. package/dist/node_modules/cron/lib/job.js +0 -0
  18. package/dist/node_modules/cron/lib/time.js +33 -20
  19. package/dist/node_modules/cron/node_modules/luxon/build/amd/luxon.js +7826 -0
  20. package/dist/node_modules/cron/node_modules/luxon/build/cjs-browser/luxon.js +7824 -0
  21. package/dist/node_modules/cron/node_modules/luxon/build/es6/luxon.js +7217 -0
  22. package/dist/node_modules/cron/node_modules/luxon/build/global/luxon.js +7829 -0
  23. package/dist/node_modules/cron/node_modules/luxon/build/global/luxon.min.js +1 -0
  24. package/dist/node_modules/cron/node_modules/luxon/build/node/luxon.js +6932 -0
  25. package/dist/node_modules/cron/node_modules/luxon/package.json +85 -0
  26. package/dist/node_modules/cron/node_modules/luxon/src/datetime.js +2248 -0
  27. package/dist/node_modules/cron/node_modules/luxon/src/duration.js +948 -0
  28. package/dist/node_modules/cron/node_modules/luxon/src/errors.js +61 -0
  29. package/dist/node_modules/cron/node_modules/luxon/src/impl/conversions.js +161 -0
  30. package/dist/node_modules/cron/node_modules/luxon/src/impl/diff.js +75 -0
  31. package/dist/node_modules/cron/node_modules/luxon/src/impl/digits.js +75 -0
  32. package/dist/node_modules/cron/node_modules/luxon/src/impl/english.js +233 -0
  33. package/dist/node_modules/cron/node_modules/luxon/src/impl/formats.js +176 -0
  34. package/dist/node_modules/cron/node_modules/luxon/src/impl/formatter.js +400 -0
  35. package/dist/node_modules/cron/node_modules/luxon/src/impl/invalid.js +14 -0
  36. package/dist/node_modules/cron/node_modules/luxon/src/impl/locale.js +494 -0
  37. package/dist/node_modules/cron/node_modules/luxon/src/impl/regexParser.js +335 -0
  38. package/dist/node_modules/cron/node_modules/luxon/src/impl/tokenParser.js +444 -0
  39. package/dist/node_modules/cron/node_modules/luxon/src/impl/util.js +274 -0
  40. package/dist/node_modules/cron/node_modules/luxon/src/impl/zoneUtil.js +34 -0
  41. package/dist/node_modules/cron/node_modules/luxon/src/info.js +169 -0
  42. package/dist/node_modules/cron/node_modules/luxon/src/interval.js +637 -0
  43. package/dist/node_modules/cron/node_modules/luxon/src/luxon.js +26 -0
  44. package/dist/node_modules/cron/node_modules/luxon/src/package.json +4 -0
  45. package/dist/node_modules/cron/node_modules/luxon/src/settings.js +148 -0
  46. package/dist/node_modules/cron/node_modules/luxon/src/zone.js +91 -0
  47. package/dist/node_modules/cron/node_modules/luxon/src/zones/IANAZone.js +189 -0
  48. package/dist/node_modules/cron/node_modules/luxon/src/zones/fixedOffsetZone.js +102 -0
  49. package/dist/node_modules/cron/node_modules/luxon/src/zones/invalidZone.js +53 -0
  50. package/dist/node_modules/cron/node_modules/luxon/src/zones/systemZone.js +61 -0
  51. package/dist/node_modules/cron/package.json +1 -1
  52. package/dist/node_modules/cron/types/index.d.ts +181 -0
  53. package/dist/node_modules/cron/types/index.test-d.ts +85 -0
  54. package/dist/server/actions/authenticators.js +3 -0
  55. package/dist/server/basic-auth.js +5 -2
  56. package/dist/server/migrations/20231218132032-fix-allow-signup.d.ts +5 -0
  57. package/dist/server/migrations/20231218132032-fix-allow-signup.js +54 -0
  58. package/dist/server/model/authenticator.d.ts +5 -2
  59. package/dist/server/model/authenticator.js +2 -2
  60. package/package.json +2 -2
  61. package/dist/client/AuthPluginProvider.d.ts +0 -2
  62. package/dist/client/basic/SigninPage.d.ts +0 -6
  63. package/dist/client/basic/SignupPage.d.ts +0 -5
@@ -0,0 +1,637 @@
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 whether this Interval's end is at least its start, meaning that the Interval isn't 'backwards'.
201
+ * @type {boolean}
202
+ */
203
+ get isValid() {
204
+ return this.invalidReason === null;
205
+ }
206
+
207
+ /**
208
+ * Returns an error code if this Interval is invalid, or null if the Interval is valid
209
+ * @type {string}
210
+ */
211
+ get invalidReason() {
212
+ return this.invalid ? this.invalid.reason : null;
213
+ }
214
+
215
+ /**
216
+ * Returns an explanation of why this Interval became invalid, or null if the Interval is valid
217
+ * @type {string}
218
+ */
219
+ get invalidExplanation() {
220
+ return this.invalid ? this.invalid.explanation : null;
221
+ }
222
+
223
+ /**
224
+ * Returns the length of the Interval in the specified unit.
225
+ * @param {string} unit - the unit (such as 'hours' or 'days') to return the length in.
226
+ * @return {number}
227
+ */
228
+ length(unit = "milliseconds") {
229
+ return this.isValid ? this.toDuration(...[unit]).get(unit) : NaN;
230
+ }
231
+
232
+ /**
233
+ * Returns the count of minutes, hours, days, months, or years included in the Interval, even in part.
234
+ * Unlike {@link Interval#length} this counts sections of the calendar, not periods of time, e.g. specifying 'day'
235
+ * asks 'what dates are included in this interval?', not 'how many days long is this interval?'
236
+ * @param {string} [unit='milliseconds'] - the unit of time to count.
237
+ * @return {number}
238
+ */
239
+ count(unit = "milliseconds") {
240
+ if (!this.isValid) return NaN;
241
+ const start = this.start.startOf(unit),
242
+ end = this.end.startOf(unit);
243
+ return Math.floor(end.diff(start, unit).get(unit)) + (end.valueOf() !== this.end.valueOf());
244
+ }
245
+
246
+ /**
247
+ * Returns whether this Interval's start and end are both in the same unit of time
248
+ * @param {string} unit - the unit of time to check sameness on
249
+ * @return {boolean}
250
+ */
251
+ hasSame(unit) {
252
+ return this.isValid ? this.isEmpty() || this.e.minus(1).hasSame(this.s, unit) : false;
253
+ }
254
+
255
+ /**
256
+ * Return whether this Interval has the same start and end DateTimes.
257
+ * @return {boolean}
258
+ */
259
+ isEmpty() {
260
+ return this.s.valueOf() === this.e.valueOf();
261
+ }
262
+
263
+ /**
264
+ * Return whether this Interval's start is after the specified DateTime.
265
+ * @param {DateTime} dateTime
266
+ * @return {boolean}
267
+ */
268
+ isAfter(dateTime) {
269
+ if (!this.isValid) return false;
270
+ return this.s > dateTime;
271
+ }
272
+
273
+ /**
274
+ * Return whether this Interval's end is before the specified DateTime.
275
+ * @param {DateTime} dateTime
276
+ * @return {boolean}
277
+ */
278
+ isBefore(dateTime) {
279
+ if (!this.isValid) return false;
280
+ return this.e <= dateTime;
281
+ }
282
+
283
+ /**
284
+ * Return whether this Interval contains the specified DateTime.
285
+ * @param {DateTime} dateTime
286
+ * @return {boolean}
287
+ */
288
+ contains(dateTime) {
289
+ if (!this.isValid) return false;
290
+ return this.s <= dateTime && this.e > dateTime;
291
+ }
292
+
293
+ /**
294
+ * "Sets" the start and/or end dates. Returns a newly-constructed Interval.
295
+ * @param {Object} values - the values to set
296
+ * @param {DateTime} values.start - the starting DateTime
297
+ * @param {DateTime} values.end - the ending DateTime
298
+ * @return {Interval}
299
+ */
300
+ set({ start, end } = {}) {
301
+ if (!this.isValid) return this;
302
+ return Interval.fromDateTimes(start || this.s, end || this.e);
303
+ }
304
+
305
+ /**
306
+ * Split this Interval at each of the specified DateTimes
307
+ * @param {...DateTime} dateTimes - the unit of time to count.
308
+ * @return {Array}
309
+ */
310
+ splitAt(...dateTimes) {
311
+ if (!this.isValid) return [];
312
+ const sorted = dateTimes
313
+ .map(friendlyDateTime)
314
+ .filter((d) => this.contains(d))
315
+ .sort(),
316
+ results = [];
317
+ let { s } = this,
318
+ i = 0;
319
+
320
+ while (s < this.e) {
321
+ const added = sorted[i] || this.e,
322
+ next = +added > +this.e ? this.e : added;
323
+ results.push(Interval.fromDateTimes(s, next));
324
+ s = next;
325
+ i += 1;
326
+ }
327
+
328
+ return results;
329
+ }
330
+
331
+ /**
332
+ * Split this Interval into smaller Intervals, each of the specified length.
333
+ * Left over time is grouped into a smaller interval
334
+ * @param {Duration|Object|number} duration - The length of each resulting interval.
335
+ * @return {Array}
336
+ */
337
+ splitBy(duration) {
338
+ const dur = Duration.fromDurationLike(duration);
339
+
340
+ if (!this.isValid || !dur.isValid || dur.as("milliseconds") === 0) {
341
+ return [];
342
+ }
343
+
344
+ let { s } = this,
345
+ idx = 1,
346
+ next;
347
+
348
+ const results = [];
349
+ while (s < this.e) {
350
+ const added = this.start.plus(dur.mapUnits((x) => x * idx));
351
+ next = +added > +this.e ? this.e : added;
352
+ results.push(Interval.fromDateTimes(s, next));
353
+ s = next;
354
+ idx += 1;
355
+ }
356
+
357
+ return results;
358
+ }
359
+
360
+ /**
361
+ * Split this Interval into the specified number of smaller intervals.
362
+ * @param {number} numberOfParts - The number of Intervals to divide the Interval into.
363
+ * @return {Array}
364
+ */
365
+ divideEqually(numberOfParts) {
366
+ if (!this.isValid) return [];
367
+ return this.splitBy(this.length() / numberOfParts).slice(0, numberOfParts);
368
+ }
369
+
370
+ /**
371
+ * Return whether this Interval overlaps with the specified Interval
372
+ * @param {Interval} other
373
+ * @return {boolean}
374
+ */
375
+ overlaps(other) {
376
+ return this.e > other.s && this.s < other.e;
377
+ }
378
+
379
+ /**
380
+ * Return whether this Interval's end is adjacent to the specified Interval's start.
381
+ * @param {Interval} other
382
+ * @return {boolean}
383
+ */
384
+ abutsStart(other) {
385
+ if (!this.isValid) return false;
386
+ return +this.e === +other.s;
387
+ }
388
+
389
+ /**
390
+ * Return whether this Interval's start is adjacent to the specified Interval's end.
391
+ * @param {Interval} other
392
+ * @return {boolean}
393
+ */
394
+ abutsEnd(other) {
395
+ if (!this.isValid) return false;
396
+ return +other.e === +this.s;
397
+ }
398
+
399
+ /**
400
+ * Return whether this Interval engulfs the start and end of the specified Interval.
401
+ * @param {Interval} other
402
+ * @return {boolean}
403
+ */
404
+ engulfs(other) {
405
+ if (!this.isValid) return false;
406
+ return this.s <= other.s && this.e >= other.e;
407
+ }
408
+
409
+ /**
410
+ * Return whether this Interval has the same start and end as the specified Interval.
411
+ * @param {Interval} other
412
+ * @return {boolean}
413
+ */
414
+ equals(other) {
415
+ if (!this.isValid || !other.isValid) {
416
+ return false;
417
+ }
418
+
419
+ return this.s.equals(other.s) && this.e.equals(other.e);
420
+ }
421
+
422
+ /**
423
+ * Return an Interval representing the intersection of this Interval and the specified Interval.
424
+ * Specifically, the resulting Interval has the maximum start time and the minimum end time of the two Intervals.
425
+ * Returns null if the intersection is empty, meaning, the intervals don't intersect.
426
+ * @param {Interval} other
427
+ * @return {Interval}
428
+ */
429
+ intersection(other) {
430
+ if (!this.isValid) return this;
431
+ const s = this.s > other.s ? this.s : other.s,
432
+ e = this.e < other.e ? this.e : other.e;
433
+
434
+ if (s >= e) {
435
+ return null;
436
+ } else {
437
+ return Interval.fromDateTimes(s, e);
438
+ }
439
+ }
440
+
441
+ /**
442
+ * Return an Interval representing the union of this Interval and the specified Interval.
443
+ * Specifically, the resulting Interval has the minimum start time and the maximum end time of the two Intervals.
444
+ * @param {Interval} other
445
+ * @return {Interval}
446
+ */
447
+ union(other) {
448
+ if (!this.isValid) return this;
449
+ const s = this.s < other.s ? this.s : other.s,
450
+ e = this.e > other.e ? this.e : other.e;
451
+ return Interval.fromDateTimes(s, e);
452
+ }
453
+
454
+ /**
455
+ * Merge an array of Intervals into a equivalent minimal set of Intervals.
456
+ * Combines overlapping and adjacent Intervals.
457
+ * @param {Array} intervals
458
+ * @return {Array}
459
+ */
460
+ static merge(intervals) {
461
+ const [found, final] = intervals
462
+ .sort((a, b) => a.s - b.s)
463
+ .reduce(
464
+ ([sofar, current], item) => {
465
+ if (!current) {
466
+ return [sofar, item];
467
+ } else if (current.overlaps(item) || current.abutsStart(item)) {
468
+ return [sofar, current.union(item)];
469
+ } else {
470
+ return [sofar.concat([current]), item];
471
+ }
472
+ },
473
+ [[], null]
474
+ );
475
+ if (final) {
476
+ found.push(final);
477
+ }
478
+ return found;
479
+ }
480
+
481
+ /**
482
+ * Return an array of Intervals representing the spans of time that only appear in one of the specified Intervals.
483
+ * @param {Array} intervals
484
+ * @return {Array}
485
+ */
486
+ static xor(intervals) {
487
+ let start = null,
488
+ currentCount = 0;
489
+ const results = [],
490
+ ends = intervals.map((i) => [
491
+ { time: i.s, type: "s" },
492
+ { time: i.e, type: "e" },
493
+ ]),
494
+ flattened = Array.prototype.concat(...ends),
495
+ arr = flattened.sort((a, b) => a.time - b.time);
496
+
497
+ for (const i of arr) {
498
+ currentCount += i.type === "s" ? 1 : -1;
499
+
500
+ if (currentCount === 1) {
501
+ start = i.time;
502
+ } else {
503
+ if (start && +start !== +i.time) {
504
+ results.push(Interval.fromDateTimes(start, i.time));
505
+ }
506
+
507
+ start = null;
508
+ }
509
+ }
510
+
511
+ return Interval.merge(results);
512
+ }
513
+
514
+ /**
515
+ * Return an Interval representing the span of time in this Interval that doesn't overlap with any of the specified Intervals.
516
+ * @param {...Interval} intervals
517
+ * @return {Array}
518
+ */
519
+ difference(...intervals) {
520
+ return Interval.xor([this].concat(intervals))
521
+ .map((i) => this.intersection(i))
522
+ .filter((i) => i && !i.isEmpty());
523
+ }
524
+
525
+ /**
526
+ * Returns a string representation of this Interval appropriate for debugging.
527
+ * @return {string}
528
+ */
529
+ toString() {
530
+ if (!this.isValid) return INVALID;
531
+ return `[${this.s.toISO()} – ${this.e.toISO()})`;
532
+ }
533
+
534
+ /**
535
+ * Returns a localized string representing this Interval. Accepts the same options as the
536
+ * Intl.DateTimeFormat constructor and any presets defined by Luxon, such as
537
+ * {@link DateTime.DATE_FULL} or {@link DateTime.TIME_SIMPLE}. The exact behavior of this method
538
+ * is browser-specific, but in general it will return an appropriate representation of the
539
+ * Interval in the assigned locale. Defaults to the system's locale if no locale has been
540
+ * specified.
541
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
542
+ * @param {Object} [formatOpts=DateTime.DATE_SHORT] - Either a DateTime preset or
543
+ * Intl.DateTimeFormat constructor options.
544
+ * @param {Object} opts - Options to override the configuration of the start DateTime.
545
+ * @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(); //=> 11/7/2022 – 11/8/2022
546
+ * @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(DateTime.DATE_FULL); //=> November 7 – 8, 2022
547
+ * @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(DateTime.DATE_FULL, { locale: 'fr-FR' }); //=> 7–8 novembre 2022
548
+ * @example Interval.fromISO('2022-11-07T17:00Z/2022-11-07T19:00Z').toLocaleString(DateTime.TIME_SIMPLE); //=> 6:00 – 8:00 PM
549
+ * @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
550
+ * @return {string}
551
+ */
552
+ toLocaleString(formatOpts = Formats.DATE_SHORT, opts = {}) {
553
+ return this.isValid
554
+ ? Formatter.create(this.s.loc.clone(opts), formatOpts).formatInterval(this)
555
+ : INVALID;
556
+ }
557
+
558
+ /**
559
+ * Returns an ISO 8601-compliant string representation of this Interval.
560
+ * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
561
+ * @param {Object} opts - The same options as {@link DateTime#toISO}
562
+ * @return {string}
563
+ */
564
+ toISO(opts) {
565
+ if (!this.isValid) return INVALID;
566
+ return `${this.s.toISO(opts)}/${this.e.toISO(opts)}`;
567
+ }
568
+
569
+ /**
570
+ * Returns an ISO 8601-compliant string representation of date of this Interval.
571
+ * The time components are ignored.
572
+ * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
573
+ * @return {string}
574
+ */
575
+ toISODate() {
576
+ if (!this.isValid) return INVALID;
577
+ return `${this.s.toISODate()}/${this.e.toISODate()}`;
578
+ }
579
+
580
+ /**
581
+ * Returns an ISO 8601-compliant string representation of time of this Interval.
582
+ * The date components are ignored.
583
+ * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
584
+ * @param {Object} opts - The same options as {@link DateTime#toISO}
585
+ * @return {string}
586
+ */
587
+ toISOTime(opts) {
588
+ if (!this.isValid) return INVALID;
589
+ return `${this.s.toISOTime(opts)}/${this.e.toISOTime(opts)}`;
590
+ }
591
+
592
+ /**
593
+ * Returns a string representation of this Interval formatted according to the specified format
594
+ * string. **You may not want this.** See {@link Interval#toLocaleString} for a more flexible
595
+ * formatting tool.
596
+ * @param {string} dateFormat - The format string. This string formats the start and end time.
597
+ * See {@link DateTime#toFormat} for details.
598
+ * @param {Object} opts - Options.
599
+ * @param {string} [opts.separator = ' – '] - A separator to place between the start and end
600
+ * representations.
601
+ * @return {string}
602
+ */
603
+ toFormat(dateFormat, { separator = " – " } = {}) {
604
+ if (!this.isValid) return INVALID;
605
+ return `${this.s.toFormat(dateFormat)}${separator}${this.e.toFormat(dateFormat)}`;
606
+ }
607
+
608
+ /**
609
+ * Return a Duration representing the time spanned by this interval.
610
+ * @param {string|string[]} [unit=['milliseconds']] - the unit or units (such as 'hours' or 'days') to include in the duration.
611
+ * @param {Object} opts - options that affect the creation of the Duration
612
+ * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
613
+ * @example Interval.fromDateTimes(dt1, dt2).toDuration().toObject() //=> { milliseconds: 88489257 }
614
+ * @example Interval.fromDateTimes(dt1, dt2).toDuration('days').toObject() //=> { days: 1.0241812152777778 }
615
+ * @example Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes']).toObject() //=> { hours: 24, minutes: 34.82095 }
616
+ * @example Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes', 'seconds']).toObject() //=> { hours: 24, minutes: 34, seconds: 49.257 }
617
+ * @example Interval.fromDateTimes(dt1, dt2).toDuration('seconds').toObject() //=> { seconds: 88489.257 }
618
+ * @return {Duration}
619
+ */
620
+ toDuration(unit, opts) {
621
+ if (!this.isValid) {
622
+ return Duration.invalid(this.invalidReason);
623
+ }
624
+ return this.e.diff(this.s, unit, opts);
625
+ }
626
+
627
+ /**
628
+ * Run mapFn on the interval start and end, returning a new Interval from the resulting DateTimes
629
+ * @param {function} mapFn
630
+ * @return {Interval}
631
+ * @example Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.toUTC())
632
+ * @example Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.plus({ hours: 2 }))
633
+ */
634
+ mapEndpoints(mapFn) {
635
+ return Interval.fromDateTimes(mapFn(this.s), mapFn(this.e));
636
+ }
637
+ }
@@ -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.3.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.3.0"
4
+ }