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