date-and-time 0.14.2 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/EXTEND.md +29 -11
  2. package/LOCALE.md +19 -34
  3. package/PLUGINS.md +222 -113
  4. package/README.md +203 -171
  5. package/date-and-time.js +171 -147
  6. package/date-and-time.min.js +14 -14
  7. package/esm/date-and-time.es.js +466 -0
  8. package/esm/date-and-time.es.min.js +17 -0
  9. package/esm/date-and-time.mjs +466 -0
  10. package/esm/locale/ar.es.js +39 -0
  11. package/esm/locale/ar.mjs +39 -0
  12. package/esm/locale/az.es.js +44 -0
  13. package/esm/locale/az.mjs +44 -0
  14. package/esm/locale/bn.es.js +50 -0
  15. package/esm/locale/bn.mjs +50 -0
  16. package/esm/locale/cs.es.js +22 -0
  17. package/esm/locale/cs.mjs +22 -0
  18. package/esm/locale/de.es.js +23 -0
  19. package/esm/locale/de.mjs +23 -0
  20. package/esm/locale/dk.es.js +22 -0
  21. package/esm/locale/dk.mjs +22 -0
  22. package/esm/locale/el.es.js +44 -0
  23. package/esm/locale/el.mjs +44 -0
  24. package/esm/locale/en.es.js +13 -0
  25. package/esm/locale/en.mjs +13 -0
  26. package/esm/locale/es.es.js +42 -0
  27. package/esm/locale/es.mjs +42 -0
  28. package/esm/locale/fa.es.js +39 -0
  29. package/esm/locale/fa.mjs +39 -0
  30. package/esm/locale/fr.es.js +23 -0
  31. package/esm/locale/fr.mjs +23 -0
  32. package/esm/locale/hi.es.js +50 -0
  33. package/esm/locale/hi.mjs +50 -0
  34. package/esm/locale/hu.es.js +23 -0
  35. package/esm/locale/hu.mjs +23 -0
  36. package/esm/locale/id.es.js +46 -0
  37. package/esm/locale/id.mjs +46 -0
  38. package/esm/locale/it.es.js +23 -0
  39. package/esm/locale/it.mjs +23 -0
  40. package/esm/locale/ja.es.js +31 -0
  41. package/esm/locale/ja.mjs +31 -0
  42. package/esm/locale/jv.es.js +46 -0
  43. package/esm/locale/jv.mjs +46 -0
  44. package/esm/locale/ko.es.js +23 -0
  45. package/esm/locale/ko.mjs +23 -0
  46. package/esm/locale/my.es.js +38 -0
  47. package/esm/locale/my.mjs +38 -0
  48. package/esm/locale/nl.es.js +37 -0
  49. package/esm/locale/nl.mjs +37 -0
  50. package/esm/locale/pa-in.es.js +62 -0
  51. package/esm/locale/pa-in.mjs +62 -0
  52. package/esm/locale/pl.es.js +37 -0
  53. package/esm/locale/pl.mjs +37 -0
  54. package/esm/locale/pt.es.js +44 -0
  55. package/esm/locale/pt.mjs +44 -0
  56. package/esm/locale/ro.es.js +22 -0
  57. package/esm/locale/ro.mjs +22 -0
  58. package/esm/locale/ru.es.js +44 -0
  59. package/esm/locale/ru.mjs +44 -0
  60. package/esm/locale/rw.es.js +22 -0
  61. package/esm/locale/rw.mjs +22 -0
  62. package/esm/locale/sr.es.js +22 -0
  63. package/esm/locale/sr.mjs +22 -0
  64. package/esm/locale/th.es.js +23 -0
  65. package/esm/locale/th.mjs +23 -0
  66. package/esm/locale/tr.es.js +22 -0
  67. package/esm/locale/tr.mjs +22 -0
  68. package/esm/locale/uk.es.js +57 -0
  69. package/esm/locale/uk.mjs +57 -0
  70. package/esm/locale/uz.es.js +22 -0
  71. package/esm/locale/uz.mjs +22 -0
  72. package/esm/locale/vi.es.js +23 -0
  73. package/esm/locale/vi.mjs +23 -0
  74. package/esm/locale/zh-cn.es.js +48 -0
  75. package/esm/locale/zh-cn.mjs +48 -0
  76. package/esm/locale/zh-tw.es.js +46 -0
  77. package/esm/locale/zh-tw.mjs +46 -0
  78. package/esm/plugin/day-of-week.es.js +19 -0
  79. package/esm/plugin/day-of-week.mjs +19 -0
  80. package/esm/plugin/meridiem.es.js +47 -0
  81. package/esm/plugin/meridiem.mjs +47 -0
  82. package/esm/plugin/microsecond.es.js +31 -0
  83. package/esm/plugin/microsecond.mjs +31 -0
  84. package/esm/plugin/ordinal.es.js +34 -0
  85. package/esm/plugin/ordinal.mjs +34 -0
  86. package/esm/plugin/timespan.es.js +75 -0
  87. package/esm/plugin/timespan.mjs +75 -0
  88. package/esm/plugin/timezone.es.js +73 -0
  89. package/esm/plugin/timezone.mjs +73 -0
  90. package/esm/plugin/two-digit-year.es.js +21 -0
  91. package/esm/plugin/two-digit-year.mjs +21 -0
  92. package/locale/ar.js +14 -19
  93. package/locale/az.js +14 -19
  94. package/locale/bn.js +14 -19
  95. package/locale/cs.js +14 -19
  96. package/locale/de.js +15 -20
  97. package/locale/dk.js +15 -20
  98. package/locale/el.js +21 -24
  99. package/locale/en.js +17 -19
  100. package/locale/es.js +14 -19
  101. package/locale/fa.js +14 -19
  102. package/locale/fr.js +14 -19
  103. package/locale/hi.js +14 -19
  104. package/locale/hu.js +14 -19
  105. package/locale/id.js +14 -19
  106. package/locale/it.js +14 -19
  107. package/locale/ja.js +14 -19
  108. package/locale/jv.js +14 -19
  109. package/locale/ko.js +14 -19
  110. package/locale/my.js +14 -19
  111. package/locale/nl.js +20 -23
  112. package/locale/pa-in.js +14 -19
  113. package/locale/pl.js +20 -23
  114. package/locale/pt.js +14 -19
  115. package/locale/ro.js +15 -20
  116. package/locale/ru.js +14 -19
  117. package/locale/rw.js +30 -0
  118. package/locale/sr.js +14 -19
  119. package/locale/th.js +14 -19
  120. package/locale/tr.js +14 -19
  121. package/locale/uk.js +23 -26
  122. package/locale/uz.js +14 -19
  123. package/locale/vi.js +14 -19
  124. package/locale/zh-cn.js +14 -19
  125. package/locale/zh-tw.js +14 -19
  126. package/package.json +26 -11
  127. package/plugin/day-of-week.js +13 -14
  128. package/plugin/meridiem.js +32 -24
  129. package/plugin/microsecond.js +14 -15
  130. package/plugin/ordinal.js +13 -14
  131. package/plugin/timespan.js +13 -14
  132. package/plugin/timezone.js +81 -0
  133. package/plugin/two-digit-year.js +13 -19
