esday 0.4.1 → 0.5.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 +8 -0
- package/LICENSE +21 -0
- package/README.md +20 -2
- package/chunks/B5f9poqo.js +120 -0
- package/chunks/BDssPbM_.js +106 -0
- package/chunks/BRRrAbUl.js +56 -0
- package/chunks/BXRGSAJG.js +128 -0
- package/chunks/BeVgU2nj.js +188 -0
- package/chunks/BtmEtAW3.js +43 -0
- package/chunks/CQ57zhVp.js +106 -0
- package/chunks/CQJ0-ZuR.js +106 -0
- package/chunks/CWqzr5E5.js +108 -0
- package/chunks/Cb5SvF6r.js +25 -0
- package/chunks/Cg4ZI9v8.js +180 -0
- package/chunks/CoBtJ4c1.js +144 -0
- package/chunks/D009Z-ld.js +109 -0
- package/chunks/DMtTiWuY.js +127 -0
- package/chunks/DXHbH1CI.js +9 -0
- package/chunks/Dixb5KKs.js +116 -0
- package/chunks/DjY7KvwG.js +28 -0
- package/chunks/DqhiVwLi.d.ts +203 -0
- package/chunks/GjKpN6U-.js +135 -0
- package/chunks/MtjcOKi-.d.ts +6 -0
- package/chunks/St35qgL0.d.ts +103 -0
- package/chunks/Y32qdU_5.js +62 -0
- package/chunks/br7kModF.js +110 -0
- package/chunks/l2Rxo2H0.js +106 -0
- package/chunks/tfkJ5D3p.js +115 -0
- package/index.d.ts +3 -6
- package/index.js +556 -293
- package/locales/af.d.ts +8 -0
- package/locales/af.js +106 -0
- package/locales/am.d.ts +8 -0
- package/locales/am.js +106 -0
- package/locales/ar-dz.d.ts +11 -0
- package/locales/ar-dz.js +32 -0
- package/locales/ar-iq.d.ts +11 -0
- package/locales/ar-iq.js +14 -0
- package/locales/ar-kw.d.ts +11 -0
- package/locales/ar-kw.js +28 -0
- package/locales/ar-ly.d.ts +11 -0
- package/locales/ar-ly.js +14 -0
- package/locales/ar-ma.d.ts +11 -0
- package/locales/ar-ma.js +29 -0
- package/locales/ar-sa.d.ts +11 -0
- package/locales/ar-sa.js +29 -0
- package/locales/ar-tn.d.ts +11 -0
- package/locales/ar-tn.js +29 -0
- package/locales/ar.d.ts +8 -0
- package/locales/ar.js +3 -0
- package/locales/az.d.ts +8 -0
- package/locales/az.js +106 -0
- package/locales/be.d.ts +8 -0
- package/locales/be.js +140 -0
- package/locales/bg.d.ts +8 -0
- package/locales/bg.js +125 -0
- package/locales/bi.d.ts +8 -0
- package/locales/bi.js +106 -0
- package/locales/bm.d.ts +8 -0
- package/locales/bm.js +106 -0
- package/locales/bn-bd.d.ts +11 -0
- package/locales/bn-bd.js +24 -0
- package/locales/bn.d.ts +8 -0
- package/locales/bn.js +3 -0
- package/locales/bo.d.ts +8 -0
- package/locales/bo.js +106 -0
- package/locales/br.d.ts +8 -0
- package/locales/br.js +179 -0
- package/locales/bs.d.ts +8 -0
- package/locales/bs.js +128 -0
- package/locales/ca.d.ts +8 -0
- package/locales/ca.js +143 -0
- package/locales/cs.d.ts +8 -0
- package/locales/cs.js +182 -0
- package/locales/cv.d.ts +8 -0
- package/locales/cv.js +106 -0
- package/locales/cy.d.ts +8 -0
- package/locales/cy.js +106 -0
- package/locales/da.d.ts +8 -0
- package/locales/da.js +106 -0
- package/locales/de-at.d.ts +11 -0
- package/locales/de-at.js +44 -0
- package/locales/de-ch.d.ts +11 -0
- package/locales/de-ch.js +14 -0
- package/locales/de.d.ts +8 -0
- package/locales/de.js +3 -0
- package/locales/dv.d.ts +8 -0
- package/locales/dv.js +106 -0
- package/locales/el.d.ts +8 -0
- package/locales/el.js +115 -0
- package/locales/en-au.d.ts +11 -0
- package/locales/en-au.js +27 -0
- package/locales/en-ca.d.ts +11 -0
- package/locales/en-ca.js +27 -0
- package/locales/en-gb.d.ts +13 -0
- package/locales/en-gb.js +28 -0
- package/locales/en-ie.d.ts +11 -0
- package/locales/en-ie.js +26 -0
- package/locales/en-il.d.ts +11 -0
- package/locales/en-il.js +28 -0
- package/locales/en-in.d.ts +11 -0
- package/locales/en-in.js +26 -0
- package/locales/en-nz.d.ts +11 -0
- package/locales/en-nz.js +28 -0
- package/locales/en-sg.d.ts +11 -0
- package/locales/en-sg.js +28 -0
- package/locales/en-tt.d.ts +11 -0
- package/locales/en-tt.js +28 -0
- package/locales/en-us.d.ts +11 -0
- package/locales/en-us.js +13 -0
- package/locales/en.d.ts +7 -5
- package/locales/en.js +3 -1
- package/locales/eo.d.ts +8 -0
- package/locales/eo.js +106 -0
- package/locales/es-do.d.ts +11 -0
- package/locales/es-do.js +27 -0
- package/locales/es-mx.d.ts +11 -0
- package/locales/es-mx.js +15 -0
- package/locales/es-pr.d.ts +11 -0
- package/locales/es-pr.js +18 -0
- package/locales/es-us.d.ts +11 -0
- package/locales/es-us.js +14 -0
- package/locales/es.d.ts +8 -0
- package/locales/es.js +3 -0
- package/locales/et.d.ts +8 -0
- package/locales/et.js +142 -0
- package/locales/eu.d.ts +8 -0
- package/locales/eu.js +106 -0
- package/locales/fa.d.ts +8 -0
- package/locales/fa.js +106 -0
- package/locales/fi.d.ts +8 -0
- package/locales/fi.js +165 -0
- package/locales/fil.d.ts +8 -0
- package/locales/fil.js +106 -0
- package/locales/fo.d.ts +8 -0
- package/locales/fo.js +106 -0
- package/locales/fr-ca.d.ts +11 -0
- package/locales/fr-ca.js +18 -0
- package/locales/fr-ch.d.ts +11 -0
- package/locales/fr-ch.js +18 -0
- package/locales/fr.d.ts +8 -0
- package/locales/fr.js +3 -0
- package/locales/fy.d.ts +8 -0
- package/locales/fy.js +106 -0
- package/locales/ga.d.ts +8 -0
- package/locales/ga.js +106 -0
- package/locales/gd.d.ts +8 -0
- package/locales/gd.js +106 -0
- package/locales/gl.d.ts +8 -0
- package/locales/gl.js +116 -0
- package/locales/gom-deva.d.ts +8 -0
- package/locales/gom-deva.js +146 -0
- package/locales/gom-latn.d.ts +8 -0
- package/locales/gom-latn.js +146 -0
- package/locales/gu.d.ts +8 -0
- package/locales/gu.js +106 -0
- package/locales/he.d.ts +8 -0
- package/locales/he.js +129 -0
- package/locales/hi.d.ts +8 -0
- package/locales/hi.js +125 -0
- package/locales/hr.d.ts +8 -0
- package/locales/hr.js +189 -0
- package/locales/ht.d.ts +8 -0
- package/locales/ht.js +106 -0
- package/locales/hu.d.ts +8 -0
- package/locales/hu.js +140 -0
- package/locales/hy-am.d.ts +8 -0
- package/locales/hy-am.js +127 -0
- package/locales/id.d.ts +8 -0
- package/locales/id.js +106 -0
- package/locales/is.d.ts +8 -0
- package/locales/is.js +155 -0
- package/locales/it-ch.d.ts +11 -0
- package/locales/it-ch.js +32 -0
- package/locales/it.d.ts +8 -0
- package/locales/it.js +3 -0
- package/locales/ja.d.ts +15 -0
- package/locales/ja.js +109 -0
- package/locales/jv.d.ts +8 -0
- package/locales/jv.js +106 -0
- package/locales/ka.d.ts +8 -0
- package/locales/ka.js +126 -0
- package/locales/kk.d.ts +8 -0
- package/locales/kk.js +106 -0
- package/locales/km.d.ts +8 -0
- package/locales/km.js +106 -0
- package/locales/kn.d.ts +8 -0
- package/locales/kn.js +106 -0
- package/locales/ko.d.ts +8 -0
- package/locales/ko.js +105 -0
- package/locales/ku.d.ts +8 -0
- package/locales/ku.js +119 -0
- package/locales/ky.d.ts +8 -0
- package/locales/ky.js +106 -0
- package/locales/lb.d.ts +8 -0
- package/locales/lb.js +166 -0
- package/locales/lo.d.ts +8 -0
- package/locales/lo.js +105 -0
- package/locales/lt.d.ts +8 -0
- package/locales/lt.js +106 -0
- package/locales/lv.d.ts +8 -0
- package/locales/lv.js +106 -0
- package/locales/me.d.ts +8 -0
- package/locales/me.js +129 -0
- package/locales/mi.d.ts +8 -0
- package/locales/mi.js +106 -0
- package/locales/mk.d.ts +8 -0
- package/locales/mk.js +117 -0
- package/locales/ml.d.ts +8 -0
- package/locales/ml.js +109 -0
- package/locales/mn.d.ts +8 -0
- package/locales/mn.js +106 -0
- package/locales/mr.d.ts +8 -0
- package/locales/mr.js +215 -0
- package/locales/ms-my.d.ts +11 -0
- package/locales/ms-my.js +14 -0
- package/locales/ms.d.ts +8 -0
- package/locales/ms.js +3 -0
- package/locales/mt.d.ts +8 -0
- package/locales/mt.js +106 -0
- package/locales/my.d.ts +8 -0
- package/locales/my.js +132 -0
- package/locales/nb.d.ts +8 -0
- package/locales/nb.js +106 -0
- package/locales/ne.d.ts +8 -0
- package/locales/ne.js +106 -0
- package/locales/nl-be.d.ts +11 -0
- package/locales/nl-be.js +18 -0
- package/locales/nl.d.ts +8 -0
- package/locales/nl.js +3 -0
- package/locales/nn.d.ts +8 -0
- package/locales/nn.js +106 -0
- package/locales/oc-lnc.d.ts +8 -0
- package/locales/oc-lnc.js +126 -0
- package/locales/pa-in.d.ts +8 -0
- package/locales/pa-in.js +123 -0
- package/locales/pl.d.ts +8 -0
- package/locales/pl.js +159 -0
- package/locales/pt-br.d.ts +11 -0
- package/locales/pt-br.js +53 -0
- package/locales/pt.d.ts +8 -0
- package/locales/pt.js +3 -0
- package/locales/rn.d.ts +8 -0
- package/locales/rn.js +106 -0
- package/locales/ro.d.ts +8 -0
- package/locales/ro.js +106 -0
- package/locales/ru.d.ts +15 -0
- package/locales/ru.js +236 -0
- package/locales/rw.d.ts +8 -0
- package/locales/rw.js +106 -0
- package/locales/sd.d.ts +8 -0
- package/locales/sd.js +106 -0
- package/locales/se.d.ts +8 -0
- package/locales/se.js +106 -0
- package/locales/si.d.ts +8 -0
- package/locales/si.js +106 -0
- package/locales/sk.d.ts +8 -0
- package/locales/sk.js +162 -0
- package/locales/sl.d.ts +8 -0
- package/locales/sl.js +171 -0
- package/locales/sq.d.ts +8 -0
- package/locales/sq.js +106 -0
- package/locales/sr-cyrl.d.ts +11 -0
- package/locales/sr-cyrl.js +173 -0
- package/locales/sr.d.ts +8 -0
- package/locales/sr.js +3 -0
- package/locales/ss.d.ts +8 -0
- package/locales/ss.js +108 -0
- package/locales/sv-fi.d.ts +11 -0
- package/locales/sv-fi.js +27 -0
- package/locales/sv.d.ts +8 -0
- package/locales/sv.js +3 -0
- package/locales/sw.d.ts +8 -0
- package/locales/sw.js +106 -0
- package/locales/ta.d.ts +8 -0
- package/locales/ta.js +137 -0
- package/locales/te.d.ts +8 -0
- package/locales/te.js +109 -0
- package/locales/tet.d.ts +8 -0
- package/locales/tet.js +110 -0
- package/locales/tg.d.ts +8 -0
- package/locales/tg.js +128 -0
- package/locales/th.d.ts +8 -0
- package/locales/th.js +106 -0
- package/locales/tk.d.ts +8 -0
- package/locales/tk.js +134 -0
- package/locales/tl-ph.d.ts +8 -0
- package/locales/tl-ph.js +106 -0
- package/locales/tlh.d.ts +8 -0
- package/locales/tlh.js +152 -0
- package/locales/tr.d.ts +8 -0
- package/locales/tr.js +134 -0
- package/locales/tzl.d.ts +8 -0
- package/locales/tzl.js +123 -0
- package/locales/tzm-latn.d.ts +11 -0
- package/locales/tzm-latn.js +68 -0
- package/locales/tzm.d.ts +8 -0
- package/locales/tzm.js +3 -0
- package/locales/ug-cn.d.ts +8 -0
- package/locales/ug-cn.js +111 -0
- package/locales/uk.d.ts +8 -0
- package/locales/uk.js +194 -0
- package/locales/ur.d.ts +8 -0
- package/locales/ur.js +108 -0
- package/locales/uz-latn.d.ts +11 -0
- package/locales/uz-latn.js +68 -0
- package/locales/uz.d.ts +8 -0
- package/locales/uz.js +3 -0
- package/locales/vi.d.ts +8 -0
- package/locales/vi.js +106 -0
- package/locales/x-pseudo.d.ts +8 -0
- package/locales/x-pseudo.js +110 -0
- package/locales/yo.d.ts +8 -0
- package/locales/yo.js +106 -0
- package/locales/zh-cn.d.ts +11 -0
- package/locales/zh-cn.js +14 -0
- package/locales/zh-hk.d.ts +11 -0
- package/locales/zh-hk.js +23 -0
- package/locales/zh-mo.d.ts +11 -0
- package/locales/zh-mo.js +23 -0
- package/locales/zh-tw.d.ts +11 -0
- package/locales/zh-tw.js +23 -0
- package/locales/zh.d.ts +13 -4
- package/locales/zh.js +2 -63
- package/package.json +51 -25
- package/plugins/advancedFormat/index.d.ts +8 -0
- package/plugins/advancedFormat/index.js +20 -0
- package/plugins/advancedParse/index.d.ts +8 -0
- package/plugins/advancedParse/index.js +406 -0
- package/plugins/calendar/index.d.ts +14 -0
- package/plugins/calendar/index.js +33 -0
- package/plugins/dayOfYear/index.d.ts +13 -0
- package/plugins/dayOfYear/index.js +12 -0
- package/plugins/isBetween/index.d.ts +23 -0
- package/plugins/isBetween/index.js +16 -0
- package/plugins/isLeapYear/index.d.ts +12 -0
- package/plugins/isLeapYear/index.js +11 -0
- package/plugins/isSameOrAfter/index.d.ts +12 -0
- package/plugins/isSameOrAfter/index.js +10 -0
- package/plugins/isSameOrBefore/index.d.ts +12 -0
- package/plugins/isSameOrBefore/index.js +10 -0
- package/plugins/isToday/index.d.ts +8 -6
- package/plugins/isToday/index.js +10 -6
- package/plugins/isTomorrow/index.d.ts +12 -0
- package/plugins/isTomorrow/index.js +14 -0
- package/plugins/isYesterday/index.d.ts +12 -0
- package/plugins/isYesterday/index.js +14 -0
- package/plugins/isoWeek/index.d.ts +21 -0
- package/plugins/isoWeek/index.js +240 -0
- package/plugins/locale/index.d.ts +4 -75
- package/plugins/locale/index.js +6 -69
- package/plugins/localeData/index.d.ts +8 -0
- package/plugins/localeData/index.js +148 -0
- package/plugins/localizedFormat/index.d.ts +8 -0
- package/plugins/localizedFormat/index.js +88 -0
- package/plugins/localizedParse/index.d.ts +8 -0
- package/plugins/localizedParse/index.js +199 -0
- package/plugins/minMax/index.d.ts +13 -0
- package/plugins/minMax/index.js +22 -0
- package/plugins/objectSupport/index.d.ts +8 -0
- package/plugins/objectSupport/index.js +104 -0
- package/plugins/pluralGetSet/index.d.ts +20 -0
- package/plugins/pluralGetSet/index.js +16 -0
- package/plugins/quarterOfYear/index.d.ts +16 -0
- package/plugins/quarterOfYear/index.js +58 -0
- package/plugins/relativeTime/index.d.ts +59 -0
- package/plugins/relativeTime/index.js +154 -0
- package/plugins/toArray/index.d.ts +12 -0
- package/plugins/toArray/index.js +18 -0
- package/plugins/toObject/index.d.ts +20 -0
- package/plugins/toObject/index.js +18 -0
- package/plugins/utc/index.d.ts +14 -17
- package/plugins/utc/index.js +191 -37
- package/plugins/week/index.d.ts +21 -0
- package/plugins/week/index.js +360 -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/plugins/customParseFormat/index.d.ts +0 -5
- package/plugins/customParseFormat/index.js +0 -159
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { constants_default } from "../../chunks/Y32qdU_5.js";
|
|
2
|
+
import { createInstanceFromExist } from "../../chunks/DXHbH1CI.js";
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/relativeTime/index.ts
|
|
5
|
+
const relativeTimePlugin = (options, dayClass, dayFactory) => {
|
|
6
|
+
const proto = dayClass.prototype;
|
|
7
|
+
const defaultRelativeTimeDef = {
|
|
8
|
+
future: "in %s",
|
|
9
|
+
past: "%s ago",
|
|
10
|
+
s: "a few seconds",
|
|
11
|
+
ss: "%d seconds",
|
|
12
|
+
m: "a minute",
|
|
13
|
+
mm: "%d minutes",
|
|
14
|
+
h: "an hour",
|
|
15
|
+
hh: "%d hours",
|
|
16
|
+
d: "a day",
|
|
17
|
+
dd: "%d days",
|
|
18
|
+
M: "a month",
|
|
19
|
+
MM: "%d months",
|
|
20
|
+
y: "a year",
|
|
21
|
+
yy: "%d years"
|
|
22
|
+
};
|
|
23
|
+
const thresholds = options.thresholds ?? [
|
|
24
|
+
{
|
|
25
|
+
key: "s",
|
|
26
|
+
thresholdValue: 44,
|
|
27
|
+
thresholdUnit: constants_default.SECOND
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
key: "ss",
|
|
31
|
+
thresholdValue: 43,
|
|
32
|
+
thresholdUnit: constants_default.SECOND
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
key: "m",
|
|
36
|
+
thresholdValue: 89,
|
|
37
|
+
thresholdUnit: constants_default.SECOND
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
key: "mm",
|
|
41
|
+
thresholdValue: 44,
|
|
42
|
+
thresholdUnit: constants_default.MIN
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: "h",
|
|
46
|
+
thresholdValue: 89,
|
|
47
|
+
thresholdUnit: constants_default.MIN
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
key: "hh",
|
|
51
|
+
thresholdValue: 21,
|
|
52
|
+
thresholdUnit: constants_default.HOUR
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
key: "d",
|
|
56
|
+
thresholdValue: 35,
|
|
57
|
+
thresholdUnit: constants_default.HOUR
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
key: "dd",
|
|
61
|
+
thresholdValue: 25,
|
|
62
|
+
thresholdUnit: constants_default.DAY
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
key: "M",
|
|
66
|
+
thresholdValue: 45,
|
|
67
|
+
thresholdUnit: constants_default.DAY
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
key: "MM",
|
|
71
|
+
thresholdValue: 10,
|
|
72
|
+
thresholdUnit: constants_default.MONTH
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
key: "y",
|
|
76
|
+
thresholdValue: 17,
|
|
77
|
+
thresholdUnit: constants_default.MONTH
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
key: "yy",
|
|
81
|
+
thresholdUnit: constants_default.YEAR
|
|
82
|
+
}
|
|
83
|
+
];
|
|
84
|
+
const rounding = options.rounding ?? Math.round;
|
|
85
|
+
/**
|
|
86
|
+
* Calculate the difference between instance and referenceDate in given units
|
|
87
|
+
* as fractional value for 'from' and 'to'
|
|
88
|
+
* @param instance - date to calculate difference for
|
|
89
|
+
* @param referenceDate - base date for calculating the difference
|
|
90
|
+
* @param unit - unit of the difference
|
|
91
|
+
* @param isFrom - difference for 'from'?
|
|
92
|
+
* @returns difference as float
|
|
93
|
+
*/
|
|
94
|
+
function differenceInUnits(instance, referenceDate, unit, isFrom) {
|
|
95
|
+
return isFrom ? referenceDate.diff(instance, unit, true) : instance.diff(referenceDate, unit, true);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Format instance date as relative to reference date as
|
|
99
|
+
* human readable length of time.
|
|
100
|
+
* @param reference - date the output relates to
|
|
101
|
+
* @param withoutSuffix - format without 'in ---' or '... ago'
|
|
102
|
+
* @param this - date to format
|
|
103
|
+
* @param isFrom - format as 'from' or 'fromNow'
|
|
104
|
+
* @returns difference formatted as human string (e.g. 5 days ago)
|
|
105
|
+
*/
|
|
106
|
+
function fromToBase(reference, withoutSuffix, isFrom) {
|
|
107
|
+
const referenceDate = dayFactory(reference);
|
|
108
|
+
if (!(this.isValid() && referenceDate.isValid())) return constants_default.INVALID_DATE_STRING;
|
|
109
|
+
const locale = this.localeObject?.();
|
|
110
|
+
const relativeTimeDef = locale?.relativeTime ?? defaultRelativeTimeDef;
|
|
111
|
+
let diffAsUnit = 0;
|
|
112
|
+
let out = "";
|
|
113
|
+
let isFuture = false;
|
|
114
|
+
for (let i = 0; i < thresholds.length; i++) {
|
|
115
|
+
const threshold = thresholds[i];
|
|
116
|
+
const thresholdUnit = threshold.thresholdUnit ?? constants_default.SECOND;
|
|
117
|
+
diffAsUnit = differenceInUnits(this, referenceDate, thresholdUnit, isFrom);
|
|
118
|
+
const absoluteDiff = rounding(Math.abs(diffAsUnit));
|
|
119
|
+
isFuture = diffAsUnit > 0;
|
|
120
|
+
if (absoluteDiff <= (threshold.thresholdValue ?? Number.POSITIVE_INFINITY)) {
|
|
121
|
+
const thresholdKey = threshold.key;
|
|
122
|
+
const formatUnit = thresholdKey.slice(0, 1);
|
|
123
|
+
const outputDiff = differenceInUnits(this, referenceDate, formatUnit, isFrom);
|
|
124
|
+
const outputDiffAbs = rounding(Math.abs(outputDiff));
|
|
125
|
+
const format = relativeTimeDef[thresholdKey];
|
|
126
|
+
out = typeof format === "string" ? format.replace("%d", `${outputDiffAbs}`) : format(outputDiffAbs, withoutSuffix, thresholdKey, isFuture);
|
|
127
|
+
const postFormat = locale?.postFormat;
|
|
128
|
+
if (postFormat) out = postFormat(out);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (withoutSuffix) return out;
|
|
133
|
+
const suffix = isFuture ? relativeTimeDef.future : relativeTimeDef.past;
|
|
134
|
+
return typeof suffix === "function" ? suffix(out, withoutSuffix, isFuture ? "future" : "past", isFuture) : suffix.replace("%s", out);
|
|
135
|
+
}
|
|
136
|
+
proto.to = function(referenceDate, withoutSuffix) {
|
|
137
|
+
return fromToBase.call(this, referenceDate, withoutSuffix ?? false, true);
|
|
138
|
+
};
|
|
139
|
+
proto.from = function(referenceDate, withoutSuffix) {
|
|
140
|
+
return fromToBase.call(this, referenceDate, withoutSuffix ?? false, false);
|
|
141
|
+
};
|
|
142
|
+
proto.toNow = function(withoutSuffix) {
|
|
143
|
+
const now = createInstanceFromExist(/* @__PURE__ */ new Date(), this);
|
|
144
|
+
return this.to(now, withoutSuffix);
|
|
145
|
+
};
|
|
146
|
+
proto.fromNow = function(withoutSuffix) {
|
|
147
|
+
const now = createInstanceFromExist(/* @__PURE__ */ new Date(), this);
|
|
148
|
+
return this.from(now, withoutSuffix);
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
var relativeTime_default = relativeTimePlugin;
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
export { relativeTime_default as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EsDayPlugin } from "../../chunks/DqhiVwLi.js";
|
|
2
|
+
import "../../chunks/MtjcOKi-.js";
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/toArray/index.d.ts
|
|
5
|
+
declare module 'esday' {
|
|
6
|
+
interface EsDay {
|
|
7
|
+
toArray: () => [number, number, number, number, number, number, number];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
declare const toArrayPlugin: EsDayPlugin<{}>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { toArrayPlugin as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/plugins/toArray/index.ts
|
|
2
|
+
const toArrayPlugin = (_, dayClass) => {
|
|
3
|
+
dayClass.prototype.toArray = function() {
|
|
4
|
+
return [
|
|
5
|
+
this.year(),
|
|
6
|
+
this.month(),
|
|
7
|
+
this.date(),
|
|
8
|
+
this.hour(),
|
|
9
|
+
this.minute(),
|
|
10
|
+
this.second(),
|
|
11
|
+
this.millisecond()
|
|
12
|
+
];
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
var toArray_default = toArrayPlugin;
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { toArray_default as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EsDayPlugin } from "../../chunks/DqhiVwLi.js";
|
|
2
|
+
import "../../chunks/MtjcOKi-.js";
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/toObject/index.d.ts
|
|
5
|
+
declare module 'esday' {
|
|
6
|
+
interface EsDay {
|
|
7
|
+
toObject: () => {
|
|
8
|
+
years: number;
|
|
9
|
+
months: number;
|
|
10
|
+
date: number;
|
|
11
|
+
hours: number;
|
|
12
|
+
minutes: number;
|
|
13
|
+
seconds: number;
|
|
14
|
+
milliseconds: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
declare const toObjectPlugin: EsDayPlugin<{}>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { toObjectPlugin as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/plugins/toObject/index.ts
|
|
2
|
+
const toObjectPlugin = (_, dayClass) => {
|
|
3
|
+
dayClass.prototype.toObject = function() {
|
|
4
|
+
return {
|
|
5
|
+
years: this.year(),
|
|
6
|
+
months: this.month(),
|
|
7
|
+
date: this.date(),
|
|
8
|
+
hours: this.hour(),
|
|
9
|
+
minutes: this.minute(),
|
|
10
|
+
seconds: this.second(),
|
|
11
|
+
milliseconds: this.millisecond()
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
var toObject_default = toObjectPlugin;
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { toObject_default as default };
|
package/plugins/utc/index.d.ts
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DateType, EsDayPlugin, SimpleType } from "../../chunks/DqhiVwLi.js";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* utc plugin
|
|
5
|
-
*
|
|
6
|
-
* when utc mode is enabled, get and set methods will use UTC time
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
3
|
+
//#region src/plugins/utc/index.d.ts
|
|
9
4
|
|
|
10
5
|
declare module 'esday' {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
interface EsDay {
|
|
7
|
+
utc: (keepLocalTime?: boolean) => EsDay;
|
|
8
|
+
local: () => EsDay;
|
|
9
|
+
isUTC: () => boolean;
|
|
10
|
+
}
|
|
11
|
+
interface EsDayFactory {
|
|
12
|
+
utc: (date?: DateType, ...others: (SimpleType | string[] | {
|
|
13
|
+
[key: string]: SimpleType;
|
|
14
|
+
})[]) => EsDay;
|
|
15
|
+
}
|
|
19
16
|
}
|
|
20
17
|
declare const utcPlugin: EsDayPlugin<{}>;
|
|
21
|
-
|
|
22
|
-
export { utcPlugin };
|
|
18
|
+
//#endregion
|
|
19
|
+
export { utcPlugin as default };
|
package/plugins/utc/index.js
CHANGED
|
@@ -1,40 +1,194 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { constants_default } from "../../chunks/Y32qdU_5.js";
|
|
2
|
+
import { isObject, isUndefined } from "../../chunks/Cb5SvF6r.js";
|
|
3
|
+
import { normalizeUnitWithPlurals } from "../../chunks/DjY7KvwG.js";
|
|
4
|
+
import { getUnitInDateUTC, setUnitInDateUTC } from "../../chunks/BtmEtAW3.js";
|
|
5
|
+
import { createInstanceFromExist } from "../../chunks/DXHbH1CI.js";
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
7
|
+
//#region src/plugins/utc/index.ts
|
|
8
|
+
const REGEX_VALID_OFFSET_FORMAT = /[+-]\d\d(?::?\d\d)?/g;
|
|
9
|
+
const REGEX_OFFSET_HOURS_MINUTES_FORMAT = /[+-]|\d\d/g;
|
|
10
|
+
function offsetFromString(value = "") {
|
|
11
|
+
const offset = value.match(REGEX_VALID_OFFSET_FORMAT);
|
|
12
|
+
if (!offset) return NaN;
|
|
13
|
+
const [indicator, hoursOffset, minutesOffset] = Object.assign([
|
|
14
|
+
"-",
|
|
15
|
+
0,
|
|
16
|
+
0
|
|
17
|
+
], `${offset[0]}`.match(REGEX_OFFSET_HOURS_MINUTES_FORMAT));
|
|
18
|
+
const totalOffsetInMinutes = +hoursOffset * 60 + +minutesOffset;
|
|
19
|
+
if (totalOffsetInMinutes === 0) return 0;
|
|
20
|
+
return indicator === "+" ? totalOffsetInMinutes : -totalOffsetInMinutes;
|
|
21
|
+
}
|
|
22
|
+
function utcOffsetGetImpl(that, defaultValue = NaN) {
|
|
23
|
+
if (that["$conf"].utc) return 0;
|
|
24
|
+
if (that["$conf"].offset !== void 0) return Number(that["$conf"].offset);
|
|
25
|
+
return defaultValue;
|
|
26
|
+
}
|
|
27
|
+
function utcOffsetSetImpl(that, offset, keepLocalTime) {
|
|
28
|
+
let offsetAsNumber;
|
|
29
|
+
if (typeof offset === "string") {
|
|
30
|
+
offsetAsNumber = offsetFromString(offset);
|
|
31
|
+
if (Number.isNaN(offsetAsNumber)) return that;
|
|
32
|
+
} else offsetAsNumber = offset;
|
|
33
|
+
const offsetAsMinutes = Math.abs(offsetAsNumber) <= 16 ? offsetAsNumber * 60 : offsetAsNumber;
|
|
34
|
+
if (keepLocalTime) {
|
|
35
|
+
const localTimezoneOffset = that["$conf"].utc ? that.toDate().getTimezoneOffset() : -1 * that.utcOffset();
|
|
36
|
+
let instance = that;
|
|
37
|
+
if (that["$conf"].utc) {
|
|
38
|
+
instance = instance.add(localTimezoneOffset, constants_default.MIN);
|
|
39
|
+
instance["$conf"].utc = offsetAsMinutes === 0;
|
|
40
|
+
}
|
|
41
|
+
instance["$conf"].offset = offsetAsMinutes;
|
|
42
|
+
instance["$conf"].tzOffset = localTimezoneOffset;
|
|
43
|
+
return instance;
|
|
44
|
+
}
|
|
45
|
+
if (offsetAsNumber !== 0) {
|
|
46
|
+
const localTimezoneOffset = that["$conf"].utc ? that.toDate().getTimezoneOffset() : -1 * that.utcOffset();
|
|
47
|
+
const instance = that.local().add(offsetAsMinutes + localTimezoneOffset, constants_default.MIN);
|
|
48
|
+
instance["$conf"].offset = offsetAsMinutes;
|
|
49
|
+
instance["$conf"].tzOffset = localTimezoneOffset;
|
|
50
|
+
return instance;
|
|
51
|
+
}
|
|
52
|
+
return that.utc();
|
|
53
|
+
}
|
|
54
|
+
function addUtc(that, value, units) {
|
|
55
|
+
const $d = that["$d"];
|
|
56
|
+
const unit = normalizeUnitWithPlurals(units);
|
|
57
|
+
const instanceFactorySet = (multiplier) => {
|
|
58
|
+
const newInstance = that.clone();
|
|
59
|
+
newInstance["$d"].setUTCDate($d.getUTCDate() + Math.round(multiplier * value));
|
|
60
|
+
return newInstance;
|
|
61
|
+
};
|
|
62
|
+
switch (normalizeUnitWithPlurals(unit)) {
|
|
63
|
+
case constants_default.YEAR: return that.set("year", that.get("year") + value);
|
|
64
|
+
case constants_default.MONTH: return that.set("month", that.get("month") + value);
|
|
65
|
+
case constants_default.WEEK: return instanceFactorySet(7);
|
|
66
|
+
case constants_default.DAY:
|
|
67
|
+
case constants_default.DAY_OF_MONTH: return instanceFactorySet(1);
|
|
68
|
+
case constants_default.HOUR:
|
|
69
|
+
case constants_default.MIN:
|
|
70
|
+
case constants_default.SECOND:
|
|
71
|
+
case constants_default.MS: {
|
|
72
|
+
const step = {
|
|
73
|
+
minute: 60 * 1e3,
|
|
74
|
+
hour: 3600 * 1e3,
|
|
75
|
+
second: 1e3
|
|
76
|
+
}[unit] || 1;
|
|
77
|
+
const nextTimeStamp = $d.getTime() + value * step;
|
|
78
|
+
return createInstanceFromExist(new Date(nextTimeStamp), that);
|
|
79
|
+
}
|
|
80
|
+
default: return that.clone();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const utcPlugin = (_, dayClass, dayFactory) => {
|
|
84
|
+
dayFactory.utc = (d, ...others) => {
|
|
85
|
+
const inst = dayFactory(d, ...others, { utc: true });
|
|
86
|
+
return inst;
|
|
87
|
+
};
|
|
88
|
+
const proto = dayClass.prototype;
|
|
89
|
+
proto.utc = function(keepLocalTime) {
|
|
90
|
+
const inst = this.clone();
|
|
91
|
+
inst["$d"] = this.toDate();
|
|
92
|
+
inst["$conf"].utc = true;
|
|
93
|
+
if (keepLocalTime) return inst.add(this.utcOffset(), constants_default.MIN);
|
|
94
|
+
return inst;
|
|
95
|
+
};
|
|
96
|
+
proto.local = function() {
|
|
97
|
+
const inst = this.clone();
|
|
98
|
+
inst["$conf"].utc = false;
|
|
99
|
+
return inst;
|
|
100
|
+
};
|
|
101
|
+
proto.isUTC = function() {
|
|
102
|
+
return !!this["$conf"].utc;
|
|
103
|
+
};
|
|
104
|
+
proto.toISOString = function() {
|
|
105
|
+
if (this.isValid()) return this.toDate().toISOString();
|
|
106
|
+
return constants_default.INVALID_DATE_STRING;
|
|
107
|
+
};
|
|
108
|
+
proto.utcOffset = function(offset, keepLocalTime) {
|
|
109
|
+
if (offset === void 0) {
|
|
110
|
+
const defaultOffset = -Math.round(this["$d"].getTimezoneOffset());
|
|
111
|
+
return utcOffsetGetImpl(this, defaultOffset);
|
|
112
|
+
}
|
|
113
|
+
return utcOffsetSetImpl(this, offset, keepLocalTime);
|
|
114
|
+
};
|
|
115
|
+
const oldValueOf = proto.valueOf;
|
|
116
|
+
proto.valueOf = function() {
|
|
117
|
+
if (this["$conf"].offset !== void 0) {
|
|
118
|
+
const internalDate = this["$d"];
|
|
119
|
+
const offsetToUse = Number(this["$conf"].tzOffset ?? internalDate.getTimezoneOffset());
|
|
120
|
+
const addedOffset = Number(this["$conf"].offset) + offsetToUse;
|
|
121
|
+
return internalDate.valueOf() - addedOffset * constants_default.MILLISECONDS_A_MINUTE;
|
|
122
|
+
}
|
|
123
|
+
return oldValueOf.call(this);
|
|
124
|
+
};
|
|
125
|
+
const oldFormat = proto.format;
|
|
126
|
+
proto.format = function(formatStr) {
|
|
127
|
+
const UTC_FORMAT_DEFAULT = "YYYY-MM-DDTHH:mm:ss[Z]";
|
|
128
|
+
const str = formatStr || (this["$conf"].utc ? UTC_FORMAT_DEFAULT : "");
|
|
129
|
+
return oldFormat.call(this, str);
|
|
130
|
+
};
|
|
131
|
+
const oldDateFromDateComponents = proto["dateFromDateComponents"];
|
|
132
|
+
proto["dateFromDateComponents"] = function(Y, M, D, h, m, s, ms, offsetMs) {
|
|
133
|
+
if (!this["$conf"].utc) return oldDateFromDateComponents(Y, M, D, h, m, s, ms, offsetMs);
|
|
134
|
+
const parsedYearOrDefault = Y ?? (/* @__PURE__ */ new Date()).getFullYear();
|
|
135
|
+
const parsedMonthOrDefault = M ?? (Y !== void 0 ? 1 : (/* @__PURE__ */ new Date()).getMonth() + 1);
|
|
136
|
+
const dateComponents = {
|
|
137
|
+
Y: parsedYearOrDefault,
|
|
138
|
+
M: parsedMonthOrDefault - 1,
|
|
139
|
+
D: D ?? 1,
|
|
140
|
+
h: h ?? 0,
|
|
141
|
+
m: m ?? 0,
|
|
142
|
+
s: s ?? 0,
|
|
143
|
+
ms: ms ?? 0
|
|
144
|
+
};
|
|
145
|
+
const yearWithoutCentury = Math.abs(parsedYearOrDefault) < 100;
|
|
146
|
+
let result;
|
|
147
|
+
let overflowed = false;
|
|
148
|
+
result = new Date(Date.UTC(dateComponents.Y, dateComponents.M, dateComponents.D, dateComponents.h, dateComponents.m, dateComponents.s, dateComponents.ms));
|
|
149
|
+
if (yearWithoutCentury) result.setUTCFullYear(dateComponents.Y);
|
|
150
|
+
overflowed = M !== void 0 && M - 1 !== result.getUTCMonth() || D !== void 0 && D !== result.getUTCDate() || h !== void 0 && h !== result.getUTCHours() || m !== void 0 && m !== result.getUTCMinutes() || s !== void 0 && s !== result.getUTCSeconds();
|
|
151
|
+
if (overflowed) result = constants_default.INVALID_DATE;
|
|
152
|
+
else if (!isUndefined(offsetMs)) result.setUTCMilliseconds(result.getUTCMilliseconds() - offsetMs);
|
|
153
|
+
return result;
|
|
154
|
+
};
|
|
155
|
+
const oldGet = proto.get;
|
|
156
|
+
proto.get = function(unit) {
|
|
157
|
+
const normalizedUnit = normalizeUnitWithPlurals(unit);
|
|
158
|
+
if (normalizedUnit === constants_default.QUARTER || normalizedUnit === constants_default.WEEK) return NaN;
|
|
159
|
+
if (this["$conf"].utc) return getUnitInDateUTC(this["$d"], unit);
|
|
160
|
+
return oldGet.call(this, unit);
|
|
161
|
+
};
|
|
162
|
+
const old$set = proto["$set"];
|
|
163
|
+
proto["$set"] = function(unit, values) {
|
|
164
|
+
const utc = !!this["$conf"].utc;
|
|
165
|
+
if (utc) {
|
|
166
|
+
if (isObject(unit)) return this.clone();
|
|
167
|
+
const $date = this["$d"];
|
|
168
|
+
const normalizedUnit = normalizeUnitWithPlurals(unit);
|
|
169
|
+
if (normalizedUnit === constants_default.DAY) setUnitInDateUTC($date, constants_default.DAY_OF_MONTH, this.date() + (values[0] - this.day()));
|
|
170
|
+
else if (normalizedUnit !== constants_default.QUARTER && normalizedUnit !== constants_default.WEEK) {
|
|
171
|
+
const typedUnit = normalizedUnit;
|
|
172
|
+
setUnitInDateUTC($date, typedUnit, values);
|
|
173
|
+
}
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
return old$set.call(this, unit, values);
|
|
177
|
+
};
|
|
178
|
+
const oldAdd = proto.add;
|
|
179
|
+
proto.add = function(value, unit) {
|
|
180
|
+
if (isObject(value) || unit === void 0) return this.clone();
|
|
181
|
+
if (this["$conf"].utc) return addUtc(this, value, unit);
|
|
182
|
+
return oldAdd.call(this, value, unit);
|
|
183
|
+
};
|
|
184
|
+
const oldSubtract = proto.subtract;
|
|
185
|
+
proto.subtract = function(value, unit) {
|
|
186
|
+
if (isObject(value) || unit === void 0) return this.clone();
|
|
187
|
+
if (this["$conf"].utc) return addUtc(this, -value, unit);
|
|
188
|
+
return oldSubtract.call(this, value, unit);
|
|
189
|
+
};
|
|
38
190
|
};
|
|
191
|
+
var utc_default = utcPlugin;
|
|
39
192
|
|
|
40
|
-
|
|
193
|
+
//#endregion
|
|
194
|
+
export { utc_default as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EsDayPlugin } from "../../chunks/DqhiVwLi.js";
|
|
2
|
+
import "../../chunks/MtjcOKi-.js";
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/week/index.d.ts
|
|
5
|
+
|
|
6
|
+
declare module 'esday' {
|
|
7
|
+
interface EsDay {
|
|
8
|
+
week(): number;
|
|
9
|
+
week(newWeek: number): EsDay;
|
|
10
|
+
weeks(): number;
|
|
11
|
+
weeks(newWeek: number): EsDay;
|
|
12
|
+
weekday(): number;
|
|
13
|
+
weekday(newWeekday: number): EsDay;
|
|
14
|
+
weekYear(): number;
|
|
15
|
+
weekYear(newWeekYear: number): EsDay;
|
|
16
|
+
weeksInYear(): number;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
declare const weekPlugin: EsDayPlugin<{}>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { weekPlugin as default };
|