@fr0st/datetime 6.1.1 → 8.0.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.
@@ -1,605 +0,0 @@
1
- import { calculateDiff, getBiggestDiff } from './../helpers.js';
2
- import { formatRelative } from './../formatter/format.js';
3
-
4
- /**
5
- * DateTime Comparisons
6
- */
7
-
8
- /**
9
- * Get the difference between this and another Date in milliseconds.
10
- * @param {DateTime} other The date to compare to.
11
- * @return {number} The difference.
12
- */
13
- export function diff(other) {
14
- return this - other;
15
- };
16
-
17
- /**
18
- * Get the difference between this and another Date in days.
19
- * @param {DateTime} other The date to compare to.
20
- * @param {object} [options] The options for comparing the dates.
21
- * @param {Boolean} [options.relative=true] Whether to use the relative difference.
22
- * @return {number} The difference.
23
- */
24
- export function diffInDays(other, { relative = true } = {}) {
25
- return calculateDiff(this, other, 'day', relative);
26
- };
27
-
28
- /**
29
- * Get the difference between this and another Date in hours.
30
- * @param {DateTime} other The date to compare to.
31
- * @param {object} [options] The options for comparing the dates.
32
- * @param {Boolean} [options.relative=true] Whether to use the relative difference.
33
- * @return {number} The difference.
34
- */
35
- export function diffInHours(other, { relative = true } = {}) {
36
- return calculateDiff(this, other, 'hour', relative);
37
- };
38
-
39
- /**
40
- * Get the difference between this and another Date in minutes.
41
- * @param {DateTime} other The date to compare to.
42
- * @param {object} [options] The options for comparing the dates.
43
- * @param {Boolean} [options.relative=true] Whether to use the relative difference.
44
- * @return {number} The difference.
45
- */
46
- export function diffInMinutes(other, { relative = true } = {}) {
47
- return calculateDiff(this, other, 'minute', relative);
48
- };
49
-
50
- /**
51
- * Get the difference between this and another Date in months.
52
- * @param {DateTime} other The date to compare to.
53
- * @param {object} [options] The options for comparing the dates.
54
- * @param {Boolean} [options.relative=true] Whether to use the relative difference.
55
- * @return {number} The difference.
56
- */
57
- export function diffInMonths(other, { relative = true } = {}) {
58
- return calculateDiff(this, other, 'month', relative);
59
- };
60
-
61
- /**
62
- * Get the difference between this and another Date in seconds.
63
- * @param {DateTime} other The date to compare to.
64
- * @param {object} [options] The options for comparing the dates.
65
- * @param {Boolean} [options.relative=true] Whether to use the relative difference.
66
- * @return {number} The difference.
67
- */
68
- export function diffInSeconds(other, { relative = true } = {}) {
69
- return calculateDiff(this, other, 'second', relative);
70
- };
71
-
72
- /**
73
- * Get the difference between this and another Date in weeks.
74
- * @param {DateTime} other The date to compare to.
75
- * @param {object} [options] The options for comparing the dates.
76
- * @param {Boolean} [options.relative=true] Whether to use the relative difference.
77
- * @return {number} The difference.
78
- */
79
- export function diffInWeeks(other, { relative = true } = {}) {
80
- return calculateDiff(this, other, 'week', relative);
81
- };
82
-
83
- /**
84
- * Get the difference between this and another Date in years.
85
- * @param {DateTime} other The date to compare to.
86
- * @param {object} [options] The options for comparing the dates.
87
- * @param {Boolean} [options.relative=true] Whether to use the relative difference.
88
- * @return {number} The difference.
89
- */
90
- export function diffInYears(other, { relative = true } = {}) {
91
- return calculateDiff(this, other, 'year', relative);
92
- };
93
-
94
- /**
95
- * Get the difference between this and another Date in human readable form.
96
- * @param {DateTime} other The date to compare to.
97
- * @return {string} The difference in human readable form.
98
- */
99
- export function humanDiff(other) {
100
- const [amount, unit] = getBiggestDiff(this, other);
101
- return formatRelative(this.getLocale(), amount, unit);
102
- };
103
-
104
- /**
105
- * Get the difference between this and another Date in days in human readable form.
106
- * @param {DateTime} other The date to compare to.
107
- * @return {string} The difference in days in human readable form.
108
- */
109
- export function humanDiffInDays(other) {
110
- return formatRelative(this.getLocale(), this.diffInDays(other), 'day');
111
- };
112
-
113
- /**
114
- * Get the difference between this and another Date in hours in human readable form.
115
- * @param {DateTime} other The date to compare to.
116
- * @return {string} The difference in hours in human readable form.
117
- */
118
- export function humanDiffInHours(other) {
119
- return formatRelative(this.getLocale(), this.diffInHours(other), 'hour');
120
- };
121
-
122
- /**
123
- * Get the difference between this and another Date in minutes in human readable form.
124
- * @param {DateTime} other The date to compare to.
125
- * @return {string} The difference in minutes in human readable form.
126
- */
127
- export function humanDiffInMinutes(other) {
128
- return formatRelative(this.getLocale(), this.diffInMinutes(other), 'minute');
129
- };
130
-
131
- /**
132
- * Get the difference between this and another Date in months in human readable form.
133
- * @param {DateTime} other The date to compare to.
134
- * @return {string} The difference in months in human readable form.
135
- */
136
- export function humanDiffInMonths(other) {
137
- return formatRelative(this.getLocale(), this.diffInMonths(other), 'month');
138
- };
139
-
140
- /**
141
- * Get the difference between this and another Date in seconds in human readable form.
142
- * @param {DateTime} other The date to compare to.
143
- * @return {string} The difference in seconds in human readable form.
144
- */
145
- export function humanDiffInSeconds(other) {
146
- return formatRelative(this.getLocale(), this.diffInSeconds(other), 'second');
147
- };
148
-
149
- /**
150
- * Get the difference between this and another Date in weeks in human readable form.
151
- * @param {DateTime} other The date to compare to.
152
- * @return {string} The difference in weeks in human readable form.
153
- */
154
- export function humanDiffInWeeks(other) {
155
- return formatRelative(this.getLocale(), this.diffInWeeks(other), 'week');
156
- };
157
-
158
- /**
159
- * Get the difference between this and another Date in years in human readable form.
160
- * @param {DateTime} other The date to compare to.
161
- * @return {string} The difference in years in human readable form.
162
- */
163
- export function humanDiffInYears(other) {
164
- return formatRelative(this.getLocale(), this.diffInYears(other), 'year');
165
- };
166
-
167
- /**
168
- * Determine whether this DateTime is after another date.
169
- * @param {DateTime} other The date to compare to.
170
- * @return {Boolean} TRUE if this DateTime is after the other date, otherwise FALSE.
171
- */
172
- export function isAfter(other) {
173
- return this.diff(other) > 0;
174
- }
175
-
176
- /**
177
- * Determine whether this DateTime is after another date (comparing by day).
178
- * @param {DateTime} other The date to compare to.
179
- * @return {Boolean} TRUE if this DateTime is after the other date (comparing by day), otherwise FALSE.
180
- */
181
- export function isAfterDay(other) {
182
- return this.diffInDays(other) > 0;
183
- }
184
-
185
- /**
186
- * Determine whether this DateTime is after another date (comparing by hour).
187
- * @param {DateTime} other The date to compare to.
188
- * @return {Boolean} TRUE if this DateTime is after the other date (comparing by hour), otherwise FALSE.
189
- */
190
- export function isAfterHour(other) {
191
- return this.diffInHours(other) > 0;
192
- }
193
-
194
- /**
195
- * Determine whether this DateTime is after another date (comparing by minute).
196
- * @param {DateTime} other The date to compare to.
197
- * @return {Boolean} TRUE if this DateTime is after the other date (comparing by minute), otherwise FALSE.
198
- */
199
- export function isAfterMinute(other) {
200
- return this.diffInMinutes(other) > 0;
201
- }
202
-
203
- /**
204
- * Determine whether this DateTime is after another date (comparing by month).
205
- * @param {DateTime} other The date to compare to.
206
- * @return {Boolean} TRUE if this DateTime is after the other date (comparing by month), otherwise FALSE.
207
- */
208
- export function isAfterMonth(other) {
209
- return this.diffInMonths(other) > 0;
210
- }
211
-
212
- /**
213
- * Determine whether this DateTime is after another date (comparing by second).
214
- * @param {DateTime} other The date to compare to.
215
- * @return {Boolean} TRUE if this DateTime is after the other date (comparing by second), otherwise FALSE.
216
- */
217
- export function isAfterSecond(other) {
218
- return this.diffInSeconds(other) > 0;
219
- }
220
-
221
- /**
222
- * Determine whether this DateTime is after another date (comparing by week).
223
- * @param {DateTime} other The date to compare to.
224
- * @return {Boolean} TRUE if this DateTime is after the other date (comparing by week), otherwise FALSE.
225
- */
226
- export function isAfterWeek(other) {
227
- return this.diffInWeeks(other) > 0;
228
- }
229
-
230
- /**
231
- * Determine whether this DateTime is after another date (comparing by year).
232
- * @param {DateTime} other The date to compare to.
233
- * @return {Boolean} TRUE if this DateTime is after the other date (comparing by year), otherwise FALSE.
234
- */
235
- export function isAfterYear(other) {
236
- return this.diffInYears(other) > 0;
237
- }
238
-
239
- /**
240
- * Determine whether this DateTime is before another date.
241
- * @param {DateTime} other The date to compare to.
242
- * @return {Boolean} TRUE if this DateTime is before the other date, otherwise FALSE.
243
- */
244
- export function isBefore(other) {
245
- return this.diff(other) < 0;
246
- }
247
-
248
- /**
249
- * Determine whether this DateTime is before another date (comparing by day).
250
- * @param {DateTime} other The date to compare to.
251
- * @return {Boolean} TRUE if this DateTime is before the other date (comparing by day), otherwise FALSE.
252
- */
253
- export function isBeforeDay(other) {
254
- return this.diffInDays(other) < 0;
255
- }
256
-
257
- /**
258
- * Determine whether this DateTime is before another date (comparing by hour).
259
- * @param {DateTime} other The date to compare to.
260
- * @return {Boolean} TRUE if this DateTime is before the other date (comparing by hour), otherwise FALSE.
261
- */
262
- export function isBeforeHour(other) {
263
- return this.diffInHours(other) < 0;
264
- }
265
-
266
- /**
267
- * Determine whether this DateTime is before another date (comparing by minute).
268
- * @param {DateTime} other The date to compare to.
269
- * @return {Boolean} TRUE if this DateTime is before the other date (comparing by minute), otherwise FALSE.
270
- */
271
- export function isBeforeMinute(other) {
272
- return this.diffInMinutes(other) < 0;
273
- }
274
-
275
- /**
276
- * Determine whether this DateTime is before another date (comparing by month).
277
- * @param {DateTime} other The date to compare to.
278
- * @return {Boolean} TRUE if this DateTime is before the other date (comparing by month), otherwise FALSE.
279
- */
280
- export function isBeforeMonth(other) {
281
- return this.diffInMonths(other) < 0;
282
- }
283
-
284
- /**
285
- * Determine whether this DateTime is before another date (comparing by second).
286
- * @param {DateTime} other The date to compare to.
287
- * @return {Boolean} TRUE if this DateTime is before the other date (comparing by second), otherwise FALSE.
288
- */
289
- export function isBeforeSecond(other) {
290
- return this.diffInSeconds(other) < 0;
291
- }
292
-
293
- /**
294
- * Determine whether this DateTime is before another date (comparing by week).
295
- * @param {DateTime} other The date to compare to.
296
- * @return {Boolean} TRUE if this DateTime is before the other date (comparing by week), otherwise FALSE.
297
- */
298
- export function isBeforeWeek(other) {
299
- return this.diffInWeeks(other) < 0;
300
- }
301
-
302
- /**
303
- * Determine whether this DateTime is before another date (comparing by year).
304
- * @param {DateTime} other The date to compare to.
305
- * @return {Boolean} TRUE if this DateTime is before the other date (comparing by year), otherwise FALSE.
306
- */
307
- export function isBeforeYear(other) {
308
- return this.diffInYears(other) < 0;
309
- }
310
-
311
- /**
312
- * Determine whether this DateTime is between two other dates.
313
- * @param {DateTime} start The first date to compare to.
314
- * @param {DateTime} end The second date to compare to.
315
- * @return {Boolean} TRUE if this DateTime is between two other dates, otherwise FALSE.
316
- */
317
- export function isBetween(start, end) {
318
- return this.isAfter(start) && this.isBefore(end);
319
- }
320
-
321
- /**
322
- * Determine whether this DateTime is between two other dates (comparing by day).
323
- * @param {DateTime} start The first date to compare to.
324
- * @param {DateTime} end The second date to compare to.
325
- * @return {Boolean} TRUE if this DateTime is between two other dates (comparing by day), otherwise FALSE.
326
- */
327
- export function isBetweenDay(start, end) {
328
- return this.isAfterDay(start) && this.isBeforeDay(end);
329
- }
330
-
331
- /**
332
- * Determine whether this DateTime is between two other dates (comparing by hour).
333
- * @param {DateTime} start The first date to compare to.
334
- * @param {DateTime} end The second date to compare to.
335
- * @return {Boolean} TRUE if this DateTime is between two other dates (comparing by hour), otherwise FALSE.
336
- */
337
- export function isBetweenHour(start, end) {
338
- return this.isAfterHour(start) && this.isBeforeHour(end);
339
- }
340
-
341
- /**
342
- * Determine whether this DateTime is between two other dates (comparing by minute).
343
- * @param {DateTime} start The first date to compare to.
344
- * @param {DateTime} end The second date to compare to.
345
- * @return {Boolean} TRUE if this DateTime is between two other dates (comparing by minute), otherwise FALSE.
346
- */
347
- export function isBetweenMinute(start, end) {
348
- return this.isAfterMinute(start) && this.isBeforeMinute(end);
349
- }
350
-
351
- /**
352
- * Determine whether this DateTime is between two other dates (comparing by month).
353
- * @param {DateTime} start The first date to compare to.
354
- * @param {DateTime} end The second date to compare to.
355
- * @return {Boolean} TRUE if this DateTime is between two other dates (comparing by month), otherwise FALSE.
356
- */
357
- export function isBetweenMonth(start, end) {
358
- return this.isAfterMonth(start) && this.isBeforeMonth(end);
359
- }
360
-
361
- /**
362
- * Determine whether this DateTime is between two other dates (comparing by second).
363
- * @param {DateTime} start The first date to compare to.
364
- * @param {DateTime} end The second date to compare to.
365
- * @return {Boolean} TRUE if this DateTime is between two other dates (comparing by second), otherwise FALSE.
366
- */
367
- export function isBetweenSecond(start, end) {
368
- return this.isAfterSecond(start) && this.isBeforeSecond(end);
369
- }
370
-
371
- /**
372
- * Determine whether this DateTime is between two other dates (comparing by week).
373
- * @param {DateTime} start The first date to compare to.
374
- * @param {DateTime} end The second date to compare to.
375
- * @return {Boolean} TRUE if this DateTime is between two other dates (comparing by week), otherwise FALSE.
376
- */
377
- export function isBetweenWeek(start, end) {
378
- return this.isAfterWeek(start) && this.isBeforeWeek(end);
379
- }
380
-
381
- /**
382
- * Determine whether this DateTime is between two other dates (comparing by year).
383
- * @param {DateTime} start The first date to compare to.
384
- * @param {DateTime} end The second date to compare to.
385
- * @return {Boolean} TRUE if this DateTime is between two other dates (comparing by year), otherwise FALSE.
386
- */
387
- export function isBetweenYear(start, end) {
388
- return this.isAfterYear(start) && this.isBeforeYear(end);
389
- }
390
-
391
- /**
392
- * Determine whether this DateTime is the same as another date.
393
- * @param {DateTime} other The date to compare to.
394
- * @return {Boolean} TRUE if this DateTime is the same as the other date, otherwise FALSE.
395
- */
396
- export function isSame(other) {
397
- return this.diff(other) === 0;
398
- }
399
-
400
- /**
401
- * Determine whether this DateTime is the same as another date (comparing by day).
402
- * @param {DateTime} other The date to compare to.
403
- * @return {Boolean} TRUE if this DateTime is the same as the other date (comparing by day), otherwise FALSE.
404
- */
405
- export function isSameDay(other) {
406
- return this.diffInDays(other) === 0;
407
- }
408
-
409
- /**
410
- * Determine whether this DateTime is the same as another date (comparing by hour).
411
- * @param {DateTime} other The date to compare to.
412
- * @return {Boolean} TRUE if this DateTime is the same as the other date (comparing by hour), otherwise FALSE.
413
- */
414
- export function isSameHour(other) {
415
- return this.diffInHours(other) === 0;
416
- }
417
-
418
- /**
419
- * Determine whether this DateTime is the same as another date (comparing by minute).
420
- * @param {DateTime} other The date to compare to.
421
- * @return {Boolean} TRUE if this DateTime is the same as the other date (comparing by minute), otherwise FALSE.
422
- */
423
- export function isSameMinute(other) {
424
- return this.diffInMinutes(other) === 0;
425
- }
426
-
427
- /**
428
- * Determine whether this DateTime is the same as another date (comparing by month).
429
- * @param {DateTime} other The date to compare to.
430
- * @return {Boolean} TRUE if this DateTime is the same as the other date (comparing by month), otherwise FALSE.
431
- */
432
- export function isSameMonth(other) {
433
- return this.diffInMonths(other) === 0;
434
- }
435
-
436
- /**
437
- * Determine whether this DateTime is the same as another date (comparing by second).
438
- * @param {DateTime} other The date to compare to.
439
- * @return {Boolean} TRUE if this DateTime is the same as the other date (comparing by second), otherwise FALSE.
440
- */
441
- export function isSameSecond(other) {
442
- return this.diffInSeconds(other) === 0;
443
- }
444
-
445
- /**
446
- * Determine whether this DateTime is the same as another date (comparing by week).
447
- * @param {DateTime} other The date to compare to.
448
- * @return {Boolean} TRUE if this DateTime is the same as the other date (comparing by week), otherwise FALSE.
449
- */
450
- export function isSameWeek(other) {
451
- return this.diffInWeeks(other) === 0;
452
- }
453
-
454
- /**
455
- * Determine whether this DateTime is the same as another date (comparing by year).
456
- * @param {DateTime} other The date to compare to.
457
- * @return {Boolean} TRUE if this DateTime is the same as the other date (comparing by year), otherwise FALSE.
458
- */
459
- export function isSameYear(other) {
460
- return this.diffInYears(other) === 0;
461
- }
462
-
463
- /**
464
- * Determine whether this DateTime is the same as or after another date.
465
- * @param {DateTime} other The date to compare to.
466
- * @return {Boolean} TRUE if this DateTime is the same as or after the other date, otherwise FALSE.
467
- */
468
- export function isSameOrAfter(other) {
469
- return this.diff(other) >= 0;
470
- }
471
-
472
- /**
473
- * Determine whether this DateTime is the same as or after another date (comparing by day).
474
- * @param {DateTime} other The date to compare to.
475
- * @return {Boolean} TRUE if this DateTime is the same as or after the other date (comparing by day), otherwise FALSE.
476
- */
477
- export function isSameOrAfterDay(other) {
478
- return this.diffInDays(other) >= 0;
479
- }
480
-
481
- /**
482
- * Determine whether this DateTime is the same as or after another date (comparing by hour).
483
- * @param {DateTime} other The date to compare to.
484
- * @return {Boolean} TRUE if this DateTime is the same as or after the other date (comparing by hour), otherwise FALSE.
485
- */
486
- export function isSameOrAfterHour(other) {
487
- return this.diffInHours(other) >= 0;
488
- }
489
-
490
- /**
491
- * Determine whether this DateTime is the same as or after another date (comparing by minute).
492
- * @param {DateTime} other The date to compare to.
493
- * @return {Boolean} TRUE if this DateTime is the same as or after the other date (comparing by minute), otherwise FALSE.
494
- */
495
- export function isSameOrAfterMinute(other) {
496
- return this.diffInMinutes(other) >= 0;
497
- }
498
-
499
- /**
500
- * Determine whether this DateTime is the same as or after another date (comparing by month).
501
- * @param {DateTime} other The date to compare to.
502
- * @return {Boolean} TRUE if this DateTime is the same as or after the other date (comparing by month), otherwise FALSE.
503
- */
504
- export function isSameOrAfterMonth(other) {
505
- return this.diffInMonths(other) >= 0;
506
- }
507
-
508
- /**
509
- * Determine whether this DateTime is the same as or after another date (comparing by second).
510
- * @param {DateTime} other The date to compare to.
511
- * @return {Boolean} TRUE if this DateTime is the same as or after the other date (comparing by second), otherwise FALSE.
512
- */
513
- export function isSameOrAfterSecond(other) {
514
- return this.diffInSeconds(other) >= 0;
515
- }
516
-
517
- /**
518
- * Determine whether this DateTime is the same as or after another date (comparing by week).
519
- * @param {DateTime} other The date to compare to.
520
- * @return {Boolean} TRUE if this DateTime is the same as or after the other date (comparing by week), otherwise FALSE.
521
- */
522
- export function isSameOrAfterWeek(other) {
523
- return this.diffInWeeks(other) >= 0;
524
- }
525
-
526
- /**
527
- * Determine whether this DateTime is the same as or after another date (comparing by year).
528
- * @param {DateTime} other The date to compare to.
529
- * @return {Boolean} TRUE if this DateTime is the same as or after the other date (comparing by year), otherwise FALSE.
530
- */
531
- export function isSameOrAfterYear(other) {
532
- return this.diffInYears(other) >= 0;
533
- }
534
-
535
- /**
536
- * Determine whether this DateTime is the same as or before another date.
537
- * @param {DateTime} other The date to compare to.
538
- * @return {Boolean} TRUE if this DateTime is the same as or before the other date, otherwise FALSE.
539
- */
540
- export function isSameOrBefore(other) {
541
- return this.diff(other) <= 0;
542
- }
543
-
544
- /**
545
- * Determine whether this DateTime is the same as or before another date (comparing by day).
546
- * @param {DateTime} other The date to compare to.
547
- * @return {Boolean} TRUE if this DateTime is the same as or before the other date (comparing by day), otherwise FALSE.
548
- */
549
- export function isSameOrBeforeDay(other) {
550
- return this.diffInDays(other) <= 0;
551
- }
552
-
553
- /**
554
- * Determine whether this DateTime is the same as or before another date (comparing by hour).
555
- * @param {DateTime} other The date to compare to.
556
- * @return {Boolean} TRUE if this DateTime is the same as or before the other date (comparing by hour), otherwise FALSE.
557
- */
558
- export function isSameOrBeforeHour(other) {
559
- return this.diffInHours(other) <= 0;
560
- }
561
-
562
- /**
563
- * Determine whether this DateTime is the same as or before another date (comparing by minute).
564
- * @param {DateTime} other The date to compare to.
565
- * @return {Boolean} TRUE if this DateTime is the same as or before the other date (comparing by minute), otherwise FALSE.
566
- */
567
- export function isSameOrBeforeMinute(other) {
568
- return this.diffInMinutes(other) <= 0;
569
- }
570
-
571
- /**
572
- * Determine whether this DateTime is the same as or before another date (comparing by month).
573
- * @param {DateTime} other The date to compare to.
574
- * @return {Boolean} TRUE if this DateTime is the same as or before the other date (comparing by month), otherwise FALSE.
575
- */
576
- export function isSameOrBeforeMonth(other) {
577
- return this.diffInMonths(other) <= 0;
578
- }
579
-
580
- /**
581
- * Determine whether this DateTime is the same as or before another date (comparing by second).
582
- * @param {DateTime} other The date to compare to.
583
- * @return {Boolean} TRUE if this DateTime is the same as or before the other date (comparing by second), otherwise FALSE.
584
- */
585
- export function isSameOrBeforeSecond(other) {
586
- return this.diffInSeconds(other) <= 0;
587
- }
588
-
589
- /**
590
- * Determine whether this DateTime is the same as or before another date (comparing by week).
591
- * @param {DateTime} other The date to compare to.
592
- * @return {Boolean} TRUE if this DateTime is the same as or before the other date (comparing by week), otherwise FALSE.
593
- */
594
- export function isSameOrBeforeWeek(other) {
595
- return this.diffInWeeks(other) <= 0;
596
- }
597
-
598
- /**
599
- * Determine whether this DateTime is the same as or before another date (comparing by year).
600
- * @param {DateTime} other The date to compare to.
601
- * @return {Boolean} TRUE if this DateTime is the same as or before the other date (comparing by year), otherwise FALSE.
602
- */
603
- export function isSameOrBeforeYear(other) {
604
- return this.diffInYears(other) <= 0;
605
- }