date-and-time 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,15 +25,16 @@ npm i date-and-time
25
25
 
26
26
  ## Recent Changes
27
27
 
28
+ - 3.0.1
29
+ - Fixed calculation of last day of month in `addYears()` and `addMonths()`.
30
+ - Fixed lint errors.
31
+
28
32
  - 3.0.0
29
33
  - **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
34
 
31
35
  - 2.4.3
32
36
  - Fixed an issue where using `addMonths()` in timezones with daylight saving time returned incorrect results.
33
37
 
34
- - 2.4.2
35
- - Fixed an issue where the timezone plugin stopped working due to Node.js timezone update.
36
-
37
38
  ## Usage
38
39
 
39
40
  - ES Modules:
@@ -432,31 +433,51 @@ date.transform('13:05', 'HH:mm', 'hh:mm A');
432
433
 
433
434
  - @param {**Date**} dateObj - A Date object
434
435
  - @param {**number**} years - Number of years to add
435
- - @param {**boolean**} [utc] - Calculates as UTC
436
+ - @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
436
437
  - @returns {**Date**} The Date object after adding the value
437
438
 
439
+ Adds years to the date object.
440
+
438
441
  ```javascript
439
442
  const now = new Date();
440
443
  const next_year = date.addYears(now, 1);
441
444
  ```
442
445
 
446
+ Exceptional behavior of the calculation for the last day of the month:
447
+
448
+ ```javascript
449
+ const now = new Date(Date.UTC(2020, 1, 29)); // => Feb 29 2020
450
+ const next_year = date.addYears(now, 1, true); // => Feb 28 2021
451
+ const next_next_year = date.addYears(next_year, 1, true); // => Feb 28 2022
452
+ ```
453
+
443
454
  ### addMonths(dateObj, months[, utc])
444
455
 
445
456
  - @param {**Date**} dateObj - A Date object
446
457
  - @param {**number**} months - Number of months to add
447
- - @param {**boolean**} [utc] - Calculates as UTC
458
+ - @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
448
459
  - @returns {**Date**} The Date object after adding the value
449
460
 
461
+ Adds months to the date object.
462
+
450
463
  ```javascript
451
464
  const now = new Date();
452
465
  const next_month = date.addMonths(now, 1);
453
466
  ```
454
467
 
468
+ Exceptional behavior of the calculation for the last day of the month:
469
+
470
+ ```javascript
471
+ const now = new Date(Date.UTC(2023, 0, 31)); // => Jan 31 2023
472
+ const next_month = date.addMonths(now, 1, true); // => Feb 28 2023
473
+ const next_next_month = date.addMonths(next_month, 1, true); // => Mar 28 2023
474
+ ```
475
+
455
476
  ### addDays(dateObj, days[, utc])
456
477
 
457
478
  - @param {**Date**} dateObj - A Date object
458
479
  - @param {**number**} days - Number of days to add
459
- - @param {**boolean**} [utc] - Calculates as UTC
480
+ - @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
460
481
  - @returns {**Date**} The Date object after adding the value
461
482
 
462
483
  ```javascript
@@ -468,7 +489,7 @@ const yesterday = date.addDays(now, -1);
468
489
 
469
490
  - @param {**Date**} dateObj - A Date object
470
491
  - @param {**number**} hours - Number of hours to add
471
- - @param {**boolean**} [utc] - Calculates as UTC
492
+ - @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
472
493
  - @returns {**Date**} The Date object after adding the value
473
494
 
474
495
  ```javascript
@@ -480,7 +501,7 @@ const an_hour_ago = date.addHours(now, -1);
480
501
 
481
502
  - @param {**Date**} dateObj - A Date object
482
503
  - @param {**number**} minutes - Number of minutes to add
483
- - @param {**boolean**} [utc] - Calculates as UTC
504
+ - @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
484
505
  - @returns {**Date**} The Date object after adding the value
485
506
 
