esday 1.0.0 → 1.1.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/CHANGELOG.md +10 -0
- package/README.md +17 -9
- package/chunks/{DuP2qVZn.d.ts → BB5OVV-y.d.ts} +1 -1
- package/chunks/{Dc43cziu.d.ts → CBlQG2yl.d.ts} +1 -2
- package/chunks/CStrb5bT.js +454 -0
- package/chunks/DE-bYjyv.js +473 -0
- package/chunks/{CNIy0PdR.js → DIG_UBsE.js} +2 -1
- package/chunks/{D2Xh96oz.js → oiGWnahC.js} +6 -5
- package/index.d.ts +2 -2
- package/index.js +1 -1
- package/locales/af.d.ts +0 -1
- package/locales/am.d.ts +0 -1
- package/locales/ar-dz.d.ts +0 -1
- package/locales/ar-iq.d.ts +0 -1
- package/locales/ar-kw.d.ts +0 -1
- package/locales/ar-ly.d.ts +0 -1
- package/locales/ar-ma.d.ts +0 -1
- package/locales/ar-sa.d.ts +0 -1
- package/locales/ar-tn.d.ts +0 -1
- package/locales/ar.d.ts +0 -1
- package/locales/az.d.ts +0 -1
- package/locales/be.d.ts +0 -1
- package/locales/bg.d.ts +0 -1
- package/locales/bi.d.ts +0 -1
- package/locales/bm.d.ts +0 -1
- package/locales/bn-bd.d.ts +0 -1
- package/locales/bn.d.ts +0 -1
- package/locales/bo.d.ts +0 -1
- package/locales/br.d.ts +0 -1
- package/locales/bs.d.ts +0 -1
- package/locales/ca.d.ts +0 -1
- package/locales/cs.d.ts +0 -1
- package/locales/cv.d.ts +0 -1
- package/locales/cy.d.ts +0 -1
- package/locales/da.d.ts +0 -1
- package/locales/de-at.d.ts +0 -1
- package/locales/de-ch.d.ts +0 -1
- package/locales/de.d.ts +0 -1
- package/locales/dv.d.ts +0 -1
- package/locales/el.d.ts +0 -1
- package/locales/en-au.d.ts +0 -1
- package/locales/en-ca.d.ts +0 -1
- package/locales/en-gb.d.ts +0 -1
- package/locales/en-ie.d.ts +0 -1
- package/locales/en-il.d.ts +0 -1
- package/locales/en-in.d.ts +0 -1
- package/locales/en-nz.d.ts +0 -1
- package/locales/en-sg.d.ts +0 -1
- package/locales/en-tt.d.ts +0 -1
- package/locales/en-us.d.ts +0 -1
- package/locales/en.d.ts +0 -1
- package/locales/eo.d.ts +0 -1
- package/locales/es-do.d.ts +0 -1
- package/locales/es-mx.d.ts +0 -1
- package/locales/es-pr.d.ts +0 -1
- package/locales/es-us.d.ts +0 -1
- package/locales/es.d.ts +0 -1
- package/locales/et.d.ts +0 -1
- package/locales/eu.d.ts +0 -1
- package/locales/fa.d.ts +0 -1
- package/locales/fi.d.ts +0 -1
- package/locales/fil.d.ts +0 -1
- package/locales/fo.d.ts +0 -1
- package/locales/fr-ca.d.ts +0 -1
- package/locales/fr-ch.d.ts +0 -1
- package/locales/fr.d.ts +0 -1
- package/locales/fy.d.ts +0 -1
- package/locales/ga.d.ts +0 -1
- package/locales/gd.d.ts +0 -1
- package/locales/gl.d.ts +0 -1
- package/locales/gom-deva.d.ts +0 -1
- package/locales/gom-latn.d.ts +0 -1
- package/locales/gu.d.ts +0 -1
- package/locales/he.d.ts +0 -1
- package/locales/he.js +2 -1
- package/locales/hi.d.ts +0 -1
- package/locales/hr.d.ts +0 -1
- package/locales/ht.d.ts +0 -1
- package/locales/hu.d.ts +0 -1
- package/locales/hy-am.d.ts +0 -1
- package/locales/id.d.ts +0 -1
- package/locales/is.d.ts +0 -1
- package/locales/it-ch.d.ts +0 -1
- package/locales/it.d.ts +0 -1
- package/locales/ja.d.ts +0 -1
- package/locales/jv.d.ts +0 -1
- package/locales/ka.d.ts +0 -1
- package/locales/kk.d.ts +0 -1
- package/locales/km.d.ts +0 -1
- package/locales/kn.d.ts +0 -1
- package/locales/ko.d.ts +0 -1
- package/locales/ku.d.ts +0 -1
- package/locales/ky.d.ts +0 -1
- package/locales/lb.d.ts +0 -1
- package/locales/lo.d.ts +0 -1
- package/locales/lt.d.ts +0 -1
- package/locales/lv.d.ts +0 -1
- package/locales/me.d.ts +0 -1
- package/locales/mi.d.ts +0 -1
- package/locales/mk.d.ts +0 -1
- package/locales/ml.d.ts +0 -1
- package/locales/mn.d.ts +0 -1
- package/locales/mr.d.ts +0 -1
- package/locales/ms-my.d.ts +0 -1
- package/locales/ms.d.ts +0 -1
- package/locales/mt.d.ts +0 -1
- package/locales/my.d.ts +0 -1
- package/locales/nb.d.ts +0 -1
- package/locales/ne.d.ts +0 -1
- package/locales/nl-be.d.ts +0 -1
- package/locales/nl.d.ts +0 -1
- package/locales/nn.d.ts +0 -1
- package/locales/oc-lnc.d.ts +0 -1
- package/locales/pa-in.d.ts +0 -1
- package/locales/pl.d.ts +0 -1
- package/locales/pt-br.d.ts +0 -1
- package/locales/pt.d.ts +0 -1
- package/locales/rn.d.ts +0 -1
- package/locales/ro.d.ts +0 -1
- package/locales/ru.d.ts +0 -1
- package/locales/rw.d.ts +0 -1
- package/locales/sd.d.ts +0 -1
- package/locales/se.d.ts +0 -1
- package/locales/si.d.ts +0 -1
- package/locales/sk.d.ts +0 -1
- package/locales/sl.d.ts +0 -1
- package/locales/sq.d.ts +0 -1
- package/locales/sr-cyrl.d.ts +0 -1
- package/locales/sr.d.ts +0 -1
- package/locales/ss.d.ts +0 -1
- package/locales/sv-fi.d.ts +0 -1
- package/locales/sv.d.ts +0 -1
- package/locales/sw.d.ts +0 -1
- package/locales/ta.d.ts +0 -1
- package/locales/te.d.ts +0 -1
- package/locales/tet.d.ts +0 -1
- package/locales/tg.d.ts +0 -1
- package/locales/th.d.ts +0 -1
- package/locales/tk.d.ts +0 -1
- package/locales/tl-ph.d.ts +0 -1
- package/locales/tlh.d.ts +0 -1
- package/locales/tr.d.ts +0 -1
- package/locales/tzl.d.ts +0 -1
- package/locales/tzm-latn.d.ts +0 -1
- package/locales/tzm.d.ts +0 -1
- package/locales/ug-cn.d.ts +0 -1
- package/locales/uk.d.ts +0 -1
- package/locales/ur.d.ts +0 -1
- package/locales/uz-latn.d.ts +0 -1
- package/locales/uz.d.ts +0 -1
- package/locales/vi.d.ts +0 -1
- package/locales/x-pseudo.d.ts +0 -1
- package/locales/yo.d.ts +0 -1
- package/locales/zh-cn.d.ts +0 -1
- package/locales/zh-hk.d.ts +0 -1
- package/locales/zh-mo.d.ts +0 -1
- package/locales/zh-tw.d.ts +0 -1
- package/locales/zh.d.ts +0 -1
- package/package.json +22 -18
- package/plugins/advancedFormat/index.d.ts +1 -2
- package/plugins/advancedParse/index.d.ts +1 -2
- package/plugins/calendar/index.d.ts +1 -2
- package/plugins/dayOfYear/index.d.ts +1 -2
- package/plugins/duration/index.d.ts +1 -2
- package/plugins/duration/index.js +1 -471
- package/plugins/index.d.ts +28 -0
- package/plugins/index.js +28 -0
- package/plugins/isBetween/index.d.ts +1 -2
- package/plugins/isLeapYear/index.d.ts +1 -2
- package/plugins/isSameOrAfter/index.d.ts +1 -2
- package/plugins/isSameOrBefore/index.d.ts +1 -2
- package/plugins/isToday/index.d.ts +1 -2
- package/plugins/isTomorrow/index.d.ts +1 -2
- package/plugins/isYesterday/index.d.ts +1 -2
- package/plugins/isoWeek/index.d.ts +1 -2
- package/plugins/locale/index.d.ts +1 -2
- package/plugins/locale/index.js +4 -2
- package/plugins/localeData/index.d.ts +1 -2
- package/plugins/localeData/index.js +5 -3
- package/plugins/localizedFormat/index.d.ts +1 -2
- package/plugins/localizedParse/index.d.ts +1 -2
- package/plugins/localizedParse/index.js +2 -1
- package/plugins/minMax/index.d.ts +1 -2
- package/plugins/objectSupport/index.d.ts +1 -2
- package/plugins/pluralGetSet/index.d.ts +1 -2
- package/plugins/quarterOfYear/index.d.ts +1 -2
- package/plugins/relativeTime/index.d.ts +1 -2
- package/plugins/timezone/index.d.ts +1 -2
- package/plugins/timezone/index.js +1 -453
- package/plugins/toArray/index.d.ts +1 -2
- package/plugins/toObject/index.d.ts +1 -2
- package/plugins/utc/index.d.ts +1 -2
- package/plugins/utc/index.js +1 -1
- package/plugins/week/index.d.ts +1 -2
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import { r as INVALID_DATE_STRING } from "./CeKusvtV.js";
|
|
2
|
+
import { a as isUndefined, r as isObject } from "./DuRKUq5K.js";
|
|
3
|
+
import { n as normalizeUnitWithPlurals, r as normalizeUnitWithPluralsToPlural } from "./DMdr1ZL1.js";
|
|
4
|
+
import { n as padStart } from "./DXFoLbHM.js";
|
|
5
|
+
import { i as _checkPrivateRedeclaration, r as _assertClassBrand, t as esday } from "./oiGWnahC.js";
|
|
6
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/classPrivateFieldInitSpec.js
|
|
7
|
+
function _classPrivateFieldInitSpec(e, t, a) {
|
|
8
|
+
_checkPrivateRedeclaration(e, t), t.set(e, a);
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/classPrivateFieldSet2.js
|
|
12
|
+
function _classPrivateFieldSet2(s, a, r) {
|
|
13
|
+
return s.set(_assertClassBrand(s, a), r), r;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/classPrivateFieldGet2.js
|
|
17
|
+
function _classPrivateFieldGet2(s, a) {
|
|
18
|
+
return s.get(_assertClassBrand(s, a));
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/plugins/duration/index.ts
|
|
22
|
+
/** = 0:
|
|
23
|
+
* Duration plugin
|
|
24
|
+
*
|
|
25
|
+
* This plugin adds 'duration' and 'isDuration' to the esday factory.
|
|
26
|
+
*
|
|
27
|
+
* To use the humanize method or any of the locale methods, the plugin Locale,
|
|
28
|
+
* a loaded locale and the plugin RelativeTime are required.
|
|
29
|
+
*/
|
|
30
|
+
var _defaultLocale = /* @__PURE__ */ new WeakMap();
|
|
31
|
+
var _localeName = /* @__PURE__ */ new WeakMap();
|
|
32
|
+
var _detailsCache = /* @__PURE__ */ new WeakMap();
|
|
33
|
+
var _timeAsMs = /* @__PURE__ */ new WeakMap();
|
|
34
|
+
var _days = /* @__PURE__ */ new WeakMap();
|
|
35
|
+
var _months = /* @__PURE__ */ new WeakMap();
|
|
36
|
+
var _isValid = /* @__PURE__ */ new WeakMap();
|
|
37
|
+
var DurationImpl = class DurationImpl {
|
|
38
|
+
constructor(value, unit, localeName) {
|
|
39
|
+
_classPrivateFieldInitSpec(this, _defaultLocale, "en");
|
|
40
|
+
_classPrivateFieldInitSpec(this, _localeName, void 0);
|
|
41
|
+
_classPrivateFieldInitSpec(this, _detailsCache, {
|
|
42
|
+
years: 0,
|
|
43
|
+
quarters: 0,
|
|
44
|
+
months: 0,
|
|
45
|
+
weeks: 0,
|
|
46
|
+
days: 0,
|
|
47
|
+
hours: 0,
|
|
48
|
+
minutes: 0,
|
|
49
|
+
seconds: 0,
|
|
50
|
+
milliseconds: 0
|
|
51
|
+
});
|
|
52
|
+
_classPrivateFieldInitSpec(this, _timeAsMs, 0);
|
|
53
|
+
_classPrivateFieldInitSpec(this, _days, 0);
|
|
54
|
+
_classPrivateFieldInitSpec(this, _months, 0);
|
|
55
|
+
_classPrivateFieldInitSpec(this, _isValid, void 0);
|
|
56
|
+
this.absFloor = (number) => number < 0 ? Math.ceil(number) || 0 : Math.floor(number);
|
|
57
|
+
this.absCeil = (number) => number < 0 ? Math.floor(number) : Math.ceil(number);
|
|
58
|
+
this.sign = (number) => Number(number > 0) - Number(number < 0) || +number;
|
|
59
|
+
const numbersOnlyRegex = /^\d+$/gs;
|
|
60
|
+
const iso8601Regex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
|
|
61
|
+
const aspNetRegex = /^(-|\+)?(?:(\d*)[. ])?(\d+):(\d+)(?::(\d+)(\.\d*)?)?$/;
|
|
62
|
+
_classPrivateFieldSet2(_localeName, this, localeName ?? _classPrivateFieldGet2(_defaultLocale, this));
|
|
63
|
+
const normalizedUnit = normalizeUnitWithPluralsToPlural(unit);
|
|
64
|
+
const parsedInputRaw = {};
|
|
65
|
+
const parsedInput = {
|
|
66
|
+
years: 0,
|
|
67
|
+
quarters: 0,
|
|
68
|
+
months: 0,
|
|
69
|
+
weeks: 0,
|
|
70
|
+
days: 0,
|
|
71
|
+
hours: 0,
|
|
72
|
+
minutes: 0,
|
|
73
|
+
seconds: 0,
|
|
74
|
+
milliseconds: 0
|
|
75
|
+
};
|
|
76
|
+
if (value === void 0 || value === null) parsedInputRaw.milliseconds = 0;
|
|
77
|
+
else if (value instanceof DurationImpl) {
|
|
78
|
+
const baseValues = value.durationBase();
|
|
79
|
+
parsedInputRaw.milliseconds = baseValues.milliseconds;
|
|
80
|
+
parsedInputRaw.days = baseValues.days;
|
|
81
|
+
parsedInputRaw.months = baseValues.months;
|
|
82
|
+
} else if (isObject(value)) {
|
|
83
|
+
value = this.normalizeInputObject(value);
|
|
84
|
+
const keys = Object.keys(value);
|
|
85
|
+
for (const stringKey of keys) {
|
|
86
|
+
const key = stringKey;
|
|
87
|
+
parsedInputRaw[key] = +value[key];
|
|
88
|
+
}
|
|
89
|
+
} else if (typeof value === "number") if (isUndefined(normalizedUnit)) parsedInputRaw.milliseconds = value;
|
|
90
|
+
else parsedInputRaw[this.toKeyOfDurationCache(normalizedUnit)] = value;
|
|
91
|
+
else if (typeof value === "string") {
|
|
92
|
+
let parsedIso;
|
|
93
|
+
let parsedAsp;
|
|
94
|
+
if (numbersOnlyRegex.test(value)) if (isUndefined(normalizedUnit)) parsedInputRaw.milliseconds = +value;
|
|
95
|
+
else parsedInputRaw[this.toKeyOfDurationCache(normalizedUnit)] = +value;
|
|
96
|
+
else if (parsedIso = iso8601Regex.exec(value)) {
|
|
97
|
+
const sign = parsedIso[1] === "-" ? -1 : 1;
|
|
98
|
+
const durationDetailsKeys = [
|
|
99
|
+
"years",
|
|
100
|
+
"months",
|
|
101
|
+
"weeks",
|
|
102
|
+
"days",
|
|
103
|
+
"hours",
|
|
104
|
+
"minutes",
|
|
105
|
+
"seconds",
|
|
106
|
+
"milliseconds"
|
|
107
|
+
];
|
|
108
|
+
const durationParts = parsedIso.slice(2);
|
|
109
|
+
for (let i = 0; i < durationParts.length; ++i) if (!isUndefined(durationParts[i]) && Number.isFinite(Number(durationParts[i].replace(",", ".")))) parsedInputRaw[durationDetailsKeys[i]] = Number(durationParts[i].replace(",", ".")) * sign;
|
|
110
|
+
} else if (parsedAsp = aspNetRegex.exec(value)) {
|
|
111
|
+
const sign = parsedAsp[1] === "-" ? -1 : 1;
|
|
112
|
+
const durationParts = parsedAsp.slice(2).map((value, index) => {
|
|
113
|
+
let valueAsNumber = 0;
|
|
114
|
+
if (!isUndefined(value) && Number.isFinite(Number(value))) if (index !== 4) valueAsNumber = this.absFloor(Number(value)) * sign;
|
|
115
|
+
else valueAsNumber = Math.round(Number(value) * 1e3) * sign;
|
|
116
|
+
return valueAsNumber;
|
|
117
|
+
});
|
|
118
|
+
[parsedInputRaw.days, parsedInputRaw.hours, parsedInputRaw.minutes, parsedInputRaw.seconds, parsedInputRaw.milliseconds] = durationParts;
|
|
119
|
+
}
|
|
120
|
+
} else parsedInputRaw.milliseconds = 1;
|
|
121
|
+
_classPrivateFieldSet2(_isValid, this, this.isDurationValid(parsedInputRaw));
|
|
122
|
+
Object.assign(parsedInput, parsedInputRaw);
|
|
123
|
+
this.setTimeDaysMonths(parsedInput);
|
|
124
|
+
this.setDetailsCache();
|
|
125
|
+
}
|
|
126
|
+
isValid() {
|
|
127
|
+
return _classPrivateFieldGet2(_isValid, this);
|
|
128
|
+
}
|
|
129
|
+
clone() {
|
|
130
|
+
return new DurationImpl(this.durationBase(), void 0, _classPrivateFieldGet2(_localeName, this));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Format Duration as ISO string.
|
|
134
|
+
* For ISO strings we do not use the normal bubbling rules:
|
|
135
|
+
* * milliseconds bubble up until they become hours
|
|
136
|
+
* * days do not bubble at all
|
|
137
|
+
* * months bubble up until they become years
|
|
138
|
+
* This is because there is no context-free conversion between
|
|
139
|
+
* hours and days (think of clock changes) and also not between
|
|
140
|
+
* days and months (28-31 days per month)
|
|
141
|
+
* @returns Duration formatted as ISO string
|
|
142
|
+
*/
|
|
143
|
+
toISOString() {
|
|
144
|
+
if (!this.isValid()) return INVALID_DATE_STRING;
|
|
145
|
+
let seconds = Math.abs(_classPrivateFieldGet2(_timeAsMs, this)) / 1e3;
|
|
146
|
+
const days = Math.abs(_classPrivateFieldGet2(_days, this));
|
|
147
|
+
let months = Math.abs(_classPrivateFieldGet2(_months, this));
|
|
148
|
+
const total = this.asSeconds();
|
|
149
|
+
if (!total) return "P0D";
|
|
150
|
+
let minutes = this.absFloor(seconds / 60);
|
|
151
|
+
const hours = this.absFloor(minutes / 60);
|
|
152
|
+
seconds %= 60;
|
|
153
|
+
minutes %= 60;
|
|
154
|
+
const years = this.absFloor(months / 12);
|
|
155
|
+
months %= 12;
|
|
156
|
+
const s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, "") : "";
|
|
157
|
+
const totalSign = total < 0 ? "-" : "";
|
|
158
|
+
const ymSign = this.sign(_classPrivateFieldGet2(_months, this)) !== this.sign(total) ? "-" : "";
|
|
159
|
+
const daysSign = this.sign(_classPrivateFieldGet2(_days, this)) !== this.sign(total) ? "-" : "";
|
|
160
|
+
const hmsSign = this.sign(_classPrivateFieldGet2(_timeAsMs, this)) !== this.sign(total) ? "-" : "";
|
|
161
|
+
return totalSign + "P" + (years ? `${ymSign}${years}Y` : "") + (months ? `${ymSign}${months}M` : "") + (days ? `${daysSign}${days}D` : "") + (hours || minutes || seconds ? "T" : "") + (hours ? `${hmsSign}${hours}H` : "") + (minutes ? `${hmsSign}${minutes}M` : "") + (seconds ? `${hmsSign}${s}S` : "");
|
|
162
|
+
}
|
|
163
|
+
toString() {
|
|
164
|
+
return this.toISOString();
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Generate a value used by JSON.stringify to serialize Duration object
|
|
168
|
+
* @returns same string as toISOString()
|
|
169
|
+
*/
|
|
170
|
+
toJSON() {
|
|
171
|
+
return this.toISOString();
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Stringify this instance as JSON.
|
|
175
|
+
* Unit 'quarters' and 'weeks' are ignored, as they are only values derived from days / months / years.
|
|
176
|
+
* @returns a string representation of this instance
|
|
177
|
+
*/
|
|
178
|
+
asStringifiedJSON() {
|
|
179
|
+
const { quarters, weeks, ...durationProperties } = _classPrivateFieldGet2(_detailsCache, this);
|
|
180
|
+
return JSON.stringify(durationProperties);
|
|
181
|
+
}
|
|
182
|
+
valueOf() {
|
|
183
|
+
return this.asMilliseconds();
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Format the duration as a comprehensive string.
|
|
187
|
+
* @param formatStr - format to use for formatting
|
|
188
|
+
* @returns formatted duration
|
|
189
|
+
*/
|
|
190
|
+
format(formatStr) {
|
|
191
|
+
const REGEX_FORMAT = /\[([^\]]+)]|YYYY|Y{1,2}|M{1,2}|D{1,2}|H{1,2}|m{1,2}|s{1,2}|SSS/g;
|
|
192
|
+
const str = formatStr || "YYYY-MM-DDTHH:mm:ss.SSS";
|
|
193
|
+
const matches = {
|
|
194
|
+
Y: _classPrivateFieldGet2(_detailsCache, this).years,
|
|
195
|
+
YY: padStart(_classPrivateFieldGet2(_detailsCache, this).years, 2, "0"),
|
|
196
|
+
YYYY: padStart(_classPrivateFieldGet2(_detailsCache, this).years, 4, "0"),
|
|
197
|
+
M: _classPrivateFieldGet2(_detailsCache, this).months,
|
|
198
|
+
MM: padStart(_classPrivateFieldGet2(_detailsCache, this).months, 2, "0"),
|
|
199
|
+
D: _classPrivateFieldGet2(_detailsCache, this).days,
|
|
200
|
+
DD: padStart(_classPrivateFieldGet2(_detailsCache, this).days, 2, "0"),
|
|
201
|
+
H: _classPrivateFieldGet2(_detailsCache, this).hours,
|
|
202
|
+
HH: padStart(_classPrivateFieldGet2(_detailsCache, this).hours, 2, "0"),
|
|
203
|
+
m: _classPrivateFieldGet2(_detailsCache, this).minutes,
|
|
204
|
+
mm: padStart(_classPrivateFieldGet2(_detailsCache, this).minutes, 2, "0"),
|
|
205
|
+
s: _classPrivateFieldGet2(_detailsCache, this).seconds,
|
|
206
|
+
ss: padStart(_classPrivateFieldGet2(_detailsCache, this).seconds, 2, "0"),
|
|
207
|
+
SSS: padStart(_classPrivateFieldGet2(_detailsCache, this).milliseconds, 3, "0")
|
|
208
|
+
};
|
|
209
|
+
return str.replace(REGEX_FORMAT, (match) => String(matches[match]));
|
|
210
|
+
}
|
|
211
|
+
humanize(p1, thresholds) {
|
|
212
|
+
if (!this.isValid()) return INVALID_DATE_STRING;
|
|
213
|
+
let withSuffix = false;
|
|
214
|
+
if (typeof p1 === "boolean") withSuffix = p1;
|
|
215
|
+
let thresholdsToUse = Object.assign({}, esday.defaultThresholds(), thresholds);
|
|
216
|
+
if (typeof p1 === "object") thresholdsToUse = Object.assign(thresholdsToUse, p1);
|
|
217
|
+
const locale = esday.getLocale(this.locale());
|
|
218
|
+
const diffAsUnits = {
|
|
219
|
+
s: this.asSeconds(),
|
|
220
|
+
m: this.asMinutes(),
|
|
221
|
+
h: this.asHours(),
|
|
222
|
+
d: this.asDays(),
|
|
223
|
+
w: this.asWeeks(),
|
|
224
|
+
M: this.asMonths(),
|
|
225
|
+
y: this.asYears()
|
|
226
|
+
};
|
|
227
|
+
return esday.formatDifference(diffAsUnits, !withSuffix, locale, thresholdsToUse);
|
|
228
|
+
}
|
|
229
|
+
add(input, unit) {
|
|
230
|
+
return this.addDurationImpl(input, unit);
|
|
231
|
+
}
|
|
232
|
+
subtract(input, unit) {
|
|
233
|
+
return this.addDurationImpl(input, unit, true);
|
|
234
|
+
}
|
|
235
|
+
locale(locale) {
|
|
236
|
+
if (isUndefined(locale)) return _classPrivateFieldGet2(_localeName, this);
|
|
237
|
+
return new DurationImpl(this, void 0, locale);
|
|
238
|
+
}
|
|
239
|
+
localeObject() {
|
|
240
|
+
return esday.getLocale(this.locale());
|
|
241
|
+
}
|
|
242
|
+
get(unit) {
|
|
243
|
+
if (this.isValid()) return _classPrivateFieldGet2(_detailsCache, this)[this.toKeyOfDurationCache(unit)];
|
|
244
|
+
else return NaN;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Gets the duration calculated as 'unit' value
|
|
248
|
+
* @param unit - unit to use to calculate the return value
|
|
249
|
+
* @returns duration as unit
|
|
250
|
+
*/
|
|
251
|
+
as(unit) {
|
|
252
|
+
if (!this.isValid()) return NaN;
|
|
253
|
+
let days;
|
|
254
|
+
let months;
|
|
255
|
+
const milliseconds = _classPrivateFieldGet2(_timeAsMs, this);
|
|
256
|
+
const units = normalizeUnitWithPlurals(unit);
|
|
257
|
+
if (units === "month" || units === "quarter" || units === "year") {
|
|
258
|
+
days = _classPrivateFieldGet2(_days, this) + milliseconds / 864e5;
|
|
259
|
+
months = _classPrivateFieldGet2(_months, this) + this.daysToMonths(days);
|
|
260
|
+
switch (units) {
|
|
261
|
+
case "month": return months;
|
|
262
|
+
case "quarter": return months / 3;
|
|
263
|
+
case "year": return months / 12;
|
|
264
|
+
}
|
|
265
|
+
} else {
|
|
266
|
+
days = _classPrivateFieldGet2(_days, this) + Math.round(this.monthsToDays(_classPrivateFieldGet2(_months, this)));
|
|
267
|
+
switch (units) {
|
|
268
|
+
case "week": return days / 7 + milliseconds / 6048e5;
|
|
269
|
+
case "day": return days + milliseconds / 864e5;
|
|
270
|
+
case "hour": return days * 24 + milliseconds / 36e5;
|
|
271
|
+
case "minute": return days * 1440 + milliseconds / 6e4;
|
|
272
|
+
case "second": return days * 86400 + milliseconds / 1e3;
|
|
273
|
+
case "millisecond": return Math.floor(days * 864e5) + milliseconds;
|
|
274
|
+
default: throw new Error(`Unknown unit ${units}`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
milliseconds() {
|
|
279
|
+
return this.get("milliseconds");
|
|
280
|
+
}
|
|
281
|
+
asMilliseconds() {
|
|
282
|
+
return this.as("milliseconds");
|
|
283
|
+
}
|
|
284
|
+
seconds() {
|
|
285
|
+
return this.get("seconds");
|
|
286
|
+
}
|
|
287
|
+
asSeconds() {
|
|
288
|
+
return this.as("seconds");
|
|
289
|
+
}
|
|
290
|
+
minutes() {
|
|
291
|
+
return this.get("minutes");
|
|
292
|
+
}
|
|
293
|
+
asMinutes() {
|
|
294
|
+
return this.as("minutes");
|
|
295
|
+
}
|
|
296
|
+
hours() {
|
|
297
|
+
return this.get("hours");
|
|
298
|
+
}
|
|
299
|
+
asHours() {
|
|
300
|
+
return this.as("hours");
|
|
301
|
+
}
|
|
302
|
+
days() {
|
|
303
|
+
return this.get("days");
|
|
304
|
+
}
|
|
305
|
+
asDays() {
|
|
306
|
+
return this.as("days");
|
|
307
|
+
}
|
|
308
|
+
weeks() {
|
|
309
|
+
return this.absFloor(this.days() / 7);
|
|
310
|
+
}
|
|
311
|
+
asWeeks() {
|
|
312
|
+
return this.as("weeks");
|
|
313
|
+
}
|
|
314
|
+
months() {
|
|
315
|
+
return this.get("months");
|
|
316
|
+
}
|
|
317
|
+
asMonths() {
|
|
318
|
+
return this.as("months");
|
|
319
|
+
}
|
|
320
|
+
quarters() {
|
|
321
|
+
return this.get("quarters");
|
|
322
|
+
}
|
|
323
|
+
asQuarters() {
|
|
324
|
+
return this.as("quarters");
|
|
325
|
+
}
|
|
326
|
+
years() {
|
|
327
|
+
return this.get("years");
|
|
328
|
+
}
|
|
329
|
+
asYears() {
|
|
330
|
+
return this.as("years");
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Get an object literal with the internal data to recreate a clone of
|
|
334
|
+
* a duration instance (milliseconds, days, months). These values are different
|
|
335
|
+
* from the values returned by e.g. durationInstance.days().
|
|
336
|
+
* @description for use in Duration plugin to generate a Duration object from a Duration object
|
|
337
|
+
* @returns an object literal with the internal data of a duration object
|
|
338
|
+
*/
|
|
339
|
+
durationBase() {
|
|
340
|
+
return {
|
|
341
|
+
milliseconds: _classPrivateFieldGet2(_timeAsMs, this),
|
|
342
|
+
days: _classPrivateFieldGet2(_days, this),
|
|
343
|
+
months: _classPrivateFieldGet2(_months, this)
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
toKeyOfDurationCache(unit) {
|
|
347
|
+
return normalizeUnitWithPluralsToPlural(unit);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Do the given input values represent a valid duration?
|
|
351
|
+
* @param parsedInput - object containing all values found in input string
|
|
352
|
+
* @returns true=input defines a valid duration
|
|
353
|
+
*/
|
|
354
|
+
isDurationValid(parsedInput) {
|
|
355
|
+
const ordering = [
|
|
356
|
+
"years",
|
|
357
|
+
"quarters",
|
|
358
|
+
"months",
|
|
359
|
+
"weeks",
|
|
360
|
+
"days",
|
|
361
|
+
"hours",
|
|
362
|
+
"minutes",
|
|
363
|
+
"seconds",
|
|
364
|
+
"milliseconds"
|
|
365
|
+
];
|
|
366
|
+
for (const key in parsedInput) {
|
|
367
|
+
const value = parsedInput[key];
|
|
368
|
+
if (ordering.indexOf(key) === -1 || value === null || Number.isNaN(value)) return false;
|
|
369
|
+
}
|
|
370
|
+
let unitHasDecimal = false;
|
|
371
|
+
const orderLen = ordering.length;
|
|
372
|
+
for (let i = 0; i < orderLen; ++i) {
|
|
373
|
+
const value = parsedInput[ordering[i]];
|
|
374
|
+
if (!isUndefined(value)) {
|
|
375
|
+
if (unitHasDecimal) return false;
|
|
376
|
+
if (!Number.isInteger(value)) unitHasDecimal = true;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Normalize the keys in the object defining a duration.
|
|
383
|
+
* @param input - object containing duration definition with short, long or plural keys
|
|
384
|
+
* @returns object containing duration definition with plural keys
|
|
385
|
+
*/
|
|
386
|
+
normalizeInputObject(input) {
|
|
387
|
+
const normalizedInput = {};
|
|
388
|
+
let normalizedProp;
|
|
389
|
+
for (const prop in input) {
|
|
390
|
+
normalizedProp = normalizeUnitWithPluralsToPlural(prop);
|
|
391
|
+
if (!isUndefined(normalizedProp)) normalizedInput[normalizedProp] = input[prop];
|
|
392
|
+
}
|
|
393
|
+
return normalizedInput;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Calculate #timeAsMs, #days and #months from parsed input
|
|
397
|
+
*/
|
|
398
|
+
setTimeDaysMonths(parsedInput) {
|
|
399
|
+
_classPrivateFieldSet2(_timeAsMs, this, parsedInput.milliseconds + parsedInput.seconds * 1e3 + parsedInput.minutes * 1e3 * 60 + parsedInput.hours * 1e3 * 60 * 60);
|
|
400
|
+
_classPrivateFieldSet2(_days, this, parsedInput.days + parsedInput.weeks * 7);
|
|
401
|
+
_classPrivateFieldSet2(_months, this, parsedInput.months + parsedInput.quarters * 3 + parsedInput.years * 12);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Update cached duration details (seconds, minutes, etc)
|
|
405
|
+
* from #timeAsMs, #days and #months
|
|
406
|
+
*/
|
|
407
|
+
setDetailsCache() {
|
|
408
|
+
let milliseconds = _classPrivateFieldGet2(_timeAsMs, this);
|
|
409
|
+
let days = _classPrivateFieldGet2(_days, this);
|
|
410
|
+
let months = _classPrivateFieldGet2(_months, this);
|
|
411
|
+
if (!(milliseconds >= 0 && days >= 0 && months >= 0 || milliseconds <= 0 && days <= 0 && months <= 0)) {
|
|
412
|
+
milliseconds += this.absCeil(this.monthsToDays(months) + days) * 864e5;
|
|
413
|
+
days = 0;
|
|
414
|
+
months = 0;
|
|
415
|
+
}
|
|
416
|
+
_classPrivateFieldGet2(_detailsCache, this).milliseconds = milliseconds % 1e3;
|
|
417
|
+
const seconds = this.absFloor(milliseconds / 1e3);
|
|
418
|
+
_classPrivateFieldGet2(_detailsCache, this).seconds = seconds % 60;
|
|
419
|
+
const minutes = this.absFloor(seconds / 60);
|
|
420
|
+
_classPrivateFieldGet2(_detailsCache, this).minutes = minutes % 60;
|
|
421
|
+
const hours = this.absFloor(minutes / 60);
|
|
422
|
+
_classPrivateFieldGet2(_detailsCache, this).hours = hours % 24;
|
|
423
|
+
days += this.absFloor(hours / 24);
|
|
424
|
+
const monthsFromDays = this.absFloor(this.daysToMonths(days));
|
|
425
|
+
months += monthsFromDays;
|
|
426
|
+
days -= this.absCeil(this.monthsToDays(monthsFromDays));
|
|
427
|
+
const years = this.absFloor(months / 12);
|
|
428
|
+
months %= 12;
|
|
429
|
+
_classPrivateFieldGet2(_detailsCache, this).days = days;
|
|
430
|
+
_classPrivateFieldGet2(_detailsCache, this).months = months;
|
|
431
|
+
_classPrivateFieldGet2(_detailsCache, this).years = years;
|
|
432
|
+
_classPrivateFieldGet2(_detailsCache, this).weeks = this.absFloor(days / 7);
|
|
433
|
+
_classPrivateFieldGet2(_detailsCache, this).quarters = this.absFloor(_classPrivateFieldGet2(_detailsCache, this).months / 3);
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Convert days to months taking into account leap year rules:
|
|
437
|
+
* 400 years have exactly 146097 days (no fractional part left)
|
|
438
|
+
* 400 years have exactly 4800 months (12 months a year)
|
|
439
|
+
* @param days - days to convert to months
|
|
440
|
+
* @returns number of months
|
|
441
|
+
*/
|
|
442
|
+
daysToMonths(days) {
|
|
443
|
+
return days * 4800 / 146097;
|
|
444
|
+
}
|
|
445
|
+
monthsToDays(months) {
|
|
446
|
+
return months * 146097 / 4800;
|
|
447
|
+
}
|
|
448
|
+
addDurationImpl(value, unit, isSubtract) {
|
|
449
|
+
let durationToAdd;
|
|
450
|
+
const direction = isSubtract ? -1 : 1;
|
|
451
|
+
if (typeof value === "number") durationToAdd = new DurationImpl(value, unit, this.locale());
|
|
452
|
+
else if (value instanceof DurationImpl) durationToAdd = value;
|
|
453
|
+
else durationToAdd = new DurationImpl(value, void 0, this.locale());
|
|
454
|
+
const valuesToAdd = durationToAdd.durationBase();
|
|
455
|
+
const newDurationBase = {
|
|
456
|
+
milliseconds: _classPrivateFieldGet2(_timeAsMs, this) + direction * valuesToAdd.milliseconds,
|
|
457
|
+
days: _classPrivateFieldGet2(_days, this) + direction * valuesToAdd.days,
|
|
458
|
+
months: _classPrivateFieldGet2(_months, this) + direction * valuesToAdd.months
|
|
459
|
+
};
|
|
460
|
+
return new DurationImpl(newDurationBase, void 0, this.locale());
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
const durationPlugin = (_, _dayClass, dayFactory) => {
|
|
464
|
+
dayFactory.duration = (input, unit) => {
|
|
465
|
+
const locale = dayFactory.locale?.();
|
|
466
|
+
return new DurationImpl(input, unit, locale);
|
|
467
|
+
};
|
|
468
|
+
dayFactory.isDuration = (d) => {
|
|
469
|
+
return d instanceof DurationImpl;
|
|
470
|
+
};
|
|
471
|
+
};
|
|
472
|
+
//#endregion
|
|
473
|
+
export { durationPlugin as t };
|
|
@@ -16,7 +16,8 @@ const UNIT_FIELD_MAP = {
|
|
|
16
16
|
};
|
|
17
17
|
const prettyUnitsDate = Object.keys(UNIT_FIELD_MAP);
|
|
18
18
|
function unitToField(unit) {
|
|
19
|
-
|
|
19
|
+
const p = normalizeUnitWithPlurals(unit);
|
|
20
|
+
return UNIT_FIELD_MAP[p];
|
|
20
21
|
}
|
|
21
22
|
function getUnitInDate(date, unit) {
|
|
22
23
|
return date[`get${unitToField(unit)}`]();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { f as constants_default } from "./CeKusvtV.js";
|
|
2
2
|
import { a as isUndefined, n as isEmptyObject, o as isValidDate, r as isObject, t as isArray } from "./DuRKUq5K.js";
|
|
3
3
|
import { n as normalizeUnitWithPlurals, t as normalizeUnit } from "./DMdr1ZL1.js";
|
|
4
|
-
import { i as setUnitInDate, r as prettyUnitsDate, t as getUnitInDate } from "./
|
|
4
|
+
import { i as setUnitInDate, r as prettyUnitsDate, t as getUnitInDate } from "./DIG_UBsE.js";
|
|
5
5
|
import { t as createInstanceFromExist } from "./i3oEJgL3.js";
|
|
6
6
|
import { n as padStart, r as padZoneStr } from "./DXFoLbHM.js";
|
|
7
7
|
//#region src/core/Impl/add.ts
|
|
@@ -225,17 +225,17 @@ function startOfImpl(that, unit, reverse = false) {
|
|
|
225
225
|
return result;
|
|
226
226
|
}
|
|
227
227
|
//#endregion
|
|
228
|
-
//#region \0@oxc-project+runtime@0.
|
|
228
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/checkPrivateRedeclaration.js
|
|
229
229
|
function _checkPrivateRedeclaration(e, t) {
|
|
230
230
|
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
231
231
|
}
|
|
232
232
|
//#endregion
|
|
233
|
-
//#region \0@oxc-project+runtime@0.
|
|
233
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/classPrivateMethodInitSpec.js
|
|
234
234
|
function _classPrivateMethodInitSpec(e, a) {
|
|
235
235
|
_checkPrivateRedeclaration(e, a), a.add(e);
|
|
236
236
|
}
|
|
237
237
|
//#endregion
|
|
238
|
-
//#region \0@oxc-project+runtime@0.
|
|
238
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/assertClassBrand.js
|
|
239
239
|
function _assertClassBrand(e, t, n) {
|
|
240
240
|
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
241
241
|
throw new TypeError("Private element is not present on this object");
|
|
@@ -333,7 +333,8 @@ var EsDay = class EsDay {
|
|
|
333
333
|
return this.clone();
|
|
334
334
|
}
|
|
335
335
|
diff(date, units, asFloat = false) {
|
|
336
|
-
|
|
336
|
+
const parsedDate = esday(date);
|
|
337
|
+
return diffImpl(this, parsedDate, units, asFloat);
|
|
337
338
|
}
|
|
338
339
|
utcOffset(offset, _keepLocalTime) {
|
|
339
340
|
if (offset !== void 0) return new EsDay(constants_default.INVALID_DATE);
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { A as UnitMs, E as UnitIsoWeek, F as UnitTypeCore, I as UnitTypeGetSet, M as UnitSecond, N as UnitType, O as UnitMin, P as UnitTypeAddSub, R as UnitWeek, S as UnitDate, T as UnitHour, _ as LongUnit, a as EsDayFactory, b as PrettyUnitFromPlurals, c as FormattingTokenDefinitions, d as ParsingObjectPlurals, f as ParsingObjectShort, g as SimpleType, h as SimpleObject, i as DateType, j as UnitQuarter, k as UnitMonth, l as ParsingObject, m as UnitsObjectTypeSet, n as ConfigurationObject, o as EsDayFactoryParserFn, p as UnitsObjectTypeAddSub, r as DateFromDateComponents, s as EsDayPlugin, t as EsDay, u as ParsingObjectLong, v as PrettyUnitAsPlural, w as UnitDay, x as ShortUnit, y as PrettyUnitAsSingular, z as UnitYear } from "./chunks/
|
|
2
|
-
import { t as esday } from "./chunks/
|
|
1
|
+
import { A as UnitMs, E as UnitIsoWeek, F as UnitTypeCore, I as UnitTypeGetSet, M as UnitSecond, N as UnitType, O as UnitMin, P as UnitTypeAddSub, R as UnitWeek, S as UnitDate, T as UnitHour, _ as LongUnit, a as EsDayFactory, b as PrettyUnitFromPlurals, c as FormattingTokenDefinitions, d as ParsingObjectPlurals, f as ParsingObjectShort, g as SimpleType, h as SimpleObject, i as DateType, j as UnitQuarter, k as UnitMonth, l as ParsingObject, m as UnitsObjectTypeSet, n as ConfigurationObject, o as EsDayFactoryParserFn, p as UnitsObjectTypeAddSub, r as DateFromDateComponents, s as EsDayPlugin, t as EsDay, u as ParsingObjectLong, v as PrettyUnitAsPlural, w as UnitDay, x as ShortUnit, y as PrettyUnitAsSingular, z as UnitYear } from "./chunks/BB5OVV-y.js";
|
|
2
|
+
import { t as esday } from "./chunks/CBlQG2yl.js";
|
|
3
3
|
export { ConfigurationObject, DateFromDateComponents, DateType, EsDay, EsDayFactory, EsDayFactoryParserFn, EsDayPlugin, FormattingTokenDefinitions, type LongUnit, ParsingObject, ParsingObjectLong, ParsingObjectPlurals, ParsingObjectShort, type PrettyUnitAsPlural, type PrettyUnitAsSingular, type PrettyUnitFromPlurals, type ShortUnit, type SimpleObject, type SimpleType, type UnitDate, type UnitDay, type UnitHour, type UnitIsoWeek, type UnitMin, type UnitMonth, type UnitMs, type UnitQuarter, type UnitSecond, type UnitType, type UnitTypeAddSub, type UnitTypeCore, type UnitTypeGetSet, type UnitWeek, type UnitYear, UnitsObjectTypeAddSub, UnitsObjectTypeSet, esday };
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as EsDay, t as esday } from "./chunks/
|
|
1
|
+
import { n as EsDay, t as esday } from "./chunks/oiGWnahC.js";
|
|
2
2
|
export { EsDay, esday };
|
package/locales/af.d.ts
CHANGED
package/locales/am.d.ts
CHANGED
package/locales/ar-dz.d.ts
CHANGED
package/locales/ar-iq.d.ts
CHANGED
package/locales/ar-kw.d.ts
CHANGED
package/locales/ar-ly.d.ts
CHANGED
package/locales/ar-ma.d.ts
CHANGED
package/locales/ar-sa.d.ts
CHANGED
package/locales/ar-tn.d.ts
CHANGED
package/locales/ar.d.ts
CHANGED
package/locales/az.d.ts
CHANGED
package/locales/be.d.ts
CHANGED
package/locales/bg.d.ts
CHANGED
package/locales/bi.d.ts
CHANGED
package/locales/bm.d.ts
CHANGED
package/locales/bn-bd.d.ts
CHANGED
package/locales/bn.d.ts
CHANGED
package/locales/bo.d.ts
CHANGED