esday 0.4.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/LICENSE +21 -0
- package/README.md +63 -33
- package/chunks/AyQQ6US-.js +84 -0
- package/chunks/BkjWOpMU.js +68 -0
- package/chunks/C5qDMHT5.d.ts +6 -0
- package/chunks/CODi8AFH.d.ts +231 -0
- package/chunks/CXWzCl3n.js +481 -0
- package/chunks/CdvTtmWL.js +56 -0
- package/chunks/Shk32pTP.js +9 -0
- package/chunks/v_QBn7Xm.js +25 -0
- package/chunks/xt8C2lbv.js +38 -0
- package/index.d.mts +3 -0
- package/index.mjs +3 -0
- package/locales/af.d.mts +6 -0
- package/locales/af.mjs +108 -0
- package/locales/am.d.mts +6 -0
- package/locales/am.mjs +108 -0
- package/locales/ar-dz.d.mts +9 -0
- package/locales/ar-dz.mjs +30 -0
- package/locales/ar-iq.d.mts +9 -0
- package/locales/ar-iq.mjs +12 -0
- package/locales/ar-kw.d.mts +9 -0
- package/locales/ar-kw.mjs +26 -0
- package/locales/ar-ly.d.mts +9 -0
- package/locales/ar-ly.mjs +12 -0
- package/locales/ar-ma.d.mts +9 -0
- package/locales/ar-ma.mjs +27 -0
- package/locales/ar-sa.d.mts +9 -0
- package/locales/ar-sa.mjs +27 -0
- package/locales/ar-tn.d.mts +9 -0
- package/locales/ar-tn.mjs +27 -0
- package/locales/ar.d.mts +6 -0
- package/locales/ar.mjs +198 -0
- package/locales/az.d.mts +6 -0
- package/locales/az.mjs +108 -0
- package/locales/be.d.mts +6 -0
- package/locales/be.mjs +136 -0
- package/locales/bg.d.mts +6 -0
- package/locales/bg.mjs +127 -0
- package/locales/bi.d.mts +6 -0
- package/locales/bi.mjs +108 -0
- package/locales/bm.d.mts +6 -0
- package/locales/bm.mjs +108 -0
- package/locales/bn-bd.d.mts +9 -0
- package/locales/bn-bd.mjs +22 -0
- package/locales/bn.d.mts +6 -0
- package/locales/bn.mjs +137 -0
- package/locales/bo.d.mts +6 -0
- package/locales/bo.mjs +108 -0
- package/locales/br.d.mts +6 -0
- package/locales/br.mjs +180 -0
- package/locales/bs.d.mts +6 -0
- package/locales/bs.mjs +130 -0
- package/locales/ca.d.mts +6 -0
- package/locales/ca.mjs +142 -0
- package/locales/cs.d.mts +6 -0
- package/locales/cs.mjs +186 -0
- package/locales/cv.d.mts +6 -0
- package/locales/cv.mjs +108 -0
- package/locales/cy.d.mts +6 -0
- package/locales/cy.mjs +108 -0
- package/locales/da.d.mts +6 -0
- package/locales/da.mjs +108 -0
- package/locales/de-at.d.mts +9 -0
- package/locales/de-at.mjs +42 -0
- package/locales/de-ch.d.mts +9 -0
- package/locales/de-ch.mjs +12 -0
- package/locales/de.d.mts +6 -0
- package/locales/de.mjs +131 -0
- package/locales/dv.d.mts +6 -0
- package/locales/dv.mjs +108 -0
- package/locales/el.d.mts +6 -0
- package/locales/el.mjs +117 -0
- package/locales/en-au.d.mts +9 -0
- package/locales/en-au.mjs +26 -0
- package/locales/en-ca.d.mts +9 -0
- package/locales/en-ca.mjs +26 -0
- package/locales/en-gb.d.mts +11 -0
- package/locales/en-gb.mjs +29 -0
- package/locales/en-ie.d.mts +9 -0
- package/locales/en-ie.mjs +25 -0
- package/locales/en-il.d.mts +9 -0
- package/locales/en-il.mjs +27 -0
- package/locales/en-in.d.mts +9 -0
- package/locales/en-in.mjs +25 -0
- package/locales/en-nz.d.mts +9 -0
- package/locales/en-nz.mjs +27 -0
- package/locales/en-sg.d.mts +9 -0
- package/locales/en-sg.mjs +27 -0
- package/locales/en-tt.d.mts +9 -0
- package/locales/en-tt.mjs +27 -0
- package/locales/en-us.d.mts +9 -0
- package/locales/en-us.mjs +12 -0
- package/locales/en.d.mts +6 -0
- package/locales/en.mjs +117 -0
- package/locales/eo.d.mts +6 -0
- package/locales/eo.mjs +108 -0
- package/locales/es-do.d.mts +9 -0
- package/locales/es-do.mjs +25 -0
- package/locales/es-mx.d.mts +9 -0
- package/locales/es-mx.mjs +13 -0
- package/locales/es-pr.d.mts +9 -0
- package/locales/es-pr.mjs +16 -0
- package/locales/es-us.d.mts +9 -0
- package/locales/es-us.mjs +12 -0
- package/locales/es.d.mts +6 -0
- package/locales/es.mjs +118 -0
- package/locales/et.d.mts +6 -0
- package/locales/et.mjs +146 -0
- package/locales/eu.d.mts +6 -0
- package/locales/eu.mjs +108 -0
- package/locales/fa.d.mts +6 -0
- package/locales/fa.mjs +108 -0
- package/locales/fi.d.mts +6 -0
- package/locales/fi.mjs +171 -0
- package/locales/fil.d.mts +6 -0
- package/locales/fil.mjs +108 -0
- package/locales/fo.d.mts +6 -0
- package/locales/fo.mjs +108 -0
- package/locales/fr-ca.d.mts +9 -0
- package/locales/fr-ca.mjs +16 -0
- package/locales/fr-ch.d.mts +9 -0
- package/locales/fr-ch.mjs +16 -0
- package/locales/fr.d.mts +6 -0
- package/locales/fr.mjs +110 -0
- package/locales/fy.d.mts +6 -0
- package/locales/fy.mjs +108 -0
- package/locales/ga.d.mts +6 -0
- package/locales/ga.mjs +108 -0
- package/locales/gd.d.mts +6 -0
- package/locales/gd.mjs +108 -0
- package/locales/gl.d.mts +6 -0
- package/locales/gl.mjs +118 -0
- package/locales/gom-deva.d.mts +6 -0
- package/locales/gom-deva.mjs +148 -0
- package/locales/gom-latn.d.mts +6 -0
- package/locales/gom-latn.mjs +148 -0
- package/locales/gu.d.mts +6 -0
- package/locales/gu.mjs +108 -0
- package/locales/he.d.mts +6 -0
- package/locales/he.mjs +132 -0
- package/locales/hi.d.mts +6 -0
- package/locales/hi.mjs +124 -0
- package/locales/hr.d.mts +6 -0
- package/locales/hr.mjs +195 -0
- package/locales/ht.d.mts +6 -0
- package/locales/ht.mjs +108 -0
- package/locales/hu.d.mts +6 -0
- package/locales/hu.mjs +144 -0
- package/locales/hy-am.d.mts +6 -0
- package/locales/hy-am.mjs +126 -0
- package/locales/id.d.mts +6 -0
- package/locales/id.mjs +108 -0
- package/locales/is.d.mts +6 -0
- package/locales/is.mjs +167 -0
- package/locales/it-ch.d.mts +9 -0
- package/locales/it-ch.mjs +27 -0
- package/locales/it.d.mts +6 -0
- package/locales/it.mjs +121 -0
- package/locales/ja.d.mts +12 -0
- package/locales/ja.mjs +111 -0
- package/locales/jv.d.mts +6 -0
- package/locales/jv.mjs +108 -0
- package/locales/ka.d.mts +6 -0
- package/locales/ka.mjs +125 -0
- package/locales/kk.d.mts +6 -0
- package/locales/kk.mjs +108 -0
- package/locales/km.d.mts +6 -0
- package/locales/km.mjs +108 -0
- package/locales/kn.d.mts +6 -0
- package/locales/kn.mjs +108 -0
- package/locales/ko.d.mts +6 -0
- package/locales/ko.mjs +107 -0
- package/locales/ku.d.mts +6 -0
- package/locales/ku.mjs +121 -0
- package/locales/ky.d.mts +6 -0
- package/locales/ky.mjs +108 -0
- package/locales/lb.d.mts +6 -0
- package/locales/lb.mjs +169 -0
- package/locales/lo.d.mts +6 -0
- package/locales/lo.mjs +107 -0
- package/locales/lt.d.mts +6 -0
- package/locales/lt.mjs +108 -0
- package/locales/lv.d.mts +6 -0
- package/locales/lv.mjs +108 -0
- package/locales/me.d.mts +6 -0
- package/locales/me.mjs +129 -0
- package/locales/mi.d.mts +6 -0
- package/locales/mi.mjs +108 -0
- package/locales/mk.d.mts +6 -0
- package/locales/mk.mjs +119 -0
- package/locales/ml.d.mts +6 -0
- package/locales/ml.mjs +111 -0
- package/locales/mn.d.mts +6 -0
- package/locales/mn.mjs +127 -0
- package/locales/mr.d.mts +6 -0
- package/locales/mr.mjs +229 -0
- package/locales/ms-my.d.mts +9 -0
- package/locales/ms-my.mjs +12 -0
- package/locales/ms.d.mts +6 -0
- package/locales/ms.mjs +108 -0
- package/locales/mt.d.mts +6 -0
- package/locales/mt.mjs +108 -0
- package/locales/my.d.mts +6 -0
- package/locales/my.mjs +134 -0
- package/locales/nb.d.mts +6 -0
- package/locales/nb.mjs +108 -0
- package/locales/ne.d.mts +6 -0
- package/locales/ne.mjs +108 -0
- package/locales/nl-be.d.mts +9 -0
- package/locales/nl-be.mjs +16 -0
- package/locales/nl.d.mts +6 -0
- package/locales/nl.mjs +108 -0
- package/locales/nn.d.mts +6 -0
- package/locales/nn.mjs +108 -0
- package/locales/oc-lnc.d.mts +6 -0
- package/locales/oc-lnc.mjs +125 -0
- package/locales/pa-in.d.mts +6 -0
- package/locales/pa-in.mjs +125 -0
- package/locales/pl.d.mts +6 -0
- package/locales/pl.mjs +162 -0
- package/locales/pt-br.d.mts +9 -0
- package/locales/pt-br.mjs +51 -0
- package/locales/pt.d.mts +6 -0
- package/locales/pt.mjs +110 -0
- package/locales/rn.d.mts +6 -0
- package/locales/rn.mjs +108 -0
- package/locales/ro.d.mts +6 -0
- package/locales/ro.mjs +108 -0
- package/locales/ru.d.mts +12 -0
- package/locales/ru.mjs +237 -0
- package/locales/rw.d.mts +6 -0
- package/locales/rw.mjs +108 -0
- package/locales/sd.d.mts +6 -0
- package/locales/sd.mjs +108 -0
- package/locales/se.d.mts +6 -0
- package/locales/se.mjs +108 -0
- package/locales/si.d.mts +6 -0
- package/locales/si.mjs +108 -0
- package/locales/sk.d.mts +6 -0
- package/locales/sk.mjs +168 -0
- package/locales/sl.d.mts +6 -0
- package/locales/sl.mjs +177 -0
- package/locales/sq.d.mts +6 -0
- package/locales/sq.mjs +108 -0
- package/locales/sr-cyrl.d.mts +9 -0
- package/locales/sr-cyrl.mjs +174 -0
- package/locales/sr.d.mts +6 -0
- package/locales/sr.mjs +186 -0
- package/locales/ss.d.mts +6 -0
- package/locales/ss.mjs +110 -0
- package/locales/sv-fi.d.mts +9 -0
- package/locales/sv-fi.mjs +25 -0
- package/locales/sv.d.mts +6 -0
- package/locales/sv.mjs +111 -0
- package/locales/sw.d.mts +6 -0
- package/locales/sw.mjs +108 -0
- package/locales/ta.d.mts +6 -0
- package/locales/ta.mjs +139 -0
- package/locales/te.d.mts +6 -0
- package/locales/te.mjs +111 -0
- package/locales/tet.d.mts +6 -0
- package/locales/tet.mjs +111 -0
- package/locales/tg.d.mts +6 -0
- package/locales/tg.mjs +127 -0
- package/locales/th.d.mts +6 -0
- package/locales/th.mjs +108 -0
- package/locales/tk.d.mts +6 -0
- package/locales/tk.mjs +135 -0
- package/locales/tl-ph.d.mts +6 -0
- package/locales/tl-ph.mjs +108 -0
- package/locales/tlh.d.mts +6 -0
- package/locales/tlh.mjs +155 -0
- package/locales/tr.d.mts +6 -0
- package/locales/tr.mjs +135 -0
- package/locales/tzl.d.mts +6 -0
- package/locales/tzl.mjs +125 -0
- package/locales/tzm-latn.d.mts +9 -0
- package/locales/tzm-latn.mjs +68 -0
- package/locales/tzm.d.mts +6 -0
- package/locales/tzm.mjs +108 -0
- package/locales/ug-cn.d.mts +6 -0
- package/locales/ug-cn.mjs +113 -0
- package/locales/uk.d.mts +6 -0
- package/locales/uk.mjs +199 -0
- package/locales/ur.d.mts +6 -0
- package/locales/ur.mjs +110 -0
- package/locales/uz-latn.d.mts +9 -0
- package/locales/uz-latn.mjs +68 -0
- package/locales/uz.d.mts +6 -0
- package/locales/uz.mjs +108 -0
- package/locales/vi.d.mts +6 -0
- package/locales/vi.mjs +108 -0
- package/locales/x-pseudo.d.mts +6 -0
- package/locales/x-pseudo.mjs +111 -0
- package/locales/yo.d.mts +6 -0
- package/locales/yo.mjs +108 -0
- package/locales/zh-cn.d.mts +9 -0
- package/locales/zh-cn.mjs +12 -0
- package/locales/zh-hk.d.mts +9 -0
- package/locales/zh-hk.mjs +21 -0
- package/locales/zh-mo.d.mts +9 -0
- package/locales/zh-mo.mjs +21 -0
- package/locales/zh-tw.d.mts +9 -0
- package/locales/zh-tw.mjs +21 -0
- package/locales/zh.d.mts +12 -0
- package/locales/zh.mjs +129 -0
- package/package.json +61 -29
- package/plugins/advancedFormat/index.d.mts +6 -0
- package/plugins/advancedFormat/index.mjs +18 -0
- package/plugins/advancedParse/index.d.mts +6 -0
- package/plugins/advancedParse/index.mjs +407 -0
- package/plugins/calendar/index.d.mts +12 -0
- package/plugins/calendar/index.mjs +32 -0
- package/plugins/dayOfYear/index.d.mts +12 -0
- package/plugins/dayOfYear/index.mjs +11 -0
- package/plugins/duration/index.d.mts +78 -0
- package/plugins/duration/index.mjs +477 -0
- package/plugins/isBetween/index.d.mts +22 -0
- package/plugins/isBetween/index.mjs +15 -0
- package/plugins/isLeapYear/index.d.mts +11 -0
- package/plugins/isLeapYear/index.mjs +10 -0
- package/plugins/isSameOrAfter/index.d.mts +11 -0
- package/plugins/isSameOrAfter/index.mjs +9 -0
- package/plugins/isSameOrBefore/index.d.mts +11 -0
- package/plugins/isSameOrBefore/index.mjs +9 -0
- package/plugins/isToday/index.d.mts +11 -0
- package/plugins/isToday/index.mjs +11 -0
- package/plugins/isTomorrow/index.d.mts +11 -0
- package/plugins/isTomorrow/index.mjs +13 -0
- package/plugins/isYesterday/index.d.mts +11 -0
- package/plugins/isYesterday/index.mjs +13 -0
- package/plugins/isoWeek/index.d.mts +19 -0
- package/plugins/isoWeek/index.mjs +228 -0
- package/plugins/locale/index.d.mts +104 -0
- package/plugins/locale/index.mjs +141 -0
- package/plugins/localeData/index.d.mts +6 -0
- package/plugins/localeData/index.mjs +155 -0
- package/plugins/localizedFormat/index.d.mts +6 -0
- package/plugins/localizedFormat/index.mjs +83 -0
- package/plugins/localizedParse/index.d.mts +6 -0
- package/plugins/localizedParse/index.mjs +217 -0
- package/plugins/minMax/index.d.mts +12 -0
- package/plugins/minMax/index.mjs +21 -0
- package/plugins/objectSupport/index.d.mts +6 -0
- package/plugins/objectSupport/index.mjs +99 -0
- package/plugins/pluralGetSet/index.d.mts +18 -0
- package/plugins/pluralGetSet/index.mjs +15 -0
- package/plugins/quarterOfYear/index.d.mts +14 -0
- package/plugins/quarterOfYear/index.mjs +51 -0
- package/plugins/relativeTime/index.d.mts +47 -0
- package/plugins/relativeTime/index.mjs +187 -0
- package/plugins/timezone/index.d.mts +6 -0
- package/plugins/timezone/index.mjs +456 -0
- package/plugins/toArray/index.d.mts +11 -0
- package/plugins/toArray/index.mjs +17 -0
- package/plugins/toObject/index.d.mts +19 -0
- package/plugins/toObject/index.mjs +17 -0
- package/plugins/utc/index.d.mts +18 -0
- package/plugins/utc/index.mjs +192 -0
- package/plugins/week/index.d.mts +19 -0
- package/plugins/week/index.mjs +350 -0
- package/EsDay-KXQgnL1r.d.ts +0 -89
- package/chunk-MLKGABMK.js +0 -7
- package/chunk-NUV73YDM.js +0 -60
- package/chunk-SQBPUYUY.js +0 -140
- package/index.d.ts +0 -6
- package/index.js +0 -310
- package/locales/en.d.ts +0 -6
- package/locales/en.js +0 -1
- package/locales/zh.d.ts +0 -6
- package/locales/zh.js +0 -64
- package/plugins/customParseFormat/index.d.ts +0 -5
- package/plugins/customParseFormat/index.js +0 -159
- package/plugins/isToday/index.d.ts +0 -10
- package/plugins/isToday/index.js +0 -8
- package/plugins/locale/index.d.ts +0 -75
- package/plugins/locale/index.js +0 -70
- package/plugins/utc/index.d.ts +0 -22
- package/plugins/utc/index.js +0 -40
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { o as EsDayPlugin } from "../../chunks/CODi8AFH.js";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/isoWeek/index.d.ts
|
|
4
|
+
declare module 'esday' {
|
|
5
|
+
interface EsDay {
|
|
6
|
+
isoWeek(): number;
|
|
7
|
+
isoWeek(newIsoWeek: number): EsDay;
|
|
8
|
+
isoWeeks(): number;
|
|
9
|
+
isoWeeks(newIsoWeek: number): EsDay;
|
|
10
|
+
isoWeekday(): number;
|
|
11
|
+
isoWeekday(newIsoWeekday: number): EsDay;
|
|
12
|
+
isoWeekYear(): number;
|
|
13
|
+
isoWeekYear(newIsoWeekYear: number): EsDay;
|
|
14
|
+
isoWeeksInYear(): number;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
declare const isoWeekPlugin: EsDayPlugin<{}>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { isoWeekPlugin as default };
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { p as constants_default } from "../../chunks/BkjWOpMU.js";
|
|
2
|
+
import { a as isUndefined } from "../../chunks/v_QBn7Xm.js";
|
|
3
|
+
import { t as createInstanceFromExist } from "../../chunks/Shk32pTP.js";
|
|
4
|
+
import { n as padStart } from "../../chunks/CdvTtmWL.js";
|
|
5
|
+
|
|
6
|
+
//#region src/plugins/isoWeek/index.ts
|
|
7
|
+
const weekStart = constants_default.INDEX_MONDAY;
|
|
8
|
+
const yearStart = 4;
|
|
9
|
+
const match1to2NoLeadingZero = /^[1-9]\d?/;
|
|
10
|
+
const match1 = /\d/;
|
|
11
|
+
const match2 = /\d\d/;
|
|
12
|
+
const match1to2 = /\d\d?/;
|
|
13
|
+
const match4 = /\d{4}/;
|
|
14
|
+
const match1to4 = /\d{1,4}/;
|
|
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 isoWeek, isoWeekday or
|
|
28
|
+
* isoWeekYear 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 addIsoWeekProperty(property) {
|
|
34
|
+
return function isoWeekPropUpdater(parsedElements, input, _parseOptions) {
|
|
35
|
+
parsedElements[property] = +input;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Convert 2-digit year to 4-digit year.
|
|
40
|
+
* Years > 68 are converted to 19xx;
|
|
41
|
+
* else they are converted to 20xx.
|
|
42
|
+
* @param input value to convert to a year
|
|
43
|
+
* @returns converted 4-digit year
|
|
44
|
+
*/
|
|
45
|
+
function parseTwoDigitYear(input) {
|
|
46
|
+
const year = +input.slice(0, 2);
|
|
47
|
+
return year + (year > 68 ? 1900 : 2e3);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Add parsed year as 2-digit value to parsedElements
|
|
51
|
+
* @param parsedElements - object containing the components of a parsed date
|
|
52
|
+
* @param input - parsed value (year)
|
|
53
|
+
* @param _options - parsing options e.g. containing the locale to use
|
|
54
|
+
*/
|
|
55
|
+
function twoDigitsIsoYearUpdater(parsedElements, input, _parseOptions) {
|
|
56
|
+
parsedElements["isoWeekYear"] = parseTwoDigitYear(input);
|
|
57
|
+
}
|
|
58
|
+
const isoWeekPlugin = (_, dayClass, dayFactory) => {
|
|
59
|
+
const proto = dayClass.prototype;
|
|
60
|
+
/**
|
|
61
|
+
* Set the isoWeek of the parsed date.
|
|
62
|
+
* Must be called in the context of an EsDay instance.
|
|
63
|
+
* @param this - context for this function (required for getting the $conf settings)
|
|
64
|
+
* @param parsedDate - Date object returned by parsing function
|
|
65
|
+
* @param parsedElements - object containing the components of a parsed date
|
|
66
|
+
* @returns parsedDate with iso week set to parsed value
|
|
67
|
+
*/
|
|
68
|
+
function _postParseIsoWeek(parsedDate, parsedElements) {
|
|
69
|
+
let modifiedDate = parsedDate;
|
|
70
|
+
if (!(Number.isNaN(parsedDate.valueOf()) || isUndefined(parsedElements.isoWeek)) && isUndefined(parsedElements.date)) {
|
|
71
|
+
const newEsday = createInstanceFromExist(parsedDate, this);
|
|
72
|
+
const parsedIsoWeek = parsedElements.isoWeek;
|
|
73
|
+
modifiedDate = newEsday.isoWeek(parsedIsoWeek).isoWeekday(weekStart).toDate();
|
|
74
|
+
}
|
|
75
|
+
return modifiedDate;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Set the isoWeekDay of the parsed date.
|
|
79
|
+
* Must be called in the context of an EsDay instance.
|
|
80
|
+
* @param this - context for this function (required for getting the $conf settings)
|
|
81
|
+
* @param parsedDate - Date object returned by parsing function
|
|
82
|
+
* @param parsedElements - object containing the components of a parsed date
|
|
83
|
+
* @returns parsedDate or invalid date (if iso day of week does not match)
|
|
84
|
+
*/
|
|
85
|
+
function _postParseIsoDayOfWeek(parsedDate, parsedElements) {
|
|
86
|
+
let modifiedDate = parsedDate;
|
|
87
|
+
if (!(Number.isNaN(parsedDate.valueOf()) || isUndefined(parsedElements.isoWeekday)) && isUndefined(parsedElements.month)) {
|
|
88
|
+
const newEsday = createInstanceFromExist(parsedDate, this);
|
|
89
|
+
const newIsoWeekday = parsedElements.isoWeekday;
|
|
90
|
+
modifiedDate = newEsday.isoWeekday(newIsoWeekday).toDate();
|
|
91
|
+
}
|
|
92
|
+
return modifiedDate;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Set isoWeekYear of parsed date.
|
|
96
|
+
* Must be called in the context of an EsDay instance.
|
|
97
|
+
* @param this - context for this function (required for getting the $conf settings)
|
|
98
|
+
* @param parsedDate - Date object returned by parsing function
|
|
99
|
+
* @param parsedElements - object containing the components of a parsed date
|
|
100
|
+
* @returns parsedDate with isoWeekYear set to parsed value
|
|
101
|
+
*/
|
|
102
|
+
function _postParseIsoYear(parsedDate, parsedElements) {
|
|
103
|
+
let modifiedDate = parsedDate;
|
|
104
|
+
if (!(Number.isNaN(parsedDate.valueOf()) || isUndefined(parsedElements.isoWeekYear))) {
|
|
105
|
+
const newEsday = createInstanceFromExist(parsedDate, this);
|
|
106
|
+
const parsedIsoWeekYear = parsedElements.isoWeekYear;
|
|
107
|
+
if (Object.keys(parsedElements).length === 1) {
|
|
108
|
+
let modifiedEsday = newEsday.isoWeekYear(parsedIsoWeekYear);
|
|
109
|
+
modifiedEsday = modifiedEsday.year(parsedIsoWeekYear).isoWeek(1).isoWeekday(1);
|
|
110
|
+
modifiedDate = modifiedEsday.toDate();
|
|
111
|
+
} else if (!isUndefined(parsedElements.isoWeek)) modifiedDate = newEsday.isoWeekYear(parsedIsoWeekYear).toDate();
|
|
112
|
+
}
|
|
113
|
+
return modifiedDate;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Gets or sets the ISO week keeping the time.
|
|
117
|
+
*/
|
|
118
|
+
proto.isoWeek = function(newIsoWeek) {
|
|
119
|
+
if (newIsoWeek !== void 0) {
|
|
120
|
+
const currentWeekday = this.isoWeekday();
|
|
121
|
+
const h = this.hour();
|
|
122
|
+
const m = this.minute();
|
|
123
|
+
const s = this.second();
|
|
124
|
+
const ms = this.millisecond();
|
|
125
|
+
return this.add((newIsoWeek - this.isoWeek()) * 7, constants_default.DAY).isoWeekday(currentWeekday).hour(h, m, s, ms);
|
|
126
|
+
}
|
|
127
|
+
let yearStartDate = this.month(0, yearStart).hour(0, 0, 0, 0);
|
|
128
|
+
const diffToWeekStart = (7 + yearStartDate.day() - weekStart) % 7;
|
|
129
|
+
yearStartDate = yearStartDate.subtract(diffToWeekStart, constants_default.DAY);
|
|
130
|
+
if (this.valueOf() < yearStartDate.valueOf()) return this.subtract(1, constants_default.YEAR).isoWeeksInYear();
|
|
131
|
+
return this.diff(yearStartDate, constants_default.WEEK) + 1;
|
|
132
|
+
};
|
|
133
|
+
proto.isoWeeks = proto.isoWeek;
|
|
134
|
+
/**
|
|
135
|
+
* Gets or sets the ISO day of the week with 1 being Monday and 7 being Sunday.
|
|
136
|
+
*/
|
|
137
|
+
proto.isoWeekday = function(newIsoWeekday) {
|
|
138
|
+
if (newIsoWeekday !== void 0) return this.day(this.day() % 7 ? newIsoWeekday : newIsoWeekday - 7);
|
|
139
|
+
return this.day() || 7;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Gets or sets the year of the ISO week. This year may differ from
|
|
143
|
+
* the calendar year at the start or the end of a year (depending on
|
|
144
|
+
* 'yearStart').
|
|
145
|
+
* According to ISO 8601 the week 01 is the week with the first Thursday
|
|
146
|
+
* in it (see https://en.wikipedia.org/wiki/ISO_week_date).
|
|
147
|
+
* Setting the IsoWeekYear will keep the week number and the day of the week.
|
|
148
|
+
*/
|
|
149
|
+
proto.isoWeekYear = function(newIsoWeekYear) {
|
|
150
|
+
if (newIsoWeekYear !== void 0) {
|
|
151
|
+
if (this.isoWeekYear() === newIsoWeekYear) return this;
|
|
152
|
+
const currentWeek = this.isoWeek();
|
|
153
|
+
const currentWeekday = this.isoWeekday();
|
|
154
|
+
let newDate = this.year(newIsoWeekYear).isoWeek(currentWeek).isoWeekday(currentWeekday);
|
|
155
|
+
if (newDate.isoWeekYear() !== newIsoWeekYear) {
|
|
156
|
+
const yearDiff = newIsoWeekYear - newDate.isoWeekYear();
|
|
157
|
+
newDate = newDate.add(yearDiff, constants_default.YEAR).isoWeekday(currentWeekday);
|
|
158
|
+
}
|
|
159
|
+
return newDate;
|
|
160
|
+
}
|
|
161
|
+
return this.add(yearStart - this.isoWeekday(), constants_default.DAY).year();
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Get the number of weeks in the current year.
|
|
165
|
+
* Most years have 52 weeks, some have 53 weeks.
|
|
166
|
+
*/
|
|
167
|
+
proto.isoWeeksInYear = function() {
|
|
168
|
+
const yearStartWeekday = this.month(0).date(1).day();
|
|
169
|
+
const year = this.year();
|
|
170
|
+
const isLeapYear = year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
171
|
+
if (yearStartWeekday === constants_default.INDEX_THURSDAY || isLeapYear && yearStartWeekday === constants_default.INDEX_WEDNESDAY) return 53;
|
|
172
|
+
return 52;
|
|
173
|
+
};
|
|
174
|
+
const oldStartOf = dayClass.prototype.startOf;
|
|
175
|
+
proto.startOf = function(units) {
|
|
176
|
+
if (units === constants_default.ISOWEEK) return this.date(this.date() - (this.isoWeekday() - weekStart)).startOf(constants_default.DAY);
|
|
177
|
+
return oldStartOf.call(this, units);
|
|
178
|
+
};
|
|
179
|
+
const oldEndOf = proto.endOf;
|
|
180
|
+
proto.endOf = function(units) {
|
|
181
|
+
if (units === constants_default.ISOWEEK) return this.date(this.date() + (7 - this.isoWeekday())).endOf(constants_default.DAY);
|
|
182
|
+
return oldEndOf.call(this, units);
|
|
183
|
+
};
|
|
184
|
+
dayFactory.addFormatTokenDefinitions({
|
|
185
|
+
W: (sourceDate) => sourceDate.isoWeek().toString(),
|
|
186
|
+
WW: (sourceDate) => padStart(sourceDate.isoWeek(), 2, "0"),
|
|
187
|
+
Wo: (sourceDate) => toOrdinal(sourceDate, sourceDate.isoWeek()),
|
|
188
|
+
E: (sourceDate) => sourceDate.isoWeekday().toString(),
|
|
189
|
+
GG: (sourceDate) => padStart(sourceDate.isoWeekYear(), 2, "0").slice(-2),
|
|
190
|
+
GGGG: (sourceDate) => padStart(sourceDate.isoWeekYear(), 4, "0")
|
|
191
|
+
});
|
|
192
|
+
const parseTokensDefinitions = {
|
|
193
|
+
W: [
|
|
194
|
+
match1to2,
|
|
195
|
+
match1to2NoLeadingZero,
|
|
196
|
+
addIsoWeekProperty("isoWeek"),
|
|
197
|
+
_postParseIsoWeek
|
|
198
|
+
],
|
|
199
|
+
WW: [
|
|
200
|
+
match1to2,
|
|
201
|
+
match2,
|
|
202
|
+
addIsoWeekProperty("isoWeek"),
|
|
203
|
+
_postParseIsoWeek
|
|
204
|
+
],
|
|
205
|
+
E: [
|
|
206
|
+
match1to2,
|
|
207
|
+
match1,
|
|
208
|
+
addIsoWeekProperty("isoWeekday"),
|
|
209
|
+
_postParseIsoDayOfWeek
|
|
210
|
+
],
|
|
211
|
+
GG: [
|
|
212
|
+
match1to4,
|
|
213
|
+
match2,
|
|
214
|
+
twoDigitsIsoYearUpdater,
|
|
215
|
+
_postParseIsoYear
|
|
216
|
+
],
|
|
217
|
+
GGGG: [
|
|
218
|
+
match1to4,
|
|
219
|
+
match4,
|
|
220
|
+
addIsoWeekProperty("isoWeekYear"),
|
|
221
|
+
_postParseIsoYear
|
|
222
|
+
]
|
|
223
|
+
};
|
|
224
|
+
dayFactory.addParseTokenDefinitions?.(parseTokensDefinitions);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
//#endregion
|
|
228
|
+
export { isoWeekPlugin as default };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { o as EsDayPlugin, t as EsDay } from "../../chunks/CODi8AFH.js";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/locale/types.d.ts
|
|
4
|
+
type ReadonlyTuple<T, N extends number, R extends readonly T[] = []> = R['length'] extends N ? R : ReadonlyTuple<T, N, readonly [T, ...R]>;
|
|
5
|
+
declare module 'esday' {
|
|
6
|
+
interface EsDay {
|
|
7
|
+
locale(): string;
|
|
8
|
+
locale(localeName: string): EsDay;
|
|
9
|
+
localeObject: () => Locale;
|
|
10
|
+
}
|
|
11
|
+
interface EsDayFactory {
|
|
12
|
+
locale(): string;
|
|
13
|
+
locale(localeName: string): EsDay;
|
|
14
|
+
registerLocale: (locale: Locale, newName?: string) => EsDayFactory;
|
|
15
|
+
unregisterLocale: (localeName: string) => EsDayFactory;
|
|
16
|
+
getLocale: (localeName: string) => Locale;
|
|
17
|
+
updateLocale: (localeName: string, newLocale: Partial<Locale>) => EsDayFactory;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
type DayNames<T = string> = ReadonlyTuple<T, 7>;
|
|
21
|
+
interface DayNamesStandaloneFormat<T = DayNames<string>> {
|
|
22
|
+
format: T;
|
|
23
|
+
standalone: T;
|
|
24
|
+
isFormat: RegExp;
|
|
25
|
+
}
|
|
26
|
+
type MonthNames<T = string> = ReadonlyTuple<T, 12>;
|
|
27
|
+
interface MonthNamesStandaloneFormat<T = MonthNames<string>> {
|
|
28
|
+
format: T;
|
|
29
|
+
standalone: T;
|
|
30
|
+
isFormat?: RegExp;
|
|
31
|
+
}
|
|
32
|
+
interface MonthNamesFunction<T = MonthNames<string>> {
|
|
33
|
+
(esdayInstance: EsDay, format: string): string;
|
|
34
|
+
format: T;
|
|
35
|
+
standalone: T;
|
|
36
|
+
}
|
|
37
|
+
type LocaleFormatKeys = 'LT' | 'LTS' | 'L' | 'LL' | 'LLL' | 'LLLL' | 'l' | 'll' | 'lll' | 'llll';
|
|
38
|
+
type CalendarSpecValFunction = (this: EsDay, refDate?: EsDay) => string;
|
|
39
|
+
type CalendarSpecVal = string | CalendarSpecValFunction;
|
|
40
|
+
interface Calendar {
|
|
41
|
+
sameDay: CalendarSpecVal;
|
|
42
|
+
nextDay: CalendarSpecVal;
|
|
43
|
+
nextWeek: CalendarSpecVal;
|
|
44
|
+
lastDay: CalendarSpecVal;
|
|
45
|
+
lastWeek: CalendarSpecVal;
|
|
46
|
+
sameElse: CalendarSpecVal;
|
|
47
|
+
}
|
|
48
|
+
type CalendarPartial = Partial<Calendar>;
|
|
49
|
+
type RelativeTimeKeys = 'future' | 'past' | 's' | 'ss' | 'm' | 'mm' | 'h' | 'hh' | 'd' | 'dd' | 'w' | 'ww' | 'M' | 'MM' | 'y' | 'yy';
|
|
50
|
+
type RelativeTimeElementFunction = (timeValue: string | number, withoutSuffix: boolean, token: RelativeTimeKeys, isFuture: boolean) => string;
|
|
51
|
+
interface Locale {
|
|
52
|
+
/**
|
|
53
|
+
* Name of the locale
|
|
54
|
+
*/
|
|
55
|
+
readonly name: string;
|
|
56
|
+
/**
|
|
57
|
+
* Array of full day names
|
|
58
|
+
* @example ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
|
|
59
|
+
*/
|
|
60
|
+
readonly weekdays: DayNames | DayNamesStandaloneFormat;
|
|
61
|
+
/**
|
|
62
|
+
* Array of short versions of day names
|
|
63
|
+
* @example ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
|
64
|
+
*/
|
|
65
|
+
readonly weekdaysShort: DayNames;
|
|
66
|
+
/**
|
|
67
|
+
* Array of minimal versions of day names
|
|
68
|
+
* @example ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']
|
|
69
|
+
*/
|
|
70
|
+
readonly weekdaysMin: DayNames;
|
|
71
|
+
readonly months: MonthNames | MonthNamesStandaloneFormat | MonthNamesFunction;
|
|
72
|
+
readonly monthsShort: MonthNames | MonthNamesStandaloneFormat | MonthNamesFunction;
|
|
73
|
+
readonly dayOfMonthOrdinalParse: RegExp;
|
|
74
|
+
readonly ordinal: (number: number, period?: string) => string;
|
|
75
|
+
readonly weekStart: number;
|
|
76
|
+
readonly yearStart: number;
|
|
77
|
+
readonly formats: Record<LocaleFormatKeys, string>;
|
|
78
|
+
readonly calendar: Calendar;
|
|
79
|
+
readonly relativeTime: Record<RelativeTimeKeys, string | RelativeTimeElementFunction>;
|
|
80
|
+
readonly meridiem: (hour: number, minute: number, isLowercase: boolean) => string;
|
|
81
|
+
readonly preParse?: (dateString: string) => string;
|
|
82
|
+
readonly postFormat?: (formattedDate: string) => string;
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/plugins/locale/index.d.ts
|
|
86
|
+
/**
|
|
87
|
+
* Set a property in a literal object avoiding a typescript error TS2322.
|
|
88
|
+
* @param targetLocale - object whose property to create or set
|
|
89
|
+
* @param propName - name of the property to create or set
|
|
90
|
+
* @param newValue - new value of the property
|
|
91
|
+
*/
|
|
92
|
+
declare function setLocaleProperty(targetLocale: Locale, propName: string, newValue: any): void;
|
|
93
|
+
/**
|
|
94
|
+
* Clone a Locale. Used to create a locale for a territory based
|
|
95
|
+
* on the locale of the corresponding language.
|
|
96
|
+
* All properties of the cloned locale are 'readonly' and can only
|
|
97
|
+
* be set by using the function 'setProperty'.
|
|
98
|
+
* @param source - locale to clone
|
|
99
|
+
* @returns cloned locale with all all properties set to 'readonly'.
|
|
100
|
+
*/
|
|
101
|
+
declare function cloneLocale(source: Locale): Locale;
|
|
102
|
+
declare const localePlugin: EsDayPlugin<{}>;
|
|
103
|
+
//#endregion
|
|
104
|
+
export { Calendar, CalendarPartial, CalendarSpecVal, CalendarSpecValFunction, DayNames, DayNamesStandaloneFormat, Locale, LocaleFormatKeys, MonthNames, MonthNamesFunction, MonthNamesStandaloneFormat, RelativeTimeElementFunction, RelativeTimeKeys, cloneLocale, localePlugin as default, setLocaleProperty };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { p as constants_default } from "../../chunks/BkjWOpMU.js";
|
|
2
|
+
import { s as undefinedOr } from "../../chunks/v_QBn7Xm.js";
|
|
3
|
+
import { t as normalizeUnit } from "../../chunks/AyQQ6US-.js";
|
|
4
|
+
import localeEn from "../../locales/en.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/plugins/locale/index.ts
|
|
7
|
+
const LocaleStore = /* @__PURE__ */ new Map();
|
|
8
|
+
let $localeGlobal = "en";
|
|
9
|
+
function getLocale(name) {
|
|
10
|
+
return LocaleStore.get(name) || localeEn;
|
|
11
|
+
}
|
|
12
|
+
function registerLocale(locale, rename) {
|
|
13
|
+
LocaleStore.set(rename || locale.name, locale);
|
|
14
|
+
}
|
|
15
|
+
function unregisterLocale(name) {
|
|
16
|
+
LocaleStore.delete(name);
|
|
17
|
+
}
|
|
18
|
+
function updateLocale(localeName, locale) {
|
|
19
|
+
const updatedLocale = {
|
|
20
|
+
...getLocale(localeName),
|
|
21
|
+
...locale
|
|
22
|
+
};
|
|
23
|
+
LocaleStore.set(localeName, updatedLocale);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Same as 'setLocaleProperty', but for arbitrary objects to enable use
|
|
27
|
+
* e.g. for cloning the 'relativeTime' property.
|
|
28
|
+
* @param target - object whose property to create or set
|
|
29
|
+
* @param propName - name of the property to create or set
|
|
30
|
+
* @param newValue - new value of the property
|
|
31
|
+
*/
|
|
32
|
+
function setObjectProperty(target, propName, newValue) {
|
|
33
|
+
Object.defineProperty(target, propName, {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: false,
|
|
37
|
+
value: newValue
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Set a property in a literal object avoiding a typescript error TS2322.
|
|
42
|
+
* @param targetLocale - object whose property to create or set
|
|
43
|
+
* @param propName - name of the property to create or set
|
|
44
|
+
* @param newValue - new value of the property
|
|
45
|
+
*/
|
|
46
|
+
function setLocaleProperty(targetLocale, propName, newValue) {
|
|
47
|
+
setObjectProperty(targetLocale, propName, newValue);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Clone an object. Used for cloning a Locale, but with a generic
|
|
51
|
+
* name, as we call it recursively.
|
|
52
|
+
* @param sourceObject - object to clone
|
|
53
|
+
* @returns cloned object with all properties set to 'readonly'.
|
|
54
|
+
*/
|
|
55
|
+
function cloneObject(sourceObject) {
|
|
56
|
+
const result = {};
|
|
57
|
+
for (const [key, sourceValue] of Object.entries(sourceObject)) if (typeof sourceValue === "string" || typeof sourceValue === "number" || typeof sourceValue === "function") setObjectProperty(result, key, sourceValue);
|
|
58
|
+
else if (Array.isArray(sourceValue)) setObjectProperty(result, key, structuredClone(sourceValue));
|
|
59
|
+
else if (sourceValue instanceof RegExp) setObjectProperty(result, key, new RegExp(sourceValue.source, sourceValue.flags));
|
|
60
|
+
else if (typeof sourceValue === "object") setObjectProperty(result, key, cloneObject(sourceValue));
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Clone a Locale. Used to create a locale for a territory based
|
|
65
|
+
* on the locale of the corresponding language.
|
|
66
|
+
* All properties of the cloned locale are 'readonly' and can only
|
|
67
|
+
* be set by using the function 'setProperty'.
|
|
68
|
+
* @param source - locale to clone
|
|
69
|
+
* @returns cloned locale with all all properties set to 'readonly'.
|
|
70
|
+
*/
|
|
71
|
+
function cloneLocale(source) {
|
|
72
|
+
return cloneObject(source);
|
|
73
|
+
}
|
|
74
|
+
function getSetPrivateLocaleName(inst, newLocaleName) {
|
|
75
|
+
if (newLocaleName) inst["$conf"]["localeName"] = newLocaleName;
|
|
76
|
+
return inst["$conf"]["localeName"] || "";
|
|
77
|
+
}
|
|
78
|
+
const localePlugin = (_, dayClass, dayFactory) => {
|
|
79
|
+
dayClass.prototype.localeObject = function() {
|
|
80
|
+
return getLocale(getSetPrivateLocaleName(this));
|
|
81
|
+
};
|
|
82
|
+
dayClass.prototype.locale = function(localeName) {
|
|
83
|
+
if (localeName === void 0) return getSetPrivateLocaleName(this);
|
|
84
|
+
const inst = this.clone();
|
|
85
|
+
getSetPrivateLocaleName(inst, localeName);
|
|
86
|
+
return inst;
|
|
87
|
+
};
|
|
88
|
+
const oldClone = dayClass.prototype["clone"];
|
|
89
|
+
dayClass.prototype["clone"] = function() {
|
|
90
|
+
const inst = oldClone.call(this);
|
|
91
|
+
getSetPrivateLocaleName(inst, getSetPrivateLocaleName(this));
|
|
92
|
+
return inst;
|
|
93
|
+
};
|
|
94
|
+
const oldParse = dayClass.prototype["$parse"];
|
|
95
|
+
dayClass.prototype["$parse"] = function(d) {
|
|
96
|
+
getSetPrivateLocaleName(this, $localeGlobal);
|
|
97
|
+
oldParse.call(this, d);
|
|
98
|
+
};
|
|
99
|
+
const oldStartOf = dayClass.prototype["startOf"];
|
|
100
|
+
const oldEndOf = dayClass.prototype["endOf"];
|
|
101
|
+
const fixDiff = (inst, origin, unit, reverse = false) => {
|
|
102
|
+
if (normalizeUnit(unit) === constants_default.WEEK) {
|
|
103
|
+
const defaultStartOfWeek = constants_default.INDEX_MONDAY;
|
|
104
|
+
const weekStart = undefinedOr(inst.localeObject().weekStart, defaultStartOfWeek);
|
|
105
|
+
const $day = origin.day();
|
|
106
|
+
const $date = origin.date();
|
|
107
|
+
const diff = ($day < weekStart ? $day + 7 : $day) - weekStart;
|
|
108
|
+
return origin.date(reverse ? $date + (6 - diff) : $date - diff).hour(inst.hour(), inst.minute(), inst.second(), inst.millisecond());
|
|
109
|
+
}
|
|
110
|
+
return inst;
|
|
111
|
+
};
|
|
112
|
+
dayClass.prototype["startOf"] = function(unit) {
|
|
113
|
+
return fixDiff(oldStartOf.call(this, unit), this, unit);
|
|
114
|
+
};
|
|
115
|
+
dayClass.prototype["endOf"] = function(unit) {
|
|
116
|
+
return fixDiff(oldEndOf.call(this, unit), this, unit, true);
|
|
117
|
+
};
|
|
118
|
+
dayFactory.locale = (localeName) => {
|
|
119
|
+
if (localeName === void 0) return $localeGlobal;
|
|
120
|
+
$localeGlobal = localeName;
|
|
121
|
+
return dayFactory;
|
|
122
|
+
};
|
|
123
|
+
dayFactory.registerLocale = (locale, newName) => {
|
|
124
|
+
registerLocale(locale, newName);
|
|
125
|
+
return dayFactory;
|
|
126
|
+
};
|
|
127
|
+
dayFactory.unregisterLocale = (localeName) => {
|
|
128
|
+
unregisterLocale(localeName);
|
|
129
|
+
return dayFactory;
|
|
130
|
+
};
|
|
131
|
+
dayFactory.getLocale = (localeName) => {
|
|
132
|
+
return getLocale(localeName);
|
|
133
|
+
};
|
|
134
|
+
dayFactory.updateLocale = (localeName, locale) => {
|
|
135
|
+
updateLocale(localeName, locale);
|
|
136
|
+
return dayFactory;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
export { cloneLocale, localePlugin as default, setLocaleProperty };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { t as esday } from "../../chunks/CXWzCl3n.js";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/localeData/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* LocaleData plugin
|
|
6
|
+
*
|
|
7
|
+
* This plugin adds 'method1', 'method2' and formatting and parsing tokens to EsDay
|
|
8
|
+
*
|
|
9
|
+
* This plugin requires the 'Locale' plugin. For using the 'weekdays' function to
|
|
10
|
+
* format a date, the plugin 'Week' is required too.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Get list of month names or format a date as month (short or long month name).
|
|
14
|
+
* @param locale - locale to use
|
|
15
|
+
* @param propName - name of the property to extract
|
|
16
|
+
* @param date - date to format as month name (optional)
|
|
17
|
+
* @param format - format to use for selection of nameArray, if nameArray depends on format context (optional)
|
|
18
|
+
* @returns array with weekday names or formatted date
|
|
19
|
+
*/
|
|
20
|
+
const getWeekdays = (locale, propName, date, format) => {
|
|
21
|
+
let nameArray;
|
|
22
|
+
const property = locale[propName];
|
|
23
|
+
if (Array.isArray(property)) nameArray = property;
|
|
24
|
+
else nameArray = property.standalone;
|
|
25
|
+
if (date !== void 0) {
|
|
26
|
+
let defaultFormat = "";
|
|
27
|
+
switch (propName) {
|
|
28
|
+
case "weekdays":
|
|
29
|
+
defaultFormat = "dddd";
|
|
30
|
+
break;
|
|
31
|
+
case "weekdaysShort":
|
|
32
|
+
defaultFormat = "ddd";
|
|
33
|
+
break;
|
|
34
|
+
case "weekdaysMin":
|
|
35
|
+
defaultFormat = "dd";
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
if (!Array.isArray(property)) {
|
|
39
|
+
const propAsObject = property;
|
|
40
|
+
nameArray = propAsObject.isFormat.test(format ?? defaultFormat) ? propAsObject.format : propAsObject.standalone;
|
|
41
|
+
}
|
|
42
|
+
return nameArray[date.day()];
|
|
43
|
+
}
|
|
44
|
+
return nameArray;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Get list of month names or format a date as month (short or long month name).
|
|
48
|
+
* @param locale - locale to use
|
|
49
|
+
* @param propName - name of the property to extract
|
|
50
|
+
* @param date - date to format as month name (optional)
|
|
51
|
+
* @param format - format to use for selection of nameArray, if nameArray depends on format context (optional)
|
|
52
|
+
* @returns array with month names or formatted date
|
|
53
|
+
*/
|
|
54
|
+
const getMonths = (locale, propName, date, format) => {
|
|
55
|
+
let nameArray;
|
|
56
|
+
const property = locale[propName];
|
|
57
|
+
if (Array.isArray(property)) nameArray = property;
|
|
58
|
+
else if (typeof property === "function") nameArray = property.standalone;
|
|
59
|
+
else nameArray = property.standalone;
|
|
60
|
+
if (date !== void 0) {
|
|
61
|
+
const defaultFormat = propName === "months" ? "MMMM" : "MMM";
|
|
62
|
+
if (typeof property === "function") {
|
|
63
|
+
const propAsFunction = property;
|
|
64
|
+
const formattedDate = propAsFunction(date, format ?? defaultFormat);
|
|
65
|
+
if (propAsFunction.standalone.includes(formattedDate)) nameArray = propAsFunction.standalone;
|
|
66
|
+
else nameArray = propAsFunction.format;
|
|
67
|
+
} else if (typeof property === "object") {
|
|
68
|
+
const propAsObject = property;
|
|
69
|
+
if (propAsObject.isFormat !== void 0) nameArray = propAsObject.isFormat.test(format ?? defaultFormat) ? propAsObject.format : propAsObject.standalone;
|
|
70
|
+
}
|
|
71
|
+
return nameArray[date.month()];
|
|
72
|
+
}
|
|
73
|
+
return nameArray;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Get the full format of the abbreviated date-time format (e.g. 'LT')
|
|
77
|
+
* @param locale - locale to use
|
|
78
|
+
* @param format - abbreviated date-time format
|
|
79
|
+
* @returns full format of abbreviated date-time format
|
|
80
|
+
*/
|
|
81
|
+
const getLongDateFormat = (locale, format) => {
|
|
82
|
+
return locale.formats[format] ?? "";
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Get a locale dependant format for relative dates.
|
|
86
|
+
* @param locale - locale to use
|
|
87
|
+
* @param key - key to select the format (e.g. 'nextDay')
|
|
88
|
+
* @param date - reference date to calculate the relative date for
|
|
89
|
+
* @param now - date to format as base for the relative date
|
|
90
|
+
* @returns - format to use for relative date
|
|
91
|
+
*/
|
|
92
|
+
const getCalendar = (locale, key, date, now) => {
|
|
93
|
+
let result = "";
|
|
94
|
+
const defaultKey = "sameElse";
|
|
95
|
+
const calendarArray = locale.calendar;
|
|
96
|
+
const calendarEntry = calendarArray[key ?? defaultKey] ?? calendarArray[defaultKey];
|
|
97
|
+
const nowDate = now ?? esday();
|
|
98
|
+
if (typeof calendarEntry === "function") {
|
|
99
|
+
/* istanbul ignore else -- @preserve */
|
|
100
|
+
if (date !== void 0) result = calendarEntry.call(date, nowDate);
|
|
101
|
+
} else result = calendarEntry;
|
|
102
|
+
return result;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
*
|
|
106
|
+
* @param locale - locale to use
|
|
107
|
+
* @param timeValue - time value to convert
|
|
108
|
+
* @param withoutSuffix - return value without the suffix (e.g. '4 years' instead of 'in 4 years')
|
|
109
|
+
* @param token - token to use for selecting an entry in the list of relativeTime
|
|
110
|
+
* @param isFuture - suffix to use (e.g. 'in' or 'ago')
|
|
111
|
+
* @returns formatted timeValue
|
|
112
|
+
*/
|
|
113
|
+
const getRelativeTime = (locale, timeValue, withoutSuffix, token, isFuture) => {
|
|
114
|
+
let result = "";
|
|
115
|
+
const relativeTimeEntry = locale.relativeTime[token];
|
|
116
|
+
if (typeof relativeTimeEntry === "function") result = relativeTimeEntry(timeValue, withoutSuffix, token, isFuture);
|
|
117
|
+
else result = relativeTimeEntry.replace(/%d/i, timeValue.toString());
|
|
118
|
+
return result;
|
|
119
|
+
};
|
|
120
|
+
const createLocaleDataObject = (locale) => {
|
|
121
|
+
const localeData = {
|
|
122
|
+
weekdays: (date, format) => getWeekdays(locale, "weekdays", date, format),
|
|
123
|
+
weekdaysShort: (date, format) => getWeekdays(locale, "weekdaysShort", date, format),
|
|
124
|
+
weekdaysMin: (date, format) => getWeekdays(locale, "weekdaysMin", date, format),
|
|
125
|
+
months: (date, format) => getMonths(locale, "months", date, format),
|
|
126
|
+
monthsShort: (date, format) => getMonths(locale, "monthsShort", date, format),
|
|
127
|
+
ordinal: locale.ordinal,
|
|
128
|
+
firstDayOfWeek: () => locale.weekStart,
|
|
129
|
+
firstDayOfYear: () => locale.yearStart,
|
|
130
|
+
longDateFormat: (format) => getLongDateFormat(locale, format),
|
|
131
|
+
calendar: (key, date, now) => getCalendar(locale, key, date, now),
|
|
132
|
+
relativeTime: (timeValue, withoutSuffix, token, isFuture) => getRelativeTime(locale, timeValue, withoutSuffix, token, isFuture),
|
|
133
|
+
meridiem: locale.meridiem
|
|
134
|
+
};
|
|
135
|
+
if (locale.preParse !== void 0) localeData.preParse = locale.preParse;
|
|
136
|
+
if (locale.postFormat !== void 0) localeData.postFormat = locale.postFormat;
|
|
137
|
+
return localeData;
|
|
138
|
+
};
|
|
139
|
+
const localeDataPlugin = (_, dayClass, dayFactory) => {
|
|
140
|
+
const proto = dayClass.prototype;
|
|
141
|
+
proto.localeData = function() {
|
|
142
|
+
return createLocaleDataObject(this.localeObject());
|
|
143
|
+
};
|
|
144
|
+
dayFactory.localeData = (localeName) => {
|
|
145
|
+
return createLocaleDataObject(localeName !== void 0 ? dayFactory.getLocale(localeName) : dayFactory.getLocale(dayFactory.locale()));
|
|
146
|
+
};
|
|
147
|
+
dayFactory.months = () => getMonths(dayFactory.getLocale(dayFactory.locale()), "months");
|
|
148
|
+
dayFactory.monthsShort = () => getMonths(dayFactory.getLocale(dayFactory.locale()), "monthsShort");
|
|
149
|
+
dayFactory.weekdays = () => getWeekdays(dayFactory.getLocale(dayFactory.locale()), "weekdays");
|
|
150
|
+
dayFactory.weekdaysShort = () => getWeekdays(dayFactory.getLocale(dayFactory.locale()), "weekdaysShort");
|
|
151
|
+
dayFactory.weekdaysMin = () => getWeekdays(dayFactory.getLocale(dayFactory.locale()), "weekdaysMin");
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
export { localeDataPlugin as default };
|