@ui5/webcomponents-localization 0.0.0-dff5837d7 → 0.0.0-e818f286e

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.
Files changed (119) hide show
  1. package/.eslintignore +1 -0
  2. package/CHANGELOG.md +220 -0
  3. package/README.md +36 -6
  4. package/dist/Assets-static.js +2 -0
  5. package/dist/dates/CalendarDate.js +29 -3
  6. package/dist/dates/ExtremeDates.js +39 -0
  7. package/dist/dates/convertMonthNumbersToMonthNames.js +33 -0
  8. package/dist/dates/getDaysInMonth.js +11 -0
  9. package/dist/dates/getRoundedTimestamp.js +14 -0
  10. package/dist/dates/getTodayUTCTimestamp.js +9 -0
  11. package/dist/dates/modifyDateBy.js +42 -0
  12. package/dist/dates/transformDateToSecondaryType.js +20 -0
  13. package/dist/generated/assets/cldr/ar.json +5 -3
  14. package/dist/generated/assets/cldr/ar_EG.json +5 -3
  15. package/dist/generated/assets/cldr/ar_SA.json +5 -3
  16. package/dist/generated/assets/cldr/bg.json +5 -3
  17. package/dist/generated/assets/cldr/ca.json +5 -3
  18. package/dist/generated/assets/cldr/cs.json +5 -3
  19. package/dist/generated/assets/cldr/cy.json +5886 -0
  20. package/dist/generated/assets/cldr/da.json +5 -3
  21. package/dist/generated/assets/cldr/de.json +5 -3
  22. package/dist/generated/assets/cldr/de_AT.json +5 -3
  23. package/dist/generated/assets/cldr/de_CH.json +5 -3
  24. package/dist/generated/assets/cldr/el.json +5 -3
  25. package/dist/generated/assets/cldr/el_CY.json +5 -3
  26. package/dist/generated/assets/cldr/en.json +6 -3
  27. package/dist/generated/assets/cldr/en_AU.json +6 -4
  28. package/dist/generated/assets/cldr/en_GB.json +5 -3
  29. package/dist/generated/assets/cldr/en_HK.json +5 -3
  30. package/dist/generated/assets/cldr/en_IE.json +5 -3
  31. package/dist/generated/assets/cldr/en_IN.json +5 -3
  32. package/dist/generated/assets/cldr/en_NZ.json +5 -3
  33. package/dist/generated/assets/cldr/en_PG.json +5 -3
  34. package/dist/generated/assets/cldr/en_SG.json +5 -3
  35. package/dist/generated/assets/cldr/en_ZA.json +5 -3
  36. package/dist/generated/assets/cldr/es.json +5 -3
  37. package/dist/generated/assets/cldr/es_AR.json +5 -3
  38. package/dist/generated/assets/cldr/es_BO.json +5 -3
  39. package/dist/generated/assets/cldr/es_CL.json +5 -3
  40. package/dist/generated/assets/cldr/es_CO.json +5 -3
  41. package/dist/generated/assets/cldr/es_MX.json +5 -3
  42. package/dist/generated/assets/cldr/es_PE.json +5 -3
  43. package/dist/generated/assets/cldr/es_UY.json +5 -3
  44. package/dist/generated/assets/cldr/es_VE.json +5 -3
  45. package/dist/generated/assets/cldr/et.json +5 -3
  46. package/dist/generated/assets/cldr/fa.json +5 -3
  47. package/dist/generated/assets/cldr/fi.json +5 -3
  48. package/dist/generated/assets/cldr/fr.json +5 -3
  49. package/dist/generated/assets/cldr/fr_BE.json +5 -3
  50. package/dist/generated/assets/cldr/fr_CA.json +5 -3
  51. package/dist/generated/assets/cldr/fr_CH.json +5 -3
  52. package/dist/generated/assets/cldr/fr_LU.json +5 -3
  53. package/dist/generated/assets/cldr/he.json +5 -3
  54. package/dist/generated/assets/cldr/hi.json +5 -3
  55. package/dist/generated/assets/cldr/hr.json +5 -3
  56. package/dist/generated/assets/cldr/hu.json +5 -3
  57. package/dist/generated/assets/cldr/id.json +5 -3
  58. package/dist/generated/assets/cldr/it.json +5 -3
  59. package/dist/generated/assets/cldr/it_CH.json +5 -3
  60. package/dist/generated/assets/cldr/ja.json +5 -3
  61. package/dist/generated/assets/cldr/kk.json +5 -3
  62. package/dist/generated/assets/cldr/ko.json +5 -3
  63. package/dist/generated/assets/cldr/lt.json +5 -3
  64. package/dist/generated/assets/cldr/lv.json +5 -3
  65. package/dist/generated/assets/cldr/ms.json +5 -3
  66. package/dist/generated/assets/cldr/nb.json +5 -3
  67. package/dist/generated/assets/cldr/nl.json +5 -3
  68. package/dist/generated/assets/cldr/nl_BE.json +5 -3
  69. package/dist/generated/assets/cldr/pl.json +5 -3
  70. package/dist/generated/assets/cldr/pt.json +5 -3
  71. package/dist/generated/assets/cldr/pt_PT.json +5 -3
  72. package/dist/generated/assets/cldr/ro.json +5 -3
  73. package/dist/generated/assets/cldr/ru.json +5 -3
  74. package/dist/generated/assets/cldr/ru_UA.json +5 -3
  75. package/dist/generated/assets/cldr/sk.json +5 -3
  76. package/dist/generated/assets/cldr/sl.json +5 -3
  77. package/dist/generated/assets/cldr/sr.json +5 -3
  78. package/dist/generated/assets/cldr/sr_Latn.json +5129 -0
  79. package/dist/generated/assets/cldr/sv.json +5 -3
  80. package/dist/generated/assets/cldr/th.json +5 -3
  81. package/dist/generated/assets/cldr/tr.json +5 -3
  82. package/dist/generated/assets/cldr/uk.json +5 -3
  83. package/dist/generated/assets/cldr/vi.json +5 -3
  84. package/dist/generated/assets/cldr/zh_CN.json +5 -3
  85. package/dist/generated/assets/cldr/zh_HK.json +5 -3
  86. package/dist/generated/assets/cldr/zh_SG.json +5 -3
  87. package/dist/generated/assets/cldr/zh_TW.json +5 -3
  88. package/dist/generated/json-imports/LocaleData-static.js +90 -0
  89. package/dist/generated/json-imports/LocaleData.js +88 -91
  90. package/dist/getCachedLocaleDataInstance.js +13 -0
  91. package/dist/sap/base/Log.js +2 -10
  92. package/dist/sap/base/assert.js +1 -5
  93. package/dist/sap/base/util/LoaderExtensions.js +12 -2
  94. package/dist/sap/base/util/array/uniqueSort.js +7 -7
  95. package/dist/sap/base/util/deepEqual.js +1 -5
  96. package/dist/sap/ui/base/Interface.js +3 -5
  97. package/dist/sap/ui/base/Metadata.js +1 -3
  98. package/dist/sap/ui/base/Object.js +26 -2
  99. package/dist/sap/ui/core/Core.js +2 -0
  100. package/dist/sap/ui/core/Locale.js +67 -31
  101. package/dist/sap/ui/core/LocaleData.js +56 -1504
  102. package/dist/sap/ui/core/date/UniversalDate.js +13 -5
  103. package/dist/sap/ui/core/format/DateFormat.js +402 -194
  104. package/dist/sap/ui/core/format/TimezoneUtil.js +83 -0
  105. package/package-scripts.js +10 -6
  106. package/package.json +12 -14
  107. package/src/Assets-static.js +2 -0
  108. package/src/dates/CalendarDate.js +29 -3
  109. package/src/dates/ExtremeDates.js +39 -0
  110. package/src/dates/convertMonthNumbersToMonthNames.js +33 -0
  111. package/src/dates/getDaysInMonth.js +11 -0
  112. package/src/dates/getRoundedTimestamp.js +14 -0
  113. package/src/dates/getTodayUTCTimestamp.js +9 -0
  114. package/src/dates/modifyDateBy.js +42 -0
  115. package/src/dates/transformDateToSecondaryType.js +20 -0
  116. package/src/getCachedLocaleDataInstance.js +13 -0
  117. package/src/sap/base/util/LoaderExtensions.js +12 -2
  118. package/src/sap/ui/core/Core.js +2 -0
  119. package/used-modules.txt +1 -0
