@ui5/webcomponents-localization 0.0.0-de4752078 → 0.0.0-e58530409

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.
@@ -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
  }
@@ -162,8 +165,8 @@ UniversalDate.prototype.getTimezoneLong = function () {
162
165
  };
163
166
  var iMillisecondsInWeek = 7 * 24 * 60 * 60 * 1000;
164
167
  UniversalDate.getWeekByDate = function (sCalendarType, iYear, iMonth, iDay) {
165
- var oLocale = Core.getConfiguration().getFormatSettings().getFormatLocale(), clDate = this.getClass(sCalendarType), oFirstDay = getFirstDayOfFirstWeek(clDate, iYear), oDate = new clDate(clDate.UTC(iYear, iMonth, iDay)), iWeek, iLastYear, iNextYear, oLastFirstDay, oNextFirstDay;
166
- if (oLocale.getRegion() === 'US') {
168
+ var oLocale = Core.getConfiguration().getFormatSettings().getFormatLocale(), oLocaleData = LocaleData.getInstance(oLocale), clDate = this.getClass(sCalendarType), oFirstDay = getFirstDayOfFirstWeek(clDate, iYear), oDate = new clDate(clDate.UTC(iYear, iMonth, iDay)), iWeek, iLastYear, iNextYear, oLastFirstDay, oNextFirstDay;
169
+ if (oLocaleData.firstDayStartsFirstWeek()) {
167
170
  iWeek = calculateWeeks(oFirstDay, oDate);
168
171
  } else {
169
172
  iLastYear = iYear - 1;
@@ -186,8 +189,8 @@ UniversalDate.getWeekByDate = function (sCalendarType, iYear, iMonth, iDay) {
186
189
  };
187
190
  };
188
191
  UniversalDate.getFirstDateOfWeek = function (sCalendarType, iYear, iWeek) {
189
- var oLocale = Core.getConfiguration().getFormatSettings().getFormatLocale(), clDate = this.getClass(sCalendarType), oFirstDay = getFirstDayOfFirstWeek(clDate, iYear), oDate = new clDate(oFirstDay.valueOf() + iWeek * iMillisecondsInWeek);
190
- if (oLocale.getRegion() === 'US' && iWeek === 0 && oFirstDay.getUTCFullYear() < iYear) {
192
+ var oLocale = Core.getConfiguration().getFormatSettings().getFormatLocale(), oLocaleData = LocaleData.getInstance(oLocale), clDate = this.getClass(sCalendarType), oFirstDay = getFirstDayOfFirstWeek(clDate, iYear), oDate = new clDate(oFirstDay.valueOf() + iWeek * iMillisecondsInWeek), bIsRegionUS = oLocaleData.firstDayStartsFirstWeek();
193
+ if (bIsRegionUS && iWeek === 0 && oFirstDay.getUTCFullYear() < iYear) {
191
194
  return {
192
195
  year: iYear,
193
196
  month: 0,
@@ -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--;