date-and-time 2.4.3 → 3.0.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/README.md CHANGED
@@ -25,15 +25,15 @@ npm i date-and-time
25
25
 
26
26
  ## Recent Changes
27
27
 
28
+ - 3.0.0
29
+ - **Breaking Changes!** Added `utc` option to the 3rd parameter of `addYears()`, `addMonths()`, `addDays()`, `addHours()`, `addMinutes()`, `addSeconds()` and `addMilliseconds()`. If you use these functions in timezones with daylight savings time, you may get different results depending on the 3rd parameter.
30
+
28
31
  - 2.4.3
29
- - Fixed an issue where using the `addMonths` function in regions with daylight saving time would return incorrect results.
32
+ - Fixed an issue where using `addMonths()` in timezones with daylight saving time returned incorrect results.
30
33
 
31
34
  - 2.4.2
32
35
  - Fixed an issue where the timezone plugin stopped working due to Node.js timezone update.
33
36
 
34
- - 2.4.1
35
- - Fixed the previous Jest support.
36
-
37
37
  ## Usage
38
38
 
39
39
  - ES Modules:
@@ -88,25 +88,25 @@ import date from '/path/to/date-and-time.es.min.js';
88
88
  - [transform](#transformdatestring-arg1-arg2-utc)
89
89
  - Format transformation of date and time strings (String -> String)
90
90
 
91
- - [addYears](#addyearsdateobj-years)
91
+ - [addYears](#addyearsdateobj-years-utc)
92
92
  - Adding years
93
93
 
94
- - [addMonths](#addmonthsdateobj-months)
94
+ - [addMonths](#addmonthsdateobj-months-utc)
95
95
  - Adding months
96
96
 
97
- - [addDays](#adddaysdateobj-days)
97
+ - [addDays](#adddaysdateobj-days-utc)
98
98
  - Adding days
99
99
 
100
- - [addHours](#addhoursdateobj-hours)
100
+ - [addHours](#addhoursdateobj-hours-utc)
101
101
  - Adding hours
102
102
 
103
- - [addMinutes](#addminutesdateobj-minutes)
103
+ - [addMinutes](#addminutesdateobj-minutes-utc)
104
104
  - Adding minutes
105
105
 
106
- - [addSeconds](#addsecondsdateobj-seconds)
106
+ - [addSeconds](#addsecondsdateobj-seconds-utc)
107
107
  - Adding seconds
108
108
 
109
- - [addMilliseconds](#addmillisecondsdateobj-milliseconds)
109
+ - [addMilliseconds](#addmillisecondsdateobj-milliseconds-utc)
110
110
  - Adding milliseconds
111
111
 
112
112
  - [subtract](#subtractdate1-date2)
@@ -428,10 +428,11 @@ date.transform('3/8/2020', 'D/M/YYYY', 'M/D/YYYY');
428
428
  date.transform('13:05', 'HH:mm', 'hh:mm A');
429
429
  ```
430
430
 
431
- ### addYears(dateObj, years)
431
+ ### addYears(dateObj, years[, utc])
432
432
 
433
433
  - @param {**Date**} dateObj - A Date object
434
434
  - @param {**number**} years - Number of years to add
435
+ - @param {**boolean**} [utc] - Calculates as UTC
435
436
  - @returns {**Date**} The Date object after adding the value
436
437
 
437
438
  ```javascript
@@ -439,10 +440,11 @@ const now = new Date();
439
440
  const next_year = date.addYears(now, 1);
440
441
  ```
441
442
 
442
- ### addMonths(dateObj, months)
443
+ ### addMonths(dateObj, months[, utc])
443
444
 
444
445
  - @param {**Date**} dateObj - A Date object
445
446
  - @param {**number**} months - Number of months to add
447
+ - @param {**boolean**} [utc] - Calculates as UTC
446
448
  - @returns {**Date**} The Date object after adding the value
447
449
 
448
450
  ```javascript
@@ -450,10 +452,11 @@ const now = new Date();
450
452
  const next_month = date.addMonths(now, 1);
451
453
  ```
452
454
 
453
- ### addDays(dateObj, days)
455
+ ### addDays(dateObj, days[, utc])
454
456
 
455
457
  - @param {**Date**} dateObj - A Date object
456
458
  - @param {**number**} days - Number of days to add
459
+ - @param {**boolean**} [utc] - Calculates as UTC
457
460
  - @returns {**Date**} The Date object after adding the value
458
461
 
459
462
  ```javascript
@@ -461,10 +464,11 @@ const now = new Date();
461
464
  const yesterday = date.addDays(now, -1);
462
465
  ```
463
466
 
464
- ### addHours(dateObj, hours)
467
+ ### addHours(dateObj, hours[, utc])
465
468
 
466
469
  - @param {**Date**} dateObj - A Date object
467
470
  - @param {**number**} hours - Number of hours to add
471
+ - @param {**boolean**} [utc] - Calculates as UTC
468
472
  - @returns {**Date**} The Date object after adding the value
469
473
 
470
474
  ```javascript
@@ -472,10 +476,11 @@ const now = new Date();
472
476
  const an_hour_ago = date.addHours(now, -1);
473
477
  ```
474
478
 
475
- ### addMinutes(dateObj, minutes)
479
+ ### addMinutes(dateObj, minutes[, utc])
476
480
 
477
481
  - @param {**Date**} dateObj - A Date object
478
482
  - @param {**number**} minutes - Number of minutes to add
483
+ - @param {**boolean**} [utc] - Calculates as UTC
479
484
  - @returns {**Date**} The Date object after adding the value
480
485
 
481
486
  ```javascript
@@ -483,10 +488,11 @@ const now = new Date();
483
488
  const two_minutes_later = date.addMinutes(now, 2);
484
489
  ```
485
490
 
486
- ### addSeconds(dateObj, seconds)
491
+ ### addSeconds(dateObj, seconds[, utc])
487
492
 
488
493
  - @param {**Date**} dateObj - A Date object
489
494
  - @param {**number**} seconds - Number of seconds to add
495
+ - @param {**boolean**} [utc] - Calculates as UTC
490
496
  - @returns {**Date**} The Date object after adding the value
491
497
 
492
498
  ```javascript
@@ -494,10 +500,11 @@ const now = new Date();
494
500
  const three_seconds_ago = date.addSeconds(now, -3);
495
501
  ```
496
502
 
497
- ### addMilliseconds(dateObj, milliseconds)
503
+ ### addMilliseconds(dateObj, milliseconds[, utc])
498
504
 
499
505
  - @param {**Date**} dateObj - A Date object
500
506
  - @param {**number**} milliseconds - Number of milliseconds to add
507
+ - @param {**boolean**} [utc] - Calculates as UTC
501
508
  - @returns {**Date**} The Date object after adding the value
502
509
 
503
510
  ```javascript
@@ -154,57 +154,64 @@ export function transform(dateString: string, compiledObj1: string[], compiledOb
154
154
  * Adding years
155
155
  * @param dateObj - A Date object
156
156
  * @param years - Number of years to add
157
+ * @param [utc] - Calculates as UTC
157
158
  * @returns The Date object after adding the value
158
159
  */
159
- export function addYears(dateObj: Date, years: number): Date;
160
+ export function addYears(dateObj: Date, years: number, utc?: boolean): Date;
160
161
 
161
162
  /**
162
163
  * Adding months
163
164
  * @param dateObj - A Date object
164
165
  * @param months - Number of months to add
166
+ * @param [utc] - Calculates as UTC
165
167
  * @returns The Date object after adding the value
166
168
  */
167
- export function addMonths(dateObj: Date, months: number): Date;
169
+ export function addMonths(dateObj: Date, months: number, utc?: boolean): Date;
168
170
 
169
171
  /**
170
172
  * Adding days
171
173
  * @param dateObj - A Date object
172
174
  * @param days - Number of days to add
175
+ * @param [utc] - Calculates as UTC
173
176
  * @returns The Date object after adding the value
174
177
  */
175
- export function addDays(dateObj: Date, days: number): Date;
178
+ export function addDays(dateObj: Date, days: number, utc?: boolean): Date;
176
179
 
177
180
  /**
178
181
  * Adding hours
179
182
  * @param dateObj - A Date object
180
183
  * @param hours - Number of hours to add
184
+ * @param [utc] - Calculates as UTC
181
185
  * @returns The Date object after adding the value
182
186
  */
183
- export function addHours(dateObj: Date, hours: number): Date;
187
+ export function addHours(dateObj: Date, hours: number, utc?: boolean): Date;
184
188
 
185
189
  /**
186
190
  * Adding minutes
187
191
  * @param dateObj - A Date object
188
192
  * @param minutes - Number of minutes to add
193
+ * @param [utc] - Calculates as UTC
189
194
  * @returns The Date object after adding the value
190
195
  */
191
- export function addMinutes(dateObj: Date, minutes: number): Date;
196
+ export function addMinutes(dateObj: Date, minutes: number, utc?: boolean): Date;
192
197
 
193
198
  /**
194
199
  * Adding seconds
195
200
  * @param dateObj - A Date object
196
201
  * @param seconds - Number of seconds to add
202
+ * @param [utc] - Calculates as UTC
197
203
  * @returns The Date object after adding the value
198
204
  */
199
- export function addSeconds(dateObj: Date, seconds: number): Date;
205
+ export function addSeconds(dateObj: Date, seconds: number, utc?: boolean): Date;
200
206
 
201
207
  /**
202
208
  * Adding milliseconds
203
209
  * @param dateObj - A Date object
204
210
  * @param milliseconds - Number of milliseconds to add
211
+ * @param [utc] - Calculates as UTC
205
212
  * @returns The Date object after adding the value
206
213
  */
207
- export function addMilliseconds(dateObj: Date, milliseconds: number): Date;
214
+ export function addMilliseconds(dateObj: Date, milliseconds: number, utc?: boolean): Date;
208
215
 
209
216
  /** Subtraction result object */
210
217
  export type SubtractResult = {
package/date-and-time.js CHANGED
@@ -276,22 +276,28 @@
276
276
  * Adding years
277
277
  * @param {Date} dateObj - A Date object
278
278
  * @param {number} years - Number of years to add
279
+ * @param {boolean} [utc] - Calculates as UTC
279
280
  * @returns {Date} The Date object after adding the value
280
281
  */
281
- proto.addYears = function (dateObj, years) {
282
- return (this || date).addMonths(dateObj, years * 12);
282
+ proto.addYears = function (dateObj, years, utc) {
283
+ return (this || date).addMonths(dateObj, years * 12, utc);
283
284
  };
284
285
 
285
286
  /**
286
287
  * Adding months
287
288
  * @param {Date} dateObj - A Date object
288
289
  * @param {number} months - Number of months to add
290
+ * @param {boolean} [utc] - Calculates as UTC
289
291
  * @returns {Date} The Date object after adding the value
290
292
  */
291
- proto.addMonths = function (dateObj, months) {
293
+ proto.addMonths = function (dateObj, months, utc) {
292
294
  var d = new Date(dateObj.getTime());
293
295
 
294
- d.setUTCMonth(d.getUTCMonth() + months);
296
+ if (utc) {
297
+ d.setUTCMonth(d.getUTCMonth() + months);
298
+ } else {
299
+ d.setMonth(d.getMonth() + months);
300
+ }
295
301
  return d;
296
302
  };
297
303
 
@@ -299,53 +305,62 @@
299
305
  * Adding days
300
306
  * @param {Date} dateObj - A Date object
301
307
  * @param {number} days - Number of days to add
308
+ * @param {boolean} [utc] - Calculates as UTC
302
309
  * @returns {Date} The Date object after adding the value
303
310
  */
304
- proto.addDays = function (dateObj, days) {
305
- var d = new Date(dateObj.getTime());
306
-
307
- d.setUTCDate(d.getUTCDate() + days);
308
- return d;
311
+ proto.addDays = function (dateObj, days, utc) {
312
+ return (this || date).addHours(dateObj, days * 24, utc);
309
313
  };
310
314
 
311
315
  /**
312
316
  * Adding hours
313
317
  * @param {Date} dateObj - A Date object
314
318
  * @param {number} hours - Number of hours to add
319
+ * @param {boolean} [utc] - Calculates as UTC
315
320
  * @returns {Date} The Date object after adding the value
316
321
  */
317
- proto.addHours = function (dateObj, hours) {
318
- return (this || date).addMinutes(dateObj, hours * 60);
322
+ proto.addHours = function (dateObj, hours, utc) {
323
+ return (this || date).addMinutes(dateObj, hours * 60, utc);
319
324
  };
320
325
 
321
326
  /**
322
327
  * Adding minutes
323
328
  * @param {Date} dateObj - A Date object
324
329
  * @param {number} minutes - Number of minutes to add
330
+ * @param {boolean} [utc] - Calculates as UTC
325
331
  * @returns {Date} The Date object after adding the value
326
332
  */
327
- proto.addMinutes = function (dateObj, minutes) {
328
- return (this || date).addSeconds(dateObj, minutes * 60);
333
+ proto.addMinutes = function (dateObj, minutes, utc) {
334
+ return (this || date).addSeconds(dateObj, minutes * 60, utc);
329
335
  };
330
336
 
331
337
  /**
332
338
  * Adding seconds
333
339
  * @param {Date} dateObj - A Date object
334
340
  * @param {number} seconds - Number of seconds to add
341
+ * @param {boolean} [utc] - Calculates as UTC
335
342
  * @returns {Date} The Date object after adding the value
336
343
  */
337
- proto.addSeconds = function (dateObj, seconds) {
338
- return (this || date).addMilliseconds(dateObj, seconds * 1000);
344
+ proto.addSeconds = function (dateObj, seconds, utc) {
345
+ return (this || date).addMilliseconds(dateObj, seconds * 1000, utc);
339
346
  };
340
347
 
341
348
  /**
342
349
  * Adding milliseconds
343
350
  * @param {Date} dateObj - A Date object
344
351
  * @param {number} milliseconds - Number of milliseconds to add
352
+ * @param {boolean} [utc] - Calculates as UTC
345
353
  * @returns {Date} The Date object after adding the value
346
354
  */
347
- proto.addMilliseconds = function (dateObj, milliseconds) {
348
- return new Date(dateObj.getTime() + milliseconds);
355
+ proto.addMilliseconds = function (dateObj, milliseconds, utc) {
356
+ var d = new Date(dateObj.getTime());
357
+
358
+ if (utc) {
359
+ d.setUTCMilliseconds(d.getUTCMilliseconds() + milliseconds);
360
+ } else {
361
+ d.setMilliseconds(d.getMilliseconds() + milliseconds);
362
+ }
363
+ return d;
349
364
  };
350
365
 
351
366
  /**
@@ -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={},i="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"]},o={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},s={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:u},c=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},a={_formatter:o,_parser:s};return a.compile=function(e){for(var t,n=/\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g,r=[e];t=n.exec(e);)r[r.length]=t[0];return r},a.format=function(e,n,r){var i=this||t,u="string"==typeof n?i.compile(n):n,o=e.getTimezoneOffset(),s=i.addMinutes(e,r?o:0),c=i._formatter,a="";s.getTimezoneOffset=function(){return r?0:o};for(var f,d=1,l=u.length;d<l;d++)a+=c[f=u[d]]?c.post(c[f](s,u[0])):f.replace(/\[(.*)]/,"$1");return a},a.preparse=function(e,n){var r=this||t,i="string"==typeof n?r.compile(n):n,u={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},o=/\[(.*)]/,s=r._parser,c=0;e=s.pre(e);for(var a,f,d=1,l=i.length;d<l;d++)if(s[a=i[d]]){if(!(f=s[a](e.slice(c),i[0])).length)break;c+=f.length,u[f.token||a.charAt(0)]=f.value,u._match++}else if(a===e.charAt(c)||" "===a)c++;else{if(!o.test(a)||e.slice(c).indexOf(o.exec(a)[1])){if("..."===a){c=e.length;break}break}c+=a.length-2}return u.H=u.H||s.h12(u.h,u.A),u._index=c,u._length=e.length,u},a.parse=function(e,n,r){var i=this||t,u="string"==typeof n?i.compile(n):n,o=i.preparse(e,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)},a.isValid=function(e,n){var r=this||t,i="string"==typeof e?r.preparse(e,n):e,u=[31,28+r.isLeapYear(i.Y)|0,31,30,31,30,31,31,30,31,30,31][i.M-1];return!(i._index<1||i._length<1||i._index-i._length||i._match<1||i.Y<1||i.Y>9999||i.M<1||i.M>12||i.D<1||i.D>u||i.H<0||i.H>23||i.m<0||i.m>59||i.s<0||i.s>59||i.S<0||i.S>999||i.Z<-840||i.Z>720)},a.transform=function(e,n,r,i){const u=this||t;return u.format(u.parse(e,n),r,i)},a.addYears=function(e,n){return(this||t).addMonths(e,12*n)},a.addMonths=function(e,t){var n=new Date(e.getTime());return n.setUTCMonth(n.getUTCMonth()+t),n},a.addDays=function(e,t){var n=new Date(e.getTime());return n.setUTCDate(n.getUTCDate()+t),n},a.addHours=function(e,n){return(this||t).addMinutes(e,60*n)},a.addMinutes=function(e,n){return(this||t).addSeconds(e,60*n)},a.addSeconds=function(e,n){return(this||t).addMilliseconds(e,1e3*n)},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,t){n[e]||(n[e]=t)},a.plugin=function(e,t){r[e]||(r[e]=t)},e=c(a),(t=c(a)).locale=function(f){var d="function"==typeof f?f:t.locale[f];if(!d)return i;i=d(a);var l=n[i]||{},h=c(u,l.res,!0),M=c(o,l.formatter,!0,h),g=c(s,l.parser,!0,h);for(var p in t._formatter=e._formatter=M,t._parser=e._parser=g,r)t.extend(r[p]);return i},t.extend=function(e){var n=c(t._parser.res,e.res),r=e.extender||{};for(var i in t._formatter=c(t._formatter,e.formatter,!1,n),t._parser=c(t._parser,e.parser,!1,n),r)t[i]||(t[i]=r[i])},t.plugin=function(n){var i="function"==typeof n?n:t.plugin[n];i&&t.extend(r[i(a,e)]||{})},t}));
4
+ */var e,t,n={},r={},i="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"]},o={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},s={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:u},c=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},a={_formatter:o,_parser:s};return a.compile=function(e){for(var t,n=/\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g,r=[e];t=n.exec(e);)r[r.length]=t[0];return r},a.format=function(e,n,r){var i=this||t,u="string"==typeof n?i.compile(n):n,o=e.getTimezoneOffset(),s=i.addMinutes(e,r?o:0),c=i._formatter,a="";s.getTimezoneOffset=function(){return r?0:o};for(var f,d=1,l=u.length;d<l;d++)a+=c[f=u[d]]?c.post(c[f](s,u[0])):f.replace(/\[(.*)]/,"$1");return a},a.preparse=function(e,n){var r=this||t,i="string"==typeof n?r.compile(n):n,u={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},o=/\[(.*)]/,s=r._parser,c=0;e=s.pre(e);for(var a,f,d=1,l=i.length;d<l;d++)if(s[a=i[d]]){if(!(f=s[a](e.slice(c),i[0])).length)break;c+=f.length,u[f.token||a.charAt(0)]=f.value,u._match++}else if(a===e.charAt(c)||" "===a)c++;else{if(!o.test(a)||e.slice(c).indexOf(o.exec(a)[1])){if("..."===a){c=e.length;break}break}c+=a.length-2}return u.H=u.H||s.h12(u.h,u.A),u._index=c,u._length=e.length,u},a.parse=function(e,n,r){var i=this||t,u="string"==typeof n?i.compile(n):n,o=i.preparse(e,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)},a.isValid=function(e,n){var r=this||t,i="string"==typeof e?r.preparse(e,n):e,u=[31,28+r.isLeapYear(i.Y)|0,31,30,31,30,31,31,30,31,30,31][i.M-1];return!(i._index<1||i._length<1||i._index-i._length||i._match<1||i.Y<1||i.Y>9999||i.M<1||i.M>12||i.D<1||i.D>u||i.H<0||i.H>23||i.m<0||i.m>59||i.s<0||i.s>59||i.S<0||i.S>999||i.Z<-840||i.Z>720)},a.transform=function(e,n,r,i){const u=this||t;return u.format(u.parse(e,n),r,i)},a.addYears=function(e,n,r){return(this||t).addMonths(e,12*n,r)},a.addMonths=function(e,t,n){var r=new Date(e.getTime());return n?r.setUTCMonth(r.getUTCMonth()+t):r.setMonth(r.getMonth()+t),r},a.addDays=function(e,n,r){return(this||t).addHours(e,24*n,r)},a.addHours=function(e,n,r){return(this||t).addMinutes(e,60*n,r)},a.addMinutes=function(e,n,r){return(this||t).addSeconds(e,60*n,r)},a.addSeconds=function(e,n,r){return(this||t).addMilliseconds(e,1e3*n,r)},a.addMilliseconds=function(e,t,n){var r=new Date(e.getTime());return n?r.setUTCMilliseconds(r.getUTCMilliseconds()+t):r.setMilliseconds(r.getMilliseconds()+t),r},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,t){n[e]||(n[e]=t)},a.plugin=function(e,t){r[e]||(r[e]=t)},e=c(a),(t=c(a)).locale=function(f){var d="function"==typeof f?f:t.locale[f];if(!d)return i;i=d(a);var l=n[i]||{},h=c(u,l.res,!0),M=c(o,l.formatter,!0,h),g=c(s,l.parser,!0,h);for(var p in t._formatter=e._formatter=M,t._parser=e._parser=g,r)t.extend(r[p]);return i},t.extend=function(e){var n=c(t._parser.res,e.res),r=e.extender||{};for(var i in t._formatter=c(t._formatter,e.formatter,!1,n),t._parser=c(t._parser,e.parser,!1,n),r)t[i]||(t[i]=r[i])},t.plugin=function(n){var i="function"==typeof n?n:t.plugin[n];i&&t.extend(r[i(a,e)]||{})},t}));
@@ -270,22 +270,28 @@ proto.transform = function (dateString, arg1, arg2, utc) {
270
270
  * Adding years
271
271
  * @param {Date} dateObj - A Date object
272
272
  * @param {number} years - Number of years to add
273
+ * @param {boolean} [utc] - Calculates as UTC
273
274
  * @returns {Date} The Date object after adding the value
274
275
  */
275
- proto.addYears = function (dateObj, years) {
276
- return (this || date).addMonths(dateObj, years * 12);
276
+ proto.addYears = function (dateObj, years, utc) {
277
+ return (this || date).addMonths(dateObj, years * 12, utc);
277
278
  };
278
279
 
279
280
  /**
280
281
  * Adding months
281
282
  * @param {Date} dateObj - A Date object
282
283
  * @param {number} months - Number of months to add
284
+ * @param {boolean} [utc] - Calculates as UTC
283
285
  * @returns {Date} The Date object after adding the value
284
286
  */
285
- proto.addMonths = function (dateObj, months) {
287
+ proto.addMonths = function (dateObj, months, utc) {
286
288
  var d = new Date(dateObj.getTime());
287
289
 
288
- d.setUTCMonth(d.getUTCMonth() + months);
290
+ if (utc) {
291
+ d.setUTCMonth(d.getUTCMonth() + months);
292
+ } else {
293
+ d.setMonth(d.getMonth() + months);
294
+ }
289
295
  return d;
290
296
  };
291
297
 
@@ -293,53 +299,62 @@ proto.addMonths = function (dateObj, months) {
293
299
  * Adding days
294
300
  * @param {Date} dateObj - A Date object
295
301
  * @param {number} days - Number of days to add
302
+ * @param {boolean} [utc] - Calculates as UTC
296
303
  * @returns {Date} The Date object after adding the value
297
304
  */
298
- proto.addDays = function (dateObj, days) {
299
- var d = new Date(dateObj.getTime());
300
-
301
- d.setUTCDate(d.getUTCDate() + days);
302
- return d;
305
+ proto.addDays = function (dateObj, days, utc) {
306
+ return (this || date).addHours(dateObj, days * 24, utc);
303
307
  };
304
308
 
305
309
  /**
306
310
  * Adding hours
307
311
  * @param {Date} dateObj - A Date object
308
312
  * @param {number} hours - Number of hours to add
313
+ * @param {boolean} [utc] - Calculates as UTC
309
314
  * @returns {Date} The Date object after adding the value
310
315
  */
311
- proto.addHours = function (dateObj, hours) {
312
- return (this || date).addMinutes(dateObj, hours * 60);
316
+ proto.addHours = function (dateObj, hours, utc) {
317
+ return (this || date).addMinutes(dateObj, hours * 60, utc);
313
318
  };
314
319
 
315
320
  /**
316
321
  * Adding minutes
317
322
  * @param {Date} dateObj - A Date object
318
323
  * @param {number} minutes - Number of minutes to add
324
+ * @param {boolean} [utc] - Calculates as UTC
319
325
  * @returns {Date} The Date object after adding the value
320
326
  */
321
- proto.addMinutes = function (dateObj, minutes) {
322
- return (this || date).addSeconds(dateObj, minutes * 60);
327
+ proto.addMinutes = function (dateObj, minutes, utc) {
328
+ return (this || date).addSeconds(dateObj, minutes * 60, utc);
323
329
  };
324
330
 
325
331
  /**
326
332
  * Adding seconds
327
333
  * @param {Date} dateObj - A Date object
328
334
  * @param {number} seconds - Number of seconds to add
335
+ * @param {boolean} [utc] - Calculates as UTC
329
336
  * @returns {Date} The Date object after adding the value
330
337
  */
331
- proto.addSeconds = function (dateObj, seconds) {
332
- return (this || date).addMilliseconds(dateObj, seconds * 1000);
338
+ proto.addSeconds = function (dateObj, seconds, utc) {
339
+ return (this || date).addMilliseconds(dateObj, seconds * 1000, utc);
333
340
  };
334
341
 
335
342
  /**
336
343
  * Adding milliseconds
337
344
  * @param {Date} dateObj - A Date object
338
345
  * @param {number} milliseconds - Number of milliseconds to add
346
+ * @param {boolean} [utc] - Calculates as UTC
339
347
  * @returns {Date} The Date object after adding the value
340
348
  */
341
- proto.addMilliseconds = function (dateObj, milliseconds) {
342
- return new Date(dateObj.getTime() + milliseconds);
349
+ proto.addMilliseconds = function (dateObj, milliseconds, utc) {
350
+ var d = new Date(dateObj.getTime());
351
+
352
+ if (utc) {
353
+ d.setUTCMilliseconds(d.getUTCMilliseconds() + milliseconds);
354
+ } else {
355
+ d.setMilliseconds(d.getMilliseconds() + milliseconds);
356
+ }
357
+ return d;
343
358
  };
344
359
 
345
360
  /**
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * @preserve date-and-time (c) KNOWLEDGECODE | MIT
3
3
  */
4
- var e,t,n={},r={},u="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"]},o={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},s={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:i},c=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:o,_parser:s};a.compile=function(e){for(var t,n=/\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g,r=[e];t=n.exec(e);)r[r.length]=t[0];return r},a.format=function(e,n,r){var u=this||t,i="string"==typeof n?u.compile(n):n,o=e.getTimezoneOffset(),s=u.addMinutes(e,r?o:0),c=u._formatter,a="";s.getTimezoneOffset=function(){return r?0:o};for(var f,d=1,h=i.length;d<h;d++)a+=c[f=i[d]]?c.post(c[f](s,i[0])):f.replace(/\[(.*)]/,"$1");return a},a.preparse=function(e,n){var r=this||t,u="string"==typeof n?r.compile(n):n,i={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},o=/\[(.*)]/,s=r._parser,c=0;e=s.pre(e);for(var a,f,d=1,h=u.length;d<h;d++)if(s[a=u[d]]){if(!(f=s[a](e.slice(c),u[0])).length)break;c+=f.length,i[f.token||a.charAt(0)]=f.value,i._match++}else if(a===e.charAt(c)||" "===a)c++;else{if(!o.test(a)||e.slice(c).indexOf(o.exec(a)[1])){if("..."===a){c=e.length;break}break}c+=a.length-2}return i.H=i.H||s.h12(i.h,i.A),i._index=c,i._length=e.length,i},a.parse=function(e,n,r){var u=this||t,i="string"==typeof n?u.compile(n):n,o=u.preparse(e,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(e,n){var r=this||t,u="string"==typeof e?r.preparse(e,n):e,i=[31,28+r.isLeapYear(u.Y)|0,31,30,31,30,31,31,30,31,30,31][u.M-1];return!(u._index<1||u._length<1||u._index-u._length||u._match<1||u.Y<1||u.Y>9999||u.M<1||u.M>12||u.D<1||u.D>i||u.H<0||u.H>23||u.m<0||u.m>59||u.s<0||u.s>59||u.S<0||u.S>999||u.Z<-840||u.Z>720)},a.transform=function(e,n,r,u){const i=this||t;return i.format(i.parse(e,n),r,u)},a.addYears=function(e,n){return(this||t).addMonths(e,12*n)},a.addMonths=function(e,t){var n=new Date(e.getTime());return n.setUTCMonth(n.getUTCMonth()+t),n},a.addDays=function(e,t){var n=new Date(e.getTime());return n.setUTCDate(n.getUTCDate()+t),n},a.addHours=function(e,n){return(this||t).addMinutes(e,60*n)},a.addMinutes=function(e,n){return(this||t).addSeconds(e,60*n)},a.addSeconds=function(e,n){return(this||t).addMilliseconds(e,1e3*n)},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,t){n[e]||(n[e]=t)},a.plugin=function(e,t){r[e]||(r[e]=t)},e=c(a),(t=c(a)).locale=function(f){var d="function"==typeof f?f:t.locale[f];if(!d)return u;u=d(a);var h=n[u]||{},l=c(i,h.res,!0),M=c(o,h.formatter,!0,l),g=c(s,h.parser,!0,l);for(var p in t._formatter=e._formatter=M,t._parser=e._parser=g,r)t.extend(r[p]);return u},t.extend=function(e){var n=c(t._parser.res,e.res),r=e.extender||{};for(var u in t._formatter=c(t._formatter,e.formatter,!1,n),t._parser=c(t._parser,e.parser,!1,n),r)t[u]||(t[u]=r[u])},t.plugin=function(n){var u="function"==typeof n?n:t.plugin[n];u&&t.extend(r[u(a,e)]||{})};var f=t;export{f as default};
4
+ var e,t,n={},r={},i="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"]},s={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,i=0,u=0,s=e.length;u<s;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:u},c=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},a={_formatter:s,_parser:o};a.compile=function(e){for(var t,n=/\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g,r=[e];t=n.exec(e);)r[r.length]=t[0];return r},a.format=function(e,n,r){var i=this||t,u="string"==typeof n?i.compile(n):n,s=e.getTimezoneOffset(),o=i.addMinutes(e,r?s:0),c=i._formatter,a="";o.getTimezoneOffset=function(){return r?0:s};for(var f,d=1,l=u.length;d<l;d++)a+=c[f=u[d]]?c.post(c[f](o,u[0])):f.replace(/\[(.*)]/,"$1");return a},a.preparse=function(e,n){var r=this||t,i="string"==typeof n?r.compile(n):n,u={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=/\[(.*)]/,o=r._parser,c=0;e=o.pre(e);for(var a,f,d=1,l=i.length;d<l;d++)if(o[a=i[d]]){if(!(f=o[a](e.slice(c),i[0])).length)break;c+=f.length,u[f.token||a.charAt(0)]=f.value,u._match++}else if(a===e.charAt(c)||" "===a)c++;else{if(!s.test(a)||e.slice(c).indexOf(s.exec(a)[1])){if("..."===a){c=e.length;break}break}c+=a.length-2}return u.H=u.H||o.h12(u.h,u.A),u._index=c,u._length=e.length,u},a.parse=function(e,n,r){var i=this||t,u="string"==typeof n?i.compile(n):n,s=i.preparse(e,u);return i.isValid(s)?(s.M-=s.Y<100?22801:1,r||~i._parser.find(u,"ZZ").value?new Date(Date.UTC(s.Y,s.M,s.D,s.H,s.m+s.Z,s.s,s.S)):new Date(s.Y,s.M,s.D,s.H,s.m,s.s,s.S)):new Date(NaN)},a.isValid=function(e,n){var r=this||t,i="string"==typeof e?r.preparse(e,n):e,u=[31,28+r.isLeapYear(i.Y)|0,31,30,31,30,31,31,30,31,30,31][i.M-1];return!(i._index<1||i._length<1||i._index-i._length||i._match<1||i.Y<1||i.Y>9999||i.M<1||i.M>12||i.D<1||i.D>u||i.H<0||i.H>23||i.m<0||i.m>59||i.s<0||i.s>59||i.S<0||i.S>999||i.Z<-840||i.Z>720)},a.transform=function(e,n,r,i){const u=this||t;return u.format(u.parse(e,n),r,i)},a.addYears=function(e,n,r){return(this||t).addMonths(e,12*n,r)},a.addMonths=function(e,t,n){var r=new Date(e.getTime());return n?r.setUTCMonth(r.getUTCMonth()+t):r.setMonth(r.getMonth()+t),r},a.addDays=function(e,n,r){return(this||t).addHours(e,24*n,r)},a.addHours=function(e,n,r){return(this||t).addMinutes(e,60*n,r)},a.addMinutes=function(e,n,r){return(this||t).addSeconds(e,60*n,r)},a.addSeconds=function(e,n,r){return(this||t).addMilliseconds(e,1e3*n,r)},a.addMilliseconds=function(e,t,n){var r=new Date(e.getTime());return n?r.setUTCMilliseconds(r.getUTCMilliseconds()+t):r.setMilliseconds(r.getMilliseconds()+t),r},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,t){n[e]||(n[e]=t)},a.plugin=function(e,t){r[e]||(r[e]=t)},e=c(a),(t=c(a)).locale=function(f){var d="function"==typeof f?f:t.locale[f];if(!d)return i;i=d(a);var l=n[i]||{},h=c(u,l.res,!0),M=c(s,l.formatter,!0,h),g=c(o,l.parser,!0,h);for(var p in t._formatter=e._formatter=M,t._parser=e._parser=g,r)t.extend(r[p]);return i},t.extend=function(e){var n=c(t._parser.res,e.res),r=e.extender||{};for(var i in t._formatter=c(t._formatter,e.formatter,!1,n),t._parser=c(t._parser,e.parser,!1,n),r)t[i]||(t[i]=r[i])},t.plugin=function(n){var i="function"==typeof n?n:t.plugin[n];i&&t.extend(r[i(a,e)]||{})};var f=t;export{f as default};
@@ -270,22 +270,28 @@ proto.transform = function (dateString, arg1, arg2, utc) {
270
270
  * Adding years
271
271
  * @param {Date} dateObj - A Date object
272
272
  * @param {number} years - Number of years to add
273
+ * @param {boolean} [utc] - Calculates as UTC
273
274
  * @returns {Date} The Date object after adding the value
274
275
  */
275
- proto.addYears = function (dateObj, years) {
276
- return (this || date).addMonths(dateObj, years * 12);
276
+ proto.addYears = function (dateObj, years, utc) {
277
+ return (this || date).addMonths(dateObj, years * 12, utc);
277
278
  };
278
279
 
279
280
  /**
280
281
  * Adding months
281
282
  * @param {Date} dateObj - A Date object
282
283
  * @param {number} months - Number of months to add
284
+ * @param {boolean} [utc] - Calculates as UTC
283
285
  * @returns {Date} The Date object after adding the value
284
286
  */
285
- proto.addMonths = function (dateObj, months) {
287
+ proto.addMonths = function (dateObj, months, utc) {
286
288
  var d = new Date(dateObj.getTime());
287
289
 
288
- d.setUTCMonth(d.getUTCMonth() + months);
290
+ if (utc) {
291
+ d.setUTCMonth(d.getUTCMonth() + months);
292
+ } else {
293
+ d.setMonth(d.getMonth() + months);
294
+ }
289
295
  return d;
290
296
  };
291
297
 
@@ -293,53 +299,62 @@ proto.addMonths = function (dateObj, months) {
293
299
  * Adding days
294
300
  * @param {Date} dateObj - A Date object
295
301
  * @param {number} days - Number of days to add
302
+ * @param {boolean} [utc] - Calculates as UTC
296
303
  * @returns {Date} The Date object after adding the value
297
304
  */
298
- proto.addDays = function (dateObj, days) {
299
- var d = new Date(dateObj.getTime());
300
-
301
- d.setUTCDate(d.getUTCDate() + days);
302
- return d;
305
+ proto.addDays = function (dateObj, days, utc) {
306
+ return (this || date).addHours(dateObj, days * 24, utc);
303
307
  };
304
308
 
305
309
  /**
306
310
  * Adding hours
307
311
  * @param {Date} dateObj - A Date object
308
312
  * @param {number} hours - Number of hours to add
313
+ * @param {boolean} [utc] - Calculates as UTC
309
314
  * @returns {Date} The Date object after adding the value
310
315
  */
311
- proto.addHours = function (dateObj, hours) {
312
- return (this || date).addMinutes(dateObj, hours * 60);
316
+ proto.addHours = function (dateObj, hours, utc) {
317
+ return (this || date).addMinutes(dateObj, hours * 60, utc);
313
318
  };
314
319
 
315
320
  /**
316
321
  * Adding minutes
317
322
  * @param {Date} dateObj - A Date object
318
323
  * @param {number} minutes - Number of minutes to add
324
+ * @param {boolean} [utc] - Calculates as UTC
319
325
  * @returns {Date} The Date object after adding the value
320
326
  */
321
- proto.addMinutes = function (dateObj, minutes) {
322
- return (this || date).addSeconds(dateObj, minutes * 60);
327
+ proto.addMinutes = function (dateObj, minutes, utc) {
328
+ return (this || date).addSeconds(dateObj, minutes * 60, utc);
323
329
  };
324
330
 
325
331
  /**
326
332
  * Adding seconds
327
333
  * @param {Date} dateObj - A Date object
328
334
  * @param {number} seconds - Number of seconds to add
335
+ * @param {boolean} [utc] - Calculates as UTC
329
336
  * @returns {Date} The Date object after adding the value
330
337
  */
331
- proto.addSeconds = function (dateObj, seconds) {
332
- return (this || date).addMilliseconds(dateObj, seconds * 1000);
338
+ proto.addSeconds = function (dateObj, seconds, utc) {
339
+ return (this || date).addMilliseconds(dateObj, seconds * 1000, utc);
333
340
  };
334
341
 
335
342
  /**
336
343
  * Adding milliseconds
337
344
  * @param {Date} dateObj - A Date object
338
345
  * @param {number} milliseconds - Number of milliseconds to add
346
+ * @param {boolean} [utc] - Calculates as UTC
339
347
  * @returns {Date} The Date object after adding the value
340
348
  */
341
- proto.addMilliseconds = function (dateObj, milliseconds) {
342
- return new Date(dateObj.getTime() + milliseconds);
349
+ proto.addMilliseconds = function (dateObj, milliseconds, utc) {
350
+ var d = new Date(dateObj.getTime());
351
+
352
+ if (utc) {
353
+ d.setUTCMilliseconds(d.getUTCMilliseconds() + milliseconds);
354
+ } else {
355
+ d.setMilliseconds(d.getMilliseconds() + milliseconds);
356
+ }
357
+ return d;
343
358
  };
344
359
 
345
360
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "date-and-time",
3
- "version": "2.4.3",
3
+ "version": "3.0.0",
4
4
  "description": "A Minimalist DateTime utility for Node.js and the browser",
5
5
  "main": "date-and-time.js",
6
6
  "module": "esm/date-and-time.es.js",
@@ -46,11 +46,10 @@
46
46
  },
47
47
  "homepage": "https://github.com/knowledgecode/date-and-time",
48
48
  "devDependencies": {
49
- "@rollup/plugin-terser": "^0.4.0",
49
+ "@rollup/plugin-terser": "^0.4.1",
50
50
  "expect.js": "^0.3.1",
51
51
  "mocha": "^10.2.0",
52
- "mocha-headless-chrome": "^4.0.0",
53
- "rollup": "^3.19.1",
54
- "tsd": "^0.27.0"
52
+ "rollup": "^3.20.7",
53
+ "tsd": "^0.28.1"
55
54
  }
56
55
  }