@fr0st/datetime 5.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.
package/README.md ADDED
@@ -0,0 +1,962 @@
1
+ # FrostDateTime
2
+
3
+ **FrostDateTime** is a free, open-source immutable date manipulation library for *JavaScript*.
4
+
5
+ It is a lightweight (~6kb gzipped) and modern library, and features support for ICU formats, time zones and locales.
6
+
7
+
8
+ ## Table Of Contents
9
+ - [Installation](#installation)
10
+ - [Date Creation](#date-creation)
11
+ - [Date Formatting](#date-formatting)
12
+ - [Date Attributes](#date-attributes)
13
+ - [Week Attributes](#week-attributes)
14
+ - [Time Attributes](#time-attributes)
15
+ - [Timestamps](#timestamps)
16
+ - [Time Zones](#time-zones)
17
+ - [Locales](#locales)
18
+ - [Utility Methods](#utility-methods)
19
+ - [Static Methods](#static-methods)
20
+
21
+
22
+
23
+ ## Installation
24
+
25
+ **In Browser**
26
+
27
+ ```html
28
+ <script type="text/javascript" src="/path/to/frost-datetime.min.js"></script>
29
+ ```
30
+
31
+ **Using NPM**
32
+
33
+ ```
34
+ npm i @fr0st/datetime
35
+ ```
36
+
37
+ In Node.js:
38
+
39
+ ```javascript
40
+ import DateTime from '@fr0st/datetime';
41
+ ```
42
+
43
+
44
+ ## Date Creation
45
+
46
+ - `dateString` is a string representing the date, and will default to the current timestamp.
47
+ - `options` is an object containing properties to define the new date.
48
+ - `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
49
+ - `locale` is a string representing the locale of the date, and will default to the system locale.
50
+
51
+ ```javascript
52
+ const dateTime = new DateTime(dateString, options);
53
+ ```
54
+
55
+ **From Array**
56
+
57
+ - `dateArray` is an array containing the year, month, date, hours, minutes, seconds and milliseconds.
58
+ - `options` is an object containing properties to define the new date.
59
+ - `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
60
+ - `locale` is a string representing the locale of the date, and will default to the system locale.
61
+
62
+ ```javascript
63
+ const dateTime = DateTime.fromArray(dateArray, options);
64
+ ```
65
+
66
+ The month and date in the `dateArray` will default to 1 if not set. The hours, minutes, seconds and milliseconds will default to 0.
67
+
68
+ **From Date**
69
+
70
+ - `dateObj` is a native JS *Date* object.
71
+ - `options` is an object containing properties to define the new date.
72
+ - `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
73
+ - `locale` is a string representing the locale of the date, and will default to the system locale.
74
+
75
+ ```javascript
76
+ const dateTime = DateTime.fromDate(dateObj, options);
77
+ ```
78
+
79
+ **From Format**
80
+
81
+ If you wish to parse a date string and you know the exact format, you can use the `fromFormat` static method.
82
+
83
+ - `formatString` is a string containing the format you wish to use for parsing.
84
+ - `dateString` is a string representing the date you are parsing.
85
+ - `options` is an object containing properties to define the new date.
86
+ - `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
87
+ - `locale` is a string representing the locale of the date, and will default to the system locale.
88
+
89
+ The `formatString` supports a subset of the ICU specification described in [Formats](Formats.md).
90
+
91
+ The `isValid` property on the created *DateTime* object can be used to determine whether a formatted string was a valid date.
92
+
93
+ ```javascript
94
+ const dateTime = DateTime.fromFormat(formatString, dateString, options);
95
+ ```
96
+
97
+ **From ISO String**
98
+
99
+ - `dateString` is a string representing the date you are parsing.
100
+ - `options` is an object containing properties to define the new date.
101
+ - `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
102
+ - `locale` is a string representing the locale of the date, and will default to English.
103
+
104
+ The `dateString` must be in *yyyy-MM-dd'T'HH:mm:ss.SSSxxx*" format and in English.
105
+
106
+ If the `timeZone` option is also passed, the created *DateTime* will be converted to the new `timeZone`.
107
+
108
+ The `isValid` property on the created *DateTime* object can be used to determine whether a formatted string was a valid date.
109
+
110
+ ```javascript
111
+ const dateTime = DateTime.fromISOString(dateString, options);
112
+ ```
113
+
114
+ **From Timestamp**
115
+
116
+ - `timestamp` is the number of seconds since the UNIX epoch.
117
+ - `options` is an object containing properties to define the new date.
118
+ - `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
119
+ - `locale` is a string representing the locale of the date, and will default to the system locale.
120
+
121
+ ```javascript
122
+ const dateTime = DateTime.fromTimestamp(timestamp, options);
123
+ ```
124
+
125
+ **Now**
126
+
127
+ - `options` is an object containing properties to define the new date.
128
+ - `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
129
+ - `locale` is a string representing the locale of the date, and will default to the system locale.
130
+
131
+ ```javascript
132
+ const dateTime = DateTime.now(options);
133
+ ```
134
+
135
+
136
+ ## Date Formatting
137
+
138
+ **Format**
139
+
140
+ Once you have created a *DateTime* object, you can get a string representation using a specific format with the `format` method.
141
+
142
+ - `formatString` is a string containing the format you wish to output using.
143
+
144
+ The `formatString` supports a subset of the ICU specification described in [Formats](Formats.md).
145
+
146
+ ```javascript
147
+ const dateString = dateTime.format(formatString);
148
+ ```
149
+
150
+ **To String**
151
+
152
+ Format the current date using "*eee MMM dd yyyy HH:mm:ss xx (VV)*".
153
+
154
+ ```javascript
155
+ const string = dateTime.toString();
156
+ ```
157
+
158
+ **To Date String**
159
+
160
+ Format the current date using "*eee MMM dd yyyy*".
161
+
162
+ ```javascript
163
+ const dateString = dateTime.toDateString();
164
+ ```
165
+
166
+ **To ISO String**
167
+
168
+ Format the current date using "*yyyy-MM-dd'T'HH:mm:ss.SSSxxx*" (in English and UTC time zone).
169
+
170
+ ```javascript
171
+ const isoString = dateTime.toISOString();
172
+ ```
173
+
174
+ **To Time String**
175
+
176
+ Format the current date using "*HH:mm:ss xx (VV)*".
177
+
178
+ ```javascript
179
+ const timeString = dateTime.toTimeString();
180
+ ```
181
+
182
+ **To UTC String**
183
+
184
+ Format the current date using "*eee MMM dd yyyy HH:mm:ss xx (VV)*" (in UTC time zone).
185
+
186
+ ```javascript
187
+ const utcString = dateTime.toUTCString();
188
+ ```
189
+
190
+
191
+ ## Date Attributes
192
+
193
+ **Get Date**
194
+
195
+ Get the date in current time zone.
196
+
197
+ ```javascript
198
+ const date = dateTime.getDate();
199
+ ```
200
+
201
+ **Get Day**
202
+
203
+ Get the day of the week in current time zone.
204
+
205
+ The `day` returned will be between *0* (Sunday) and *6* (Saturday).
206
+
207
+ ```javascript
208
+ const day = dateTime.getDay();
209
+ ```
210
+
211
+ **Get Day Of Year**
212
+
213
+ Get the day of the year in current time zone.
214
+
215
+ The `dayOfYear` returned will be between *0* and *365*.
216
+
217
+ ```javascript
218
+ const dayOfYear = dateTime.getDayOfYear();
219
+ ```
220
+
221
+ **Get Month**
222
+
223
+ Get the month in current time zone.
224
+
225
+ The `month` returned will be between *1* (January) and *12* (December).
226
+
227
+ ```javascript
228
+ const month = dateTime.getMonth();
229
+ ```
230
+
231
+ **Get Quarter**
232
+
233
+ Get the quarter of the year in current time zone.
234
+
235
+ The `quarter` returned will be between *1* and *4*.
236
+
237
+ ```javascript
238
+ const quarter = dateTime.getQuarter();
239
+ ```
240
+
241
+ **Get Year**
242
+
243
+ Get the year in current time zone.
244
+
245
+ ```javascript
246
+ const year = dateTime.getYear();
247
+ ```
248
+
249
+ **Set Date**
250
+
251
+ Set the date in current time zone.
252
+
253
+ - `date` is a number representing the date.
254
+
255
+ ```javascript
256
+ const newDateTime = dateTime.setDate(date);
257
+ ```
258
+
259
+ **Set Day**
260
+
261
+ Set the day of the week in current time zone.
262
+
263
+ - `day` is a number representing the day of the week (between *0* and *6*).
264
+
265
+ ```javascript
266
+ const newDateTime = dateTime.setDay(day);
267
+ ```
268
+
269
+ **Set Day Of Year**
270
+
271
+ Set the day of the year in current time zone.
272
+
273
+ - `dayOfYear` is a number representing the day of the year (between *0* and *365*).
274
+
275
+ ```javascript
276
+ const newDateTime = dateTime.setDayOfYear(dayOfYear);
277
+ ```
278
+
279
+ **Set Month**
280
+
281
+ Set the month in current time zone.
282
+
283
+ - `month` is a number representing the month (between *1* and *12*).
284
+ - `date` is a number representing the date, and will default to the current value.
285
+
286
+ If the `date` argument is omitted, and the new month contains less days than the current date, the date will be set to the last day of the new month.
287
+
288
+ To disable date clamping, use the method `DateTime.setDateClamping()` using *false* as the argument.
289
+
290
+ ```javascript
291
+ const newDateTime = dateTime.setMonth(month, date);
292
+ ```
293
+
294
+ **Set Quarter**
295
+
296
+ Set the quarter of the year in current time zone.
297
+
298
+ - `quarter` is a number representing the quarter between *1* and *4*.
299
+
300
+ ```javascript
301
+ const newDateTime = dateTime.setQuarter(quarter);
302
+ ```
303
+
304
+ **Set Year**
305
+
306
+ Set the year in current time zone.
307
+
308
+ - `year` is a number representing the year.
309
+ - `month` is a number representing the month (between *1* and *12*), and will default to the current value.
310
+ - `date` is a number representing the date, and will default to the current value.
311
+
312
+ If the `date` argument is omitted, and the new month contains less days than the current date, the date will be set to the last day of the new month.
313
+
314
+ To disable date clamping, use the method `DateTime.setDateClamping()` using *false* as the argument.
315
+
316
+ ```javascript
317
+ const newDateTime = dateTime.setYear(year, month, date);
318
+ ```
319
+
320
+
321
+ ## Week Attributes
322
+
323
+ **Get Week**
324
+
325
+ Get the week of the year in current time zone.
326
+
327
+ The `week` returned will be between *1* and *53* (week starting on Monday).
328
+
329
+ ```javascript
330
+ const week = dateTime.getWeek();
331
+ ```
332
+
333
+ **Get Week Day**
334
+
335
+ Get the local day of the week in current time zone.
336
+
337
+ The `weekDay` returned will be between *1* and *7*.
338
+
339
+ ```javascript
340
+ const weekDay = dateTime.getWeekDay();
341
+ ```
342
+
343
+ **Get Week Day In Month**
344
+
345
+ Get the day of the week in the month, in current time zone.
346
+
347
+ The `weekDayInMonth` returned will be between *1* and *5*.
348
+
349
+ ```javascript
350
+ const weekDayInMonth = dateTime.getWeekDayInMonth();
351
+ ```
352
+
353
+ **Get Week Of Month**
354
+
355
+ Get the week of the month in current time zone.
356
+
357
+ The `weekOfMonth` returned will be between *1* and *5*.
358
+
359
+ ```javascript
360
+ const weekOfMonth = dateTime.getWeekOfMonth();
361
+ ```
362
+
363
+ **Get Week Year**
364
+
365
+ Get the week year in current time zone.
366
+
367
+ This method is identical to `getYear()` except in cases where the week belongs to the previous or next year, then that value will be used instead.
368
+
369
+ ```javascript
370
+ const weekYear = dateTime.getWeekYear();
371
+ ```
372
+
373
+ **Set Week**
374
+
375
+ Set the week in current time zone.
376
+
377
+ - `week` is a number representing the week.
378
+ - `weekDay` is a number representing the day (between *1* and *7*), and will default to the current value.
379
+
380
+ ```javascript
381
+ const newDateTime = dateTime.setWeek(week, weekDay);
382
+ ```
383
+
384
+ **Set Week Day**
385
+
386
+ Set the local day of the week in current time zone.
387
+
388
+ - `weekDay` is a number representing the week day (between *1* and *7*).
389
+
390
+ ```javascript
391
+ const newDateTime = dateTime.setWeekDay(weekDay);
392
+ ```
393
+
394
+ **Set Week Day In Month**
395
+
396
+ Set the day of the week in the month, in current time zone.
397
+
398
+ - `weekDayInMonth` is a number representing the day of the week in month (between *1* and *5*).
399
+
400
+ ```javascript
401
+ const newDateTime = dateTime.setWeekDayInMonth(weekDayInMonth);
402
+ ```
403
+
404
+ **Set Week Of Month**
405
+
406
+ Set the week of the month in current time zone.
407
+
408
+ - `weekOfMonth` is a number representing the week of the month (between *1* and *5*).
409
+
410
+ ```javascript
411
+ const newDateTime = dateTime.setWeekOfMonth(weekOfMonth);
412
+ ```
413
+
414
+ **Set Week Year**
415
+
416
+ Set the week year in current time zone.
417
+
418
+ - `weekYear` is a number representing the year.
419
+ - `week` is a number representing the week, and will default to the current value.
420
+ - `weekDay` is a number representing the day (between *1* and *7*), and will default to the current value.
421
+
422
+ ```javascript
423
+ const newDateTime = dateTime.setWeekYear(weekYear, week, weekDay);
424
+ ```
425
+
426
+
427
+ ## Time Attributes
428
+
429
+ **Get Hours**
430
+
431
+ Get the hours of the day in current time zone.
432
+
433
+ The `hours` returned will be between *0* and *23*.
434
+
435
+ ```javascript
436
+ const hours = dateTime.getHours();
437
+ ```
438
+
439
+ **Get Milliseconds**
440
+
441
+ Get the milliseconds of the second in current time zone.
442
+
443
+ The `milliseconds` returned will be between *0* and *999*.
444
+
445
+ ```javascript
446
+ const milliseconds = dateTime.getMilliseconds();
447
+ ```
448
+
449
+ **Get Minutes**
450
+
451
+ Get the minutes of the hour in current time zone.
452
+
453
+ The `minutes` returned will be between *0* and *59*.
454
+
455
+ ```javascript
456
+ const minutes = dateTime.getMinutes();
457
+ ```
458
+
459
+ **Get Seconds**
460
+
461
+ Get the seconds of the minute in current time zone.
462
+
463
+ The `seconds` returned will be between *0* and *59*.
464
+
465
+ ```javascript
466
+ const seconds = dateTime.getSeconds();
467
+ ```
468
+
469
+ **Set Hours**
470
+
471
+ Set the hours of the day in current time zone.
472
+
473
+ - `hours` is a number representing the hours of the day (between *0* and *23*).
474
+ - `minutes` is a number representing the minutes of the hour (between *0* and *59*), and will default to the current value.
475
+ - `seconds` is a number representing the seconds of the minute (between *0* and *59*), and will default to the current value.
476
+ - `milliseconds` is a number representing the milliseconds of the second (between *0* and *999*), and will default to the current value.
477
+
478
+ ```javascript
479
+ const newDateTime = dateTime.setHours(hours, minutes, seconds, milliseconds);
480
+ ```
481
+
482
+ **Set Milliseconds**
483
+
484
+ Set the milliseconds of the second in current time zone.
485
+
486
+ - `milliseconds` is a number representing the milliseconds of the second (between *0* and *999*).
487
+
488
+ ```javascript
489
+ const newDateTime = dateTime.setMilliseconds(milliseconds);
490
+ ```
491
+
492
+ **Set Minutes**
493
+
494
+ Set the minutes of the hour in current time zone.
495
+
496
+ - `minutes` is a number representing the minutes of the hour (between *0* and *59*).
497
+ - `seconds` is a number representing the seconds of the minute (between *0* and *59*), and will default to the current value.
498
+ - `milliseconds` is a number representing the milliseconds of the second (between *0* and *999*), and will default to the current value.
499
+
500
+ ```javascript
501
+ const newDateTime = dateTime.setMinutes(minutes, seconds, milliseconds);
502
+ ```
503
+
504
+ **Set Seconds**
505
+
506
+ Set the seconds of the minute in current time zone.
507
+
508
+ - `seconds` is a number representing the seconds of the minute (between *0* and *59*).
509
+ - `milliseconds` is a number representing the milliseconds of the second (between *0* and *999*), and will default to the current value.
510
+
511
+ ```javascript
512
+ const newDateTime = dateTime.setSeconds(seconds, milliseconds);
513
+ ```
514
+
515
+
516
+ ## Timestamps
517
+
518
+ **Get Milliseconds**
519
+
520
+ Get the number of milliseconds since the UNIX epoch.
521
+
522
+ ```javascript
523
+ const time = dateTime.getTime();
524
+ ```
525
+
526
+ **Get Seconds**
527
+
528
+ Get the number of seconds since the UNIX epoch.
529
+
530
+ ```javascript
531
+ const timestamp = dateTime.getTimestamp();
532
+ ```
533
+
534
+ **Set Milliseconds**
535
+
536
+ Set the number of milliseconds since the UNIX epoch.
537
+
538
+ ```javascript
539
+ const newDateTime = dateTime.setTime(time);
540
+ ```
541
+
542
+ **Set Seconds**
543
+
544
+ Set the number of seconds since the UNIX epoch.
545
+
546
+ ```javascript
547
+ const newDateTime = dateTime.setTimestamp(timestamp);
548
+ ```
549
+
550
+
551
+ ## Time Zones
552
+
553
+ **Get Time Zone**
554
+
555
+ Get the name of the current time zone.
556
+
557
+ ```javascript
558
+ const timeZone = dateTime.getTimeZone();
559
+ ```
560
+
561
+ **Get Time Zone Offset**
562
+
563
+ Get the UTC offset (in minutes) of the current time zone.
564
+
565
+ ```javascript
566
+ const offset = dateTime.getTimeZoneOffset();
567
+ ```
568
+
569
+ **Set Time Zone**
570
+
571
+ Set the current time zone.
572
+
573
+ - `timeZone` is the name of the new time zone, which can be either "*UTC*", a supported value from the [IANA timeZone database](https://www.iana.org/time-zones) or an offset string.
574
+
575
+ ```javascript
576
+ const newDateTime = dateTime.setTimeZone(timeZone);
577
+ ```
578
+
579
+ **Set Time Zone Offset**
580
+
581
+ Set the UTC offset (in minutes).
582
+
583
+ - `offset` is the UTC offset (in minutes).
584
+
585
+ ```javascript
586
+ const newDateTime = dateTime.setTimeZoneOffset(offset);
587
+ ```
588
+
589
+
590
+ ## Locales
591
+
592
+ **Get Locale**
593
+
594
+ Get the name of the current locale.
595
+
596
+ ```javascript
597
+ const locale = dateTime.getLocale();
598
+ ```
599
+
600
+ **Set Locale**
601
+
602
+ Set the current locale.
603
+
604
+ - `locale` is the name of the new locale.
605
+
606
+ ```javascript
607
+ const newDateTime = dateTime.setLocale(locale);
608
+ ```
609
+
610
+
611
+ ## Manipulation
612
+
613
+ **Add**
614
+
615
+ Add a duration to the date.
616
+
617
+ - `amount` is a number representing the amount of the `timeUnit` to add.
618
+ - `timeUnit` is a string representing the unit of time to add, and can be one of either "*year*", "*month*", "*week*", "*day*", "*hour*", "*minute*" or "*second*", or their pluralized versions.
619
+
620
+ ```javascript
621
+ const newDateTime = dateTime.add(amount, timeUnit);
622
+ ```
623
+
624
+ **End Of**
625
+
626
+ Set the date to the end of a unit of time in current time zone.
627
+
628
+ - `timeUnit` is a string representing the unit of time to use, and can be one of either "*year*", "*quarter*", "*month*", "*week*", "*day*", "*hour*", "*minute*" or "*second*".
629
+
630
+ ```javascript
631
+ const newDateTime = dateTime.endOf(timeUnit);
632
+ ```
633
+
634
+ **Start Of**
635
+
636
+ Set the date to the start of a unit of time in current time zone.
637
+
638
+ - `timeUnit` is a string representing the unit of time to use, and can be one of either "*year*", "*quarter*", "*month*", "*week*", "*day*", "*hour*", "*minute*" or "*second*".
639
+
640
+ ```javascript
641
+ const newDateTime = dateTime.startOf(timeUnit);
642
+ ```
643
+
644
+ **Subtract**
645
+
646
+ - `amount` is a number representing the amount of the `timeUnit` to subtract.
647
+ - `timeUnit` is a string representing the unit of time to subtract, and can be one of either "*year*", "*month*", "*week*", "*day*", "*hour*", "*minute*" or "*second*", or their pluralized versions.
648
+
649
+ ```javascript
650
+ const newDateTime = dateTime.sub(amount, timeUnit);
651
+ ```
652
+
653
+
654
+ ## Utility Methods
655
+
656
+ **Day Name**
657
+
658
+ Get the name of the day of the week in current time zone and locale.
659
+
660
+ - `type` can be either "*long*", "*short*" or "*narrow*", and will default to "*long*" if it is not set.
661
+
662
+ ```javascript
663
+ const dayName = dateTime.dayName(type);
664
+ ```
665
+
666
+ **Day Period**
667
+
668
+ Get the day period in current time zone and locale.
669
+
670
+ - `type` can be either "*long*" or "*short*", and will default to "*long*" if it is not set.
671
+
672
+ ```javascript
673
+ const dayPeriod = dateTime.dayPeriod(type);
674
+ ```
675
+
676
+ **Days In Month**
677
+
678
+ Get the number of days in the current month.
679
+
680
+ ```javascript
681
+ const daysInMonth = dateTime.daysInMonth();
682
+ ```
683
+
684
+ **Days In Year**
685
+
686
+ Get the number of days in the current year.
687
+
688
+ ```javascript
689
+ const daysInYear = dateTime.daysInYear();
690
+ ```
691
+
692
+ **Difference**
693
+
694
+ Get the difference between two Dates.
695
+
696
+ - `other` is the *DateTime* object to compare to.
697
+ - `timeUnit` is a string representing the unit of time to return, and can be one of either "*year*", "*month*", "*week*", "*day*", "*hour*", "*minute*" or "*second*", or their pluralized versions.
698
+ - `relative` is a boolean indicating whether to return the relative difference, and will default to *true*.
699
+
700
+ If the `timeUnit` is omitted, this method will return the difference in milliseconds.
701
+
702
+ ```javascript
703
+ const diff = dateTime.diff(other, timeUnit, relative);
704
+ ```
705
+
706
+ If `relative` is *true* (default) the value returned will be the difference in the specified `timeUnit`, ignoring less significant values.
707
+
708
+ ```javascript
709
+ DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').diff(DateTime.fromFormat('yyyy-MM-dd', '2018-12-31'), 'years', true); // 1
710
+ DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').diff(DateTime.fromFormat('yyyy-MM-dd', '2018-12-31'), 'years', false); // 0
711
+ DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').diff(DateTime.fromFormat('yyyy-MM-dd', '2017-12-31'), 'years', true); // 2
712
+ DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').diff(DateTime.fromFormat('yyyy-MM-dd', '2017-12-31'), 'years', false); // 1
713
+ ```
714
+
715
+ **Era**
716
+
717
+ Get the era in current time zone and locale.
718
+
719
+ - `type` can be either "*long*", "*short*" or "*narrow*", and will default to "*long*" if it is not set.
720
+
721
+ ```javascript
722
+ const era = dateTime.era(type);
723
+ ```
724
+
725
+ **Human Difference**
726
+
727
+ Get the relative difference between two Dates in a human readable format using the current locale.
728
+
729
+ - `other` is the *DateTime* object to compare to.
730
+ - `timeUnit` is a string representing the unit of time to return, and can be one of either "*year*", "*month*", "*week*", "*day*", "*hour*", "*minute*" or "*second*", or their pluralized versions.
731
+
732
+ If the `timeUnit` is omitted, this method will use the (relative) most significant non-zero value.
733
+
734
+ ```javascript
735
+ const diff = dateTime.humanDiff(other, timeUnit);
736
+ ```
737
+
738
+ The most significant non-zero value is determined where the unit of time has a non-relative difference, or the next relative difference value is greater than or equal to the unit of time.
739
+
740
+ ```javascript
741
+ DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').humanDiff(DateTime.fromFormat('yyyy-MM-dd', '2018-12-31')); // "tomorrow"
742
+ DateTime.fromFormat('yyyy-MM-dd', '2019-02-27').humanDiff(DateTime.fromFormat('yyyy-MM-dd', '2019-01-31')); // "in 27 days"
743
+ DateTime.fromFormat('yyyy-MM-dd', '2019-02-28').humanDiff(DateTime.fromFormat('yyyy-MM-dd', '2019-01-31')); // "next month"
744
+ DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').humanDiff(DateTime.fromFormat('yyyy-MM-dd', '2018-06-01')); // "in 6 months"
745
+ DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').humanDiff(DateTime.fromFormat('yyyy-MM-dd', '2018-01-31')); // "next year"
746
+ DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').humanDiff(DateTime.fromFormat('yyyy-MM-dd', '2017-12-31')); // "in 2 years"
747
+ ```
748
+
749
+ **Is After?**
750
+
751
+ Return *true* if the *DateTime* is after another date.
752
+
753
+ - `other` is the *DateTime* object to compare to.
754
+ - `granularity` is a string specifying the level of granularity to use when comparing the dates, and can be one of either "*year*", "*month*", "*day*", "*hour*", "*minute*" or "*second*".
755
+
756
+ ```javascript
757
+ const isAfter = dateTime.isAfter(other, granularity);
758
+ ```
759
+
760
+ If a `granularity` is not specified, this method will compare the dates in milliseconds.
761
+
762
+ **Is Before?**
763
+
764
+ Return *true* if the *DateTime* is before another date.
765
+
766
+ - `other` is the *DateTime* object to compare to.
767
+ - `granularity` is a string specifying the level of granularity to use when comparing the dates, and can be one of either "*year*", "*month*", "*day*", "*hour*", "*minute*" or "*second*".
768
+
769
+ ```javascript
770
+ const isBefore = dateTime.isBefore(other, granularity);
771
+ ```
772
+
773
+ If a `granularity` is not specified, this method will compare the dates in milliseconds.
774
+
775
+ **Is Between?**
776
+
777
+ Return *true* if the *DateTime* is between two other dates.
778
+
779
+ - `start` is the starting *DateTime* object to compare to.
780
+ - `end` is the ending *DateTime* object to compare to.
781
+ - `granularity` is a string specifying the level of granularity to use when comparing the dates, and can be one of either "*year*", "*month*", "*day*", "*hour*", "*minute*" or "*second*".
782
+
783
+ ```javascript
784
+ const isBetween = dateTime.isBetween(start, end, granularity);
785
+ ```
786
+
787
+ If a `granularity` is not specified, this method will compare the dates in milliseconds.
788
+
789
+ **Is DST?**
790
+
791
+ Return *true* if the *DateTime* is in daylight savings.
792
+
793
+ ```javascript
794
+ const isDST = dateTime.isDST();
795
+ ```
796
+
797
+ **Is Leap Year?**
798
+
799
+ Return *true* if the year is a leap year.
800
+
801
+ ```javascript
802
+ const isLeapYear = dateTime.isLeapYear();
803
+ ```
804
+
805
+ **Is Same?**
806
+
807
+ Return *true* if the *DateTime* is the same as another date.
808
+
809
+ - `other` is the *DateTime* object to compare to.
810
+ - `granularity` is a string specifying the level of granularity to use when comparing the dates, and can be one of either "*year*", "*month*", "*day*", "*hour*", "*minute*" or "*second*".
811
+
812
+ ```javascript
813
+ const isSame = dateTime.isSame(other, granularity);
814
+ ```
815
+
816
+ If a `granularity` is not specified, this method will compare the dates in milliseconds.
817
+
818
+ **Is Same Or After?**
819
+
820
+ Return *true* if the *DateTime* is the same or after another date.
821
+
822
+ - `other` is the *DateTime* object to compare to.
823
+ - `granularity` is a string specifying the level of granularity to use when comparing the dates, and can be one of either "*year*", "*month*", "*day*", "*hour*", "*minute*" or "*second*".
824
+
825
+ ```javascript
826
+ const isSameOrAfter = dateTime.isSameOrAfter(other, granularity);
827
+ ```
828
+
829
+ If a `granularity` is not specified, this method will compare the dates in milliseconds.
830
+
831
+ **Is Same Or Before?**
832
+
833
+ Return *true* if the *DateTime* is the same or before another date.
834
+
835
+ - `other` is the *DateTime* object to compare to.
836
+ - `granularity` is a string specifying the level of granularity to use when comparing the dates, and can be one of either "*year*", "*month*", "*day*", "*hour*", "*minute*" or "*second*".
837
+
838
+ ```javascript
839
+ const isSameOrBefore = dateTime.isSameOrBefore(other, granularity);
840
+ ```
841
+
842
+ If a `granularity` is not specified, this method will compare the dates in milliseconds.
843
+
844
+ **Month Name**
845
+
846
+ Get the name of the month in current time zone and locale.
847
+
848
+ - `type` can be either "*long*", "*short*" or "*narrow*", and will default to "*long*" if it is not set.
849
+
850
+ ```javascript
851
+ const monthName = dateTime.monthName(type);
852
+ ```
853
+
854
+ **Time Zone Name**
855
+
856
+ Get the name of the current time zone and locale.
857
+
858
+ - `type` can be either "*long*" or "*short*", and will default to "*long*" if it is not set.
859
+
860
+ ```javascript
861
+ const timeZoneName = dateTime.timeZoneName(type);
862
+ ```
863
+
864
+ **Weeks In Year**
865
+
866
+ Get the number of weeks in the current year.
867
+
868
+ ```javascript
869
+ const weeksInYear = dateTime.weeksInYear();
870
+ ```
871
+
872
+
873
+ ## Static Methods
874
+
875
+ **Day Of Year**
876
+
877
+ Get the day of the year for a year, month and date.
878
+
879
+ - `year` is a number representing the year.
880
+ - `month` is a number representing the month (between *1* and *12*).
881
+ - `date` is a number representing the date.
882
+
883
+ ```javascript
884
+ const dayOfYear = DateTime.dayOfYear(year, month, date);
885
+ ```
886
+
887
+ **Days In Month**
888
+
889
+ Get the number of days in a month, from a year and month.
890
+
891
+ - `year` is a number representing the year.
892
+ - `month` is a number representing the month (between *1* and *12*).
893
+
894
+ ```javascript
895
+ const daysInMonth = DateTime.daysInMonth(year, month);
896
+ ```
897
+
898
+ **Days In Year**
899
+
900
+ Get the number of days in a year.
901
+
902
+ - `year` is a number representing the year.
903
+
904
+ ```javascript
905
+ const daysInYear = DateTime.daysInYear(year);
906
+ ```
907
+
908
+ **Get Default Locale**
909
+
910
+ Get the default locale.
911
+
912
+ ```javascript
913
+ locale = DateTime.getDefaultLocale();
914
+ ```
915
+
916
+ **Set Default Time Zone**
917
+
918
+ Get the default time zone.
919
+
920
+ ```javascript
921
+ timeZone = DateTime.getDefaultTimeZone();
922
+ ```
923
+
924
+ **Is Leap Year?**
925
+
926
+ Return *true* if the year is a leap year.
927
+
928
+ - `year` is a number representing the year.
929
+
930
+ ```javascript
931
+ const isLeapYear = DateTime.isLeapYear(year);
932
+ ```
933
+
934
+ **Set Date Clamping**
935
+
936
+ Set whether dates will be clamped when changing months.
937
+
938
+ - `clampDates` is a boolean indicating whether to clamp dates.
939
+
940
+ ```javascript
941
+ DateTime.setDateClamping(clampDates);
942
+ ```
943
+
944
+ **Set Default Locale**
945
+
946
+ Set the default locale.
947
+
948
+ - `locale` is the name of the locale.
949
+
950
+ ```javascript
951
+ DateTime.setDefaultLocale(locale);
952
+ ```
953
+
954
+ **Set Default Time Zone**
955
+
956
+ Set the default time zone.
957
+
958
+ - `timeZone` is the name of the time zone, which can be either "*UTC*", a supported value from the [IANA timeZone database](https://www.iana.org/time-zones) or an offset string.
959
+
960
+ ```javascript
961
+ DateTime.setDefaultTimeZone(timeZone);
962
+ ```