@ui5/webcomponents-localization 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.6.0](https://github.com/SAP/ui5-webcomponents/compare/v1.5.0...v1.6.0) (2022-07-25)
7
+
8
+
9
+ ### Features
10
+
11
+ * **ui5-calendar:** show months and years from both primary and secon… ([#5412](https://github.com/SAP/ui5-webcomponents/issues/5412)) ([d5dc7ec](https://github.com/SAP/ui5-webcomponents/commit/d5dc7ec))
12
+
13
+
14
+
15
+
16
+
6
17
  # [1.5.0](https://github.com/SAP/ui5-webcomponents/compare/v1.4.0...v1.5.0) (2022-07-03)
7
18
 
8
19
  **Note:** Version bump only for package @ui5/webcomponents-localization
@@ -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,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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/webcomponents-localization",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Localization for UI5 Web Components",
5
5
  "author": "SAP SE (https://www.sap.com)",
6
6
  "license": "Apache-2.0",
@@ -28,12 +28,12 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "@openui5/sap.ui.core": "1.101.0",
31
- "@ui5/webcomponents-tools": "1.5.0",
31
+ "@ui5/webcomponents-tools": "1.6.0",
32
32
  "chromedriver": "102.0.0",
33
33
  "mkdirp": "^1.0.4",
34
34
  "resolve": "^1.20.0"
35
35
  },
36
36
  "dependencies": {
37
- "@ui5/webcomponents-base": "1.5.0"
37
+ "@ui5/webcomponents-base": "1.6.0"
38
38
  }
39
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,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;