@@ -0,0 +1,83 @@
1
+ var TimezoneUtil = {};
2
+ var sLocalTimezone = "";
3
+ var oIntlDateTimeFormatCache = {
4
+ _oCache: new Map(),
5
+ _iCacheLimit: 10,
6
+ get: function (sTimezone) {
7
+ var cacheEntry = this._oCache.get(sTimezone);
8
+ if (cacheEntry) {
9
+ return cacheEntry;
10
+ }
11
+ var oOptions = {
12
+ hourCycle: "h23",
13
+ hour: "2-digit",
14
+ minute: "2-digit",
15
+ second: "2-digit",
16
+ fractionalSecondDigits: 3,
17
+ day: "2-digit",
18
+ month: "2-digit",
19
+ year: "numeric",
20
+ timeZone: sTimezone,
21
+ timeZoneName: "short",
22
+ era: "narrow"
23
+ };
24
+ var oInstance = new Intl.DateTimeFormat("en-US", oOptions);
25
+ if (this._oCache.size === this._iCacheLimit) {
26
+ this._oCache = new Map();
27
+ }
28
+ this._oCache.set(sTimezone, oInstance);
29
+ return oInstance;
30
+ }
31
+ };
32
+ TimezoneUtil.isValidTimezone = function (sTimezone) {
33
+ if (!sTimezone) {
34
+ return false;
35
+ }
36
+ try {
37
+ oIntlDateTimeFormatCache.get(sTimezone);
38
+ return true;
39
+ } catch (oError) {
40
+ return false;
41
+ }
42
+ };
43
+ TimezoneUtil.convertToTimezone = function (oDate, sTargetTimezone) {
44
+ var oFormatParts = this._getParts(oDate, sTargetTimezone);
45
+ return TimezoneUtil._getDateFromParts(oFormatParts);
46
+ };
47
+ TimezoneUtil._getParts = function (oDate, sTargetTimezone) {
48
+ var oIntlDate = oIntlDateTimeFormatCache.get(sTargetTimezone);
49
+ var oParts = oIntlDate.formatToParts(new Date(oDate.getTime()));
50
+ var oDateParts = Object.create(null);
51
+ for (var sKey in oParts) {
52
+ var oPart = oParts[sKey];
53
+ if (oPart.type !== "literal") {
54
+ oDateParts[oPart.type] = oPart.value;
55
+ }
56
+ }
57
+ return oDateParts;
58
+ };
59
+ TimezoneUtil._getDateFromParts = function (oParts) {
60
+ var oDate = new Date(0);
61
+ var iUTCYear = parseInt(oParts.year);
62
+ if (oParts.era === "B") {
63
+ iUTCYear = iUTCYear * -1 + 1;
64
+ }
65
+ oDate.setUTCFullYear(iUTCYear, parseInt(oParts.month) - 1, parseInt(oParts.day));
66
+ oDate.setUTCHours(parseInt(oParts.hour), parseInt(oParts.minute), parseInt(oParts.second), parseInt(oParts.fractionalSecond));
67
+ return oDate;
68
+ };
69
+ TimezoneUtil.calculateOffset = function (oDate, sTimezoneSource) {
70
+ var oFirstGuess = this.convertToTimezone(oDate, sTimezoneSource);
71
+ var iInitialOffset = oDate.getTime() - oFirstGuess.getTime();
72
+ var oDateSource = new Date(oDate.getTime() + iInitialOffset);
73
+ var oDateTarget = this.convertToTimezone(oDateSource, sTimezoneSource);
74
+ return (oDateSource.getTime() - oDateTarget.getTime()) / 1000;
75
+ };
76
+ TimezoneUtil.getLocalTimezone = function () {
77
+ if (sLocalTimezone) {
78
+ return sLocalTimezone;
79
+ }
80
+ sLocalTimezone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
81
+ return sLocalTimezone;
82
+ };
83
+ export default TimezoneUtil;
@@ -1,19 +1,23 @@
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": "path-exists dist/ || nps build.all",
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 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": "node ./lib/replace-global-core/index.js dist/",
12
- "esm-abs-to-rel": "node ./lib/esm-abs-to-rel/index.js dist/",
13
- jsonImports: "node ./lib/generate-json-imports/cldr.js",
15
+ "replace-global-core-usage": `node "${replaceGlobalCore}" dist/`,
16
+ "esm-abs-to-rel": `node "${esmAbsToRel}" dist/`,
17
+ jsonImports: "node ./lib/generate-json-imports/cldr.js"
14
18
  },
