date-and-time 2.1.2 → 2.3.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.
Files changed (54) hide show
  1. package/PLUGINS.md +42 -26
  2. package/README.md +88 -95
  3. package/date-and-time.d.ts +304 -0
  4. package/date-and-time.js +85 -74
  5. package/date-and-time.min.js +11 -10
  6. package/esm/date-and-time.es.js +85 -74
  7. package/esm/date-and-time.es.min.js +10 -10
  8. package/esm/date-and-time.mjs +85 -74
  9. package/esm/plugin/timezone.es.js +8 -6
  10. package/esm/plugin/timezone.mjs +8 -6
  11. package/locale/ar.d.ts +1 -0
  12. package/locale/az.d.ts +1 -0
  13. package/locale/bn.d.ts +1 -0
  14. package/locale/cs.d.ts +1 -0
  15. package/locale/de.d.ts +1 -0
  16. package/locale/dk.d.ts +1 -0
  17. package/locale/el.d.ts +1 -0
  18. package/locale/en.d.ts +1 -0
  19. package/locale/es.d.ts +1 -0
  20. package/locale/fa.d.ts +1 -0
  21. package/locale/fr.d.ts +1 -0
  22. package/locale/hi.d.ts +1 -0
  23. package/locale/hu.d.ts +1 -0
  24. package/locale/id.d.ts +1 -0
  25. package/locale/it.d.ts +1 -0
  26. package/locale/ja.d.ts +1 -0
  27. package/locale/jv.d.ts +1 -0
  28. package/locale/ko.d.ts +1 -0
  29. package/locale/my.d.ts +1 -0
  30. package/locale/nl.d.ts +1 -0
  31. package/locale/pa-in.d.ts +1 -0
  32. package/locale/pl.d.ts +1 -0
  33. package/locale/pt.d.ts +1 -0
  34. package/locale/ro.d.ts +1 -0
  35. package/locale/ru.d.ts +1 -0
  36. package/locale/rw.d.ts +1 -0
  37. package/locale/sr.d.ts +1 -0
  38. package/locale/sv.d.ts +1 -0
  39. package/locale/th.d.ts +1 -0
  40. package/locale/tr.d.ts +1 -0
  41. package/locale/uk.d.ts +1 -0
  42. package/locale/uz.d.ts +1 -0
  43. package/locale/vi.d.ts +1 -0
  44. package/locale/zh-cn.d.ts +1 -0
  45. package/locale/zh-tw.d.ts +1 -0
  46. package/package.json +7 -4
  47. package/plugin/day-of-week.d.ts +1 -0
  48. package/plugin/meridiem.d.ts +1 -0
  49. package/plugin/microsecond.d.ts +1 -0
  50. package/plugin/ordinal.d.ts +1 -0
  51. package/plugin/timespan.d.ts +24 -0
  52. package/plugin/timezone.d.ts +79 -0
  53. package/plugin/timezone.js +8 -6
  54. package/plugin/two-digit-year.d.ts +1 -0
package/PLUGINS.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Plugins
2
2
 
3
- This library is oriented towards minimalism, so it may seem to some developers to be lacking in features. Plugin is the most realistic solution to such dissatisfaction. By importing plugins, you can extend the functionality of this library, mainly a formatter and a parser.
3
+ This library is oriented towards minimalism, so it may seem to some developers to be lacking in features. The plugin is the most realistic solution to such dissatisfaction. By importing plugins, you can extend the functionality of this library, primarily the formatter and parser.
4
4
 
5
5
  *The formatter is used in `format()`, etc., the parser is used in `parse()`, `preparse()`, `isValid()`, etc.*
6
6
 
@@ -76,7 +76,7 @@ date.plugin('foobar');
76
76
  - It adds `timeSpan()` function that calculates the difference of two dates to the library.
77
77
 