package/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  [![Circle CI](https://circleci.com/gh/knowledgecode/date-and-time.svg?style=shield)](https://circleci.com/gh/knowledgecode/date-and-time)
4
4
 
5
- This library is a minimalist collection of functions for manipulating JS date and time. It's tiny, simple, easy to learn.
5
+ This JS library is just a collection of functions for manipulating date and time. It's small, simple, and easy to learn.
6
6
 
7
7
  ## Why
8
8
 
9
- JS modules nowadays are getting more huge and complex, and there are also many dependencies. Trying to keep each module simple and small is meaningful.
9
+ Nowadays, JS modules have become huge, complex, and have many dependencies. We think it makes sense to try to keep each module simple and small. Especially for modules that are at the bottom of the dependency chain, such as those dealing with date and time.
10
10
 
11
11
  ## Features
12
12
 
@@ -18,73 +18,120 @@ JS modules nowadays are getting more huge and complex, and there are also many d
18
18
 
19
19
  ## Install
20
20
 
21
- - via npm:
22
-
23
21
  ```shell
24
- npm install date-and-time --save
22
+ npm i date-and-time
23
+ ```
24
+
25
+ ## Recent Changes
26
+
27
+ - 2.0.1
28
+ - Fixed a bug that the timezone plugin does not support changing locales.
29
+
30
+ - 2.0.0
31
+ - Fixed a conflict when importing multiple plugins and locales.
32
+ - **Breaking Changes!** Due to the above fix, the specifications of plugin, locale, and extension have been changed. The `meridiem` plugin and the `two-digit-year` plugin are now partially incompatible with previous ones. See [here](./PLUGINS.md) for details. Also the `extend()` function has changed. If you are using it, check [here](./EXTEND.md) for any impact. The locales are still compatible.
33
+ - Added `timezone` plugin. You can now use the IANA timezone name to output a datetime string or input a date object. See [PLUGINS.md](./PLUGINS.md) for details.
34
+
35
+ - 1.0.1
36
+ - Updated dev dependencies to resolve vulnerability.
37
+
38
+ ## Usage
39
+
40
+ - ES Modules:
41
+
42
+ ```javascript
43
+ import date from 'date-and-time';
44
+ ```
45
+
46
+ - CommonJS:
47
+
48
+ ```javascript
49
+ const date = require('date-and-time');
50
+ ```
51
+
52
+ - ES Modules for the browser:
53
+
54
+ ```html
55
+ <script type="module">
56
+ import date from '/path/to/date-and-time.es.min.js';
57
+ </script>
25
58
  ```
26
59
 
27
- - local:
60
+ - Older browser:
28
61
 
29
62
  ```html
30
63
  <script src="/path/to/date-and-time.min.js"></script>
31
64
  ```
32
65
 
33
- ## Recent Changes
66
+ ### Note
34
67
 
35
- - 0.14.2
36
- - Fixed regular expression denial of service (ReDoS) vulnerability.
68
+ - If you want to use ES Modules in Node.js without a transpiler, you need to add `"type": "module"` in your `package.json` or change your file extension from `.js` to `.mjs`.
37
69
 
38
- - 0.14.1
39
- - Fixed a bug characters inside square brackets `[]` are not validated.
70
+ ## API
40
71
 
41
- - 0.14.0
42
- - **Feature Freeze**
72
+ - [format](#formatdateobj-arg-utc)
73
+ - Formatting a Date and Time (Date -> String)
43
74
 
44
- We decided to freeze the feature with this version (except the following). The next will be 1.0.0.
75
+ - [parse](#parsedatestring-arg-utc)
76
+ - Parsing a Date and Time string (String -> Date)
45
77
 
46
- - To support `ES Modules` (without transpile) in the next version, the importing method has changed in the `locale()` and the `plugin()`. As this version you will see the warning message if using the old method. See [LOCALE.md](./LOCALE.md) and [PLUGINS.md](./PLUGINS.md) for details.
78
+ - [compile](#compileformatstring)
79
+ - Compiling a format string
47
80
 
48
- - Added `transform()` function to transform the format of a date string. When changing the format, previously you would convert the date string to a date object with the `parse()`, and then format it with the `format()` again, but you can now do this with a single function.
81
+ - [preparse](#preparsedatestring-arg)
82
+ - Pre-parsing a Date and Time string
49
83
 
50
- ```javascript
51
- // 3/8/2020 => 8/3/2020
52
- date.transform('3/8/2020', 'D/M/YYYY', 'M/D/YYYY');
84
+ - [isValid](#isvalidarg1-arg2)
85
+ - Validation
53
86
 
54
- // previously
55
- const today = date.parse('3/8/2020', 'D/M/YYYY');
56
- date.format(today, 'M/D/YYYY'); // => '8/3/2020'
57
- ```
87
+ - [transform](#transformdatestring-arg1-arg2-utc)
88
+ - Transforming a Date and Time string (String -> String)
58
89
 
59
- ## Usage
90
+ - [addYears](#addyearsdateobj-years)
91
+ - Adding years
60
92
 
61
- - Node.js:
93
+ - [addMonths](#addmonthsdateobj-months)
94
+ - Adding months
62
95
 
63
- ```javascript
64
- const date = require('date-and-time');
65
- ```
96
+ - [addDays](#adddaysdateobj-days)
97
+ - Adding days
66
98
 
67
- - With a transpiler:
99
+ - [addHours](#addhoursdateobj-hours)
100
+ - Adding hours
68
101
 
69
- ```javascript
70
- import date from 'date-and-time';
71
- ```
102
+ - [addMinutes](#addminutesdateobj-minutes)
103
+ - Adding minutes
72
104
 
73
- - The browser:
105
+ - [addSeconds](#addsecondsdateobj-seconds)
106
+ - Adding seconds
74
107
 
75
- ```javascript
76
- window.date; // global object
77
- ```
108
+ - [addMilliseconds](#addmillisecondsdateobj-milliseconds)
109
+ - Adding milliseconds
78
110
 
79
- ## API
111
+ - [subtract](#subtractdate1-date2)
112
+ - Subtracting two dates
113
+
114
+ - [isLeapYear](#isleapyeary)
115
+ - Whether year is leap year
116
+
117
+ - [isSameDay](#issamedaydate1-date2)
118
+ - Comparison of two dates
119
+
120
+ - [locale](#localecode-locale)
121
+ - Changing the locale or defining new locales
122
+
123
+ - [extend](#extendextension)
124
+ - Feature extension
80
125
 
81
- ### format(dateObj, formatString[, utc])
126
+ - [plugin](#pluginname-plugin)
127
+ - Importing or defining plugins
82
128
 
83
- - Formatting a date.
84
- - @param {**Date**} dateObj - a Date object
85
- - @param {**string|Array.\<string\>**} arg - a format string or a compiled object
86
- - @param {**boolean**} [utc] - output as UTC
87
- - @returns {**string**} a formatted string
129
+ ### format(dateObj, arg[, utc])
130
+
131
+ - @param {**Date**} dateObj - a Date object
132
+ - @param {**string|Array.\<string\>**} arg - a format string or its compiled object
133
+ - @param {**boolean**} [utc] - output as UTC
134
+ - @returns {**string**} a formatted string
88
135
 
89
136
  ```javascript
90
137
  const now = new Date();
@@ -136,7 +183,7 @@ You can also use the following tokens by importing plugins. See [PLUGINS.md](./P
136
183
  | a | meridiem (lowercase) | am, pm |
137
184
  | aa | meridiem (lowercase with ellipsis) | a.m., p.m. |
138
185
 
139
- #### NOTE 1. Comments
186
+ #### Note 1. Comments
140
187
 
141
188
  String in parenthese `[...]` in the `formatString` will be ignored as comments:
142
189
 
@@ -145,7 +192,7 @@ date.format(new Date(), 'DD-[MM]-YYYY'); // => '02-MM-2015'
145
192
  date.format(new Date(), '[DD-[MM]-YYYY]'); // => 'DD-[MM]-YYYY'
146
193
  ```
147
194
 
148
- #### NOTE 2. Output as UTC
195
+ #### Note 2. Output as UTC
149
196
 
150
197
  This function usually outputs a local date-time string. Set to true the `utc` option (the 3rd parameter) if you would like to get a UTC date-time string.
151
198
 
@@ -154,17 +201,16 @@ date.format(new Date(), 'hh:mm A [GMT]Z'); // => '11:14 PM GMT-0800'
154
201
  date.format(new Date(), 'hh:mm A [GMT]Z', true); // => '07:14 AM GMT+0000'
155
202
  ```
156
203
 
157
- #### NOTE 3. More Tokens
204
+ #### Note 3. More Tokens
158
205
 
159
206
  You can also define your own tokens. See [EXTEND.md](./EXTEND.md) for details.
160
207
 
161
208
  ### parse(dateString, arg[, utc])
162
209
 
163
- - Parsing a date string.
164
- - @param {**string**} dateString - a date string
165
- - @param {**string|Array.\<string\>**} arg - a format string or a compiled object
166
- - @param {**boolean**} [utc] - input as UTC
167
- - @returns {**Date**} a constructed date
210
+ - @param {**string**} dateString - a date string
211
+ - @param {**string|Array.\<string\>**} arg - a format string or its compiled object
212
+ - @param {**boolean**} [utc] - input as UTC
213
+ - @returns {**Date**} a constructed date
168
214
 
169
215
  ```javascript
170
216
  date.parse('2015/01/02 23:14:05', 'YYYY/MM/DD HH:mm:ss'); // => Jan 2 2015 23:14:05 GMT-0800
@@ -178,45 +224,46 @@ date.parse('Feb 29 2017', 'MMM D YYYY'); // => Invalid Date
178
224
 
179
225
  Available tokens and their meanings are as follows:
180
226
 
181
- | token | meaning | examples of acceptable form |
182
- |:-------|:-------------------------------------|:---------------------------------------|
183
- | YYYY | four-digit year | 0999, 2015 |
184
- | Y | four-digit year without zero-padding | 2, 44, 88, 2015 |
185
- | MMMM | month name (long) | January, December |
186
- | MMM | month name (short) | Jan, Dec |
187
- | MM | month with zero-padding | 01, 12 |
188
- | M | month | 1, 12 |
189
- | DD | date with zero-padding | 02, 31 |
190
- | D | date | 2, 31 |
191
- | HH | 24-hour with zero-padding | 23, 08 |
192
- | H | 24-hour | 23, 8 |
193
- | hh | 12-hour with zero-padding | 11, 08 |
194
- | h | 12-hour | 11, 8 |
195
- | A | meridiem (uppercase) | AM, PM |
196
- | mm | minute with zero-padding | 14, 07 |
197
- | m | minute | 14, 7 |
198
- | ss | second with zero-padding | 05, 10 |
199
- | s | second | 5, 10 |
200
- | SSS | millisecond (high accuracy) | 753, 022 |
201
- | SS | millisecond (middle accuracy) | 75, 02 |
202
- | S | millisecond (low accuracy) | 7, 0 |
203
- | Z | timezone offset | +0100, -0800 |
227
+ | token | meaning | examples of acceptable form |
228
+ |:-------|:-------------------------------------|:----------------------------|
229
+ | YYYY | four-digit year | 0999, 2015 |
230
+ | Y | four-digit year without zero-padding | 2, 44, 88, 2015 |
231
+ | MMMM | month name (long) | January, December |
232
+ | MMM | month name (short) | Jan, Dec |
233
+ | MM | month with zero-padding | 01, 12 |
234
+ | M | month | 1, 12 |
235
+ | DD | date with zero-padding | 02, 31 |
236
+ | D | date | 2, 31 |
237
+ | HH | 24-hour with zero-padding | 23, 08 |
238
+ | H | 24-hour | 23, 8 |
239
+ | hh | 12-hour with zero-padding | 11, 08 |
240
+ | h | 12-hour | 11, 8 |
241
+ | A | meridiem (uppercase) | AM, PM |
242
+ | mm | minute with zero-padding | 14, 07 |
243
+ | m | minute | 14, 7 |
244
+ | ss | second with zero-padding | 05, 10 |
245
+ | s | second | 5, 10 |
246
+ | SSS | millisecond (high accuracy) | 753, 022 |
247
+ | SS | millisecond (middle accuracy) | 75, 02 |
248
+ | S | millisecond (low accuracy) | 7, 0 |
249
+ | Z | timezone offset | +0100, -0800 |
204
250
 
205
251
  You can also use the following tokens by importing plugins. See [PLUGINS.md](./PLUGINS.md) for details.
206
252
 
207
- | token | meaning | examples of acceptable form |
208
- |:-------|:-------------------------------------|:---------------------------------------|
209
- | YY | two-digit year | 90, 00, 08, 19 |
210
- | Y | two-digit year without zero-padding | 90, 0, 8, 19 |
211
- | A | meridiem | AM, PM, A.M., P.M., am, pm, a.m., p.m. |
212
- | dddd | day of week (long) | Friday, Sunday |
213
- | ddd | day of week (short) | Fri, Sun |
214
- | dd | day of week (very short) | Fr, Su |
215
- | SSSSSS | microsecond (high accuracy) | 123456, 000001 |
216
- | SSSSS | microsecond (middle accuracy) | 12345, 00001 |
217
- | SSSS | microsecond (low accuracy) | 1234, 0001 |
218
-
219
- #### NOTE 1. Invalid Date
253
+ | token | meaning | examples of acceptable form |
254
+ |:-------|:-------------------------------------|:----------------------------|
255
+ | YY | two-digit year | 90, 00, 08, 19 |
256
+ | AA | meridiem (uppercase with ellipsis) | A.M., P.M. |
257
+ | a | meridiem (lowercase) | am, pm |
258
+ | aa | meridiem (lowercase with ellipsis) | a.m., p.m. |
259
+ | dddd | day of week (long) | Friday, Sunday |
260
+ | ddd | day of week (short) | Fri, Sun |
261
+ | dd | day of week (very short) | Fr, Su |
262
+ | SSSSSS | microsecond (high accuracy) | 123456, 000001 |
263
+ | SSSSS | microsecond (middle accuracy) | 12345, 00001 |
264
+ | SSSS | microsecond (low accuracy) | 1234, 0001 |
265
+
266
+ #### Note 1. Invalid Date
220
267
 
221
268
  If the 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:
222
269
 
@@ -228,7 +275,7 @@ if (isNaN(today)) {
228
275
  }
229
276
  ```
230
277
 
231
- #### NOTE 2. Input as UTC
278
+ #### Note 2. Input as UTC
232
279
 
233
280
  This function usually assumes the `dateString` is a local date-time. Set to true the `utc` option (the 3rd parameter) if it is a UTC date-time.
234
281
 
@@ -237,7 +284,7 @@ date.parse('11:14:05 PM', 'hh:mm:ss A'); // => Jan 1 1970 23:14:05 GMT-
237
284
  date.parse('11:14:05 PM', 'hh:mm:ss A', true); // => Jan 1 1970 23:14:05 GMT+0000 (Jan 1 1970 15:14:05 GMT-0800)
238
285
  ```
239
286
 
240
- #### NOTE 3. Default Date Time
287
+ #### Note 3. Default Date Time
241
288
 
242
289
  Default date is `January 1, 1970`, time is `00:00:00.000`. Values not passed will be complemented with them:
243
290
 
@@ -246,7 +293,7 @@ date.parse('11:14:05 PM', 'hh:mm:ss A'); // => Jan 1 1970 23:14:05 GMT-0800
246
293
  date.parse('Feb 2000', 'MMM YYYY'); // => Feb 1 2000 00:00:00 GMT-0800
247
294
  ```
248
295
 
249
- #### NOTE 4. Max Date / Min Date
296
+ #### Note 4. Max Date / Min Date
250
297
 
251
298
  Parsable maximum date is `December 31, 9999`, minimum date is `January 1, 0001`.
252
299
 
@@ -258,7 +305,7 @@ date.parse('Jan 1 0001', 'MMM D YYYY'); // => Jan 1 0001 00:00:00 GMT-0800
258
305
  date.parse('Jan 1 0000', 'MMM D YYYY'); // => Invalid Date
259
306
  ```
260
307
 
261
- #### NOTE 5. 12-hour notation and Meridiem
308
+ #### Note 5. 12-hour notation and Meridiem
262
309
 
263
310
  If use `hh` or `h` (12-hour) token, use together `A` (meridiem) token to get the right value.
264
311
 
@@ -267,7 +314,7 @@ date.parse('11:14:05', 'hh:mm:ss'); // => Jan 1 1970 11:14:05 GMT-0800
267
314
  date.parse('11:14:05 PM', 'hh:mm:ss A'); // => Jan 1 1970 23:14:05 GMT-0800
268
315
  ```
269
316
 
270
- #### NOTE 6. Token disablement
317
+ #### Note 6. Token disablement
271
318
 
272
319
  Use square brackets `[]` if a date-time string includes some token characters. Tokens inside square brackets in the `formatString` will be interpreted as normal characters:
273
320
 
@@ -276,9 +323,9 @@ date.parse('12 hours 34 minutes', 'HH hours mm minutes'); // => Invalid Da
276
323
  date.parse('12 hours 34 minutes', 'HH [hours] mm [minutes]'); // => Jan 1 1970 12:34:00 GMT-0800
277
324
  ```
278
325
 
279
- #### NOTE 7. Wildcard
326
+ #### Note 7. Wildcard
280
327
 
281
- A white space works as a wildcard token. This token is not interpret into anything. This means it can be ignored a specific variable string. For example, when you would like to ignore a time part from a date string, you can write as follows:
328
+ A white space works as a wildcard token. This token is not interpreted into anything. This means it can be ignored a specific variable string. For example, when you would like to ignore a time part from a date string, you can write as follows:
282
329
 
283
330
  ```javascript
284
331
  // This will be an error.
@@ -287,9 +334,9 @@ date.parse('2015/01/02 11:14:05', 'YYYY/MM/DD'); // => Invalid Date
287
334
  date.parse('2015/01/02 11:14:05', 'YYYY/MM/DD '); // => Jan 2 2015 00:00:00 GMT-0800
288
335
  ```
289
336
 
290
- #### NOTE 8. Ellipsis
337
+ #### Note 8. Ellipsis
291
338
 
292
- The parser supports `...` (ellipse) token. The above example can also be written like this:
339
+ The parser supports `...` (ellipsis) token. The above example can be also written like this:
293
340
 
294
341
  ```javascript
295
342
  date.parse('2015/01/02 11:14:05', 'YYYY/MM/DD...'); // => Jan 2 2015 00:00:00 GMT-0800
@@ -297,9 +344,10 @@ date.parse('2015/01/02 11:14:05', 'YYYY/MM/DD...'); // => Jan 2 2015 00:00:00
297
344
 
298
345
  ### compile(formatString)
299
346
 
300
- - Compiling a format string for the parser.
301
- - @param {**string**} formatString - a format string
302
- - @returns {**Array.\<string\>**} a compiled object
347
+ - @param {**string**} formatString - a format string
348
+ - @returns {**Array.\<string\>**} a compiled object
349
+
350
+ If you are going to execute the `format()`, the `parse()` or the `isValid()` so many times with one string format, recommended to precompile and reuse it for performance.
303
351
 
304
352
  ```javascript
305
353
  const pattern = date.compile('MMM D YYYY h:m:s A');
@@ -311,14 +359,11 @@ date.parse('2015/01/02 11:14:05', 'YYYY/MM/DD...'); // => Jan 2 2015 00:00:00
311
359
  date.format(new Date(), pattern); // => Mar 16 2020 6:24:56 PM
312
360
  ```
313
361
 
314
- If you are going to call the `format()`, the `parse()` or the `isValid()` many times with one string format, recommended to precompile and reuse it for performance.
315
-
316
362
  ### preparse(dateString, arg)
317
363
 
318
- - Pre-parsing a date string.
319
- - @param {**string**} dateString - a date string
320
- - @param {**string|Array.\<string\>**} arg - a format string or a compiled object
321
- - @returns {**Object**} a date structure
364
+ - @param {**string**} dateString - a date string
365
+ - @param {**string|Array.\<string\>**} arg - a format string or its compiled object
366
+ - @returns {**Object**} a date structure
322
367
 
323
368
  This function takes exactly the same parameters with the `parse()`, but returns a date structure as follows unlike that:
324
369
 
@@ -346,10 +391,9 @@ This date structure provides a parsing result. You will be able to tell from it
346
391
 
347
392
  ### isValid(arg1[, arg2])
348
393
 
349
- - Validation.
350
- - @param {**Object|string**} arg1 - a date structure or a date string
351
- - @param {**string|Array.\<string\>**} [arg2] - a format string or a compiled object
352
- - @returns {**boolean**} whether the date string is a valid date
394
+ - @param {**Object|string**} arg1 - a date structure or a date string
395
+ - @param {**string|Array.\<string\>**} [arg2] - a format string or its compiled object
396
+ - @returns {**boolean**} whether the date string is a valid date
353
397
 
354
398
  This function takes either exactly the same parameters with the `parse()` or a date structure which the `preparse()` returns, evaluates the validity of them.
355
399
 
@@ -365,12 +409,11 @@ date.isValid(result); // => true
365
409
 
366
410
  ### transform(dateString, arg1, arg2[, utc])
367
411
 
368
- - Transformation of date string.
369
- - @param {**string**} dateString - a date string
370
- - @param {**string|Array.\<string\>**} arg1 - the format string of the date string or the compiled object
371
- - @param {**string|Array.\<string\>**} arg2 - the transformed format string or the compiled object
372
- - @param {**boolean**} [utc] - output as UTC
373
- - @returns {**string**} a formatted string
412
+ - @param {**string**} dateString - a date string
413
+ - @param {**string|Array.\<string\>**} arg1 - a format string or its compiled object
414
+ - @param {**string|Array.\<string\>**} arg2 - a transformed format string or its compiled object
415
+ - @param {**boolean**} [utc] - output as UTC
416
+ - @returns {**string**} a formatted string
374
417
 
375
418
  This function transforms the format of a date string. The 2nd parameter, `arg1`, is the format string of it. Available token list is equal to the `parse()`'s. The 3rd parameter, `arg2`, is the transformed format string. Available token list is equal to the `format()`'s.
376
419
 
@@ -384,10 +427,9 @@ date.transform('13:05', 'HH:mm', 'hh:mm A');
384
427
 
385
428
  ### addYears(dateObj, years)
386
429
 
387
- - Adding years.
388
- - @param {**Date**} dateObj - a Date object
389
- - @param {**number**} years - number of years to add
390
- - @returns {**Date**} a date after adding the value
430
+ - @param {**Date**} dateObj - a Date object
431
+ - @param {**number**} years - number of years to add
432
+ - @returns {**Date**} a date after adding the value
391
433
 
392
434
  ```javascript
393
435
  const now = new Date();
@@ -396,10 +438,9 @@ const next_year = date.addYears(now, 1);
396
438
 
397
439
  ### addMonths(dateObj, months)
398
440
 
399
- - Adding months.
400
- - @param {**Date**} dateObj - a Date object
401
- - @param {**number**} months - number of months to add
402
- - @returns {**Date**} a date after adding the value
441
+ - @param {**Date**} dateObj - a Date object
442
+ - @param {**number**} months - number of months to add
443
+ - @returns {**Date**} a date after adding the value
403
444
 
404
445
  ```javascript
405
446
  const now = new Date();
@@ -408,10 +449,9 @@ const next_month = date.addMonths(now, 1);
408
449
 
409
450
  ### addDays(dateObj, days)
410
451
 
411
- - Adding days.
412
- - @param {**Date**} dateObj - a Date object
413
- - @param {**number**} days - number of days to add
414
- - @returns {**Date**} a date after adding the value
452
+ - @param {**Date**} dateObj - a Date object
453
+ - @param {**number**} days - number of days to add
454
+ - @returns {**Date**} a date after adding the value
415
455
 
416
456
  ```javascript
417
457
  const now = new Date();
@@ -420,10 +460,9 @@ const yesterday = date.addDays(now, -1);
420
460
 
421
461
  ### addHours(dateObj, hours)
422
462
 
423
- - Adding hours.
424
- - @param {**Date**} dateObj - a Date object
425
- - @param {**number**} hours - number of hours to add
426
- - @returns {**Date**} a date after adding the value
463
+ - @param {**Date**} dateObj - a Date object
464
+ - @param {**number**} hours - number of hours to add
465
+ - @returns {**Date**} a date after adding the value
427
466
 
428
467
  ```javascript
429
468
  const now = new Date();
@@ -432,10 +471,9 @@ const an_hour_ago = date.addHours(now, -1);
432
471
 
433
472
  ### addMinutes(dateObj, minutes)
434
473
 
435
- - Adding minutes.
436
- - @param {**Date**} dateObj - a Date object
437
- - @param {**number**} minutes - number of minutes to add
438
- - @returns {**Date**} a date after adding the value
474
+ - @param {**Date**} dateObj - a Date object
475
+ - @param {**number**} minutes - number of minutes to add
476
+ - @returns {**Date**} a date after adding the value
439
477
 
440
478
  ```javascript
441
479
  const now = new Date();
@@ -444,10 +482,9 @@ const two_minutes_later = date.addMinutes(now, 2);
444
482
 
445
483
  ### addSeconds(dateObj, seconds)
446
484
 
447
- - Adding seconds.
448
- - @param {**Date**} dateObj - a Date object
449
- - @param {**number**} seconds - number of seconds to add
450
- - @returns {**Date**} a date after adding the value
485
+ - @param {**Date**} dateObj - a Date object
486
+ - @param {**number**} seconds - number of seconds to add
487
+ - @returns {**Date**} a date after adding the value
451
488
 
452
489
  ```javascript
453
490
  const now = new Date();
@@ -456,10 +493,9 @@ const three_seconds_ago = date.addSeconds(now, -3);
456
493
 
457
494
  ### addMilliseconds(dateObj, milliseconds)
458
495
 
459
- - Adding milliseconds.
460
- - @param {**Date**} dateObj - a Date object
461
- - @param {**number**} milliseconds - number of milliseconds to add
462
- - @returns {**Date**} a date after adding the value
496
+ - @param {**Date**} dateObj - a Date object
497
+ - @param {**number**} milliseconds - number of milliseconds to add
498
+ - @returns {**Date**} a date after adding the value
463
499
 
464
500
  ```javascript
465
501
  const now = new Date();
@@ -468,10 +504,9 @@ const a_millisecond_later = date.addMilliseconds(now, 1);
468
504
 
469
505
  ### subtract(date1, date2)
470
506
 
471
- - Subtracting.
472
- - @param {**Date**} date1 - a Date object
473
- - @param {**Date**} date2 - a Date object
474
- - @returns {**Object**} a result object subtracting date2 from date1
507
+ - @param {**Date**} date1 - a Date object
508
+ - @param {**Date**} date2 - a Date object
509
+ - @returns {**Object**} a result object subtracting date2 from date1
475
510
 
476
511
  ```javascript
477
512
  const today = new Date(2015, 0, 2);
@@ -486,9 +521,8 @@ date.subtract(today, yesterday).toMilliseconds(); // => 86400000
486
521
 
487
522
  ### isLeapYear(y)
488
523
 
489
- - Leap year.
490
- - @param {**number**} y - year
491
- - @returns {**boolean**} whether the year is a leap year
524
+ - @param {**number**} y - year
525
+ - @returns {**boolean**} whether year is leap year
492
526
 
493
527
  ```javascript
494
528
  date.isLeapYear(2015); // => false
@@ -497,10 +531,9 @@ date.isLeapYear(2012); // => true
497
531
 
498
532
  ### isSameDay(date1, date2)
499
533
 
500
- - Comparison of two dates.
501
- - @param {**Date**} date1 - a Date object
502
- - @param {**Date**} date2 - a Date object
503
- - @returns {**boolean**} whether the dates are the same day (times are ignored)
534
+ - @param {**Date**} date1 - a Date object
535
+ - @param {**Date**} date2 - a Date object
536
+ - @returns {**boolean**} whether the two dates are the same day (time is ignored)
504
537
 
505
538
  ```javascript
506
539
  const date1 = new Date(2017, 0, 2, 0); // Jan 2 2017 00:00:00
@@ -512,41 +545,40 @@ date.isSameDay(date1, date3); // => false
512
545
 
513
546
  ### locale([code[, locale]])
514
547
 
515
- - Change locale or setting a new locale definition.
516
- - @param {**string**} [code] - language code
517
- - @param {**Object**} [locale] - locale definition
518
- - @returns {**string**} current language code
548
+ - @param {**Function|string**} [code] - locale installer | language code
549
+ - @param {**Object**} [locale] - locale definition
550
+ - @returns {**string**} current language code
519
551
 
520
- It returns a current language code if called without any parameters.
552
+ It returns the current language code if called without any parameters.
521
553
 
522
554
  ```javascript
523
555
  date.locale(); // => "en"
524
556
  ```
525
557
 
526
- To switch to any other language, call it with a language code.
558
+ To switch to any other language, call it with a locale installer or a language code.
527
559
 
528
560
  ```javascript
529
- date.locale('es'); // Switch to Spanish
561
+ import es from 'date-and-time/locale/es';
562
+
563
+ date.locale(es); // Switch to Spanish
530
564
  ```
531
565
 
532
566
  See [LOCALE.md](./LOCALE.md) for details.
533
567
 
534
568
  ### extend(extension)
535
569
 
536
- - Locale extension.
537
- - @param {**Object**} extension - locale definition
538
- - @returns {**void**}
570
+ - @param {**Object**} extension - extension object
571
+ - @returns {**void**}
539
572
 
540
- Extend a current locale. See [EXTEND.md](./EXTEND.md) for details.
573
+ It extends this library. See [EXTEND.md](./EXTEND.md) for details.
541
574
 
542
- ### plugin(name[, extension])
575
+ ### plugin(name[, plugin])
543
576
 
544
- - Plugin import or definition.
545
- - @param {**string**} name - plugin name
546
- - @param {**Object**} [extension] - locale definition
547
- - @returns {**void**}
577
+ - @param {**Function|string**} name - plugin installer | plugin name
578
+ - @param {**Object**} [plugin] - plugin object
579
+ - @returns {**void**}
548
580
 
549
- Plugin is a named locale definition defined with the `extend()`. See [PLUGINS.md](./PLUGINS.md) for details.
581
+ Plugin is a named extension object. By installing predefined plugins, you can easily extend this library. See [PLUGINS.md](./PLUGINS.md) for details.
550
582
 
551
583
  ## Browser Support
552
584