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