78
78
  - [timezone](#timezone)
79
- - It adds `formatTZ()` and `parseTZ()` functions that support `IANA time zone names` to the library.
79
+ - It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zone names` to the library.
80
80
 
81
81
  - [two-digit-year](#two-digit-year)
82
82
  - It adds two-digit year notation to the parser.
@@ -238,9 +238,9 @@ It adds `timeSpan()` function that calculates the difference of two dates to the
238
238
 
239
239
  #### timeSpan(date1, date2)
240
240
 
241
- - @param {**Date**} date1 - a Date object
242
- - @param {**Date**} date2 - a Date object
243
- - @returns {**Object**} a result object subtracting date2 from date1
241
+ - @param {**Date**} date1 - A Date object
242
+ - @param {**Date**} date2 - A Date object
243
+ - @returns {**Object**} The result object of subtracting date2 from date1
244
244
 
245
245
  ```javascript
246
246
  const date = require('date-and-time');
@@ -262,11 +262,11 @@ Like `subtract()`, `timeSpan()` returns an object with functions like this:
262
262
 
263
263
  | function | description |
264
264
  |:---------------|:------------------------|
265
- | toDays | Outputs as dates |
266
- | toHours | Outputs as hours |
267
- | toMinutes | Outputs as minutes |
268
- | toSeconds | Outputs as seconds |
269
- | toMilliseconds | Outputs as milliseconds |
265
+ | toDays | Outputs in dates |
266
+ | toHours | Outputs in hours |
267
+ | toMinutes | Outputs in minutes |
268
+ | toSeconds | Outputs in seconds |
269
+ | toMilliseconds | Outputs in milliseconds |
270
270
 
271
271
  In these functions can be available some tokens to format the calculation result. Here are the tokens and their meanings:
272
272
 
@@ -290,25 +290,35 @@ In these functions can be available some tokens to format the calculation result
290
290
 
291
291
  ### timezone
292
292
 
293
- It adds `formatTZ()` and `parseTZ()` functions that support `IANA time zone names` (`America/Los_Angeles`, `Asia/Tokyo`, and so on) to the library.
293
+ It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zone names` (`America/Los_Angeles`, `Asia/Tokyo`, and so on) to the library.
294
294
 
295
295
  #### formatTZ(dateObj, arg[, timeZone])
296
296
 
297
- - @param {**Date**} dateObj - a Date object
298
- - @param {**string|Array.\<string\>**} arg - a format string or its compiled object
299
- - @param {**string**} [timeZone] - output as this time zone
300
- - @returns {**string**} a formatted string
297
+ - @param {**Date**} dateObj - A Date object
298
+ - @param {**string|Array.\<string\>**} arg - A format string or its compiled object
299
+ - @param {**string**} [timeZone] - Output as this time zone
300
+ - @returns {**string**} A formatted string
301
301
 
302
- The `formatTZ()` is upward compatible with `format()`. Tokens available here are the same as for the `format()`. If the `timeZone` is omitted, it output the date string with local time zone.
302
+ `formatTZ()` is upward compatible with `format()`. Tokens available for `arg` are the same as those for `format()`. If `timeZone` is omitted, this function assumes `timeZone` to be a local time zone and outputs a string. This means that the result is the same as when `format()` is used.
303
303
 
304
304
  #### parseTZ(dateString, arg[, timeZone])
305
305
 
306
- - @param {**string**} dateString - a date string
307
- - @param {**string|Array.\<string\>**} arg - a format string or its compiled object
308
- - @param {**string**} [timeZone] - input as this time zone
309
- - @returns {**Date**} a constructed date
306
+ - @param {**string**} dateString - A date and time string
307
+ - @param {**string|Array.\<string\>**} arg - A format string or its compiled object
308
+ - @param {**string**} [timeZone] - Input as this time zone
309
+ - @returns {**Date**} A Date object
310
310
 
311
- The `parseTZ()` is upward compatible with `parse()`. Tokens available here are the same as for the `parse()`. If the `timeZone` is omitted, the time zone of the date string is assumed to be local time zone.
311
+ `parseTZ()` is upward compatible with `parse()`. Tokens available for `arg` are the same as those for `parse()`. `timeZone` in this function is used as supplemental information. if `dateString` contains a time zone offset value (i.e. -0800, +0900), `timeZone` is not be used. If `dateString` doesn't contain a time zone offset value and `timeZone` is omitted, this function assumes `timeZone` to be a local time zone. This means that the result is the same as when `parse()` is used.
312
+
313
+ #### transformTZ(dateString, arg1, arg2[, timeZone])
314
+
315
+ - @param {**string**} dateString - A date and time string
316
+ - @param {**string|Array.\<string\>**} arg1 - A format string before transformation or its compiled object
317
+ - @param {**string|Array.\<string\>**} arg2 - A format string after transformation or its compiled object
318
+ - @param {**string**} [timeZone] - Output as this time zone
319
+ - @returns {**string**} A formatted string
320
+
321
+ `transformTZ()` is upward compatible with `transform()`. `dateString` must itself contain a time zone offset value (i.e. -0800, +0900), otherwise this function assumes it is a local time zone. Tokens available for `arg1` are the same as those for `parse()`, also tokens available for `arg2` are the same as those for `format()`. `timeZone` is a `IANA time zone names`, which is required to output a new formatted string. If it is omitted, this function assumes `timeZone` to be a local time zone. This means that the result is the same as when `transform()` is used.
312
322
 
313
323
  ```javascript
314
324
  const date = require('date-and-time');
@@ -329,16 +339,22 @@ date.parseTZ('Sep 25 2021 4:00:00', 'MMM D YYYY H:mm:ss', 'Pacific/Honolulu');
329
339
 
330
340
  // Parses the date string assuming that the time zone is "Europe/London" (UTC+0100).
331
341
  date.parseTZ('Sep 25 2021 4:00:00', 'MMM D YYYY H:mm:ss', 'Europe/London'); // 2021-09-25T03:00:00.000Z
342
+
343
+ // Transforms the date string from EST (Eastern Standard Time) to PDT (Pacific Daylight Time).
344
+ date.transformTZ('2021-11-07T03:59:59 UTC-0500', 'YYYY-MM-DD[T]HH:mm:ss [UTC]Z', 'MMMM D YYYY H:mm:ss UTC[Z]', 'America/Los_Angeles'); // November 7 2021 1:59:59 UTC-0700
345
+
346
+ // Transforms the date string from PDT(Pacific Daylight Time) to JST (Japan Standard Time).
347
+ date.transformTZ('2021-03-14T03:00:00 UTC-0700', 'YYYY-MM-DD[T]HH:mm:ss [UTC]Z', 'MMMM D YYYY H:mm:ss UTC[Z]', 'Asia/Tokyo'); // March 14 2021 19:00:00 UTC+0900
332
348
  ```
333
349
 
334
350
  #### Caveats
335
351
 
336
352
  - This plugin uses the [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) object to parse `IANA time zone names`. Note that if you use this plugin in older browsers, this may **NOT** be supported there. At least it does not work in IE.
337
- - If you don't need to use `IANA time zone names`, you should not use this plugin for performance reasons. The `format()` and the `parse()` are enough.
353
+ - If you don't need to use `IANA time zone names`, you should not use this plugin for performance reasons. Recommended to use `format()` and `parse()`.
338
354
 
339
355
  #### Start of DST (Daylight Saving Time)
340
356
 
341
- For example, in the US, when local standard time is about to reach Sunday, 14 March 2021, `02:00:00` clocks are turned `forward` 1 hour to Sunday, 14 March 2021, `03:00:00` local daylight time instead. Thus, there is no `02:00:00` to `02:59:59` on 14 March 2021. In such edge cases, the `parseTZ()` will parse like this:
357
+ For example, in the US, when local standard time is about to reach Sunday, 14 March 2021, `02:00:00` clocks are turned `forward` 1 hour to Sunday, 14 March 2021, `03:00:00` local daylight time instead. Thus there is no `02:00:00` to `02:59:59` on 14 March 2021. In such edge cases, `parseTZ()` will parse like this:
342
358
 
343
359
  ```javascript
344
360
  date.parseTZ('Mar 14 2021 1:59:59', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => 2021-03-14T09:59:59Z
@@ -349,16 +365,16 @@ date.parseTZ('Mar 14 2021 3:00:00', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles')
349
365
 
350
366
  #### End of DST
351
367
 
352
- Also, when local daylight time is about to reach Sunday, 7 November 2021, `02:00:00` clocks are turned `backward` 1 hour to Sunday, 7 November 2021, `01:00:00` local standard time instead. Thus, `01:00:00` to `01:59:59` on November 7 2021 is repeated twice. Since there are two possible times between them, DST or not, the `parseTZ()` assumes that the time is former to make the result unique:
368
+ Also, when local daylight time is about to reach Sunday, 7 November 2021, `02:00:00` clocks are turned `backward` 1 hour to Sunday, 7 November 2021, `01:00:00` local standard time instead. Thus `01:00:00` to `01:59:59` on November 7 2021 is repeated twice. Since there are two possible times here, `parseTZ()` assumes that the time is the former (DST) in order to make the result unique:
353
369
 
354
370
  ```javascript
355
- // The parseTZ() assumes that this time is DST.
371
+ // This time is DST or PST? The parseTZ() always assumes that it is DST.
356
372
  date.parseTZ('Nov 7 2021 1:59:59', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => 2021-11-07T08:59:59Z
357
373
  // This time is already PST.
358
374
  date.parseTZ('Nov 7 2021 2:00:00', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => 2021-11-07T10:00:00Z
359
375
  ```
360
376
 
361
- At the first example above, if you want the parser to parse the time as PST (Pacific Standard Time), use the `parse()` with a time offset instead:
377
+ In the first example above, if you want `parseTZ()` to parse the time as PST, you need to pass a date string containing the time zone offset value. In this case, it is better to use `parse()` instead:
362
378
 
363
379
  ```javascript
364
380
  date.parse('Nov 7 2021 1:59:59 -0800', 'MMM D YYYY H:mm:ss Z'); // => 2021-11-07T09:59:59Z
package/README.md CHANGED
@@ -24,25 +24,16 @@ npm i date-and-time
24
24
 
25
25
  ## Recent Changes
26
26
 
27
- - 2.1.2
28
- - Fixed an issue that the lib's validation logic would condider an error when a timezone offset value of a datetime string was greater then +12 hours.
27
+ - 2.3.0
28
+ - TypeScript support.
29
+ - Fixed an issue where `parseTZ()` in timezone plugin could return `NaN` instead of `Invalid Date` if parsing failed.
29
30
 
30
- - 2.1.1
31
- - Updated dev dependencies to resolve vulnerability.
31
+ - 2.2.1
32
+ - Fixed an issue where `parse()` would treat a date and time string containing a UTC time zone (i.e. +0000) as a local time zone when parsing.
32
33
 
33
- - 2.1.0
34
- - Fixed an issue that the lib's functions assigned to variables using ES6 destructuring assignment cause an error.
35
-
36
- ```javascript
37
- // Destructuring assignment
38
- const { format, parse } = require('date-and-time');
39
-
40
- // These used to be errors in 2.0.x.
41
- format(new Date(), 'MMM DD YYYY');
42
- parse('Jan 11 2022', 'MMM DD YYYY');
43
- ```
44
-
45
- - Added Swedish support.
34
+ - 2.2.0
35
+ - Added `tranformTZ()` to `timezone` plugin. See [PLUGINS.md](./PLUGINS.md) for details.
36
+ - Added `ZZ` token to support time zone values with colon like `-08:00` `+09:00` to `format()` and `parse()`.
46
37
 
47
38
  ## Usage
48
39
 
@@ -69,32 +60,34 @@ import date from '/path/to/date-and-time.es.min.js';
69
60
  - Older browser:
70
61
 
71
62
  ```html
72
- <script src="/path/to/date-and-time.min.js"></script>
63
+ <script src="/path/to/date-and-time.min.js">
64
+ // You will be able to access the global variable `date`.
65
+ </script>
73
66
  ```
74
67
 
75
68
  ### Note
76
69
 
77
- - 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`.
70
+ - If you want to use ES Modules in Node.js without the transpiler, you need to add `"type": "module"` in your `package.json` or change your file extension from `.js` to `.mjs`.
78
71
 
79
72
  ## API
80
73
 
81
74
  - [format](#formatdateobj-arg-utc)
82
- - Formatting a Date and Time (Date -> String)
75
+ - Formatting date and time objects (Date -> String)
83
76
 
84
77
  - [parse](#parsedatestring-arg-utc)
85
- - Parsing a Date and Time string (String -> Date)
78
+ - Parsing date and time strings (String -> Date)
86
79
 
87
80
  - [compile](#compileformatstring)
88
- - Compiling a format string
81
+ - Compiling format strings
89
82
 
90
83
  - [preparse](#preparsedatestring-arg)
91
- - Pre-parsing a Date and Time string
84
+ - Pre-parsing date and time strings
92
85
 
93
86
  - [isValid](#isvalidarg1-arg2)
94
- - Validation
87
+ - Date and time string validation
95
88
 
96
89
  - [transform](#transformdatestring-arg1-arg2-utc)
97
- - Transforming a Date and Time string (String -> String)
90
+ - Format transformation of date and time strings (String -> String)
98
91
 
99
92
  - [addYears](#addyearsdateobj-years)
100
93
  - Adding years
@@ -118,29 +111,29 @@ import date from '/path/to/date-and-time.es.min.js';
118
111
  - Adding milliseconds
119
112
 
120
113
  - [subtract](#subtractdate1-date2)
121
- - Subtracting two dates
114
+ - Subtracting two dates (date1 - date2)
122
115
 
123
116
  - [isLeapYear](#isleapyeary)
124
- - Whether year is leap year
117
+ - Whether a year is a leap year
125
118
 
126
119
  - [isSameDay](#issamedaydate1-date2)
127
120
  - Comparison of two dates
128
121
 
129
- - [locale](#localecode-locale)
130
- - Changing the locale or defining new locales
122
+ - [locale](#localelocale)
123
+ - Changing locales
131
124
 
132
125
  - [extend](#extendextension)
133
- - Feature extension
126
+ - Functional extension
134
127
 
135
- - [plugin](#pluginname-plugin)
136
- - Importing or defining plugins
128
+ - [plugin](#pluginplugin)
129
+ - Importing plugins
137
130
 
138
131
  ### format(dateObj, arg[, utc])
139
132
 
140
- - @param {**Date**} dateObj - a Date object
141
- - @param {**string|Array.\<string\>**} arg - a format string or its compiled object
142
- - @param {**boolean**} [utc] - output as UTC
143
- - @returns {**string**} a formatted string
133
+ - @param {**Date**} dateObj - A Date object
134
+ - @param {**string|Array.\<string\>**} arg - A format string or its compiled object
135
+ - @param {**boolean**} [utc] - Output as UTC
136
+ - @returns {**string**} A formatted string
144
137
 
145
138
  ```javascript
146
139
  const now = new Date();
@@ -181,7 +174,8 @@ Available tokens and their meanings are as follows:
181
174
  | SSS | millisecond (high accuracy) | 753, 022 |
182
175
  | SS | millisecond (middle accuracy) | 75, 02 |
183
176
  | S | millisecond (low accuracy) | 7, 0 |
184
- | Z | timezone offset | +0100, -0800 |
177
+ | Z | time zone offset value | +0100, -0800 |
178
+ | ZZ | time zone offset value with colon | +01:00, -08:00 |
185
179
 
186
180
  You can also use the following tokens by importing plugins. See [PLUGINS.md](./PLUGINS.md) for details.
187
181
 
@@ -203,7 +197,7 @@ date.format(new Date(), '[DD-[MM]-YYYY]'); // => 'DD-[MM]-YYYY'
203
197
 
204
198
  #### Note 2. Output as UTC
205
199
 
206
- 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.
200
+ This function usually outputs a local date and time string. Set to true the `utc` option (the 3rd parameter) if you would like to get a UTC date and time string.
207
201
 
208
202
  ```javascript
209
203
  date.format(new Date(), 'hh:mm A [GMT]Z'); // => '11:14 PM GMT-0800'
@@ -216,10 +210,10 @@ You can also define your own tokens. See [EXTEND.md](./EXTEND.md) for details.
216
210
 
217
211
  ### parse(dateString, arg[, utc])
218
212
 
219
- - @param {**string**} dateString - a date string
220
- - @param {**string|Array.\<string\>**} arg - a format string or its compiled object
221
- - @param {**boolean**} [utc] - input as UTC
222
- - @returns {**Date**} a constructed date
213
+ - @param {**string**} dateString - A date and time string
214
+ - @param {**string|Array.\<string\>**} arg - A format string or its compiled object
215
+ - @param {**boolean**} [utc] - Input as UTC
216
+ - @returns {**Date**} A Date object
223
217
 
224
218
  ```javascript
225
219
  date.parse('2015/01/02 23:14:05', 'YYYY/MM/DD HH:mm:ss'); // => Jan 2 2015 23:14:05 GMT-0800
@@ -255,7 +249,8 @@ Available tokens and their meanings are as follows:
255
249
  | SSS | millisecond (high accuracy) | 753, 022 |
256
250
  | SS | millisecond (middle accuracy) | 75, 02 |
257
251
  | S | millisecond (low accuracy) | 7, 0 |
258
- | Z | timezone offset | +0100, -0800 |
252
+ | Z | time zone offset value | +0100, -0800 |
253
+ | ZZ | time zone offset value with colon | +01:00, -08:00 |
259
254
 
260
255
  You can also use the following tokens by importing plugins. See [PLUGINS.md](./PLUGINS.md) for details.
261
256
 
@@ -286,7 +281,7 @@ if (isNaN(today)) {
286
281
 
287
282
  #### Note 2. Input as UTC
288
283
 
289
- 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.
284
+ This function assumes the `dateString` is a local datea and time unless it contains a time zone offset value. Set to true the `utc` option (the 3rd parameter) if it is a UTC date and time.
290
285
 
291
286
  ```javascript
292
287
  date.parse('11:14:05 PM', 'hh:mm:ss A'); // => Jan 1 1970 23:14:05 GMT-0800
@@ -325,7 +320,7 @@ date.parse('11:14:05 PM', 'hh:mm:ss A'); // => Jan 1 1970 23:14:05 GMT-0800
325
320
 
326
321
  #### Note 6. Token disablement
327
322
 
328
- 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:
323
+ Use square brackets `[]` if a datea and time string includes some token characters. Tokens inside square brackets in the `formatString` will be interpreted as normal characters:
329
324
 
330
325
  ```javascript
331
326
  date.parse('12 hours 34 minutes', 'HH hours mm minutes'); // => Invalid Date
@@ -353,8 +348,8 @@ date.parse('2015/01/02 11:14:05', 'YYYY/MM/DD...'); // => Jan 2 2015 00:00:00
353
348
 
354
349
  ### compile(formatString)
355
350
 
356
- - @param {**string**} formatString - a format string
357
- - @returns {**Array.\<string\>**} a compiled object
351
+ - @param {**string**} formatString - A format string
352
+ - @returns {**Array.\<string\>**} A compiled object
358
353
 
359
354
  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.
360
355
 
@@ -370,9 +365,9 @@ If you are going to execute the `format()`, the `parse()` or the `isValid()` so
370
365
 
371
366
  ### preparse(dateString, arg)
372
367
 
373
- - @param {**string**} dateString - a date string
374
- - @param {**string|Array.\<string\>**} arg - a format string or its compiled object
375
- - @returns {**Object**} a date structure
368
+ - @param {**string**} dateString - A date and time string
369
+ - @param {**string|Array.\<string\>**} arg - A format string or its compiled object
370
+ - @returns {**Object**} A pre-parsed result object
376
371
 
377
372
  This function takes exactly the same parameters with the `parse()`, but returns a date structure as follows unlike that:
378
373
 
@@ -400,9 +395,9 @@ This date structure provides a parsing result. You will be able to tell from it
400
395
 
401
396
  ### isValid(arg1[, arg2])
402
397
 
403
- - @param {**Object|string**} arg1 - a date structure or a date string
404
- - @param {**string|Array.\<string\>**} [arg2] - a format string or its compiled object
405
- - @returns {**boolean**} whether the date string is a valid date
398
+ - @param {**Object|string**} arg1 - A pre-parsed result object or a date and time string
399
+ - @param {**string|Array.\<string\>**} [arg2] - A format string or its compiled object
400
+ - @returns {**boolean**} Whether the date and time string is a valid date and time
406
401
 
407
402
  This function takes either exactly the same parameters with the `parse()` or a date structure which the `preparse()` returns, evaluates the validity of them.
408
403
 
@@ -418,11 +413,11 @@ date.isValid(result); // => true
418
413
 
419
414
  ### transform(dateString, arg1, arg2[, utc])
420
415
 
421
- - @param {**string**} dateString - a date string
422
- - @param {**string|Array.\<string\>**} arg1 - a format string or its compiled object
423
- - @param {**string|Array.\<string\>**} arg2 - a transformed format string or its compiled object
424
- - @param {**boolean**} [utc] - output as UTC
425
- - @returns {**string**} a formatted string
416
+ - @param {**string**} dateString - A date and time string
417
+ - @param {**string|Array.\<string\>**} arg1 - A format string or its compiled object before transformation
418
+ - @param {**string|Array.\<string\>**} arg2 - A format string or its compiled object after transformation
419
+ - @param {**boolean**} [utc] - Output as UTC
420
+ - @returns {**string**} A formatted string
426
421
 
427
422
  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.
428
423
 
@@ -436,9 +431,9 @@ date.transform('13:05', 'HH:mm', 'hh:mm A');
436
431
 
437
432
  ### addYears(dateObj, years)
438
433
 
439
- - @param {**Date**} dateObj - a Date object
440
- - @param {**number**} years - number of years to add
441
- - @returns {**Date**} a date after adding the value
434
+ - @param {**Date**} dateObj - A Date object
435
+ - @param {**number**} years - Number of years to add
436
+ - @returns {**Date**} The Date object after adding the value
442
437
 
443
438
  ```javascript
444
439
  const now = new Date();
@@ -447,9 +442,9 @@ const next_year = date.addYears(now, 1);
447
442
 
448
443
  ### addMonths(dateObj, months)
449
444
 
450
- - @param {**Date**} dateObj - a Date object
451
- - @param {**number**} months - number of months to add
452
- - @returns {**Date**} a date after adding the value
445
+ - @param {**Date**} dateObj - A Date object
446
+ - @param {**number**} months - Number of months to add
447
+ - @returns {**Date**} The Date object after adding the value
453
448
 
454
449
  ```javascript
455
450
  const now = new Date();
@@ -458,9 +453,9 @@ const next_month = date.addMonths(now, 1);
458
453
 
459
454
  ### addDays(dateObj, days)
460
455
 
461
- - @param {**Date**} dateObj - a Date object
462
- - @param {**number**} days - number of days to add
463
- - @returns {**Date**} a date after adding the value
456
+ - @param {**Date**} dateObj - A Date object
457
+ - @param {**number**} days - Number of days to add
458
+ - @returns {**Date**} The Date object after adding the value
464
459
 
465
460
  ```javascript
466
461
  const now = new Date();
@@ -469,9 +464,9 @@ const yesterday = date.addDays(now, -1);
469
464
 
470
465
  ### addHours(dateObj, hours)
471
466
 
472
- - @param {**Date**} dateObj - a Date object
473
- - @param {**number**} hours - number of hours to add
474
- - @returns {**Date**} a date after adding the value
467
+ - @param {**Date**} dateObj - A Date object
468
+ - @param {**number**} hours - Number of hours to add
469
+ - @returns {**Date**} The Date object after adding the value
475
470
 
476
471
  ```javascript
477
472
  const now = new Date();
@@ -480,9 +475,9 @@ const an_hour_ago = date.addHours(now, -1);
480
475
 
481
476
  ### addMinutes(dateObj, minutes)
482
477
 
483
- - @param {**Date**} dateObj - a Date object
484
- - @param {**number**} minutes - number of minutes to add
485
- - @returns {**Date**} a date after adding the value
478
+ - @param {**Date**} dateObj - A Date object
479
+ - @param {**number**} minutes - Number of minutes to add
480
+ - @returns {**Date**} The Date object after adding the value
486
481
 
487
482
  ```javascript
488
483
  const now = new Date();
@@ -491,9 +486,9 @@ const two_minutes_later = date.addMinutes(now, 2);
491
486
 
492
487
  ### addSeconds(dateObj, seconds)
493
488
 
494
- - @param {**Date**} dateObj - a Date object
495
- - @param {**number**} seconds - number of seconds to add
496
- - @returns {**Date**} a date after adding the value
489
+ - @param {**Date**} dateObj - A Date object
490
+ - @param {**number**} seconds - Number of seconds to add
491
+ - @returns {**Date**} The Date object after adding the value
497
492
 
498
493
  ```javascript
499
494
  const now = new Date();
@@ -502,9 +497,9 @@ const three_seconds_ago = date.addSeconds(now, -3);
502
497
 
503
498
  ### addMilliseconds(dateObj, milliseconds)
504
499
 
505
- - @param {**Date**} dateObj - a Date object
506
- - @param {**number**} milliseconds - number of milliseconds to add
507
- - @returns {**Date**} a date after adding the value
500
+ - @param {**Date**} dateObj - A Date object
501
+ - @param {**number**} milliseconds - Number of milliseconds to add
502
+ - @returns {**Date**} The Date object after adding the value
508
503
 
509
504
  ```javascript
510
505
  const now = new Date();
@@ -513,9 +508,9 @@ const a_millisecond_later = date.addMilliseconds(now, 1);
513
508
 
514
509
  ### subtract(date1, date2)
515
510
 
516
- - @param {**Date**} date1 - a Date object
517
- - @param {**Date**} date2 - a Date object
518
- - @returns {**Object**} a result object subtracting date2 from date1
511
+ - @param {**Date**} date1 - A Date object
512
+ - @param {**Date**} date2 - A Date object
513
+ - @returns {**Object**} The result object of subtracting date2 from date1
519
514
 
520
515
  ```javascript
521
516
  const today = new Date(2015, 0, 2);
@@ -530,8 +525,8 @@ date.subtract(today, yesterday).toMilliseconds(); // => 86400000
530
525
 
531
526
  ### isLeapYear(y)
532
527
 
533
- - @param {**number**} y - year
534
- - @returns {**boolean**} whether year is leap year
528
+ - @param {**number**} y - A year to check
529
+ - @returns {**boolean**} Whether the year is a leap year
535
530
 
536
531
  ```javascript
537
532
  date.isLeapYear(2015); // => false
@@ -540,9 +535,9 @@ date.isLeapYear(2012); // => true
540
535
 
541
536
  ### isSameDay(date1, date2)
542
537
 
543
- - @param {**Date**} date1 - a Date object
544
- - @param {**Date**} date2 - a Date object
545
- - @returns {**boolean**} whether the two dates are the same day (time is ignored)
538
+ - @param {**Date**} date1 - A Date object
539
+ - @param {**Date**} date2 - A Date object
540
+ - @returns {**boolean**} Whether the two dates are the same day (time is ignored)
546
541
 
547
542
  ```javascript
548
543
  const date1 = new Date(2017, 0, 2, 0); // Jan 2 2017 00:00:00
@@ -552,11 +547,10 @@ date.isSameDay(date1, date2); // => true
552
547
  date.isSameDay(date1, date3); // => false
553
548
  ```
554
549
 
555
- ### locale([code[, locale]])
550
+ ### locale([locale])
556
551
 
557
- - @param {**Function|string**} [code] - locale installer | language code
558
- - @param {**Object**} [locale] - locale definition
559
- - @returns {**string**} current language code
552
+ - @param {**Function|string**} [locale] - A locale installer or language code
553
+ - @returns {**string**} The current language code
560
554
 
561
555
  It returns the current language code if called without any parameters.
562
556
 
@@ -576,15 +570,14 @@ See [LOCALE.md](./LOCALE.md) for details.
576
570
 
577
571
  ### extend(extension)
578
572
 
579
- - @param {**Object**} extension - extension object
573
+ - @param {**Object**} extension - An extension object
580
574
  - @returns {**void**}
581
575
 
582
576
  It extends this library. See [EXTEND.md](./EXTEND.md) for details.
583
577
 
584
- ### plugin(name[, plugin])
578
+ ### plugin(plugin)
585
579
 
586
- - @param {**Function|string**} name - plugin installer | plugin name
587
- - @param {**Object**} [plugin] - plugin object
580
+ - @param {**Function|string**} plugin - A plugin installer or plugin name
588
581
  - @returns {**void**}
589
582
 
590
583
  Plugin is a named extension object. By installing predefined plugins, you can easily extend this library. See [PLUGINS.md](./PLUGINS.md) for details.