15
19
  copy: {
16
- "used-modules": "node ./lib/copy-list/index.js ./used-modules.txt dist/",
20
+ "used-modules": `node "${copyUsedModules}" ./used-modules.txt dist/`,
17
21
  cldr: `copy-and-watch "../../node_modules/@openui5/sap.ui.core/src/sap/ui/core/cldr/*.json" dist/generated/assets/cldr/`,
18
22
  overlay: `copy-and-watch "overlay/**/*.js" dist/`,
19
23
  src: `copy-and-watch "src/**/*.js" dist/`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/webcomponents-localization",
3
- "version": "0.0.0-dff5837d7",
3
+ "version": "0.0.0-e818f286e",
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,13 @@
22
27
  "prepublishOnly": "npm run clean && npm run build"
23
28
  },
24
29
  "devDependencies": {
25
- "@buxlabs/amd-to-es6": "^0.15.0",
26
- "@openui5/sap.ui.core": "1.76.0",
27
- "@ui5/webcomponents-tools": "0.0.0-dff5837d7",
28
- "chromedriver": "latest",
29
- "copy-and-watch": "^0.1.4",
30
- "escodegen": "^1.11.0",
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.101.0",
31
+ "@ui5/webcomponents-tools": "0.0.0-e818f286e",
32
+ "chromedriver": "102.0.0",
33
+ "mkdirp": "^1.0.4",
34
+ "resolve": "^1.20.0"
37
35
  },
