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