date-and-time 2.2.0 → 2.3.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.
- package/PLUGINS.md +22 -22
- package/README.md +87 -83
- package/date-and-time.d.ts +304 -0
- package/date-and-time.js +76 -74
- package/date-and-time.min.js +8 -8
- package/esm/date-and-time.es.js +76 -74
- package/esm/date-and-time.es.min.js +7 -7
- package/esm/date-and-time.mjs +76 -74
- package/esm/plugin/timezone.es.js +3 -5
- package/esm/plugin/timezone.mjs +3 -5
- package/locale/ar.d.ts +1 -0
- package/locale/az.d.ts +1 -0
- package/locale/bn.d.ts +1 -0
- package/locale/cs.d.ts +1 -0
- package/locale/de.d.ts +1 -0
- package/locale/dk.d.ts +1 -0
- package/locale/el.d.ts +1 -0
- package/locale/en.d.ts +1 -0
- package/locale/es.d.ts +1 -0
- package/locale/fa.d.ts +1 -0
- package/locale/fr.d.ts +1 -0
- package/locale/hi.d.ts +1 -0
- package/locale/hu.d.ts +1 -0
- package/locale/id.d.ts +1 -0
- package/locale/it.d.ts +1 -0
- package/locale/ja.d.ts +1 -0
- package/locale/jv.d.ts +1 -0
- package/locale/ko.d.ts +1 -0
- package/locale/my.d.ts +1 -0
- package/locale/nl.d.ts +1 -0
- package/locale/pa-in.d.ts +1 -0
- package/locale/pl.d.ts +1 -0
- package/locale/pt.d.ts +1 -0
- package/locale/ro.d.ts +1 -0
- package/locale/ru.d.ts +1 -0
- package/locale/rw.d.ts +1 -0
- package/locale/sr.d.ts +1 -0
- package/locale/sv.d.ts +1 -0
- package/locale/th.d.ts +1 -0
- package/locale/tr.d.ts +1 -0
- package/locale/uk.d.ts +1 -0
- package/locale/uz.d.ts +1 -0
- package/locale/vi.d.ts +1 -0
- package/locale/zh-cn.d.ts +1 -0
- package/locale/zh-tw.d.ts +1 -0
- package/package.json +7 -4
- package/plugin/day-of-week.d.ts +1 -0
- package/plugin/meridiem.d.ts +1 -0
- package/plugin/microsecond.d.ts +1 -0
- package/plugin/ordinal.d.ts +1 -0
- package/plugin/timespan.d.ts +24 -0
- package/plugin/timezone.d.ts +79 -0
- package/plugin/timezone.js +3 -5
- 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.
|
|
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
|
|
|
@@ -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 -
|
|
242
|
-
- @param {**Date**} date2 -
|
|
243
|
-
- @returns {**Object**}
|
|
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
|
|
266
|
-
| toHours | Outputs
|
|
267
|
-
| toMinutes | Outputs
|
|
268
|
-
| toSeconds | Outputs
|
|
269
|
-
| toMilliseconds | Outputs
|
|
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
|
|
|
@@ -294,29 +294,29 @@ It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zo
|
|
|
294
294
|
|
|
295
295
|
#### formatTZ(dateObj, arg[, timeZone])
|
|
296
296
|
|
|
297
|
-
- @param {**Date**} dateObj -
|
|
298
|
-
- @param {**string|Array.\<string\>**} arg -
|
|
299
|
-
- @param {**string**} [timeZone] -
|
|
300
|
-
- @returns {**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
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 -
|
|
307
|
-
- @param {**string|Array.\<string\>**} arg -
|
|
308
|
-
- @param {**string**} [timeZone] -
|
|
309
|
-
- @returns {**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
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
312
|
|
|
313
313
|
#### transformTZ(dateString, arg1, arg2[, timeZone])
|
|
314
314
|
|
|
315
|
-
- @param {**string**} dateString -
|
|
316
|
-
- @param {**string|Array.\<string\>**} arg1 -
|
|
317
|
-
- @param {**string|Array.\<string\>**} arg2 -
|
|
318
|
-
- @param {**string**} [timeZone] -
|
|
319
|
-
- @returns {**string**}
|
|
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
320
|
|
|
321
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.
|
|
322
322
|
|
package/README.md
CHANGED
|
@@ -24,15 +24,19 @@ npm i date-and-time
|
|
|
24
24
|
|
|
25
25
|
## Recent Changes
|
|
26
26
|
|
|
27
|
-
- 2.
|
|
28
|
-
-
|
|
29
|
-
|
|
27
|
+
- 2.3.1
|
|
28
|
+
- Updated dev dependencies to resolve vulnerabilities.
|
|
29
|
+
|
|
30
|
+
- 2.3.0
|
|
31
|
+
- TypeScript support.
|
|
32
|
+
- Fixed an issue where `parseTZ()` in timezone plugin could return `NaN` instead of `Invalid Date` if parsing failed.
|
|
30
33
|
|
|
31
|
-
- 2.1
|
|
32
|
-
- Fixed an issue
|
|
34
|
+
- 2.2.1
|
|
35
|
+
- 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.
|
|
33
36
|
|
|
34
|
-
- 2.
|
|
35
|
-
-
|
|
37
|
+
- 2.2.0
|
|
38
|
+
- Added `tranformTZ()` to `timezone` plugin. See [PLUGINS.md](./PLUGINS.md) for details.
|
|
39
|
+
- Added `ZZ` token to support time zone values with colon like `-08:00` `+09:00` to `format()` and `parse()`.
|
|
36
40
|
|
|
37
41
|
## Usage
|
|
38
42
|
|
|
@@ -59,32 +63,34 @@ import date from '/path/to/date-and-time.es.min.js';
|
|
|
59
63
|
- Older browser:
|
|
60
64
|
|
|
61
65
|
```html
|
|
62
|
-
<script src="/path/to/date-and-time.min.js"
|
|
66
|
+
<script src="/path/to/date-and-time.min.js">
|
|
67
|
+
// You will be able to access the global variable `date`.
|
|
68
|
+
</script>
|
|
63
69
|
```
|
|
64
70
|
|
|
65
71
|
### Note
|
|
66
72
|
|
|
67
|
-
- If you want to use ES Modules in Node.js without
|
|
73
|
+
- 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`.
|
|
68
74
|
|
|
69
75
|
## API
|
|
70
76
|
|
|
71
77
|
- [format](#formatdateobj-arg-utc)
|
|
72
|
-
- Formatting
|
|
78
|
+
- Formatting date and time objects (Date -> String)
|
|
73
79
|
|
|
74
80
|
- [parse](#parsedatestring-arg-utc)
|
|
75
|
-
- Parsing
|
|
81
|
+
- Parsing date and time strings (String -> Date)
|
|
76
82
|
|
|
77
83
|
- [compile](#compileformatstring)
|
|
78
|
-
- Compiling
|
|
84
|
+
- Compiling format strings
|
|
79
85
|
|
|
80
86
|
- [preparse](#preparsedatestring-arg)
|
|
81
|
-
- Pre-parsing
|
|
87
|
+
- Pre-parsing date and time strings
|
|
82
88
|
|
|
83
89
|
- [isValid](#isvalidarg1-arg2)
|
|
84
|
-
-
|
|
90
|
+
- Date and time string validation
|
|
85
91
|
|
|
86
92
|
- [transform](#transformdatestring-arg1-arg2-utc)
|
|
87
|
-
-
|
|
93
|
+
- Format transformation of date and time strings (String -> String)
|
|
88
94
|
|
|
89
95
|
- [addYears](#addyearsdateobj-years)
|
|
90
96
|
- Adding years
|
|
@@ -108,29 +114,29 @@ import date from '/path/to/date-and-time.es.min.js';
|
|
|
108
114
|
- Adding milliseconds
|
|
109
115
|
|
|
110
116
|
- [subtract](#subtractdate1-date2)
|
|
111
|
-
- Subtracting two dates
|
|
117
|
+
- Subtracting two dates (date1 - date2)
|
|
112
118
|
|
|
113
119
|
- [isLeapYear](#isleapyeary)
|
|
114
|
-
- Whether year is leap year
|
|
120
|
+
- Whether a year is a leap year
|
|
115
121
|
|
|
116
122
|
- [isSameDay](#issamedaydate1-date2)
|
|
117
123
|
- Comparison of two dates
|
|
118
124
|
|
|
119
|
-
- [locale](#
|
|
120
|
-
- Changing
|
|
125
|
+
- [locale](#localelocale)
|
|
126
|
+
- Changing locales
|
|
121
127
|
|
|
122
128
|
- [extend](#extendextension)
|
|
123
|
-
-
|
|
129
|
+
- Functional extension
|
|
124
130
|
|
|
125
|
-
- [plugin](#
|
|
126
|
-
- Importing
|
|
131
|
+
- [plugin](#pluginplugin)
|
|
132
|
+
- Importing plugins
|
|
127
133
|
|
|
128
134
|
### format(dateObj, arg[, utc])
|
|
129
135
|
|
|
130
|
-
- @param {**Date**} dateObj -
|
|
131
|
-
- @param {**string|Array.\<string\>**} arg -
|
|
132
|
-
- @param {**boolean**} [utc] -
|
|
133
|
-
- @returns {**string**}
|
|
136
|
+
- @param {**Date**} dateObj - A Date object
|
|
137
|
+
- @param {**string|Array.\<string\>**} arg - A format string or its compiled object
|
|
138
|
+
- @param {**boolean**} [utc] - Output as UTC
|
|
139
|
+
- @returns {**string**} A formatted string
|
|
134
140
|
|
|
135
141
|
```javascript
|
|
136
142
|
const now = new Date();
|
|
@@ -194,7 +200,7 @@ date.format(new Date(), '[DD-[MM]-YYYY]'); // => 'DD-[MM]-YYYY'
|
|
|
194
200
|
|
|
195
201
|
#### Note 2. Output as UTC
|
|
196
202
|
|
|
197
|
-
This function usually outputs a local date
|
|
203
|
+
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.
|
|
198
204
|
|
|
199
205
|
```javascript
|
|
200
206
|
date.format(new Date(), 'hh:mm A [GMT]Z'); // => '11:14 PM GMT-0800'
|
|
@@ -207,10 +213,10 @@ You can also define your own tokens. See [EXTEND.md](./EXTEND.md) for details.
|
|
|
207
213
|
|
|
208
214
|
### parse(dateString, arg[, utc])
|
|
209
215
|
|
|
210
|
-
- @param {**string**} dateString -
|
|
211
|
-
- @param {**string|Array.\<string\>**} arg -
|
|
212
|
-
- @param {**boolean**} [utc] -
|
|
213
|
-
- @returns {**Date**}
|
|
216
|
+
- @param {**string**} dateString - A date and time string
|
|
217
|
+
- @param {**string|Array.\<string\>**} arg - A format string or its compiled object
|
|
218
|
+
- @param {**boolean**} [utc] - Input as UTC
|
|
219
|
+
- @returns {**Date**} A Date object
|
|
214
220
|
|
|
215
221
|
```javascript
|
|
216
222
|
date.parse('2015/01/02 23:14:05', 'YYYY/MM/DD HH:mm:ss'); // => Jan 2 2015 23:14:05 GMT-0800
|
|
@@ -278,7 +284,7 @@ if (isNaN(today)) {
|
|
|
278
284
|
|
|
279
285
|
#### Note 2. Input as UTC
|
|
280
286
|
|
|
281
|
-
This function assumes the `dateString` is a local
|
|
287
|
+
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.
|
|
282
288
|
|
|
283
289
|
```javascript
|
|
284
290
|
date.parse('11:14:05 PM', 'hh:mm:ss A'); // => Jan 1 1970 23:14:05 GMT-0800
|
|
@@ -317,7 +323,7 @@ date.parse('11:14:05 PM', 'hh:mm:ss A'); // => Jan 1 1970 23:14:05 GMT-0800
|
|
|
317
323
|
|
|
318
324
|
#### Note 6. Token disablement
|
|
319
325
|
|
|
320
|
-
Use square brackets `[]` if a
|
|
326
|
+
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:
|
|
321
327
|
|
|
322
328
|
```javascript
|
|
323
329
|
date.parse('12 hours 34 minutes', 'HH hours mm minutes'); // => Invalid Date
|
|
@@ -345,8 +351,8 @@ date.parse('2015/01/02 11:14:05', 'YYYY/MM/DD...'); // => Jan 2 2015 00:00:00
|
|
|
345
351
|
|
|
346
352
|
### compile(formatString)
|
|
347
353
|
|
|
348
|
-
- @param {**string**} formatString -
|
|
349
|
-
- @returns {**Array.\<string\>**}
|
|
354
|
+
- @param {**string**} formatString - A format string
|
|
355
|
+
- @returns {**Array.\<string\>**} A compiled object
|
|
350
356
|
|
|
351
357
|
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.
|
|
352
358
|
|
|
@@ -362,9 +368,9 @@ If you are going to execute the `format()`, the `parse()` or the `isValid()` so
|
|
|
362
368
|
|
|
363
369
|
### preparse(dateString, arg)
|
|
364
370
|
|
|
365
|
-
- @param {**string**} dateString -
|
|
366
|
-
- @param {**string|Array.\<string\>**} arg -
|
|
367
|
-
- @returns {**Object**}
|
|
371
|
+
- @param {**string**} dateString - A date and time string
|
|
372
|
+
- @param {**string|Array.\<string\>**} arg - A format string or its compiled object
|
|
373
|
+
- @returns {**Object**} A pre-parsed result object
|
|
368
374
|
|
|
369
375
|
This function takes exactly the same parameters with the `parse()`, but returns a date structure as follows unlike that:
|
|
370
376
|
|
|
@@ -392,9 +398,9 @@ This date structure provides a parsing result. You will be able to tell from it
|
|
|
392
398
|
|
|
393
399
|
### isValid(arg1[, arg2])
|
|
394
400
|
|
|
395
|
-
- @param {**Object|string**} arg1 -
|
|
396
|
-
- @param {**string|Array.\<string\>**} [arg2] -
|
|
397
|
-
- @returns {**boolean**}
|
|
401
|
+
- @param {**Object|string**} arg1 - A pre-parsed result object or a date and time string
|
|
402
|
+
- @param {**string|Array.\<string\>**} [arg2] - A format string or its compiled object
|
|
403
|
+
- @returns {**boolean**} Whether the date and time string is a valid date and time
|
|
398
404
|
|
|
399
405
|
This function takes either exactly the same parameters with the `parse()` or a date structure which the `preparse()` returns, evaluates the validity of them.
|
|
400
406
|
|
|
@@ -410,11 +416,11 @@ date.isValid(result); // => true
|
|
|
410
416
|
|
|
411
417
|
### transform(dateString, arg1, arg2[, utc])
|
|
412
418
|
|
|
413
|
-
- @param {**string**} dateString -
|
|
414
|
-
- @param {**string|Array.\<string\>**} arg1 -
|
|
415
|
-
- @param {**string|Array.\<string\>**} arg2 -
|
|
416
|
-
- @param {**boolean**} [utc] -
|
|
417
|
-
- @returns {**string**}
|
|
419
|
+
- @param {**string**} dateString - A date and time string
|
|
420
|
+
- @param {**string|Array.\<string\>**} arg1 - A format string or its compiled object before transformation
|
|
421
|
+
- @param {**string|Array.\<string\>**} arg2 - A format string or its compiled object after transformation
|
|
422
|
+
- @param {**boolean**} [utc] - Output as UTC
|
|
423
|
+
- @returns {**string**} A formatted string
|
|
418
424
|
|
|
419
425
|
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.
|
|
420
426
|
|
|
@@ -428,9 +434,9 @@ date.transform('13:05', 'HH:mm', 'hh:mm A');
|
|
|
428
434
|
|
|
429
435
|
### addYears(dateObj, years)
|
|
430
436
|
|
|
431
|
-
- @param {**Date**} dateObj -
|
|
432
|
-
- @param {**number**} years -
|
|
433
|
-
- @returns {**Date**}
|
|
437
|
+
- @param {**Date**} dateObj - A Date object
|
|
438
|
+
- @param {**number**} years - Number of years to add
|
|
439
|
+
- @returns {**Date**} The Date object after adding the value
|
|
434
440
|
|
|
435
441
|
```javascript
|
|
436
442
|
const now = new Date();
|
|
@@ -439,9 +445,9 @@ const next_year = date.addYears(now, 1);
|
|
|
439
445
|
|
|
440
446
|
### addMonths(dateObj, months)
|
|
441
447
|
|
|
442
|
-
- @param {**Date**} dateObj -
|
|
443
|
-
- @param {**number**} months -
|
|
444
|
-
- @returns {**Date**}
|
|
448
|
+
- @param {**Date**} dateObj - A Date object
|
|
449
|
+
- @param {**number**} months - Number of months to add
|
|
450
|
+
- @returns {**Date**} The Date object after adding the value
|
|
445
451
|
|
|
446
452
|
```javascript
|
|
447
453
|
const now = new Date();
|
|
@@ -450,9 +456,9 @@ const next_month = date.addMonths(now, 1);
|
|
|
450
456
|
|
|
451
457
|
### addDays(dateObj, days)
|
|
452
458
|
|
|
453
|
-
- @param {**Date**} dateObj -
|
|
454
|
-
- @param {**number**} days -
|
|
455
|
-
- @returns {**Date**}
|
|
459
|
+
- @param {**Date**} dateObj - A Date object
|
|
460
|
+
- @param {**number**} days - Number of days to add
|
|
461
|
+
- @returns {**Date**} The Date object after adding the value
|
|
456
462
|
|
|
457
463
|
```javascript
|
|
458
464
|
const now = new Date();
|
|
@@ -461,9 +467,9 @@ const yesterday = date.addDays(now, -1);
|
|
|
461
467
|
|
|
462
468
|
### addHours(dateObj, hours)
|
|
463
469
|
|
|
464
|
-
- @param {**Date**} dateObj -
|
|
465
|
-
- @param {**number**} hours -
|
|
466
|
-
- @returns {**Date**}
|
|
470
|
+
- @param {**Date**} dateObj - A Date object
|
|
471
|
+
- @param {**number**} hours - Number of hours to add
|
|
472
|
+
- @returns {**Date**} The Date object after adding the value
|
|
467
473
|
|
|
468
474
|
```javascript
|
|
469
475
|
const now = new Date();
|
|
@@ -472,9 +478,9 @@ const an_hour_ago = date.addHours(now, -1);
|
|
|
472
478
|
|
|
473
479
|
### addMinutes(dateObj, minutes)
|
|
474
480
|
|
|
475
|
-
- @param {**Date**} dateObj -
|
|
476
|
-
- @param {**number**} minutes -
|
|
477
|
-
- @returns {**Date**}
|
|
481
|
+
- @param {**Date**} dateObj - A Date object
|
|
482
|
+
- @param {**number**} minutes - Number of minutes to add
|
|
483
|
+
- @returns {**Date**} The Date object after adding the value
|
|
478
484
|
|
|
479
485
|
```javascript
|
|
480
486
|
const now = new Date();
|
|
@@ -483,9 +489,9 @@ const two_minutes_later = date.addMinutes(now, 2);
|
|
|
483
489
|
|
|
484
490
|
### addSeconds(dateObj, seconds)
|
|
485
491
|
|
|
486
|
-
- @param {**Date**} dateObj -
|
|
487
|
-
- @param {**number**} seconds -
|
|
488
|
-
- @returns {**Date**}
|
|
492
|
+
- @param {**Date**} dateObj - A Date object
|
|
493
|
+
- @param {**number**} seconds - Number of seconds to add
|
|
494
|
+
- @returns {**Date**} The Date object after adding the value
|
|
489
495
|
|
|
490
496
|
```javascript
|
|
491
497
|
const now = new Date();
|
|
@@ -494,9 +500,9 @@ const three_seconds_ago = date.addSeconds(now, -3);
|
|
|
494
500
|
|
|
495
501
|
### addMilliseconds(dateObj, milliseconds)
|
|
496
502
|
|
|
497
|
-
- @param {**Date**} dateObj -
|
|
498
|
-
- @param {**number**} milliseconds -
|
|
499
|
-
- @returns {**Date**}
|
|
503
|
+
- @param {**Date**} dateObj - A Date object
|
|
504
|
+
- @param {**number**} milliseconds - Number of milliseconds to add
|
|
505
|
+
- @returns {**Date**} The Date object after adding the value
|
|
500
506
|
|
|
501
507
|
```javascript
|
|
502
508
|
const now = new Date();
|
|
@@ -505,9 +511,9 @@ const a_millisecond_later = date.addMilliseconds(now, 1);
|
|
|
505
511
|
|
|
506
512
|
### subtract(date1, date2)
|
|
507
513
|
|
|
508
|
-
- @param {**Date**} date1 -
|
|
509
|
-
- @param {**Date**} date2 -
|
|
510
|
-
- @returns {**Object**}
|
|
514
|
+
- @param {**Date**} date1 - A Date object
|
|
515
|
+
- @param {**Date**} date2 - A Date object
|
|
516
|
+
- @returns {**Object**} The result object of subtracting date2 from date1
|
|
511
517
|
|
|
512
518
|
```javascript
|
|
513
519
|
const today = new Date(2015, 0, 2);
|
|
@@ -522,8 +528,8 @@ date.subtract(today, yesterday).toMilliseconds(); // => 86400000
|
|
|
522
528
|
|
|
523
529
|
### isLeapYear(y)
|
|
524
530
|
|
|
525
|
-
- @param {**number**} y - year
|
|
526
|
-
- @returns {**boolean**}
|
|
531
|
+
- @param {**number**} y - A year to check
|
|
532
|
+
- @returns {**boolean**} Whether the year is a leap year
|
|
527
533
|
|
|
528
534
|
```javascript
|
|
529
535
|
date.isLeapYear(2015); // => false
|
|
@@ -532,9 +538,9 @@ date.isLeapYear(2012); // => true
|
|
|
532
538
|
|
|
533
539
|
### isSameDay(date1, date2)
|
|
534
540
|
|
|
535
|
-
- @param {**Date**} date1 -
|
|
536
|
-
- @param {**Date**} date2 -
|
|
537
|
-
- @returns {**boolean**}
|
|
541
|
+
- @param {**Date**} date1 - A Date object
|
|
542
|
+
- @param {**Date**} date2 - A Date object
|
|
543
|
+
- @returns {**boolean**} Whether the two dates are the same day (time is ignored)
|
|
538
544
|
|
|
539
545
|
```javascript
|
|
540
546
|
const date1 = new Date(2017, 0, 2, 0); // Jan 2 2017 00:00:00
|
|
@@ -544,11 +550,10 @@ date.isSameDay(date1, date2); // => true
|
|
|
544
550
|
date.isSameDay(date1, date3); // => false
|
|
545
551
|
```
|
|
546
552
|
|
|
547
|
-
### locale([
|
|
553
|
+
### locale([locale])
|
|
548
554
|
|
|
549
|
-
- @param {**Function|string**} [
|
|
550
|
-
- @
|
|
551
|
-
- @returns {**string**} current language code
|
|
555
|
+
- @param {**Function|string**} [locale] - A locale installer or language code
|
|
556
|
+
- @returns {**string**} The current language code
|
|
552
557
|
|
|
553
558
|
It returns the current language code if called without any parameters.
|
|
554
559
|
|
|
@@ -568,15 +573,14 @@ See [LOCALE.md](./LOCALE.md) for details.
|
|
|
568
573
|
|
|
569
574
|
### extend(extension)
|
|
570
575
|
|
|
571
|
-
- @param {**Object**} extension - extension object
|
|
576
|
+
- @param {**Object**} extension - An extension object
|
|
572
577
|
- @returns {**void**}
|
|
573
578
|
|
|
574
579
|
It extends this library. See [EXTEND.md](./EXTEND.md) for details.
|
|
575
580
|
|
|
576
|
-
### plugin(
|
|
581
|
+
### plugin(plugin)
|
|
577
582
|
|
|
578
|
-
- @param {**Function|string**}
|
|
579
|
-
- @param {**Object**} [plugin] - plugin object
|
|
583
|
+
- @param {**Function|string**} plugin - A plugin installer or plugin name
|
|
580
584
|
- @returns {**void**}
|
|
581
585
|
|
|
582
586
|
Plugin is a named extension object. By installing predefined plugins, you can easily extend this library. See [PLUGINS.md](./PLUGINS.md) for details.
|