date-and-time 4.0.1 → 4.0.3

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,3 +1,5 @@
1
+ # date-and-time
2
+
1
3
  <div align="center">
2
4
  <img src="https://raw.githubusercontent.com/knowledgecode/date-and-time/refs/heads/master/logo.png" alt="date-and-time" width="256">
3
5
  </div>
@@ -10,13 +12,15 @@
10
12
 
11
13
  </div>
12
14
 
13
- ## Install
15
+ The simplest, most intuitive date and time library.
16
+
17
+ ## Installation
14
18
 
15
19
  ```shell
16
20
  npm i date-and-time
17
21
  ```
18
22
 
19
- - ESModules:
23
+ - ES Modules:
20
24
 
21
25
  ```typescript
22
26
  import { format } from 'date-and-time';
@@ -42,1279 +46,16 @@ Version `4.x` has been completely rewritten in TypeScript and some features from
42
46
  - Tree shaking is now supported
43
47
  - Supports `ES2021` and no longer supports older browsers
44
48
 
45
- For details, please refer to [MIGRATION.md](https://github.com/knowledgecode/date-and-time/blob/master/docs/MIGRATION.md).
49
+ For details, please refer to [migration.md](https://github.com/knowledgecode/date-and-time/blob/master/docs/migration.md).
46
50
 
47
51
  ## API
48
52
 
49
- ### format(dateObj, arg[, options])
50
-
51
- <details>
52
- <summary>Formats a Date object according to the specified format string.</summary>
53
-
54
- - dateObj
55
- - type: `Date`
56
- - The Date object to format
57
- - arg
58
- - type: `string | CompiledObject`
59
- - The format string or compiled object to match against the Date object
60
- - [options]
61
- - type: `FormatterOptions`
62
- - Optional formatter options for customization
63
-
64
- ```typescript
65
- import { format } from 'date-and-time';
66
- import Tokyo from 'date-and-time/timezones/Asia/Tokyo';
67
- import ja from 'date-and-time/locales/ja';
68
-
69
- const now = new Date();
70
-
71
- format(now, 'YYYY/MM/DD HH:mm:ss');
72
- // => 2015/01/01 23:14:05
73
-
74
- format(now, 'ddd, MMM DD YYYY');
75
- // => Thu, Jan 01 2015
76
-
77
- format(now, 'ddd, MMM DD YYYY hh:mm A [GMT]Z', { timeZone: 'UTC' });
78
- // => Fri, Jan 02 2015 07:14 AM GMT+0000
79
-
80
- format(now, 'YYYY年MMMM月D日dddd Ah:mm:ss [GMT]Z', { timeZone: Tokyo, locale: ja });
81
- // => 2015年1月2日金曜日 午後4:14:05 GMT+0900
82
- ```
83
-
84
- The tokens available for use in the format string specified as the second argument and their meanings are as follows:
85
-
86
- | Token | Meaning | Output Examples |
87
- |:---------|:--------------------------------------------|:----------------------|
88
- | YYYY | 4-digit year | 0999, 2015 |
89
- | YY | 2-digit year | 99, 01, 15 |
90
- | Y | Year without zero padding | 2, 44, 888, 2015 |
91
- | MMMM | Full month name | January, December |
92
- | MMM | Short month name | Jan, Dec |
93
- | MM | Month | 01, 12 |
94
- | M | Month without zero padding | 1, 12 |
95
- | DD | Day | 02, 31 |
96
- | D | Day without zero padding | 2, 31 |
97
- | dddd | Full day name | Friday, Sunday |
98
- | ddd | Short day name | Fri, Sun |
99
- | dd | Very short day name | Fr, Su |
100
- | HH | Hour in 24-hour format | 23, 08 |
101
- | H | Hour in 24-hour format without zero padding | 23, 8 |
102
- | hh | Hour in 12-hour format | 11, 08 |
103
- | h | Hour in 12-hour format without zero padding | 11, 8 |
104
- | A | Uppercase AM/PM | AM, PM |
105
- | AA | Uppercase AM/PM (with periods) | A.M., P.M. |
106
- | a | Lowercase AM/PM | am, pm |
107
- | aa | Lowercase AM/PM (with periods) | a.m., p.m. |
108
- | mm | Minutes | 14, 07 |
109
- | m | Minutes without zero padding | 14, 7 |
110
- | ss | Seconds | 05, 10 |
111
- | s | Seconds without zero padding | 5, 10 |
112
- | SSS | 3-digit milliseconds | 753, 022 |
113
- | SS | 2-digit milliseconds | 75, 02 |
114
- | S | 1-digit milliseconds | 7, 0 |
115
- | Z | Timezone offset | +0100, -0800 |
116
- | ZZ | Timezone offset with colon | +01:00, -08:00 |
117
-
118
- Additionally, by importing plugins, you can use the following tokens. For details, please refer to [PLUGINS.md](https://github.com/knowledgecode/date-and-time/blob/master/docs/PLUGINS.md).
119
-
120
- | Token | Meaning | Output Examples |
121
- |:---------|:--------------------------------------------|:----------------------|
122
- | DDD | Ordinal representation of day | 1st, 2nd, 3rd |
123
- | z | Short timezone name | PST, EST |
124
- | zz | Long timezone name | Pacific Standard Time |
125
-
126
- The breakdown of `FormatterOptions` that can be specified as the third argument is as follows:
127
-
128
- <details>
129
- <summary><strong>hour12</strong></summary>
130
-
131
- - type: `h11 | h12`
132
- - default: `h12`
133
- - The hour format to use for formatting. This is used when the hour is in 12-hour format. It can be `h11` for 11-hour format or `h12` for 12-hour format.
134
-
135
- ```typescript
136
- format(now, 'dddd, MMMM D, YYYY [at] h:mm:ss.SSS A [GMT]ZZ', { hour12: 'h11' });
137
- // Wednesday, July 23, 2025 at 0:12:54.814 AM GMT-07:00
138
- ```
139
-
140
- </details>
141
-
142
- <details>
143
- <summary><strong>hour24</strong></summary>
144
-
145
- - type: `h23 | h24`
146
- - default: `h23`
147
- - The hour format to use for formatting. This is used when the hour is in 24-hour format. It can be `h23` for 23-hour format or `h24` for 24-hour format.
148
-
149
- ```typescript
150
- format(now, 'dddd, MMMM D, YYYY [at] H:mm:ss.SSS [GMT]ZZ', { hour24: 'h24' });
151
- // => Wednesday, July 23, 2025 at 24:12:54.814 GMT-07:00
152
- ```
153
-
154
- </details>
155
-
156
- <details>
157
- <summary><strong>numeral</strong></summary>
158
-
159
- - type: `Numeral`
160
- - default: `latn`
161
- - The numeral system to use for formatting numbers. This is an object that provides methods to encode and decode numbers in the specified numeral system.
162
-
163
- ```typescript
164
- import arab from 'date-and-time/numerals/arab';
165
-
166
- format(now, 'DD/MM/YYYY', { numeral: arab });
167
- // => ٠٨/٠٧/٢٠٢٥
168
- ```
169
-
170
- Currently, the following numeral systems are supported:
171
-
172
- - `arab`
173
- - `arabext`
174
- - `beng`
175
- - `latn`
176
- - `mymr`
177
-
178
- </details>
179
-
180
- <details>
181
- <summary><strong>calendar</strong></summary>
182
-
183
- - type: `buddhist | gregory`
184
- - default: `gregory`
185
- - The calendar system to use for formatting dates. This can be `buddhist` for Buddhist calendar or `gregory` for Gregorian calendar.
186
-
187
- ```typescript
188
- format(now, 'dddd, MMMM D, YYYY', { calendar: 'buddhist' });
189
- // => Wednesday, July 23, 2568
190
- ```
191
-
192
- </details>
193
-
194
- <details>
195
- <summary><strong>timeZone</strong></summary>
196
-
197
- - type: `TimeZone | UTC`
198
- - default: `undefined`
199
- - The time zone to use for formatting dates and times. This can be a specific time zone object or `UTC` to use Coordinated Universal Time. If not specified, it defaults to undefined, which means the local time zone will be used.
200
-
201
- ```typescript
202
- import New_York from 'date-and-time/timezones/America/New_York';
203
-
204
- format(now, 'dddd, MMMM D, YYYY [at] H:mm:ss.SSS [GMT]ZZ', { timeZone: New_York });
205
- // => Wednesday, July 23, 2025 at 3:28:27.443 GMT-04:00
206
- ```
207
-
208
- </details>
209
-
210
- <details>
211
- <summary><strong>locale</strong></summary>
212
-
213
- - type: `Locale`
214
- - default: `en`
215
- - The locale to use for formatting dates and times. This is an object that provides methods to get localized month names, day names, and meridiems.
216
-
217
- ```typescript
218
- import es from 'date-and-time/locales/es';
219
-
220
- format(now, 'dddd, D [de] MMMM [de] YYYY, h:mm:ss.SSS aa [GMT]ZZ', { locale: es });
221
- // => miércoles, 23 de julio de 2025, 12:38:08,533 a.m. GMT-07:00
222
- ```
223
-
224
- <details>
225
- <summary>Currently, the following locales are supported:</summary>
226
-
227
- - `ar` (Arabic)
228
- - `az` (Azerbaijani)
229
- - `bn` (Bengali)
230
- - `cs` (Czech)
231
- - `da` (Danish)
232
- - `de` (German)
233
- - `el` (Greek)
234
- - `en` (English)
235
- - `es` (Spanish)
236
- - `fa` (Persian)
237
- - `fi` (Finnish)
238
- - `fr` (French)
239
- - `he` (Hebrew)
240
- - `hi` (Hindi)
241
- - `hu` (Hungarian)
242
- - `id` (Indonesian)
243
- - `it` (Italian)
244
- - `ja` (Japanese)
245
- - `ko` (Korean)
246
- - `ms` (Malay)
247
- - `my` (Burmese)
248
- - `nl` (Dutch)
249
- - `no` (Norwegian)
250
- - `pl` (Polish)
251
- - `pt-BR` (Brazilian Portuguese)
252
- - `pt-PT` (European Portuguese)
253
- - `ro` (Romanian)
254
- - `ru` (Russian)
255
- - `rw` (Kinyarwanda)
256
- - `sr-Cyrl` (Serbian Cyrillic)
257
- - `sr-Latn` (Serbian Latin)
258
- - `sv` (Swedish)
259
- - `ta` (Tamil)
260
- - `th` (Thai)
261
- - `tr` (Turkish)
262
- - `uk` (Ukrainian)
263
- - `uz-Cyrl` (Uzbek Cyrillic)
264
- - `uz-Latn` (Uzbek Latin)
265
- - `vi` (Vietnamese)
266
- - `zh-Hans` (Simplified Chinese)
267
- - `zh-Hant` (Traditional Chinese)
268
-
269
- </details>
270
- </details>
271
-
272
- #### Notes
273
-
274
- <details open>
275
- <summary><strong>Comments</strong></summary>
276
-
277
- Parts of the format string enclosed in brackets are output as-is, regardless of whether they are valid tokens.
278
-
279
- ```typescript
280
- format(new Date(), 'DD-[MM]-YYYY'); // => '02-MM-2015'
281
- format(new Date(), '[DD-[MM]-YYYY]'); // => 'DD-[MM]-YYYY'
282
- ```
283
-
284
- </details>
285
-
286
- <details open>
287
- <summary><strong>Output as UTC timezone</strong></summary>
288
-
289
- To output date and time as UTC timezone, specify the string `UTC` in the `timeZone` property of `FormatterOptions`.
290
-
291
- ```typescript
292
- format(new Date(), 'hh:mm A [GMT]Z');
293
- // => '12:14 PM GMT-0700'
294
-
295
- format(new Date(), 'hh:mm A [GMT]Z', { timeZone: 'UTC' });
296
- // => '07:14 AM GMT+0000'
297
- ```
298
-
299
- </details>
300
- </details>
301
-
302
- ### parse(dateString, arg[, options])
303
-
304
- <details>
305
- <summary>Parses a date string according to the specified format.</summary>
306
-
307
- - dateString
308
- - type: `string`
309
- - The date string to parse
310
- - arg
311
- - type: `string | CompiledObject`
312
- - The format string or compiled object to match against the date string
313
- - [options]
314
- - type: `ParserOptions`
315
- - Optional parser options for customization
316
-
317
- ```typescript
318
- import { parse } from 'date-and-time';
319
- import Paris from 'date-and-time/timezones/Europe/Paris';
320
- import fr from 'date-and-time/locales/fr';
321
-
322
- parse('2015/01/02 23:14:05', 'YYYY/MM/DD HH:mm:ss');
323
- // => Jan 02 2015 23:14:05 GMT-0800
324
-
325
- parse('02-01-2015', 'DD-MM-YYYY');
326
- // => Jan 02 2015 00:00:00 GMT-0800
327
-
328
- parse('11:14:05 PM', 'h:mm:ss A', { timeZone: 'UTC' });
329
- // => Jan 02 1970 23:14:05 GMT+0000
330
-
331
- parse(
332
- '02 janv. 2015, 11:14:05 PM', 'DD MMM YYYY, h:mm:ss A',
333
- { timeZone: Paris, locale: fr }
334
- );
335
- // => Jan 02 2015 23:14:05 GMT+0100
336
-
337
- parse('Jam 1 2017', 'MMM D YYYY');
338
- // => Invalid Date
339
- ```
340
-
341
- The tokens available for use in the format string specified as the second argument and their meanings are as follows:
342
-
343
- | Token | Meaning | Input Examples |
344
- |:----------|:--------------------------------------------|:--------------------|
345
- | YYYY | 4-digit year | 0999, 2015 |
346
- | Y | Year without zero padding | 2, 44, 88, 2015 |
347
- | MMMM | Full month name | January, December |
348
- | MMM | Short month name | Jan, Dec |
349
- | MM | Month | 01, 12 |
350
- | M | Month without zero padding | 1, 12 |
351
- | DD | Day | 02, 31 |
352
- | D | Day without zero padding | 2, 31 |
353
- | HH | Hour in 24-hour format | 23, 08 |
354
- | H | Hour in 24-hour format without zero padding | 23, 8 |
355
- | hh | Hour in 12-hour format | 11, 08 |
356
- | h | Hour in 12-hour format without zero padding | 11, 8 |
357
- | A | Uppercase AM/PM | AM, PM |
358
- | AA | Uppercase AM/PM (with periods) | A.M., P.M. |
359
- | a | Lowercase AM/PM | am, pm |
360
- | aa | Lowercase AM/PM (with periods) | a.m., p.m. |
361
- | mm | Minutes | 14, 07 |
362
- | m | Minutes without zero padding | 14, 7 |
363
- | ss | Seconds | 05, 10 |
364
- | s | Seconds without zero padding | 5, 10 |
365
- | SSS | 3-digit milliseconds | 753, 022 |
366
- | SS | 2-digit milliseconds | 75, 02 |
367
- | S | 1-digit milliseconds | 7, 0 |
368
- | Z | Timezone offset | +0100, -0800 |
369
- | ZZ | Timezone offset with colon | +01:00, -08:00 |
370
-
371
- Additionally, by importing plugins, you can use the following tokens. For details, please refer to [PLUGINS.md](https://github.com/knowledgecode/date-and-time/blob/master/docs/PLUGINS.md).
372
-
373
- | Token | Meaning | Input Examples |
374
- |:----------|:-------------------------------------------|:---------------------|
375
- | YY | 2-digit year | 90, 00, 08, 19 |
376
- | DDD | Ordinal representation of day | 1st, 2nd, 3rd |
377
- | dddd | Full day name | Friday, Sunday |
378
- | ddd | Short day name | Fri, Sun |
379
- | dd | Very short day name | Fr, Su |
380
- | SSSSSS | 6-digit milliseconds | 123456, 000001 |
381
- | SSSSS | 5-digit milliseconds | 12345, 00001 |
382
- | SSSS | 4-digit milliseconds | 1234, 0001 |
383
- | fff | 3-digit microseconds | 753, 022 |
384
- | ff | 2-digit microseconds | 75, 02 |
385
- | f | 1-digit microseconds | 7, 0 |
386
- | SSSSSSSSS | 9-digit milliseconds | 123456789, 000000001 |
387
- | SSSSSSSS | 8-digit milliseconds | 12345678, 00000001 |
388
- | SSSSSSS | 7-digit milliseconds | 1234567, 0000001 |
389
- | FFF | 3-digit nanoseconds | 753, 022 |
390
- | FF | 2-digit nanoseconds | 75, 02 |
391
- | F | 1-digit nanoseconds | 7, 0 |
392
-
393
- The breakdown of `ParserOptions` that can be specified as the third argument is as follows:
394
-
395
- <details>
396
- <summary><strong>hour12</strong></summary>
397
-
398
- - type: `h11 | h12`
399
- - default: `h12`
400
- - The hour format to use for parsing. This is used when the hour is in 12-hour format. It can be `h11` for 11-hour format (0 - 11) or `h12` for 12-hour format (1 - 12).
401
-
402
- ```typescript
403
- parse('0:12:54 PM', 'h:mm:ss A', { hour12: 'h11' });
404
- // => Jan 01 1970 12:12:54 GMT-0800
405
- ```
406
-
407
- </details>
408
-
409
- <details>
410
- <summary><strong>hour24</strong></summary>
411
-
412
- - type: `h23 | h24`
413
- - default: `h23`
414
- - The hour format to use for parsing. This is used when the hour is in 24-hour format. It can be `h23` for 23-hour format (0 - 23) or `h24` for 24-hour format (1 - 24).
415
-
416
- ```typescript
417
- parse('24:12:54', 'h:mm:ss', { hour24: 'h24' });
418
- // => Jan 01 1970 00:12:54 GMT-0800
419
- ```
420
-
421
- </details>
422
-
423
- <details>
424
- <summary><strong>numeral</strong></summary>
425
-
426
- - type: `Numeral`
427
- - default: `latn`
428
- - The numeral system to use for parsing numbers. This is an object that provides methods to encode and decode numbers in the specified numeral system.
429
-
430
- ```typescript
431
- import arab from 'date-and-time/numerals/arab';
432
-
433
- parse('٠٨/٠٧/٢٠٢٥', 'DD/MM/YYYY', { numeral: arab });
434
- // => July 09 2025 00:00:00 GMT-0700
435
- ```
436
-
437
- Currently, the following numeral systems are supported:
438
-
439
- - `arab`
440
- - `arabext`
441
- - `beng`
442
- - `latn`
443
- - `mymr`
444
-
445
- </details>
446
-
447
- <details>
448
- <summary><strong>calendar</strong></summary>
449
-
450
- - type: `buddhist | gregory`
451
- - default: `gregory`
452
- - The calendar system to use for parsing dates. This can be `buddhist` for Buddhist calendar or `gregory` for Gregorian calendar.
453
-
454
- ```typescript
455
- parse('July 09 2025', 'MMMM DD YYYY', { calendar: 'buddhist' });
456
- // => July 09 1482 00:00:00 GMT-0752
457
- // Note: Buddhist calendar is 543 years ahead of Gregorian calendar,
458
- // so 2025 BE (Buddhist Era) equals 1482 CE (Common Era)
459
- ```
460
-
461
- </details>
462
-
463
- <details>
464
- <summary><strong>ignoreCase</strong></summary>
465
-
466
- - type: `boolean`
467
- - default: `false`
468
- - Whether to ignore case when matching strings. This is useful for matching month names, day names, and meridiems in a case-insensitive manner. If true, the parser will convert both the input string and the strings in the locale to lowercase before matching.
469
-
470
- ```typescript
471
- parse('july 09 2025', 'MMMM DD YYYY', { ignoreCase: true });
472
- // => July 09 2025 00:00:00 GMT-0700
473
- ```
474
-
475
- </details>
476
-
477
- <details>
478
- <summary><strong>timeZone</strong></summary>
479
-
480
- - type: `TimeZone | UTC`
481
- - default: `undefined`
482
- - The time zone to use for parsing dates and times. This can be a specific time zone object or `UTC` to use Coordinated Universal Time. If not specified, it defaults to undefined, which means the local time zone will be used.
483
-
484
- ```typescript
485
- import New_York from 'date-and-time/timezones/America/New_York';
486
-
487
- parse('July 09 2025, 12:34:56', 'MMMM D YYYY, H:mm:ss', { timeZone: New_York });
488
- // => July 09 2025 09:34:56 GMT-0700 (July 09 2025 12:34:56 GMT-0400)
489
-
490
- parse('July 09 2025, 12:34:56', 'MMMM D YYYY, H:mm:ss', { timeZone: 'UTC' });
491
- // => July 09 2025 05:34:56 GMT-0700 (July 09 2025 12:34:56 GMT+0000)
492
- ```
493
-
494
- </details>
495
-
496
- <details>
497
- <summary><strong>locale</strong></summary>
498
-
499
- - type: `Locale`
500
- - default: `en`
501
- - The locale to use for parsing dates and times. This is an object that provides methods to get localized month names, day names, and meridiems.
502
-
503
- ```typescript
504
- import es from 'date-and-time/locales/es';
505
-
506
- parse(
507
- '23 de julio de 2025, 12:38:08,533 a.m. GMT-07:00',
508
- 'D [de] MMMM [de] YYYY, h:mm:ss,SSS aa [GMT]ZZ',
509
- { locale: es }
510
- );
511
- // => July 23 2025 12:38:08.533 GMT-0700
512
- ```
513
-
514
- <details>
515
- <summary>Currently, the following locales are supported:</summary>
516
-
517
- - `ar` (Arabic)
518
- - `az` (Azerbaijani)
519
- - `bn` (Bengali)
520
- - `cs` (Czech)
521
- - `da` (Danish)
522
- - `de` (German)
523
- - `el` (Greek)
524
- - `en` (English)
525
- - `es` (Spanish)
526
- - `fa` (Persian)
527
- - `fi` (Finnish)
528
- - `fr` (French)
529
- - `he` (Hebrew)
530
- - `hi` (Hindi)
531
- - `hu` (Hungarian)
532
- - `id` (Indonesian)
533
- - `it` (Italian)
534
- - `ja` (Japanese)
535
- - `ko` (Korean)
536
- - `ms` (Malay)
537
- - `my` (Burmese)
538
- - `nl` (Dutch)
539
- - `no` (Norwegian)
540
- - `pl` (Polish)
541
- - `pt-BR` (Brazilian Portuguese)
542
- - `pt-PT` (European Portuguese)
543
- - `ro` (Romanian)
544
- - `ru` (Russian)
545
- - `rw` (Kinyarwanda)
546
- - `sr-Cyrl` (Serbian Cyrillic)
547
- - `sr-Latn` (Serbian Latin)
548
- - `sv` (Swedish)
549
- - `ta` (Tamil)
550
- - `th` (Thai)
551
- - `tr` (Turkish)
552
- - `uk` (Ukrainian)
553
- - `uz-Cyrl` (Uzbek Cyrillic)
554
- - `uz-Latn` (Uzbek Latin)
555
- - `vi` (Vietnamese)
556
- - `zh-Hans` (Simplified Chinese)
557
- - `zh-Hant` (Traditional Chinese)
558
-
559
- </details>
560
- </details>
561
-
562
- #### Notes
563
-
564
- <details open>
565
- <summary><strong>When parsing fails</strong></summary>
566
-
567
- If this function fails to parse, it will return `Invalid Date`. Notice that the `Invalid Date` is a Date object, not `NaN` or `null`. You can tell whether the Date object is invalid as follows:
568
-
569
- ```typescript
570
- const today = parse('Jam 1 2017', 'MMM D YYYY');
571
-
572
- if (isNaN(today.getTime())) {
573
- console.error('Parsing failed');
574
- }
575
- ```
576
-
577
- </details>
578
-
579
- <details open>
580
- <summary><strong>Input as UTC timezone</strong></summary>
581
-
582
- If the `dateString` does not contain a timezone offset and the `timeZone` property of the third argument is not specified, this function considers the `dateString` to be in the local timezone. If you want to process a `dateString` without a timezone offset as UTC timezone, set the string `UTC` to the `timeZone` property in the third argument. Note that the timezone offset contained in the `dateString` takes precedence over the `timeZone` property of the third argument.
583
-
584
- ```typescript
585
- parse('11:14:05 PM', 'hh:mm:ss A');
586
- // => Jan 1 1970 23:14:05 GMT-0800
587
-
588
- parse('11:14:05 PM GMT+0000', 'hh:mm:ss A [GMT]Z');
589
- // => Jan 1 1970 23:14:05 GMT+0000
590
-
591
- parse('11:14:05 PM', 'hh:mm:ss A', { timeZone: 'UTC' });
592
- // => Jan 1 1970 23:14:05 GMT+0000
593
- ```
594
-
595
- </details>
596
-
597
- <details open>
598
- <summary><strong>Default Date Time</strong></summary>
599
-
600
- Default date is `January 1, 1970`, time is `00:00:00.000`. Any date/time components not specified in the input string will be filled with these default values.
601
-
602
- ```typescript
603
- parse('11:14:05 PM', 'hh:mm:ss A');
604
- // => Jan 1 1970 23:14:05 GMT-0800
605
-
606
- parse('Feb 2000', 'MMM YYYY');
607
- // => Feb 1 2000 00:00:00 GMT-0800
608
- ```
609
-
610
- </details>
611
-
612
- <details open>
613
- <summary><strong>Max Date / Min Date</strong></summary>
614
-
615
- The parsable maximum date is `December 31, 9999`, and the minimum date is `January 1, 0001`.
616
-
617
- ```typescript
618
- parse('Dec 31 9999', 'MMM D YYYY');
619
- // => Dec 31 9999 00:00:00 GMT-0800
620
-
621
- parse('Dec 31 10000', 'MMM D YYYY');
622
- // => Invalid Date
623
-
624
- parse('Jan 1 0001', 'MMM D YYYY');
625
- // => Jan 1 0001 00:00:00 GMT-0800
626
-
627
- parse('Jan 1 0000', 'MMM D YYYY');
628
- // => Invalid Date
629
- ```
630
-
631
- </details>
632
-
633
- <details open>
634
- <summary><strong>12-hour notation and Meridiem</strong></summary>
635
-
636
- If you use the `hh` or `h` (12-hour) token, use it together with the `A` (meridiem) token to get the correct value.
637
-
638
- ```typescript
639
- parse('11:14:05', 'hh:mm:ss');
640
- // => Jan 1 1970 11:14:05 GMT-0800
641
-
642
- parse('11:14:05 PM', 'hh:mm:ss A');
643
- // => Jan 1 1970 23:14:05 GMT-0800
644
- ```
645
-
646
- </details>
647
-
648
- <details open>
649
- <summary><strong>Token invalidation</strong></summary>
650
-
651
- Any part of the given format string that you do not want to be recognized as a token should be enclosed in square brackets. They are considered comments and will not be parsed.
652
-
653
- ```typescript
654
- parse('12 hours 34 minutes', 'HH hours mm minutes');
655
- // => Invalid Date
656
-
657
- parse('12 hours 34 minutes', 'HH [hours] mm [minutes]');
658
- // => Jan 1 1970 12:34:00 GMT-0800
659
- ```
660
-
661
- </details>
662
-
663
- <details open>
664
- <summary><strong>Wildcard</strong></summary>
665
-
666
- Whitespace acts as a wildcard token. This token will skip parsing the corresponding parts of the date and time strings. This behavior is similar to enclosing part of a format string in square brackets (Token invalidation), but with the flexibility that the contents do not have to match exactly - only the character count needs to match between the format string and input string.
667
-
668
- ```typescript
669
- // This will be an error.
670
- parse('2015/01/02 11:14:05', 'YYYY/MM/DD');
671
- // => Invalid Date
672
-
673
- parse('2015/01/02 11:14:05', 'YYYY/MM/DD ');
674
- // => Jan 2 2015 00:00:00 GMT-0800
675
- ```
676
-
677
- </details>
678
-
679
- <details open>
680
- <summary><strong>Ellipsis</strong></summary>
681
-
682
- `...` token ignores subsequent corresponding date and time strings. Use this token only at the end of a format string. The above example can also be written like this:
683
-
684
- ```typescript
685
- parse('2015/01/02 11:14:05', 'YYYY/MM/DD...');
686
- // => Jan 2 2015 00:00:00 GMT-0800
687
- ```
688
-
689
- </details>
690
- </details>
691
-
692
- ### compile(formatString)
693
-
694
- <details>
695
- <summary>Compiles a format string into a tokenized array for efficient parsing and formatting.</summary>
696
-
697
- - formatString
698
- - type: `string`
699
- - The format string to compile
700
-
701
- If you are going to execute the `format`, `parse`, or `isValid` functions many times with one string format, it is recommended to precompile and reuse it for performance.
702
-
703
- ```typescript
704
- import { compile, parse, format } from 'date-and-time';
705
-
706
- const pattern = compile('MMM D YYYY h:m:s A');
707
-
708
- parse('Mar 22 2019 2:54:21 PM', pattern);
709
- parse('Jul 27 2019 4:15:24 AM', pattern);
710
- parse('Dec 25 2019 3:51:11 AM', pattern);
711
-
712
- format(new Date(), pattern);
713
- // => Mar 16 2020 6:24:56 PM
714
- ```
715
-
716
- </details>
717
-
718
- ### preparse(dateString, arg[, options])
719
-
720
- <details>
721
- <summary>Preparses a date string according to the specified pattern.</summary>
722
-
723
- - dateString
724
- - type: `string`
725
- - The date string to preparse
726
- - arg
727
- - type: `string | CompiledObject`
728
- - The pattern string or compiled object to match against the date string
729
- - [options]
730
- - type: `ParserOptions`
731
- - Optional parser options
732
-
733
- ```typescript
734
- import { preparse } from 'date-and-time';
735
-
736
- preparse('Jan 2015 02 23:14:05 GMT-0800', 'MMM YYYY DD HH:mm:ss [GMT]Z');
737
-
738
- {
739
- Y: 2015, // Year
740
- M: 1, // Month
741
- D: 2, // Day
742
- H: 23, // Hour (24-hour)
743
- m: 14, // Minute
744
- s: 5, // Second
745
- Z: 480, // Timezone offset in minutes
746
- _index: 29, // Current parsing position
747
- _length: 29, // Total length of date string
748
- _match: 7 // Number of matched tokens
749
- }
750
- ```
751
-
752
- This date structure provides a parsing result. You will be able to tell from it how the date string was parsed (or why the parsing failed).
753
-
754
- </details>
755
-
756
- ### isValid(dateString, arg[, options])
757
-
758
- <details>
759
- <summary>Validates whether a date string is valid according to the specified format.</summary>
760
-
761
- - dateString
762
- - type: `string`
763
- - The date string to validate
764
- - arg
765
- - type: `string | CompiledObject`
766
- - The format string or compiled object
767
- - [options]
768
- - type: `ParserOptions`
769
- - Optional parser options
770
-
771
- ```typescript
772
- isValid('2015/01/02 23:14:05', 'YYYY/MM/DD HH:mm:ss'); // => true
773
- isValid('29-02-2015', 'DD-MM-YYYY'); // => false
774
- ```
775
-
776
- For details about `ParserOptions`, refer to the `parse` function section.
777
-
778
- </details>
779
-
780
- ### transform(dateString, arg1, arg2[, options1[, options2]])
781
-
782
- <details>
783
- <summary>Transforms a date string from one format to another.</summary>
784
-
785
- - dateString
786
- - type: `string`
787
- - The date string to transform
788
- - arg1
789
- - type: `string | CompiledObject`
790
- - The format string or compiled object for parsing
791
- - arg2
792
- - type: `string | CompiledObject`
793
- - The format string or compiled object for formatting
794
- - [options1]
795
- - type: `ParserOptions`
796
- - Optional parser options
797
- - [options2]
798
- - type: `FormatterOptions`
799
- - Optional formatter options
800
-
801
- This is a syntactic sugar for combining `parse` and `format` processing to convert date formats in a single function. It converts `dateString` to `arg2` format. Actually, it parses the `dateString` in `arg1` format and then formats it in `arg2` format.
802
-
803
- ```typescript
804
- import { transform } from 'date-and-time';
805
- import New_York from 'date-and-time/timezones/America/New_York';
806
- import Los_Angeles from 'date-and-time/timezones/America/Los_Angeles';
807
-
808
- // Swap the order of month and day
809
- transform('3/8/2020', 'D/M/YYYY', 'M/D/YYYY');
810
- // => 8/3/2020
811
-
812
- // Convert 24-hour format to 12-hour format
813
- transform('13:05', 'HH:mm', 'hh:mm A');
814
- // => 01:05 PM
815
-
816
- // Convert EST to PST
817
- transform(
818
- '3/8/2020 1:05 PM', 'D/M/YYYY h:mm A', 'D/M/YYYY h:mm A',
819
- { timeZone: New_York }, { timeZone: Los_Angeles }
820
- );
821
- // => 3/8/2020 10:05 AM
822
- ```
823
-
824
- For details about `ParserOptions`, refer to the `parse` function section. For details about `FormatterOptions`, refer to the `format` function section.
825
-
826
- </details>
827
-
828
- ### addYears(dateObj, years[, timeZone])
829
-
830
- <details>
831
- <summary>Adds the specified number of years to a Date object.</summary>
832
-
833
- - dateObj
834
- - type: `Date`
835
- - The Date object to modify
836
- - years
837
- - type: `number`
838
- - The number of years to add
839
- - [timeZone]
840
- - type: `TimeZone | UTC`
841
- - Optional time zone object or `UTC`
842
-
843
- ```typescript
844
- import { addYears } from 'date-and-time';
845
- import Los_Angeles from 'date-and-time/timezones/America/Los_Angeles';
846
-
847
- const now = new Date(2024, 2, 11, 1); // => Mar 11 2024 01:00:00 GMT-07:00
848
-
849
- addYears(now, 1, Los_Angeles); // => Mar 11 2025 01:00:00 GMT-07:00
850
- addYears(now, -1, Los_Angeles); // => Mar 11 2023 01:00:00 GMT-08:00
851
- ```
852
-
853
- Exceptional behavior of the calculation for the last day of the month:
854
-
855
- ```typescript
856
- const now = new Date(Date.UTC(2020, 1, 29)); // => Feb 29 2020
857
- const next = addYears(now, 1, 'UTC'); // => Feb 28 2021
858
- const back = addYears(next, -1, 'UTC'); // => Feb 28 2020 (not the original date)
859
- ```
860
-
861
- </details>
862
-
863
- ### addMonths(dateObj, months[, timeZone])
864
-
865
- <details>
866
- <summary>Adds the specified number of months to a Date object.</summary>
867
-
868
- - dateObj
869
- - type: `Date`
870
- - The Date object to modify
871
- - months
872
- - type: `number`
873
- - The number of months to add
874
- - [timeZone]
875
- - type: `TimeZone | UTC`
876
- - Optional time zone object or `UTC`
877
-
878
- ```typescript
879
- import { addMonths } from 'date-and-time';
880
- import Los_Angeles from 'date-and-time/timezones/America/Los_Angeles';
881
-
882
- const now = new Date(2024, 2, 11, 1); // => Mar 11 2024 01:00:00 GMT-07:00
883
-
884
- addMonths(now, 1, Los_Angeles); // => Apr 11 2024 01:00:00 GMT-07:00
885
- addMonths(now, -1, Los_Angeles); // => Feb 11 2024 01:00:00 GMT-08:00
886
- ```
887
-
888
- Exceptional behavior of the calculation for the last day of the month:
889
-
890
- ```typescript
891
- const now = new Date(Date.UTC(2023, 0, 31)); // => Jan 31 2023
892
- const apr = addMonths(now, 3, 'UTC'); // => Apr 30 2023
893
- const feb = addMonths(apr, -2, 'UTC'); // => Feb 28 2023
894
- ```
895
-
896
- </details>
897
-
898
- ### addDays(dateObj, days[, timeZone])
899
-
900
- <details>
901
- <summary>Adds the specified number of days to a Date object.</summary>
902
-
903
- - dateObj
904
- - type: `Date`
905
- - The Date object to modify
906
- - days
907
- - type: `number`
908
- - The number of days to add
909
- - [timeZone]
910
- - type: `TimeZone | UTC`
911
- - Optional time zone object or `UTC`
912
-
913
- ```typescript
914
- import { addDays } from 'date-and-time';
915
- import Los_Angeles from 'date-and-time/timezones/America/Los_Angeles';
916
-
917
- const now = new Date(2024, 2, 11, 1); // => Mar 11 2024 01:00:00 GMT-07:00
918
-
919
- addDays(now, 1, Los_Angeles); // => Mar 12 2024 01:00:00 GMT-07:00
920
- addDays(now, -1, Los_Angeles); // => Mar 10 2024 01:00:00 GMT-08:00
921
- ```
922
-
923
- </details>
924
-
925
- ### addHours(dateObj, hours)
926
-
927
- <details>
928
- <summary>Adds the specified number of hours to a Date object.</summary>
929
-
930
- - dateObj
931
- - type: `Date`
932
- - The Date object to modify
933
- - hours
934
- - type: `number`
935
- - The number of hours to add
936
-
937
- ```typescript
938
- import { addHours } from 'date-and-time';
939
-
940
- const now = new Date(2025, 6, 24); // => Jul 24 2025 00:00:00
941
-
942
- addHours(now, -1); // => Jul 23 2025 23:00:00
943
- ```
944
-
945
- </details>
946
-
947
- ### addMinutes(dateObj, minutes)
948
-
949
- <details>
950
- <summary>Adds the specified number of minutes to a Date object.</summary>
951
-
952
- - dateObj
953
- - type: `Date`
954
- - The Date object to modify
955
- - minutes
956
- - type: `number`
957
- - The number of minutes to add
958
-
959
- ```typescript
960
- import { addMinutes } from 'date-and-time';
961
-
962
- const now = new Date(2025, 6, 24); // => Jul 24 2025 00:00:00
963
-
964
- addMinutes(now, 2); // => Jul 24 2025 00:02:00
965
- ```
966
-
967
- </details>
968
-
969
- ### addSeconds(dateObj, seconds)
970
-
971
- <details>
972
- <summary>Adds the specified number of seconds to a Date object.</summary>
973
-
974
- - dateObj
975
- - type: `Date`
976
- - The Date object to modify
977
- - seconds
978
- - type: `number`
979
- - The number of seconds to add
980
-
981
- ```typescript
982
- import { addSeconds } from 'date-and-time';
983
-
984
- const now = new Date(2025, 6, 24); // => Jul 24 2025 00:00:00
985
-
986
- addSeconds(now, -3); // => Jul 23 2025 23:59:57
987
- ```
988
-
989
- </details>
990
-
991
- ### addMilliseconds(dateObj, milliseconds)
992
-
993
- <details>
994
- <summary>Adds the specified number of milliseconds to a Date object.</summary>
995
-
996
- - dateObj
997
- - type: `Date`
998
- - The Date object to modify
999
- - milliseconds
1000
- - type: `number`
1001
- - The number of milliseconds to add
1002
-
1003
- ```typescript
1004
- import { addMilliseconds } from 'date-and-time';
1005
-
1006
- const now = new Date(2025, 6, 24); // => Jul 24 2025 00:00:00.000
1007
-
1008
- addMilliseconds(now, 123); // => Jul 24 2025 00:00:00.123
1009
- ```
1010
-
1011
- </details>
1012
-
1013
- ### subtract(from, to)
1014
-
1015
- <details>
1016
- <summary>Calculates the difference between two dates.</summary>
1017
-
1018
- - from
1019
- - type: `Date`
1020
- - The first Date object
1021
- - to
1022
- - type: `Date`
1023
- - The second Date object
1024
-
1025
- Returns a `Duration` instance with methods to get the difference in various units.
1026
-
1027
- ```typescript
1028
- import { subtract } from 'date-and-time';
1029
-
1030
- const yesterday = new Date(2015, 0, 1);
1031
- const today = new Date(2015, 0, 2, 3, 4, 5, 6);
1032
-
1033
- const duration = subtract(yesterday, today);
1034
-
1035
- duration.toDays().value; // => 1.127835...
1036
- duration.toHours().value; // => 27.068057...
1037
- duration.toMinutes().value; // => 1624.083433...
1038
- duration.toSeconds().value; // => 97445.006
1039
- duration.toMilliseconds().value; // => 97445006
1040
- duration.toMicroseconds().value; // => 97445006000
1041
- duration.toNanoseconds().value; // => 97445006000000
1042
- ```
1043
-
1044
- #### Duration
1045
-
1046
- The `Duration` object can be directly created not only as a return value of the `subtract` function, but also by passing any numeric value (milliseconds) as a constructor argument.
1047
-
1048
- ```typescript
1049
- import { Duration } from 'date-and-time';
1050
-
1051
- const duration = new Duration(123);
1052
-
1053
- duration.toSeconds().value; // => 0.123
1054
- ```
1055
-
1056
- <details>
1057
- <summary><strong>toDays()</strong></summary>
1058
-
1059
- This method calculates the number of days in the duration and returns a descriptor that includes the value in days, a format method for custom formatting, and a toParts method that returns an object with the parts of the duration.
1060
-
1061
- ```typescript
1062
- duration.toDays().value;
1063
- // => 1.127835...
1064
-
1065
- duration.toDays().format('D[day], H:mm:ss.SSSfffFFF');
1066
- // => 1day, 3:04:05.006000000
1067
-
1068
- duration.toDays().toParts();
1069
- // => { days: 1, hours: 3, minutes: 4, seconds: 5, ... }
1070
- ```
1071
-
1072
- </details>
1073
-
1074
- <details>
1075
- <summary><strong>toHours()</strong></summary>
1076
-
1077
- This method calculates the number of hours in the duration and returns a descriptor that includes the value in hours, a format method for custom formatting, and a toParts method that returns an object with the parts of the duration.
1078
-
1079
- ```typescript
1080
- duration.toHours().value;
1081
- // => 27.068057...
1082
-
1083
- duration.toHours().format('H:mm:ss.SSSfffFFF');
1084
- // => 27:04:05.006000000
1085
-
1086
- duration.toHours().toParts();
1087
- // => { hours: 27, minutes: 4, seconds: 5, ... }
1088
- ```
1089
-
1090
- </details>
1091
-
1092
- <details>
1093
- <summary><strong>toMinutes()</strong></summary>
1094
-
1095
- This method calculates the number of minutes in the duration and returns a descriptor that includes the value in minutes, a format method for custom formatting, and a toParts method that returns an object with the parts of the duration.
1096
-
1097
- ```typescript
1098
- duration.toMinutes().value;
1099
- // => 1624.083433...
1100
-
1101
- duration.toMinutes().format('m[min] ss.SSSfffFFF');
1102
- // => 1624min 05.006000000
1103
-
1104
- duration.toMinutes().toParts();
1105
- // => { minutes: 1624, seconds: 5, milliseconds: 6, ... }
1106
- ```
1107
-
1108
- </details>
1109
-
1110
- <details>
1111
- <summary><strong>toSeconds()</strong></summary>
1112
-
1113
- This method calculates the number of seconds in the duration and returns a descriptor that includes the value in seconds, a format method for custom formatting, and a toParts method that returns an object with the parts of the duration.
1114
-
1115
- ```typescript
1116
- duration.toSeconds().value;
1117
- // => 97445.006
1118
-
1119
- duration.toSeconds().format('s[sec] SSSfffFFF');
1120
- // => 97445sec 006000000
1121
-
1122
- duration.toSeconds().toParts();
1123
- // => { seconds: 97445, milliseconds: 6, microseconds: 0, ... }
1124
- ```
1125
-
1126
- </details>
1127
-
1128
- <details>
1129
- <summary><strong>toMilliseconds()</strong></summary>
1130
-
1131
- This method calculates the number of milliseconds in the duration and returns a descriptor that includes the value in milliseconds, a format method for custom formatting, and a toParts method that returns an object with the parts of the duration.
1132
-
1133
- ```typescript
1134
- duration.toMilliseconds().value;
1135
- // => 97445006
1136
-
1137
- duration.toMilliseconds().format('S.fffFFF');
1138
- // => 97445006.000000
1139
-
1140
- duration.toMilliseconds().toParts();
1141
- // => { milliseconds: 97445006, microseconds: 0, nanoseconds: 0 }
1142
- ```
1143
-
1144
- </details>
1145
-
1146
- <details>
1147
- <summary><strong>toMicroseconds()</strong></summary>
1148
-
1149
- This method calculates the number of microseconds in the duration and returns a descriptor that includes the value in microseconds, a format method for custom formatting, and a toParts method that returns an object with the microseconds and nanoseconds parts.
1150
-
1151
- ```typescript
1152
- duration.toMicroseconds().value;
1153
- // => 97445006000
1154
-
1155
- duration.toMicroseconds().format('f.FFF');
1156
- // => 97445006000.000
1157
-
1158
- duration.toMicroseconds().toParts();
1159
- // => { microseconds: 97445006000, nanoseconds: 0 }
1160
- ```
1161
-
1162
- </details>
1163
-
1164
- <details>
1165
- <summary><strong>toNanoseconds()</strong></summary>
1166
-
1167
- This method calculates the number of nanoseconds in the duration and returns a descriptor that includes the value in nanoseconds, a format method for custom formatting, and a toParts method that returns an object with the nanoseconds part.
1168
-
1169
- ```typescript
1170
- duration.toNanoseconds().value;
1171
- // => 97445006000000
1172
-
1173
- duration.toNanoseconds().format('F[ns]');
1174
- // => 97445006000000ns
1175
-
1176
- duration.toNanoseconds().toParts();
1177
- // => { nanoseconds: 97445006000000 }
1178
- ```
1179
-
1180
- </details>
1181
-
1182
- #### DurationDescriptor
1183
-
1184
- ##### value
1185
-
1186
- The value of the duration in the respective unit.
1187
-
1188
- ##### format(formatString[, numeral])
1189
-
1190
- <details>
1191
- <summary>Formats the duration according to the provided format string.</summary>
1192
-
1193
- - formatString
1194
- - type: `string`
1195
- - The format string to use for formatting
1196
- - [numeral]
1197
- - type: `Numeral`
1198
- - default: `latn`
1199
- - Optional numeral object for number formatting
1200
-
1201
- The tokens available for use in the format string specified as the first argument and their meanings are as follows. However, tokens for units larger than the `DurationDescriptor` cannot be used. For example, in the case of a `DurationDescriptor` obtained by the `toHours` method, the `D` token representing days cannot be used. For a `DurationDescriptor` obtained by the `toNanoseconds` method, only the `F` token representing nanoseconds can be used.
1202
-
1203
- | Token | Meaning |
1204
- |:---------|:-----------------------------------|
1205
- | D | Days |
1206
- | H | Hours |
1207
- | m | Minutes |
1208
- | s | Seconds |
1209
- | S | Milliseconds |
1210
- | f | Microseconds |
1211
- | F | Nanoseconds |
1212
-
1213
- What makes the format string in `DurationDescriptor` different from others is that repeating the same token produces a zero-padding effect. For example, formatting `1 day` with `DDDD` results in an output of `0001`.
1214
-
1215
- </details>
1216
-
1217
- ##### toParts()
1218
-
1219
- <details>
1220
- <summary>Converts the duration to an object containing the parts of the duration in the respective unit.</summary>
1221
-
1222
- ```typescript
1223
- {
1224
- days: 1,
1225
- hours: 3,
1226
- minutes: 4,
1227
- seconds: 5,
1228
- milliseconds: 6,
1229
- microseconds: 0,
1230
- nanoseconds: 0
1231
- }
1232
- ```
1233
-
1234
- </details>
1235
-
1236
- #### Notes
1237
-
1238
- <details open>
1239
- <summary><strong>Negative Duration</strong></summary>
1240
-
1241
- When the `value` becomes negative, there are slight differences in the output results of the `format` method and the `toParts` method. In the `format` method, only the largest unit in the `DurationDescriptor`, for example, only the `D` token in the case of a `DurationDescriptor` obtained by the `toDays` method, gets a minus sign, while in the `toParts` method, all units get a minus sign.
1242
-
1243
- ```typescript
1244
- duration.toDays().value;
1245
- // => -1.127835...
1246
-
1247
- duration.toDays().format('D[day], H:mm:ss.SSSfffFFF');
1248
- // => -1day, 3:04:05.006000000
1249
-
1250
- duration.toDays().toParts();
1251
- // => { days: -1, hours: -3, minutes: -4, seconds: -5, ... }
1252
- ```
1253
-
1254
- </details>
1255
-
1256
- <details open>
1257
- <summary><strong>Negative Zero</strong></summary>
1258
-
1259
- The `format` method may output `-0`. For example, when the value of a `DurationDescriptor` obtained by the `toDays` method is a negative decimal less than 1, using the `D` token in the `format` method outputs `-0`.
1260
-
1261
- ```typescript
1262
- duration.toDays().value;
1263
- // => -0.127835...
1264
-
1265
- duration.toDays().format('D[day], H:mm:ss.SSSfffFFF');
1266
- // => -0day, 3:04:05.006000000
1267
-
1268
- duration.toDays().toParts();
1269
- // => { days: 0, hours: -3, minutes: -4, seconds: -5, ... }
1270
- ```
1271
-
1272
- </details>
1273
- </details>
1274
-
1275
- ### isLeapYear(year)
1276
-
1277
- <details>
1278
- <summary>Determines if the specified year is a leap year.</summary>
1279
-
1280
- - year
1281
- - type: `number`
1282
- - The year to check
1283
-
1284
- ```typescript
1285
- import { isLeapYear } from 'date-and-time';
1286
-
1287
- isLeapYear(2015); // => false
1288
- isLeapYear(2012); // => true
1289
- ```
1290
-
1291
- </details>
1292
-
1293
- ### isSameDay(date1, date2)
1294
-
1295
- <details>
1296
- <summary>Determines if two dates represent the same calendar day.</summary>
1297
-
1298
- - date1
1299
- - type: `Date`
1300
- - The first date to compare
1301
- - date2
1302
- - type: `Date`
1303
- - The second date to compare
1304
-
1305
- ```typescript
1306
- import { isSameDay } from 'date-and-time';
1307
-
1308
- const date1 = new Date(2017, 0, 2, 0); // Jan 2 2017 00:00:00
1309
- const date2 = new Date(2017, 0, 2, 23, 59); // Jan 2 2017 23:59:00
1310
- const date3 = new Date(2017, 0, 1, 23, 59); // Jan 1 2017 23:59:00
1311
-
1312
- isSameDay(date1, date2); // => true
1313
- isSameDay(date1, date3); // => false
1314
- ```
1315
-
1316
- </details>
53
+ For comprehensive documentation and examples, visit: **[GitHub Pages](https://knowledgecode.github.io/date-and-time/)**
1317
54
 
1318
55
  ## License
1319
56
 
1320
57
  MIT
58
+
59
+ ## Contributing
60
+
61
+ Contributions are welcome! Please feel free to submit a Pull Request.