38
36
  "dependencies": {
39
- "@ui5/webcomponents-base": "0.0.0-dff5837d7"
37
+ "@ui5/webcomponents-base": "0.0.0-e818f286e"
40
38
  }
41
39
  }
@@ -0,0 +1,2 @@
1
+ // Currently the base package provides CLDR assets only
2
+ import "./generated/json-imports/LocaleData-static.js";
@@ -64,9 +64,29 @@ class CalendarDate {
64
64
  return this._oUDate.getUTCMonth();
65
65
  }
66
66
 
67
- setMonth(month) {
67
+ /**
68
+ * Sets the given month as ordinal month of the year.
69
+ * @param {int} month An integer between 0 and 11, representing the months January through December( or their
70
+ * equivalent month names for the given calendar).
71
+ * If the specified value is is outside of the expected range, this method attempts to update the date information
72
+ * accordingly. For example, if 12 is given as a month, the year will be incremented by 1, and 1 will be used for month.
73
+ * @param {int} [date] An integer between 1 and 31, representing the day of the month, but other values are allowed.
74
+ * 0 will result in the previous month's last day.
75
+ * -1 will result in the day before the previous month's last day.
76
+ * 32 will result in:
77
+ * - first day of the next month if the current month has 31 days.
78
+ * - second day of the next month if the current month has 30 days.
79
+ * Other value will result in adding or subtracting days according to the given value.
80
+ * @returns {sap.ui.unified.calendar.CalendarDate} <code>this</code> for method chaining.
81
+ */
82
+ setMonth(month, date) {
68
83
  checkNumericLike(month, `Invalid month: ${month}`);
69
- this._oUDate.setUTCMonth(month);
84
+ if (date || date === 0) {
85
+ checkNumericLike(date, `Invalid date: ${date}`);
86
+ this._oUDate.setUTCMonth(month, date);
87
+ } else {
88
+ this._oUDate.setUTCMonth(month);
89
+ }
70
90
  return this;
71
91
  }
72
92
 
@@ -157,7 +177,13 @@ class CalendarDate {
157
177
 
158
178
  static fromTimestamp(iTimestamp, sCalendarType) {
159
179
  const oCalDate = new CalendarDate(0, 0, 1);
160
- oCalDate._oUDate = UniversalDate.getInstance(new Date(iTimestamp), sCalendarType);
180
+ let oUDate;
181
+ try {
182
+ oUDate = UniversalDate.getInstance(new Date(iTimestamp), sCalendarType);
183
+ } catch (e) {
184
+ oUDate = new Date(NaN); // UniversalDate.getInstance may now throw an Exception - keep the old behavior
185
+ }
186
+ oCalDate._oUDate = oUDate;
161
187
  return oCalDate;
162
188
  }
163
189
  }
@@ -0,0 +1,39 @@
1
+ import CalendarDate from "./CalendarDate.js";
2
+
3
+ const cache = new Map();
4
+
5
+ const getMinCalendarDate = primaryCalendarType => {
6
+ const key = `min ${primaryCalendarType}`;
7
+
8
+ if (!cache.has(key)) {
9
+ const minDate = new CalendarDate(1, 0, 1, primaryCalendarType);
10
+ minDate.setYear(1);
11
+ minDate.setMonth(0);
12
+ minDate.setDate(1);
13
+ cache.set(key, minDate);
14
+ }
15
+
16
+ return cache.get(key);
17
+ };
18
+
19
+ const getMaxCalendarDate = primaryCalendarType => {
20
+ const key = `max ${primaryCalendarType}`;
21
+
22
+ if (!cache.has(key)) {
23
+ const maxDate = new CalendarDate(1, 0, 1, primaryCalendarType);
24
+ maxDate.setYear(9999);
25
+ maxDate.setMonth(11);
26
+ const tempDate = new CalendarDate(maxDate, primaryCalendarType);
27
+ tempDate.setDate(1);
28
+ tempDate.setMonth(tempDate.getMonth() + 1, 0);
29
+ maxDate.setDate(tempDate.getDate());// 31st for Gregorian Calendar
30
+ cache.set(key, maxDate);
31
+ }
32
+
33
+ return cache.get(key);
34
+ };
35
+
36
+ export {
37
+ getMinCalendarDate,
38
+ getMaxCalendarDate,
39
+ };
@@ -0,0 +1,33 @@
1
+ import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js";
2
+ import getCachedLocaleDataInstance from "../getCachedLocaleDataInstance.js";
3
+
4
+ /**
5
+ * Convert month number to month name (text).
6
+ * If the numbers of the two months are the same you will get the name of the month,
7
+ * otherwise you will get the two names separated by a dash
8
+ *
9
+ * @param firstMonth CalendarDate Month
10
+ * @param lastMonth CalendarDate Month
11
+ * @param calendarType calendar type
12
+ * @returns {String}
13
+ */
14
+ const convertMonthNumbersToMonthNames = (firstMonth, lastMonth, calendarType) => {
15
+ const localeData = getCachedLocaleDataInstance(getLocale());
16
+ const pattern = localeData.getIntervalPattern();
17
+ const secondaryMonthsNames = localeData.getMonthsStandAlone("abbreviated", calendarType);
18
+ const secondaryMonthsNamesWide = localeData.getMonthsStandAlone("wide", calendarType);
19
+
20
+ if (firstMonth === lastMonth) {
21
+ return {
22
+ text: localeData.getMonths("abbreviated", calendarType)[firstMonth],
23
+ textInfo: localeData.getMonths("wide", calendarType)[firstMonth],
24
+ };
25
+ }
26
+
27
+ return {
28
+ text: pattern.replace(/\{0\}/, secondaryMonthsNames[firstMonth]).replace(/\{1\}/, secondaryMonthsNames[lastMonth]),
29
+ textInfo: pattern.replace(/\{0\}/, secondaryMonthsNamesWide[firstMonth]).replace(/\{1\}/, secondaryMonthsNamesWide[lastMonth]),
30
+ };
31
+ };
32
+
33
+ export default convertMonthNumbersToMonthNames;
@@ -0,0 +1,11 @@
1
+ import CalendarDate from "./CalendarDate.js";
2
+
3
+ const getDaysInMonth = date => {
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 millisecondsUTC
4
+ * @returns {number}
5
+ */
6
+ const getRoundedTimestamp = millisecondsUTC => {
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,9 @@
1
+ import CalendarDate from "./CalendarDate.js";
2
+
3
+ /**
4
+ * Returns a UTC timestamp representing today
5
+ * @public
6
+ */
7
+ const getTodayUTCTimestamp = primaryCalendarType => CalendarDate.fromLocalJSDate(new Date(), primaryCalendarType).valueOf() / 1000;
8
+
9
+ 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, amount, unit, minDate = null, maxDate = null) => {
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;
@@ -0,0 +1,20 @@
1
+ import CalendarDate from "./CalendarDate.js";
2
+ import getDaysInMonth from "./getDaysInMonth.js";
3
+
4
+ const transformDateToSecondaryType = (primaryCalendarType, secondaryCalendarType, timeStamp, hasYearPicker) => {
5
+ let firstDate = CalendarDate.fromLocalJSDate(new Date(timeStamp * 1000), primaryCalendarType);
6
+ let lastDate = CalendarDate.fromLocalJSDate(new Date(timeStamp * 1000), primaryCalendarType);
7
+ firstDate.setDate(1);
8
+
9
+ if (hasYearPicker) {
10
+ firstDate.setMonth(0);
11
+ lastDate.setMonth(11);
12
+ }
13
+
14
+ lastDate.setDate(getDaysInMonth(lastDate));
15
+ firstDate = new CalendarDate(firstDate, secondaryCalendarType);
16
+ lastDate = new CalendarDate(lastDate, secondaryCalendarType);
17
+ return { firstDate, lastDate };
18
+ };
19
+
20
+ export default transformDateToSecondaryType;
@@ -0,0 +1,13 @@
1
+ import LocaleData from "./LocaleData.js";
2
+
3
+ const cache = new Map();
4
+
5
+ const getCachedLocaleDataInstance = locale => {
6
+ if (!cache.has(locale)) {
7
+ cache.set(locale, LocaleData.getInstance(locale));
8
+ }
9
+
10
+ return cache.get(locale);
11
+ };
12
+
13
+ export default getCachedLocaleDataInstance;
@@ -1,7 +1,17 @@
1
- import { getModuleContent } from "@ui5/webcomponents-base/dist/asset-registries/LocaleData.js";
1
+ import { getLocaleData } from "@ui5/webcomponents-base/dist/asset-registries/LocaleData.js";
2
+
3
+ const loadResource = moduleName => {
4
+ const moduleFormat = moduleName.match(/sap\/ui\/core\/cldr\/(\w+)\.json/);
5
+ if (!moduleFormat) {
6
+ throw new Error(`Unknown module "${moduleName}"`);
7
+ }
8
+
9
+ const localeId = moduleFormat[1];
10
+ return getLocaleData(localeId);
11
+ };
2
12
 
3
13
  const LoaderExtensions = {
4
- loadResource: getModuleContent,
14
+ loadResource,
5
15
  };
6
16
 
7
17
  export default LoaderExtensions;
@@ -2,6 +2,7 @@ import { getLanguage } from "@ui5/webcomponents-base/dist/config/Language.js";
2
2
  import { getCalendarType } from "@ui5/webcomponents-base/dist/config/CalendarType.js";
3
3
  import getDesigntimePropertyAsArray from "@ui5/webcomponents-base/dist/util/getDesigntimePropertyAsArray.js";
4
4
  import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js";
5
+ import TimezoneUtil from "./format/TimezoneUtil.js";
5
6
 
6
7
  const emptyFn = () => {};
7
8
 
@@ -24,6 +25,7 @@ const Configuration = {
24
25
  getSupportedLanguages: () => getDesigntimePropertyAsArray("$core-i18n-locales:,ar,bg,ca,cs,da,de,el,en,es,et,fi,fr,hi,hr,hu,it,iw,ja,ko,lt,lv,nl,no,pl,pt,ro,ru,sh,sk,sl,sv,th,tr,uk,vi,zh_CN,zh_TW$"),
25
26
  getOriginInfo: emptyFn,
26
27
  getFormatSettings: () => FormatSettings,
28
+ getTimezone: () => TimezoneUtil.getLocalTimezone(),
27
29
  };
28
30
 
29
31
  /**
package/used-modules.txt CHANGED
@@ -22,4 +22,5 @@ sap/ui/core/date/Islamic.js
22
22
  sap/ui/core/date/Japanese.js
23
23
  sap/ui/core/date/Persian.js
24
24
  sap/ui/core/date/UniversalDate.js
25
+ sap/ui/core/format/TimezoneUtil.js
25
26
  sap/ui/core/format/DateFormat.js