esday 0.3.0 → 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 +51 -0
- 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 +552 -326
- 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 +8 -0
- package/locales/en.js +3 -0
- 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 +15 -0
- package/locales/zh.js +3 -0
- package/package.json +79 -21
- 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 -0
- package/plugins/locale/index.js +7 -0
- 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 +19 -0
- package/plugins/utc/index.js +194 -0
- package/plugins/week/index.d.ts +21 -0
- package/plugins/week/index.js +360 -0
- package/EsDay-CKy0jEj2.d.ts +0 -68
- package/plugins/customParseFormat/index.d.ts +0 -5
- package/plugins/customParseFormat/index.js +0 -159
|
@@ -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 };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DateType, EsDayPlugin, SimpleType } from "../../chunks/DqhiVwLi.js";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/utc/index.d.ts
|
|
4
|
+
|
|
5
|
+
declare module 'esday' {
|
|
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
|
+
}
|
|
16
|
+
}
|
|
17
|
+
declare const utcPlugin: EsDayPlugin<{}>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { utcPlugin as default };
|
|
@@ -0,0 +1,194 @@
|
|
|
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";
|
|
6
|
+
|
|
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
|
+
};
|
|
190
|
+
};
|
|
191
|
+
var utc_default = utcPlugin;
|
|
192
|
+
|
|
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 };
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { constants_default } from "../../chunks/Y32qdU_5.js";
|
|
2
|
+
import { isArray, isObject, isUndefined } from "../../chunks/Cb5SvF6r.js";
|
|
3
|
+
import { normalizeUnitWithPlurals } from "../../chunks/DjY7KvwG.js";
|
|
4
|
+
import { createInstanceFromExist } from "../../chunks/DXHbH1CI.js";
|
|
5
|
+
import { padStart } from "../../chunks/BRRrAbUl.js";
|
|
6
|
+
|
|
7
|
+
//#region src/plugins/week/index.ts
|
|
8
|
+
const match1to2NoLeadingZero = /^[1-9]\d?/;
|
|
9
|
+
const match1 = /\d/;
|
|
10
|
+
const match2 = /\d\d/;
|
|
11
|
+
const match1to2 = /\d\d?/;
|
|
12
|
+
const match4 = /\d{4}/;
|
|
13
|
+
const match1to4 = /\d{1,4}/;
|
|
14
|
+
const matchWord = /\d*[^-_:/,()\s\d]+/;
|
|
15
|
+
/**
|
|
16
|
+
* Convert a number to an ordinal number, if a locale is available.
|
|
17
|
+
* Otherwise return value as string.
|
|
18
|
+
* @param sourceDate - date to take the locale from
|
|
19
|
+
* @param value - value to convert
|
|
20
|
+
* @returns value as ordinal
|
|
21
|
+
*/
|
|
22
|
+
function toOrdinal(sourceDate, value) {
|
|
23
|
+
const defaultValue = value.toString();
|
|
24
|
+
return sourceDate.localeObject?.().ordinal?.(value) ?? defaultValue;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create a function that will parse the input string as week, weekday or
|
|
28
|
+
* weekYear number and add it to the given 'parsedElements' containing the
|
|
29
|
+
* date&time components.
|
|
30
|
+
* @param property - name of the property to set
|
|
31
|
+
* @returns function that will add the given value to date&time component as new element
|
|
32
|
+
*/
|
|
33
|
+
function addWeek(property) {
|
|
34
|
+
return function weekPropUpdater(parsedElements, input, _parseOptions) {
|
|
35
|
+
parsedElements[property] = +input;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a function that will convert the value from the input string
|
|
40
|
+
* to a day of week number and add it to the given 'parsedElements'
|
|
41
|
+
* containing the date&time components.
|
|
42
|
+
* @param property - name of the list of weekday names to use
|
|
43
|
+
* @returns function that will add the weekday value to date&time component
|
|
44
|
+
*/
|
|
45
|
+
function addDayOfWeek(property, esday) {
|
|
46
|
+
return function weekdayUpdater(parsedElements, input, parseOptions) {
|
|
47
|
+
if (property === "day") parsedElements[property] = +input;
|
|
48
|
+
else {
|
|
49
|
+
const localeName = parseOptions["locale"];
|
|
50
|
+
const weekdays = esday.getLocale(localeName)[property];
|
|
51
|
+
let weekdayNames;
|
|
52
|
+
if (isArray(weekdays)) weekdayNames = weekdays;
|
|
53
|
+
else weekdayNames = weekdays.standalone;
|
|
54
|
+
parsedElements.day = weekdayNames.indexOf(input);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function parseTwoDigitYear(input) {
|
|
59
|
+
const inputLimited = input.slice(0, 2);
|
|
60
|
+
const year = +inputLimited;
|
|
61
|
+
return year + (year > 68 ? 1900 : 2e3);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Add parsed year as 2-digit value to parsedElements
|
|
65
|
+
* @param parsedElements - object containing the components of a parsed date
|
|
66
|
+
* @param input - parsed value (year)
|
|
67
|
+
* @param _options - parsing options e.g. containing the locale to use
|
|
68
|
+
*/
|
|
69
|
+
function twoDigitsYearUpdater(parsedElements, input, _parseOptions) {
|
|
70
|
+
parsedElements["weekYear"] = parseTwoDigitYear(input);
|
|
71
|
+
}
|
|
72
|
+
const weekPlugin = (_, dayClass, dayFactory) => {
|
|
73
|
+
const proto = dayClass.prototype;
|
|
74
|
+
/**
|
|
75
|
+
* Set the week of the parsed date.
|
|
76
|
+
* Must be called in the context of an EsDay instance.
|
|
77
|
+
* @param this - context for this function (required for getting the $conf settings)
|
|
78
|
+
* @param parsedDate - Date object returned by parsing function
|
|
79
|
+
* @param parsedElements - object containing the components of a parsed date
|
|
80
|
+
* @returns parsedDate with week set to parsed value
|
|
81
|
+
*/
|
|
82
|
+
function _postParseWeek(parsedDate, parsedElements) {
|
|
83
|
+
let modifiedDate = parsedDate;
|
|
84
|
+
if (!(Number.isNaN(parsedDate.valueOf()) || isUndefined(parsedElements.week)) && isUndefined(parsedElements.date)) {
|
|
85
|
+
const newEsday = createInstanceFromExist(parsedDate, this);
|
|
86
|
+
const parsedWeek = parsedElements.week;
|
|
87
|
+
const modifiedEsday = newEsday.week(parsedWeek).weekday(0);
|
|
88
|
+
modifiedDate = modifiedEsday.toDate();
|
|
89
|
+
}
|
|
90
|
+
return modifiedDate;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Set the dayOfWeek of the parsed date.
|
|
94
|
+
* Must be called in the context of an EsDay instance.
|
|
95
|
+
* @param this - context for this function (required for getting the $conf settings)
|
|
96
|
+
* @param parsedDate - Date object returned by parsing function
|
|
97
|
+
* @param parsedElements - object containing the components of a parsed date
|
|
98
|
+
* @returns parsedDate or invalid date (if day of week does not match)
|
|
99
|
+
*/
|
|
100
|
+
function _postParseWeekDay(parsedDate, parsedElements) {
|
|
101
|
+
const newWeekday = parsedElements.weekday;
|
|
102
|
+
if (!isUndefined(newWeekday) && newWeekday !== null && (newWeekday < 0 || newWeekday > 6)) return constants_default.INVALID_DATE;
|
|
103
|
+
let modifiedDate = parsedDate;
|
|
104
|
+
if (!(Number.isNaN(parsedDate.valueOf()) || isUndefined(newWeekday)) && isUndefined(parsedElements.date)) {
|
|
105
|
+
let newEsday = dayFactory(parsedDate, { utc: this["$conf"].utc });
|
|
106
|
+
newEsday["$conf"] = structuredClone(this["$conf"]);
|
|
107
|
+
if (isUndefined(parsedElements.weekYear) && isUndefined(parsedElements.week)) {
|
|
108
|
+
const now = /* @__PURE__ */ new Date();
|
|
109
|
+
newEsday = newEsday.month(now.getMonth()).date(now.getDate());
|
|
110
|
+
}
|
|
111
|
+
const modifiedEsday = newEsday.weekday(newWeekday);
|
|
112
|
+
modifiedDate = modifiedEsday.toDate();
|
|
113
|
+
}
|
|
114
|
+
return modifiedDate;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Verify that parsed date is the expected day-of-week or set the day-of-week.
|
|
118
|
+
* Must be called in the context of an EsDay instance.
|
|
119
|
+
* @param this - context for this function (required for getting the $conf settings)
|
|
120
|
+
* @param parsedDate - Date object returned by parsing function
|
|
121
|
+
* @param parsedElements - object containing the components of a parsed date
|
|
122
|
+
* @returns parsedDate or invalid date (if day of week does not match)
|
|
123
|
+
*/
|
|
124
|
+
function _postParseDayOfWeek(parsedDate, parsedElements) {
|
|
125
|
+
let modifiedDate = parsedDate;
|
|
126
|
+
if (!(Number.isNaN(parsedDate.valueOf()) || isUndefined(parsedElements.day))) {
|
|
127
|
+
const now = createInstanceFromExist(/* @__PURE__ */ new Date(), this);
|
|
128
|
+
let newEsday = createInstanceFromExist(parsedDate, this);
|
|
129
|
+
if (parsedElements.year !== void 0 && parsedElements.month === void 0 && parsedElements.date === void 0) {
|
|
130
|
+
const currentWeek = now.week();
|
|
131
|
+
const dayOfWeek = (parsedElements.day + 7 - newEsday.localeObject().weekStart) % 7;
|
|
132
|
+
newEsday = newEsday.week(currentWeek).weekday(dayOfWeek);
|
|
133
|
+
modifiedDate = newEsday.toDate();
|
|
134
|
+
}
|
|
135
|
+
if (newEsday.day() !== parsedElements.day) modifiedDate = constants_default.INVALID_DATE;
|
|
136
|
+
}
|
|
137
|
+
return modifiedDate;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Set weekYear of parsed date.
|
|
141
|
+
* Must be called in the context of an EsDay instance.
|
|
142
|
+
* @param this - context for this function (required for getting the $conf settings)
|
|
143
|
+
* @param parsedDate - Date object returned by parsing function
|
|
144
|
+
* @param parsedElements - object containing the components of a parsed date
|
|
145
|
+
* @returns parsedDate with weekYear set to parsed value
|
|
146
|
+
*/
|
|
147
|
+
function _postParseYear(parsedDate, parsedElements) {
|
|
148
|
+
let modifiedDate = parsedDate;
|
|
149
|
+
if (!(Number.isNaN(parsedDate.valueOf()) || isUndefined(parsedElements.weekYear))) {
|
|
150
|
+
const newEsday = createInstanceFromExist(parsedDate, this);
|
|
151
|
+
const parsedWeekYear = parsedElements.weekYear;
|
|
152
|
+
if (Object.keys(parsedElements).length === 1) {
|
|
153
|
+
const now = /* @__PURE__ */ new Date();
|
|
154
|
+
let modifiedEsday = newEsday.weekYear(parsedWeekYear);
|
|
155
|
+
modifiedEsday = modifiedEsday.year(parsedWeekYear).month(now.getMonth()).date(now.getDate()).weekday(0);
|
|
156
|
+
modifiedDate = modifiedEsday.toDate();
|
|
157
|
+
} else if (!isUndefined(parsedElements.week)) {
|
|
158
|
+
const modifiedEsday = newEsday.weekYear(parsedWeekYear);
|
|
159
|
+
modifiedDate = modifiedEsday.toDate();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return modifiedDate;
|
|
163
|
+
}
|
|
164
|
+
proto.week = function(newWeek) {
|
|
165
|
+
if (newWeek !== void 0) {
|
|
166
|
+
const currentWeekday = this.weekday();
|
|
167
|
+
const h = this.hour();
|
|
168
|
+
const m = this.minute();
|
|
169
|
+
const s = this.second();
|
|
170
|
+
const ms = this.millisecond();
|
|
171
|
+
return this.add((newWeek - this.week()) * 7, constants_default.DAY).weekday(currentWeekday).hour(h, m, s, ms);
|
|
172
|
+
}
|
|
173
|
+
const yearStart = this.localeObject?.().yearStart || constants_default.INDEX_THURSDAY;
|
|
174
|
+
if (this.month() === 11 && this.date() > 25) {
|
|
175
|
+
const nextYearStartDay = this.startOf(constants_default.YEAR).add(1, constants_default.YEAR).date(yearStart);
|
|
176
|
+
const thisEndOfWeek = this.endOf(constants_default.WEEK);
|
|
177
|
+
if (nextYearStartDay.isBefore(thisEndOfWeek)) return 1;
|
|
178
|
+
}
|
|
179
|
+
const yearStartDay = this.startOf(constants_default.YEAR).date(yearStart);
|
|
180
|
+
const yearStartWeek = yearStartDay.startOf(constants_default.WEEK).subtract(1, constants_default.MS);
|
|
181
|
+
const diffInWeek = this.diff(yearStartWeek, constants_default.WEEK, true);
|
|
182
|
+
if (diffInWeek < 0) return this.startOf(constants_default.WEEK).week();
|
|
183
|
+
return Math.ceil(diffInWeek);
|
|
184
|
+
};
|
|
185
|
+
proto.weeks = proto.week;
|
|
186
|
+
/**
|
|
187
|
+
* Get or set the locale aware day of the week.
|
|
188
|
+
* 0 is always the first day of the week (according to locale.weekStart property),
|
|
189
|
+
* 6 is always the last day of the week.
|
|
190
|
+
* E.g. in Europe 0=Monday ... 6=Sunday.
|
|
191
|
+
* If no locale is loaded, Monday is used as start of week.
|
|
192
|
+
*/
|
|
193
|
+
dayClass.prototype.weekday = function(newWeekday) {
|
|
194
|
+
const weekStart = this.localeObject?.().weekStart ?? constants_default.INDEX_MONDAY;
|
|
195
|
+
const dow = this.day();
|
|
196
|
+
const weekday = (dow < weekStart ? dow + 7 : dow) - weekStart;
|
|
197
|
+
if (newWeekday !== void 0) return this.subtract(weekday, constants_default.DAY).add(newWeekday, constants_default.DAY);
|
|
198
|
+
return weekday;
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* Gets or sets the year of the week. This year may differ from
|
|
202
|
+
* the calendar year at the start or the end of a year (depending on
|
|
203
|
+
* 'yearStart').
|
|
204
|
+
* Setting the weekYear will keep the week number and the day of the week.
|
|
205
|
+
* If no locale is loaded, Monday is used as start of week.
|
|
206
|
+
*/
|
|
207
|
+
proto.weekYear = function(newWeekYear) {
|
|
208
|
+
if (newWeekYear !== void 0) {
|
|
209
|
+
if (this.weekYear() === newWeekYear) return this;
|
|
210
|
+
const currentWeek = this.week();
|
|
211
|
+
const currentWeekday = this.weekday();
|
|
212
|
+
let newDate = this.year(newWeekYear).week(currentWeek).weekday(currentWeekday);
|
|
213
|
+
if (newDate.weekYear() !== newWeekYear) {
|
|
214
|
+
const yearDiff = newWeekYear - newDate.weekYear();
|
|
215
|
+
newDate = newDate.add(yearDiff, constants_default.YEAR).weekday(currentWeekday);
|
|
216
|
+
}
|
|
217
|
+
return newDate;
|
|
218
|
+
}
|
|
219
|
+
const month = this.month();
|
|
220
|
+
const weekOfYear = this.week();
|
|
221
|
+
const year = this.year();
|
|
222
|
+
if (weekOfYear === 1 && month === 11) return year + 1;
|
|
223
|
+
if (month === 0 && weekOfYear >= 52) return year - 1;
|
|
224
|
+
return year;
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Get the number of weeks in the current year.
|
|
228
|
+
* Most years have 52 weeks, some have 53 weeks.
|
|
229
|
+
*/
|
|
230
|
+
proto.weeksInYear = function() {
|
|
231
|
+
const weekStart = this.localeObject?.().weekStart ?? constants_default.INDEX_MONDAY;
|
|
232
|
+
const yearStart = this.localeObject?.().yearStart ?? constants_default.INDEX_THURSDAY;
|
|
233
|
+
const preWeekStart = ((weekStart + 6) % 7 + 8 - yearStart) % 7;
|
|
234
|
+
const prePreWeekStart = (preWeekStart + 6) % 7;
|
|
235
|
+
const yearStartWeekday = this.month(0).date(1).day();
|
|
236
|
+
const year = this.year();
|
|
237
|
+
const isLeapYear = year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
238
|
+
if (yearStartWeekday === preWeekStart || isLeapYear && yearStartWeekday === prePreWeekStart) return 53;
|
|
239
|
+
return 52;
|
|
240
|
+
};
|
|
241
|
+
const oldStartOf = proto.startOf;
|
|
242
|
+
proto.startOf = function(units) {
|
|
243
|
+
if (units === constants_default.WEEK) {
|
|
244
|
+
let newDate = this.clone();
|
|
245
|
+
const weekStart = newDate.localeObject?.().weekStart ?? constants_default.INDEX_MONDAY;
|
|
246
|
+
const newDateWeekday = newDate.day();
|
|
247
|
+
const diff = (newDateWeekday < weekStart ? newDateWeekday + 7 : newDateWeekday) - weekStart;
|
|
248
|
+
const newDayOfMonth = newDate.date() - diff;
|
|
249
|
+
newDate = newDate.date(newDayOfMonth);
|
|
250
|
+
return newDate["$set"](constants_default.HOUR, [
|
|
251
|
+
0,
|
|
252
|
+
0,
|
|
253
|
+
0,
|
|
254
|
+
0
|
|
255
|
+
]);
|
|
256
|
+
}
|
|
257
|
+
return oldStartOf.call(this, units);
|
|
258
|
+
};
|
|
259
|
+
const oldEndOf = proto.endOf;
|
|
260
|
+
proto.endOf = function(units) {
|
|
261
|
+
if (units === constants_default.WEEK) {
|
|
262
|
+
let newDate = this.clone();
|
|
263
|
+
const weekStart = newDate.localeObject?.().weekStart ?? constants_default.INDEX_MONDAY;
|
|
264
|
+
const newDateWeekday = newDate.day();
|
|
265
|
+
const diff = (newDateWeekday < weekStart ? newDateWeekday + 7 : newDateWeekday) - weekStart;
|
|
266
|
+
const newDayOfMonth = newDate.date() + (6 - diff);
|
|
267
|
+
newDate = newDate.date(newDayOfMonth);
|
|
268
|
+
return newDate["$set"](constants_default.HOUR, [
|
|
269
|
+
23,
|
|
270
|
+
59,
|
|
271
|
+
59,
|
|
272
|
+
999
|
|
273
|
+
]);
|
|
274
|
+
}
|
|
275
|
+
return oldEndOf.call(this, units);
|
|
276
|
+
};
|
|
277
|
+
const oldGet = proto.get;
|
|
278
|
+
proto.get = function(unit) {
|
|
279
|
+
const normalizedUnit = normalizeUnitWithPlurals(unit);
|
|
280
|
+
if (normalizedUnit === constants_default.WEEK) return this.week();
|
|
281
|
+
return oldGet.call(this, unit);
|
|
282
|
+
};
|
|
283
|
+
const old$set = proto["$set"];
|
|
284
|
+
proto["$set"] = function(unit, values) {
|
|
285
|
+
if (isObject(unit)) return this.clone();
|
|
286
|
+
const normalizedUnit = normalizeUnitWithPlurals(unit);
|
|
287
|
+
if (normalizedUnit === constants_default.WEEK) return this.week(values[0]);
|
|
288
|
+
return old$set.call(this, unit, values);
|
|
289
|
+
};
|
|
290
|
+
const additionalTokens = {
|
|
291
|
+
w: (sourceDate) => sourceDate.week().toString(),
|
|
292
|
+
ww: (sourceDate) => padStart(sourceDate.week(), 2, "0"),
|
|
293
|
+
wo: (sourceDate) => toOrdinal(sourceDate, sourceDate.week()),
|
|
294
|
+
e: (sourceDate) => sourceDate.weekday().toString(),
|
|
295
|
+
gg: (sourceDate) => padStart(sourceDate.weekYear(), 2, "0").slice(-2),
|
|
296
|
+
gggg: (sourceDate) => padStart(sourceDate.weekYear(), 4, "0")
|
|
297
|
+
};
|
|
298
|
+
dayFactory.addFormatTokenDefinitions(additionalTokens);
|
|
299
|
+
const parseTokensDefinitions = {
|
|
300
|
+
d: [
|
|
301
|
+
match1to2,
|
|
302
|
+
match1to2,
|
|
303
|
+
addDayOfWeek("day", dayFactory),
|
|
304
|
+
_postParseDayOfWeek
|
|
305
|
+
],
|
|
306
|
+
dd: [
|
|
307
|
+
matchWord,
|
|
308
|
+
matchWord,
|
|
309
|
+
addDayOfWeek("weekdaysMin", dayFactory),
|
|
310
|
+
_postParseDayOfWeek
|
|
311
|
+
],
|
|
312
|
+
ddd: [
|
|
313
|
+
matchWord,
|
|
314
|
+
matchWord,
|
|
315
|
+
addDayOfWeek("weekdaysShort", dayFactory),
|
|
316
|
+
_postParseDayOfWeek
|
|
317
|
+
],
|
|
318
|
+
dddd: [
|
|
319
|
+
matchWord,
|
|
320
|
+
matchWord,
|
|
321
|
+
addDayOfWeek("weekdays", dayFactory),
|
|
322
|
+
_postParseDayOfWeek
|
|
323
|
+
],
|
|
324
|
+
w: [
|
|
325
|
+
match1to2,
|
|
326
|
+
match1to2NoLeadingZero,
|
|
327
|
+
addWeek("week"),
|
|
328
|
+
_postParseWeek
|
|
329
|
+
],
|
|
330
|
+
ww: [
|
|
331
|
+
match1to2,
|
|
332
|
+
match2,
|
|
333
|
+
addWeek("week"),
|
|
334
|
+
_postParseWeek
|
|
335
|
+
],
|
|
336
|
+
e: [
|
|
337
|
+
match1to2,
|
|
338
|
+
match1,
|
|
339
|
+
addWeek("weekday"),
|
|
340
|
+
_postParseWeekDay
|
|
341
|
+
],
|
|
342
|
+
gg: [
|
|
343
|
+
match1to4,
|
|
344
|
+
match2,
|
|
345
|
+
twoDigitsYearUpdater,
|
|
346
|
+
_postParseYear
|
|
347
|
+
],
|
|
348
|
+
gggg: [
|
|
349
|
+
match1to4,
|
|
350
|
+
match4,
|
|
351
|
+
addWeek("weekYear"),
|
|
352
|
+
_postParseYear
|
|
353
|
+
]
|
|
354
|
+
};
|
|
355
|
+
dayFactory.addParseTokenDefinitions?.(parseTokensDefinitions);
|
|
356
|
+
};
|
|
357
|
+
var week_default = weekPlugin;
|
|
358
|
+
|
|
359
|
+
//#endregion
|
|
360
|
+
export { week_default as default };
|