@ui5/webcomponents-localization 0.0.0-dff5837d7 → 0.0.0-e55c2cec6
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/.eslintignore +1 -0
- package/CHANGELOG.md +260 -0
- package/README.md +36 -6
- package/dist/Assets-static.d.ts +1 -0
- package/dist/Assets-static.js +3 -0
- package/dist/Assets-static.js.map +1 -0
- package/dist/Assets.d.ts +1 -0
- package/dist/Assets.js +1 -0
- package/dist/Assets.js.map +1 -0
- package/dist/DateFormat.d.ts +6 -0
- package/dist/DateFormat.js +6 -2
- package/dist/DateFormat.js.map +1 -0
- package/dist/LocaleData.d.ts +6 -0
- package/dist/LocaleData.js +6 -2
- package/dist/LocaleData.js.map +1 -0
- package/dist/dates/CalendarDate.d.ts +41 -0
- package/dist/dates/CalendarDate.js +170 -181
- package/dist/dates/CalendarDate.js.map +1 -0
- package/dist/dates/ExtremeDates.d.ts +5 -0
- package/dist/dates/ExtremeDates.js +29 -0
- package/dist/dates/ExtremeDates.js.map +1 -0
- package/dist/dates/UniversalDate.d.ts +46 -0
- package/dist/dates/UniversalDate.js +5 -0
- package/dist/dates/UniversalDate.js.map +1 -0
- package/dist/dates/calculateWeekNumber.d.ts +4 -0
- package/dist/dates/calculateWeekNumber.js +42 -48
- package/dist/dates/calculateWeekNumber.js.map +1 -0
- package/dist/dates/convertMonthNumbersToMonthNames.d.ts +16 -0
- package/dist/dates/convertMonthNumbersToMonthNames.js +30 -0
- package/dist/dates/convertMonthNumbersToMonthNames.js.map +1 -0
- package/dist/dates/getDaysInMonth.d.ts +3 -0
- package/dist/dates/getDaysInMonth.js +10 -0
- package/dist/dates/getDaysInMonth.js.map +1 -0
- package/dist/dates/getRoundedTimestamp.d.ts +7 -0
- package/dist/dates/getRoundedTimestamp.js +14 -0
- package/dist/dates/getRoundedTimestamp.js.map +1 -0
- package/dist/dates/getTodayUTCTimestamp.d.ts +7 -0
- package/dist/dates/getTodayUTCTimestamp.js +8 -0
- package/dist/dates/getTodayUTCTimestamp.js.map +1 -0
- package/dist/dates/modifyDateBy.d.ts +13 -0
- package/dist/dates/modifyDateBy.js +40 -0
- package/dist/dates/modifyDateBy.js.map +1 -0
- package/dist/dates/transformDateToSecondaryType.d.ts +7 -0
- package/dist/dates/transformDateToSecondaryType.js +17 -0
- package/dist/dates/transformDateToSecondaryType.js.map +1 -0
- package/{src/features/calendar/Buddhist.js → dist/features/calendar/Buddhist.d.ts} +0 -0
- package/dist/features/calendar/Buddhist.js +1 -0
- package/dist/features/calendar/Buddhist.js.map +1 -0
- package/{src/features/calendar/Gregorian.js → dist/features/calendar/Gregorian.d.ts} +0 -0
- package/dist/features/calendar/Gregorian.js +1 -0
- package/dist/features/calendar/Gregorian.js.map +1 -0
- package/{src/features/calendar/Islamic.js → dist/features/calendar/Islamic.d.ts} +0 -0
- package/dist/features/calendar/Islamic.js +1 -0
- package/dist/features/calendar/Islamic.js.map +1 -0
- package/{src/features/calendar/Japanese.js → dist/features/calendar/Japanese.d.ts} +0 -0
- package/dist/features/calendar/Japanese.js +1 -0
- package/dist/features/calendar/Japanese.js.map +1 -0
- package/{src/features/calendar/Persian.js → dist/features/calendar/Persian.d.ts} +0 -0
- package/dist/features/calendar/Persian.js +1 -0
- package/dist/features/calendar/Persian.js.map +1 -0
- package/dist/generated/assets/cldr/ar.json +803 -3
- package/dist/generated/assets/cldr/ar_EG.json +803 -3
- package/dist/generated/assets/cldr/ar_SA.json +803 -3
- package/dist/generated/assets/cldr/bg.json +768 -3
- package/dist/generated/assets/cldr/ca.json +802 -3
- package/dist/generated/assets/cldr/cs.json +801 -3
- package/dist/generated/assets/cldr/cy.json +6614 -0
- package/dist/generated/assets/cldr/da.json +768 -3
- package/dist/generated/assets/cldr/de.json +802 -3
- package/dist/generated/assets/cldr/de_AT.json +802 -3
- package/dist/generated/assets/cldr/de_CH.json +802 -3
- package/dist/generated/assets/cldr/el.json +701 -3
- package/dist/generated/assets/cldr/el_CY.json +701 -3
- package/dist/generated/assets/cldr/en.json +767 -3
- package/dist/generated/assets/cldr/en_AU.json +768 -4
- package/dist/generated/assets/cldr/en_GB.json +767 -3
- package/dist/generated/assets/cldr/en_HK.json +767 -3
- package/dist/generated/assets/cldr/en_IE.json +767 -3
- package/dist/generated/assets/cldr/en_IN.json +767 -3
- package/dist/generated/assets/cldr/en_NZ.json +767 -3
- package/dist/generated/assets/cldr/en_PG.json +767 -3
- package/dist/generated/assets/cldr/en_SG.json +767 -3
- package/dist/generated/assets/cldr/en_ZA.json +767 -3
- package/dist/generated/assets/cldr/es.json +734 -3
- package/dist/generated/assets/cldr/es_AR.json +734 -3
- package/dist/generated/assets/cldr/es_BO.json +737 -6
- package/dist/generated/assets/cldr/es_CL.json +737 -6
- package/dist/generated/assets/cldr/es_CO.json +734 -3
- package/dist/generated/assets/cldr/es_MX.json +737 -6
- package/dist/generated/assets/cldr/es_PE.json +737 -6
- package/dist/generated/assets/cldr/es_UY.json +737 -6
- package/dist/generated/assets/cldr/es_VE.json +736 -5
- package/dist/generated/assets/cldr/et.json +767 -3
- package/dist/generated/assets/cldr/fa.json +769 -3
- package/dist/generated/assets/cldr/fi.json +801 -3
- package/dist/generated/assets/cldr/fr.json +767 -3
- package/dist/generated/assets/cldr/fr_BE.json +767 -3
- package/dist/generated/assets/cldr/fr_CA.json +767 -3
- package/dist/generated/assets/cldr/fr_CH.json +767 -3
- package/dist/generated/assets/cldr/fr_LU.json +767 -3
- package/dist/generated/assets/cldr/he.json +802 -3
- package/dist/generated/assets/cldr/hi.json +734 -3
- package/dist/generated/assets/cldr/hr.json +767 -3
- package/dist/generated/assets/cldr/hu.json +835 -3
- package/dist/generated/assets/cldr/id.json +767 -3
- package/dist/generated/assets/cldr/it.json +767 -3
- package/dist/generated/assets/cldr/it_CH.json +767 -3
- package/dist/generated/assets/cldr/ja.json +801 -3
- package/dist/generated/assets/cldr/kk.json +767 -3
- package/dist/generated/assets/cldr/ko.json +801 -3
- package/dist/generated/assets/cldr/lt.json +767 -3
- package/dist/generated/assets/cldr/lv.json +767 -3
- package/dist/generated/assets/cldr/ms.json +735 -3
- package/dist/generated/assets/cldr/nb.json +768 -3
- package/dist/generated/assets/cldr/nl.json +734 -3
- package/dist/generated/assets/cldr/nl_BE.json +734 -3
- package/dist/generated/assets/cldr/pl.json +801 -3
- package/dist/generated/assets/cldr/pt.json +767 -3
- package/dist/generated/assets/cldr/pt_PT.json +767 -3
- package/dist/generated/assets/cldr/ro.json +767 -3
- package/dist/generated/assets/cldr/ru.json +767 -3
- package/dist/generated/assets/cldr/ru_UA.json +767 -3
- package/dist/generated/assets/cldr/sk.json +801 -3
- package/dist/generated/assets/cldr/sl.json +801 -3
- package/dist/generated/assets/cldr/sr.json +767 -3
- package/dist/generated/assets/cldr/sr_Latn.json +5891 -0
- package/dist/generated/assets/cldr/sv.json +768 -3
- package/dist/generated/assets/cldr/th.json +835 -3
- package/dist/generated/assets/cldr/tr.json +835 -3
- package/dist/generated/assets/cldr/uk.json +767 -3
- package/dist/generated/assets/cldr/vi.json +767 -3
- package/dist/generated/assets/cldr/zh_CN.json +803 -4
- package/dist/generated/assets/cldr/zh_HK.json +803 -4
- package/dist/generated/assets/cldr/zh_SG.json +803 -4
- package/dist/generated/assets/cldr/zh_TW.json +802 -3
- package/dist/generated/json-imports/LocaleData-static.js +90 -0
- package/dist/generated/json-imports/LocaleData.js +88 -91
- package/dist/getCachedLocaleDataInstance.d.ts +4 -0
- package/dist/getCachedLocaleDataInstance.js +10 -0
- package/dist/getCachedLocaleDataInstance.js.map +1 -0
- package/dist/locale/getLocaleData.d.ts +11 -0
- package/dist/locale/getLocaleData.js +13 -17
- package/dist/locale/getLocaleData.js.map +1 -0
- package/dist/sap/base/Log.js +28 -37
- package/dist/sap/base/assert.js +5 -10
- package/dist/sap/base/util/LoaderExtensions.d.ts +4 -0
- package/dist/sap/base/util/LoaderExtensions.js +11 -4
- package/dist/sap/base/util/LoaderExtensions.js.map +1 -0
- package/dist/sap/base/util/array/uniqueSort.js +7 -7
- package/dist/sap/base/util/deepEqual.js +1 -5
- package/dist/sap/ui/base/Interface.js +3 -5
- package/dist/sap/ui/base/Metadata.js +1 -3
- package/dist/sap/ui/base/Object.js +26 -2
- package/dist/sap/ui/core/Configuration.d.ts +17 -0
- package/dist/sap/ui/core/Configuration.js +20 -0
- package/dist/sap/ui/core/Configuration.js.map +1 -0
- package/dist/sap/ui/core/Core.d.ts +26 -0
- package/dist/sap/ui/core/Core.js +7 -32
- package/dist/sap/ui/core/Core.js.map +1 -0
- package/dist/sap/ui/core/FormatSettings.d.ts +10 -0
- package/dist/sap/ui/core/FormatSettings.js +13 -0
- package/dist/sap/ui/core/FormatSettings.js.map +1 -0
- package/dist/sap/ui/core/Locale.js +70 -31
- package/dist/sap/ui/core/LocaleData.js +133 -1506
- package/dist/sap/ui/core/date/Buddhist.js +0 -6
- package/dist/sap/ui/core/date/CalendarUtils.js +36 -0
- package/dist/sap/ui/core/date/CalendarWeekNumbering.js +7 -0
- package/dist/sap/ui/core/date/Islamic.js +3 -3
- package/dist/sap/ui/core/date/Japanese.js +4 -4
- package/dist/sap/ui/core/date/UniversalDate.js +82 -23
- package/dist/sap/ui/core/format/DateFormat.js +530 -222
- package/dist/sap/ui/core/format/TimezoneUtil.js +94 -0
- package/package-scripts.js +14 -7
- package/package.json +13 -14
- package/src/Assets-static.ts +2 -0
- package/src/{Assets.js → Assets.ts} +0 -0
- package/src/DateFormat.ts +8 -0
- package/src/LocaleData.ts +8 -0
- package/src/dates/{CalendarDate.js → CalendarDate.ts} +64 -35
- package/src/dates/ExtremeDates.ts +40 -0
- package/src/dates/UniversalDate.ts +51 -0
- package/src/dates/{calculateWeekNumber.js → calculateWeekNumber.ts} +5 -3
- package/src/dates/convertMonthNumbersToMonthNames.ts +34 -0
- package/src/dates/getDaysInMonth.ts +11 -0
- package/src/dates/getRoundedTimestamp.ts +14 -0
- package/src/dates/getTodayUTCTimestamp.ts +10 -0
- package/src/dates/modifyDateBy.ts +42 -0
- package/src/dates/transformDateToSecondaryType.ts +21 -0
- package/src/features/calendar/Buddhist.ts +1 -0
- package/src/features/calendar/Gregorian.ts +1 -0
- package/src/features/calendar/Islamic.ts +1 -0
- package/src/features/calendar/Japanese.ts +1 -0
- package/src/features/calendar/Persian.ts +1 -0
- package/src/getCachedLocaleDataInstance.ts +15 -0
- package/src/locale/{getLocaleData.js → getLocaleData.ts} +9 -8
- package/src/sap/base/util/LoaderExtensions.ts +17 -0
- package/src/sap/ui/core/{Core.js → Configuration.ts} +5 -21
- package/src/sap/ui/core/Core.ts +15 -0
- package/src/sap/ui/core/FormatSettings.ts +15 -0
- package/tsconfig.json +13 -0
- package/used-modules.txt +4 -1
- package/src/DateFormat.js +0 -3
- package/src/LocaleData.js +0 -3
- package/src/sap/base/util/LoaderExtensions.js +0 -7
@@ -0,0 +1,94 @@
|
|
1
|
+
var TimezoneUtil = {};
|
2
|
+
var sLocalTimezone = "";
|
3
|
+
var aSupportedTimezoneIDs;
|
4
|
+
var oIntlDateTimeFormatCache = {
|
5
|
+
_oCache: new Map(),
|
6
|
+
_iCacheLimit: 10,
|
7
|
+
get: function (sTimezone) {
|
8
|
+
var cacheEntry = this._oCache.get(sTimezone);
|
9
|
+
if (cacheEntry) {
|
10
|
+
return cacheEntry;
|
11
|
+
}
|
12
|
+
var oOptions = {
|
13
|
+
hourCycle: "h23",
|
14
|
+
hour: "2-digit",
|
15
|
+
minute: "2-digit",
|
16
|
+
second: "2-digit",
|
17
|
+
fractionalSecondDigits: 3,
|
18
|
+
day: "2-digit",
|
19
|
+
month: "2-digit",
|
20
|
+
year: "numeric",
|
21
|
+
timeZone: sTimezone,
|
22
|
+
timeZoneName: "short",
|
23
|
+
era: "narrow"
|
24
|
+
};
|
25
|
+
var oInstance = new Intl.DateTimeFormat("en-US", oOptions);
|
26
|
+
if (this._oCache.size === this._iCacheLimit) {
|
27
|
+
this._oCache = new Map();
|
28
|
+
}
|
29
|
+
this._oCache.set(sTimezone, oInstance);
|
30
|
+
return oInstance;
|
31
|
+
}
|
32
|
+
};
|
33
|
+
TimezoneUtil.isValidTimezone = function (sTimezone) {
|
34
|
+
if (!sTimezone) {
|
35
|
+
return false;
|
36
|
+
}
|
37
|
+
if (Intl.supportedValuesOf) {
|
38
|
+
try {
|
39
|
+
aSupportedTimezoneIDs = aSupportedTimezoneIDs || Intl.supportedValuesOf("timeZone");
|
40
|
+
if (aSupportedTimezoneIDs.includes(sTimezone)) {
|
41
|
+
return true;
|
42
|
+
}
|
43
|
+
} catch (oError) {
|
44
|
+
aSupportedTimezoneIDs = [];
|
45
|
+
}
|
46
|
+
}
|
47
|
+
try {
|
48
|
+
oIntlDateTimeFormatCache.get(sTimezone);
|
49
|
+
return true;
|
50
|
+
} catch (oError) {
|
51
|
+
return false;
|
52
|
+
}
|
53
|
+
};
|
54
|
+
TimezoneUtil.convertToTimezone = function (oDate, sTargetTimezone) {
|
55
|
+
var oFormatParts = this._getParts(oDate, sTargetTimezone);
|
56
|
+
return TimezoneUtil._getDateFromParts(oFormatParts);
|
57
|
+
};
|
58
|
+
TimezoneUtil._getParts = function (oDate, sTargetTimezone) {
|
59
|
+
var oIntlDate = oIntlDateTimeFormatCache.get(sTargetTimezone);
|
60
|
+
var oParts = oIntlDate.formatToParts(new Date(oDate.getTime()));
|
61
|
+
var oDateParts = Object.create(null);
|
62
|
+
for (var sKey in oParts) {
|
63
|
+
var oPart = oParts[sKey];
|
64
|
+
if (oPart.type !== "literal") {
|
65
|
+
oDateParts[oPart.type] = oPart.value;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
return oDateParts;
|
69
|
+
};
|
70
|
+
TimezoneUtil._getDateFromParts = function (oParts) {
|
71
|
+
var oDate = new Date(0);
|
72
|
+
var iUTCYear = parseInt(oParts.year);
|
73
|
+
if (oParts.era === "B") {
|
74
|
+
iUTCYear = iUTCYear * -1 + 1;
|
75
|
+
}
|
76
|
+
oDate.setUTCFullYear(iUTCYear, parseInt(oParts.month) - 1, parseInt(oParts.day));
|
77
|
+
oDate.setUTCHours(parseInt(oParts.hour), parseInt(oParts.minute), parseInt(oParts.second), parseInt(oParts.fractionalSecond || 0));
|
78
|
+
return oDate;
|
79
|
+
};
|
80
|
+
TimezoneUtil.calculateOffset = function (oDate, sTimezoneSource) {
|
81
|
+
var oFirstGuess = this.convertToTimezone(oDate, sTimezoneSource);
|
82
|
+
var iInitialOffset = oDate.getTime() - oFirstGuess.getTime();
|
83
|
+
var oDateSource = new Date(oDate.getTime() + iInitialOffset);
|
84
|
+
var oDateTarget = this.convertToTimezone(oDateSource, sTimezoneSource);
|
85
|
+
return (oDateSource.getTime() - oDateTarget.getTime()) / 1000;
|
86
|
+
};
|
87
|
+
TimezoneUtil.getLocalTimezone = function () {
|
88
|
+
if (sLocalTimezone) {
|
89
|
+
return sLocalTimezone;
|
90
|
+
}
|
91
|
+
sLocalTimezone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
92
|
+
return sLocalTimezone;
|
93
|
+
};
|
94
|
+
export default TimezoneUtil;
|
package/package-scripts.js
CHANGED
@@ -1,25 +1,32 @@
|
|
1
|
+
const resolve = require("resolve");
|
2
|
+
const copyUsedModules = resolve.sync("@ui5/webcomponents-tools/lib/copy-list/index.js");
|
3
|
+
const replaceGlobalCore = resolve.sync("@ui5/webcomponents-tools/lib/replace-global-core/index.js");
|
4
|
+
const esmAbsToRel = resolve.sync("@ui5/webcomponents-tools/lib/esm-abs-to-rel/index.js");
|
5
|
+
|
1
6
|
const scripts = {
|
2
7
|
clean: "rimraf dist",
|
3
8
|
lint: "eslint . --config config/.eslintrc.js",
|
4
9
|
build: {
|
5
|
-
"default": "
|
6
|
-
all: "nps lint clean copy.used-modules copy.cldr copy.overlay build.replace-amd build.replace-export-true build.replace-export-false build.amd-to-es6 build.replace-global-core-usage build.esm-abs-to-rel build.jsonImports copy.src",
|
10
|
+
"default": "nps lint clean copy.used-modules copy.cldr copy.overlay build.replace-amd build.replace-export-true build.replace-export-false build.amd-to-es6 build.replace-global-core-usage build.esm-abs-to-rel build.jsonImports build.typescript copy.src",
|
7
11
|
"replace-amd": "replace-in-file sap.ui.define define dist/**/*.js",
|
8
12
|
"replace-export-true": `replace-in-file ", /* bExport= */ true" "" dist/**/*.js`,
|
9
13
|
"replace-export-false": `replace-in-file ", /* bExport= */ false" "" dist/**/*.js`,
|
10
14
|
"amd-to-es6": "amdtoes6 --src=dist --replace --glob=**/*.js",
|
11
|
-
"replace-global-core-usage":
|
12
|
-
"esm-abs-to-rel":
|
13
|
-
|
15
|
+
"replace-global-core-usage": `node "${replaceGlobalCore}" dist/`,
|
16
|
+
"esm-abs-to-rel": `node "${esmAbsToRel}" dist/`,
|
17
|
+
typescript: "tsc",
|
18
|
+
jsonImports: "node ./lib/generate-json-imports/cldr.js"
|
14
19
|
},
|
20
|
+
typescript: "tsc",
|
15
21
|
copy: {
|
16
|
-
"used-modules":
|
22
|
+
"used-modules": `node "${copyUsedModules}" ./used-modules.txt dist/`,
|
17
23
|
cldr: `copy-and-watch "../../node_modules/@openui5/sap.ui.core/src/sap/ui/core/cldr/*.json" dist/generated/assets/cldr/`,
|
18
24
|
overlay: `copy-and-watch "overlay/**/*.js" dist/`,
|
19
25
|
src: `copy-and-watch "src/**/*.js" dist/`,
|
20
26
|
},
|
21
27
|
watch: {
|
22
|
-
default: 'nps watch.src',
|
28
|
+
default: 'concurrently "nps watch.src" "nps watch.typescript" ',
|
29
|
+
typescript: "tsc --watch",
|
23
30
|
src: `nps "copy.src --watch --skip-initial-copy"`,
|
24
31
|
},
|
25
32
|
start: "nps watch",
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ui5/webcomponents-localization",
|
3
|
-
"version": "0.0.0-
|
3
|
+
"version": "0.0.0-e55c2cec6",
|
4
4
|
"description": "Localization for UI5 Web Components",
|
5
5
|
"author": "SAP SE (https://www.sap.com)",
|
6
6
|
"license": "Apache-2.0",
|
@@ -14,6 +14,11 @@
|
|
14
14
|
"url": "https://github.com/SAP/ui5-webcomponents.git",
|
15
15
|
"directory": "packages/localization"
|
16
16
|
},
|
17
|
+
"exports": {
|
18
|
+
"./dist/*": "./dist/*",
|
19
|
+
"./package.json": "./package.json",
|
20
|
+
"./*": "./dist/*"
|
21
|
+
},
|
17
22
|
"scripts": {
|
18
23
|
"clean": "nps clean",
|
19
24
|
"lint": "nps lint",
|
@@ -22,20 +27,14 @@
|
|
22
27
|
"prepublishOnly": "npm run clean && npm run build"
|
23
28
|
},
|
24
29
|
"devDependencies": {
|
25
|
-
"@
|
26
|
-
"@openui5
|
27
|
-
"@ui5/webcomponents-tools": "0.0.0-
|
28
|
-
"chromedriver": "
|
29
|
-
"
|
30
|
-
"
|
31
|
-
"esprima": "^4.0.1",
|
32
|
-
"glob": "^7.1.3",
|
33
|
-
"mkdirp": "^0.5.1",
|
34
|
-
"path-exists-cli": "^1.0.0",
|
35
|
-
"replace-in-file": "^3.4.2",
|
36
|
-
"rimraf": "^2.6.2"
|
30
|
+
"@openui5/sap.ui.core": "1.109.0",
|
31
|
+
"@types/openui5": "^1.108.0",
|
32
|
+
"@ui5/webcomponents-tools": "0.0.0-e55c2cec6",
|
33
|
+
"chromedriver": "108.0.0",
|
34
|
+
"mkdirp": "^1.0.4",
|
35
|
+
"resolve": "^1.20.0"
|
37
36
|
},
|
38
37
|
"dependencies": {
|
39
|
-
"@ui5/webcomponents-base": "0.0.0-
|
38
|
+
"@ui5/webcomponents-base": "0.0.0-e55c2cec6"
|
40
39
|
}
|
41
40
|
}
|
File without changes
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type DateFormatT from "sap/ui/core/format/DateFormat";
|
2
|
+
// @ts-ignore
|
3
|
+
import DateFormatNative from "./sap/ui/core/format/DateFormat.js";
|
4
|
+
|
5
|
+
const DateFormatWrapped = DateFormatNative as typeof DateFormatT;
|
6
|
+
class DateFormat extends DateFormatWrapped {}
|
7
|
+
|
8
|
+
export default DateFormat;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type LocaleDataOpenUI5T from "sap/ui/core/LocaleData";
|
2
|
+
// @ts-ignore
|
3
|
+
import LocaleDataNative from "./sap/ui/core/LocaleData.js";
|
4
|
+
|
5
|
+
const LocaleDataWrapped = LocaleDataNative as typeof LocaleDataOpenUI5T;
|
6
|
+
class LocaleData extends LocaleDataWrapped {}
|
7
|
+
|
8
|
+
export default LocaleData;
|
@@ -1,23 +1,26 @@
|
|
1
|
-
import
|
1
|
+
import type CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
|
2
|
+
import UniversalDate from "./UniversalDate.js";
|
2
3
|
|
3
4
|
class CalendarDate {
|
4
|
-
|
5
|
+
_oUDate!: Date | UniversalDate;
|
6
|
+
|
7
|
+
constructor(year?: number | CalendarDate, month?: number | string, date?: number, calendarType?: string) { // eslint-disable-line
|
5
8
|
let aArgs = arguments, // eslint-disable-line
|
6
|
-
oJSDate,
|
7
|
-
oNow,
|
8
|
-
sCalendarType;
|
9
|
+
oJSDate: Date,
|
10
|
+
oNow: Date,
|
11
|
+
sCalendarType!: CalendarType;
|
9
12
|
|
10
13
|
switch (aArgs.length) {
|
11
14
|
case 0: // defaults to the current date
|
12
15
|
oNow = new Date();
|
13
|
-
return this.constructor(oNow.getFullYear(), oNow.getMonth(), oNow.getDate());
|
16
|
+
return (this.constructor(oNow.getFullYear(), oNow.getMonth(), oNow.getDate()) as CalendarDate);
|
14
17
|
|
15
18
|
case 1: // CalendarDate
|
16
19
|
case 2: // CalendarDate, sCalendarType
|
17
20
|
if (!(aArgs[0] instanceof CalendarDate)) {
|
18
|
-
throw new Error("Invalid arguments: the first argument must be of type
|
21
|
+
throw new Error("Invalid arguments: the first argument must be of type CalendarDate.");
|
19
22
|
}
|
20
|
-
sCalendarType = aArgs[1] ? aArgs[1] : aArgs[0]._oUDate.sCalendarType;
|
23
|
+
sCalendarType = aArgs[1] ? aArgs[1] : (aArgs[0]._oUDate as UniversalDate).sCalendarType;
|
21
24
|
// Use source.valueOf() (returns the same point of time regardless calendar type) instead of
|
22
25
|
// source's getters to avoid non-gregorian Year, Month and Date may be used to construct a Gregorian date
|
23
26
|
oJSDate = new Date(aArgs[0].valueOf());
|
@@ -31,12 +34,12 @@ class CalendarDate {
|
|
31
34
|
|
32
35
|
case 3: // year, month, date
|
33
36
|
case 4: // year, month, date, sCalendarType
|
34
|
-
checkNumericLike(aArgs[0], `Invalid year: ${aArgs[0]}`);
|
35
|
-
checkNumericLike(aArgs[1], `Invalid month: ${aArgs[1]}`);
|
36
|
-
checkNumericLike(aArgs[2], `Invalid date: ${aArgs[2]}`);
|
37
|
+
checkNumericLike(aArgs[0] as number, `Invalid year: ${aArgs[0] as number}`);
|
38
|
+
checkNumericLike(aArgs[1] as number, `Invalid month: ${aArgs[1] as number}`);
|
39
|
+
checkNumericLike(aArgs[2] as number, `Invalid date: ${aArgs[2] as number}`);
|
37
40
|
|
38
41
|
oJSDate = new Date(0, 0, 1);
|
39
|
-
oJSDate.setFullYear(aArgs[0], aArgs[1], aArgs[2]); // 2 digits year is not supported. If so, it is considered as full year as well.
|
42
|
+
oJSDate.setFullYear(aArgs[0] as number, aArgs[1] as number, aArgs[2] as number); // 2 digits year is not supported. If so, it is considered as full year as well.
|
40
43
|
|
41
44
|
if (aArgs[3]) {
|
42
45
|
sCalendarType = aArgs[3];
|
@@ -46,7 +49,7 @@ class CalendarDate {
|
|
46
49
|
|
47
50
|
default:
|
48
51
|
throw new Error(`${"Invalid arguments. Accepted arguments are: 1) oCalendarDate, (optional)calendarType"
|
49
|
-
+ "or 2) year, month, date, (optional) calendarType"}${aArgs}`);
|
52
|
+
+ "or 2) year, month, date, (optional) calendarType"}${aArgs as unknown as string}`);
|
50
53
|
}
|
51
54
|
}
|
52
55
|
|
@@ -54,7 +57,7 @@ class CalendarDate {
|
|
54
57
|
return this._oUDate.getUTCFullYear();
|
55
58
|
}
|
56
59
|
|
57
|
-
setYear(year) {
|
60
|
+
setYear(year: number) {
|
58
61
|
checkNumericLike(year, `Invalid year: ${year}`);
|
59
62
|
this._oUDate.setUTCFullYear(year);
|
60
63
|
return this;
|
@@ -64,9 +67,29 @@ class CalendarDate {
|
|
64
67
|
return this._oUDate.getUTCMonth();
|
65
68
|
}
|
66
69
|
|
67
|
-
|
70
|
+
/**
|
71
|
+
* Sets the given month as ordinal month of the year.
|
72
|
+
* @param {int} month An integer between 0 and 11, representing the months January through December( or their
|
73
|
+
* equivalent month names for the given calendar).
|
74
|
+
* If the specified value is is outside of the expected range, this method attempts to update the date information
|
75
|
+
* accordingly. For example, if 12 is given as a month, the year will be incremented by 1, and 1 will be used for month.
|
76
|
+
* @param {int} [date] An integer between 1 and 31, representing the day of the month, but other values are allowed.
|
77
|
+
* 0 will result in the previous month's last day.
|
78
|
+
* -1 will result in the day before the previous month's last day.
|
79
|
+
* 32 will result in:
|
80
|
+
* - first day of the next month if the current month has 31 days.
|
81
|
+
* - second day of the next month if the current month has 30 days.
|
82
|
+
* Other value will result in adding or subtracting days according to the given value.
|
83
|
+
* @returns {sap.ui.unified.calendar.CalendarDate} <code>this</code> for method chaining.
|
84
|
+
*/
|
85
|
+
setMonth(month: number, date?: number) {
|
68
86
|
checkNumericLike(month, `Invalid month: ${month}`);
|
69
|
-
|
87
|
+
if (date || date === 0) {
|
88
|
+
checkNumericLike(date, `Invalid date: ${date}`);
|
89
|
+
this._oUDate.setUTCMonth(month, date);
|
90
|
+
} else {
|
91
|
+
this._oUDate.setUTCMonth(month);
|
92
|
+
}
|
70
93
|
return this;
|
71
94
|
}
|
72
95
|
|
@@ -74,7 +97,7 @@ class CalendarDate {
|
|
74
97
|
return this._oUDate.getUTCDate();
|
75
98
|
}
|
76
99
|
|
77
|
-
setDate(date) {
|
100
|
+
setDate(date: number) {
|
78
101
|
checkNumericLike(date, `Invalid date: ${date}`);
|
79
102
|
this._oUDate.setUTCDate(date);
|
80
103
|
return this;
|
@@ -85,30 +108,30 @@ class CalendarDate {
|
|
85
108
|
}
|
86
109
|
|
87
110
|
getCalendarType() {
|
88
|
-
return this._oUDate.sCalendarType;
|
111
|
+
return (this._oUDate as UniversalDate).sCalendarType;
|
89
112
|
}
|
90
113
|
|
91
|
-
isBefore(oCalendarDate) {
|
114
|
+
isBefore(oCalendarDate: CalendarDate) {
|
92
115
|
checkCalendarDate(oCalendarDate);
|
93
116
|
return this.valueOf() < oCalendarDate.valueOf();
|
94
117
|
}
|
95
118
|
|
96
|
-
isAfter(oCalendarDate) {
|
119
|
+
isAfter(oCalendarDate: CalendarDate) {
|
97
120
|
checkCalendarDate(oCalendarDate);
|
98
121
|
return this.valueOf() > oCalendarDate.valueOf();
|
99
122
|
}
|
100
123
|
|
101
|
-
isSameOrBefore(oCalendarDate) {
|
124
|
+
isSameOrBefore(oCalendarDate: CalendarDate) {
|
102
125
|
checkCalendarDate(oCalendarDate);
|
103
126
|
return this.valueOf() <= oCalendarDate.valueOf();
|
104
127
|
}
|
105
128
|
|
106
|
-
isSameOrAfter(oCalendarDate) {
|
129
|
+
isSameOrAfter(oCalendarDate: CalendarDate) {
|
107
130
|
checkCalendarDate(oCalendarDate);
|
108
131
|
return this.valueOf() >= oCalendarDate.valueOf();
|
109
132
|
}
|
110
133
|
|
111
|
-
isSame(oCalendarDate) {
|
134
|
+
isSame(oCalendarDate: CalendarDate) {
|
112
135
|
checkCalendarDate(oCalendarDate);
|
113
136
|
return this.valueOf() === oCalendarDate.valueOf();
|
114
137
|
}
|
@@ -135,34 +158,40 @@ class CalendarDate {
|
|
135
158
|
}
|
136
159
|
|
137
160
|
toString() {
|
138
|
-
return `${this._oUDate.sCalendarType}: ${this.getYear()}/${this.getMonth() + 1}/${this.getDate()}`;
|
161
|
+
return `${(this._oUDate as UniversalDate).sCalendarType}: ${this.getYear()}/${this.getMonth() + 1}/${this.getDate()}`;
|
139
162
|
}
|
140
163
|
|
141
164
|
valueOf() {
|
142
165
|
return this._oUDate.getTime();
|
143
166
|
}
|
144
167
|
|
145
|
-
static fromLocalJSDate(oJSDate, sCalendarType) {
|
168
|
+
static fromLocalJSDate(oJSDate: Date, sCalendarType?: CalendarType) {
|
146
169
|
// Cross frame check for a date should be performed here otherwise setDateValue would fail in OPA tests
|
147
170
|
// because Date object in the test is different than the Date object in the application (due to the iframe).
|
148
171
|
// We can use jQuery.type or this method:
|
149
|
-
function isValidDate(date) {
|
150
|
-
return date && Object.prototype.toString.call(date) === "[object Date]" && !isNaN(date); // eslint-disable-line
|
172
|
+
function isValidDate(date: Date) {
|
173
|
+
return date && Object.prototype.toString.call(date) === "[object Date]" && !isNaN(date as unknown as number); // eslint-disable-line
|
151
174
|
}
|
152
175
|
if (!isValidDate(oJSDate)) {
|
153
|
-
throw new Error(`Date parameter must be a JavaScript Date object: [${oJSDate}].`);
|
176
|
+
throw new Error(`Date parameter must be a JavaScript Date object: [${oJSDate as unknown as string}].`);
|
154
177
|
}
|
155
178
|
return new CalendarDate(oJSDate.getFullYear(), oJSDate.getMonth(), oJSDate.getDate(), sCalendarType);
|
156
179
|
}
|
157
180
|
|
158
|
-
static fromTimestamp(iTimestamp, sCalendarType) {
|
181
|
+
static fromTimestamp(iTimestamp: number, sCalendarType?: CalendarType) {
|
159
182
|
const oCalDate = new CalendarDate(0, 0, 1);
|
160
|
-
|
183
|
+
let oUDate;
|
184
|
+
try {
|
185
|
+
oUDate = UniversalDate.getInstance(new Date(iTimestamp), sCalendarType);
|
186
|
+
} catch (e) {
|
187
|
+
oUDate = new Date(NaN); // UniversalDate.getInstance may now throw an Exception - keep the old behavior
|
188
|
+
}
|
189
|
+
oCalDate._oUDate = oUDate;
|
161
190
|
return oCalDate;
|
162
191
|
}
|
163
192
|
}
|
164
193
|
|
165
|
-
function createUniversalUTCDate(oDate, sCalendarType) {
|
194
|
+
function createUniversalUTCDate(oDate: Date, sCalendarType: CalendarType) {
|
166
195
|
if (sCalendarType) {
|
167
196
|
return UniversalDate.getInstance(createUTCDate(oDate), sCalendarType);
|
168
197
|
}
|
@@ -174,7 +203,7 @@ function createUniversalUTCDate(oDate, sCalendarType) {
|
|
174
203
|
* @param {Date} oDate JavaScript date object. Time related information is cut.
|
175
204
|
* @returns {Date} JavaScript date created from the date object, but this time considered as UTC date information.
|
176
205
|
*/
|
177
|
-
function createUTCDate(oDate) {
|
206
|
+
function createUTCDate(oDate: Date) {
|
178
207
|
const oUTCDate = new Date(Date.UTC(0, 0, 1));
|
179
208
|
|
180
209
|
oUTCDate.setUTCFullYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate());
|
@@ -182,9 +211,9 @@ function createUTCDate(oDate) {
|
|
182
211
|
return oUTCDate;
|
183
212
|
}
|
184
213
|
|
185
|
-
function checkCalendarDate(oCalendarDate) {
|
214
|
+
function checkCalendarDate(oCalendarDate: CalendarDate) {
|
186
215
|
if (!(oCalendarDate instanceof CalendarDate)) {
|
187
|
-
throw new Error(`Invalid calendar date: [${oCalendarDate}]. Expected:
|
216
|
+
throw new Error(`Invalid calendar date: [${oCalendarDate as unknown as string}]. Expected: CalendarDate`);
|
188
217
|
}
|
189
218
|
}
|
190
219
|
|
@@ -194,7 +223,7 @@ function checkCalendarDate(oCalendarDate) {
|
|
194
223
|
* @param {string} message The message to be used if an error is to be thrown
|
195
224
|
* @throws will throw an error if the value is null or undefined or is not like a number
|
196
225
|
*/
|
197
|
-
function checkNumericLike(value, message) {
|
226
|
+
function checkNumericLike(value: any, message: string) {
|
198
227
|
if (value === undefined || value === Infinity || isNaN(value)) { // eslint-disable-line
|
199
228
|
throw message;
|
200
229
|
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
|
2
|
+
import CalendarDate from "./CalendarDate.js";
|
3
|
+
|
4
|
+
const cache = new Map<string, CalendarDate>();
|
5
|
+
|
6
|
+
const getMinCalendarDate = (primaryCalendarType: CalendarType) => {
|
7
|
+
const key = `min ${primaryCalendarType}`;
|
8
|
+
|
9
|
+
if (!cache.has(key)) {
|
10
|
+
const minDate = new CalendarDate(1, 0, 1, primaryCalendarType);
|
11
|
+
minDate.setYear(1);
|
12
|
+
minDate.setMonth(0);
|
13
|
+
minDate.setDate(1);
|
14
|
+
cache.set(key, minDate);
|
15
|
+
}
|
16
|
+
|
17
|
+
return cache.get(key)!;
|
18
|
+
};
|
19
|
+
|
20
|
+
const getMaxCalendarDate = (primaryCalendarType: CalendarType) => {
|
21
|
+
const key = `max ${primaryCalendarType}`;
|
22
|
+
|
23
|
+
if (!cache.has(key)) {
|
24
|
+
const maxDate = new CalendarDate(1, 0, 1, primaryCalendarType);
|
25
|
+
maxDate.setYear(9999);
|
26
|
+
maxDate.setMonth(11);
|
27
|
+
const tempDate = new CalendarDate(maxDate, primaryCalendarType);
|
28
|
+
tempDate.setDate(1);
|
29
|
+
tempDate.setMonth(tempDate.getMonth() + 1, 0);
|
30
|
+
maxDate.setDate(tempDate.getDate());// 31st for Gregorian Calendar
|
31
|
+
cache.set(key, maxDate);
|
32
|
+
}
|
33
|
+
|
34
|
+
return cache.get(key)!;
|
35
|
+
};
|
36
|
+
|
37
|
+
export {
|
38
|
+
getMinCalendarDate,
|
39
|
+
getMaxCalendarDate,
|
40
|
+
};
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import type CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
|
2
|
+
// @ts-ignore
|
3
|
+
import UniversalDateNative from "../sap/ui/core/date/UniversalDate.js";
|
4
|
+
|
5
|
+
type UniversalDate = {
|
6
|
+
new (time: number): UniversalDate;
|
7
|
+
oDate: Date,
|
8
|
+
sCalendarType: string,
|
9
|
+
getInstance: (oDate: Date, sCalendarType?: CalendarType) => UniversalDate,
|
10
|
+
getDate: () => number,
|
11
|
+
getMonth: () => number,
|
12
|
+
getFullYear: () => number,
|
13
|
+
getYear: () => number,
|
14
|
+
getDay: () => number,
|
15
|
+
getHours: () => number,
|
16
|
+
getMinutes: () => number,
|
17
|
+
getSeconds: () => number,
|
18
|
+
getMilliseconds: () => number,
|
19
|
+
getUTCDate: () => number,
|
20
|
+
getUTCMonth: () => number,
|
21
|
+
getUTCFullYear: () => number,
|
22
|
+
getUTCDay: () => number,
|
23
|
+
getUTCHours: () => number,
|
24
|
+
getUTCMinutes: () => number,
|
25
|
+
getUTCSeconds: () => number,
|
26
|
+
getUTCMilliseconds: () => number,
|
27
|
+
getTime: () => number,
|
28
|
+
valueOf: () => number,
|
29
|
+
getTimezoneOffset: () => number,
|
30
|
+
toString: () => string,
|
31
|
+
toDateString: () => string,
|
32
|
+
setDate: (dayValue: number) => number,
|
33
|
+
setFullYear: (yearValue: number, monthValue?: number, dateValue?: number) => number,
|
34
|
+
setYear: (yearValue: number) => number,
|
35
|
+
setMonth: (monthValue: number, dayValue?: number) => number,
|
36
|
+
setHours: (hoursValue: number, minutesValue?: number, secondsValue?: number, msValue?: number) => number,
|
37
|
+
setMinutes: (minutesValue: number, secondsValue?: number, msValue?: number) => number,
|
38
|
+
setSeconds: (secondsValue: number, msValue?: number) => number,
|
39
|
+
setMilliseconds: (setMilliseconds: number) => number,
|
40
|
+
setUTCDate:(dayValue: number) => number,
|
41
|
+
setUTCFullYear: (yearValue: number, monthValue?: number, dayValue?: number) => number,
|
42
|
+
setUTCMonth: (monthValue: number, dayValue?: number) => number,
|
43
|
+
setUTCHours: (hoursValue: number, minutesValue?: number, secondsValue?: number, msValue?: number) => number,
|
44
|
+
setUTCMinutes: (minutesValue: number, secondsValue?: number, msValue?: number) => number,
|
45
|
+
setUTCSeconds: (secondsValue: number, msValue?: number) => number,
|
46
|
+
setUTCMilliseconds: (setMilliseconds: number) => number,
|
47
|
+
}
|
48
|
+
|
49
|
+
const UniversalDate: UniversalDate = UniversalDateNative;
|
50
|
+
|
51
|
+
export default UniversalDate;
|
@@ -1,9 +1,11 @@
|
|
1
|
-
import
|
1
|
+
import type Locale from "@ui5/webcomponents-base/dist/locale/Locale.js";
|
2
|
+
import UniversalDate from "./UniversalDate.js";
|
3
|
+
import type LocaleData from "../LocaleData.js";
|
2
4
|
|
3
|
-
const calculateWeekNumber = (confFirstDayOfWeek, oDate, iYear, oLocale, oLocaleData) => {
|
5
|
+
const calculateWeekNumber = (confFirstDayOfWeek: number | undefined, oDate: Date, iYear: number, oLocale: Locale, oLocaleData: LocaleData) => {
|
4
6
|
let iWeekNum = 0;
|
5
7
|
let iWeekDay = 0;
|
6
|
-
const iFirstDayOfWeek = Number.isInteger(confFirstDayOfWeek) ? confFirstDayOfWeek : oLocaleData.getFirstDayOfWeek();
|
8
|
+
const iFirstDayOfWeek = Number.isInteger(confFirstDayOfWeek) ? confFirstDayOfWeek! : oLocaleData.getFirstDayOfWeek();
|
7
9
|
|
8
10
|
// search Locale for containing "en-US", since sometimes
|
9
11
|
// when any user settings have been defined, subtag "sapufmt" is added to the locale name
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js";
|
2
|
+
import type CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
|
3
|
+
import getCachedLocaleDataInstance from "../getCachedLocaleDataInstance.js";
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Convert month number to month name (text).
|
7
|
+
* If the numbers of the two months are the same you will get the name of the month,
|
8
|
+
* otherwise you will get the two names separated by a dash
|
9
|
+
*
|
10
|
+
* @param firstMonth CalendarDate Month
|
11
|
+
* @param lastMonth CalendarDate Month
|
12
|
+
* @param calendarType calendar type
|
13
|
+
* @returns {String}
|
14
|
+
*/
|
15
|
+
const convertMonthNumbersToMonthNames = (firstMonth: number, lastMonth: number, calendarType?: CalendarType) => {
|
16
|
+
const localeData = getCachedLocaleDataInstance(getLocale());
|
17
|
+
const pattern = localeData.getIntervalPattern("");
|
18
|
+
const secondaryMonthsNames = localeData.getMonthsStandAlone("abbreviated", calendarType) as Array<string>;
|
19
|
+
const secondaryMonthsNamesWide = localeData.getMonthsStandAlone("wide", calendarType) as Array<string>;
|
20
|
+
|
21
|
+
if (firstMonth === lastMonth) {
|
22
|
+
return {
|
23
|
+
text: localeData.getMonths("abbreviated", calendarType)[firstMonth],
|
24
|
+
textInfo: localeData.getMonths("wide", calendarType)[firstMonth],
|
25
|
+
};
|
26
|
+
}
|
27
|
+
|
28
|
+
return {
|
29
|
+
text: pattern.replace(/\{0\}/, secondaryMonthsNames[firstMonth]).replace(/\{1\}/, secondaryMonthsNames[lastMonth]),
|
30
|
+
textInfo: pattern.replace(/\{0\}/, secondaryMonthsNamesWide[firstMonth]).replace(/\{1\}/, secondaryMonthsNamesWide[lastMonth]),
|
31
|
+
};
|
32
|
+
};
|
33
|
+
|
34
|
+
export default convertMonthNumbersToMonthNames;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import CalendarDate from "./CalendarDate.js";
|
2
|
+
|
3
|
+
const getDaysInMonth = (date: CalendarDate) => {
|
4
|
+
const tempCalendarDate = new CalendarDate(date);
|
5
|
+
tempCalendarDate.setDate(1);
|
6
|
+
tempCalendarDate.setMonth(tempCalendarDate.getMonth() + 1);
|
7
|
+
tempCalendarDate.setDate(0);
|
8
|
+
return tempCalendarDate.getDate();
|
9
|
+
};
|
10
|
+
|
11
|
+
export default getDaysInMonth;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* Returns a timestamp with only the year, month and day (with zero hours, minutes and seconds) and without 000 for milliseconds
|
3
|
+
* @param { number } millisecondsUTC
|
4
|
+
* @returns { number }
|
5
|
+
*/
|
6
|
+
const getRoundedTimestamp = (millisecondsUTC: number) => {
|
7
|
+
if (!millisecondsUTC) {
|
8
|
+
millisecondsUTC = new Date().getTime();
|
9
|
+
}
|
10
|
+
const rounded = millisecondsUTC - (millisecondsUTC % (24 * 60 * 60 * 1000));
|
11
|
+
return rounded / 1000;
|
12
|
+
};
|
13
|
+
|
14
|
+
export default getRoundedTimestamp;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
|
2
|
+
import CalendarDate from "./CalendarDate.js";
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Returns a UTC timestamp representing today
|
6
|
+
* @public
|
7
|
+
*/
|
8
|
+
const getTodayUTCTimestamp = (primaryCalendarType: CalendarType) => CalendarDate.fromLocalJSDate(new Date(), primaryCalendarType).valueOf() / 1000;
|
9
|
+
|
10
|
+
export default getTodayUTCTimestamp;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import CalendarDate from "./CalendarDate.js";
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Adds or subtracts a given amount of days/months/years from a date.
|
5
|
+
* If minDate or maxDate are given, the result will be enforced within these limits
|
6
|
+
*
|
7
|
+
* @param date CalendarDate instance
|
8
|
+
* @param amount how many days/months/years to add (can be a negative number)
|
9
|
+
* @param unit what to modify: "day", "month" or "year"
|
10
|
+
* @param minDate minimum date to enforce
|
11
|
+
* @param maxDate maximum date to enforce
|
12
|
+
*/
|
13
|
+
const modifyDateBy = (date: CalendarDate, amount: number, unit: string, minDate?: CalendarDate, maxDate?: CalendarDate) => {
|
14
|
+
const newDate = new CalendarDate(date);
|
15
|
+
if (unit === "day") {
|
16
|
+
newDate.setDate(date.getDate() + amount);
|
17
|
+
} else if (unit === "month") {
|
18
|
+
newDate.setMonth(date.getMonth() + amount);
|
19
|
+
const stillSameMonth = amount === -1 && newDate.getMonth() === date.getMonth(); // f.e. PageUp remained in the same month
|
20
|
+
const monthSkipped = amount === 1 && newDate.getMonth() - date.getMonth() > 1; // f.e. PageDown skipped a whole month
|
21
|
+
if (stillSameMonth || monthSkipped) { // Select the last day of the month in any of these 2 scenarios
|
22
|
+
newDate.setDate(0);
|
23
|
+
}
|
24
|
+
} else {
|
25
|
+
newDate.setYear(date.getYear() + amount);
|
26
|
+
if (newDate.getMonth() !== date.getMonth()) { // f.e. 29th Feb to next/prev year
|
27
|
+
newDate.setDate(0); // Select the last day of the month
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
if (minDate && newDate.valueOf() < minDate.valueOf()) {
|
32
|
+
return new CalendarDate(minDate);
|
33
|
+
}
|
34
|
+
|
35
|
+
if (maxDate && newDate.valueOf() > maxDate.valueOf()) {
|
36
|
+
return new CalendarDate(maxDate);
|
37
|
+
}
|
38
|
+
|
39
|
+
return newDate;
|
40
|
+
};
|
41
|
+
|
42
|
+
export default modifyDateBy;
|