esday 0.4.1 → 0.6.2
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 +43 -0
- package/LICENSE +21 -0
- package/README.md +63 -33
- package/chunks/AyQQ6US-.js +84 -0
- package/chunks/BkjWOpMU.js +68 -0
- package/chunks/C5qDMHT5.d.ts +6 -0
- package/chunks/CODi8AFH.d.ts +231 -0
- package/chunks/CXWzCl3n.js +481 -0
- package/chunks/CdvTtmWL.js +56 -0
- package/chunks/Shk32pTP.js +9 -0
- package/chunks/v_QBn7Xm.js +25 -0
- package/chunks/xt8C2lbv.js +38 -0
- package/index.d.mts +3 -0
- package/index.mjs +3 -0
- package/locales/af.d.mts +6 -0
- package/locales/af.mjs +108 -0
- package/locales/am.d.mts +6 -0
- package/locales/am.mjs +108 -0
- package/locales/ar-dz.d.mts +9 -0
- package/locales/ar-dz.mjs +30 -0
- package/locales/ar-iq.d.mts +9 -0
- package/locales/ar-iq.mjs +12 -0
- package/locales/ar-kw.d.mts +9 -0
- package/locales/ar-kw.mjs +26 -0
- package/locales/ar-ly.d.mts +9 -0
- package/locales/ar-ly.mjs +12 -0
- package/locales/ar-ma.d.mts +9 -0
- package/locales/ar-ma.mjs +27 -0
- package/locales/ar-sa.d.mts +9 -0
- package/locales/ar-sa.mjs +27 -0
- package/locales/ar-tn.d.mts +9 -0
- package/locales/ar-tn.mjs +27 -0
- package/locales/ar.d.mts +6 -0
- package/locales/ar.mjs +198 -0
- package/locales/az.d.mts +6 -0
- package/locales/az.mjs +108 -0
- package/locales/be.d.mts +6 -0
- package/locales/be.mjs +136 -0
- package/locales/bg.d.mts +6 -0
- package/locales/bg.mjs +127 -0
- package/locales/bi.d.mts +6 -0
- package/locales/bi.mjs +108 -0
- package/locales/bm.d.mts +6 -0
- package/locales/bm.mjs +108 -0
- package/locales/bn-bd.d.mts +9 -0
- package/locales/bn-bd.mjs +22 -0
- package/locales/bn.d.mts +6 -0
- package/locales/bn.mjs +137 -0
- package/locales/bo.d.mts +6 -0
- package/locales/bo.mjs +108 -0
- package/locales/br.d.mts +6 -0
- package/locales/br.mjs +180 -0
- package/locales/bs.d.mts +6 -0
- package/locales/bs.mjs +130 -0
- package/locales/ca.d.mts +6 -0
- package/locales/ca.mjs +142 -0
- package/locales/cs.d.mts +6 -0
- package/locales/cs.mjs +186 -0
- package/locales/cv.d.mts +6 -0
- package/locales/cv.mjs +108 -0
- package/locales/cy.d.mts +6 -0
- package/locales/cy.mjs +108 -0
- package/locales/da.d.mts +6 -0
- package/locales/da.mjs +108 -0
- package/locales/de-at.d.mts +9 -0
- package/locales/de-at.mjs +42 -0
- package/locales/de-ch.d.mts +9 -0
- package/locales/de-ch.mjs +12 -0
- package/locales/de.d.mts +6 -0
- package/locales/de.mjs +131 -0
- package/locales/dv.d.mts +6 -0
- package/locales/dv.mjs +108 -0
- package/locales/el.d.mts +6 -0
- package/locales/el.mjs +117 -0
- package/locales/en-au.d.mts +9 -0
- package/locales/en-au.mjs +26 -0
- package/locales/en-ca.d.mts +9 -0
- package/locales/en-ca.mjs +26 -0
- package/locales/en-gb.d.mts +11 -0
- package/locales/en-gb.mjs +29 -0
- package/locales/en-ie.d.mts +9 -0
- package/locales/en-ie.mjs +25 -0
- package/locales/en-il.d.mts +9 -0
- package/locales/en-il.mjs +27 -0
- package/locales/en-in.d.mts +9 -0
- package/locales/en-in.mjs +25 -0
- package/locales/en-nz.d.mts +9 -0
- package/locales/en-nz.mjs +27 -0
- package/locales/en-sg.d.mts +9 -0
- package/locales/en-sg.mjs +27 -0
- package/locales/en-tt.d.mts +9 -0
- package/locales/en-tt.mjs +27 -0
- package/locales/en-us.d.mts +9 -0
- package/locales/en-us.mjs +12 -0
- package/locales/en.d.mts +6 -0
- package/locales/en.mjs +117 -0
- package/locales/eo.d.mts +6 -0
- package/locales/eo.mjs +108 -0
- package/locales/es-do.d.mts +9 -0
- package/locales/es-do.mjs +25 -0
- package/locales/es-mx.d.mts +9 -0
- package/locales/es-mx.mjs +13 -0
- package/locales/es-pr.d.mts +9 -0
- package/locales/es-pr.mjs +16 -0
- package/locales/es-us.d.mts +9 -0
- package/locales/es-us.mjs +12 -0
- package/locales/es.d.mts +6 -0
- package/locales/es.mjs +118 -0
- package/locales/et.d.mts +6 -0
- package/locales/et.mjs +146 -0
- package/locales/eu.d.mts +6 -0
- package/locales/eu.mjs +108 -0
- package/locales/fa.d.mts +6 -0
- package/locales/fa.mjs +108 -0
- package/locales/fi.d.mts +6 -0
- package/locales/fi.mjs +171 -0
- package/locales/fil.d.mts +6 -0
- package/locales/fil.mjs +108 -0
- package/locales/fo.d.mts +6 -0
- package/locales/fo.mjs +108 -0
- package/locales/fr-ca.d.mts +9 -0
- package/locales/fr-ca.mjs +16 -0
- package/locales/fr-ch.d.mts +9 -0
- package/locales/fr-ch.mjs +16 -0
- package/locales/fr.d.mts +6 -0
- package/locales/fr.mjs +110 -0
- package/locales/fy.d.mts +6 -0
- package/locales/fy.mjs +108 -0
- package/locales/ga.d.mts +6 -0
- package/locales/ga.mjs +108 -0
- package/locales/gd.d.mts +6 -0
- package/locales/gd.mjs +108 -0
- package/locales/gl.d.mts +6 -0
- package/locales/gl.mjs +118 -0
- package/locales/gom-deva.d.mts +6 -0
- package/locales/gom-deva.mjs +148 -0
- package/locales/gom-latn.d.mts +6 -0
- package/locales/gom-latn.mjs +148 -0
- package/locales/gu.d.mts +6 -0
- package/locales/gu.mjs +108 -0
- package/locales/he.d.mts +6 -0
- package/locales/he.mjs +132 -0
- package/locales/hi.d.mts +6 -0
- package/locales/hi.mjs +124 -0
- package/locales/hr.d.mts +6 -0
- package/locales/hr.mjs +195 -0
- package/locales/ht.d.mts +6 -0
- package/locales/ht.mjs +108 -0
- package/locales/hu.d.mts +6 -0
- package/locales/hu.mjs +144 -0
- package/locales/hy-am.d.mts +6 -0
- package/locales/hy-am.mjs +126 -0
- package/locales/id.d.mts +6 -0
- package/locales/id.mjs +108 -0
- package/locales/is.d.mts +6 -0
- package/locales/is.mjs +167 -0
- package/locales/it-ch.d.mts +9 -0
- package/locales/it-ch.mjs +27 -0
- package/locales/it.d.mts +6 -0
- package/locales/it.mjs +121 -0
- package/locales/ja.d.mts +12 -0
- package/locales/ja.mjs +111 -0
- package/locales/jv.d.mts +6 -0
- package/locales/jv.mjs +108 -0
- package/locales/ka.d.mts +6 -0
- package/locales/ka.mjs +125 -0
- package/locales/kk.d.mts +6 -0
- package/locales/kk.mjs +108 -0
- package/locales/km.d.mts +6 -0
- package/locales/km.mjs +108 -0
- package/locales/kn.d.mts +6 -0
- package/locales/kn.mjs +108 -0
- package/locales/ko.d.mts +6 -0
- package/locales/ko.mjs +107 -0
- package/locales/ku.d.mts +6 -0
- package/locales/ku.mjs +121 -0
- package/locales/ky.d.mts +6 -0
- package/locales/ky.mjs +108 -0
- package/locales/lb.d.mts +6 -0
- package/locales/lb.mjs +169 -0
- package/locales/lo.d.mts +6 -0
- package/locales/lo.mjs +107 -0
- package/locales/lt.d.mts +6 -0
- package/locales/lt.mjs +108 -0
- package/locales/lv.d.mts +6 -0
- package/locales/lv.mjs +108 -0
- package/locales/me.d.mts +6 -0
- package/locales/me.mjs +129 -0
- package/locales/mi.d.mts +6 -0
- package/locales/mi.mjs +108 -0
- package/locales/mk.d.mts +6 -0
- package/locales/mk.mjs +119 -0
- package/locales/ml.d.mts +6 -0
- package/locales/ml.mjs +111 -0
- package/locales/mn.d.mts +6 -0
- package/locales/mn.mjs +127 -0
- package/locales/mr.d.mts +6 -0
- package/locales/mr.mjs +229 -0
- package/locales/ms-my.d.mts +9 -0
- package/locales/ms-my.mjs +12 -0
- package/locales/ms.d.mts +6 -0
- package/locales/ms.mjs +108 -0
- package/locales/mt.d.mts +6 -0
- package/locales/mt.mjs +108 -0
- package/locales/my.d.mts +6 -0
- package/locales/my.mjs +134 -0
- package/locales/nb.d.mts +6 -0
- package/locales/nb.mjs +108 -0
- package/locales/ne.d.mts +6 -0
- package/locales/ne.mjs +108 -0
- package/locales/nl-be.d.mts +9 -0
- package/locales/nl-be.mjs +16 -0
- package/locales/nl.d.mts +6 -0
- package/locales/nl.mjs +108 -0
- package/locales/nn.d.mts +6 -0
- package/locales/nn.mjs +108 -0
- package/locales/oc-lnc.d.mts +6 -0
- package/locales/oc-lnc.mjs +125 -0
- package/locales/pa-in.d.mts +6 -0
- package/locales/pa-in.mjs +125 -0
- package/locales/pl.d.mts +6 -0
- package/locales/pl.mjs +162 -0
- package/locales/pt-br.d.mts +9 -0
- package/locales/pt-br.mjs +51 -0
- package/locales/pt.d.mts +6 -0
- package/locales/pt.mjs +110 -0
- package/locales/rn.d.mts +6 -0
- package/locales/rn.mjs +108 -0
- package/locales/ro.d.mts +6 -0
- package/locales/ro.mjs +108 -0
- package/locales/ru.d.mts +12 -0
- package/locales/ru.mjs +237 -0
- package/locales/rw.d.mts +6 -0
- package/locales/rw.mjs +108 -0
- package/locales/sd.d.mts +6 -0
- package/locales/sd.mjs +108 -0
- package/locales/se.d.mts +6 -0
- package/locales/se.mjs +108 -0
- package/locales/si.d.mts +6 -0
- package/locales/si.mjs +108 -0
- package/locales/sk.d.mts +6 -0
- package/locales/sk.mjs +168 -0
- package/locales/sl.d.mts +6 -0
- package/locales/sl.mjs +177 -0
- package/locales/sq.d.mts +6 -0
- package/locales/sq.mjs +108 -0
- package/locales/sr-cyrl.d.mts +9 -0
- package/locales/sr-cyrl.mjs +174 -0
- package/locales/sr.d.mts +6 -0
- package/locales/sr.mjs +186 -0
- package/locales/ss.d.mts +6 -0
- package/locales/ss.mjs +110 -0
- package/locales/sv-fi.d.mts +9 -0
- package/locales/sv-fi.mjs +25 -0
- package/locales/sv.d.mts +6 -0
- package/locales/sv.mjs +111 -0
- package/locales/sw.d.mts +6 -0
- package/locales/sw.mjs +108 -0
- package/locales/ta.d.mts +6 -0
- package/locales/ta.mjs +139 -0
- package/locales/te.d.mts +6 -0
- package/locales/te.mjs +111 -0
- package/locales/tet.d.mts +6 -0
- package/locales/tet.mjs +111 -0
- package/locales/tg.d.mts +6 -0
- package/locales/tg.mjs +127 -0
- package/locales/th.d.mts +6 -0
- package/locales/th.mjs +108 -0
- package/locales/tk.d.mts +6 -0
- package/locales/tk.mjs +135 -0
- package/locales/tl-ph.d.mts +6 -0
- package/locales/tl-ph.mjs +108 -0
- package/locales/tlh.d.mts +6 -0
- package/locales/tlh.mjs +155 -0
- package/locales/tr.d.mts +6 -0
- package/locales/tr.mjs +135 -0
- package/locales/tzl.d.mts +6 -0
- package/locales/tzl.mjs +125 -0
- package/locales/tzm-latn.d.mts +9 -0
- package/locales/tzm-latn.mjs +68 -0
- package/locales/tzm.d.mts +6 -0
- package/locales/tzm.mjs +108 -0
- package/locales/ug-cn.d.mts +6 -0
- package/locales/ug-cn.mjs +113 -0
- package/locales/uk.d.mts +6 -0
- package/locales/uk.mjs +199 -0
- package/locales/ur.d.mts +6 -0
- package/locales/ur.mjs +110 -0
- package/locales/uz-latn.d.mts +9 -0
- package/locales/uz-latn.mjs +68 -0
- package/locales/uz.d.mts +6 -0
- package/locales/uz.mjs +108 -0
- package/locales/vi.d.mts +6 -0
- package/locales/vi.mjs +108 -0
- package/locales/x-pseudo.d.mts +6 -0
- package/locales/x-pseudo.mjs +111 -0
- package/locales/yo.d.mts +6 -0
- package/locales/yo.mjs +108 -0
- package/locales/zh-cn.d.mts +9 -0
- package/locales/zh-cn.mjs +12 -0
- package/locales/zh-hk.d.mts +9 -0
- package/locales/zh-hk.mjs +21 -0
- package/locales/zh-mo.d.mts +9 -0
- package/locales/zh-mo.mjs +21 -0
- package/locales/zh-tw.d.mts +9 -0
- package/locales/zh-tw.mjs +21 -0
- package/locales/zh.d.mts +12 -0
- package/locales/zh.mjs +129 -0
- package/package.json +61 -29
- package/plugins/advancedFormat/index.d.mts +6 -0
- package/plugins/advancedFormat/index.mjs +18 -0
- package/plugins/advancedParse/index.d.mts +6 -0
- package/plugins/advancedParse/index.mjs +407 -0
- package/plugins/calendar/index.d.mts +12 -0
- package/plugins/calendar/index.mjs +32 -0
- package/plugins/dayOfYear/index.d.mts +12 -0
- package/plugins/dayOfYear/index.mjs +11 -0
- package/plugins/duration/index.d.mts +78 -0
- package/plugins/duration/index.mjs +477 -0
- package/plugins/isBetween/index.d.mts +22 -0
- package/plugins/isBetween/index.mjs +15 -0
- package/plugins/isLeapYear/index.d.mts +11 -0
- package/plugins/isLeapYear/index.mjs +10 -0
- package/plugins/isSameOrAfter/index.d.mts +11 -0
- package/plugins/isSameOrAfter/index.mjs +9 -0
- package/plugins/isSameOrBefore/index.d.mts +11 -0
- package/plugins/isSameOrBefore/index.mjs +9 -0
- package/plugins/isToday/index.d.mts +11 -0
- package/plugins/isToday/index.mjs +11 -0
- package/plugins/isTomorrow/index.d.mts +11 -0
- package/plugins/isTomorrow/index.mjs +13 -0
- package/plugins/isYesterday/index.d.mts +11 -0
- package/plugins/isYesterday/index.mjs +13 -0
- package/plugins/isoWeek/index.d.mts +19 -0
- package/plugins/isoWeek/index.mjs +228 -0
- package/plugins/locale/index.d.mts +104 -0
- package/plugins/locale/index.mjs +141 -0
- package/plugins/localeData/index.d.mts +6 -0
- package/plugins/localeData/index.mjs +155 -0
- package/plugins/localizedFormat/index.d.mts +6 -0
- package/plugins/localizedFormat/index.mjs +83 -0
- package/plugins/localizedParse/index.d.mts +6 -0
- package/plugins/localizedParse/index.mjs +217 -0
- package/plugins/minMax/index.d.mts +12 -0
- package/plugins/minMax/index.mjs +21 -0
- package/plugins/objectSupport/index.d.mts +6 -0
- package/plugins/objectSupport/index.mjs +99 -0
- package/plugins/pluralGetSet/index.d.mts +18 -0
- package/plugins/pluralGetSet/index.mjs +15 -0
- package/plugins/quarterOfYear/index.d.mts +14 -0
- package/plugins/quarterOfYear/index.mjs +51 -0
- package/plugins/relativeTime/index.d.mts +47 -0
- package/plugins/relativeTime/index.mjs +187 -0
- package/plugins/timezone/index.d.mts +6 -0
- package/plugins/timezone/index.mjs +456 -0
- package/plugins/toArray/index.d.mts +11 -0
- package/plugins/toArray/index.mjs +17 -0
- package/plugins/toObject/index.d.mts +19 -0
- package/plugins/toObject/index.mjs +17 -0
- package/plugins/utc/index.d.mts +18 -0
- package/plugins/utc/index.mjs +192 -0
- package/plugins/week/index.d.mts +19 -0
- package/plugins/week/index.mjs +350 -0
- package/EsDay-KXQgnL1r.d.ts +0 -89
- package/chunk-MLKGABMK.js +0 -7
- package/chunk-NUV73YDM.js +0 -60
- package/chunk-SQBPUYUY.js +0 -140
- package/index.d.ts +0 -6
- package/index.js +0 -310
- package/locales/en.d.ts +0 -6
- package/locales/en.js +0 -1
- package/locales/zh.d.ts +0 -6
- package/locales/zh.js +0 -64
- package/plugins/customParseFormat/index.d.ts +0 -5
- package/plugins/customParseFormat/index.js +0 -159
- package/plugins/isToday/index.d.ts +0 -10
- package/plugins/isToday/index.js +0 -8
- package/plugins/locale/index.d.ts +0 -75
- package/plugins/locale/index.js +0 -70
- package/plugins/utc/index.d.ts +0 -22
- package/plugins/utc/index.js +0 -40
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
import { p as constants_default } from "./BkjWOpMU.js";
|
|
2
|
+
import { a as isUndefined, n as isEmptyObject, o as isValidDate, r as isObject, t as isArray } from "./v_QBn7Xm.js";
|
|
3
|
+
import { n as normalizeUnitWithPlurals, t as normalizeUnit } from "./AyQQ6US-.js";
|
|
4
|
+
import { i as setUnitInDate, r as prettyUnitsDate, t as getUnitInDate } from "./xt8C2lbv.js";
|
|
5
|
+
import { t as createInstanceFromExist } from "./Shk32pTP.js";
|
|
6
|
+
import { n as padStart, r as padZoneStr } from "./CdvTtmWL.js";
|
|
7
|
+
|
|
8
|
+
//#region src/core/Impl/add.ts
|
|
9
|
+
function addImpl(that, value, units) {
|
|
10
|
+
const $d = that["$d"];
|
|
11
|
+
const unit = normalizeUnitWithPlurals(units);
|
|
12
|
+
const instanceFactorySet = (multiplier) => {
|
|
13
|
+
return that.set("date", that.get("date") + Math.round(multiplier * value));
|
|
14
|
+
};
|
|
15
|
+
switch (normalizeUnitWithPlurals(unit)) {
|
|
16
|
+
case constants_default.YEAR: return that.set("year", that.get("year") + value);
|
|
17
|
+
case constants_default.MONTH: return that.set("month", that.get("month") + value);
|
|
18
|
+
case constants_default.WEEK: return instanceFactorySet(7);
|
|
19
|
+
case constants_default.DAY:
|
|
20
|
+
case constants_default.DAY_OF_MONTH: return instanceFactorySet(1);
|
|
21
|
+
case constants_default.HOUR:
|
|
22
|
+
case constants_default.MIN:
|
|
23
|
+
case constants_default.SECOND:
|
|
24
|
+
case constants_default.MS: {
|
|
25
|
+
const step = {
|
|
26
|
+
minute: 60 * 1e3,
|
|
27
|
+
hour: 3600 * 1e3,
|
|
28
|
+
second: 1e3
|
|
29
|
+
}[unit] || 1;
|
|
30
|
+
const nextTimeStamp = $d.getTime() + value * step;
|
|
31
|
+
return createInstanceFromExist(new Date(nextTimeStamp), that);
|
|
32
|
+
}
|
|
33
|
+
default: return that.clone();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/core/Impl/diff.ts
|
|
39
|
+
/**
|
|
40
|
+
* get difference between 2 dates as months.
|
|
41
|
+
* As implemented by moment.js, the algorithm is optimized to ensure that two months
|
|
42
|
+
* with the same date are always a whole number apart.
|
|
43
|
+
* @param a - date 1
|
|
44
|
+
* @param b - date 2
|
|
45
|
+
* @returns b - a in months
|
|
46
|
+
*/
|
|
47
|
+
function monthDiff(a, b) {
|
|
48
|
+
if (a.date() < b.date()) return -monthDiff(b, a);
|
|
49
|
+
const wholeMonthDiff = (b.year() - a.year()) * 12 + (b.month() - a.month());
|
|
50
|
+
const anchor = a.clone().add(wholeMonthDiff, constants_default.MONTH);
|
|
51
|
+
const c = b.valueOf() - anchor.valueOf() < 0;
|
|
52
|
+
const anchor2 = a.clone().add(wholeMonthDiff + (c ? -1 : 1), constants_default.MONTH);
|
|
53
|
+
return +(-(wholeMonthDiff + (b.valueOf() - anchor.valueOf()) / (c ? anchor.valueOf() - anchor2.valueOf() : anchor2.valueOf() - anchor.valueOf())) || 0);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Drop fractional part of a number.
|
|
57
|
+
* @param n - number to inspect
|
|
58
|
+
* @returns n without fractional part
|
|
59
|
+
*/
|
|
60
|
+
function absFloor(n) {
|
|
61
|
+
return n < 0 ? Math.ceil(n) : Math.floor(n);
|
|
62
|
+
}
|
|
63
|
+
function diffImpl(that, date, units, asFloat = false) {
|
|
64
|
+
const diffInMs = that.valueOf() - date.valueOf();
|
|
65
|
+
const diffInMonths = monthDiff(that, date);
|
|
66
|
+
const zoneDelta = (that.utcOffset() - date.utcOffset()) * constants_default.MILLISECONDS_A_MINUTE;
|
|
67
|
+
let result;
|
|
68
|
+
if (isUndefined(units)) result = diffInMs;
|
|
69
|
+
else switch (normalizeUnitWithPlurals(units)) {
|
|
70
|
+
case constants_default.YEAR:
|
|
71
|
+
result = diffInMonths / 12;
|
|
72
|
+
break;
|
|
73
|
+
case constants_default.MONTH:
|
|
74
|
+
result = diffInMonths;
|
|
75
|
+
break;
|
|
76
|
+
case constants_default.QUARTER:
|
|
77
|
+
result = diffInMonths / 3;
|
|
78
|
+
break;
|
|
79
|
+
case constants_default.WEEK:
|
|
80
|
+
result = (diffInMs + zoneDelta) / constants_default.MILLISECONDS_A_WEEK;
|
|
81
|
+
break;
|
|
82
|
+
case constants_default.DAY:
|
|
83
|
+
result = (diffInMs + zoneDelta) / constants_default.MILLISECONDS_A_DAY;
|
|
84
|
+
break;
|
|
85
|
+
case constants_default.HOUR:
|
|
86
|
+
result = diffInMs / constants_default.MILLISECONDS_A_HOUR;
|
|
87
|
+
break;
|
|
88
|
+
case constants_default.MIN:
|
|
89
|
+
result = diffInMs / constants_default.MILLISECONDS_A_MINUTE;
|
|
90
|
+
break;
|
|
91
|
+
case constants_default.SECOND:
|
|
92
|
+
result = diffInMs / constants_default.MILLISECONDS_A_SECOND;
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
result = diffInMs;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
return asFloat ? result : absFloor(result);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/core/Impl/format.ts
|
|
103
|
+
const formattingSeparatorsRegex = "\\[([^\\]]+)\\]";
|
|
104
|
+
let formattingTokensRegex;
|
|
105
|
+
const formatTokensDefinitions = {
|
|
106
|
+
YY: (sourceDate) => padStart(sourceDate.year(), 2, "0").slice(-2),
|
|
107
|
+
YYYY: (sourceDate) => padStart(sourceDate.year(), 4, "0"),
|
|
108
|
+
M: (sourceDate) => String(sourceDate.month() + 1),
|
|
109
|
+
MM: (sourceDate) => padStart(sourceDate.month() + 1, 2, "0"),
|
|
110
|
+
D: (sourceDate) => String(sourceDate.date()),
|
|
111
|
+
DD: (sourceDate) => padStart(sourceDate.date(), 2, "0"),
|
|
112
|
+
H: (sourceDate) => String(sourceDate.hour()),
|
|
113
|
+
HH: (sourceDate) => padStart(sourceDate.hour(), 2, "0"),
|
|
114
|
+
m: (sourceDate) => String(sourceDate.minute()),
|
|
115
|
+
mm: (sourceDate) => padStart(sourceDate.minute(), 2, "0"),
|
|
116
|
+
s: (sourceDate) => String(sourceDate.second()),
|
|
117
|
+
ss: (sourceDate) => padStart(sourceDate.second(), 2, "0"),
|
|
118
|
+
SSS: (sourceDate) => padStart(sourceDate.millisecond(), 3, "0"),
|
|
119
|
+
Z: (sourceDate) => padZoneStr(sourceDate.utcOffset())
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Compare 2 tokens for sorting.
|
|
123
|
+
* Longer token and upper case token are sorted to the top.
|
|
124
|
+
* As we sort here object keys, a and b can never be equal.
|
|
125
|
+
* @param a - token 1
|
|
126
|
+
* @param b - token 2
|
|
127
|
+
* @returns -1 (a<b), 0 (a==b), 1 (a>b)
|
|
128
|
+
*/
|
|
129
|
+
function compareTokens(a, b) {
|
|
130
|
+
if (a.length < b.length) return 1;
|
|
131
|
+
if (a.length > b.length) return -1;
|
|
132
|
+
if (a < b) return 1;
|
|
133
|
+
return -1;
|
|
134
|
+
}
|
|
135
|
+
function formattingTokensRegexFromDefinitions() {
|
|
136
|
+
const tokenKeys = Object.keys(formatTokensDefinitions).sort(compareTokens);
|
|
137
|
+
formattingTokensRegex = new RegExp(`${formattingSeparatorsRegex}|${tokenKeys.join("|")}`, "g");
|
|
138
|
+
}
|
|
139
|
+
formattingTokensRegexFromDefinitions();
|
|
140
|
+
/**
|
|
141
|
+
* Add formatting tokens to list of global formatting tokens.
|
|
142
|
+
* @param newTokens - list of new parsing token definitions
|
|
143
|
+
*/
|
|
144
|
+
function addFormatTokenDefinitions(newTokens) {
|
|
145
|
+
for (const key in newTokens) if (!Object.prototype.hasOwnProperty.call(formatTokensDefinitions, key)) formatTokensDefinitions[key] = newTokens[key];
|
|
146
|
+
formattingTokensRegexFromDefinitions();
|
|
147
|
+
}
|
|
148
|
+
function formatImpl(that, formatStr) {
|
|
149
|
+
if (!that.isValid()) return constants_default.INVALID_DATE_STRING;
|
|
150
|
+
const activeFormatString = formatStr || constants_default.FORMAT_DEFAULT;
|
|
151
|
+
const matches = (match) => {
|
|
152
|
+
const formatter = formatTokensDefinitions[match];
|
|
153
|
+
return formatter(that, formatStr);
|
|
154
|
+
};
|
|
155
|
+
return activeFormatString.replace(formattingTokensRegex, (match, $1) => $1 || matches(match));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/core/Impl/parse.ts
|
|
160
|
+
/**
|
|
161
|
+
* Create a Date object from an array of date components (year, month, ...).
|
|
162
|
+
* The month is 0 based (0..11).
|
|
163
|
+
* @param this - context to access the right function 'dateFromDateComponents'
|
|
164
|
+
* @param dateArray - array with date components (y, M, D, h, m, s ms)
|
|
165
|
+
* @returns Date object created from given array elements
|
|
166
|
+
*/
|
|
167
|
+
function parseArrayToDate(dateArray) {
|
|
168
|
+
const dateArrayTuple = [
|
|
169
|
+
0,
|
|
170
|
+
1,
|
|
171
|
+
1,
|
|
172
|
+
0,
|
|
173
|
+
0,
|
|
174
|
+
0,
|
|
175
|
+
0
|
|
176
|
+
];
|
|
177
|
+
dateArray.forEach((value, index) => {
|
|
178
|
+
if (value !== void 0) dateArrayTuple[index] = index !== 1 ? value : value + 1;
|
|
179
|
+
});
|
|
180
|
+
return this.dateFromDateComponents(...dateArrayTuple);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/core/Impl/startOf.ts
|
|
185
|
+
function startOfImpl(that, unit, reverse = false) {
|
|
186
|
+
const result = that.clone();
|
|
187
|
+
const setterFunc = result["$set"];
|
|
188
|
+
const instanceFactorySet = (method, slice) => {
|
|
189
|
+
const argument = reverse ? [
|
|
190
|
+
23,
|
|
191
|
+
59,
|
|
192
|
+
59,
|
|
193
|
+
999
|
|
194
|
+
].slice(slice) : [
|
|
195
|
+
0,
|
|
196
|
+
0,
|
|
197
|
+
0,
|
|
198
|
+
0
|
|
199
|
+
].slice(slice);
|
|
200
|
+
setterFunc.call(result, method, argument);
|
|
201
|
+
};
|
|
202
|
+
const instanceFactory = (date, month) => {
|
|
203
|
+
setterFunc.call(result, constants_default.MONTH, [month, date]);
|
|
204
|
+
};
|
|
205
|
+
const $month = result.month();
|
|
206
|
+
switch (normalizeUnit(unit)) {
|
|
207
|
+
case constants_default.YEAR:
|
|
208
|
+
reverse ? instanceFactory(31, 11) : instanceFactory(1, 0);
|
|
209
|
+
instanceFactorySet(constants_default.HOUR, 0);
|
|
210
|
+
break;
|
|
211
|
+
case constants_default.MONTH:
|
|
212
|
+
reverse ? instanceFactory(0, $month + 1) : instanceFactory(1, $month);
|
|
213
|
+
instanceFactorySet(constants_default.HOUR, 0);
|
|
214
|
+
break;
|
|
215
|
+
case constants_default.DAY:
|
|
216
|
+
case constants_default.DAY_OF_MONTH:
|
|
217
|
+
instanceFactorySet(constants_default.HOUR, 0);
|
|
218
|
+
break;
|
|
219
|
+
case constants_default.HOUR:
|
|
220
|
+
instanceFactorySet(constants_default.MIN, 1);
|
|
221
|
+
break;
|
|
222
|
+
case constants_default.MIN:
|
|
223
|
+
instanceFactorySet(constants_default.SECOND, 2);
|
|
224
|
+
break;
|
|
225
|
+
case constants_default.SECOND:
|
|
226
|
+
instanceFactorySet(constants_default.MS, 3);
|
|
227
|
+
break;
|
|
228
|
+
default: break;
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/checkPrivateRedeclaration.js
|
|
235
|
+
function _checkPrivateRedeclaration(e, t) {
|
|
236
|
+
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/classPrivateMethodInitSpec.js
|
|
241
|
+
function _classPrivateMethodInitSpec(e, a) {
|
|
242
|
+
_checkPrivateRedeclaration(e, a), a.add(e);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/assertClassBrand.js
|
|
247
|
+
function _assertClassBrand(e, t, n) {
|
|
248
|
+
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
249
|
+
throw new TypeError("Private element is not present on this object");
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/core/EsDay.ts
|
|
254
|
+
var _EsDay_brand = /* @__PURE__ */ new WeakSet();
|
|
255
|
+
var EsDay = class EsDay {
|
|
256
|
+
constructor(d, conf) {
|
|
257
|
+
_classPrivateMethodInitSpec(this, _EsDay_brand);
|
|
258
|
+
this.$conf = {};
|
|
259
|
+
if (!isUndefined(conf)) this.$conf = structuredClone(conf);
|
|
260
|
+
this.$parse(d);
|
|
261
|
+
}
|
|
262
|
+
$parse(d) {
|
|
263
|
+
this.$d = _assertClassBrand(_EsDay_brand, this, _parseImpl).call(this, d);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Create a Date object from the date components (year, month, ...).
|
|
267
|
+
* The month is 1 based (1..12).
|
|
268
|
+
* Potential hook for plugins to change the details of Date creation.
|
|
269
|
+
* @param Y - year of date to create
|
|
270
|
+
* @param M - year of date to create (1..12)
|
|
271
|
+
* @param D - year of date to create
|
|
272
|
+
* @param h - year of date to create
|
|
273
|
+
* @param m - year of date to create
|
|
274
|
+
* @param s - year of date to create
|
|
275
|
+
* @param ms - year of date to create
|
|
276
|
+
* @param offsetMs - offset from utc in milliseconds
|
|
277
|
+
* @returns Date object created from input parameters
|
|
278
|
+
*/
|
|
279
|
+
dateFromDateComponents(Y, M, D, h, m, s, ms, offsetMs) {
|
|
280
|
+
const parsedYearOrDefault = Y ?? (/* @__PURE__ */ new Date()).getFullYear();
|
|
281
|
+
const dateComponents = {
|
|
282
|
+
Y: parsedYearOrDefault,
|
|
283
|
+
M: (M ?? (Y !== void 0 ? 1 : (/* @__PURE__ */ new Date()).getMonth() + 1)) - 1,
|
|
284
|
+
D: D ?? 1,
|
|
285
|
+
h: h ?? 0,
|
|
286
|
+
m: m ?? 0,
|
|
287
|
+
s: s ?? 0,
|
|
288
|
+
ms: ms ?? 0
|
|
289
|
+
};
|
|
290
|
+
const yearWithoutCentury = Math.abs(parsedYearOrDefault) < 100;
|
|
291
|
+
let overflowed = false;
|
|
292
|
+
let result = new Date(dateComponents.Y, dateComponents.M, dateComponents.D, dateComponents.h, dateComponents.m, dateComponents.s, dateComponents.ms);
|
|
293
|
+
if (yearWithoutCentury) result.setFullYear(dateComponents.Y);
|
|
294
|
+
overflowed = M !== void 0 && (M < 1 || M > 12 || M - 1 !== result.getMonth()) || D !== void 0 && (D < 0 || D !== result.getDate()) || h !== void 0 && (h < 0 || h > 23) || m !== void 0 && (m < 0 || m > 59) || s !== void 0 && (s < 0 || s > 59);
|
|
295
|
+
if (overflowed) result = constants_default.INVALID_DATE;
|
|
296
|
+
else if (!isUndefined(offsetMs)) {
|
|
297
|
+
const currentOffsetMin = result.getTimezoneOffset();
|
|
298
|
+
const newMs = result.getMilliseconds() - (currentOffsetMin * 6e4 + offsetMs);
|
|
299
|
+
result.setMilliseconds(newMs);
|
|
300
|
+
}
|
|
301
|
+
return result;
|
|
302
|
+
}
|
|
303
|
+
isSame(that, units = constants_default.MS) {
|
|
304
|
+
const other = esday(that);
|
|
305
|
+
return this.startOf(units) <= other && other <= this.endOf(units);
|
|
306
|
+
}
|
|
307
|
+
isAfter(that, units = constants_default.MS) {
|
|
308
|
+
return esday(that) < this.startOf(units);
|
|
309
|
+
}
|
|
310
|
+
isBefore(that, units = constants_default.MS) {
|
|
311
|
+
return this.endOf(units) < esday(that);
|
|
312
|
+
}
|
|
313
|
+
valueOf() {
|
|
314
|
+
return this.$d.getTime();
|
|
315
|
+
}
|
|
316
|
+
unix() {
|
|
317
|
+
return Math.floor(this.valueOf() / 1e3);
|
|
318
|
+
}
|
|
319
|
+
isValid() {
|
|
320
|
+
return isValidDate(this.$d);
|
|
321
|
+
}
|
|
322
|
+
clone() {
|
|
323
|
+
const newInst = new EsDay(this.$d);
|
|
324
|
+
newInst.$conf = structuredClone(this.$conf);
|
|
325
|
+
return newInst;
|
|
326
|
+
}
|
|
327
|
+
format(formatStr) {
|
|
328
|
+
return formatImpl(this, formatStr);
|
|
329
|
+
}
|
|
330
|
+
startOf(units) {
|
|
331
|
+
return startOfImpl(this, units);
|
|
332
|
+
}
|
|
333
|
+
endOf(units) {
|
|
334
|
+
return startOfImpl(this, units, true);
|
|
335
|
+
}
|
|
336
|
+
add(value, unit) {
|
|
337
|
+
if (!isObject(value)) return addImpl(this, value, unit ?? constants_default.MS);
|
|
338
|
+
return this.clone();
|
|
339
|
+
}
|
|
340
|
+
subtract(value, unit) {
|
|
341
|
+
if (!isObject(value) && unit !== void 0) return this.add(-value, unit);
|
|
342
|
+
return this.clone();
|
|
343
|
+
}
|
|
344
|
+
diff(date, units, asFloat = false) {
|
|
345
|
+
return diffImpl(this, date, units, asFloat);
|
|
346
|
+
}
|
|
347
|
+
utcOffset(offset, _keepLocalTime) {
|
|
348
|
+
if (offset !== void 0) return new EsDay(constants_default.INVALID_DATE);
|
|
349
|
+
return -Math.round(this.$d.getTimezoneOffset());
|
|
350
|
+
}
|
|
351
|
+
get(unit) {
|
|
352
|
+
const normalizedUnit = normalizeUnitWithPlurals(unit);
|
|
353
|
+
if (normalizedUnit === constants_default.QUARTER || normalizedUnit === constants_default.WEEK) return NaN;
|
|
354
|
+
return getUnitInDate(this.$d, unit);
|
|
355
|
+
}
|
|
356
|
+
set(unit, ...values) {
|
|
357
|
+
return this.clone().$set(unit, values);
|
|
358
|
+
}
|
|
359
|
+
toDate() {
|
|
360
|
+
return new Date(this.valueOf());
|
|
361
|
+
}
|
|
362
|
+
toJSON() {
|
|
363
|
+
return this.isValid() ? this.toISOString() : null;
|
|
364
|
+
}
|
|
365
|
+
toISOString() {
|
|
366
|
+
if (this.isValid()) return this.$d.toISOString();
|
|
367
|
+
return constants_default.INVALID_DATE_STRING;
|
|
368
|
+
}
|
|
369
|
+
toString() {
|
|
370
|
+
return this.$d.toUTCString();
|
|
371
|
+
}
|
|
372
|
+
$set(unit, values) {
|
|
373
|
+
if (isObject(unit)) return this;
|
|
374
|
+
const normalizedUnit = normalizeUnitWithPlurals(unit);
|
|
375
|
+
if (normalizedUnit === constants_default.DAY) setUnitInDate(this.$d, constants_default.DAY_OF_MONTH, this.date() + (values[0] - this.day()));
|
|
376
|
+
else if (normalizedUnit === constants_default.YEAR && values.length === 2) {
|
|
377
|
+
const originalDate = this.date();
|
|
378
|
+
setUnitInDate(this.$d, constants_default.YEAR, values);
|
|
379
|
+
if (originalDate > 0 && this.date() !== originalDate) setUnitInDate(this.$d, constants_default.DAY_OF_MONTH, 0);
|
|
380
|
+
} else if (normalizedUnit === constants_default.MONTH) {
|
|
381
|
+
const originalDate = values.length === 1 ? this.date() : values[1];
|
|
382
|
+
setUnitInDate(this.$d, constants_default.MONTH, values);
|
|
383
|
+
if (originalDate > 0 && this.date() !== originalDate) setUnitInDate(this.$d, constants_default.DAY_OF_MONTH, 0);
|
|
384
|
+
} else if (normalizedUnit !== constants_default.QUARTER && normalizedUnit !== constants_default.WEEK) {
|
|
385
|
+
const typedUnit = normalizedUnit;
|
|
386
|
+
setUnitInDate(this.$d, typedUnit, values);
|
|
387
|
+
}
|
|
388
|
+
return this;
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
/**
|
|
392
|
+
* Convert a parsed element to a number | undefined;
|
|
393
|
+
* empty strings are treated as undefined.
|
|
394
|
+
* @param parsedElement - element to be converted
|
|
395
|
+
* @returns parsed element as number
|
|
396
|
+
*/
|
|
397
|
+
function _toNumber(parsedElement) {
|
|
398
|
+
if (parsedElement === void 0 || typeof parsedElement === "string" && parsedElement.trim().length === 0) return;
|
|
399
|
+
return Number(parsedElement);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Convert a parsed milliseconds element to a number | undefined;
|
|
403
|
+
* for milliseconds only the 1st 3 digits are considered;
|
|
404
|
+
* empty strings are treated as '0'.
|
|
405
|
+
* @param parsedElement - element to be converted
|
|
406
|
+
* @returns parsed element as number
|
|
407
|
+
*/
|
|
408
|
+
function _toMsNumber(parsedElement) {
|
|
409
|
+
if (parsedElement === void 0) return;
|
|
410
|
+
return Number(parsedElement.toString().slice(0, 3));
|
|
411
|
+
}
|
|
412
|
+
function _parseImpl(date) {
|
|
413
|
+
if (date instanceof Date) return new Date(date);
|
|
414
|
+
if (date === null) return /* @__PURE__ */ new Date(NaN);
|
|
415
|
+
if (isUndefined(date)) return /* @__PURE__ */ new Date();
|
|
416
|
+
if (isEmptyObject(date)) return /* @__PURE__ */ new Date();
|
|
417
|
+
if (Array.isArray(date)) return parseArrayToDate.call(this, date);
|
|
418
|
+
if (typeof date === "string") {
|
|
419
|
+
let dateTrimmed = date.trimStart();
|
|
420
|
+
if (!/Z$/i.test(dateTrimmed)) {
|
|
421
|
+
const d = dateTrimmed.match(constants_default.REGEX_PARSE_DEFAULT);
|
|
422
|
+
if (d) {
|
|
423
|
+
const Y = _assertClassBrand(_EsDay_brand, this, _toNumber).call(this, d[1]);
|
|
424
|
+
const M = _assertClassBrand(_EsDay_brand, this, _toNumber).call(this, d[2]);
|
|
425
|
+
const D = _assertClassBrand(_EsDay_brand, this, _toNumber).call(this, d[3]);
|
|
426
|
+
const h = _assertClassBrand(_EsDay_brand, this, _toNumber).call(this, d[4]);
|
|
427
|
+
const m = _assertClassBrand(_EsDay_brand, this, _toNumber).call(this, d[5]);
|
|
428
|
+
const s = _assertClassBrand(_EsDay_brand, this, _toNumber).call(this, d[6]);
|
|
429
|
+
const ms = _assertClassBrand(_EsDay_brand, this, _toMsNumber).call(this, d[7]);
|
|
430
|
+
return this.dateFromDateComponents(Y, M, D, h, m, s, ms);
|
|
431
|
+
}
|
|
432
|
+
} else {
|
|
433
|
+
dateTrimmed = dateTrimmed.replace(/(\.\d{3})\d*(?=Z)/, "$1");
|
|
434
|
+
return new Date(dateTrimmed);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
if (typeof date === "string") date = date.replace(/(\.\d{3})\d*(?=Z)/, "$1");
|
|
438
|
+
return new Date(date);
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Getter / Setter for date components:
|
|
442
|
+
* esday().year(...args)
|
|
443
|
+
* esday().month(...args)
|
|
444
|
+
* esday().date(...args)
|
|
445
|
+
* esday().day(...args)
|
|
446
|
+
* esday().hour(...args)
|
|
447
|
+
* esday().minute(...args)
|
|
448
|
+
* esday().second(...args)
|
|
449
|
+
* esday().millisecond(...args)
|
|
450
|
+
*/
|
|
451
|
+
for (const key of prettyUnitsDate) EsDay.prototype[key] = function(...args) {
|
|
452
|
+
if (args?.length) return this.set(key, ...args);
|
|
453
|
+
return this.get(key);
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
//#endregion
|
|
457
|
+
//#region src/core/factory.ts
|
|
458
|
+
const esday = (d, ...others) => {
|
|
459
|
+
if (d instanceof EsDay) return d.clone();
|
|
460
|
+
const conf = {};
|
|
461
|
+
others.forEach((o, i) => {
|
|
462
|
+
if (isArray(o)) conf[`args_${i + 1}`] = o;
|
|
463
|
+
else if (isObject(o)) Object.assign(conf, o);
|
|
464
|
+
else conf[`args_${i + 1}`] = o;
|
|
465
|
+
});
|
|
466
|
+
const result = new EsDay(d, conf);
|
|
467
|
+
const resultConf = result["$conf"];
|
|
468
|
+
for (const property in resultConf) if (property.startsWith("args_")) delete resultConf[property];
|
|
469
|
+
return result;
|
|
470
|
+
};
|
|
471
|
+
esday.addFormatTokenDefinitions = addFormatTokenDefinitions;
|
|
472
|
+
esday.extend = (plugin, option) => {
|
|
473
|
+
if (!plugin.$i) {
|
|
474
|
+
plugin(option || {}, EsDay, esday);
|
|
475
|
+
plugin.$i = true;
|
|
476
|
+
}
|
|
477
|
+
return esday;
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
//#endregion
|
|
481
|
+
export { _checkPrivateRedeclaration as i, EsDay as n, _assertClassBrand as r, esday as t };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//#region src/common/str-utils.ts
|
|
2
|
+
/**
|
|
3
|
+
* Pad the start of a string with a specified character
|
|
4
|
+
* @param origin the string or number to pad
|
|
5
|
+
* @param length the length of the final string
|
|
6
|
+
* @param pad the character to pad with
|
|
7
|
+
* @returns the padded string
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* padStart('hello', 10, 'a') // 'aaaaahello'
|
|
12
|
+
*/
|
|
13
|
+
function padStart(origin, length, pad) {
|
|
14
|
+
const originStr = String(origin);
|
|
15
|
+
if (!originStr || originStr.length >= length) return originStr;
|
|
16
|
+
return `${Array.from({ length: length + 1 - originStr.length }).join(pad)}${originStr}`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Add leading zeros to a number to get the defined length: if
|
|
20
|
+
* the number is negative, the dash is appended after padding, the
|
|
21
|
+
* resulting string has 'length+1' characters
|
|
22
|
+
* @param origin the number to pad
|
|
23
|
+
* @param length the length of the final string (without dash)
|
|
24
|
+
* @returns the padded string
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
*
|
|
28
|
+
* padStart(1, 4) // '0001'
|
|
29
|
+
*/
|
|
30
|
+
function padNumberWithLeadingZeros(origin, length) {
|
|
31
|
+
const isNegative = origin < 0;
|
|
32
|
+
let result = String(origin);
|
|
33
|
+
let dash = "";
|
|
34
|
+
if (isNegative) {
|
|
35
|
+
result = result.slice(1);
|
|
36
|
+
dash = "-";
|
|
37
|
+
}
|
|
38
|
+
return `${dash}${result.padStart(length, "0")}`;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Format utcOffset as a string with format 'hh:mm':
|
|
42
|
+
* hh: hours of the utcOffset
|
|
43
|
+
* mm: minutes of the utcOffset
|
|
44
|
+
* @param utcOffset - utcOffset to convert to a string
|
|
45
|
+
* @returns utcOffset formatted as a string
|
|
46
|
+
*/
|
|
47
|
+
function padZoneStr(utcOffset) {
|
|
48
|
+
const negMinutes = -utcOffset;
|
|
49
|
+
const minutes = Math.abs(negMinutes);
|
|
50
|
+
const hourOffset = Math.floor(minutes / 60);
|
|
51
|
+
const minuteOffset = Math.trunc(minutes % 60);
|
|
52
|
+
return `${negMinutes <= 0 ? "+" : "-"}${padStart(hourOffset, 2, "0")}:${padStart(minuteOffset, 2, "0")}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
export { padStart as n, padZoneStr as r, padNumberWithLeadingZeros as t };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/common/is.ts
|
|
2
|
+
function isUndefined(value) {
|
|
3
|
+
return value === void 0;
|
|
4
|
+
}
|
|
5
|
+
function undefinedOr(v, or) {
|
|
6
|
+
return isUndefined(v) ? or : v;
|
|
7
|
+
}
|
|
8
|
+
function isObject(value) {
|
|
9
|
+
return typeof value === "object" && value !== null;
|
|
10
|
+
}
|
|
11
|
+
function isEmptyObject(value) {
|
|
12
|
+
return isObject(value) && Object.keys(value).length === 0;
|
|
13
|
+
}
|
|
14
|
+
function isString(value) {
|
|
15
|
+
return typeof value === "string";
|
|
16
|
+
}
|
|
17
|
+
function isArray(value) {
|
|
18
|
+
return Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
function isValidDate(value) {
|
|
21
|
+
return !Number.isNaN(value.valueOf());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { isUndefined as a, isString as i, isEmptyObject as n, isValidDate as o, isObject as r, undefinedOr as s, isArray as t };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { t as isArray } from "./v_QBn7Xm.js";
|
|
2
|
+
import { n as normalizeUnitWithPlurals } from "./AyQQ6US-.js";
|
|
3
|
+
|
|
4
|
+
//#region src/common/date-fields.ts
|
|
5
|
+
/**
|
|
6
|
+
* Map units to fields of a javascript Date object.
|
|
7
|
+
*/
|
|
8
|
+
const UNIT_FIELD_MAP = {
|
|
9
|
+
year: "FullYear",
|
|
10
|
+
month: "Month",
|
|
11
|
+
date: "Date",
|
|
12
|
+
day: "Day",
|
|
13
|
+
hour: "Hours",
|
|
14
|
+
minute: "Minutes",
|
|
15
|
+
second: "Seconds",
|
|
16
|
+
millisecond: "Milliseconds"
|
|
17
|
+
};
|
|
18
|
+
const prettyUnitsDate = Object.keys(UNIT_FIELD_MAP);
|
|
19
|
+
function unitToField(unit) {
|
|
20
|
+
return UNIT_FIELD_MAP[normalizeUnitWithPlurals(unit)];
|
|
21
|
+
}
|
|
22
|
+
function getUnitInDate(date, unit) {
|
|
23
|
+
return date[`get${unitToField(unit)}`]();
|
|
24
|
+
}
|
|
25
|
+
function getUnitInDateUTC(date, unit) {
|
|
26
|
+
return date[`getUTC${unitToField(unit)}`]();
|
|
27
|
+
}
|
|
28
|
+
function setUnitInDate(date, unit, value) {
|
|
29
|
+
date[`set${unitToField(unit)}`](...isArray(value) ? value : [value]);
|
|
30
|
+
return date;
|
|
31
|
+
}
|
|
32
|
+
function setUnitInDateUTC(date, unit, value) {
|
|
33
|
+
date[`setUTC${unitToField(unit)}`](...isArray(value) ? value : [value]);
|
|
34
|
+
return date;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { setUnitInDateUTC as a, setUnitInDate as i, getUnitInDateUTC as n, prettyUnitsDate as r, getUnitInDate as t };
|
package/index.d.mts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { A as UnitQuarter, C as UnitDay, D as UnitMin, F as UnitTypeGetSet, L as UnitWeek, M as UnitType, N as UnitTypeAddSub, O as UnitMonth, P as UnitTypeCore, R as UnitYear, T as UnitIsoWeek, _ as PrettyUnitAsPlural, a as EsDayFactoryParserFn, b as ShortUnit, c as ParsingObject, d as ParsingObjectShort, f as UnitsObjectTypeAddSub, g as LongUnit, h as SimpleType, i as EsDayFactory, j as UnitSecond, k as UnitMs, l as ParsingObjectLong, m as SimpleObject, n as DateFromDateComponents, o as EsDayPlugin, p as UnitsObjectTypeSet, r as DateType, s as FormattingTokenDefinitions, t as EsDay, u as ParsingObjectPlurals, v as PrettyUnitAsSingular, w as UnitHour, x as UnitDate, y as PrettyUnitFromPlurals } from "./chunks/CODi8AFH.js";
|
|
2
|
+
import { t as esday } from "./chunks/C5qDMHT5.js";
|
|
3
|
+
export { DateFromDateComponents, DateType, EsDay, EsDayFactory, EsDayFactoryParserFn, EsDayPlugin, FormattingTokenDefinitions, LongUnit, ParsingObject, ParsingObjectLong, ParsingObjectPlurals, ParsingObjectShort, PrettyUnitAsPlural, PrettyUnitAsSingular, PrettyUnitFromPlurals, ShortUnit, SimpleObject, SimpleType, UnitDate, UnitDay, UnitHour, UnitIsoWeek, UnitMin, UnitMonth, UnitMs, UnitQuarter, UnitSecond, UnitType, UnitTypeAddSub, UnitTypeCore, UnitTypeGetSet, UnitWeek, UnitYear, UnitsObjectTypeAddSub, UnitsObjectTypeSet, esday };
|
package/index.mjs
ADDED