486
507
  ```javascript
@@ -492,7 +513,7 @@ const two_minutes_later = date.addMinutes(now, 2);
492
513
 
493
514
  - @param {**Date**} dateObj - A Date object
494
515
  - @param {**number**} seconds - Number of seconds to add
495
- - @param {**boolean**} [utc] - Calculates as UTC
516
+ - @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
496
517
  - @returns {**Date**} The Date object after adding the value
497
518
 
498
519
  ```javascript
@@ -504,7 +525,7 @@ const three_seconds_ago = date.addSeconds(now, -3);
504
525
 
505
526
  - @param {**Date**} dateObj - A Date object
506
527
  - @param {**number**} milliseconds - Number of milliseconds to add
507
- - @param {**boolean**} [utc] - Calculates as UTC
528
+ - @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
508
529
  - @returns {**Date**} The Date object after adding the value
509
530
 
510
531
  ```javascript
package/date-and-time.js CHANGED
@@ -94,12 +94,12 @@
94
94
  return result;
95
95
  },
96
96
  Z: function (str/*, formatString */) {
97
- var result = this.exec(/^[\+-]\d{2}[0-5]\d/, str);
97
+ var result = this.exec(/^[+-]\d{2}[0-5]\d/, str);
98
98
  result.value = (result.value / 100 | 0) * -60 - result.value % 100;
99
99
  return result;
100
100
  },
101
101
  ZZ: function (str/*, formatString */) {
102
- var arr = /^([\+-])(\d{2}):([0-5]\d)/.exec(str) || ['', '', '', ''];
102
+ var arr = /^([+-])(\d{2}):([0-5]\d)/.exec(str) || ['', '', '', ''];
103
103
  return { value: 0 - ((arr[1] + arr[2] | 0) * 60 + (arr[1] + arr[3] | 0)), length: arr[0].length };
104
104
  },
105
105
  h12: function (h, a) { return (h === 12 ? 0 : h) + a * 12; },
@@ -151,7 +151,7 @@
151
151
  * @returns {Array.<string>} A compiled object
152
152
  */
153
153
  proto.compile = function (formatString) {
154
- var re = /\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g, keys, pattern = [formatString];
154
+ var re = /\[([^[\]]|\[[^[\]]*])*]|([A-Za-z])\2+|\.{3}|./g, keys, pattern = [formatString];
155
155
 
156
156
  while ((keys = re.exec(formatString))) {
157
157
  pattern[pattern.length] = keys[0];
@@ -214,7 +214,7 @@
214
214
  break;
215
215
  }
216
216
  }
217
- dt.H = dt.H || parser.h12(dt.h, dt.A);
217
+ dt.H ||= dt.H || parser.h12(dt.h, dt.A);
218
218
  dt._index = offset;
219
219
  dt._length = dateString.length;
220
220
  return dt;
@@ -295,8 +295,14 @@
295
295
 
296
296
  if (utc) {
297
297
  d.setUTCMonth(d.getUTCMonth() + months);
298
+ if (d.getUTCDate() < dateObj.getUTCDate()) {
299
+ return (this || date).addDays(d, -d.getUTCDate(), utc);
300
+ }
298
301
  } else {
299
302
  d.setMonth(d.getMonth() + months);
303
+ if (d.getDate() < dateObj.getDate()) {
304
+ return (this || date).addDays(d, -d.getDate(), utc);
305
+ }
300
306
  }
301
307
  return d;
302
308
  };
@@ -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,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}));
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};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,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,n,r){var i=new Date(e.getTime());if(r){if(i.setUTCMonth(i.getUTCMonth()+n),i.getUTCDate()<e.getUTCDate())return(this||t).addDays(i,-i.getUTCDate(),r)}else if(i.setMonth(i.getMonth()+n),i.getDate()<e.getDate())return(this||t).addDays(i,-i.getDate(),r);return i},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)]||{})},t}));
@@ -88,12 +88,12 @@ var locales = {},
88
88
  return result;
89
89
  },
90
90
  Z: function (str/*, formatString */) {
91
- var result = this.exec(/^[\+-]\d{2}[0-5]\d/, str);
91
+ var result = this.exec(/^[+-]\d{2}[0-5]\d/, str);
92
92
  result.value = (result.value / 100 | 0) * -60 - result.value % 100;
93
93
  return result;
94
94
  },
95
95
  ZZ: function (str/*, formatString */) {
96
- var arr = /^([\+-])(\d{2}):([0-5]\d)/.exec(str) || ['', '', '', ''];
96
+ var arr = /^([+-])(\d{2}):([0-5]\d)/.exec(str) || ['', '', '', ''];
97
97
  return { value: 0 - ((arr[1] + arr[2] | 0) * 60 + (arr[1] + arr[3] | 0)), length: arr[0].length };
98
98
  },
99
99
  h12: function (h, a) { return (h === 12 ? 0 : h) + a * 12; },
@@ -145,7 +145,7 @@ var locales = {},
145
145
  * @returns {Array.<string>} A compiled object
146
146
  */
147
147
  proto.compile = function (formatString) {
148
- var re = /\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g, keys, pattern = [formatString];
148
+ var re = /\[([^[\]]|\[[^[\]]*])*]|([A-Za-z])\2+|\.{3}|./g, keys, pattern = [formatString];
149
149
 
150
150
  while ((keys = re.exec(formatString))) {
151
151
  pattern[pattern.length] = keys[0];
@@ -208,7 +208,7 @@ proto.preparse = function (dateString, arg) {
208
208
  break;
209
209
  }
210
210
  }
211
- dt.H = dt.H || parser.h12(dt.h, dt.A);
211
+ dt.H ||= dt.H || parser.h12(dt.h, dt.A);
212
212
  dt._index = offset;
213
213
  dt._length = dateString.length;
214
214
  return dt;
@@ -289,8 +289,14 @@ proto.addMonths = function (dateObj, months, utc) {
289
289
 
290
290
  if (utc) {
291
291
  d.setUTCMonth(d.getUTCMonth() + months);
292
+ if (d.getUTCDate() < dateObj.getUTCDate()) {
293
+ return (this || date).addDays(d, -d.getUTCDate(), utc);
294
+ }
292
295
  } else {
293
296
  d.setMonth(d.getMonth() + months);
297
+ if (d.getDate() < dateObj.getDate()) {
298
+ return (this || date).addDays(d, -d.getDate(), utc);
299
+ }
294
300
  }
295
301
  return d;
296
302
  };
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * @preserve date-and-time (c) KNOWLEDGECODE | MIT
3
3
  */
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};
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},a=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:s,_parser:o};c.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},c.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),a=i._formatter,c="";o.getTimezoneOffset=function(){return r?0:s};for(var d,f=1,l=u.length;f<l;f++)c+=a[d=u[f]]?a.post(a[d](o,u[0])):d.replace(/\[(.*)]/,"$1");return c},c.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,a=0;e=o.pre(e);for(var c,d,f=1,l=i.length;f<l;f++)if(o[c=i[f]]){if(!(d=o[c](e.slice(a),i[0])).length)break;a+=d.length,u[d.token||c.charAt(0)]=d.value,u._match++}else if(c===e.charAt(a)||" "===c)a++;else{if(!s.test(c)||e.slice(a).indexOf(s.exec(c)[1])){if("..."===c){a=e.length;break}break}a+=c.length-2}return u.H||=u.H||o.h12(u.h,u.A),u._index=a,u._length=e.length,u},c.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)},c.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)},c.transform=function(e,n,r,i){const u=this||t;return u.format(u.parse(e,n),r,i)},c.addYears=function(e,n,r){return(this||t).addMonths(e,12*n,r)},c.addMonths=function(e,n,r){var i=new Date(e.getTime());if(r){if(i.setUTCMonth(i.getUTCMonth()+n),i.getUTCDate()<e.getUTCDate())return(this||t).addDays(i,-i.getUTCDate(),r)}else if(i.setMonth(i.getMonth()+n),i.getDate()<e.getDate())return(this||t).addDays(i,-i.getDate(),r);return i},c.addDays=function(e,n,r){return(this||t).addHours(e,24*n,r)},c.addHours=function(e,n,r){return(this||t).addMinutes(e,60*n,r)},c.addMinutes=function(e,n,r){return(this||t).addSeconds(e,60*n,r)},c.addSeconds=function(e,n,r){return(this||t).addMilliseconds(e,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,t){n[e]||(n[e]=t)},c.plugin=function(e,t){r[e]||(r[e]=t)},e=a(c),(t=a(c)).locale=function(d){var f="function"==typeof d?d:t.locale[d];if(!f)return i;i=f(c);var l=n[i]||{},h=a(u,l.res,!0),M=a(s,l.formatter,!0,h),g=a(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=a(t._parser.res,e.res),r=e.extender||{};for(var i in t._formatter=a(t._formatter,e.formatter,!1,n),t._parser=a(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(c,e)]||{})};var d=t;export{d as default};
@@ -88,12 +88,12 @@ var locales = {},
88
88
  return result;
89
89
  },
90
90
  Z: function (str/*, formatString */) {
91
- var result = this.exec(/^[\+-]\d{2}[0-5]\d/, str);
91
+ var result = this.exec(/^[+-]\d{2}[0-5]\d/, str);
92
92
  result.value = (result.value / 100 | 0) * -60 - result.value % 100;
93
93
  return result;
94
94
  },
95
95
  ZZ: function (str/*, formatString */) {
96
- var arr = /^([\+-])(\d{2}):([0-5]\d)/.exec(str) || ['', '', '', ''];
96
+ var arr = /^([+-])(\d{2}):([0-5]\d)/.exec(str) || ['', '', '', ''];
97
97
  return { value: 0 - ((arr[1] + arr[2] | 0) * 60 + (arr[1] + arr[3] | 0)), length: arr[0].length };
98
98
  },
99
99
  h12: function (h, a) { return (h === 12 ? 0 : h) + a * 12; },
@@ -145,7 +145,7 @@ var locales = {},
145
145
  * @returns {Array.<string>} A compiled object
146
146
  */
147
147
  proto.compile = function (formatString) {
148
- var re = /\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g, keys, pattern = [formatString];
148
+ var re = /\[([^[\]]|\[[^[\]]*])*]|([A-Za-z])\2+|\.{3}|./g, keys, pattern = [formatString];
149
149
 
150
150
  while ((keys = re.exec(formatString))) {
151
151
  pattern[pattern.length] = keys[0];
@@ -208,7 +208,7 @@ proto.preparse = function (dateString, arg) {
208
208
  break;
209
209
  }
210
210
  }
211
- dt.H = dt.H || parser.h12(dt.h, dt.A);
211
+ dt.H ||= dt.H || parser.h12(dt.h, dt.A);
212
212
  dt._index = offset;
213
213
  dt._length = dateString.length;
214
214
  return dt;
@@ -289,8 +289,14 @@ proto.addMonths = function (dateObj, months, utc) {
289
289
 
290
290
  if (utc) {
291
291
  d.setUTCMonth(d.getUTCMonth() + months);
292
+ if (d.getUTCDate() < dateObj.getUTCDate()) {
293
+ return (this || date).addDays(d, -d.getUTCDate(), utc);
294
+ }
292
295
  } else {
293
296
  d.setMonth(d.getMonth() + months);
297
+ if (d.getDate() < dateObj.getDate()) {
298
+ return (this || date).addDays(d, -d.getDate(), utc);
299
+ }
294
300
  }
295
301
  return d;
296
302
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "date-and-time",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
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,10 +46,10 @@
46
46
  },
47
47
  "homepage": "https://github.com/knowledgecode/date-and-time",
48
48
  "devDependencies": {
49
- "@rollup/plugin-terser": "^0.4.1",
49
+ "@rollup/plugin-terser": "^0.4.3",
50
50
  "expect.js": "^0.3.1",
51
51
  "mocha": "^10.2.0",
52
- "rollup": "^3.20.7",
52
+ "rollup": "^3.25.0",
53
53
  "tsd": "^0.28.1"
54
54
  }
55
55
  }