!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?module.exports=s():"function"==typeof define&&define.amd?define(s):(t="undefined"!=typeof globalThis?globalThis:t||self).dayjs_plugin_duration=s()}(this,function(){"use strict";function r(t){return t instanceof $}function o(t,s,i){return new $(t,i,s.$l)}function e(t){return d.p(t)+"s"}function i(t){return t<0?Math.ceil(t):Math.floor(t)}function h(t,s){return t?t<0?{negative:!0,format:""+Math.abs(t)+s}:{negative:!1,format:""+t+s}:{negative:!1,format:""}}var u,d,t,s=36e5,n=864e5,a=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,c=31536e6,f=2592e6,m=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,l={years:c,months:f,days:n,hours:s,minutes:6e4,seconds:1e3,milliseconds:1,weeks:6048e5},$=((t=y.prototype).calMilliseconds=function(){var i=this;this.$ms=Object.keys(this.$d).reduce(function(t,s){return t+(i.$d[s]||0)*l[s]},0)},t.parseFromMilliseconds=function(){var t=this.$ms;this.$d.years=i(t/c),this.$d.months=i((t%=c)/f),this.$d.days=i((t%=f)/n),this.$d.hours=i((t%=n)/s),this.$d.minutes=i((t%=s)/6e4),this.$d.seconds=i((t%=6e4)/1e3),this.$d.milliseconds=t%=1e3},t.toISOString=function(){var t=h(this.$d.years,"Y"),s=h(this.$d.months,"M"),i=+this.$d.days||0,i=(this.$d.weeks&&(i+=7*this.$d.weeks),h(i,"D")),n=h(this.$d.hours,"H"),e=h(this.$d.minutes,"M"),r=this.$d.seconds||0,r=(this.$d.milliseconds&&(r+=this.$d.milliseconds/1e3),h(r,"S")),o=t.negative||s.negative||i.negative||n.negative||e.negative||r.negative,u=n.format||e.format||r.format?"T":"",o=(o?"-":"")+"P"+t.format+s.format+i.format+u+n.format+e.format+r.format;return"P"==o||"-P"==o?"P0D":o},t.toJSON=function(){return this.toISOString()},t.format=function(t){var t=t||"YYYY-MM-DDTHH:mm:ss",i={Y:this.$d.years,YY:d.s(this.$d.years,2,"0"),YYYY:d.s(this.$d.years,4,"0"),M:this.$d.months,MM:d.s(this.$d.months,2,"0"),D:this.$d.days,DD:d.s(this.$d.days,2,"0"),H:this.$d.hours,HH:d.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:d.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:d.s(this.$d.seconds,2,"0"),SSS:d.s(this.$d.milliseconds,3,"0")};return t.replace(a,function(t,s){return s||String(i[t])})},t.as=function(t){return this.$ms/l[e(t)]},t.get=function(t){var s=this.$ms,t=e(t);return"milliseconds"===t?s%=1e3:s="weeks"===t?i(s/l[t]):this.$d[t],0===s?0:s},t.add=function(t,s,i){s=s?t*l[e(s)]:(r(t)?t:o(t,this)).$ms;return o(this.$ms+s*(i?-1:1),this)},t.subtract=function(t,s){return this.add(t,s,!0)},t.locale=function(t){var s=this.clone();return s.$l=t,s},t.clone=function(){return o(this.$ms,this)},t.humanize=function(t){return u().add(this.$ms,"ms").locale(this.$l).fromNow(!t)},t.milliseconds=function(){return this.get("milliseconds")},t.asMilliseconds=function(){return this.as("milliseconds")},t.seconds=function(){return this.get("seconds")},t.asSeconds=function(){return this.as("seconds")},t.minutes=function(){return this.get("minutes")},t.asMinutes=function(){return this.as("minutes")},t.hours=function(){return this.get("hours")},t.asHours=function(){return this.as("hours")},t.days=function(){return this.get("days")},t.asDays=function(){return this.as("days")},t.weeks=function(){return this.get("weeks")},t.asWeeks=function(){return this.as("weeks")},t.months=function(){return this.get("months")},t.asMonths=function(){return this.as("months")},t.years=function(){return this.get("years")},t.asYears=function(){return this.as("years")},y);function y(s,t,i){var n=this;if(this.$d={},this.$l=i,void 0===s&&(this.$ms=0,this.parseFromMilliseconds()),t)return o(s*l[e(t)],this);if("number"==typeof s)return this.$ms=s,this.parseFromMilliseconds(),this;if("object"==typeof s)return Object.keys(s).forEach(function(t){n.$d[e(t)]=s[t]}),this.calMilliseconds(),this;if("string"==typeof s){i=s.match(m);if(i)return t=i.slice(2).map(function(t){return null!=t?Number(t):0}),this.$d.years=t[0],this.$d.months=t[1],this.$d.weeks=t[2],this.$d.days=t[3],this.$d.hours=t[4],this.$d.minutes=t[5],this.$d.seconds=t[6],this.calMilliseconds(),this}return this}return function(t,s,n){d=(u=n)().$utils(),n.duration=function(t,s){var i=n.locale();return o(t,{$l:i},s)},n.isDuration=r;var i=s.prototype.add,e=s.prototype.subtract;s.prototype.add=function(t,s){return r(t)&&(t=t.asMilliseconds()),i.bind(this)(t,s)},s.prototype.subtract=function(t,s){return r(t)&&(t=t.asMilliseconds()),e.bind(this)(t,s)}}});