@fr0st/datetime 6.0.1 → 7.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 CHANGED
@@ -1,1868 +1,407 @@
1
- # FrostDateTime
2
-
3
- **FrostDateTime** is a free, open-source immutable date manipulation library for *JavaScript*.
4
-
5
- It is a lightweight (~7kb 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
- - [Manipulation](#manipulation)
19
- - [Comparisons](#comparisons)
20
- - [Utility Methods](#utility-methods)
21
- - [Static Methods](#static-methods)
22
-
23
-
24
-
25
- ## Installation
26
-
27
- **In Browser**
28
-
29
- ```html
30
- <script type="text/javascript" src="/path/to/frost-datetime.min.js"></script>
31
- ```
32
-
33
- **Using NPM**
34
-
35
- ```
36
- npm i @fr0st/datetime
37
- ```
38
-
39
- In Node.js:
40
-
41
- ```javascript
42
- import DateTime from '@fr0st/datetime';
43
- ```
44
-
45
-
46
- ## Date Creation
47
-
48
- - `dateString` is a string representing the date, and will default to the current timestamp.
49
- - `options` is an object containing options for creating the new date.
50
- - `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
51
- - `locale` is a string representing the locale of the date, and will default to the system locale.
52
-
53
- ```javascript
54
- const dateTime = new DateTime(dateString, options);
55
- ```
56
-
57
- **From Array**
58
-
59
- - `dateArray` is an array containing the year, month, date, hours, minutes, seconds and milliseconds.
60
- - `options` is an object containing options for creating the new date.
61
- - `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
62
- - `locale` is a string representing the locale of the date, and will default to the system locale.
63
-
64
- ```javascript
65
- const dateTime = DateTime.fromArray(dateArray, options);
66
- ```
67
-
68
- The month and date in the `dateArray` will default to 1 if not set. The hours, minutes, seconds and milliseconds will default to 0.
69
-
70
- **From Date**
71
-
72
- - `dateObj` is a native JS *Date* object.
73
- - `options` is an object containing options for creating the new date.
74
- - `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
75
- - `locale` is a string representing the locale of the date, and will default to the system locale.
76
-
77
- ```javascript
78
- const dateTime = DateTime.fromDate(dateObj, options);
79
- ```
80
-
81
- **From Format**
82
-
83
- If you wish to parse a date string and you know the exact format, you can use the `fromFormat` static method.
84
-
85
- - `formatString` is a string containing the format you wish to use for parsing.
86
- - `dateString` is a string representing the date you are parsing.
87
- - `options` is an object containing options for creating the new date.
88
- - `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
89
- - `locale` is a string representing the locale of the date, and will default to the system locale.
90
-
91
- The `formatString` supports a subset of the ICU specification described in [Formats](Formats.md).
92
-
93
- The `isValid` property on the created *DateTime* object can be used to determine whether a formatted string was a valid date.
94
-
95
- ```javascript
96
- const dateTime = DateTime.fromFormat(formatString, dateString, options);
97
- ```
98
-
99
- **From ISO String**
100
-
101
- - `dateString` is a string representing the date you are parsing.
102
- - `options` is an object containing options for creating the new date.
103
- - `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
104
- - `locale` is a string representing the locale of the date, and will default to English.
105
-
106
- The `dateString` must be in *yyyy-MM-dd'T'HH:mm:ss.SSSxxx*" format and in English.
107
-
108
- If the `timeZone` option is also passed, the created *DateTime* will be converted to the new `timeZone`.
109
-
110
- The `isValid` property on the created *DateTime* object can be used to determine whether a formatted string was a valid date.
111
-
112
- ```javascript
113
- const dateTime = DateTime.fromISOString(dateString, options);
114
- ```
115
-
116
- **From Timestamp**
117
-
118
- - `timestamp` is the number of seconds since the UNIX epoch.
119
- - `options` is an object containing options for creating the new date.
120
- - `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
121
- - `locale` is a string representing the locale of the date, and will default to the system locale.
122
-
123
- ```javascript
124
- const dateTime = DateTime.fromTimestamp(timestamp, options);
125
- ```
126
-
127
- **Now**
128
-
129
- - `options` is an object containing options for creating the new date.
130
- - `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
131
- - `locale` is a string representing the locale of the date, and will default to the system locale.
132
-
133
- ```javascript
134
- const dateTime = DateTime.now(options);
135
- ```
136
-
137
-
138
- ## Date Formatting
139
-
140
- **Format**
141
-
142
- Once you have created a *DateTime* object, you can get a string representation using a specific format with the `format` method.
143
-
144
- - `formatString` is a string containing the format you wish to output using.
145
-
146
- The `formatString` supports a subset of the ICU specification described in [Formats](Formats.md).
147
-
148
- ```javascript
149
- const dateString = dateTime.format(formatString);
150
- ```
151
-
152
- **To String**
153
-
154
- Format the current date using "*eee MMM dd yyyy HH:mm:ss xx (VV)*".
155
-
156
- ```javascript
157
- const string = dateTime.toString();
158
- ```
159
-
160
- **To Date String**
161
-
162
- Format the current date using "*eee MMM dd yyyy*".
163
-
164
- ```javascript
165
- const dateString = dateTime.toDateString();
166
- ```
167
-
168
- **To ISO String**
169
-
170
- Format the current date using "*yyyy-MM-dd'T'HH:mm:ss.SSSxxx*" (in English and UTC time zone).
171
-
172
- ```javascript
173
- const isoString = dateTime.toISOString();
174
- ```
175
-
176
- **To Time String**
177
-
178
- Format the current date using "*HH:mm:ss xx (VV)*".
179
-
180
- ```javascript
181
- const timeString = dateTime.toTimeString();
182
- ```
183
-
184
- **To UTC String**
185
-
186
- Format the current date using "*eee MMM dd yyyy HH:mm:ss xx (VV)*" (in UTC time zone).
187
-
188
- ```javascript
189
- const utcString = dateTime.toUTCString();
190
- ```
191
-
192
-
193
- ## Date Attributes
194
-
195
- **Get Date**
196
-
197
- Get the date in current time zone.
198
-
199
- ```javascript
200
- const date = dateTime.getDate();
201
- ```
202
-
203
- **Get Day**
204
-
205
- Get the day of the week in current time zone.
206
-
207
- The `day` returned will be between *0* (Sunday) and *6* (Saturday).
208
-
209
- ```javascript
210
- const day = dateTime.getDay();
211
- ```
212
-
213
- **Get Day Of Year**
214
-
215
- Get the day of the year in current time zone.
216
-
217
- The `dayOfYear` returned will be between *0* and *365*.
218
-
219
- ```javascript
220
- const dayOfYear = dateTime.getDayOfYear();
221
- ```
222
-
223
- **Get Month**
224
-
225
- Get the month in current time zone.
226
-
227
- The `month` returned will be between *1* (January) and *12* (December).
228
-
229
- ```javascript
230
- const month = dateTime.getMonth();
231
- ```
232
-
233
- **Get Quarter**
234
-
235
- Get the quarter of the year in current time zone.
236
-
237
- The `quarter` returned will be between *1* and *4*.
238
-
239
- ```javascript
240
- const quarter = dateTime.getQuarter();
241
- ```
242
-
243
- **Get Year**
244
-
245
- Get the year in current time zone.
246
-
247
- ```javascript
248
- const year = dateTime.getYear();
249
- ```
250
-
251
- **Set Date**
252
-
253
- Set the date in current time zone.
254
-
255
- - `date` is a number representing the date.
256
-
257
- ```javascript
258
- const newDateTime = dateTime.setDate(date);
259
- ```
260
-
261
- **Set Day**
262
-
263
- Set the day of the week in current time zone.
264
-
265
- - `day` is a number representing the day of the week (between *0* and *6*).
266
-
267
- ```javascript
268
- const newDateTime = dateTime.setDay(day);
269
- ```
270
-
271
- **Set Day Of Year**
272
-
273
- Set the day of the year in current time zone.
274
-
275
- - `dayOfYear` is a number representing the day of the year (between *0* and *365*).
276
-
277
- ```javascript
278
- const newDateTime = dateTime.setDayOfYear(dayOfYear);
279
- ```
280
-
281
- **Set Month**
282
-
283
- Set the month in current time zone.
284
-
285
- - `month` is a number representing the month (between *1* and *12*).
286
- - `date` is a number representing the date, and will default to the current value.
287
-
288
- 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.
289
-
290
- To disable date clamping, use the method `DateTime.setDateClamping()` using *false* as the argument.
291
-
292
- ```javascript
293
- const newDateTime = dateTime.setMonth(month, date);
294
- ```
295
-
296
- **Set Quarter**
297
-
298
- Set the quarter of the year in current time zone.
299
-
300
- - `quarter` is a number representing the quarter between *1* and *4*.
301
-
302
- ```javascript
303
- const newDateTime = dateTime.setQuarter(quarter);
304
- ```
305
-
306
- **Set Year**
307
-
308
- Set the year in current time zone.
309
-
310
- - `year` is a number representing the year.
311
- - `month` is a number representing the month (between *1* and *12*), and will default to the current value.
312
- - `date` is a number representing the date, and will default to the current value.
313
-
314
- 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.
315
-
316
- To disable date clamping, use the method `DateTime.setDateClamping()` using *false* as the argument.
317
-
318
- ```javascript
319
- const newDateTime = dateTime.setYear(year, month, date);
320
- ```
321
-
322
-
323
- ## Week Attributes
324
-
325
- **Get Week**
326
-
327
- Get the week of the year in current time zone.
328
-
329
- The `week` returned will be between *1* and *53* (week starting on Monday).
330
-
331
- ```javascript
332
- const week = dateTime.getWeek();
333
- ```
334
-
335
- **Get Week Day**
336
-
337
- Get the local day of the week in current time zone.
338
-
339
- The `weekDay` returned will be between *1* and *7*.
340
-
341
- ```javascript
342
- const weekDay = dateTime.getWeekDay();
343
- ```
344
-
345
- **Get Week Day In Month**
346
-
347
- Get the day of the week in the month, in current time zone.
348
-
349
- The `weekDayInMonth` returned will be between *1* and *5*.
350
-
351
- ```javascript
352
- const weekDayInMonth = dateTime.getWeekDayInMonth();
353
- ```
354
-
355
- **Get Week Of Month**
356
-
357
- Get the week of the month in current time zone.
358
-
359
- The `weekOfMonth` returned will be between *1* and *5*.
360
-
361
- ```javascript
362
- const weekOfMonth = dateTime.getWeekOfMonth();
363
- ```
364
-
365
- **Get Week Year**
366
-
367
- Get the week year in current time zone.
368
-
369
- 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.
370
-
371
- ```javascript
372
- const weekYear = dateTime.getWeekYear();
373
- ```
374
-
375
- **Set Week**
376
-
377
- Set the week in current time zone.
378
-
379
- - `week` is a number representing the week.
380
- - `weekDay` is a number representing the day (between *1* and *7*), and will default to the current value.
381
-
382
- ```javascript
383
- const newDateTime = dateTime.setWeek(week, weekDay);
384
- ```
385
-
386
- **Set Week Day**
387
-
388
- Set the local day of the week in current time zone.
389
-
390
- - `weekDay` is a number representing the week day (between *1* and *7*).
391
-
392
- ```javascript
393
- const newDateTime = dateTime.setWeekDay(weekDay);
394
- ```
395
-
396
- **Set Week Day In Month**
397
-
398
- Set the day of the week in the month, in current time zone.
399
-
400
- - `weekDayInMonth` is a number representing the day of the week in month (between *1* and *5*).
401
-
402
- ```javascript
403
- const newDateTime = dateTime.setWeekDayInMonth(weekDayInMonth);
404
- ```
405
-
406
- **Set Week Of Month**
407
-
408
- Set the week of the month in current time zone.
409
-
410
- - `weekOfMonth` is a number representing the week of the month (between *1* and *5*).
411
-
412
- ```javascript
413
- const newDateTime = dateTime.setWeekOfMonth(weekOfMonth);
414
- ```
415
-
416
- **Set Week Year**
417
-
418
- Set the week year in current time zone.
419
-
420
- - `weekYear` is a number representing the year.
421
- - `week` is a number representing the week, and will default to the current value.
422
- - `weekDay` is a number representing the day (between *1* and *7*), and will default to the current value.
423
-
424
- ```javascript
425
- const newDateTime = dateTime.setWeekYear(weekYear, week, weekDay);
426
- ```
427
-
428
-
429
- ## Time Attributes
430
-
431
- **Get Hours**
432
-
433
- Get the hours of the day in current time zone.
434
-
435
- The `hours` returned will be between *0* and *23*.
436
-
437
- ```javascript
438
- const hours = dateTime.getHours();
439
- ```
440
-
441
- **Get Milliseconds**
442
-
443
- Get the milliseconds of the second in current time zone.
444
-
445
- The `milliseconds` returned will be between *0* and *999*.
446
-
447
- ```javascript
448
- const milliseconds = dateTime.getMilliseconds();
449
- ```
450
-
451
- **Get Minutes**
452
-
453
- Get the minutes of the hour in current time zone.
454
-
455
- The `minutes` returned will be between *0* and *59*.
456
-
457
- ```javascript
458
- const minutes = dateTime.getMinutes();
459
- ```
460
-
461
- **Get Seconds**
462
-
463
- Get the seconds of the minute in current time zone.
464
-
465
- The `seconds` returned will be between *0* and *59*.
466
-
467
- ```javascript
468
- const seconds = dateTime.getSeconds();
469
- ```
470
-
471
- **Set Hours**
472
-
473
- Set the hours of the day in current time zone.
474
-
475
- - `hours` is a number representing the hours of the day (between *0* and *23*).
476
- - `minutes` is a number representing the minutes of the hour (between *0* and *59*), and will default to the current value.
477
- - `seconds` is a number representing the seconds of the minute (between *0* and *59*), and will default to the current value.
478
- - `milliseconds` is a number representing the milliseconds of the second (between *0* and *999*), and will default to the current value.
479
-
480
- ```javascript
481
- const newDateTime = dateTime.setHours(hours, minutes, seconds, milliseconds);
482
- ```
483
-
484
- **Set Milliseconds**
485
-
486
- Set the milliseconds of the second in current time zone.
487
-
488
- - `milliseconds` is a number representing the milliseconds of the second (between *0* and *999*).
489
-
490
- ```javascript
491
- const newDateTime = dateTime.setMilliseconds(milliseconds);
492
- ```
493
-
494
- **Set Minutes**
495
-
496
- Set the minutes of the hour in current time zone.
497
-
498
- - `minutes` is a number representing the minutes of the hour (between *0* and *59*).
499
- - `seconds` is a number representing the seconds of the minute (between *0* and *59*), and will default to the current value.
500
- - `milliseconds` is a number representing the milliseconds of the second (between *0* and *999*), and will default to the current value.
501
-
502
- ```javascript
503
- const newDateTime = dateTime.setMinutes(minutes, seconds, milliseconds);
504
- ```
505
-
506
- **Set Seconds**
507
-
508
- Set the seconds of the minute in current time zone.
509
-
510
- - `seconds` is a number representing the seconds of the minute (between *0* and *59*).
511
- - `milliseconds` is a number representing the milliseconds of the second (between *0* and *999*), and will default to the current value.
512
-
513
- ```javascript
514
- const newDateTime = dateTime.setSeconds(seconds, milliseconds);
515
- ```
516
-
517
-
518
- ## Timestamps
519
-
520
- **Get Milliseconds**
521
-
522
- Get the number of milliseconds since the UNIX epoch.
523
-
524
- ```javascript
525
- const time = dateTime.getTime();
526
- ```
527
-
528
- **Get Seconds**
529
-
530
- Get the number of seconds since the UNIX epoch.
531
-
532
- ```javascript
533
- const timestamp = dateTime.getTimestamp();
534
- ```
535
-
536
- **Set Milliseconds**
537
-
538
- Set the number of milliseconds since the UNIX epoch.
539
-
540
- ```javascript
541
- const newDateTime = dateTime.setTime(time);
542
- ```
543
-
544
- **Set Seconds**
545
-
546
- Set the number of seconds since the UNIX epoch.
547
-
548
- ```javascript
549
- const newDateTime = dateTime.setTimestamp(timestamp);
550
- ```
551
-
552
-
553
- ## Time Zones
554
-
555
- **Get Time Zone**
556
-
557
- Get the name of the current time zone.
558
-
559
- ```javascript
560
- const timeZone = dateTime.getTimeZone();
561
- ```
562
-
563
- **Get Time Zone Offset**
564
-
565
- Get the UTC offset (in minutes) of the current time zone.
566
-
567
- ```javascript
568
- const offset = dateTime.getTimeZoneOffset();
569
- ```
570
-
571
- **Set Time Zone**
572
-
573
- Set the current time zone.
574
-
575
- - `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.
576
-
577
- ```javascript
578
- const newDateTime = dateTime.setTimeZone(timeZone);
579
- ```
580
-
581
- **Set Time Zone Offset**
582
-
583
- Set the UTC offset (in minutes).
584
-
585
- - `offset` is the UTC offset (in minutes).
586
-
587
- ```javascript
588
- const newDateTime = dateTime.setTimeZoneOffset(offset);
589
- ```
590
-
591
-
592
- ## Locales
593
-
594
- **Get Locale**
595
-
596
- Get the name of the current locale.
597
-
598
- ```javascript
599
- const locale = dateTime.getLocale();
600
- ```
601
-
602
- **Set Locale**
603
-
604
- Set the current locale.
605
-
606
- - `locale` is the name of the new locale.
607
-
608
- ```javascript
609
- const newDateTime = dateTime.setLocale(locale);
610
- ```
611
-
612
-
613
- ## Manipulation
614
-
615
- **Add Day**
616
-
617
- Add a day to the current date.
618
-
619
- ```javascript
620
- const newDateTime = dateTime.addDay();
621
- ```
622
-
623
- **Add Days**
624
-
625
- Add days to the current date.
626
-
627
- - `amount` is a number representing the amount of days to add.
628
-
629
- ```javascript
630
- const newDateTime = dateTime.addDay(amount);
631
- ```
632
-
633
- **Add Hour**
634
-
635
- Add a hour to the current date.
636
-
637
- ```javascript
638
- const newDateTime = dateTime.addHour();
639
- ```
640
-
641
- **Add Hours**
642
-
643
- Add hours to the current date.
644
-
645
- - `amount` is a number representing the amount of hours to add.
646
-
647
- ```javascript
648
- const newDateTime = dateTime.addHours(amount);
649
- ```
650
-
651
- **Add Minute**
652
-
653
- Add a minute to the current date.
654
-
655
- ```javascript
656
- const newDateTime = dateTime.addMinute();
657
- ```
658
-
659
- **Add Minutes**
660
-
661
- Add minutes to the current date.
662
-
663
- - `amount` is a number representing the amount of minutes to add.
664
-
665
- ```javascript
666
- const newDateTime = dateTime.addMinutes(amount);
667
- ```
668
-
669
- **Add Month**
670
-
671
- Add a month to the current date.
672
-
673
- ```javascript
674
- const newDateTime = dateTime.addMonth();
675
- ```
676
-
677
- **Add Months**
678
-
679
- Add months to the current date.
680
-
681
- - `amount` is a number representing the amount of months to add.
682
-
683
- ```javascript
684
- const newDateTime = dateTime.addMonths(amount);
685
- ```
686
-
687
- **Add Second**
688
-
689
- Add a second to the current date.
690
-
691
- ```javascript
692
- const newDateTime = dateTime.addSecond();
693
- ```
694
-
695
- **Add Seconds**
696
-
697
- Add seconds to the current date.
698
-
699
- - `amount` is a number representing the amount of seconds to add.
700
-
701
- ```javascript
702
- const newDateTime = dateTime.addSeconds(amount);
703
- ```
704
-
705
- **Add Week**
706
-
707
- Add a week to the current date.
708
-
709
- ```javascript
710
- const newDateTime = dateTime.addWeek();
711
- ```
712
-
713
- **Add Weeks**
714
-
715
- Add weeks to the current date.
716
-
717
- - `amount` is a number representing the amount of weeks to add.
718
-
719
- ```javascript
720
- const newDateTime = dateTime.addWeeks(amount);
721
- ```
722
-
723
- **Add Year**
724
-
725
- Add a year to the current date.
726
-
727
- ```javascript
728
- const newDateTime = dateTime.addYear();
729
- ```
730
-
731
- **Add Years**
732
-
733
- Add years to the current date.
734
-
735
- - `amount` is a number representing the amount of years to add.
736
-
737
- ```javascript
738
- const newDateTime = dateTime.addYears(amount);
739
- ```
740
-
741
- **End Of Day**
742
-
743
- Set the date to the end of the day in current time zone.
744
-
745
- ```javascript
746
- const newDateTime = dateTime.endOfDay();
747
- ```
748
-
749
- **End Of Hour**
750
-
751
- Set the date to the end of the hour in current time zone.
752
-
753
- ```javascript
754
- const newDateTime = dateTime.endOfHour();
755
- ```
756
-
757
- **End Of Minute**
758
-
759
- Set the date to the end of the minute in current time zone.
760
-
761
- ```javascript
762
- const newDateTime = dateTime.endOfMinute();
763
- ```
764
-
765
- **End Of Month**
766
-
767
- Set the date to the end of the month in current time zone.
768
-
769
- ```javascript
770
- const newDateTime = dateTime.endOfMonth();
771
- ```
772
-
773
- **End Of Quarter**
774
-
775
- Set the date to the end of the quarter in current time zone.
776
-
777
- ```javascript
778
- const newDateTime = dateTime.endOfQuarter();
779
- ```
780
-
781
- **End Of Second**
782
-
783
- Set the date to the end of the second in current time zone.
784
-
785
- ```javascript
786
- const newDateTime = dateTime.endOfSecond();
787
- ```
788
-
789
- **End Of Week**
790
-
791
- Set the date to the end of the week in current time zone.
792
-
793
- ```javascript
794
- const newDateTime = dateTime.endOfWeek();
795
- ```
796
-
797
- **End Of Year**
798
-
799
- Set the date to the end of the year in current time zone.
800
-
801
- ```javascript
802
- const newDateTime = dateTime.endOfYear();
803
- ```
804
-
805
- **Start Of Day**
806
-
807
- Set the date to the start of the day in current time zone.
808
-
809
- ```javascript
810
- const newDateTime = dateTime.startOfDay();
811
- ```
812
-
813
- **Start Of Hour**
814
-
815
- Set the date to the start of the hour in current time zone.
816
-
817
- ```javascript
818
- const newDateTime = dateTime.startOfHour();
819
- ```
820
-
821
- **Start Of Minute**
822
-
823
- Set the date to the start of the minute in current time zone.
824
-
825
- ```javascript
826
- const newDateTime = dateTime.startOfMinute();
827
- ```
828
-
829
- **Start Of Month**
830
-
831
- Set the date to the start of the month in current time zone.
832
-
833
- ```javascript
834
- const newDateTime = dateTime.startOfMonth();
835
- ```
836
-
837
- **Start Of Quarter**
838
-
839
- Set the date to the start of the quarter in current time zone.
840
-
841
- ```javascript
842
- const newDateTime = dateTime.startOfQuarter();
843
- ```
844
-
845
- **Start Of Second**
846
-
847
- Set the date to the start of the second in current time zone.
848
-
849
- ```javascript
850
- const newDateTime = dateTime.startOfSecond();
851
- ```
852
-
853
- **Start Of Week**
854
-
855
- Set the date to the start of the week in current time zone.
856
-
857
- ```javascript
858
- const newDateTime = dateTime.startOfWeek();
859
- ```
860
-
861
- **Start Of Year**
862
-
863
- Set the date to the start of the year in current time zone.
864
-
865
- ```javascript
866
- const newDateTime = dateTime.startOfYear();
867
- ```
868
-
869
- **Subtract Day**
870
-
871
- Subtract a day to the current date.
872
-
873
- ```javascript
874
- const newDateTime = dateTime.subtractDay();
875
- ```
876
-
877
- **Subtract Days**
878
-
879
- Subtract days to the current date.
880
-
881
- - `amount` is a number representing the amount of days to subtract.
882
-
883
- ```javascript
884
- const newDateTime = dateTime.subtractDay(amount);
885
- ```
886
-
887
- **Subtract Hour**
888
-
889
- Subtract a hour to the current date.
890
-
891
- ```javascript
892
- const newDateTime = dateTime.subtractHour();
893
- ```
894
-
895
- **Subtract Hours**
896
-
897
- Subtract hours to the current date.
898
-
899
- - `amount` is a number representing the amount of hours to subtract.
900
-
901
- ```javascript
902
- const newDateTime = dateTime.subtractHours(amount);
903
- ```
904
-
905
- **Subtract Minute**
906
-
907
- Subtract a minute to the current date.
908
-
909
- ```javascript
910
- const newDateTime = dateTime.subtractMinute();
911
- ```
912
-
913
- **Subtract Minutes**
914
-
915
- Subtract minutes to the current date.
916
-
917
- - `amount` is a number representing the amount of minutes to subtract.
918
-
919
- ```javascript
920
- const newDateTime = dateTime.subtractMinutes(amount);
921
- ```
922
-
923
- **Subtract Month**
924
-
925
- Subtract a month to the current date.
926
-
927
- ```javascript
928
- const newDateTime = dateTime.subtractMonth();
929
- ```
930
-
931
- **Subtract Months**
932
-
933
- Subtract months to the current date.
934
-
935
- - `amount` is a number representing the amount of months to subtract.
936
-
937
- ```javascript
938
- const newDateTime = dateTime.subtractMonths(amount);
939
- ```
940
-
941
- **Subtract Second**
942
-
943
- Subtract a second to the current date.
944
-
945
- ```javascript
946
- const newDateTime = dateTime.subtractSecond();
947
- ```
948
-
949
- **Subtract Seconds**
950
-
951
- Subtract seconds to the current date.
952
-
953
- - `amount` is a number representing the amount of seconds to subtract.
954
-
955
- ```javascript
956
- const newDateTime = dateTime.subtractSeconds(amount);
957
- ```
958
-
959
- **Subtract Week**
960
-
961
- Subtract a week to the current date.
962
-
963
- ```javascript
964
- const newDateTime = dateTime.subtractWeek();
965
- ```
966
-
967
- **Subtract Weeks**
968
-
969
- Subtract weeks to the current date.
970
-
971
- - `amount` is a number representing the amount of weeks to subtract.
972
-
973
- ```javascript
974
- const newDateTime = dateTime.subtractWeeks(amount);
975
- ```
976
-
977
- **Subtract Year**
978
-
979
- Subtract a year to the current date.
980
-
981
- ```javascript
982
- const newDateTime = dateTime.subtractYear();
983
- ```
984
-
985
- **Subtract Years**
986
-
987
- Subtract years to the current date.
988
-
989
- - `amount` is a number representing the amount of years to subtract.
990
-
991
- ```javascript
992
- const newDateTime = dateTime.subtractYears(amount);
993
- ```
994
-
995
-
996
- ## Comparisons
997
-
998
- **Difference**
999
-
1000
- Get the difference between two dates in milliseconds.
1001
-
1002
- - `other` is the *DateTime* object to compare to.
1003
-
1004
- ```javascript
1005
- const diff = dateTime.diff(other);
1006
- ```
1007
-
1008
- **Difference In Days**
1009
-
1010
- Get the difference between two dates in days.
1011
-
1012
- - `other` is the *DateTime* object to compare to.
1013
- - `options` is an object containing options for how to compare the dates.
1014
- - `relative` is a boolean indicating whether to return the relative difference, and will default to *true*.
1015
-
1016
- ```javascript
1017
- const diff = dateTime.diffInDays(other, options);
1018
- ```
1019
-
1020
- If `relative` is *true* (default) the value returned will be the relative difference, ignoring higher precision properties.
1021
-
1022
- **Difference In Hours**
1023
-
1024
- Get the difference between two dates in hours.
1025
-
1026
- - `other` is the *DateTime* object to compare to.
1027
- - `options` is an object containing options for how to compare the dates.
1028
- - `relative` is a boolean indicating whether to return the relative difference, and will default to *true*.
1029
-
1030
- ```javascript
1031
- const diff = dateTime.diffInHours(other, options);
1032
- ```
1033
-
1034
- If `relative` is *true* (default) the value returned will be the relative difference, ignoring higher precision properties.
1035
-
1036
- **Difference In Minutes**
1037
-
1038
- Get the difference between two dates in minutes.
1039
-
1040
- - `other` is the *DateTime* object to compare to.
1041
- - `options` is an object containing options for how to compare the dates.
1042
- - `relative` is a boolean indicating whether to return the relative difference, and will default to *true*.
1043
-
1044
- ```javascript
1045
- const diff = dateTime.diffInMinutes(other, options);
1046
- ```
1047
-
1048
- If `relative` is *true* (default) the value returned will be the relative difference, ignoring higher precision properties.
1049
-
1050
- **Difference In Months**
1051
-
1052
- Get the difference between two dates in months.
1053
-
1054
- - `other` is the *DateTime* object to compare to.
1055
- - `options` is an object containing options for how to compare the dates.
1056
- - `relative` is a boolean indicating whether to return the relative difference, and will default to *true*.
1057
-
1058
- ```javascript
1059
- const diff = dateTime.diffInMonths(other, options);
1060
- ```
1061
-
1062
- If `relative` is *true* (default) the value returned will be the relative difference, ignoring higher precision properties.
1063
-
1064
- **Difference In Seconds**
1065
-
1066
- Get the difference between two dates in seconds.
1067
-
1068
- - `other` is the *DateTime* object to compare to.
1069
- - `options` is an object containing options for how to compare the dates.
1070
- - `relative` is a boolean indicating whether to return the relative difference, and will default to *true*.
1071
-
1072
- ```javascript
1073
- const diff = dateTime.diffInSeconds(other, options);
1074
- ```
1075
-
1076
- If `relative` is *true* (default) the value returned will be the relative difference, ignoring higher precision properties.
1077
-
1078
- **Difference In Weeks**
1079
-
1080
- Get the difference between two dates in weeks.
1081
-
1082
- - `other` is the *DateTime* object to compare to.
1083
- - `options` is an object containing options for how to compare the dates.
1084
- - `relative` is a boolean indicating whether to return the relative difference, and will default to *true*.
1085
-
1086
- ```javascript
1087
- const diff = dateTime.diffInWeeks(other, options);
1088
- ```
1089
-
1090
- If `relative` is *true* (default) the value returned will be the relative difference, ignoring higher precision properties.
1091
-
1092
- **Difference In Years**
1093
-
1094
- Get the difference between two dates in years.
1095
-
1096
- - `other` is the *DateTime* object to compare to.
1097
- - `options` is an object containing options for how to compare the dates.
1098
- - `relative` is a boolean indicating whether to return the relative difference, and will default to *true*.
1099
-
1100
- ```javascript
1101
- const diff = dateTime.diffInYears(other, options);
1102
- ```
1103
-
1104
- If `relative` is *true* (default) the value returned will be the relative difference, ignoring higher precision properties.
1105
-
1106
- **Human Difference**
1107
-
1108
- Get the relative difference between two Dates in a human readable format using the current locale.
1109
-
1110
- - `other` is the *DateTime* object to compare to.
1111
-
1112
- ```javascript
1113
- const humanDiff = dateTime.humanDiff(other);
1114
- ```
1115
-
1116
- 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.
1117
-
1118
- ```javascript
1119
- DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').humanDiff(DateTime.fromFormat('yyyy-MM-dd', '2018-12-31')); // "tomorrow"
1120
- DateTime.fromFormat('yyyy-MM-dd', '2019-02-27').humanDiff(DateTime.fromFormat('yyyy-MM-dd', '2019-01-31')); // "in 27 days"
1121
- DateTime.fromFormat('yyyy-MM-dd', '2019-02-28').humanDiff(DateTime.fromFormat('yyyy-MM-dd', '2019-01-31')); // "next month"
1122
- DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').humanDiff(DateTime.fromFormat('yyyy-MM-dd', '2018-06-01')); // "in 6 months"
1123
- DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').humanDiff(DateTime.fromFormat('yyyy-MM-dd', '2018-01-31')); // "next year"
1124
- DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').humanDiff(DateTime.fromFormat('yyyy-MM-dd', '2017-12-31')); // "in 2 years"
1125
- ```
1126
-
1127
- **Human Difference In Days**
1128
-
1129
- Get the relative difference between two Dates in days in a human readable format using the current locale.
1130
-
1131
- - `other` is the *DateTime* object to compare to.
1132
-
1133
- ```javascript
1134
- const humanDiff = dateTime.humanDiffInDays(other);
1135
- ```
1136
-
1137
- **Human Difference In Hours**
1138
-
1139
- Get the relative difference between two Dates in hours in a human readable format using the current locale.
1140
-
1141
- - `other` is the *DateTime* object to compare to.
1142
-
1143
- ```javascript
1144
- const humanDiff = dateTime.humanDiffInHours(other);
1145
- ```
1146
-
1147
- **Human Difference In Minutes**
1148
-
1149
- Get the relative difference between two Dates in minutes in a human readable format using the current locale.
1150
-
1151
- - `other` is the *DateTime* object to compare to.
1152
-
1153
- ```javascript
1154
- const humanDiff = dateTime.humanDiffInMinutes(other);
1155
- ```
1156
-
1157
- **Human Difference In Months**
1158
-
1159
- Get the relative difference between two Dates in months in a human readable format using the current locale.
1160
-
1161
- - `other` is the *DateTime* object to compare to.
1162
-
1163
- ```javascript
1164
- const humanDiff = dateTime.humanDiffInMonths(other);
1165
- ```
1166
-
1167
- **Human Difference In Seconds**
1168
-
1169
- Get the relative difference between two Dates in seconds in a human readable format using the current locale.
1170
-
1171
- - `other` is the *DateTime* object to compare to.
1172
-
1173
- ```javascript
1174
- const humanDiff = dateTime.humanDiffInSeconds(other);
1175
- ```
1176
-
1177
- **Human Difference In Weeks**
1178
-
1179
- Get the relative difference between two Dates in weeks in a human readable format using the current locale.
1180
-
1181
- - `other` is the *DateTime* object to compare to.
1182
-
1183
- ```javascript
1184
- const humanDiff = dateTime.humanDiffInWeeks(other);
1185
- ```
1186
-
1187
- **Human Difference In Years**
1188
-
1189
- Get the relative difference between two Dates in years in a human readable format using the current locale.
1190
-
1191
- - `other` is the *DateTime* object to compare to.
1192
-
1193
- ```javascript
1194
- const humanDiff = dateTime.humanDiffInYears(other);
1195
- ```
1196
-
1197
- **Is After?**
1198
-
1199
- Return *true* if the *DateTime* is after another date.
1200
-
1201
- - `other` is the *DateTime* object to compare to.
1202
-
1203
- ```javascript
1204
- const isAfter = dateTime.isAfter(other);
1205
- ```
1206
-
1207
- **Is After Day?**
1208
-
1209
- Return *true* if the *DateTime* is after another date (comparing by day).
1210
-
1211
- - `other` is the *DateTime* object to compare to.
1212
-
1213
- ```javascript
1214
- const isAfter = dateTime.isAfterDay(other);
1215
- ```
1216
-
1217
- **Is After Hour?**
1218
-
1219
- Return *true* if the *DateTime* is after another date (comparing by hour).
1220
-
1221
- - `other` is the *DateTime* object to compare to.
1222
-
1223
- ```javascript
1224
- const isAfter = dateTime.isAfterHour(other);
1225
- ```
1226
-
1227
- **Is After Minute?**
1228
-
1229
- Return *true* if the *DateTime* is after another date (comparing by minute).
1230
-
1231
- - `other` is the *DateTime* object to compare to.
1232
-
1233
- ```javascript
1234
- const isAfter = dateTime.isAfterMinute(other);
1235
- ```
1236
-
1237
- **Is After Month?**
1238
-
1239
- Return *true* if the *DateTime* is after another date (comparing by month).
1240
-
1241
- - `other` is the *DateTime* object to compare to.
1242
-
1243
- ```javascript
1244
- const isAfter = dateTime.isAfterMonth(other);
1245
- ```
1246
-
1247
- **Is After Second?**
1248
-
1249
- Return *true* if the *DateTime* is after another date (comparing by second).
1250
-
1251
- - `other` is the *DateTime* object to compare to.
1252
-
1253
- ```javascript
1254
- const isAfter = dateTime.isAfterSecond(other);
1255
- ```
1256
-
1257
- **Is After Week?**
1258
-
1259
- Return *true* if the *DateTime* is after another date (comparing by week).
1260
-
1261
- - `other` is the *DateTime* object to compare to.
1262
-
1263
- ```javascript
1264
- const isAfter = dateTime.isAfterWeek(other);
1265
- ```
1266
-
1267
- **Is After Year?**
1268
-
1269
- Return *true* if the *DateTime* is after another date (comparing by year).
1270
-
1271
- - `other` is the *DateTime* object to compare to.
1272
-
1273
- ```javascript
1274
- const isAfter = dateTime.isAfterYear(other);
1275
- ```
1276
-
1277
- **Is Before?**
1278
-
1279
- Return *true* if the *DateTime* is before another date.
1280
-
1281
- - `other` is the *DateTime* object to compare to.
1282
-
1283
- ```javascript
1284
- const isBefore = dateTime.isBefore(other);
1285
- ```
1286
-
1287
- **Is Before Day?**
1288
-
1289
- Return *true* if the *DateTime* is before another date (comparing by day).
1290
-
1291
- - `other` is the *DateTime* object to compare to.
1292
-
1293
- ```javascript
1294
- const isBefore = dateTime.isBeforeDay(other);
1295
- ```
1296
-
1297
- **Is Before Hour?**
1298
-
1299
- Return *true* if the *DateTime* is before another date (comparing by hour).
1300
-
1301
- - `other` is the *DateTime* object to compare to.
1302
-
1303
- ```javascript
1304
- const isBefore = dateTime.isBeforeHour(other);
1305
- ```
1306
-
1307
- **Is Before Minute?**
1308
-
1309
- Return *true* if the *DateTime* is before another date (comparing by minute).
1310
-
1311
- - `other` is the *DateTime* object to compare to.
1312
-
1313
- ```javascript
1314
- const isBefore = dateTime.isBeforeMinute(other);
1315
- ```
1316
-
1317
- **Is Before Month?**
1318
-
1319
- Return *true* if the *DateTime* is before another date (comparing by month).
1320
-
1321
- - `other` is the *DateTime* object to compare to.
1322
-
1323
- ```javascript
1324
- const isBefore = dateTime.isBeforeMonth(other);
1325
- ```
1326
-
1327
- **Is Before Second?**
1328
-
1329
- Return *true* if the *DateTime* is before another date (comparing by second).
1330
-
1331
- - `other` is the *DateTime* object to compare to.
1332
-
1333
- ```javascript
1334
- const isBefore = dateTime.isBeforeSecond(other);
1335
- ```
1336
-
1337
- **Is Before Week?**
1338
-
1339
- Return *true* if the *DateTime* is before another date (comparing by week).
1340
-
1341
- - `other` is the *DateTime* object to compare to.
1342
-
1343
- ```javascript
1344
- const isBefore = dateTime.isBeforeWeek(other);
1345
- ```
1346
-
1347
- **Is Before Year?**
1348
-
1349
- Return *true* if the *DateTime* is before another date (comparing by year).
1350
-
1351
- - `other` is the *DateTime* object to compare to.
1352
-
1353
- ```javascript
1354
- const isBefore = dateTime.isBeforeYear(other);
1355
- ```
1356
-
1357
- **Is Between?**
1358
-
1359
- Return *true* if the *DateTime* is between two other dates.
1360
-
1361
- - `start` is the starting *DateTime* object to compare to.
1362
- - `end` is the ending *DateTime* object to compare to.
1363
-
1364
- ```javascript
1365
- const isBetween = dateTime.isBetween(start, end);
1366
- ```
1367
-
1368
- **Is Between Day?**
1369
-
1370
- Return *true* if the *DateTime* is between two other dates (comparing by day).
1371
-
1372
- - `start` is the starting *DateTime* object to compare to.
1373
- - `end` is the ending *DateTime* object to compare to.
1374
-
1375
- ```javascript
1376
- const isBetween = dateTime.isBetweenDay(start, end);
1377
- ```
1378
-
1379
- **Is Between Hour?**
1380
-
1381
- Return *true* if the *DateTime* is between two other dates (comparing by hour).
1382
-
1383
- - `start` is the starting *DateTime* object to compare to.
1384
- - `end` is the ending *DateTime* object to compare to.
1385
-
1386
- ```javascript
1387
- const isBetween = dateTime.isBetweenHour(start, end);
1388
- ```
1389
-
1390
- **Is Between Minute?**
1391
-
1392
- Return *true* if the *DateTime* is between two other dates (comparing by minute).
1393
-
1394
- - `start` is the starting *DateTime* object to compare to.
1395
- - `end` is the ending *DateTime* object to compare to.
1396
-
1397
- ```javascript
1398
- const isBetween = dateTime.isBetweenMinute(start, end);
1399
- ```
1400
-
1401
- **Is Between Month?**
1402
-
1403
- Return *true* if the *DateTime* is between two other dates (comparing by month).
1404
-
1405
- - `start` is the starting *DateTime* object to compare to.
1406
- - `end` is the ending *DateTime* object to compare to.
1407
-
1408
- ```javascript
1409
- const isBetween = dateTime.isBetweenMonth(start, end);
1410
- ```
1411
-
1412
- **Is Between Second?**
1413
-
1414
- Return *true* if the *DateTime* is between two other dates (comparing by second).
1415
-
1416
- - `start` is the starting *DateTime* object to compare to.
1417
- - `end` is the ending *DateTime* object to compare to.
1418
-
1419
- ```javascript
1420
- const isBetween = dateTime.isBetweenSecond(start, end);
1421
- ```
1422
-
1423
- **Is Between Week?**
1424
-
1425
- Return *true* if the *DateTime* is between two other dates (comparing by week).
1426
-
1427
- - `start` is the starting *DateTime* object to compare to.
1428
- - `end` is the ending *DateTime* object to compare to.
1429
-
1430
- ```javascript
1431
- const isBetween = dateTime.isBetweenWeek(start, end);
1432
- ```
1433
-
1434
- **Is Between Year?**
1435
-
1436
- Return *true* if the *DateTime* is between two other dates (comparing by year).
1437
-
1438
- - `start` is the starting *DateTime* object to compare to.
1439
- - `end` is the ending *DateTime* object to compare to.
1440
-
1441
- ```javascript
1442
- const isBetween = dateTime.isBetweenYear(start, end);
1443
- ```
1444
-
1445
- **Is Same?**
1446
-
1447
- Return *true* if the *DateTime* is the same as another date.
1448
-
1449
- - `other` is the *DateTime* object to compare to.
1450
-
1451
- ```javascript
1452
- const isSame = dateTime.isSame(other);
1453
- ```
1454
-
1455
- **Is Same Day?**
1456
-
1457
- Return *true* if the *DateTime* is the same as another date (comparing by day).
1458
-
1459
- - `other` is the *DateTime* object to compare to.
1460
-
1461
- ```javascript
1462
- const isSame = dateTime.isSameDay(other);
1463
- ```
1464
-
1465
- **Is Same Hour?**
1466
-
1467
- Return *true* if the *DateTime* is the same as another date (comparing by hour).
1468
-
1469
- - `other` is the *DateTime* object to compare to.
1470
-
1471
- ```javascript
1472
- const isSame = dateTime.isSameHour(other);
1473
- ```
1474
-
1475
- **Is Same Minute?**
1476
-
1477
- Return *true* if the *DateTime* is the same as another date (comparing by minute).
1478
-
1479
- - `other` is the *DateTime* object to compare to.
1480
-
1481
- ```javascript
1482
- const isSame = dateTime.isSameMinute(other);
1483
- ```
1484
-
1485
- **Is Same Month?**
1486
-
1487
- Return *true* if the *DateTime* is the same as another date (comparing by month).
1488
-
1489
- - `other` is the *DateTime* object to compare to.
1490
-
1491
- ```javascript
1492
- const isSame = dateTime.isSameMonth(other);
1493
- ```
1494
-
1495
- **Is Same Second?**
1496
-
1497
- Return *true* if the *DateTime* is the same as another date (comparing by second).
1498
-
1499
- - `other` is the *DateTime* object to compare to.
1500
-
1501
- ```javascript
1502
- const isSame = dateTime.isSameSecond(other);
1503
- ```
1504
-
1505
- **Is Same Week?**
1506
-
1507
- Return *true* if the *DateTime* is the same as another date (comparing by week).
1508
-
1509
- - `other` is the *DateTime* object to compare to.
1510
-
1511
- ```javascript
1512
- const isSame = dateTime.isSameWeek(other);
1513
- ```
1514
-
1515
- **Is Same Year?**
1516
-
1517
- Return *true* if the *DateTime* is the same as another date (comparing by year).
1518
-
1519
- - `other` is the *DateTime* object to compare to.
1520
-
1521
- ```javascript
1522
- const isSame = dateTime.isSameYear(other);
1523
- ```
1524
-
1525
- **Is Same Or After?**
1526
-
1527
- Return *true* if the *DateTime* is the same as or after another date.
1528
-
1529
- - `other` is the *DateTime* object to compare to.
1530
-
1531
- ```javascript
1532
- const isSameOrAfter = dateTime.isSameOrAfter(other);
1533
- ```
1534
-
1535
- **Is Same Or After Day?**
1536
-
1537
- Return *true* if the *DateTime* is the same as or after another date (comparing by day).
1538
-
1539
- - `other` is the *DateTime* object to compare to.
1540
-
1541
- ```javascript
1542
- const isSameOrAfter = dateTime.isSameOrAfterDay(other);
1543
- ```
1544
-
1545
- **Is Same Or After Hour?**
1546
-
1547
- Return *true* if the *DateTime* is the same as or after another date (comparing by hour).
1548
-
1549
- - `other` is the *DateTime* object to compare to.
1550
-
1551
- ```javascript
1552
- const isSameOrAfter = dateTime.isSameOrAfterHour(other);
1553
- ```
1554
-
1555
- **Is Same Or After Minute?**
1556
-
1557
- Return *true* if the *DateTime* is the same as or after another date (comparing by minute).
1558
-
1559
- - `other` is the *DateTime* object to compare to.
1560
-
1561
- ```javascript
1562
- const isSameOrAfter = dateTime.isSameOrAfterMinute(other);
1563
- ```
1564
-
1565
- **Is Same Or After Month?**
1566
-
1567
- Return *true* if the *DateTime* is the same as or after another date (comparing by month).
1568
-
1569
- - `other` is the *DateTime* object to compare to.
1570
-
1571
- ```javascript
1572
- const isSameOrAfter = dateTime.isSameOrAfterMonth(other);
1573
- ```
1574
-
1575
- **Is Same Or After Second?**
1576
-
1577
- Return *true* if the *DateTime* is the same as or after another date (comparing by second).
1578
-
1579
- - `other` is the *DateTime* object to compare to.
1580
-
1581
- ```javascript
1582
- const isSameOrAfter = dateTime.isSameOrAfterSecond(other);
1583
- ```
1584
-
1585
- **Is Same Or After Week?**
1586
-
1587
- Return *true* if the *DateTime* is the same as or after another date (comparing by week).
1588
-
1589
- - `other` is the *DateTime* object to compare to.
1590
-
1591
- ```javascript
1592
- const isSameOrAfter = dateTime.isSameOrAfterWeek(other);
1593
- ```
1594
-
1595
- **Is Same Or After Year?**
1596
-
1597
- Return *true* if the *DateTime* is the same as or after another date (comparing by year).
1598
-
1599
- - `other` is the *DateTime* object to compare to.
1600
-
1601
- ```javascript
1602
- const isSameOrAfter = dateTime.isSameOrAfterYear(other);
1603
- ```
1604
-
1605
- **Is Same Or Before?**
1606
-
1607
- Return *true* if the *DateTime* is the same as or before another date.
1608
-
1609
- - `other` is the *DateTime* object to compare to.
1610
-
1611
- ```javascript
1612
- const isSameOrBefore = dateTime.isSameOrBefore(other);
1613
- ```
1614
-
1615
- **Is Same Or Before Day?**
1616
-
1617
- Return *true* if the *DateTime* is the same as or before another date (comparing by day).
1618
-
1619
- - `other` is the *DateTime* object to compare to.
1620
-
1621
- ```javascript
1622
- const isSameOrBefore = dateTime.isSameOrBeforeDay(other);
1623
- ```
1624
-
1625
- **Is Same Or Before Hour?**
1626
-
1627
- Return *true* if the *DateTime* is the same as or before another date (comparing by hour).
1628
-
1629
- - `other` is the *DateTime* object to compare to.
1630
-
1631
- ```javascript
1632
- const isSameOrBefore = dateTime.isSameOrBeforeHour(other);
1633
- ```
1634
-
1635
- **Is Same Or Before Minute?**
1636
-
1637
- Return *true* if the *DateTime* is the same as or before another date (comparing by minute).
1638
-
1639
- - `other` is the *DateTime* object to compare to.
1640
-
1641
- ```javascript
1642
- const isSameOrBefore = dateTime.isSameOrBeforeMinute(other);
1643
- ```
1644
-
1645
- **Is Same Or Before Month?**
1646
-
1647
- Return *true* if the *DateTime* is the same as or before another date (comparing by month).
1648
-
1649
- - `other` is the *DateTime* object to compare to.
1650
-
1651
- ```javascript
1652
- const isSameOrBefore = dateTime.isSameOrBeforeMonth(other);
1653
- ```
1654
-
1655
- **Is Same Or Before Second?**
1656
-
1657
- Return *true* if the *DateTime* is the same as or before another date (comparing by second).
1658
-
1659
- - `other` is the *DateTime* object to compare to.
1660
-
1661
- ```javascript
1662
- const isSameOrBefore = dateTime.isSameOrBeforeSecond(other);
1663
- ```
1664
-
1665
- **Is Same Or Before Week?**
1666
-
1667
- Return *true* if the *DateTime* is the same as or before another date (comparing by week).
1668
-
1669
- - `other` is the *DateTime* object to compare to.
1670
-
1671
- ```javascript
1672
- const isSameOrBefore = dateTime.isSameOrBeforeWeek(other);
1673
- ```
1674
-
1675
- **Is Same Or Before Year?**
1676
-
1677
- Return *true* if the *DateTime* is the same as or before another date (comparing by year).
1678
-
1679
- - `other` is the *DateTime* object to compare to.
1680
-
1681
- ```javascript
1682
- const isSameOrBefore = dateTime.isSameOrBeforeYear(other);
1683
- ```
1684
-
1685
-
1686
- ## Utility Methods
1687
-
1688
- **Day Name**
1689
-
1690
- Get the name of the day of the week in current time zone and locale.
1691
-
1692
- - `type` can be either "*long*", "*short*" or "*narrow*", and will default to "*long*" if it is not set.
1693
-
1694
- ```javascript
1695
- const dayName = dateTime.dayName(type);
1696
- ```
1697
-
1698
- **Day Period**
1699
-
1700
- Get the day period in current time zone and locale.
1701
-
1702
- - `type` can be either "*long*" or "*short*", and will default to "*long*" if it is not set.
1703
-
1704
- ```javascript
1705
- const dayPeriod = dateTime.dayPeriod(type);
1706
- ```
1707
-
1708
- **Days In Month**
1709
-
1710
- Get the number of days in the current month.
1711
-
1712
- ```javascript
1713
- const daysInMonth = dateTime.daysInMonth();
1714
- ```
1715
-
1716
- **Days In Year**
1717
-
1718
- Get the number of days in the current year.
1719
-
1720
- ```javascript
1721
- const daysInYear = dateTime.daysInYear();
1722
- ```
1723
-
1724
- **Era**
1725
-
1726
- Get the era in current time zone and locale.
1727
-
1728
- - `type` can be either "*long*", "*short*" or "*narrow*", and will default to "*long*" if it is not set.
1729
-
1730
- ```javascript
1731
- const era = dateTime.era(type);
1732
- ```
1733
-
1734
- **Is DST?**
1735
-
1736
- Return *true* if the *DateTime* is in daylight savings.
1737
-
1738
- ```javascript
1739
- const isDST = dateTime.isDST();
1740
- ```
1741
-
1742
- **Is Leap Year?**
1743
-
1744
- Return *true* if the year is a leap year.
1745
-
1746
- ```javascript
1747
- const isLeapYear = dateTime.isLeapYear();
1748
- ```
1749
-
1750
- **Month Name**
1751
-
1752
- Get the name of the month in current time zone and locale.
1753
-
1754
- - `type` can be either "*long*", "*short*" or "*narrow*", and will default to "*long*" if it is not set.
1755
-
1756
- ```javascript
1757
- const monthName = dateTime.monthName(type);
1758
- ```
1759
-
1760
- **Time Zone Name**
1761
-
1762
- Get the name of the current time zone and locale.
1763
-
1764
- - `type` can be either "*long*" or "*short*", and will default to "*long*" if it is not set.
1765
-
1766
- ```javascript
1767
- const timeZoneName = dateTime.timeZoneName(type);
1768
- ```
1769
-
1770
- **Weeks In Year**
1771
-
1772
- Get the number of weeks in the current year.
1773
-
1774
- ```javascript
1775
- const weeksInYear = dateTime.weeksInYear();
1776
- ```
1777
-
1778
-
1779
- ## Static Methods
1780
-
1781
- **Day Of Year**
1782
-
1783
- Get the day of the year for a year, month and date.
1784
-
1785
- - `year` is a number representing the year.
1786
- - `month` is a number representing the month (between *1* and *12*).
1787
- - `date` is a number representing the date.
1788
-
1789
- ```javascript
1790
- const dayOfYear = DateTime.dayOfYear(year, month, date);
1791
- ```
1792
-
1793
- **Days In Month**
1794
-
1795
- Get the number of days in a month, from a year and month.
1796
-
1797
- - `year` is a number representing the year.
1798
- - `month` is a number representing the month (between *1* and *12*).
1799
-
1800
- ```javascript
1801
- const daysInMonth = DateTime.daysInMonth(year, month);
1802
- ```
1803
-
1804
- **Days In Year**
1805
-
1806
- Get the number of days in a year.
1807
-
1808
- - `year` is a number representing the year.
1809
-
1810
- ```javascript
1811
- const daysInYear = DateTime.daysInYear(year);
1812
- ```
1813
-
1814
- **Get Default Locale**
1815
-
1816
- Get the default locale.
1817
-
1818
- ```javascript
1819
- const locale = DateTime.getDefaultLocale();
1820
- ```
1821
-
1822
- **Get Default Time Zone**
1823
-
1824
- Get the default time zone.
1825
-
1826
- ```javascript
1827
- const timeZone = DateTime.getDefaultTimeZone();
1828
- ```
1829
-
1830
- **Is Leap Year?**
1831
-
1832
- Return *true* if the year is a leap year.
1833
-
1834
- - `year` is a number representing the year.
1835
-
1836
- ```javascript
1837
- const isLeapYear = DateTime.isLeapYear(year);
1838
- ```
1839
-
1840
- **Set Date Clamping**
1841
-
1842
- Set whether dates will be clamped when changing months.
1843
-
1844
- - `clampDates` is a boolean indicating whether to clamp dates.
1845
-
1846
- ```javascript
1847
- DateTime.setDateClamping(clampDates);
1848
- ```
1849
-
1850
- **Set Default Locale**
1851
-
1852
- Set the default locale.
1853
-
1854
- - `locale` is the name of the locale.
1855
-
1856
- ```javascript
1857
- DateTime.setDefaultLocale(locale);
1858
- ```
1859
-
1860
- **Set Default Time Zone**
1861
-
1862
- Set the default time zone.
1863
-
1864
- - `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.
1865
-
1866
- ```javascript
1867
- DateTime.setDefaultTimeZone(timeZone);
1868
- ```
1
+ # FrostDateTime
2
+
3
+ [![CI](https://github.com/elusivecodes/FrostDateTime/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/elusivecodes/FrostDateTime/actions/workflows/ci.yml)
4
+ [![npm version](https://img.shields.io/npm/v/%40fr0st%2Fdatetime?style=flat-square)](https://www.npmjs.com/package/@fr0st/datetime)
5
+ [![npm downloads](https://img.shields.io/npm/dm/%40fr0st%2Fdatetime?style=flat-square)](https://www.npmjs.com/package/@fr0st/datetime)
6
+ [![minzipped size](https://img.shields.io/bundlejs/size/%40fr0st/datetime?format=minzip&style=flat-square)](https://bundlejs.com/?q=@fr0st/datetime)
7
+ [![license](https://img.shields.io/github/license/elusivecodes/FrostDateTime?style=flat-square)](./LICENSE)
8
+
9
+ Immutable date and time handling for JavaScript with locale-aware formatting, parsing, calendar math, and IANA or fixed-offset time zones. FrostDateTime works in Node and bundlers, and also ships a browser-friendly UMD bundle that exposes `globalThis.DateTime`.
10
+
11
+ ## Highlights
12
+
13
+ - Default ESM `DateTime` export for Node and bundlers
14
+ - Browser UMD bundle in `dist/` exposed as `globalThis.DateTime`
15
+ - No runtime dependencies
16
+ - Immutable operations across getters, setters, and date math
17
+ - Locale-aware formatting, parsing, relative time, and week rules through `Intl`
18
+ - IANA time zones such as `Australia/Brisbane` and fixed offsets such as `+10:00`
19
+ - JSDoc-powered IntelliSense
20
+
21
+ ## Installation
22
+
23
+ ### Node / bundlers
24
+
25
+ ```bash
26
+ npm i @fr0st/datetime
27
+ ```
28
+
29
+ FrostDateTime is ESM-only. Import the default `DateTime` export in Node and bundlers.
30
+
31
+ ```js
32
+ import DateTime from '@fr0st/datetime';
33
+ ```
34
+
35
+ ### Browser (UMD)
36
+
37
+ Load the bundle from your own copy or a CDN:
38
+
39
+ ```html
40
+ <script src="/path/to/dist/frost-datetime.min.js"></script>
41
+ <!-- or -->
42
+ <script src="https://cdn.jsdelivr.net/npm/@fr0st/datetime@latest/dist/frost-datetime.min.js"></script>
43
+ <script>
44
+ const date = DateTime.now({ timeZone: 'UTC' });
45
+ console.log(date.toISOString());
46
+ </script>
47
+ ```
48
+
49
+ ## Quick Start
50
+
51
+ ```js
52
+ import DateTime from '@fr0st/datetime';
53
+
54
+ const meeting = DateTime.fromFormat(
55
+ 'yyyy-MM-dd HH:mm:ss',
56
+ '2026-03-23 09:30:00',
57
+ { timeZone: 'Australia/Brisbane' },
58
+ );
59
+
60
+ const nextWeek = meeting.addWeeks(1);
61
+
62
+ nextWeek.toString();
63
+ // Mon Mar 30 2026 09:30:00 +1000 (Australia/Brisbane)
64
+
65
+ nextWeek.toISOString();
66
+ // 2026-03-29T23:30:00.000+00:00
67
+
68
+ nextWeek.monthName();
69
+ // March
70
+ ```
71
+
72
+ TypeScript note: FrostDateTime is written in JavaScript and uses JSDoc types, which most editors surface as IntelliSense.
73
+
74
+ ## Date Model
75
+
76
+ FrostDateTime revolves around an immutable `DateTime` class and a small set of predictable parsing and formatting rules.
77
+
78
+ - Every setter and manipulation method returns a new instance
79
+ - Constructor numbers are milliseconds since the UNIX epoch
80
+ - `fromTimestamp()` and `withTimestamp()` use seconds since the UNIX epoch
81
+ - Strings without a zone designator are interpreted in the requested or default time zone
82
+ - Strings with an explicit zone or offset define an instant; `options.timeZone` only changes its representation
83
+ - Calendar fields and localized date names use the Gregorian calendar
84
+ - Week calculations such as `getWeek()`, `getWeekYear()`, `withWeekYear()`, and `weeksInYear()` use the active locale's week rules, including Unicode `rg` region overrides
85
+
86
+ ```js
87
+ const a = DateTime.fromArray([2026, 3, 23], { timeZone: 'UTC' });
88
+ const b = a.addDays(1);
89
+
90
+ a.toISOString(); // 2026-03-23T00:00:00.000+00:00
91
+ b.toISOString(); // 2026-03-24T00:00:00.000+00:00
92
+
93
+ new DateTime('January 1, 2019 00:00:00', { timeZone: 'Australia/Brisbane' })
94
+ .toISOString();
95
+ // 2018-12-31T14:00:00.000+00:00
96
+ ```
97
+
98
+ ## API
99
+
100
+ FrostDateTime exports a default `DateTime` class from `@fr0st/datetime`.
101
+
102
+ ### Creating dates
103
+
104
+ All creation methods accept an optional options object:
105
+
106
+ ```ts
107
+ {
108
+ timeZone?: string;
109
+ locale?: string;
110
+ }
111
+ ```
112
+
113
+ - `new DateTime(date?, options?)`: create from now, milliseconds, or a string accepted by `Date.parse()`
114
+ - `DateTime.fromArray(dateArray, options?)`: create from `[year, month, date, hours, minutes, seconds, milliseconds]`
115
+ - `DateTime.fromDate(date, options?)`: wrap a native `Date`
116
+ - `DateTime.fromFormat(formatString, dateString, options?)`: parse a string with a known token pattern
117
+ - `DateTime.fromISOString(dateString, options?)`: parse `yyyy-MM-dd'T'HH:mm:ss.SSSxxx`
118
+ - `DateTime.fromTimestamp(timestamp, options?)`: create from seconds since the UNIX epoch
119
+ - `DateTime.now(options?)`: create the current time
120
+
121
+ For constructor strings, an explicit `Z` or numeric offset defines the instant. Passing a different `options.timeZone` changes only how that instant is represented. Supported unzoned ISO forms are interpreted as wall time in the requested or default time zone:
122
+
123
+ - `yyyy`
124
+ - `yyyy-MM`
125
+ - `yyyy-MM-dd`
126
+ - `yyyy-MM-dd HH:mm[:ss[.fraction]]`
127
+ - `yyyy-MM-ddTHH:mm[:ss[.fraction]]`
128
+
129
+ Omitted month and day fields default to `1`, and omitted time fields default to local midnight. Other accepted string shapes are parsed through `Date.parse()`; unzoned results are likewise interpreted as local wall time in the requested or default time zone.
130
+
131
+ ```js
132
+ const now = new DateTime();
133
+ const fromMillis = new DateTime(1711152000000);
134
+ const fromArray = DateTime.fromArray([2026, 3, 23, 9, 30], {
135
+ timeZone: 'Europe/London',
136
+ });
137
+ const fromFormat = DateTime.fromFormat(
138
+ 'dd/MM/yyyy HH:mm:ss',
139
+ '23/03/2026 09:30:00',
140
+ { timeZone: 'Australia/Brisbane' },
141
+ );
142
+ ```
143
+
144
+ `fromFormat()` and `fromISOString()` can return an invalid `DateTime` when the text parses structurally but the calendar values are impossible.
145
+
146
+ ```js
147
+ const invalid = DateTime.fromFormat('yyyy-MM-dd', '2019-02-31');
148
+ invalid.isValid; // false
149
+ ```
150
+
151
+ A time-only `fromFormat()` pattern starts from January 1, 1970 in the requested local time zone. Directly adjacent numeric tokens consume their pattern widths exactly, so compact fixed-width patterns can be parsed; standalone numeric tokens are not capped at the pattern width:
152
+
153
+ ```js
154
+ DateTime.fromFormat('yyyyMMddHHmmss', '20190102123456');
155
+ ```
156
+
157
+ `fromFormat()` rejects output-only or intentionally unsupported token widths. The compatibility matrix in [Formats.md](./Formats.md#php-intldateformatter-token-width-compatibility) records the supported PHP behavior and known differences.
158
+
159
+ Format tokens are documented in [Formats.md](./Formats.md).
160
+
161
+ ### Formatting and output
162
+
163
+ - `format(formatString)`: format with FrostDateTime's token set
164
+ - `toString()`: `eee MMM dd yyyy HH:mm:ss xx (VV)`
165
+ - `toDateString()`: `eee MMM dd yyyy`
166
+ - `toTimeString()`: `HH:mm:ss xx (VV)`
167
+ - `toISOString()`: `yyyy-MM-dd'T'HH:mm:ss.SSSxxx` in English and UTC
168
+ - `toJSON()`: same UTC ISO string for valid dates, `null` for invalid dates
169
+ - `toUTCString()`: `toString()` shape in English and UTC
170
+
171
+ ```js
172
+ const date = DateTime.fromArray([2026, 3, 23, 9, 30, 15], {
173
+ locale: 'en',
174
+ timeZone: 'Australia/Brisbane',
175
+ });
176
+
177
+ date.format('eee MMM dd yyyy HH:mm:ss xxx (VV)');
178
+ // Mon Mar 23 2026 09:30:15 +10:00 (Australia/Brisbane)
179
+ ```
180
+
181
+ Supported format tokens are listed in [Formats.md](./Formats.md).
182
+
183
+ ### Locale and time-zone helpers
184
+
185
+ Relevant instance methods:
186
+
187
+ - `getLocale()`
188
+ - `withLocale(locale)`
189
+ - `getTimeZone()`
190
+ - `getTimeZoneOffset()`
191
+ - `withTimeZone(timeZone)`
192
+ - `withTimeZoneOffset(offsetMinutes)`
193
+ - `dayName(type?)`
194
+ - `dayPeriod(type?)`
195
+ - `monthName(type?)`
196
+ - `era(type?)`
197
+ - `timeZoneName(type?)`
198
+
199
+ Accepted time-zone formats:
200
+
201
+ - IANA names such as `UTC`, `Europe/London`, and `America/New_York`
202
+ - Numeric offsets in `±HH`, `±HHMM`, `±HH:MM`, `±HHMMSS`, or `±HH:MM:SS` form
203
+ - The same numeric forms prefixed with `GMT`, such as `GMT+10:00`
204
+
205
+ The absolute fixed offset must be less than 24 hours and have whole-second precision. `getTimeZoneOffset()` and `withTimeZoneOffset()` use the native `Date#getTimezoneOffset()` sign convention: a `UTC-10:00` zone reports `600`, while `UTC+10:00` reports `-600`. Fractional minutes can represent whole seconds, such as `31 / 60` for 31 seconds.
206
+
207
+ ```js
208
+ const brisbane = DateTime.fromArray([2026, 3, 23, 9, 30], {
209
+ timeZone: 'Australia/Brisbane',
210
+ });
211
+
212
+ brisbane.withTimeZone('UTC').toString();
213
+ // Sun Mar 22 2026 23:30:00 +0000 (UTC)
214
+
215
+ DateTime.fromArray([2026, 3, 23], { locale: 'ar-eg' }).toDateString();
216
+ ```
217
+
218
+ ### Getters and copy methods
219
+
220
+ #### Calendar fields
221
+
222
+ | Value | Getter | With |
223
+ | --- | --- | --- |
224
+ | day of month | `getDate()` | `withDate(date)` |
225
+ | day of week (`0-6`, Sunday-based) | `getDay()` | `withDay(day)` |
226
+ | day of year | `getDayOfYear()` | `withDayOfYear(dayOfYear)` |
227
+ | month (`1-12`) | `getMonth()` | `withMonth(month, date?)` |
228
+ | quarter (`1-4`) | `getQuarter()` | `withQuarter(quarter)` |
229
+ | year | `getYear()` | `withYear(year, month?, date?)` |
230
+
231
+ #### Week fields
232
+
233
+ | Value | Getter | With |
234
+ | --- | --- | --- |
235
+ | locale-aware week of year | `getWeek()` | `withWeek(week, day?)` |
236
+ | locale-aware day of week (`1-7`) | `getWeekDay()` | `withWeekDay(day)` |
237
+ | week day in month | `getWeekDayInMonth()` | `withWeekDayInMonth(week)` |
238
+ | week of month | `getWeekOfMonth()` | `withWeekOfMonth(week)` |
239
+ | locale-aware week year | `getWeekYear()` | `withWeekYear(year, week?, day?)` |
240
+
241
+ #### Time fields
242
+
243
+ | Value | Getter | With |
244
+ | --- | --- | --- |
245
+ | hour | `getHours()` | `withHours(hours, minutes?, seconds?, milliseconds?)` |
246
+ | minute | `getMinutes()` | `withMinutes(minutes, seconds?, milliseconds?)` |
247
+ | second | `getSeconds()` | `withSeconds(seconds, milliseconds?)` |
248
+ | millisecond | `getMilliseconds()` | `withMilliseconds(milliseconds)` |
249
+ | seconds since UNIX epoch | `getTimestamp()` | `withTimestamp(timestamp)` |
250
+ | milliseconds since UNIX epoch | `getTime()` | `withTime(time)` |
251
+
252
+ ### Manipulation
253
+
254
+ #### Add and subtract
255
+
256
+ | Add | Subtract |
257
+ | --- | --- |
258
+ | `addDay()` / `addDays(amount)` | `subDay()` / `subDays(amount)` |
259
+ | `addWeek()` / `addWeeks(amount)` | `subWeek()` / `subWeeks(amount)` |
260
+ | `addMonth()` / `addMonths(amount)` | `subMonth()` / `subMonths(amount)` |
261
+ | `addYear()` / `addYears(amount)` | `subYear()` / `subYears(amount)` |
262
+ | `addHour()` / `addHours(amount)` | `subHour()` / `subHours(amount)` |
263
+ | `addMinute()` / `addMinutes(amount)` | `subMinute()` / `subMinutes(amount)` |
264
+ | `addSecond()` / `addSeconds(amount)` | `subSecond()` / `subSeconds(amount)` |
265
+
266
+ #### Boundaries
267
+
268
+ | Start | End |
269
+ | --- | --- |
270
+ | `startOfDay()` | `endOfDay()` |
271
+ | `startOfWeek()` | `endOfWeek()` |
272
+ | `startOfMonth()` | `endOfMonth()` |
273
+ | `startOfQuarter()` | `endOfQuarter()` |
274
+ | `startOfYear()` | `endOfYear()` |
275
+ | `startOfHour()` | `endOfHour()` |
276
+ | `startOfMinute()` | `endOfMinute()` |
277
+ | `startOfSecond()` | `endOfSecond()` |
278
+
279
+ ### Differences and comparisons
280
+
281
+ #### Numeric differences
282
+
283
+ - `diff(other)`: milliseconds
284
+ - `diffInDays(other, options?)`
285
+ - `diffInWeeks(other, options?)`
286
+ - `diffInMonths(other, options?)`
287
+ - `diffInYears(other, options?)`
288
+ - `diffInHours(other, options?)`
289
+ - `diffInMinutes(other, options?)`
290
+ - `diffInSeconds(other, options?)`
291
+
292
+ `options.relative` defaults to `true` for unit-based differences and compares calendar boundaries. For days and weeks, this uses local calendar dates and locale-aware week starts rather than elapsed 24-hour periods. Set `relative: false` to count completed elapsed units instead.
293
+
294
+ ```js
295
+ const a = DateTime.fromArray([2026, 3, 23]);
296
+ const b = DateTime.fromArray([2026, 3, 30]);
297
+
298
+ a.diffInDays(b); // -7
299
+ ```
300
+
301
+ #### Human-readable differences
302
+
303
+ - `humanDiff(other)`
304
+ - `humanDiffInDays(other)`
305
+ - `humanDiffInWeeks(other)`
306
+ - `humanDiffInMonths(other)`
307
+ - `humanDiffInYears(other)`
308
+ - `humanDiffInHours(other)`
309
+ - `humanDiffInMinutes(other)`
310
+ - `humanDiffInSeconds(other)`
311
+
312
+ ```js
313
+ const earlier = DateTime.fromArray([2026, 3, 23], {
314
+ locale: 'en',
315
+ timeZone: 'UTC',
316
+ });
317
+
318
+ earlier.addWeeks(1).humanDiff(earlier);
319
+ // "next week"
320
+ ```
321
+
322
+ #### Boolean comparisons
323
+
324
+ Base comparisons:
325
+
326
+ - `isAfter(other)`
327
+ - `isBefore(other)`
328
+ - `isBetween(start, end)`
329
+ - `isSame(other)`
330
+ - `isSameOrAfter(other)`
331
+ - `isSameOrBefore(other)`
332
+
333
+ Scoped comparisons exist for these units:
334
+
335
+ - `Day`
336
+ - `Week`
337
+ - `Month`
338
+ - `Year`
339
+ - `Hour`
340
+ - `Minute`
341
+ - `Second`
342
+
343
+ Examples:
344
+
345
+ - `isAfterDay(other)`
346
+ - `isBetweenMonth(start, end)`
347
+ - `isSameWeek(other)`
348
+ - `isSameOrBeforeYear(other)`
349
+
350
+ ### Utility methods
351
+
352
+ #### Instance helpers
353
+
354
+ - `daysInMonth()`
355
+ - `daysInYear()`
356
+ - `weeksInYear()`
357
+ - `isLeapYear()`
358
+ - `isDst()`
359
+
360
+ #### Static helpers
361
+
362
+ - `DateTime.dayOfYear(year, month, date)`
363
+ - `DateTime.daysInMonth(year, month)`
364
+ - `DateTime.daysInYear(year)`
365
+ - `DateTime.isLeapYear(year)`
366
+
367
+ ### Global configuration
368
+
369
+ These affect new instances when you do not pass explicit options:
370
+
371
+ - `DateTime.getDefaultLocale()`
372
+ - `DateTime.setDefaultLocale(locale)`
373
+ - `DateTime.getDefaultTimeZone()`
374
+ - `DateTime.setDefaultTimeZone(timeZone)`
375
+ - `DateTime.setDateClamping(enabled)`
376
+ - `DateTime.clearDataCache()`
377
+
378
+ ```js
379
+ DateTime.setDateClamping(true);
380
+ DateTime.clearDataCache();
381
+ ```
382
+
383
+ ## Behavior Notes
384
+
385
+ - Constructor-based parsing throws on invalid strings or unsupported time zones.
386
+ - `fromFormat()` rejects trailing characters and marks impossible parsed dates as `isValid === false`.
387
+ - `fromISOString()` parses the RFC 3339 / ISO-style shape used by `toISOString()`.
388
+ - `toISOString()` always returns a UTC string regardless of the instance time zone.
389
+ - `toJSON()` returns the same value as `toISOString()` for valid dates and `null` for invalid dates.
390
+ - `withTimeZone()` keeps the same instant and changes representation.
391
+ - `withTimeZoneOffset()` returns a fixed-offset view of the same instant.
392
+ - A nonexistent local wall time moves forward to the next valid time, while a repeated wall time uses the later occurrence.
393
+ - Calendar addition and subtraction across a fully deleted day follow the operation direction.
394
+ - Date clamping controls whether month and year changes clamp invalid dates.
395
+ - `DateTime.clearDataCache()` clears cached formatter and locale data, which is mainly useful in tests and long-lived processes.
396
+
397
+ ## Development
398
+
399
+ ```bash
400
+ npm test
401
+ npm run js-lint
402
+ npm run build
403
+ ```
404
+
405
+ ## License
406
+
407
+ FrostDateTime is released under the [MIT License](./LICENSE).