esday 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +5 -1
- package/chunks/{DXFoLbHM.js → 9Re3Ck2t.js} +1 -2
- package/chunks/{CeKusvtV.js → BfEWL_VC.js} +0 -1
- package/chunks/{oiGWnahC.js → Bk-WlP29.js} +20 -35
- package/chunks/{DuRKUq5K.js → BtFAvcS3.js} +1 -2
- package/chunks/BzQsG1-n.js +473 -0
- package/chunks/DBmUXISx.d.ts +3 -0
- package/chunks/{DMdr1ZL1.js → DLzmBvJ7.js} +2 -3
- package/chunks/{DIG_UBsE.js → DThHId1s.js} +3 -4
- package/chunks/{BB5OVV-y.d.ts → MfctHIHI.d.ts} +0 -8
- package/chunks/RZP9wuxV.js +452 -0
- package/chunks/{i3oEJgL3.js → SIX-1Rv6.js} +1 -2
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/locales/af.d.ts +3 -2
- package/locales/af.js +1 -2
- package/locales/am.d.ts +3 -2
- package/locales/am.js +1 -2
- package/locales/ar-dz.d.ts +0 -2
- package/locales/ar-dz.js +1 -2
- package/locales/ar-iq.d.ts +0 -2
- package/locales/ar-iq.js +1 -2
- package/locales/ar-kw.d.ts +0 -2
- package/locales/ar-kw.js +1 -2
- package/locales/ar-ly.d.ts +0 -2
- package/locales/ar-ly.js +1 -2
- package/locales/ar-ma.d.ts +0 -2
- package/locales/ar-ma.js +1 -2
- package/locales/ar-sa.d.ts +0 -2
- package/locales/ar-sa.js +1 -2
- package/locales/ar-tn.d.ts +0 -2
- package/locales/ar-tn.js +1 -2
- package/locales/ar.d.ts +3 -2
- package/locales/ar.js +1 -2
- package/locales/az.d.ts +3 -2
- package/locales/az.js +1 -2
- package/locales/be.d.ts +3 -2
- package/locales/be.js +1 -2
- package/locales/bg.d.ts +3 -2
- package/locales/bg.js +1 -2
- package/locales/bi.d.ts +3 -2
- package/locales/bi.js +1 -2
- package/locales/bm.d.ts +3 -2
- package/locales/bm.js +1 -2
- package/locales/bn-bd.d.ts +0 -2
- package/locales/bn-bd.js +2 -3
- package/locales/bn.d.ts +3 -2
- package/locales/bn.js +1 -2
- package/locales/bo.d.ts +3 -2
- package/locales/bo.js +1 -2
- package/locales/br.d.ts +3 -2
- package/locales/br.js +1 -2
- package/locales/bs.d.ts +3 -2
- package/locales/bs.js +1 -2
- package/locales/ca.d.ts +3 -2
- package/locales/ca.js +4 -5
- package/locales/cs.d.ts +3 -2
- package/locales/cs.js +1 -2
- package/locales/cv.d.ts +3 -2
- package/locales/cv.js +1 -2
- package/locales/cy.d.ts +3 -2
- package/locales/cy.js +1 -2
- package/locales/da.d.ts +3 -2
- package/locales/da.js +1 -2
- package/locales/de-at.d.ts +0 -2
- package/locales/de-at.js +2 -3
- package/locales/de-ch.d.ts +0 -2
- package/locales/de-ch.js +2 -3
- package/locales/de.d.ts +3 -2
- package/locales/de.js +1 -2
- package/locales/dv.d.ts +3 -2
- package/locales/dv.js +1 -2
- package/locales/el.d.ts +3 -2
- package/locales/el.js +1 -2
- package/locales/en-au.d.ts +0 -2
- package/locales/en-au.js +1 -2
- package/locales/en-ca.d.ts +0 -2
- package/locales/en-ca.js +1 -2
- package/locales/en-gb.d.ts +0 -2
- package/locales/en-gb.js +1 -2
- package/locales/en-ie.d.ts +0 -2
- package/locales/en-ie.js +1 -2
- package/locales/en-il.d.ts +0 -2
- package/locales/en-il.js +1 -2
- package/locales/en-in.d.ts +0 -2
- package/locales/en-in.js +1 -2
- package/locales/en-nz.d.ts +0 -2
- package/locales/en-nz.js +1 -2
- package/locales/en-sg.d.ts +0 -2
- package/locales/en-sg.js +1 -2
- package/locales/en-tt.d.ts +0 -2
- package/locales/en-tt.js +1 -2
- package/locales/en-us.d.ts +0 -2
- package/locales/en-us.js +1 -2
- package/locales/en.d.ts +4 -2
- package/locales/en.js +1 -2
- package/locales/eo.d.ts +3 -2
- package/locales/eo.js +1 -2
- package/locales/es-do.d.ts +0 -2
- package/locales/es-do.js +2 -3
- package/locales/es-mx.d.ts +0 -2
- package/locales/es-mx.js +2 -3
- package/locales/es-pr.d.ts +0 -2
- package/locales/es-pr.js +2 -3
- package/locales/es-us.d.ts +0 -2
- package/locales/es-us.js +2 -3
- package/locales/es.d.ts +3 -2
- package/locales/es.js +1 -2
- package/locales/et.d.ts +3 -2
- package/locales/et.js +1 -2
- package/locales/eu.d.ts +3 -2
- package/locales/eu.js +1 -2
- package/locales/fa.d.ts +3 -2
- package/locales/fa.js +1 -2
- package/locales/fi.d.ts +3 -2
- package/locales/fi.js +1 -2
- package/locales/fil.d.ts +3 -2
- package/locales/fil.js +1 -2
- package/locales/fo.d.ts +3 -2
- package/locales/fo.js +1 -2
- package/locales/fr-ca.d.ts +0 -2
- package/locales/fr-ca.js +2 -3
- package/locales/fr-ch.d.ts +0 -2
- package/locales/fr-ch.js +2 -3
- package/locales/fr.d.ts +3 -2
- package/locales/fr.js +1 -2
- package/locales/fy.d.ts +3 -2
- package/locales/fy.js +1 -2
- package/locales/ga.d.ts +3 -2
- package/locales/ga.js +1 -2
- package/locales/gd.d.ts +3 -2
- package/locales/gd.js +1 -2
- package/locales/gl.d.ts +3 -2
- package/locales/gl.js +1 -2
- package/locales/gom-deva.d.ts +3 -2
- package/locales/gom-deva.js +1 -2
- package/locales/gom-latn.d.ts +3 -2
- package/locales/gom-latn.js +1 -2
- package/locales/gu.d.ts +3 -2
- package/locales/gu.js +1 -2
- package/locales/he.d.ts +3 -2
- package/locales/he.js +1 -2
- package/locales/hi.d.ts +3 -2
- package/locales/hi.js +1 -2
- package/locales/hr.d.ts +3 -2
- package/locales/hr.js +1 -2
- package/locales/ht.d.ts +3 -2
- package/locales/ht.js +1 -2
- package/locales/hu.d.ts +3 -2
- package/locales/hu.js +1 -2
- package/locales/hy-am.d.ts +3 -2
- package/locales/hy-am.js +1 -2
- package/locales/id.d.ts +3 -2
- package/locales/id.js +2 -3
- package/locales/is.d.ts +3 -2
- package/locales/is.js +1 -2
- package/locales/it-ch.d.ts +0 -2
- package/locales/it-ch.js +2 -3
- package/locales/it.d.ts +3 -2
- package/locales/it.js +1 -2
- package/locales/ja.d.ts +6 -2
- package/locales/ja.js +1 -2
- package/locales/jv.d.ts +3 -2
- package/locales/jv.js +1 -2
- package/locales/ka.d.ts +3 -2
- package/locales/ka.js +3 -4
- package/locales/kk.d.ts +3 -2
- package/locales/kk.js +1 -2
- package/locales/km.d.ts +3 -2
- package/locales/km.js +1 -2
- package/locales/kn.d.ts +3 -2
- package/locales/kn.js +1 -2
- package/locales/ko.d.ts +3 -2
- package/locales/ko.js +1 -2
- package/locales/ku.d.ts +3 -2
- package/locales/ku.js +1 -2
- package/locales/ky.d.ts +3 -2
- package/locales/ky.js +1 -2
- package/locales/lb.d.ts +3 -2
- package/locales/lb.js +1 -2
- package/locales/lo.d.ts +3 -2
- package/locales/lo.js +1 -2
- package/locales/lt.d.ts +3 -2
- package/locales/lt.js +1 -2
- package/locales/lv.d.ts +3 -2
- package/locales/lv.js +1 -2
- package/locales/me.d.ts +3 -2
- package/locales/me.js +1 -2
- package/locales/mi.d.ts +0 -2
- package/locales/mi.js +1 -2
- package/locales/mk.d.ts +0 -2
- package/locales/mk.js +1 -2
- package/locales/ml.d.ts +0 -2
- package/locales/ml.js +1 -2
- package/locales/mn.d.ts +0 -2
- package/locales/mn.js +1 -2
- package/locales/mr.d.ts +3 -2
- package/locales/mr.js +3 -8
- package/locales/ms-my.d.ts +0 -2
- package/locales/ms-my.js +2 -3
- package/locales/ms.d.ts +3 -2
- package/locales/ms.js +1 -2
- package/locales/mt.d.ts +3 -2
- package/locales/mt.js +1 -2
- package/locales/my.d.ts +3 -2
- package/locales/my.js +1 -2
- package/locales/nb.d.ts +3 -2
- package/locales/nb.js +1 -2
- package/locales/ne.d.ts +3 -2
- package/locales/ne.js +1 -2
- package/locales/nl-be.d.ts +0 -2
- package/locales/nl-be.js +4 -5
- package/locales/nl.d.ts +3 -2
- package/locales/nl.js +1 -2
- package/locales/nn.d.ts +3 -2
- package/locales/nn.js +1 -2
- package/locales/oc-lnc.d.ts +3 -2
- package/locales/oc-lnc.js +1 -2
- package/locales/pa-in.d.ts +3 -2
- package/locales/pa-in.js +1 -2
- package/locales/pl.d.ts +3 -2
- package/locales/pl.js +2 -3
- package/locales/pt-br.d.ts +0 -2
- package/locales/pt-br.js +2 -3
- package/locales/pt.d.ts +3 -2
- package/locales/pt.js +1 -2
- package/locales/rn.d.ts +3 -2
- package/locales/rn.js +1 -2
- package/locales/ro.d.ts +3 -2
- package/locales/ro.js +1 -2
- package/locales/ru.d.ts +6 -2
- package/locales/ru.js +1 -2
- package/locales/rw.d.ts +3 -2
- package/locales/rw.js +1 -2
- package/locales/sd.d.ts +3 -2
- package/locales/sd.js +1 -2
- package/locales/se.d.ts +3 -2
- package/locales/se.js +1 -2
- package/locales/si.d.ts +3 -2
- package/locales/si.js +1 -2
- package/locales/sk.d.ts +3 -2
- package/locales/sk.js +1 -2
- package/locales/sl.d.ts +3 -2
- package/locales/sl.js +1 -2
- package/locales/sq.d.ts +3 -2
- package/locales/sq.js +1 -2
- package/locales/sr-cyrl.d.ts +0 -2
- package/locales/sr-cyrl.js +2 -3
- package/locales/sr.d.ts +3 -2
- package/locales/sr.js +1 -2
- package/locales/ss.d.ts +3 -2
- package/locales/ss.js +1 -2
- package/locales/sv-fi.d.ts +0 -2
- package/locales/sv-fi.js +2 -3
- package/locales/sv.d.ts +3 -2
- package/locales/sv.js +2 -3
- package/locales/sw.d.ts +3 -2
- package/locales/sw.js +3 -4
- package/locales/ta.d.ts +3 -2
- package/locales/ta.js +1 -2
- package/locales/te.d.ts +3 -2
- package/locales/te.js +1 -2
- package/locales/tet.d.ts +3 -2
- package/locales/tet.js +1 -2
- package/locales/tg.d.ts +3 -2
- package/locales/tg.js +1 -2
- package/locales/th.d.ts +3 -2
- package/locales/th.js +1 -2
- package/locales/tk.d.ts +3 -2
- package/locales/tk.js +1 -2
- package/locales/tl-ph.d.ts +3 -2
- package/locales/tl-ph.js +1 -2
- package/locales/tlh.d.ts +3 -2
- package/locales/tlh.js +1 -2
- package/locales/tr.d.ts +3 -2
- package/locales/tr.js +1 -2
- package/locales/tzl.d.ts +3 -2
- package/locales/tzl.js +1 -2
- package/locales/tzm-latn.d.ts +0 -2
- package/locales/tzm-latn.js +2 -3
- package/locales/tzm.d.ts +3 -2
- package/locales/tzm.js +1 -2
- package/locales/ug-cn.d.ts +3 -2
- package/locales/ug-cn.js +1 -2
- package/locales/uk.d.ts +0 -2
- package/locales/uk.js +2 -3
- package/locales/ur.d.ts +3 -2
- package/locales/ur.js +1 -2
- package/locales/uz-latn.d.ts +0 -2
- package/locales/uz-latn.js +3 -4
- package/locales/uz.d.ts +3 -2
- package/locales/uz.js +1 -2
- package/locales/vi.d.ts +3 -2
- package/locales/vi.js +1 -2
- package/locales/x-pseudo.d.ts +4 -2
- package/locales/x-pseudo.js +1 -2
- package/locales/yo.d.ts +3 -2
- package/locales/yo.js +1 -2
- package/locales/zh-cn.d.ts +0 -2
- package/locales/zh-cn.js +2 -3
- package/locales/zh-hk.d.ts +0 -2
- package/locales/zh-hk.js +2 -3
- package/locales/zh-mo.d.ts +0 -2
- package/locales/zh-mo.js +2 -3
- package/locales/zh-tw.d.ts +0 -2
- package/locales/zh-tw.js +2 -3
- package/locales/zh.d.ts +6 -2
- package/locales/zh.js +1 -2
- package/package.json +25 -21
- package/plugins/advancedFormat/index.d.ts +6 -3
- package/plugins/advancedFormat/index.js +2 -3
- package/plugins/advancedParse/index.d.ts +20 -3
- package/plugins/advancedParse/index.js +6 -8
- package/plugins/calendar/index.d.ts +8 -3
- package/plugins/calendar/index.js +1 -2
- package/plugins/dayOfYear/index.d.ts +1 -3
- package/plugins/dayOfYear/index.js +1 -2
- package/plugins/duration/index.d.ts +14 -8
- package/plugins/duration/index.js +1 -473
- package/plugins/index.d.ts +28 -0
- package/plugins/index.js +28 -0
- package/plugins/isBetween/index.d.ts +1 -3
- package/plugins/isBetween/index.js +2 -3
- package/plugins/isLeapYear/index.d.ts +1 -3
- package/plugins/isLeapYear/index.js +1 -2
- package/plugins/isSameOrAfter/index.d.ts +1 -3
- package/plugins/isSameOrAfter/index.js +1 -2
- package/plugins/isSameOrBefore/index.d.ts +1 -3
- package/plugins/isSameOrBefore/index.js +1 -2
- package/plugins/isToday/index.d.ts +1 -3
- package/plugins/isToday/index.js +2 -3
- package/plugins/isTomorrow/index.d.ts +1 -3
- package/plugins/isTomorrow/index.js +2 -3
- package/plugins/isYesterday/index.d.ts +1 -3
- package/plugins/isYesterday/index.js +2 -3
- package/plugins/isoWeek/index.d.ts +12 -3
- package/plugins/isoWeek/index.js +5 -6
- package/plugins/locale/index.d.ts +30 -21
- package/plugins/locale/index.js +4 -5
- package/plugins/localeData/index.d.ts +9 -3
- package/plugins/localeData/index.js +3 -6
- package/plugins/localizedFormat/index.d.ts +6 -3
- package/plugins/localizedFormat/index.js +3 -4
- package/plugins/localizedParse/index.d.ts +26 -3
- package/plugins/localizedParse/index.js +2 -3
- package/plugins/minMax/index.d.ts +1 -3
- package/plugins/minMax/index.js +2 -3
- package/plugins/objectSupport/index.d.ts +10 -3
- package/plugins/objectSupport/index.js +6 -9
- package/plugins/pluralGetSet/index.d.ts +8 -3
- package/plugins/pluralGetSet/index.js +1 -2
- package/plugins/quarterOfYear/index.d.ts +6 -3
- package/plugins/quarterOfYear/index.js +4 -5
- package/plugins/relativeTime/index.d.ts +22 -8
- package/plugins/relativeTime/index.js +7 -6
- package/plugins/timezone/index.d.ts +17 -3
- package/plugins/timezone/index.js +1 -454
- package/plugins/toArray/index.d.ts +1 -3
- package/plugins/toArray/index.js +1 -2
- package/plugins/toObject/index.d.ts +1 -3
- package/plugins/toObject/index.js +1 -2
- package/plugins/utc/index.d.ts +11 -3
- package/plugins/utc/index.js +8 -9
- package/plugins/week/index.d.ts +12 -3
- package/plugins/week/index.js +6 -7
- package/LICENSE +0 -21
- package/chunks/CBlQG2yl.d.ts +0 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as isArray } from "./
|
|
2
|
-
import { n as normalizeUnitWithPlurals } from "./
|
|
3
|
-
|
|
1
|
+
import { t as isArray } from "./BtFAvcS3.js";
|
|
2
|
+
import { n as normalizeUnitWithPlurals } from "./DLzmBvJ7.js";
|
|
3
|
+
// src/common/date-fields.ts
|
|
4
4
|
/**
|
|
5
5
|
* Map units to fields of a javascript Date object.
|
|
6
6
|
*/
|
|
@@ -33,5 +33,4 @@ function setUnitInDateUTC(date, unit, value) {
|
|
|
33
33
|
date[`setUTC${unitToField(unit)}`](...isArray(value) ? value : [value]);
|
|
34
34
|
return date;
|
|
35
35
|
}
|
|
36
|
-
//#endregion
|
|
37
36
|
export { setUnitInDateUTC as a, setUnitInDate as i, getUnitInDateUTC as n, prettyUnitsDate as r, getUnitInDate as t };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/common/units.d.ts
|
|
2
1
|
declare const UNIT_MAP_SHORT_TO_LONG: {
|
|
3
2
|
readonly y: "year";
|
|
4
3
|
readonly Q: "quarter";
|
|
@@ -73,12 +72,8 @@ type UnitSecond = UnionUnitSingular<'s'>;
|
|
|
73
72
|
type UnitSeconds = UnionUnitPlural<'s'>;
|
|
74
73
|
type UnitMs = UnionUnitSingular<'ms'>;
|
|
75
74
|
type UnitMss = UnionUnitPlural<'ms'>;
|
|
76
|
-
//#endregion
|
|
77
|
-
//#region src/types/util-types.d.ts
|
|
78
75
|
type SimpleType = string | number | boolean | null | undefined;
|
|
79
76
|
type SimpleObject = Record<string, SimpleType | string[] | Record<string, SimpleType>>;
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/types/core.d.ts
|
|
82
77
|
type EsDayFactoryParserFn = (d?: DateType, ...others: (SimpleType | string[] | {
|
|
83
78
|
[key: string]: SimpleType;
|
|
84
79
|
})[]) => EsDay;
|
|
@@ -150,8 +145,6 @@ interface ConfigurationObject {
|
|
|
150
145
|
args_2?: SimpleType | string[] | Record<string, SimpleType>;
|
|
151
146
|
args_3?: SimpleType | string[] | Record<string, SimpleType>;
|
|
152
147
|
}
|
|
153
|
-
//#endregion
|
|
154
|
-
//#region src/core/EsDay.d.ts
|
|
155
148
|
declare interface EsDay {
|
|
156
149
|
year: (() => number) & ((year: number, month?: number, date?: number) => EsDay);
|
|
157
150
|
month: (() => number) & ((month: number, date?: number) => EsDay);
|
|
@@ -232,5 +225,4 @@ declare class EsDay {
|
|
|
232
225
|
toString(): string;
|
|
233
226
|
protected $set(unit: UnitTypeGetSet | UnitsObjectTypeSet, values: number[]): this;
|
|
234
227
|
}
|
|
235
|
-
//#endregion
|
|
236
228
|
export { UnitMs as A, UnitDates as C, UnitIsoWeeks as D, UnitIsoWeek as E, UnitTypeCore as F, UnitTypeGetSet as I, UnitTypePlurals as L, UnitSecond as M, UnitType as N, UnitMin as O, UnitTypeAddSub as P, UnitWeek as R, UnitDate as S, UnitHour as T, LongUnit as _, EsDayFactory as a, PrettyUnitFromPlurals as b, FormattingTokenDefinitions as c, ParsingObjectPlurals as d, ParsingObjectShort as f, SimpleType as g, SimpleObject as h, DateType as i, UnitQuarter as j, UnitMonth as k, ParsingObject as l, UnitsObjectTypeSet as m, ConfigurationObject as n, EsDayFactoryParserFn as o, UnitsObjectTypeAddSub as p, DateFromDateComponents as r, EsDayPlugin as s, EsDay as t, ParsingObjectLong as u, PrettyUnitAsPlural as v, UnitDay as w, ShortUnit as x, PrettyUnitAsSingular as y, UnitYear as z };
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import { t as esday } from "./Bk-WlP29.js";
|
|
2
|
+
import { f as constants_default } from "./BfEWL_VC.js";
|
|
3
|
+
import { n as isEmptyObject, r as isObject } from "./BtFAvcS3.js";
|
|
4
|
+
import { n as normalizeUnitWithPlurals } from "./DLzmBvJ7.js";
|
|
5
|
+
// src/plugins/timezone/timezone-util.ts
|
|
6
|
+
/**
|
|
7
|
+
* Cache for Intl.DateTimeFormat instances for formatting date and time
|
|
8
|
+
* used to improve performance.
|
|
9
|
+
* The key is a combination of timezone and timeZoneName.
|
|
10
|
+
*/
|
|
11
|
+
const dtfCacheDateTime = {};
|
|
12
|
+
const dtfCacheTimezoneName = {};
|
|
13
|
+
const TzDefaultTimezoneLocale = "en-US";
|
|
14
|
+
/**
|
|
15
|
+
* Get a cached or newly created Intl.DateTimeFormat instance for date/time formats.
|
|
16
|
+
*
|
|
17
|
+
* This function caches Intl.DateTimeFormat objects since their creation
|
|
18
|
+
* is relatively slow. It returns a formatter configured for date and time values
|
|
19
|
+
* using the given timezone.
|
|
20
|
+
*
|
|
21
|
+
* @param timezone - The IANA timezone identifier (e.g., "Asia/Shanghai").
|
|
22
|
+
* @returns A cached or new Intl.DateTimeFormat instance.
|
|
23
|
+
*/
|
|
24
|
+
function getDateTimeFormat(timezone) {
|
|
25
|
+
const formatOptions = {
|
|
26
|
+
hour12: false,
|
|
27
|
+
hourCycle: "h23",
|
|
28
|
+
year: "numeric",
|
|
29
|
+
month: "2-digit",
|
|
30
|
+
day: "2-digit",
|
|
31
|
+
hour: "2-digit",
|
|
32
|
+
minute: "2-digit",
|
|
33
|
+
second: "2-digit",
|
|
34
|
+
weekday: "short"
|
|
35
|
+
};
|
|
36
|
+
if (timezone.length > 0) formatOptions["timeZone"] = timezone;
|
|
37
|
+
const key = `${timezone}|formatDateTime`;
|
|
38
|
+
let dtf = dtfCacheDateTime[key];
|
|
39
|
+
if (!dtf) {
|
|
40
|
+
dtf = new Intl.DateTimeFormat("en-US", formatOptions);
|
|
41
|
+
dtfCacheDateTime[key] = dtf;
|
|
42
|
+
}
|
|
43
|
+
return dtf;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get a cached or newly created Intl.DateTimeFormat instance for timezone name formats.
|
|
47
|
+
*
|
|
48
|
+
* This function caches Intl.DateTimeFormat objects since their creation
|
|
49
|
+
* is relatively slow. It returns a formatter configured for timezone names using
|
|
50
|
+
* the given timezone and locale name.
|
|
51
|
+
*
|
|
52
|
+
* @param timezone - The IANA timezone identifier (e.g., "Asia/Shanghai").
|
|
53
|
+
* @param localeName - Optional settings for the name of the locale to use.
|
|
54
|
+
* @returns A cached or new Intl.DateTimeFormat instance.
|
|
55
|
+
*/
|
|
56
|
+
function getTimezoneNameFormat(timezone, localeName = TzDefaultTimezoneLocale) {
|
|
57
|
+
const formatOptions = {
|
|
58
|
+
year: "numeric",
|
|
59
|
+
month: "2-digit",
|
|
60
|
+
timeZoneName: "short"
|
|
61
|
+
};
|
|
62
|
+
if (timezone.length > 0) formatOptions["timeZone"] = timezone;
|
|
63
|
+
const key = `${timezone}|localeName|timezoneName`;
|
|
64
|
+
let dtf = dtfCacheTimezoneName[key];
|
|
65
|
+
if (!dtf) {
|
|
66
|
+
dtf = new Intl.DateTimeFormat(localeName, formatOptions);
|
|
67
|
+
dtfCacheTimezoneName[key] = dtf;
|
|
68
|
+
}
|
|
69
|
+
return dtf;
|
|
70
|
+
}
|
|
71
|
+
// src/plugins/timezone/index.ts
|
|
72
|
+
/**
|
|
73
|
+
* timezone plugin
|
|
74
|
+
*
|
|
75
|
+
* This plugin adds the 'tz' method to the EsDay class.
|
|
76
|
+
* This plugin adds the 'tz' method/object to the esday class with the methods 'setDefault', 'getDefault' and 'guess'.
|
|
77
|
+
*
|
|
78
|
+
* This plugin adds the formatting tokens 'z' and 'Z' to EsDay.
|
|
79
|
+
*
|
|
80
|
+
* This plugin requires the 'utc' plugin.
|
|
81
|
+
* When parsing with a locale then the 'advancedParse' plugin, the 'localizedParse' plugin
|
|
82
|
+
* and at least one registered locale.
|
|
83
|
+
* This plugin can handle the 'locale' plugin.
|
|
84
|
+
*
|
|
85
|
+
* esday parameters in '$conf' defined in timezone plugin:
|
|
86
|
+
* timezone name of the timezone of this instance
|
|
87
|
+
*/
|
|
88
|
+
const UNIT_ARRAY_MAP = {
|
|
89
|
+
year: 0,
|
|
90
|
+
month: 1,
|
|
91
|
+
date: 2,
|
|
92
|
+
hour: 3,
|
|
93
|
+
minute: 4,
|
|
94
|
+
second: 5
|
|
95
|
+
};
|
|
96
|
+
const maxDstDiff = 72e5;
|
|
97
|
+
const typeToPos = {
|
|
98
|
+
year: 0,
|
|
99
|
+
month: 1,
|
|
100
|
+
day: 2,
|
|
101
|
+
hour: 3,
|
|
102
|
+
minute: 4,
|
|
103
|
+
second: 5
|
|
104
|
+
};
|
|
105
|
+
const matchContainsOffset = /^(\d{4})[-/](\d{1,2})[-/](\d{0,2}).*(([+-]\d\d:?(\d\d)?)$|Z$)/;
|
|
106
|
+
/**
|
|
107
|
+
* Generate formatted date parts for a given timestamp and timezone.
|
|
108
|
+
*
|
|
109
|
+
* This function creates a Date object from the given timestamp,
|
|
110
|
+
* retrieves a cached or new Intl.DateTimeFormat instance using
|
|
111
|
+
* the provided timezone and returns the formatted parts
|
|
112
|
+
* (year, month, day-of-month, hour, minute, second, weekday)
|
|
113
|
+
*
|
|
114
|
+
* @param timestamp - The timestamp in milliseconds since the Unix epoch.
|
|
115
|
+
* @param timezone - The IANA timezone identifier (e.g., "Asia/Shanghai").
|
|
116
|
+
* @returns An array of formatted date parts.
|
|
117
|
+
*/
|
|
118
|
+
function makeFormatPartsDateTime(timestamp, timezone) {
|
|
119
|
+
const dtf = getDateTimeFormat(timezone);
|
|
120
|
+
const date = new Date(timestamp);
|
|
121
|
+
return dtf.formatToParts(date);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Do we have to convert parsed instance to another timezone?
|
|
125
|
+
* @param input - input value to be parsed by plugin timezone
|
|
126
|
+
* @returns true: result of parsing of input value must be converted to timezone
|
|
127
|
+
*/
|
|
128
|
+
function convertRequired(input) {
|
|
129
|
+
const requiresObjectSupport = isObject(input) && !(input instanceof Date) && input !== null && !isEmptyObject(input);
|
|
130
|
+
return typeof input !== "string" && !Array.isArray(input) && !requiresObjectSupport;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Convert en-US short weekday names to a number using values like Date.getDay() does.
|
|
134
|
+
* @param shortWeekdayName - short weekday name (in locale en-US)
|
|
135
|
+
* @returns - number indicating the weekday (0=Sunday, 1=Monday, ...)
|
|
136
|
+
*/
|
|
137
|
+
function weekdayNameToNumber(shortWeekdayName) {
|
|
138
|
+
switch (shortWeekdayName) {
|
|
139
|
+
case "Sun": return 0;
|
|
140
|
+
case "Mon": return 1;
|
|
141
|
+
case "Tue": return 2;
|
|
142
|
+
case "Wed": return 3;
|
|
143
|
+
case "Thu": return 4;
|
|
144
|
+
case "Fri": return 5;
|
|
145
|
+
case "Sat": return 6;
|
|
146
|
+
/* v8 ignore next -- @preserve */
|
|
147
|
+
default: return -1;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get the date components (year, month, day ...) of the given timestamp,
|
|
152
|
+
* if formatted in the given timezone.
|
|
153
|
+
* The function returns an array with the values for
|
|
154
|
+
* [year, month, day-of-month, hour, minute, second, weekday].
|
|
155
|
+
* 'month' is 1..12; 'day-of-month' is 1..31, 'weekday' is 0..6.
|
|
156
|
+
* @param timestamp - timestamp to convert
|
|
157
|
+
* @param timezone - timezone to use for formatting
|
|
158
|
+
* @returns array of numbers with the date components of the timestamp in the timezone
|
|
159
|
+
*/
|
|
160
|
+
function timestampToDateTimeComponents(timestamp, timezone) {
|
|
161
|
+
const formatResult = makeFormatPartsDateTime(timestamp, timezone);
|
|
162
|
+
const filled = [];
|
|
163
|
+
let weekdayNumber = -1;
|
|
164
|
+
for (let i = 0; i < formatResult.length; i += 1) {
|
|
165
|
+
const { type, value } = formatResult[i];
|
|
166
|
+
if (type === "weekday") {
|
|
167
|
+
weekdayNumber = weekdayNameToNumber(value);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const pos = typeToPos[type];
|
|
171
|
+
if (pos >= 0) filled[pos] = Number.parseInt(value, 10);
|
|
172
|
+
filled[6] = weekdayNumber;
|
|
173
|
+
}
|
|
174
|
+
return filled;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Get the formatted timezone name of the given timestamp, if formatted in
|
|
178
|
+
* the given timezone.
|
|
179
|
+
* The function returns the short name of the timezone using the given locale.
|
|
180
|
+
* 'month' is 1..12; 'day-of-month' is 1..31, 'weekday' is 0..6.
|
|
181
|
+
* @param timestamp - timestamp to convert
|
|
182
|
+
* @param timezone - timezone to use for conversion
|
|
183
|
+
* @param timezone - timezone to use for conversion
|
|
184
|
+
* @returns array of numbers with the date components of the timestamp in the timezone
|
|
185
|
+
*/
|
|
186
|
+
function timestampToTimezoneName(timestamp, timezone, locale) {
|
|
187
|
+
const dtf = getTimezoneNameFormat(timezone, locale);
|
|
188
|
+
const date = new Date(timestamp);
|
|
189
|
+
const formatResult = dtf.formatToParts(date);
|
|
190
|
+
let timezoneNameShort = timezone;
|
|
191
|
+
/* istanbul ignore else -- @preserve */
|
|
192
|
+
if (formatResult.length >= 4 && formatResult[4].type === "timeZoneName") timezoneNameShort = formatResult[4].value;
|
|
193
|
+
return timezoneNameShort;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Calculate the new basic values for year, month etc. when using the "set" method.
|
|
197
|
+
* These values must be adjusted to the current timezone.
|
|
198
|
+
* @param dateComponents - array with the components of the formatted timestamp (year, month, ...)
|
|
199
|
+
* @param currentMs - milliseconds of the current timestamp (0..999)
|
|
200
|
+
* @param unit - normalized unit to set
|
|
201
|
+
* @param values - value to set (or values, if applicable e.g. for year)
|
|
202
|
+
* @returns literal object with year, month etc. after setting the new value(s)
|
|
203
|
+
*/
|
|
204
|
+
function calculateBaseComponentsForSet(dateComponents, currentMs, unit, values) {
|
|
205
|
+
let year = dateComponents[0];
|
|
206
|
+
let month = dateComponents[1] - 1;
|
|
207
|
+
let day = dateComponents[2];
|
|
208
|
+
let hour = dateComponents[3];
|
|
209
|
+
let minute = dateComponents[4];
|
|
210
|
+
let second = dateComponents[5];
|
|
211
|
+
let ms = currentMs;
|
|
212
|
+
const mainValue = values[0];
|
|
213
|
+
if (unit === constants_default.YEAR) {
|
|
214
|
+
year = mainValue;
|
|
215
|
+
if (values.length > 1) month = values[1];
|
|
216
|
+
if (values.length > 2) day = values[2];
|
|
217
|
+
} else if (unit === constants_default.MONTH) {
|
|
218
|
+
month = mainValue;
|
|
219
|
+
if (values.length > 1) day = values[1];
|
|
220
|
+
} else if (unit === constants_default.DAY) {
|
|
221
|
+
const currentWeekday = dateComponents[6];
|
|
222
|
+
day += mainValue - currentWeekday;
|
|
223
|
+
} else if (unit === constants_default.DAY_OF_MONTH) day = mainValue;
|
|
224
|
+
else if (unit === constants_default.HOUR) hour = mainValue;
|
|
225
|
+
else if (unit === constants_default.MIN) minute = mainValue;
|
|
226
|
+
else if (unit === constants_default.SECOND) second = mainValue;
|
|
227
|
+
else if (unit === constants_default.MS) ms = mainValue;
|
|
228
|
+
if (unit === constants_default.YEAR || unit === constants_default.MONTH) {
|
|
229
|
+
const lastDay = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
|
|
230
|
+
if (day > lastDay) day = lastDay;
|
|
231
|
+
}
|
|
232
|
+
let valuesIndex = 1;
|
|
233
|
+
if (unit === constants_default.HOUR && values.length > valuesIndex) minute = values[valuesIndex++];
|
|
234
|
+
if ((unit === constants_default.HOUR || unit === constants_default.MIN) && values.length > valuesIndex) second = values[valuesIndex++];
|
|
235
|
+
if ((unit === constants_default.HOUR || unit === constants_default.MIN || unit === constants_default.SECOND) && values.length > valuesIndex) ms = values[valuesIndex++];
|
|
236
|
+
return {
|
|
237
|
+
year,
|
|
238
|
+
month,
|
|
239
|
+
day,
|
|
240
|
+
hour,
|
|
241
|
+
minute,
|
|
242
|
+
second,
|
|
243
|
+
ms
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Gets the timezone of the given date formatted in the short form (e.g. 'PST')
|
|
248
|
+
* @param sourceDate - date to format the timezone for
|
|
249
|
+
* @returns the short form of the timezone of the given sourceDate
|
|
250
|
+
*/
|
|
251
|
+
function formatTimezoneShort(sourceDate) {
|
|
252
|
+
const timezone = sourceDate.tz();
|
|
253
|
+
const localeName = sourceDate.locale?.() ?? esday.locale?.();
|
|
254
|
+
return timestampToTimezoneName(sourceDate.valueOf(), timezone, localeName);
|
|
255
|
+
}
|
|
256
|
+
const timezonePLugin = (_, dayClass, esdayFactory) => {
|
|
257
|
+
const noTimezone = "";
|
|
258
|
+
let defaultTimezone;
|
|
259
|
+
/**
|
|
260
|
+
* Get timezone offset for timestamp in given timezone
|
|
261
|
+
* @param timestamp - timestamp to use
|
|
262
|
+
* @param timezone - timezone to calculate offset for
|
|
263
|
+
* @returns utc offset for timestamp in given timezone
|
|
264
|
+
*/
|
|
265
|
+
const tzOffset = (timestamp, timezone) => {
|
|
266
|
+
const filled = timestampToDateTimeComponents(timestamp, timezone);
|
|
267
|
+
const utcString = `${filled[0]}-${filled[1]}-${filled[2]} ${filled[3]}:${filled[4]}:${filled[5]}:000`;
|
|
268
|
+
const utcTs = esdayFactory.utc(utcString).valueOf();
|
|
269
|
+
let timestampAsEpoch = timestamp.valueOf();
|
|
270
|
+
const msOfTimestamp = timestampAsEpoch % 1e3;
|
|
271
|
+
timestampAsEpoch -= msOfTimestamp;
|
|
272
|
+
return (utcTs - timestampAsEpoch) / 6e4;
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* Move to the earlier date in an DST overlap, if we are in an overlap. Otherwise return input date.
|
|
276
|
+
* The return value is an literal object in the form of {timestampFixed, tzOffsetFixed, isInOverlap}.
|
|
277
|
+
* @param timestampOriginal - timestamp to be fixed
|
|
278
|
+
* @param tzOffsetOriginal - tzOffset of timestampOriginal
|
|
279
|
+
* @param timezone - timezone to use
|
|
280
|
+
* @returns literal object containing fixed date (or original date, if we are not in an overlap)
|
|
281
|
+
*/
|
|
282
|
+
const fixOverlap = (timestampOriginal, tzOffsetOriginal, timezone) => {
|
|
283
|
+
let timestampFixed = timestampOriginal;
|
|
284
|
+
let tzOffsetFixed = tzOffsetOriginal;
|
|
285
|
+
let isInOverlap = false;
|
|
286
|
+
const tzOffsetPreDst = tzOffset(timestampOriginal - maxDstDiff, timezone);
|
|
287
|
+
if (tzOffsetPreDst > tzOffsetOriginal) {
|
|
288
|
+
timestampFixed = timestampOriginal - (tzOffsetPreDst - tzOffsetOriginal) * 60 * 1e3;
|
|
289
|
+
tzOffsetFixed = tzOffset(timestampFixed, timezone);
|
|
290
|
+
if (tzOffsetFixed === tzOffsetOriginal) {
|
|
291
|
+
timestampFixed = timestampOriginal;
|
|
292
|
+
tzOffsetFixed = tzOffsetOriginal;
|
|
293
|
+
} else isInOverlap = true;
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
timestampFixed,
|
|
297
|
+
tzOffsetFixed,
|
|
298
|
+
isInOverlap
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* Change the timestamp and timezone offset of a timestamp to change the timezone while keeping the time value.
|
|
303
|
+
* @param timestampOriginal - timestamp to fix the offset for, if necessary
|
|
304
|
+
* @param tzOffsetSource - tzOffset of the originalTimestamp in the source timezone
|
|
305
|
+
* @param tzOffsetTarget - tzOffset of the originalTimestamp in the target timezone
|
|
306
|
+
* @param tzTarget - timezone to use
|
|
307
|
+
* @returns array with updated timestamp and fixed offset
|
|
308
|
+
*/
|
|
309
|
+
const fixOffsetConvert = (timestampOriginal, tzOffsetSource, tzOffsetTarget, tzTarget) => {
|
|
310
|
+
const timestampGuess1 = timestampOriginal - (tzOffsetTarget - tzOffsetSource) * 60 * 1e3;
|
|
311
|
+
const tzOffsetGuess1 = tzOffset(timestampGuess1, tzTarget);
|
|
312
|
+
if (tzOffsetGuess1 === tzOffsetTarget) {
|
|
313
|
+
const { timestampFixed, tzOffsetFixed } = fixOverlap(timestampGuess1, tzOffsetGuess1, tzTarget);
|
|
314
|
+
return [timestampFixed, tzOffsetFixed];
|
|
315
|
+
}
|
|
316
|
+
const timestampGuess2 = timestampGuess1 - (tzOffsetGuess1 - tzOffsetTarget) * 60 * 1e3;
|
|
317
|
+
const tzOffsetGuess2 = tzOffset(timestampGuess2, tzTarget);
|
|
318
|
+
if (tzOffsetGuess2 === tzOffsetGuess1) return [timestampGuess2, tzOffsetGuess2];
|
|
319
|
+
else if (tzOffsetGuess1 < tzOffsetTarget) return [timestampGuess2, tzOffsetGuess2];
|
|
320
|
+
else return [timestampGuess1, tzOffsetGuess1];
|
|
321
|
+
};
|
|
322
|
+
esdayFactory.tz = (input, ...others) => {
|
|
323
|
+
let timezone = defaultTimezone;
|
|
324
|
+
if (others.length > 0) timezone = others.pop();
|
|
325
|
+
const parsedInput = esdayFactory.utc(input, ...others);
|
|
326
|
+
if (!parsedInput.isValid()) return parsedInput;
|
|
327
|
+
const offsetParsedInput = tzOffset(parsedInput.valueOf(), timezone ?? noTimezone);
|
|
328
|
+
if (convertRequired(input) || typeof input === "string" && matchContainsOffset.test(input)) return parsedInput.tz(timezone);
|
|
329
|
+
const [targetTimestamp, targetOffset] = fixOffsetConvert(parsedInput.valueOf(), 0, offsetParsedInput, timezone ?? noTimezone);
|
|
330
|
+
const result = esdayFactory.utc(targetTimestamp, ...others);
|
|
331
|
+
result["$conf"].utcOffset = targetOffset;
|
|
332
|
+
result["$conf"].localOffset = -1 * result.toDate().getTimezoneOffset();
|
|
333
|
+
result["$conf"].utc = targetOffset === 0;
|
|
334
|
+
if (result["$conf"].localeName !== void 0 && parsedInput["$conf"].localeName !== void 0) result["$conf"].localeName = parsedInput["$conf"].localeName;
|
|
335
|
+
result["$conf"].timezone = timezone;
|
|
336
|
+
return result;
|
|
337
|
+
};
|
|
338
|
+
esdayFactory.tz.guess = () => Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
339
|
+
esdayFactory.tz.setDefault = (timezone) => {
|
|
340
|
+
defaultTimezone = timezone;
|
|
341
|
+
};
|
|
342
|
+
esdayFactory.tz.getDefault = () => {
|
|
343
|
+
return defaultTimezone;
|
|
344
|
+
};
|
|
345
|
+
const proto = dayClass.prototype;
|
|
346
|
+
proto.tz = function(timezone, keepLocalTime) {
|
|
347
|
+
if (timezone === void 0) return this["$conf"].timezone;
|
|
348
|
+
const result = this.clone();
|
|
349
|
+
const tzOffsetTarget = tzOffset(this.valueOf(), timezone);
|
|
350
|
+
const localOffset = -1 * this.toDate().getTimezoneOffset();
|
|
351
|
+
result["$conf"].localOffset = localOffset;
|
|
352
|
+
result["$conf"].utcOffset = tzOffsetTarget;
|
|
353
|
+
result["$conf"].utc = tzOffsetTarget === 0;
|
|
354
|
+
result["$conf"].timezone = timezone;
|
|
355
|
+
if (keepLocalTime) {
|
|
356
|
+
const timestampSource = result.valueOf();
|
|
357
|
+
let tzOffsetSource = 0;
|
|
358
|
+
if (!this["$conf"].utc) tzOffsetSource = this["$conf"].timezone ? Number(this["$conf"].utcOffset) : localOffset;
|
|
359
|
+
const [timestampFixed, tzOffsetFixed] = fixOffsetConvert(timestampSource, tzOffsetSource, tzOffsetTarget, timezone);
|
|
360
|
+
result["$conf"].utcOffset = tzOffsetFixed;
|
|
361
|
+
result["$conf"].utc = tzOffsetFixed === 0;
|
|
362
|
+
if (timestampSource !== timestampFixed) result.$d = new Date(timestampFixed);
|
|
363
|
+
}
|
|
364
|
+
return result;
|
|
365
|
+
};
|
|
366
|
+
const oldValueOf = proto.valueOf;
|
|
367
|
+
proto.valueOf = function() {
|
|
368
|
+
if (this["$conf"]?.timezone) return this.$d.valueOf();
|
|
369
|
+
return oldValueOf.call(this);
|
|
370
|
+
};
|
|
371
|
+
const oldGet = proto.get;
|
|
372
|
+
proto.get = function(unit) {
|
|
373
|
+
const normalizedUnit = normalizeUnitWithPlurals(unit);
|
|
374
|
+
if (normalizedUnit === constants_default.QUARTER || normalizedUnit === constants_default.WEEK || normalizedUnit === constants_default.ISOWEEK || this["$conf"]?.utc) return oldGet.call(this, unit);
|
|
375
|
+
if (this["$conf"]?.timezone) {
|
|
376
|
+
const timezone = this["$conf"].timezone;
|
|
377
|
+
const dateComponents = timestampToDateTimeComponents(this.valueOf(), timezone);
|
|
378
|
+
if (normalizedUnit === constants_default.MS) return this["$d"].getUTCMilliseconds();
|
|
379
|
+
else if (normalizedUnit === constants_default.MONTH) return dateComponents[1] - 1;
|
|
380
|
+
else if (normalizedUnit === constants_default.DAY) return dateComponents[6];
|
|
381
|
+
else return dateComponents[UNIT_ARRAY_MAP[normalizedUnit]];
|
|
382
|
+
}
|
|
383
|
+
return oldGet.call(this, unit);
|
|
384
|
+
};
|
|
385
|
+
const old$set = proto["$set"];
|
|
386
|
+
proto["$set"] = function(unit, values) {
|
|
387
|
+
if (isObject(unit)) return old$set.call(this, unit, values);
|
|
388
|
+
const timezone = this["$conf"]?.timezone;
|
|
389
|
+
if (!timezone) return old$set.call(this, unit, values);
|
|
390
|
+
const normalizedUnit = normalizeUnitWithPlurals(unit);
|
|
391
|
+
const { year, month, day, hour, minute, second, ms } = calculateBaseComponentsForSet(timestampToDateTimeComponents(this.valueOf(), timezone), this.valueOf() % 1e3, normalizedUnit, values);
|
|
392
|
+
const utcAsLocal = Date.UTC(year, month, day, hour, minute, second, ms);
|
|
393
|
+
const [timestampFixed, tzOffsetFixed] = fixOffsetConvert(utcAsLocal, 0, tzOffset(utcAsLocal, timezone), timezone);
|
|
394
|
+
this.$d = new Date(timestampFixed);
|
|
395
|
+
this["$conf"].utcOffset = tzOffsetFixed;
|
|
396
|
+
this["$conf"].localOffset = -1 * this.$d.getTimezoneOffset();
|
|
397
|
+
this["$conf"].utc = tzOffsetFixed === 0;
|
|
398
|
+
return this;
|
|
399
|
+
};
|
|
400
|
+
const oldStartOf = dayClass.prototype.startOf;
|
|
401
|
+
proto.startOf = function(units) {
|
|
402
|
+
if (!this["$conf"]?.["timezone"]) return oldStartOf.call(this, units);
|
|
403
|
+
const withoutTz = esdayFactory(this.format("YYYY-MM-DD HH:mm:ss:SSS"));
|
|
404
|
+
return oldStartOf.call(withoutTz, units).tz(this["$conf"]["timezone"], true);
|
|
405
|
+
};
|
|
406
|
+
const oldEndOf = dayClass.prototype.endOf;
|
|
407
|
+
proto.endOf = function(units) {
|
|
408
|
+
if (!this["$conf"]?.["timezone"]) return oldEndOf.call(this, units);
|
|
409
|
+
const withoutTz = esdayFactory(this.format("YYYY-MM-DD HH:mm:ss:SSS"));
|
|
410
|
+
return oldEndOf.call(withoutTz, units).tz(this["$conf"]["timezone"], true);
|
|
411
|
+
};
|
|
412
|
+
const oldAdd = proto.add;
|
|
413
|
+
proto.add = function(value, unit) {
|
|
414
|
+
if (isObject(value) || unit === void 0) return oldAdd.call(this, value, unit);
|
|
415
|
+
const newValue = oldAdd.call(this, value, unit);
|
|
416
|
+
if (!this["$conf"].timezone) return newValue;
|
|
417
|
+
const timezone = this["$conf"]["timezone"];
|
|
418
|
+
const timestamp = newValue.valueOf();
|
|
419
|
+
const tzOldOffset = tzOffset(timestamp, timezone);
|
|
420
|
+
const normalizedUnit = normalizeUnitWithPlurals(unit);
|
|
421
|
+
const timeUnits = [
|
|
422
|
+
constants_default.HOUR,
|
|
423
|
+
constants_default.MIN,
|
|
424
|
+
constants_default.SECOND,
|
|
425
|
+
constants_default.MS
|
|
426
|
+
];
|
|
427
|
+
const { isInOverlap } = fixOverlap(timestamp, tzOldOffset, timezone);
|
|
428
|
+
if (timeUnits.includes(normalizedUnit) && isInOverlap) {
|
|
429
|
+
newValue["$conf"].utcOffset = tzOldOffset;
|
|
430
|
+
newValue["$conf"].utc = tzOldOffset === 0;
|
|
431
|
+
return newValue;
|
|
432
|
+
}
|
|
433
|
+
const [timestampFixed, tzOffsetFixed] = fixOffsetConvert(timestamp, tzOldOffset, tzOffset(timestamp, timezone), timezone);
|
|
434
|
+
newValue.$d = new Date(timestampFixed);
|
|
435
|
+
newValue["$conf"].utcOffset = tzOffsetFixed;
|
|
436
|
+
newValue["$conf"].localOffset = -1 * newValue.$d.getTimezoneOffset();
|
|
437
|
+
newValue["$conf"].utc = tzOffsetFixed === 0;
|
|
438
|
+
return newValue;
|
|
439
|
+
};
|
|
440
|
+
const oldSubtract = proto.subtract;
|
|
441
|
+
proto.subtract = function(value, unit) {
|
|
442
|
+
if (isObject(value) || unit === void 0) return oldSubtract.call(this, value, unit);
|
|
443
|
+
if (this["$conf"].timezone) return proto.add.call(this, -value, unit);
|
|
444
|
+
return oldSubtract.call(this, value, unit);
|
|
445
|
+
};
|
|
446
|
+
const additionalTokens = {
|
|
447
|
+
z: formatTimezoneShort,
|
|
448
|
+
zz: formatTimezoneShort
|
|
449
|
+
};
|
|
450
|
+
esdayFactory.addFormatTokenDefinitions(additionalTokens);
|
|
451
|
+
};
|
|
452
|
+
export { timezonePLugin as t };
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { A as UnitMs, E as UnitIsoWeek, F as UnitTypeCore, I as UnitTypeGetSet, M as UnitSecond, N as UnitType, O as UnitMin, P as UnitTypeAddSub, R as UnitWeek, S as UnitDate, T as UnitHour, _ as LongUnit, a as EsDayFactory, b as PrettyUnitFromPlurals, c as FormattingTokenDefinitions, d as ParsingObjectPlurals, f as ParsingObjectShort, g as SimpleType, h as SimpleObject, i as DateType, j as UnitQuarter, k as UnitMonth, l as ParsingObject, m as UnitsObjectTypeSet, n as ConfigurationObject, o as EsDayFactoryParserFn, p as UnitsObjectTypeAddSub, r as DateFromDateComponents, s as EsDayPlugin, t as EsDay, u as ParsingObjectLong, v as PrettyUnitAsPlural, w as UnitDay, x as ShortUnit, y as PrettyUnitAsSingular, z as UnitYear } from "./chunks/
|
|
2
|
-
import { t as esday } from "./chunks/
|
|
1
|
+
import { A as UnitMs, E as UnitIsoWeek, F as UnitTypeCore, I as UnitTypeGetSet, M as UnitSecond, N as UnitType, O as UnitMin, P as UnitTypeAddSub, R as UnitWeek, S as UnitDate, T as UnitHour, _ as LongUnit, a as EsDayFactory, b as PrettyUnitFromPlurals, c as FormattingTokenDefinitions, d as ParsingObjectPlurals, f as ParsingObjectShort, g as SimpleType, h as SimpleObject, i as DateType, j as UnitQuarter, k as UnitMonth, l as ParsingObject, m as UnitsObjectTypeSet, n as ConfigurationObject, o as EsDayFactoryParserFn, p as UnitsObjectTypeAddSub, r as DateFromDateComponents, s as EsDayPlugin, t as EsDay, u as ParsingObjectLong, v as PrettyUnitAsPlural, w as UnitDay, x as ShortUnit, y as PrettyUnitAsSingular, z as UnitYear } from "./chunks/MfctHIHI.js";
|
|
2
|
+
import { t as esday } from "./chunks/DBmUXISx.js";
|
|
3
3
|
export { ConfigurationObject, DateFromDateComponents, DateType, EsDay, EsDayFactory, EsDayFactoryParserFn, EsDayPlugin, FormattingTokenDefinitions, type LongUnit, ParsingObject, ParsingObjectLong, ParsingObjectPlurals, ParsingObjectShort, type PrettyUnitAsPlural, type PrettyUnitAsSingular, type PrettyUnitFromPlurals, type ShortUnit, type SimpleObject, type SimpleType, type UnitDate, type UnitDay, type UnitHour, type UnitIsoWeek, type UnitMin, type UnitMonth, type UnitMs, type UnitQuarter, type UnitSecond, type UnitType, type UnitTypeAddSub, type UnitTypeCore, type UnitTypeGetSet, type UnitWeek, type UnitYear, UnitsObjectTypeAddSub, UnitsObjectTypeSet, esday };
|
package/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { EsDay, esday };
|
|
1
|
+
export { n as EsDay, t as esday } from "./chunks/Bk-WlP29.js";
|
package/locales/af.d.ts
CHANGED
package/locales/af.js
CHANGED
package/locales/am.d.ts
CHANGED
package/locales/am.js
CHANGED
package/locales/ar-dz.d.ts
CHANGED
package/locales/ar-dz.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import locale from "./ar.js";
|
|
2
2
|
import { cloneLocale, setLocaleProperty } from "../plugins/locale/index.js";
|
|
3
|
-
|
|
3
|
+
// src/locales/ar-dz.ts
|
|
4
4
|
/**
|
|
5
5
|
* Arabic (Algeria) [ar-DZ]
|
|
6
6
|
*/
|
|
@@ -24,5 +24,4 @@ setLocaleProperty(localeArDz, "months", months);
|
|
|
24
24
|
setLocaleProperty(localeArDz, "monthsShort", months);
|
|
25
25
|
setLocaleProperty(localeArDz, "weekStart", 0);
|
|
26
26
|
setLocaleProperty(localeArDz, "yearStart", 4);
|
|
27
|
-
//#endregion
|
|
28
27
|
export { localeArDz as default };
|
package/locales/ar-iq.d.ts
CHANGED
package/locales/ar-iq.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import locale from "./ar.js";
|
|
2
2
|
import { cloneLocale, setLocaleProperty } from "../plugins/locale/index.js";
|
|
3
|
-
|
|
3
|
+
// src/locales/ar-iq.ts
|
|
4
4
|
/**
|
|
5
5
|
* Arabic (Iraq) [ar-IQ]
|
|
6
6
|
*/
|
|
7
7
|
const localeArIq = cloneLocale(locale);
|
|
8
8
|
setLocaleProperty(localeArIq, "name", "ar-IQ");
|
|
9
|
-
//#endregion
|
|
10
9
|
export { localeArIq as default };
|
package/locales/ar-kw.d.ts
CHANGED
package/locales/ar-kw.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import locale from "./ar.js";
|
|
2
2
|
import { cloneLocale, setLocaleProperty } from "../plugins/locale/index.js";
|
|
3
|
-
|
|
3
|
+
// src/locales/ar-kw.ts
|
|
4
4
|
/**
|
|
5
5
|
* Arabic (Kuwait) [ar-KW]
|
|
6
6
|
*/
|
|
@@ -20,5 +20,4 @@ setLocaleProperty(localeArKw, "name", "ar-KW");
|
|
|
20
20
|
setLocaleProperty(localeArKw, "weekStart", 0);
|
|
21
21
|
setLocaleProperty(localeArKw, "formats", formats);
|
|
22
22
|
setLocaleProperty(localeArKw, "calendar", calendar);
|
|
23
|
-
//#endregion
|
|
24
23
|
export { localeArKw as default };
|
package/locales/ar-ly.d.ts
CHANGED
package/locales/ar-ly.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import locale from "./ar.js";
|
|
2
2
|
import { cloneLocale, setLocaleProperty } from "../plugins/locale/index.js";
|
|
3
|
-
|
|
3
|
+
// src/locales/ar-ly.ts
|
|
4
4
|
/**
|
|
5
5
|
* Arabic (Lybia) [ar-LY]
|
|
6
6
|
*/
|
|
7
7
|
const localeArLy = cloneLocale(locale);
|
|
8
8
|
setLocaleProperty(localeArLy, "name", "ar-LY");
|
|
9
|
-
//#endregion
|
|
10
9
|
export { localeArLy as default };
|