You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
286 lines
8.6 KiB
286 lines
8.6 KiB
!(function (t, s) {
|
|
if ('object' == typeof exports && 'undefined' != typeof module) {
|
|
module.exports = s();
|
|
} else {
|
|
if ('function' == typeof define && define.amd) {
|
|
define(s);
|
|
} else {
|
|
(t = 'undefined' != typeof globalThis ? globalThis : t || self).dayjs_plugin_duration = s();
|
|
}
|
|
}
|
|
})(this, function () {
|
|
'use strict';
|
|
|
|
var t;
|
|
var s;
|
|
var n = 1000;
|
|
var i = 60000;
|
|
var e = 3600000;
|
|
var r = 86400000;
|
|
var o = /\[([^\]]+)]|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;
|
|
var u = 31536000000;
|
|
var h = 2592000000;
|
|
var a = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
|
|
var d = {
|
|
years: u,
|
|
months: h,
|
|
days: r,
|
|
hours: e,
|
|
minutes: i,
|
|
seconds: n,
|
|
milliseconds: 1,
|
|
weeks: 604800000
|
|
};
|
|
var c = function (t) {
|
|
return t instanceof p;
|
|
};
|
|
var f = function (t, s, n) {
|
|
return new p(t, n, s.$l);
|
|
};
|
|
var m = function (t) {
|
|
return s.p(t) + 's';
|
|
};
|
|
var l = function (t) {
|
|
return t < 0;
|
|
};
|
|
var $ = function (t) {
|
|
return l(t) ? Math.ceil(t) : Math.floor(t);
|
|
};
|
|
var y = function (t) {
|
|
return Math.abs(t);
|
|
};
|
|
var g = function (t, s) {
|
|
return t
|
|
? l(t)
|
|
? {
|
|
negative: true,
|
|
format: '' + y(t) + s
|
|
}
|
|
: {
|
|
negative: false,
|
|
format: '' + t + s
|
|
}
|
|
: {
|
|
negative: false,
|
|
format: ''
|
|
};
|
|
};
|
|
var p = (function () {
|
|
function l(t, s, n) {
|
|
var that = this;
|
|
this.$d = {};
|
|
this.$l = n;
|
|
if (void 0 === t) {
|
|
this.$ms = 0;
|
|
this.parseFromMilliseconds();
|
|
}
|
|
if (s) {
|
|
return f(t * d[m(s)], this);
|
|
}
|
|
if ('number' == typeof t) {
|
|
this.$ms = t;
|
|
this.parseFromMilliseconds();
|
|
return this;
|
|
}
|
|
if ('object' == typeof t) {
|
|
Object.keys(t).forEach(function (s) {
|
|
that.$d[m(s)] = t[s];
|
|
});
|
|
this.calMilliseconds();
|
|
return this;
|
|
}
|
|
if ('string' == typeof t) {
|
|
var e = t.match(a);
|
|
if (e) {
|
|
var r = e.slice(2).map(function (t) {
|
|
return null != t ? Number(t) : 0;
|
|
});
|
|
this.$d.years = r[0];
|
|
this.$d.months = r[1];
|
|
this.$d.weeks = r[2];
|
|
this.$d.days = r[3];
|
|
this.$d.hours = r[4];
|
|
this.$d.minutes = r[5];
|
|
this.$d.seconds = r[6];
|
|
this.calMilliseconds();
|
|
return this;
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
var y = l.prototype;
|
|
y.calMilliseconds = function () {
|
|
var that = this;
|
|
this.$ms = Object.keys(this.$d).reduce(function (s, n) {
|
|
return s + (that.$d[n] || 0) * d[n];
|
|
}, 0);
|
|
};
|
|
y.parseFromMilliseconds = function () {
|
|
var t = this.$ms;
|
|
this.$d.years = $(t / u);
|
|
t %= u;
|
|
this.$d.months = $(t / h);
|
|
t %= h;
|
|
this.$d.days = $(t / r);
|
|
t %= r;
|
|
this.$d.hours = $(t / e);
|
|
t %= e;
|
|
this.$d.minutes = $(t / i);
|
|
t %= i;
|
|
this.$d.seconds = $(t / n);
|
|
t %= n;
|
|
this.$d.milliseconds = t;
|
|
};
|
|
y.toISOString = function () {
|
|
var t = g(this.$d.years, 'Y');
|
|
var s = g(this.$d.months, 'M');
|
|
var n = +this.$d.days || 0;
|
|
if (this.$d.weeks) {
|
|
n += 7 * this.$d.weeks;
|
|
}
|
|
var i = g(n, 'D');
|
|
var e = g(this.$d.hours, 'H');
|
|
var r = g(this.$d.minutes, 'M');
|
|
var o = this.$d.seconds || 0;
|
|
if (this.$d.milliseconds) {
|
|
o += this.$d.milliseconds / 1000;
|
|
}
|
|
var u = g(o, 'S');
|
|
var h = t.negative || s.negative || i.negative || e.negative || r.negative || u.negative;
|
|
var a = e.format || r.format || u.format ? 'T' : '';
|
|
var d = (h ? '-' : '') + 'P' + t.format + s.format + i.format + a + e.format + r.format + u.format;
|
|
return 'P' === d || '-P' === d ? 'P0D' : d;
|
|
};
|
|
y.toJSON = function () {
|
|
return this.toISOString();
|
|
};
|
|
y.format = function (t) {
|
|
var n = t || 'YYYY-MM-DDTHH:mm:ss';
|
|
var i = {
|
|
Y: this.$d.years,
|
|
YY: s.s(this.$d.years, 2, '0'),
|
|
YYYY: s.s(this.$d.years, 4, '0'),
|
|
M: this.$d.months,
|
|
MM: s.s(this.$d.months, 2, '0'),
|
|
D: this.$d.days,
|
|
DD: s.s(this.$d.days, 2, '0'),
|
|
H: this.$d.hours,
|
|
HH: s.s(this.$d.hours, 2, '0'),
|
|
m: this.$d.minutes,
|
|
mm: s.s(this.$d.minutes, 2, '0'),
|
|
s: this.$d.seconds,
|
|
ss: s.s(this.$d.seconds, 2, '0'),
|
|
SSS: s.s(this.$d.milliseconds, 3, '0')
|
|
};
|
|
return n.replace(o, function (t, s) {
|
|
return s || String(i[t]);
|
|
});
|
|
};
|
|
y.as = function (t) {
|
|
return this.$ms / d[m(t)];
|
|
};
|
|
y.get = function (t) {
|
|
var s = this.$ms;
|
|
var n = m(t);
|
|
'milliseconds' === n ? (s %= 1000) : (s = 'weeks' === n ? $(s / d[n]) : this.$d[n]);
|
|
return 0 === s ? 0 : s;
|
|
};
|
|
y.add = function (t, s, n) {
|
|
var i;
|
|
i = s ? t * d[m(s)] : c(t) ? t.$ms : f(t, this).$ms;
|
|
return f(this.$ms + i * (n ? -1 : 1), this);
|
|
};
|
|
y.subtract = function (t, s) {
|
|
return this.add(t, s, true);
|
|
};
|
|
y.locale = function (t) {
|
|
var s = this.clone();
|
|
s.$l = t;
|
|
return s;
|
|
};
|
|
y.clone = function () {
|
|
return f(this.$ms, this);
|
|
};
|
|
y.humanize = function (s) {
|
|
return t().add(this.$ms, 'ms').locale(this.$l).fromNow(!s);
|
|
};
|
|
y.milliseconds = function () {
|
|
return this.get('milliseconds');
|
|
};
|
|
y.asMilliseconds = function () {
|
|
return this.as('milliseconds');
|
|
};
|
|
y.seconds = function () {
|
|
return this.get('seconds');
|
|
};
|
|
y.asSeconds = function () {
|
|
return this.as('seconds');
|
|
};
|
|
y.minutes = function () {
|
|
return this.get('minutes');
|
|
};
|
|
y.asMinutes = function () {
|
|
return this.as('minutes');
|
|
};
|
|
y.hours = function () {
|
|
return this.get('hours');
|
|
};
|
|
y.asHours = function () {
|
|
return this.as('hours');
|
|
};
|
|
y.days = function () {
|
|
return this.get('days');
|
|
};
|
|
y.asDays = function () {
|
|
return this.as('days');
|
|
};
|
|
y.weeks = function () {
|
|
return this.get('weeks');
|
|
};
|
|
y.asWeeks = function () {
|
|
return this.as('weeks');
|
|
};
|
|
y.months = function () {
|
|
return this.get('months');
|
|
};
|
|
y.asMonths = function () {
|
|
return this.as('months');
|
|
};
|
|
y.years = function () {
|
|
return this.get('years');
|
|
};
|
|
y.asYears = function () {
|
|
return this.as('years');
|
|
};
|
|
return l;
|
|
})();
|
|
return function (n, i, e) {
|
|
t = e;
|
|
s = e().$utils();
|
|
e.duration = function (t, s) {
|
|
var n = e.locale();
|
|
return f(
|
|
t,
|
|
{
|
|
$l: n
|
|
},
|
|
s
|
|
);
|
|
};
|
|
e.isDuration = c;
|
|
var r = i.prototype.add;
|
|
var o = i.prototype.subtract;
|
|
i.prototype.add = function (t, s) {
|
|
if (c(t)) {
|
|
t = t.asMilliseconds();
|
|
}
|
|
return r.bind(this)(t, s);
|
|
};
|
|
i.prototype.subtract = function (t, s) {
|
|
if (c(t)) {
|
|
t = t.asMilliseconds();
|
|
}
|
|
return o.bind(this)(t, s);
|
|
};
|
|
};
|
|
});
|
|
|