date-and-time 3.4.1 → 3.6.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 CHANGED
@@ -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()`, `parseTZ()` and `transformTZ()` that support `IANA time zone names` to the library.
79
+ - It adds `formatTZ()`, `parseTZ()`, `transformTZ()`, `addYearsTZ()`, `addMonthsTZ()` and `addDaysTZ()` 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.
@@ -290,7 +290,7 @@ In these functions can be available some tokens to format the calculation result
290
290
 
291
291
  ### timezone
292
292
 
293
- It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zone names` (`America/Los_Angeles`, `Asia/Tokyo`, and so on) to the library.
293
+ It adds `formatTZ()`, `parseTZ()`, `transformTZ()`, `addYearsTZ()`, `addMonthsTZ()` and `addDaysTZ()` 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
 
@@ -299,7 +299,7 @@ It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zo
299
299
  - @param {**string**} [timeZone] - Output as this time zone
300
300
  - @returns {**string**} A formatted string
301
301
 
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.
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 the 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
 
@@ -308,7 +308,7 @@ It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zo
308
308
  - @param {**string**} [timeZone] - Input as this time zone
309
309
  - @returns {**Date**} A Date object
310
310
 
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.
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 the 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
 
@@ -318,7 +318,34 @@ It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zo
318
318
  - @param {**string**} [timeZone] - Output as this time zone
319
319
  - @returns {**string**} A formatted string
320
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.
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 the 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 the local time zone. This means that the result is the same as when `transform()` is used.
322
+
323
+ #### addYearsTZ(dateObj, years[, timeZone])
324
+
325
+ - @param {**Date**} dateObj - A Date object
326
+ - @param {**number**} years - The number of years to add
327
+ - @param {**string**} [timeZone] - The time zone to use for the calculation
328
+ - @returns {**Date**} The Date object after adding the specified number of years
329
+
330
+ `addYearsTZ()` can calculate adding years in the specified time zone regardless of the execution environment.
331
+
332
+ #### addMonthsTZ(dateObj, months[, timeZone])
333
+
334
+ - @param {**Date**} dateObj - A Date object
335
+ - @param {**number**} months - The number of months to add
336
+ - @param {**string**} [timeZone] - The time zone to use for the calculation
337
+ - @returns {**Date**} The Date object after adding the specified number of months
338
+
339
+ `addMonthsTZ()` can calculate adding months in the specified time zone regardless of the execution environment.
340
+
341
+ #### addDaysTZ(dateObj, days[, timeZone])
342
+
343
+ - @param {**Date**} dateObj - A Date object
344
+ - @param {**number**} days - The number of days to add
345
+ - @param {**string**} [timeZone] - The time zone to use for the calculation
346
+ - @returns {**Date**} The Date object after adding the specified number of days
347
+
348
+ `addDaysTZ()` can calculate adding days in the specified time zone regardless of the execution environment.
322
349
 
323
350
  ```javascript
324
351
  const date = require('date-and-time');
@@ -354,18 +381,20 @@ date.transformTZ('2021-03-14T03:00:00 UTC-0700', 'YYYY-MM-DD[T]HH:mm:ss [UTC]Z',
354
381
 
355
382
  #### Start of DST (Daylight Saving Time)
356
383
 
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:
384
+ For example, in the US, when local standard time is about to reach `02:00:00` on Sunday, 14 March 2021, the clocks are set `forward` by 1 hour to `03:00:00` local daylight time instead. As a result, the time from `02:00:00` to `02:59:59` on 14 March 2021 does not exist. In such edge cases, `parseTZ()` will handle the case in the following way:
358
385
 
359
386
  ```javascript
