@ui5/webcomponents-localization 1.9.3 → 1.10.1

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 (197) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE.txt +201 -0
  3. package/dist/Assets-static.d.ts +1 -0
  4. package/dist/Assets-static.js +1 -0
  5. package/dist/Assets-static.js.map +1 -0
  6. package/dist/Assets.d.ts +1 -0
  7. package/dist/Assets.js +1 -0
  8. package/dist/Assets.js.map +1 -0
  9. package/dist/DateFormat.d.ts +6 -0
  10. package/dist/DateFormat.js +6 -2
  11. package/dist/DateFormat.js.map +1 -0
  12. package/dist/LocaleData.d.ts +6 -0
  13. package/dist/LocaleData.js +6 -2
  14. package/dist/LocaleData.js.map +1 -0
  15. package/dist/dates/CalendarDate.d.ts +41 -0
  16. package/dist/dates/CalendarDate.js +170 -207
  17. package/dist/dates/CalendarDate.js.map +1 -0
  18. package/dist/dates/ExtremeDates.d.ts +5 -0
  19. package/dist/dates/ExtremeDates.js +25 -35
  20. package/dist/dates/ExtremeDates.js.map +1 -0
  21. package/dist/dates/UniversalDate.d.ts +46 -0
  22. package/dist/dates/UniversalDate.js +5 -0
  23. package/dist/dates/UniversalDate.js.map +1 -0
  24. package/dist/dates/calculateWeekNumber.d.ts +4 -0
  25. package/dist/dates/calculateWeekNumber.js +42 -48
  26. package/dist/dates/calculateWeekNumber.js.map +1 -0
  27. package/dist/dates/convertMonthNumbersToMonthNames.d.ts +16 -0
  28. package/dist/dates/convertMonthNumbersToMonthNames.js +15 -18
  29. package/dist/dates/convertMonthNumbersToMonthNames.js.map +1 -0
  30. package/dist/dates/getDaysInMonth.d.ts +3 -0
  31. package/dist/dates/getDaysInMonth.js +7 -8
  32. package/dist/dates/getDaysInMonth.js.map +1 -0
  33. package/dist/dates/getRoundedTimestamp.d.ts +7 -0
  34. package/dist/dates/getRoundedTimestamp.js +9 -9
  35. package/dist/dates/getRoundedTimestamp.js.map +1 -0
  36. package/dist/dates/getTodayUTCTimestamp.d.ts +7 -0
  37. package/dist/dates/getTodayUTCTimestamp.js +2 -3
  38. package/dist/dates/getTodayUTCTimestamp.js.map +1 -0
  39. package/dist/dates/modifyDateBy.d.ts +13 -0
  40. package/dist/dates/modifyDateBy.js +27 -29
  41. package/dist/dates/modifyDateBy.js.map +1 -0
  42. package/dist/dates/transformDateToSecondaryType.d.ts +7 -0
  43. package/dist/dates/transformDateToSecondaryType.js +12 -15
  44. package/dist/dates/transformDateToSecondaryType.js.map +1 -0
  45. package/{src/features/calendar/Buddhist.js → dist/features/calendar/Buddhist.d.ts} +0 -0
  46. package/dist/features/calendar/Buddhist.js +1 -0
  47. package/dist/features/calendar/Buddhist.js.map +1 -0
  48. package/{src/features/calendar/Gregorian.js → dist/features/calendar/Gregorian.d.ts} +0 -0
  49. package/dist/features/calendar/Gregorian.js +1 -0
  50. package/dist/features/calendar/Gregorian.js.map +1 -0
  51. package/{src/features/calendar/Islamic.js → dist/features/calendar/Islamic.d.ts} +0 -0
  52. package/dist/features/calendar/Islamic.js +1 -0
  53. package/dist/features/calendar/Islamic.js.map +1 -0
  54. package/{src/features/calendar/Japanese.js → dist/features/calendar/Japanese.d.ts} +0 -0
  55. package/dist/features/calendar/Japanese.js +1 -0
  56. package/dist/features/calendar/Japanese.js.map +1 -0
  57. package/{src/features/calendar/Persian.js → dist/features/calendar/Persian.d.ts} +0 -0
  58. package/dist/features/calendar/Persian.js +1 -0
  59. package/dist/features/calendar/Persian.js.map +1 -0
  60. package/dist/generated/assets/cldr/ar.json +799 -1
  61. package/dist/generated/assets/cldr/ar_EG.json +799 -1
  62. package/dist/generated/assets/cldr/ar_SA.json +799 -1
  63. package/dist/generated/assets/cldr/bg.json +764 -1
  64. package/dist/generated/assets/cldr/ca.json +798 -1
  65. package/dist/generated/assets/cldr/cs.json +797 -1
  66. package/dist/generated/assets/cldr/cy.json +729 -1
  67. package/dist/generated/assets/cldr/da.json +764 -1
  68. package/dist/generated/assets/cldr/de.json +798 -1
  69. package/dist/generated/assets/cldr/de_AT.json +798 -1
  70. package/dist/generated/assets/cldr/de_CH.json +798 -1
  71. package/dist/generated/assets/cldr/el.json +697 -1
  72. package/dist/generated/assets/cldr/el_CY.json +697 -1
  73. package/dist/generated/assets/cldr/en.json +763 -2
  74. package/dist/generated/assets/cldr/en_AU.json +763 -1
  75. package/dist/generated/assets/cldr/en_GB.json +763 -1
  76. package/dist/generated/assets/cldr/en_HK.json +763 -1
  77. package/dist/generated/assets/cldr/en_IE.json +763 -1
  78. package/dist/generated/assets/cldr/en_IN.json +763 -1
  79. package/dist/generated/assets/cldr/en_NZ.json +763 -1
  80. package/dist/generated/assets/cldr/en_PG.json +763 -1
  81. package/dist/generated/assets/cldr/en_SG.json +763 -1
  82. package/dist/generated/assets/cldr/en_ZA.json +763 -1
  83. package/dist/generated/assets/cldr/es.json +730 -1
  84. package/dist/generated/assets/cldr/es_AR.json +730 -1
  85. package/dist/generated/assets/cldr/es_BO.json +733 -4
  86. package/dist/generated/assets/cldr/es_CL.json +733 -4
  87. package/dist/generated/assets/cldr/es_CO.json +730 -1
  88. package/dist/generated/assets/cldr/es_MX.json +733 -4
  89. package/dist/generated/assets/cldr/es_PE.json +733 -4
  90. package/dist/generated/assets/cldr/es_UY.json +733 -4
  91. package/dist/generated/assets/cldr/es_VE.json +732 -3
  92. package/dist/generated/assets/cldr/et.json +763 -1
  93. package/dist/generated/assets/cldr/fa.json +765 -1
  94. package/dist/generated/assets/cldr/fi.json +797 -1
  95. package/dist/generated/assets/cldr/fr.json +763 -1
  96. package/dist/generated/assets/cldr/fr_BE.json +763 -1
  97. package/dist/generated/assets/cldr/fr_CA.json +763 -1
  98. package/dist/generated/assets/cldr/fr_CH.json +763 -1
  99. package/dist/generated/assets/cldr/fr_LU.json +763 -1
  100. package/dist/generated/assets/cldr/he.json +798 -1
  101. package/dist/generated/assets/cldr/hi.json +730 -1
  102. package/dist/generated/assets/cldr/hr.json +763 -1
  103. package/dist/generated/assets/cldr/hu.json +831 -1
  104. package/dist/generated/assets/cldr/id.json +763 -1
  105. package/dist/generated/assets/cldr/it.json +763 -1
  106. package/dist/generated/assets/cldr/it_CH.json +763 -1
  107. package/dist/generated/assets/cldr/ja.json +797 -1
  108. package/dist/generated/assets/cldr/kk.json +763 -1
  109. package/dist/generated/assets/cldr/ko.json +797 -1
  110. package/dist/generated/assets/cldr/lt.json +763 -1
  111. package/dist/generated/assets/cldr/lv.json +763 -1
  112. package/dist/generated/assets/cldr/ms.json +731 -1
  113. package/dist/generated/assets/cldr/nb.json +764 -1
  114. package/dist/generated/assets/cldr/nl.json +730 -1
  115. package/dist/generated/assets/cldr/nl_BE.json +730 -1
  116. package/dist/generated/assets/cldr/pl.json +797 -1
  117. package/dist/generated/assets/cldr/pt.json +763 -1
  118. package/dist/generated/assets/cldr/pt_PT.json +763 -1
  119. package/dist/generated/assets/cldr/ro.json +763 -1
  120. package/dist/generated/assets/cldr/ru.json +763 -1
  121. package/dist/generated/assets/cldr/ru_UA.json +763 -1
  122. package/dist/generated/assets/cldr/sk.json +797 -1
  123. package/dist/generated/assets/cldr/sl.json +797 -1
  124. package/dist/generated/assets/cldr/sr.json +763 -1
  125. package/dist/generated/assets/cldr/sr_Latn.json +763 -1
  126. package/dist/generated/assets/cldr/sv.json +764 -1
  127. package/dist/generated/assets/cldr/th.json +831 -1
  128. package/dist/generated/assets/cldr/tr.json +831 -1
  129. package/dist/generated/assets/cldr/uk.json +763 -1
  130. package/dist/generated/assets/cldr/vi.json +763 -1
  131. package/dist/generated/assets/cldr/zh_CN.json +799 -2
  132. package/dist/generated/assets/cldr/zh_HK.json +799 -2
  133. package/dist/generated/assets/cldr/zh_SG.json +799 -2
  134. package/dist/generated/assets/cldr/zh_TW.json +798 -1
  135. package/dist/getCachedLocaleDataInstance.d.ts +4 -0
  136. package/dist/getCachedLocaleDataInstance.js +6 -9
  137. package/dist/getCachedLocaleDataInstance.js.map +1 -0
  138. package/dist/locale/getLocaleData.d.ts +11 -0
  139. package/dist/locale/getLocaleData.js +12 -16
  140. package/dist/locale/getLocaleData.js.map +1 -0
  141. package/dist/sap/base/Log.js +28 -29
  142. package/dist/sap/base/assert.js +5 -6
  143. package/dist/sap/base/util/LoaderExtensions.d.ts +4 -0
  144. package/dist/sap/base/util/LoaderExtensions.js +9 -12
  145. package/dist/sap/base/util/LoaderExtensions.js.map +1 -0
  146. package/dist/sap/ui/core/Configuration.d.ts +17 -0
  147. package/dist/sap/ui/core/Configuration.js +20 -0
  148. package/dist/sap/ui/core/Configuration.js.map +1 -0
  149. package/dist/sap/ui/core/Core.d.ts +26 -0
  150. package/dist/sap/ui/core/Core.js +7 -34
  151. package/dist/sap/ui/core/Core.js.map +1 -0
  152. package/dist/sap/ui/core/FormatSettings.d.ts +10 -0
  153. package/dist/sap/ui/core/FormatSettings.js +13 -0
  154. package/dist/sap/ui/core/FormatSettings.js.map +1 -0
  155. package/dist/sap/ui/core/Locale.js +3 -0
  156. package/dist/sap/ui/core/LocaleData.js +78 -3
  157. package/dist/sap/ui/core/date/Buddhist.js +0 -6
  158. package/dist/sap/ui/core/date/CalendarUtils.js +36 -0
  159. package/dist/sap/ui/core/date/CalendarWeekNumbering.js +7 -0
  160. package/dist/sap/ui/core/date/Islamic.js +3 -3
  161. package/dist/sap/ui/core/date/Japanese.js +4 -4
  162. package/dist/sap/ui/core/date/UniversalDate.js +73 -22
  163. package/dist/sap/ui/core/format/DateFormat.js +157 -57
  164. package/dist/sap/ui/core/format/TimezoneUtil.js +12 -1
  165. package/package-scripts.js +5 -2
  166. package/package.json +9 -7
  167. package/src/{Assets-static.js → Assets-static.ts} +0 -0
  168. package/src/{Assets.js → Assets.ts} +0 -0
  169. package/src/DateFormat.ts +8 -0
  170. package/src/LocaleData.ts +8 -0
  171. package/src/dates/{CalendarDate.js → CalendarDate.ts} +36 -33
  172. package/src/dates/{ExtremeDates.js → ExtremeDates.ts} +6 -5
  173. package/src/dates/UniversalDate.ts +51 -0
  174. package/src/dates/{calculateWeekNumber.js → calculateWeekNumber.ts} +5 -3
  175. package/src/dates/{convertMonthNumbersToMonthNames.js → convertMonthNumbersToMonthNames.ts} +5 -4
  176. package/src/dates/{getDaysInMonth.js → getDaysInMonth.ts} +1 -1
  177. package/src/dates/{getRoundedTimestamp.js → getRoundedTimestamp.ts} +3 -3
  178. package/src/dates/getTodayUTCTimestamp.ts +10 -0
  179. package/src/dates/{modifyDateBy.js → modifyDateBy.ts} +1 -1
  180. package/src/dates/{transformDateToSecondaryType.js → transformDateToSecondaryType.ts} +2 -1
  181. package/src/features/calendar/Buddhist.ts +1 -0
  182. package/src/features/calendar/Gregorian.ts +1 -0
  183. package/src/features/calendar/Islamic.ts +1 -0
  184. package/src/features/calendar/Japanese.ts +1 -0
  185. package/src/features/calendar/Persian.ts +1 -0
  186. package/src/getCachedLocaleDataInstance.ts +15 -0
  187. package/src/locale/{getLocaleData.js → getLocaleData.ts} +8 -7
  188. package/src/sap/base/util/{LoaderExtensions.js → LoaderExtensions.ts} +1 -1
  189. package/src/sap/ui/core/{Core.js → Configuration.ts} +4 -22
  190. package/src/sap/ui/core/Core.ts +15 -0
  191. package/src/sap/ui/core/FormatSettings.ts +15 -0
  192. package/tsconfig.json +13 -0
  193. package/used-modules.txt +3 -1
  194. package/src/DateFormat.js +0 -3
  195. package/src/LocaleData.js +0 -3
  196. package/src/dates/getTodayUTCTimestamp.js +0 -9
  197. package/src/getCachedLocaleDataInstance.js +0 -13
