@ui5/webcomponents-localization 1.3.1 → 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,33 @@
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
+
17
+ # [1.5.0](https://github.com/SAP/ui5-webcomponents/compare/v1.4.0...v1.5.0) (2022-07-03)
18
+
19
+ **Note:** Version bump only for package @ui5/webcomponents-localization
20
+
21
+
22
+
23
+
24
+
25
+ # [1.4.0](https://github.com/SAP/ui5-webcomponents/compare/v1.3.1...v1.4.0) (2022-05-25)
26
+
27
+ **Note:** Version bump only for package @ui5/webcomponents-localization
28
+
29
+
30
+
31
+
32
+
6
33
  ## [1.3.1](https://github.com/SAP/ui5-webcomponents/compare/v1.3.0...v1.3.1) (2022-04-27)
7
34
 
8
35
  **Note:** Version bump only for package @ui5/webcomponents-localization
package/README.md CHANGED
@@ -1,8 +1,7 @@
1
- ![UI5 icon](https://raw.githubusercontent.com/SAP/ui5-webcomponents/master/docs/images/UI5_logo_wide.png)
1
+ ![UI5 icon](https://raw.githubusercontent.com/SAP/ui5-webcomponents/main/docs/images/UI5_logo_wide.png)
2
2
 
3
3
  # UI5 Web Components - Localization
4
4
 
5
- [![Travis CI Build Status](https://travis-ci.org/SAP/ui5-webcomponents.svg?branch=master)](https://travis-ci.org/SAP/ui5-webcomponents)
6
5
  [![npm Package Version](https://badge.fury.io/js/%40ui5%2Fwebcomponents.svg)](https://www.npmjs.com/package/@ui5/webcomponents)
7
6
 
8
7
  Provides date/time and CLDR functionality for the purposes of building UI5 Web Components.
@@ -39,16 +38,16 @@ In order to be able to use Buddhist, Islamic, Japanese, or Persian calendar with
39
38
  (by setting its `primaryCalendarType` property), you must import one or more of the modules above.
40
39
 
41
40
  ## Resources
42
- - [UI5 Web Components - README.md](https://github.com/SAP/ui5-webcomponents/blob/master/README.md)
41
+ - [UI5 Web Components - README.md](https://github.com/SAP/ui5-webcomponents/blob/main/README.md)
43
42
  - [UI5 Web Components - Home Page](https://sap.github.io/ui5-webcomponents)
44
43
  - [UI5 Web Components - Playground and API Reference](https://sap.github.io/ui5-webcomponents/playground/)
45
44
 
46
45
  ## Support
47
- We welcome all comments, suggestions, questions, and bug reports. Please follow our [Support Guidelines](https://github.com/SAP/ui5-webcomponents/blob/master/SUPPORT.md#-content) on how to report an issue, or chat with us in the `#webcomponents` channel of the [OpenUI5 Community Slack](https://join-ui5-slack.herokuapp.com/).
46
+ We welcome all comments, suggestions, questions, and bug reports. Please follow our [Support Guidelines](https://github.com/SAP/ui5-webcomponents/blob/main/SUPPORT.md#-content) on how to report an issue, or chat with us in the `#webcomponents` channel of the [OpenUI5 Community Slack](https://join-ui5-slack.herokuapp.com/).
48
47
 
49
48
  ## Contribute
50
- Please check our [Contribution Guidelines](https://github.com/SAP/ui5-webcomponents/blob/master/docs/6-contributing/02-conventions-and-guidelines.md).
49
+ Please check our [Contribution Guidelines](https://github.com/SAP/ui5-webcomponents/blob/main/docs/6-contributing/02-conventions-and-guidelines.md).
51
50
 
52
51
  ## License
53
52
  Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.
54
- This file is licensed under the Apache Software License, Version 2.0 except as noted otherwise in the [LICENSE](https://github.com/SAP/ui5-webcomponents/blob/master/LICENSE.txt) file.
53
+ This file is licensed under the Apache Software License, Version 2.0 except as noted otherwise in the [LICENSE](https://github.com/SAP/ui5-webcomponents/blob/main/LICENSE.txt) file.
@@ -177,7 +177,13 @@ class CalendarDate {
177
177
 
178
178
  static fromTimestamp(iTimestamp, sCalendarType) {
179
179
  const oCalDate = new CalendarDate(0, 0, 1);
180
- 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;
181
187
  return oCalDate;
182
188
  }
183
189
  }
@@ -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;
@@ -4914,7 +4914,7 @@
4914
4914
  "one": "i = 1 and v = 0"
4915
4915
  },
4916
4916
  "weekData-minDays": 1,
4917
- "weekData-firstDay": 0,
4917
+ "weekData-firstDay": 1,
4918
4918
  "weekData-weekendStart": 6,
4919
4919
  "weekData-weekendEnd": 0,
4920
4920
  "timeData": {
@@ -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
  /**
@@ -1,5 +1,6 @@
1
1
  import BaseObject from '../base/Object.js';
2
2
  import assert from '../../base/assert.js';
3
+ import CalendarType from './CalendarType.js';
3
4
  var rLocale = /^((?:[A-Z]{2,3}(?:-[A-Z]{3}){0,3})|[A-Z]{4}|[A-Z]{5,8})(?:-([A-Z]{4}))?(?:-([A-Z]{2}|[0-9]{3}))?((?:-[0-9A-Z]{5,8}|-[0-9][0-9A-Z]{3})*)((?:-[0-9A-WYZ](?:-[0-9A-Z]{2,8})+)*)(?:-(X(?:-[0-9A-Z]{1,8})+))?$/i;
4
5
  var Locale = BaseObject.extend('sap.ui.core.Locale', {
5
6
  constructor: function (sLocaleId) {
@@ -83,6 +84,9 @@ var Locale = BaseObject.extend('sap.ui.core.Locale', {
83
84
  return 'ZF';
84
85
  }
85
86
  return M_LOCALE_TO_ABAP_LANGUAGE[join(sLanguage, this.sScript)] || M_LOCALE_TO_ABAP_LANGUAGE[join(sLanguage, this.sRegion)] || M_LOCALE_TO_ABAP_LANGUAGE[getPseudoLanguageTag(this.sPrivateUse)] || sLanguage.toUpperCase();
87
+ },
88
+ getPreferredCalendarType: function () {
89
+ return Locale._mPreferredCalendar[this.getLanguage() + '-' + this.getRegion()] || Locale._mPreferredCalendar[this.getLanguage()] || Locale._mPreferredCalendar['default'];
86
90
  }
87
91
  });
88
92
  function getPseudoLanguageTag(sPrivateUse) {
@@ -114,6 +118,12 @@ function getDesigntimePropertyAsArray(sValue) {
114
118
  }
115
119
  var A_RTL_LOCALES = getDesigntimePropertyAsArray('$cldr-rtl-locales:ar,fa,he$') || [];
116
120
  Locale._cldrLocales = getDesigntimePropertyAsArray('$cldr-locales:ar,ar_EG,ar_SA,bg,ca,cy,cs,da,de,de_AT,de_CH,el,el_CY,en,en_AU,en_GB,en_HK,en_IE,en_IN,en_NZ,en_PG,en_SG,en_ZA,es,es_AR,es_BO,es_CL,es_CO,es_MX,es_PE,es_UY,es_VE,et,fa,fi,fr,fr_BE,fr_CA,fr_CH,fr_LU,he,hi,hr,hu,id,it,it_CH,ja,kk,ko,lt,lv,ms,nb,nl,nl_BE,pl,pt,pt_PT,ro,ru,ru_UA,sk,sl,sr,sr_Latn,sv,th,tr,uk,vi,zh_CN,zh_HK,zh_SG,zh_TW$');
121
+ Locale._mPreferredCalendar = {
122
+ 'ar-SA': CalendarType.Islamic,
123
+ 'fa': CalendarType.Persian,
124
+ 'th': CalendarType.Buddhist,
125
+ 'default': CalendarType.Gregorian
126
+ };
117
127
  Locale._coreI18nLocales = getDesigntimePropertyAsArray('$core-i18n-locales:,ar,bg,ca,cs,da,de,el,en,en_GB,es,es_MX,et,fi,fr,hi,hr,hu,it,iw,ja,kk,ko,lt,lv,ms,nl,no,pl,pt,ro,ru,sh,sk,sl,sv,th,tr,uk,vi,zh_CN,zh_TW$');
118
128
  Locale._impliesRTL = function (vLanguage) {
119
129
  var oLocale = vLanguage instanceof Locale ? vLanguage : new Locale(vLanguage);
@@ -9,7 +9,9 @@ var LocaleData = BaseObject.extend('sap.ui.core.LocaleData', {
9
9
  constructor: function (oLocale) {
10
10
  this.oLocale = oLocale;
11
11
  BaseObject.apply(this);
12
- this.mData = getData(oLocale);
12
+ var oDataLoaded = getData(oLocale);
13
+ this.mData = oDataLoaded.mData;
14
+ this.sCLDRLocaleId = oDataLoaded.sCLDRLocaleId;
13
15
  },
14
16
  _get: function () {
15
17
  return this._getDeep(this.mData, arguments);
@@ -109,6 +111,20 @@ var LocaleData = BaseObject.extend('sap.ui.core.LocaleData', {
109
111
  var sDateTimePattern = this.getDateTimePattern(sDateStyle, sCalendarType), sDatePattern = this.getDatePattern(sDateStyle, sCalendarType), sTimePattern = this.getTimePattern(sTimeStyle, sCalendarType);
110
112
  return sDateTimePattern.replace('{0}', sTimePattern).replace('{1}', sDatePattern);
111
113
  },
114
+ getCombinedDateTimeWithTimezonePattern: function (sDateStyle, sTimeStyle, sCalendarType) {
115
+ return this.applyTimezonePattern(this.getCombinedDateTimePattern(sDateStyle, sTimeStyle, sCalendarType));
116
+ },
117
+ applyTimezonePattern: function (sPattern) {
118
+ var aPatterns = [sPattern];
119
+ var aMissingTokens = [{
120
+ group: 'Timezone',
121
+ length: 2,
122
+ field: 'zone',
123
+ symbol: 'V'
124
+ }];
125
+ this._appendItems(aPatterns, aMissingTokens);
126
+ return aPatterns[0];
127
+ },
112
128
  getCustomDateTimePattern: function (sSkeleton, sCalendarType) {
113
129
  var oAvailableFormats = this._get(getCLDRCalendarName(sCalendarType), 'dateTimeFormats', 'availableFormats');
114
130
  return this._getFormatPattern(sSkeleton, oAvailableFormats, sCalendarType);
@@ -1210,14 +1226,24 @@ function getData(oLocale) {
1210
1226
  sLanguage = 'sr_Latn';
1211
1227
  }
1212
1228
  var sId = sLanguage + '_' + sRegion;
1229
+ var sCLDRLocaleId = sId;
1213
1230
  if (sLanguage && sRegion) {
1214
1231
  mData = getOrLoad(sId);
1215
1232
  }
1216
1233
  if (!mData && sLanguage) {
1217
1234
  mData = getOrLoad(sLanguage);
1235
+ sCLDRLocaleId = sLanguage;
1236
+ }
1237
+ if (!mData) {
1238
+ mData = getOrLoad('en');
1239
+ sCLDRLocaleId = 'en';
1218
1240
  }
1219
- mLocaleDatas[sId] = mData || getOrLoad('en');
1220
- return mLocaleDatas[sId];
1241
+ mLocaleDatas[sId] = mData;
1242
+ sCLDRLocaleId = sCLDRLocaleId.replace(/_/g, '-');
1243
+ return {
1244
+ mData: mData,
1245
+ sCLDRLocaleId: sCLDRLocaleId
1246
+ };
1221
1247
  }
1222
1248
  var CustomLocaleData = LocaleData.extend('sap.ui.core.CustomLocaleData', {
1223
1249
  constructor: function (oLocale) {
@@ -42,6 +42,9 @@ UniversalDate.getInstance = function (oDate, sCalendarType) {
42
42
  } else if (!oDate) {
43
43
  oDate = new Date();
44
44
  }
45
+ if (isNaN(oDate.getTime())) {
46
+ throw new Error('The given date object is invalid');
47
+ }
45
48
  if (!sCalendarType) {
46
49
  sCalendarType = Core.getConfiguration().getCalendarType();
47
50
  }
@@ -202,6 +205,9 @@ UniversalDate.getFirstDateOfWeek = function (sCalendarType, iYear, iWeek) {
202
205
  };
203
206
  function getFirstDayOfFirstWeek(clDate, iYear) {
204
207
  var oLocale = Core.getConfiguration().getFormatSettings().getFormatLocale(), oLocaleData = LocaleData.getInstance(oLocale), iMinDays = oLocaleData.getMinimalDaysInFirstWeek(), iFirstDayOfWeek = oLocaleData.getFirstDayOfWeek(), oFirstDay = new clDate(clDate.UTC(iYear, 0, 1)), iDayCount = 7;
208
+ if (isNaN(oFirstDay.getTime())) {
209
+ throw new Error('Could not determine the first day of the week, because the date ' + 'object is invalid');
210
+ }
205
211
  while (oFirstDay.getUTCDay() !== iFirstDayOfWeek) {
206
212
  oFirstDay.setUTCDate(oFirstDay.getUTCDate() - 1);
207
213
  iDayCount--;