360
387
  date.parseTZ('Mar 14 2021 1:59:59', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => 2021-03-14T09:59:59Z
361
- date.parseTZ('Mar 14 2021 2:00:00', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => NaN
362
- date.parseTZ('Mar 14 2021 2:59:59', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => NaN
363
388
  date.parseTZ('Mar 14 2021 3:00:00', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => 2021-03-14T10:00:00Z
389
+
390
+ // These times don't actually exist, but parseTZ() will handle as follows:
391
+ date.parseTZ('Mar 14 2021 2:00:00', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => 2021-03-14T10:00:00Z
392
+ date.parseTZ('Mar 14 2021 2:59:59', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => 2021-03-14T10:59:59Z
364
393
  ```
365
394
 
366
395
  #### End of DST
367
396
 
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:
397
+ Also, when local daylight time is about to reach `02:00:00` on Sunday, 7 November 2021, the clocks are set `back` by 1 hour to `01:00:00` local standard time instead. As a result, the time from `01:00:00` to `01:59:59` on 7 November 2021 occurs twice. Because this time period happens twice, `parseTZ()` assumes that the time is the earlier one (during DST) in order to make the result unique:
369
398
 
370
399
  ```javascript
371
400
  // This time is DST or PST? The parseTZ() always assumes that it is DST.
package/README.md CHANGED
@@ -25,15 +25,16 @@ npm i date-and-time
25
25
 
26
26
  ## Recent Changes
27
27
 
28
- - 3.4.1
29
- - Fixed an issue where `formatTZ()` would output 0:00 as 24:00 in 24-hour format in Node.js.
28
+ - 3.6.0
29
+ - In `parseTZ()`, enabled parsing of the missing hour during the transition from standard time to daylight saving time into a Date type.
30
+ - In `format()` with the `z` token, fixed an issue where some short time zone names were incorrect.
30
31
 
31
- - 3.4.0
32
- - Added `zz` (time zone name) and `z` (time zone name abbreviation) tokens to the `timezone` plugin.
33
- - Fixed an issue where token extensions by other plugins were not reflected in functions provided by the `timezone` plugin.
32
+ - 3.5.0
33
+ - Added `addYearsTZ()`, `addMonthsTZ()`, and `addDaysTZ()` to the `timezone` plugin.
34
+ - Revised the approach to adding time and removed the third parameter from `addHours()`, `addMinutes()`, `addSeconds()`, and `addMilliseconds()`.
34
35
 
35
- - 3.3.0
36
- - Refactored `format()`, `isValid()`, and `preparse()`, further improved performance.
36
+ - 3.4.1
37
+ - Fixed an issue where `formatTZ()` would output 0:00 as 24:00 in 24-hour format in Node.js.
37
38
 
38
39
  ## Usage
39
40
 
@@ -68,6 +69,16 @@ import date from '/path/to/date-and-time.es.min.js';
68
69
  ### Note
69
70
 
70
71
  - 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`.
72
+ - If you are using TypeScript and having trouble building, please ensure that the following settings in the `compilerOptions` of your `tsconfig.json` are set to `true`.
73
+
74
+ ```json
75
+ {
76
+ "compilerOptions": {
77
+ "allowSyntheticDefaultImports": true,
78
+ "esModuleInterop": true
79
+ }
80
+ }
81
+ ```
71
82
 
72
83
  ## API
73
84
 
@@ -98,16 +109,16 @@ import date from '/path/to/date-and-time.es.min.js';
98
109
  - [addDays](#adddaysdateobj-days-utc)
99
110
  - Adding days
100
111
 
101
- - [addHours](#addhoursdateobj-hours-utc)
112
+ - [addHours](#addhoursdateobj-hours)
102
113
  - Adding hours
103
114
 
104
- - [addMinutes](#addminutesdateobj-minutes-utc)
115
+ - [addMinutes](#addminutesdateobj-minutes)
105
116
  - Adding minutes
106
117
 
107
- - [addSeconds](#addsecondsdateobj-seconds-utc)
118
+ - [addSeconds](#addsecondsdateobj-seconds)
108
119
  - Adding seconds
109
120
 
110
- - [addMilliseconds](#addmillisecondsdateobj-milliseconds-utc)
121
+ - [addMilliseconds](#addmillisecondsdateobj-milliseconds)
111
122
  - Adding milliseconds
112
123
 
113
124
  - [subtract](#subtractdate1-date2)
@@ -434,11 +445,11 @@ date.transform('13:05', 'HH:mm', 'hh:mm A');
434
445
  ### addYears(dateObj, years[, utc])
435
446
 
436
447
  - @param {**Date**} dateObj - A Date object
437
- - @param {**number**} years - Number of years to add
438
- - @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
439
- - @returns {**Date**} The Date object after adding the value
448
+ - @param {**number**} years - The number of years to add
449
+ - @param {**boolean**} [utc] - If true, calculates the date in UTC `Added in: v3.0.0`
450
+ - @returns {**Date**} The Date object after adding the specified number of years
440
451
 
441
- Adds years to the date object.
452
+ Adds years to a date object. Subtraction is also possible by specifying a negative value. If the third parameter is false or omitted, this function calculates based on the system's default time zone. If you need to obtain calculation results based on a specific time zone regardless of the execution system, consider using the `addYearsTZ()`, which allows you to specify a time zone name as the third parameter. See [PLUGINS.md](./PLUGINS.md) for details.
442
453
 
443
454
  ```javascript
444
455
  const now = new Date();
@@ -456,11 +467,11 @@ const next_next_year = date.addYears(next_year, 1, true); // => Feb 28 2022
456
467
  ### addMonths(dateObj, months[, utc])
457
468
 
458
469
  - @param {**Date**} dateObj - A Date object
459
- - @param {**number**} months - Number of months to add
460
- - @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
461
- - @returns {**Date**} The Date object after adding the value
470
+ - @param {**number**} months - The number of months to add
471
+ - @param {**boolean**} [utc] - If true, calculates the date in UTC `Added in: v3.0.0`
472
+ - @returns {**Date**} The Date object after adding the specified number of months
462
473
 
463
- Adds months to the date object.
474
+ Adds months to a date object. Subtraction is also possible by specifying a negative value. If the third parameter is false or omitted, this function calculates based on the system's default time zone. If you need to obtain calculation results based on a specific time zone regardless of the execution system, consider using the `addMonthsTZ()`, which allows you to specify a time zone name as the third parameter. See [PLUGINS.md](./PLUGINS.md) for details.
464
475
 
465
476
  ```javascript
466
477
  const now = new Date();
@@ -478,57 +489,67 @@ const next_next_month = date.addMonths(next_month, 1, true); // => Mar 28 202
478
489
  ### addDays(dateObj, days[, utc])
479
490
 
480
491
  - @param {**Date**} dateObj - A Date object
481
- - @param {**number**} days - Number of days to add
482
- - @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
483
- - @returns {**Date**} The Date object after adding the value
492
+ - @param {**number**} days - The number of days to add
493
+ - @param {**boolean**} [utc] - If true, calculates the date in UTC `Added in: v3.0.0`
494
+ - @returns {**Date**} The Date object after adding the specified number of days
495
+
496
+ Adds days to a date object. Subtraction is also possible by specifying a negative value. If the third parameter is false or omitted, this function calculates based on the system's default time zone. If you need to obtain calculation results based on a specific time zone regardless of the execution system, consider using the `addDaysTZ()`, which allows you to specify a time zone name as the third parameter. See [PLUGINS.md](./PLUGINS.md) for details.
484
497
 
485
498
  ```javascript
486
499
  const now = new Date();
487
500
  const yesterday = date.addDays(now, -1);
488
501
  ```
489
502
 
490
- ### addHours(dateObj, hours[, utc])
503
+ ### addHours(dateObj, hours)
491
504
 
492
505
  - @param {**Date**} dateObj - A Date object
493
- - @param {**number**} hours - Number of hours to add
494
- - @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
495
- - @returns {**Date**} The Date object after adding the value
506
+ - @param {**number**} hours - The number of hours to add
507
+ - ~~@param {**boolean**} [utc] - If true, calculates the date in UTC `Added in: v3.0.0`~~ `Removed in: v3.5.0`
508
+ - @returns {**Date**} The Date object after adding the specified number of hours
509
+
510
+ Adds hours to a date object. Subtraction is also possible by specifying a negative value. The third parameter was deprecated in version 3.5.0. Regardless of what is specified for this parameter, the calculation results will not change.
496
511
 
497
512
  ```javascript
498
513
  const now = new Date();
499
514
  const an_hour_ago = date.addHours(now, -1);
500
515
  ```
501
516
 
502
- ### addMinutes(dateObj, minutes[, utc])
517
+ ### addMinutes(dateObj, minutes)
503
518
 
504
519
  - @param {**Date**} dateObj - A Date object
505
- - @param {**number**} minutes - Number of minutes to add
506
- - @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
507
- - @returns {**Date**} The Date object after adding the value
520
+ - @param {**number**} minutes - The number of minutes to add
521
+ - ~~@param {**boolean**} [utc] - If true, calculates the date in UTC `Added in: v3.0.0`~~ `Removed in: v3.5.0`
522
+ - @returns {**Date**} The Date object after adding the specified number of minutes
523
+
524
+ Adds minutes to a date object. Subtraction is also possible by specifying a negative value. The third parameter was deprecated in version 3.5.0. Regardless of what is specified for this parameter, the calculation results will not change.
508
525
 
509
526
  ```javascript
510
527
  const now = new Date();
511
528
  const two_minutes_later = date.addMinutes(now, 2);
512
529
  ```
513
530
 
514
- ### addSeconds(dateObj, seconds[, utc])
531
+ ### addSeconds(dateObj, seconds)
515
532
 
516
533
  - @param {**Date**} dateObj - A Date object
517
- - @param {**number**} seconds - Number of seconds to add
518
- - @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
519
- - @returns {**Date**} The Date object after adding the value
534
+ - @param {**number**} seconds - The number of seconds to add
535
+ - ~~@param {**boolean**} [utc] - If true, calculates the date in UTC `Added in: v3.0.0`~~ `Removed in: v3.5.0`
536
+ - @returns {**Date**} The Date object after adding the specified number of seconds
537
+
538
+ Adds seconds to a date object. Subtraction is also possible by specifying a negative value. The third parameter was deprecated in version 3.5.0. Regardless of what is specified for this parameter, the calculation results will not change.
520
539
 
521
540
  ```javascript
522
541
  const now = new Date();
523
542
  const three_seconds_ago = date.addSeconds(now, -3);
524
543
  ```
525
544
 
526
- ### addMilliseconds(dateObj, milliseconds[, utc])
545
+ ### addMilliseconds(dateObj, milliseconds)
527
546
 
528
547
  - @param {**Date**} dateObj - A Date object
529
- - @param {**number**} milliseconds - Number of milliseconds to add
530
- - @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
531
- - @returns {**Date**} The Date object after adding the value
548
+ - @param {**number**} milliseconds - The number of milliseconds to add
549
+ - ~~@param {**boolean**} [utc] - If true, calculates the date in UTC `Added in: v3.0.0`~~ `Removed in: v3.5.0`
550
+ - @returns {**Date**} The Date object after adding the specified number of milliseconds
551
+
552
+ Adds milliseconds to a date object. Subtraction is also possible by specifying a negative value. The third parameter was deprecated in version 3.5.0. Regardless of what is specified for this parameter, the calculation results will not change.
532
553
 
533
554
  ```javascript
534
555
  const now = new Date();
@@ -153,63 +153,95 @@ export function transform(dateString: string, compiledObj1: string[], compiledOb
153
153
  /**
154
154
  * Adding years
155
155
  * @param dateObj - A Date object
156
- * @param years - Number of years to add
157
- * @param [utc] - Calculates as UTC
158
- * @returns The Date object after adding the value
156
+ * @param years - The number of years to add
157
+ * @param [utc] - If true, calculates the date in UTC
158
+ * @returns The Date object after adding the specified number of years
159
159
  */
160
160
  export function addYears(dateObj: Date, years: number, utc?: boolean): Date;
161
161
 
162
162
  /**
163
163
  * Adding months
164
164
  * @param dateObj - A Date object
165
- * @param months - Number of months to add
166
- * @param [utc] - Calculates as UTC
167
- * @returns The Date object after adding the value
165
+ * @param months - The number of months to add
166
+ * @param [utc] - If true, calculates the date in UTC
167
+ * @returns The Date object after adding the specified number of months
168
168
  */
169
169
  export function addMonths(dateObj: Date, months: number, utc?: boolean): Date;
170
170
 
171
171
  /**
172
172
  * Adding days
173
173
  * @param dateObj - A Date object
174
- * @param days - Number of days to add
175
- * @param [utc] - Calculates as UTC
176
- * @returns The Date object after adding the value
174
+ * @param days - The number of days to add
175
+ * @param [utc] - If true, calculates the date in UTC
176
+ * @returns The Date object after adding the specified number of days
177
177
  */
178
178
  export function addDays(dateObj: Date, days: number, utc?: boolean): Date;
179
179
 
180
180
  /**
181
181
  * Adding hours
182
182
  * @param dateObj - A Date object
183
- * @param hours - Number of hours to add
184
- * @param [utc] - Calculates as UTC
185
- * @returns The Date object after adding the value
183
+ * @param hours - The number of hours to add
184
+ * @returns The Date object after adding the specified number of hours
185
+ */
186
+ export function addHours(dateObj: Date, hours: number): Date;
187
+
188
+ /**
189
+ * @deprecated The `utc` parameter is ignored. The function always returns the same result regardless of this value.
190
+ * @param dateObj - A Date object
191
+ * @param hours - The number of hours to add
192
+ * @param [utc] - If true, calculates the date in UTC
193
+ * @returns The Date object after adding the specified number of hours
186
194
  */
187
195
  export function addHours(dateObj: Date, hours: number, utc?: boolean): Date;
188
196
 
189
197
  /**
190
198
  * Adding minutes
191
199
  * @param dateObj - A Date object
192
- * @param minutes - Number of minutes to add
193
- * @param [utc] - Calculates as UTC
194
- * @returns The Date object after adding the value
200
+ * @param minutes - The number of minutes to add
201
+ * @returns The Date object after adding the specified number of minutes
202
+ */
203
+ export function addMinutes(dateObj: Date, minutes: number): Date;
204
+
205
+ /**
206
+ * @deprecated The `utc` parameter is ignored. The function always returns the same result regardless of this value.
207
+ * @param dateObj - A Date object
208
+ * @param minutes - The number of minutes to add
209
+ * @param [utc] - If true, calculates the date in UTC
210
+ * @returns The Date object after adding the specified number of minutes
195
211
  */
196
212
  export function addMinutes(dateObj: Date, minutes: number, utc?: boolean): Date;
197
213
 
198
214
  /**
199
215
  * Adding seconds
200
216
  * @param dateObj - A Date object
201
- * @param seconds - Number of seconds to add
202
- * @param [utc] - Calculates as UTC
203
- * @returns The Date object after adding the value
217
+ * @param seconds - The number of seconds to add
218
+ * @returns The Date object after adding the specified number of seconds
219
+ */
220
+ export function addSeconds(dateObj: Date, seconds: number): Date;
221
+
222
+ /**
223
+ * @deprecated The `utc` parameter is ignored. The function always returns the same result regardless of this value.
224
+ * @param dateObj - A Date object
225
+ * @param seconds - The number of seconds to add
226
+ * @param [utc] - If true, calculates the date in UTC
227
+ * @returns The Date object after adding the specified number of seconds
204
228
  */
205
229
  export function addSeconds(dateObj: Date, seconds: number, utc?: boolean): Date;
206
230
 
207
231
  /**
208
232
  * Adding milliseconds
209
233
  * @param dateObj - A Date object
210
- * @param milliseconds - Number of milliseconds to add
211
- * @param [utc] - Calculates as UTC
212
- * @returns The Date object after adding the value
234
+ * @param milliseconds - The number of milliseconds to add
235
+ * @returns The Date object after adding the specified number of milliseconds
236
+ */
237
+ export function addMilliseconds(dateObj: Date, milliseconds: number): Date;
238
+
239
+ /**
240
+ * @deprecated The `utc` parameter is ignored. The function always returns the same result regardless of this value.
241
+ * @param dateObj - A Date object
242
+ * @param milliseconds - The number of milliseconds to add
243
+ * @param [utc] - If true, calculates the date in UTC
244
+ * @returns The Date object after adding the specified number of milliseconds
213
245
  */
214
246
  export function addMilliseconds(dateObj: Date, milliseconds: number, utc?: boolean): Date;
215
247
 
package/date-and-time.js CHANGED
@@ -309,12 +309,14 @@
309
309
  if (utc) {
310
310
  d.setUTCMonth(d.getUTCMonth() + months);
311
311
  if (d.getUTCDate() < dateObj.getUTCDate()) {
312
- return (this || date).addDays(d, -d.getUTCDate(), utc);
312
+ d.setUTCDate(0);
313
+ return d;
313
314
  }
314
315
  } else {
315
316
  d.setMonth(d.getMonth() + months);
316
317
  if (d.getDate() < dateObj.getDate()) {
317
- return (this || date).addDays(d, -d.getDate(), utc);
318
+ d.setDate(0);
319
+ return d;
318
320
  }
319
321
  }
320
322
  return d;
@@ -328,58 +330,54 @@
328
330
  * @returns {Date} The Date object after adding the value
329
331
  */
330
332
  proto.addDays = function (dateObj, days, utc) {
331
- return (this || date).addHours(dateObj, days * 24, utc);
333
+ var d = new Date(dateObj.getTime());
334
+
335
+ if (utc) {
336
+ d.setUTCDate(d.getUTCDate() + days);
337
+ } else {
338
+ d.setDate(d.getDate() + days);
339
+ }
340
+ return d;
332
341
  };
333
342
 
334
343
  /**
335
344
  * Adding hours
336
345
  * @param {Date} dateObj - A Date object
337
346
  * @param {number} hours - Number of hours to add
338
- * @param {boolean} [utc] - Calculates as UTC
339
347
  * @returns {Date} The Date object after adding the value
340
348
  */
341
- proto.addHours = function (dateObj, hours, utc) {
342
- return (this || date).addMinutes(dateObj, hours * 60, utc);
349
+ proto.addHours = function (dateObj, hours) {
350
+ return new Date(dateObj.getTime() + hours * 60 * 60 * 1000);
343
351
  };
344
352
 
345
353
  /**
346
354
  * Adding minutes
347
355
  * @param {Date} dateObj - A Date object
348
356
  * @param {number} minutes - Number of minutes to add
349
- * @param {boolean} [utc] - Calculates as UTC
350
357
  * @returns {Date} The Date object after adding the value
351
358
  */
352
- proto.addMinutes = function (dateObj, minutes, utc) {
353
- return (this || date).addSeconds(dateObj, minutes * 60, utc);
359
+ proto.addMinutes = function (dateObj, minutes) {
360
+ return new Date(dateObj.getTime() + minutes * 60 * 1000);
354
361
  };
355
362
 
356
363
  /**
357
364
  * Adding seconds
358
365
  * @param {Date} dateObj - A Date object
359
366
  * @param {number} seconds - Number of seconds to add
360
- * @param {boolean} [utc] - Calculates as UTC
361
367
  * @returns {Date} The Date object after adding the value
362
368
  */
363
- proto.addSeconds = function (dateObj, seconds, utc) {
364
- return (this || date).addMilliseconds(dateObj, seconds * 1000, utc);
369
+ proto.addSeconds = function (dateObj, seconds) {
370
+ return new Date(dateObj.getTime() + seconds * 1000);
365
371
  };
366
372
 
367
373
  /**
368
374
  * Adding milliseconds
369
375
  * @param {Date} dateObj - A Date object
370
376
  * @param {number} milliseconds - Number of milliseconds to add
371
- * @param {boolean} [utc] - Calculates as UTC
372
377
  * @returns {Date} The Date object after adding the value
373
378
  */
374
- proto.addMilliseconds = function (dateObj, milliseconds, utc) {
375
- var d = new Date(dateObj.getTime());
376
-
377
- if (utc) {
378
- d.setUTCMilliseconds(d.getUTCMilliseconds() + milliseconds);
379
- } else {
380
- d.setMilliseconds(d.getMilliseconds() + milliseconds);
381
- }
382
- return d;
379
+ proto.addMilliseconds = function (dateObj, milliseconds) {
380
+ return new Date(dateObj.getTime() + milliseconds);
383
381
  };
384
382
 
385
383
  /**
@@ -1,4 +1,4 @@
1
1
  !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).date=t()}(this,(function(){"use strict";
2
2
  /**
3
3
  * @preserve date-and-time (c) KNOWLEDGECODE | MIT
4
- */var e,t={},n={},r="en",i={MMMM:["January","February","March","April","May","June","July","August","September","October","November","December"],MMM:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dddd:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ddd:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dd:["Su","Mo","Tu","We","Th","Fr","Sa"],A:["AM","PM"]},u={YYYY:function(e){return("000"+e.getFullYear()).slice(-4)},YY:function(e){return("0"+e.getFullYear()).slice(-2)},Y:function(e){return""+e.getFullYear()},MMMM:function(e){return this.res.MMMM[e.getMonth()]},MMM:function(e){return this.res.MMM[e.getMonth()]},MM:function(e){return("0"+(e.getMonth()+1)).slice(-2)},M:function(e){return""+(e.getMonth()+1)},DD:function(e){return("0"+e.getDate()).slice(-2)},D:function(e){return""+e.getDate()},HH:function(e){return("0"+e.getHours()).slice(-2)},H:function(e){return""+e.getHours()},A:function(e){return this.res.A[e.getHours()>11|0]},hh:function(e){return("0"+(e.getHours()%12||12)).slice(-2)},h:function(e){return""+(e.getHours()%12||12)},mm:function(e){return("0"+e.getMinutes()).slice(-2)},m:function(e){return""+e.getMinutes()},ss:function(e){return("0"+e.getSeconds()).slice(-2)},s:function(e){return""+e.getSeconds()},SSS:function(e){return("00"+e.getMilliseconds()).slice(-3)},SS:function(e){return("0"+(e.getMilliseconds()/10|0)).slice(-2)},S:function(e){return""+(e.getMilliseconds()/100|0)},dddd:function(e){return this.res.dddd[e.getDay()]},ddd:function(e){return this.res.ddd[e.getDay()]},dd:function(e){return this.res.dd[e.getDay()]},Z:function(e){var t=e.getTimezoneOffset()/.6|0;return(t>0?"-":"+")+("000"+Math.abs(t-(t%100*.4|0))).slice(-4)},ZZ:function(e){var t=e.getTimezoneOffset(),n=Math.abs(t);return(t>0?"-":"+")+("0"+(n/60|0)).slice(-2)+":"+("0"+n%60).slice(-2)},post:function(e){return e},res:i},o={YYYY:function(e){return this.exec(/^\d{4}/,e)},Y:function(e){return this.exec(/^\d{1,4}/,e)},MMMM:function(e){var t=this.find(this.res.MMMM,e);return t.value++,t},MMM:function(e){var t=this.find(this.res.MMM,e);return t.value++,t},MM:function(e){return this.exec(/^\d\d/,e)},M:function(e){return this.exec(/^\d\d?/,e)},DD:function(e){return this.exec(/^\d\d/,e)},D:function(e){return this.exec(/^\d\d?/,e)},HH:function(e){return this.exec(/^\d\d/,e)},H:function(e){return this.exec(/^\d\d?/,e)},A:function(e){return this.find(this.res.A,e)},hh:function(e){return this.exec(/^\d\d/,e)},h:function(e){return this.exec(/^\d\d?/,e)},mm:function(e){return this.exec(/^\d\d/,e)},m:function(e){return this.exec(/^\d\d?/,e)},ss:function(e){return this.exec(/^\d\d/,e)},s:function(e){return this.exec(/^\d\d?/,e)},SSS:function(e){return this.exec(/^\d{1,3}/,e)},SS:function(e){var t=this.exec(/^\d\d?/,e);return t.value*=10,t},S:function(e){var t=this.exec(/^\d/,e);return t.value*=100,t},Z:function(e){var t=this.exec(/^[+-]\d{2}[0-5]\d/,e);return t.value=-60*(t.value/100|0)-t.value%100,t},ZZ:function(e){var t=/^([+-])(\d{2}):([0-5]\d)/.exec(e)||["","","",""];return{value:0-(60*(t[1]+t[2]|0)+(t[1]+t[3]|0)),length:t[0].length}},h12:function(e,t){return(12===e?0:e)+12*t},exec:function(e,t){var n=(e.exec(t)||[""])[0];return{value:0|n,length:n.length}},find:function(e,t){for(var n,r=-1,i=0,u=0,o=e.length;u<o;u++)n=e[u],!t.indexOf(n)&&n.length>i&&(r=u,i=n.length);return{value:r,length:i}},pre:function(e){return e},res:i},s=function(e,t,n,r){var i,u={};for(i in e)u[i]=e[i];for(i in t||{})!!n^!!u[i]||(u[i]=t[i]);return r&&(u.res=r),u},c={_formatter:u,_parser:o};return c.compile=function(e){return[e].concat(e.match(/\[(?:[^[\]]|\[[^[\]]*])*]|([A-Za-z])\1*|\.{3}|./g)||[])},c.format=function(t,n,r){for(var i,u=this||e,o="string"==typeof n?u.compile(n):n,s=u._formatter,c=function(){if(r){var e=new Date(t.getTime());return e.getFullYear=e.getUTCFullYear,e.getMonth=e.getUTCMonth,e.getDate=e.getUTCDate,e.getHours=e.getUTCHours,e.getMinutes=e.getUTCMinutes,e.getSeconds=e.getUTCSeconds,e.getMilliseconds=e.getUTCMilliseconds,e.getDay=e.getUTCDay,e.getTimezoneOffset=function(){return 0},e.getTimezoneName=function(){return"UTC"},e}return t}(),a=/^\[(.*)\]$/,d="",f=1,l=o.length;f<l;f++)d+=s[i=o[f]]?s.post(s[i](c,o[0])):a.test(i)?i.replace(a,"$1"):i;return d},c.preparse=function(t,n){var r=this||e,i="string"==typeof n?r.compile(n):n,u=r._parser,o={Y:1970,M:1,D:1,H:0,A:0,h:0,m:0,s:0,S:0,Z:0,_index:0,_length:0,_match:0},s=/^\[(.*)\]$/;t=u.pre(t);for(var c,a,d,f=1,l=i.length;f<l;f++)if(c=i[f],a=t.substring(o._index),u[c]){if(!(d=u[c](a,i[0])).length)break;o[d.token||c.charAt(0)]=d.value,o._index+=d.length,o._match++}else if(c===a.charAt(0)||" "===c)o._index++;else{if(!s.test(c)||a.indexOf(c.replace(s,"$1"))){if("..."===c){o._index=t.length;break}break}o._index+=c.length-2}return o.H=o.H||u.h12(o.h,o.A),o._length=t.length,o},c.parse=function(t,n,r){var i=this||e,u="string"==typeof n?i.compile(n):n,o=i.preparse(t,u);return i.isValid(o)?(o.M-=o.Y<100?22801:1,r||~i._parser.find(u,"ZZ").value?new Date(Date.UTC(o.Y,o.M,o.D,o.H,o.m+o.Z,o.s,o.S)):new Date(o.Y,o.M,o.D,o.H,o.m,o.s,o.S)):new Date(NaN)},c.isValid=function(t,n){var r="string"==typeof t?(this||e).preparse(t,n):t;return!(r._index<1||r._length<1||r._index-r._length||r._match<1||r.Y<1||r.Y>9999||r.M<1||r.M>12||r.D<1||r.D>new Date(r.Y,r.M,0).getDate()||r.H<0||r.H>23||r.m<0||r.m>59||r.s<0||r.s>59||r.S<0||r.S>999||r.Z<-840||r.Z>720)},c.transform=function(t,n,r,i){const u=this||e;return u.format(u.parse(t,n),r,i)},c.addYears=function(t,n,r){return(this||e).addMonths(t,12*n,r)},c.addMonths=function(t,n,r){var i=new Date(t.getTime());if(r){if(i.setUTCMonth(i.getUTCMonth()+n),i.getUTCDate()<t.getUTCDate())return(this||e).addDays(i,-i.getUTCDate(),r)}else if(i.setMonth(i.getMonth()+n),i.getDate()<t.getDate())return(this||e).addDays(i,-i.getDate(),r);return i},c.addDays=function(t,n,r){return(this||e).addHours(t,24*n,r)},c.addHours=function(t,n,r){return(this||e).addMinutes(t,60*n,r)},c.addMinutes=function(t,n,r){return(this||e).addSeconds(t,60*n,r)},c.addSeconds=function(t,n,r){return(this||e).addMilliseconds(t,1e3*n,r)},c.addMilliseconds=function(e,t,n){var r=new Date(e.getTime());return n?r.setUTCMilliseconds(r.getUTCMilliseconds()+t):r.setMilliseconds(r.getMilliseconds()+t),r},c.subtract=function(e,t){var n=e.getTime()-t.getTime();return{toMilliseconds:function(){return n},toSeconds:function(){return n/1e3},toMinutes:function(){return n/6e4},toHours:function(){return n/36e5},toDays:function(){return n/864e5}}},c.isLeapYear=function(e){return!((e%4||!(e%100))&&e%400)},c.isSameDay=function(e,t){return e.toDateString()===t.toDateString()},c.locale=function(e,n){t[e]||(t[e]=n)},c.plugin=function(e,t){n[e]||(n[e]=t)},(e=s(c)).locale=function(a){var d="function"==typeof a?a:e.locale[a];if(!d)return r;r=d(c);var f=t[r]||{},l=s(i,f.res,!0),h=s(u,f.formatter,!0,l),g=s(o,f.parser,!0,l);for(var M in e._formatter=h,e._parser=g,n)e.extend(n[M]);return r},e.extend=function(t){var n=s(e._parser.res,t.res),r=t.extender||{};for(var i in e._formatter=s(e._formatter,t.formatter,!1,n),e._parser=s(e._parser,t.parser,!1,n),r)e[i]||(e[i]=r[i])},e.plugin=function(t){var r="function"==typeof t?t:e.plugin[t];r&&e.extend(n[r(c,e)]||{})},e}));
4
+ */var e,t={},n={},r="en",u={MMMM:["January","February","March","April","May","June","July","August","September","October","November","December"],MMM:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dddd:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ddd:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dd:["Su","Mo","Tu","We","Th","Fr","Sa"],A:["AM","PM"]},i={YYYY:function(e){return("000"+e.getFullYear()).slice(-4)},YY:function(e){return("0"+e.getFullYear()).slice(-2)},Y:function(e){return""+e.getFullYear()},MMMM:function(e){return this.res.MMMM[e.getMonth()]},MMM:function(e){return this.res.MMM[e.getMonth()]},MM:function(e){return("0"+(e.getMonth()+1)).slice(-2)},M:function(e){return""+(e.getMonth()+1)},DD:function(e){return("0"+e.getDate()).slice(-2)},D:function(e){return""+e.getDate()},HH:function(e){return("0"+e.getHours()).slice(-2)},H:function(e){return""+e.getHours()},A:function(e){return this.res.A[e.getHours()>11|0]},hh:function(e){return("0"+(e.getHours()%12||12)).slice(-2)},h:function(e){return""+(e.getHours()%12||12)},mm:function(e){return("0"+e.getMinutes()).slice(-2)},m:function(e){return""+e.getMinutes()},ss:function(e){return("0"+e.getSeconds()).slice(-2)},s:function(e){return""+e.getSeconds()},SSS:function(e){return("00"+e.getMilliseconds()).slice(-3)},SS:function(e){return("0"+(e.getMilliseconds()/10|0)).slice(-2)},S:function(e){return""+(e.getMilliseconds()/100|0)},dddd:function(e){return this.res.dddd[e.getDay()]},ddd:function(e){return this.res.ddd[e.getDay()]},dd:function(e){return this.res.dd[e.getDay()]},Z:function(e){var t=e.getTimezoneOffset()/.6|0;return(t>0?"-":"+")+("000"+Math.abs(t-(t%100*.4|0))).slice(-4)},ZZ:function(e){var t=e.getTimezoneOffset(),n=Math.abs(t);return(t>0?"-":"+")+("0"+(n/60|0)).slice(-2)+":"+("0"+n%60).slice(-2)},post:function(e){return e},res:u},o={YYYY:function(e){return this.exec(/^\d{4}/,e)},Y:function(e){return this.exec(/^\d{1,4}/,e)},MMMM:function(e){var t=this.find(this.res.MMMM,e);return t.value++,t},MMM:function(e){var t=this.find(this.res.MMM,e);return t.value++,t},MM:function(e){return this.exec(/^\d\d/,e)},M:function(e){return this.exec(/^\d\d?/,e)},DD:function(e){return this.exec(/^\d\d/,e)},D:function(e){return this.exec(/^\d\d?/,e)},HH:function(e){return this.exec(/^\d\d/,e)},H:function(e){return this.exec(/^\d\d?/,e)},A:function(e){return this.find(this.res.A,e)},hh:function(e){return this.exec(/^\d\d/,e)},h:function(e){return this.exec(/^\d\d?/,e)},mm:function(e){return this.exec(/^\d\d/,e)},m:function(e){return this.exec(/^\d\d?/,e)},ss:function(e){return this.exec(/^\d\d/,e)},s:function(e){return this.exec(/^\d\d?/,e)},SSS:function(e){return this.exec(/^\d{1,3}/,e)},SS:function(e){var t=this.exec(/^\d\d?/,e);return t.value*=10,t},S:function(e){var t=this.exec(/^\d/,e);return t.value*=100,t},Z:function(e){var t=this.exec(/^[+-]\d{2}[0-5]\d/,e);return t.value=-60*(t.value/100|0)-t.value%100,t},ZZ:function(e){var t=/^([+-])(\d{2}):([0-5]\d)/.exec(e)||["","","",""];return{value:0-(60*(t[1]+t[2]|0)+(t[1]+t[3]|0)),length:t[0].length}},h12:function(e,t){return(12===e?0:e)+12*t},exec:function(e,t){var n=(e.exec(t)||[""])[0];return{value:0|n,length:n.length}},find:function(e,t){for(var n,r=-1,u=0,i=0,o=e.length;i<o;i++)n=e[i],!t.indexOf(n)&&n.length>u&&(r=i,u=n.length);return{value:r,length:u}},pre:function(e){return e},res:u},s=function(e,t,n,r){var u,i={};for(u in e)i[u]=e[u];for(u in t||{})!!n^!!i[u]||(i[u]=t[u]);return r&&(i.res=r),i},a={_formatter:i,_parser:o};return a.compile=function(e){return[e].concat(e.match(/\[(?:[^[\]]|\[[^[\]]*])*]|([A-Za-z])\1*|\.{3}|./g)||[])},a.format=function(t,n,r){for(var u,i=this||e,o="string"==typeof n?i.compile(n):n,s=i._formatter,a=function(){if(r){var e=new Date(t.getTime());return e.getFullYear=e.getUTCFullYear,e.getMonth=e.getUTCMonth,e.getDate=e.getUTCDate,e.getHours=e.getUTCHours,e.getMinutes=e.getUTCMinutes,e.getSeconds=e.getUTCSeconds,e.getMilliseconds=e.getUTCMilliseconds,e.getDay=e.getUTCDay,e.getTimezoneOffset=function(){return 0},e.getTimezoneName=function(){return"UTC"},e}return t}(),c=/^\[(.*)\]$/,f="",d=1,l=o.length;d<l;d++)f+=s[u=o[d]]?s.post(s[u](a,o[0])):c.test(u)?u.replace(c,"$1"):u;return f},a.preparse=function(t,n){var r=this||e,u="string"==typeof n?r.compile(n):n,i=r._parser,o={Y:1970,M:1,D:1,H:0,A:0,h:0,m:0,s:0,S:0,Z:0,_index:0,_length:0,_match:0},s=/^\[(.*)\]$/;t=i.pre(t);for(var a,c,f,d=1,l=u.length;d<l;d++)if(a=u[d],c=t.substring(o._index),i[a]){if(!(f=i[a](c,u[0])).length)break;o[f.token||a.charAt(0)]=f.value,o._index+=f.length,o._match++}else if(a===c.charAt(0)||" "===a)o._index++;else{if(!s.test(a)||c.indexOf(a.replace(s,"$1"))){if("..."===a){o._index=t.length;break}break}o._index+=a.length-2}return o.H=o.H||i.h12(o.h,o.A),o._length=t.length,o},a.parse=function(t,n,r){var u=this||e,i="string"==typeof n?u.compile(n):n,o=u.preparse(t,i);return u.isValid(o)?(o.M-=o.Y<100?22801:1,r||~u._parser.find(i,"ZZ").value?new Date(Date.UTC(o.Y,o.M,o.D,o.H,o.m+o.Z,o.s,o.S)):new Date(o.Y,o.M,o.D,o.H,o.m,o.s,o.S)):new Date(NaN)},a.isValid=function(t,n){var r="string"==typeof t?(this||e).preparse(t,n):t;return!(r._index<1||r._length<1||r._index-r._length||r._match<1||r.Y<1||r.Y>9999||r.M<1||r.M>12||r.D<1||r.D>new Date(r.Y,r.M,0).getDate()||r.H<0||r.H>23||r.m<0||r.m>59||r.s<0||r.s>59||r.S<0||r.S>999||r.Z<-840||r.Z>720)},a.transform=function(t,n,r,u){const i=this||e;return i.format(i.parse(t,n),r,u)},a.addYears=function(t,n,r){return(this||e).addMonths(t,12*n,r)},a.addMonths=function(e,t,n){var r=new Date(e.getTime());if(n){if(r.setUTCMonth(r.getUTCMonth()+t),r.getUTCDate()<e.getUTCDate())return r.setUTCDate(0),r}else if(r.setMonth(r.getMonth()+t),r.getDate()<e.getDate())return r.setDate(0),r;return r},a.addDays=function(e,t,n){var r=new Date(e.getTime());return n?r.setUTCDate(r.getUTCDate()+t):r.setDate(r.getDate()+t),r},a.addHours=function(e,t){return new Date(e.getTime()+60*t*60*1e3)},a.addMinutes=function(e,t){return new Date(e.getTime()+60*t*1e3)},a.addSeconds=function(e,t){return new Date(e.getTime()+1e3*t)},a.addMilliseconds=function(e,t){return new Date(e.getTime()+t)},a.subtract=function(e,t){var n=e.getTime()-t.getTime();return{toMilliseconds:function(){return n},toSeconds:function(){return n/1e3},toMinutes:function(){return n/6e4},toHours:function(){return n/36e5},toDays:function(){return n/864e5}}},a.isLeapYear=function(e){return!((e%4||!(e%100))&&e%400)},a.isSameDay=function(e,t){return e.toDateString()===t.toDateString()},a.locale=function(e,n){t[e]||(t[e]=n)},a.plugin=function(e,t){n[e]||(n[e]=t)},(e=s(a)).locale=function(c){var f="function"==typeof c?c:e.locale[c];if(!f)return r;r=f(a);var d=t[r]||{},l=s(u,d.res,!0),g=s(i,d.formatter,!0,l),h=s(o,d.parser,!0,l);for(var M in e._formatter=g,e._parser=h,n)e.extend(n[M]);return r},e.extend=function(t){var n=s(e._parser.res,t.res),r=t.extender||{};for(var u in e._formatter=s(e._formatter,t.formatter,!1,n),e._parser=s(e._parser,t.parser,!1,n),r)e[u]||(e[u]=r[u])},e.plugin=function(t){var r="function"==typeof t?t:e.plugin[t];r&&e.extend(n[r(a,e)]||{})},e}));
@@ -303,12 +303,14 @@ proto.addMonths = function (dateObj, months, utc) {
303
303
  if (utc) {
304
304
  d.setUTCMonth(d.getUTCMonth() + months);
305
305
  if (d.getUTCDate() < dateObj.getUTCDate()) {
306
- return (this || date).addDays(d, -d.getUTCDate(), utc);
306
+ d.setUTCDate(0);
307
+ return d;
307
308
  }
308
309
  } else {
309
310
  d.setMonth(d.getMonth() + months);
310
311
  if (d.getDate() < dateObj.getDate()) {
311
- return (this || date).addDays(d, -d.getDate(), utc);
312
+ d.setDate(0);
313
+ return d;
312
314
  }
313
315
  }
314
316
  return d;
@@ -322,58 +324,54 @@ proto.addMonths = function (dateObj, months, utc) {
322
324
  * @returns {Date} The Date object after adding the value
323
325
  */
324
326
  proto.addDays = function (dateObj, days, utc) {
325
- return (this || date).addHours(dateObj, days * 24, utc);
327
+ var d = new Date(dateObj.getTime());
328
+
329
+ if (utc) {
330
+ d.setUTCDate(d.getUTCDate() + days);
331
+ } else {
332
+ d.setDate(d.getDate() + days);
333
+ }
334
+ return d;
326
335
  };
327
336
 
328
337
  /**
329
338
  * Adding hours
330
339
  * @param {Date} dateObj - A Date object
331
340
  * @param {number} hours - Number of hours to add
332
- * @param {boolean} [utc] - Calculates as UTC
333
341
  * @returns {Date} The Date object after adding the value
334
342
  */
335
- proto.addHours = function (dateObj, hours, utc) {
336
- return (this || date).addMinutes(dateObj, hours * 60, utc);
343
+ proto.addHours = function (dateObj, hours) {
344
+ return new Date(dateObj.getTime() + hours * 60 * 60 * 1000);
337
345
  };
338
346
 
339
347
  /**
340
348
  * Adding minutes
341
349
  * @param {Date} dateObj - A Date object
342
350
  * @param {number} minutes - Number of minutes to add
343
- * @param {boolean} [utc] - Calculates as UTC
344
351
  * @returns {Date} The Date object after adding the value
345
352
  */
346
- proto.addMinutes = function (dateObj, minutes, utc) {
347
- return (this || date).addSeconds(dateObj, minutes * 60, utc);
353
+ proto.addMinutes = function (dateObj, minutes) {
354
+ return new Date(dateObj.getTime() + minutes * 60 * 1000);
348
355
  };
349
356
 
350
357
  /**
351
358
  * Adding seconds
352
359
  * @param {Date} dateObj - A Date object
353
360
  * @param {number} seconds - Number of seconds to add
354
- * @param {boolean} [utc] - Calculates as UTC
355
361
  * @returns {Date} The Date object after adding the value
356
362
  */
357
- proto.addSeconds = function (dateObj, seconds, utc) {
358
- return (this || date).addMilliseconds(dateObj, seconds * 1000, utc);
363
+ proto.addSeconds = function (dateObj, seconds) {
364
+ return new Date(dateObj.getTime() + seconds * 1000);
359
365
  };
360
366
 
361
367
  /**
362
368
  * Adding milliseconds
363
369
  * @param {Date} dateObj - A Date object
364
370
  * @param {number} milliseconds - Number of milliseconds to add
365
- * @param {boolean} [utc] - Calculates as UTC
366
371
  * @returns {Date} The Date object after adding the value
367
372
  */
368
- proto.addMilliseconds = function (dateObj, milliseconds, utc) {
369
- var d = new Date(dateObj.getTime());
370
-
371
- if (utc) {
372
- d.setUTCMilliseconds(d.getUTCMilliseconds() + milliseconds);
373
- } else {
374
- d.setMilliseconds(d.getMilliseconds() + milliseconds);
375
- }
376
- return d;
373
+ proto.addMilliseconds = function (dateObj, milliseconds) {
374
+ return new Date(dateObj.getTime() + milliseconds);
377
375
  };
378
376
 
379
377
  /**