@@ -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 UniversalDate from "../sap/ui/core/date/UniversalDate.js";
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
- constructor() {
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 sap.ui.unified.calendar.CalendarDate.");
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;
@@ -79,7 +82,7 @@ class CalendarDate {
79
82
  * Other value will result in adding or subtracting days according to the given value.
80
83
  * @returns {sap.ui.unified.calendar.CalendarDate} <code>this</code> for method chaining.
81
84
  */
82
- setMonth(month, date) {
85
+ setMonth(month: number, date?: number) {
83
86
  checkNumericLike(month, `Invalid month: ${month}`);
84
87
  if (date || date === 0) {
85
88
  checkNumericLike(date, `Invalid date: ${date}`);
@@ -94,7 +97,7 @@ class CalendarDate {
94
97
  return this._oUDate.getUTCDate();
95
98
  }
96
99
 
97
- setDate(date) {
100
+ setDate(date: number) {
98
101
  checkNumericLike(date, `Invalid date: ${date}`);
99
102
  this._oUDate.setUTCDate(date);
100
103
  return this;
@@ -105,30 +108,30 @@ class CalendarDate {
105
108
  }
106
109
 
107
110
  getCalendarType() {
108
- return this._oUDate.sCalendarType;
111
+ return (this._oUDate as UniversalDate).sCalendarType;
109
112
  }
110
113
 
111
- isBefore(oCalendarDate) {
114
+ isBefore(oCalendarDate: CalendarDate) {
112
115
  checkCalendarDate(oCalendarDate);
113
116
  return this.valueOf() < oCalendarDate.valueOf();
114
117
  }
115
118
 
116
- isAfter(oCalendarDate) {
119
+ isAfter(oCalendarDate: CalendarDate) {
117
120
  checkCalendarDate(oCalendarDate);
118
121
  return this.valueOf() > oCalendarDate.valueOf();
119
122
  }
120
123
 
121
- isSameOrBefore(oCalendarDate) {
124
+ isSameOrBefore(oCalendarDate: CalendarDate) {
122
125
  checkCalendarDate(oCalendarDate);
123
126
  return this.valueOf() <= oCalendarDate.valueOf();
124
127
  }
125
128
 
126
- isSameOrAfter(oCalendarDate) {
129
+ isSameOrAfter(oCalendarDate: CalendarDate) {
127
130
  checkCalendarDate(oCalendarDate);
128
131
  return this.valueOf() >= oCalendarDate.valueOf();
129
132
  }
130
133
 
131
- isSame(oCalendarDate) {
134
+ isSame(oCalendarDate: CalendarDate) {
132
135
  checkCalendarDate(oCalendarDate);
133
136
  return this.valueOf() === oCalendarDate.valueOf();
134
137
  }
@@ -155,27 +158,27 @@ class CalendarDate {
155
158
  }
156
159
 
157
160
  toString() {
158
- 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()}`;
159
162
  }
160
163
 
161
164
  valueOf() {
162
165
  return this._oUDate.getTime();
163
166
  }
164
167
 
165
- static fromLocalJSDate(oJSDate, sCalendarType) {
168
+ static fromLocalJSDate(oJSDate: Date, sCalendarType?: CalendarType) {
166
169
  // Cross frame check for a date should be performed here otherwise setDateValue would fail in OPA tests
167
170
  // because Date object in the test is different than the Date object in the application (due to the iframe).
168
171
  // We can use jQuery.type or this method:
169
- function isValidDate(date) {
170
- 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
171
174
  }
172
175
  if (!isValidDate(oJSDate)) {
173
- 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}].`);
174
177
  }
175
178
  return new CalendarDate(oJSDate.getFullYear(), oJSDate.getMonth(), oJSDate.getDate(), sCalendarType);
176
179
  }
177
180
 
178
- static fromTimestamp(iTimestamp, sCalendarType) {
181
+ static fromTimestamp(iTimestamp: number, sCalendarType?: CalendarType) {
179
182
  const oCalDate = new CalendarDate(0, 0, 1);
180
183
  let oUDate;
181
184
  try {
@@ -188,7 +191,7 @@ class CalendarDate {
188
191
  }
189
192
  }
190
193
 
191
- function createUniversalUTCDate(oDate, sCalendarType) {
194
+ function createUniversalUTCDate(oDate: Date, sCalendarType: CalendarType) {
192
195
  if (sCalendarType) {
193
196
  return UniversalDate.getInstance(createUTCDate(oDate), sCalendarType);
194
197
  }
@@ -200,7 +203,7 @@ function createUniversalUTCDate(oDate, sCalendarType) {
200
203
  * @param {Date} oDate JavaScript date object. Time related information is cut.
201
204
  * @returns {Date} JavaScript date created from the date object, but this time considered as UTC date information.
202
205
  */
203
- function createUTCDate(oDate) {
206
+ function createUTCDate(oDate: Date) {
204
207
  const oUTCDate = new Date(Date.UTC(0, 0, 1));
205
208
 
206
209
  oUTCDate.setUTCFullYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate());
@@ -208,9 +211,9 @@ function createUTCDate(oDate) {
208
211
  return oUTCDate;
209
212
  }
210
213
 
211
- function checkCalendarDate(oCalendarDate) {
214
+ function checkCalendarDate(oCalendarDate: CalendarDate) {
212
215
  if (!(oCalendarDate instanceof CalendarDate)) {
213
- throw new Error(`Invalid calendar date: [${oCalendarDate}]. Expected: sap.ui.unified.calendar.CalendarDate`);
216
+ throw new Error(`Invalid calendar date: [${oCalendarDate as unknown as string}]. Expected: CalendarDate`);
214
217
  }
215
218
  }
216
219
 
@@ -220,7 +223,7 @@ function checkCalendarDate(oCalendarDate) {
220
223
  * @param {string} message The message to be used if an error is to be thrown
221
224
  * @throws will throw an error if the value is null or undefined or is not like a number
222
225
  */
223
- function checkNumericLike(value, message) {
226
+ function checkNumericLike(value: any, message: string) {
224
227
  if (value === undefined || value === Infinity || isNaN(value)) { // eslint-disable-line
225
228
  throw message;
226
229
  }
@@ -1,8 +1,9 @@
1
+ import CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
1
2
  import CalendarDate from "./CalendarDate.js";
2
3
 
3
- const cache = new Map();
4
+ const cache = new Map<string, CalendarDate>();
4
5
 
5
- const getMinCalendarDate = primaryCalendarType => {
6
+ const getMinCalendarDate = (primaryCalendarType: CalendarType) => {
6
7
  const key = `min ${primaryCalendarType}`;
7
8
 
8
9
  if (!cache.has(key)) {
@@ -13,10 +14,10 @@ const getMinCalendarDate = primaryCalendarType => {
13
14
  cache.set(key, minDate);
14
15
  }
15
16
 
16
- return cache.get(key);
17
+ return cache.get(key)!;
17
18
  };
18
19
 
19
- const getMaxCalendarDate = primaryCalendarType => {
20
+ const getMaxCalendarDate = (primaryCalendarType: CalendarType) => {
20
21
  const key = `max ${primaryCalendarType}`;
21
22
 
22
23
  if (!cache.has(key)) {
@@ -30,7 +31,7 @@ const getMaxCalendarDate = primaryCalendarType => {
30
31
  cache.set(key, maxDate);
31
32
  }
32
33
 
33
- return cache.get(key);
34
+ return cache.get(key)!;
34
35
  };
35
36
 
36
37
  export {
@@ -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 UniversalDate from "../sap/ui/core/date/UniversalDate.js";
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
@@ -1,4 +1,5 @@
1
1
  import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js";
2
+ import type CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
2
3
  import getCachedLocaleDataInstance from "../getCachedLocaleDataInstance.js";
3
4
 
4
5
  /**
@@ -11,11 +12,11 @@ import getCachedLocaleDataInstance from "../getCachedLocaleDataInstance.js";
11
12
  * @param calendarType calendar type
12
13
  * @returns {String}
13
14
  */
14
- const convertMonthNumbersToMonthNames = (firstMonth, lastMonth, calendarType) => {
15
+ const convertMonthNumbersToMonthNames = (firstMonth: number, lastMonth: number, calendarType?: CalendarType) => {
15
16
  const localeData = getCachedLocaleDataInstance(getLocale());
16
- const pattern = localeData.getIntervalPattern();
17
- const secondaryMonthsNames = localeData.getMonthsStandAlone("abbreviated", calendarType);
18
- const secondaryMonthsNamesWide = localeData.getMonthsStandAlone("wide", calendarType);
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>;
19
20
 
20
21
  if (firstMonth === lastMonth) {
21
22
  return {
@@ -1,6 +1,6 @@
1
1
  import CalendarDate from "./CalendarDate.js";
2
2
 
3
- const getDaysInMonth = date => {
3
+ const getDaysInMonth = (date: CalendarDate) => {
4
4
  const tempCalendarDate = new CalendarDate(date);
5
5
  tempCalendarDate.setDate(1);
6
6
  tempCalendarDate.setMonth(tempCalendarDate.getMonth() + 1);
@@ -1,9 +1,9 @@
1
1
  /**
2
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}
3
+ * @param { number } millisecondsUTC
4
+ * @returns { number }
5
5
  */
6
- const getRoundedTimestamp = millisecondsUTC => {
6
+ const getRoundedTimestamp = (millisecondsUTC: number) => {
7
7
  if (!millisecondsUTC) {
8
8
  millisecondsUTC = new Date().getTime();
9
9
  }
@@ -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;
@@ -10,7 +10,7 @@ import CalendarDate from "./CalendarDate.js";
10
10
  * @param minDate minimum date to enforce
11
11
  * @param maxDate maximum date to enforce
12
12
  */
13
- const modifyDateBy = (date, amount, unit, minDate = null, maxDate = null) => {
13
+ const modifyDateBy = (date: CalendarDate, amount: number, unit: string, minDate?: CalendarDate, maxDate?: CalendarDate) => {
14
14
  const newDate = new CalendarDate(date);
15
15
  if (unit === "day") {
16
16
  newDate.setDate(date.getDate() + amount);
@@ -1,7 +1,8 @@
1
+ import type CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
1
2
  import CalendarDate from "./CalendarDate.js";
2
3
  import getDaysInMonth from "./getDaysInMonth.js";
3
4
 
4
- const transformDateToSecondaryType = (primaryCalendarType, secondaryCalendarType, timeStamp, hasYearPicker) => {
5
+ const transformDateToSecondaryType = (primaryCalendarType: CalendarType | undefined, secondaryCalendarType: CalendarType| undefined, timeStamp: number, hasYearPicker?: boolean) => {
5
6
  let firstDate = CalendarDate.fromLocalJSDate(new Date(timeStamp * 1000), primaryCalendarType);
6
7
  let lastDate = CalendarDate.fromLocalJSDate(new Date(timeStamp * 1000), primaryCalendarType);
7
8
  firstDate.setDate(1);
@@ -0,0 +1 @@
1
+ import "../../sap/ui/core/date/Buddhist.js";
@@ -0,0 +1 @@
1
+ import "../../sap/ui/core/date/Gregorian.js";
@@ -0,0 +1 @@
1
+ import "../../sap/ui/core/date/Islamic.js";
@@ -0,0 +1 @@
1
+ import "../../sap/ui/core/date/Japanese.js";
@@ -0,0 +1 @@
1
+ import "../../sap/ui/core/date/Persian.js";
@@ -0,0 +1,15 @@
1
+ import type Locale from "@ui5/webcomponents-base/dist/locale/Locale.js";
2
+ import type LocaleT from "sap/ui/core/Locale";
3
+ import LocaleData from "./LocaleData.js";
4
+
5
+ const cache = new Map<Locale, LocaleData>();
6
+
7
+ const getCachedLocaleDataInstance = (locale: Locale) => {
8
+ if (!cache.has(locale)) {
9
+ cache.set(locale, new LocaleData(locale as unknown as LocaleT));
10
+ }
11
+
12
+ return cache.get(locale)!;
13
+ };
14
+
15
+ export default getCachedLocaleDataInstance;
@@ -1,27 +1,28 @@
1
1
  import { fetchCldr } from "@ui5/webcomponents-base/dist/asset-registries/LocaleData.js";
2
2
  import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js";
3
- import LocaleData from "../sap/ui/core/LocaleData.js";
3
+ import type LocaleT from "sap/ui/core/Locale";
4
+ import LocaleData from "../LocaleData.js";
4
5
 
5
- const instances = new Map();
6
+ const instances = new Map<string, LocaleData>();
6
7
 
7
8
  /**
8
9
  * Fetches and returns а LocaleData object for the required locale
9
10
  * For more information on this object's API, please see:
10
11
  * https://sdk.openui5.org/api/sap.ui.core.LocaleData
11
12
  *
12
- * @param lang - if left empty, will use the configured/current locale
13
- * @returns {LocaleData}
13
+ * @param { string } lang - if left empty, will use the configured/current locale
14
+ * @returns { Promise<LocaleData> }
14
15
  */
15
- const getLocaleData = async lang => {
16
+ const getLocaleData = async (lang: string): Promise<LocaleData> => {
16
17
  const locale = getLocale(lang);
17
18
  const localeLang = locale.getLanguage();
18
19
 
19
20
  if (!instances.has(localeLang)) {
20
21
  await fetchCldr(locale.getLanguage(), locale.getRegion(), locale.getScript());
21
- instances.set(localeLang, LocaleData.getInstance(locale));
22
+ instances.set(localeLang, new LocaleData(locale as unknown as LocaleT));
22
23
  }
23
24
 
24
- return instances.get(localeLang);
25
+ return instances.get(localeLang)!;
25
26
  };
26
27
 
27
28
  export default getLocaleData;
@@ -1,6 +1,6 @@
1
1
  import { getLocaleData } from "@ui5/webcomponents-base/dist/asset-registries/LocaleData.js";
2
2
 
3
- const loadResource = moduleName => {
3
+ const loadResource = (moduleName: string) => {
4
4
  const moduleFormat = moduleName.match(/sap\/ui\/core\/cldr\/(\w+)\.json/);
5
5
  if (!moduleFormat) {
6
6
  throw new Error(`Unknown module "${moduleName}"`);
@@ -1,21 +1,12 @@
1
1
  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
- import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js";
4
+ // @ts-ignore
5
5
  import TimezoneUtil from "./format/TimezoneUtil.js";
6
+ import FormatSettings from "./FormatSettings.js";
6
7
 
7
8
  const emptyFn = () => {};
8
9
 
9
- /**
10
- * OpenUI5 FormatSettings shim
11
- */
12
- const FormatSettings = {
13
- getFormatLocale: getLocale,
14
- getLegacyDateFormat: emptyFn,
15
- getLegacyDateCalendarCustomizing: emptyFn,
16
- getCustomLocaleData: emptyFn,
17
- };
18
-
19
10
  /**
20
11
  * OpenUI5 Configuration Shim
21
12
  */
@@ -25,16 +16,7 @@ const Configuration = {
25
16
  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$"),
26
17
  getOriginInfo: emptyFn,
27
18
  getFormatSettings: () => FormatSettings,
28
- getTimezone: () => TimezoneUtil.getLocalTimezone(),
29
- };
30
-
31
- /**
32
- * OpenUI5 Core shim
33
- */
34
- const Core = {
35
- getConfiguration: () => Configuration,
36
- getLibraryResourceBundle: emptyFn(),
37
- getFormatSettings: () => FormatSettings,
19
+ getTimezone: () => TimezoneUtil.getLocalTimezone() as string,
38
20
  };
39
21
 
40
- export default Core;
22
+ export default Configuration;
@@ -0,0 +1,15 @@
1
+ import FormatSettings from "./FormatSettings.js";
2
+ import Configuration from "./Configuration.js";
3
+
4
+ const emptyFn = () => {};
5
+
6
+ /**
7
+ * OpenUI5 Core shim
8
+ */
9
+ const Core = {
10
+ getConfiguration: () => Configuration,
11
+ getLibraryResourceBundle: emptyFn(),
12
+ getFormatSettings: () => FormatSettings,
13
+ };
14
+
15
+ export default Core;
@@ -0,0 +1,15 @@
1
+ import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js";
2
+
3
+ const emptyFn = () => {};
4
+
5
+ /**
6
+ * OpenUI5 FormatSettings shim
7
+ */
8
+ const FormatSettings = {
9
+ getFormatLocale: getLocale,
10
+ getLegacyDateFormat: emptyFn,
11
+ getLegacyDateCalendarCustomizing: emptyFn,
12
+ getCustomLocaleData: emptyFn,
13
+ };
14
+
15
+ export default FormatSettings;
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "include": ["src/**/*"],
3
+ "compilerOptions": {
4
+ "target": "ES2021",
5
+ // Generate d.ts files
6
+ "declaration": true,
7
+ "outDir": "dist",
8
+ "skipLibCheck": true,
9
+ "sourceMap": true,
10
+ "strict": true,
11
+ "moduleResolution": "node",
12
+ },
13
+ }
package/used-modules.txt CHANGED
@@ -17,10 +17,12 @@ sap/ui/core/CalendarType.js
17
17
  sap/ui/core/Locale.js
18
18
  sap/ui/core/LocaleData.js
19
19
  sap/ui/core/date/Buddhist.js
20
+ sap/ui/core/date/CalendarUtils.js
21
+ sap/ui/core/date/CalendarWeekNumbering.js
20
22
  sap/ui/core/date/Gregorian.js
21
23
  sap/ui/core/date/Islamic.js
22
24
  sap/ui/core/date/Japanese.js
23
25
  sap/ui/core/date/Persian.js
24
26
  sap/ui/core/date/UniversalDate.js
25
27
  sap/ui/core/format/TimezoneUtil.js
26
- sap/ui/core/format/DateFormat.js
28
+ sap/ui/core/format/DateFormat.js
package/src/DateFormat.js DELETED
@@ -1,3 +0,0 @@
1
- import DateFormat from "./sap/ui/core/format/DateFormat.js";
2
-
3
- export default DateFormat;
package/src/LocaleData.js DELETED
@@ -1,3 +0,0 @@
1
- import LocaleData from "./sap/ui/core/LocaleData.js";
2
-
3
- export default LocaleData;
@@ -1,9 +0,0 @@
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;
@@ -1,13 +0,0 @@
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;