@ui5/webcomponents-localization 0.0.0-fb61e9889 → 0.0.0-fc993d8cd

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 (187) hide show
  1. package/.eslintignore +1 -1
  2. package/.npsrc.json +3 -0
  3. package/CHANGELOG.md +326 -0
  4. package/README.md +5 -6
  5. package/{src/Assets-static.js → dist/Assets-static.d.ts} +0 -1
  6. package/dist/Assets-static.js +1 -0
  7. package/dist/Assets-static.js.map +1 -0
  8. package/dist/Assets.d.ts +1 -0
  9. package/dist/Assets.js +1 -0
  10. package/dist/Assets.js.map +1 -0
  11. package/dist/DateFormat.d.ts +6 -0
  12. package/dist/DateFormat.js +6 -2
  13. package/dist/DateFormat.js.map +1 -0
  14. package/dist/LocaleData.d.ts +6 -0
  15. package/dist/LocaleData.js +6 -2
  16. package/dist/LocaleData.js.map +1 -0
  17. package/dist/dates/CalendarDate.d.ts +41 -0
  18. package/dist/dates/CalendarDate.js +170 -201
  19. package/dist/dates/CalendarDate.js.map +1 -0
  20. package/dist/dates/ExtremeDates.d.ts +5 -0
  21. package/dist/dates/ExtremeDates.js +25 -35
  22. package/dist/dates/ExtremeDates.js.map +1 -0
  23. package/dist/dates/UniversalDate.d.ts +46 -0
  24. package/dist/dates/UniversalDate.js +5 -0
  25. package/dist/dates/UniversalDate.js.map +1 -0
  26. package/dist/dates/calculateWeekNumber.d.ts +4 -0
  27. package/dist/dates/calculateWeekNumber.js +42 -48
  28. package/dist/dates/calculateWeekNumber.js.map +1 -0
  29. package/dist/dates/convertMonthNumbersToMonthNames.d.ts +16 -0
  30. package/dist/dates/convertMonthNumbersToMonthNames.js +30 -0
  31. package/dist/dates/convertMonthNumbersToMonthNames.js.map +1 -0
  32. package/dist/dates/getDaysInMonth.d.ts +3 -0
  33. package/dist/dates/getDaysInMonth.js +10 -0
  34. package/dist/dates/getDaysInMonth.js.map +1 -0
  35. package/dist/dates/getRoundedTimestamp.d.ts +7 -0
  36. package/dist/dates/getRoundedTimestamp.js +9 -9
  37. package/dist/dates/getRoundedTimestamp.js.map +1 -0
  38. package/dist/dates/getTodayUTCTimestamp.d.ts +7 -0
  39. package/dist/dates/getTodayUTCTimestamp.js +2 -3
  40. package/dist/dates/getTodayUTCTimestamp.js.map +1 -0
  41. package/dist/dates/modifyDateBy.d.ts +13 -0
  42. package/dist/dates/modifyDateBy.js +27 -29
  43. package/dist/dates/modifyDateBy.js.map +1 -0
  44. package/dist/dates/transformDateToSecondaryType.d.ts +7 -0
  45. package/dist/dates/transformDateToSecondaryType.js +17 -0
  46. package/dist/dates/transformDateToSecondaryType.js.map +1 -0
  47. package/dist/features/calendar/Buddhist.js +1 -0
  48. package/dist/features/calendar/Buddhist.js.map +1 -0
  49. package/dist/features/calendar/Gregorian.js +1 -0
  50. package/dist/features/calendar/Gregorian.js.map +1 -0
  51. package/dist/features/calendar/Islamic.js +1 -0
  52. package/dist/features/calendar/Islamic.js.map +1 -0
  53. package/dist/features/calendar/Japanese.js +1 -0
  54. package/dist/features/calendar/Japanese.js.map +1 -0
  55. package/dist/features/calendar/Persian.js +1 -0
  56. package/dist/features/calendar/Persian.js.map +1 -0
  57. package/dist/generated/assets/cldr/ar.json +2804 -5906
  58. package/dist/generated/assets/cldr/ar_EG.json +2804 -5906
  59. package/dist/generated/assets/cldr/ar_SA.json +2804 -5906
  60. package/dist/generated/assets/cldr/bg.json +2727 -4979
  61. package/dist/generated/assets/cldr/ca.json +2670 -4996
  62. package/dist/generated/assets/cldr/cs.json +2710 -5498
  63. package/dist/generated/assets/cldr/cy.json +2791 -5884
  64. package/dist/generated/assets/cldr/da.json +2591 -4888
  65. package/dist/generated/assets/cldr/de.json +2608 -4916
  66. package/dist/generated/assets/cldr/de_AT.json +2608 -4917
  67. package/dist/generated/assets/cldr/de_CH.json +2608 -4915
  68. package/dist/generated/assets/cldr/el.json +2589 -4883
  69. package/dist/generated/assets/cldr/el_CY.json +2589 -4883
  70. package/dist/generated/assets/cldr/en.json +2577 -4971
  71. package/dist/generated/assets/cldr/en_AU.json +2586 -4962
  72. package/dist/generated/assets/cldr/en_GB.json +2578 -4971
  73. package/dist/generated/assets/cldr/en_HK.json +2584 -4977
  74. package/dist/generated/assets/cldr/en_IE.json +2578 -4971
  75. package/dist/generated/assets/cldr/en_IN.json +2579 -4972
  76. package/dist/generated/assets/cldr/en_NZ.json +2578 -4971
  77. package/dist/generated/assets/cldr/en_PG.json +2578 -4972
  78. package/dist/generated/assets/cldr/en_SG.json +2579 -4973
  79. package/dist/generated/assets/cldr/en_ZA.json +2578 -4972
  80. package/dist/generated/assets/cldr/es.json +2633 -4912
  81. package/dist/generated/assets/cldr/es_AR.json +2638 -4914
  82. package/dist/generated/assets/cldr/es_BO.json +2638 -4913
  83. package/dist/generated/assets/cldr/es_CL.json +2638 -4914
  84. package/dist/generated/assets/cldr/es_CO.json +2637 -4913
  85. package/dist/generated/assets/cldr/es_MX.json +2638 -4915
  86. package/dist/generated/assets/cldr/es_PE.json +2638 -4913
  87. package/dist/generated/assets/cldr/es_UY.json +2638 -4915
  88. package/dist/generated/assets/cldr/es_VE.json +2638 -4914
  89. package/dist/generated/assets/cldr/et.json +2593 -4967
  90. package/dist/generated/assets/cldr/fa.json +2606 -4883
  91. package/dist/generated/assets/cldr/fi.json +2635 -5008
  92. package/dist/generated/assets/cldr/fr.json +2583 -4979
  93. package/dist/generated/assets/cldr/fr_BE.json +2583 -4979
  94. package/dist/generated/assets/cldr/fr_CA.json +2598 -4973
  95. package/dist/generated/assets/cldr/fr_CH.json +2600 -4997
  96. package/dist/generated/assets/cldr/fr_LU.json +2583 -4979
  97. package/dist/generated/assets/cldr/he.json +2699 -5378
  98. package/dist/generated/assets/cldr/hi.json +2593 -4829
  99. package/dist/generated/assets/cldr/hr.json +2646 -4919
  100. package/dist/generated/assets/cldr/hu.json +2592 -4856
  101. package/dist/generated/assets/cldr/id.json +2538 -4658
  102. package/dist/generated/assets/cldr/it.json +2583 -4950
  103. package/dist/generated/assets/cldr/it_CH.json +2583 -4950
  104. package/dist/generated/assets/cldr/ja.json +2655 -4830
  105. package/dist/generated/assets/cldr/kk.json +2583 -4725
  106. package/dist/generated/assets/cldr/ko.json +2632 -4738
  107. package/dist/generated/assets/cldr/lt.json +2714 -5481
  108. package/dist/generated/assets/cldr/lv.json +2638 -5112
  109. package/dist/generated/assets/cldr/ms.json +2532 -4515
  110. package/dist/generated/assets/cldr/nb.json +2615 -4977
  111. package/dist/generated/assets/cldr/nl.json +2595 -4884
  112. package/dist/generated/assets/cldr/nl_BE.json +2595 -4884
  113. package/dist/generated/assets/cldr/pl.json +2717 -5176
  114. package/dist/generated/assets/cldr/pt.json +2600 -4805
  115. package/dist/generated/assets/cldr/pt_PT.json +2651 -4940
  116. package/dist/generated/assets/cldr/ro.json +2639 -5090
  117. package/dist/generated/assets/cldr/ru.json +2698 -5407
  118. package/dist/generated/assets/cldr/ru_UA.json +2698 -5407
  119. package/dist/generated/assets/cldr/sk.json +2720 -5370
  120. package/dist/generated/assets/cldr/sl.json +2682 -5340
  121. package/dist/generated/assets/cldr/sr.json +2657 -5126
  122. package/dist/generated/assets/cldr/sr_Latn.json +2658 -5127
  123. package/dist/generated/assets/cldr/sv.json +2625 -5011
  124. package/dist/generated/assets/cldr/th.json +2626 -4797
  125. package/dist/generated/assets/cldr/tr.json +2606 -4979
  126. package/dist/generated/assets/cldr/uk.json +2678 -5353
  127. package/dist/generated/assets/cldr/vi.json +2549 -4673
  128. package/dist/generated/assets/cldr/zh_CN.json +2541 -4632
  129. package/dist/generated/assets/cldr/zh_HK.json +2549 -4640
  130. package/dist/generated/assets/cldr/zh_SG.json +2548 -4640
  131. package/dist/generated/assets/cldr/zh_TW.json +2556 -4728
  132. package/dist/generated/json-imports/LocaleData-static.js +2 -1
  133. package/dist/generated/json-imports/LocaleData.js +2 -1
  134. package/dist/getCachedLocaleDataInstance.d.ts +4 -0
  135. package/dist/getCachedLocaleDataInstance.js +6 -9
  136. package/dist/getCachedLocaleDataInstance.js.map +1 -0
  137. package/dist/locale/getLocaleData.d.ts +11 -0
  138. package/dist/locale/getLocaleData.js +13 -17
  139. package/dist/locale/getLocaleData.js.map +1 -0
  140. package/dist/sap/base/Log.js +28 -29
  141. package/dist/sap/base/assert.js +5 -6
  142. package/dist/sap/base/util/LoaderExtensions.d.ts +4 -0
  143. package/dist/sap/base/util/LoaderExtensions.js +9 -12
  144. package/dist/sap/base/util/LoaderExtensions.js.map +1 -0
  145. package/dist/sap/ui/core/Configuration.d.ts +17 -0
  146. package/dist/sap/ui/core/Configuration.js +20 -0
  147. package/dist/sap/ui/core/Configuration.js.map +1 -0
  148. package/dist/sap/ui/core/Core.d.ts +26 -0
  149. package/dist/sap/ui/core/Core.js +7 -32
  150. package/dist/sap/ui/core/Core.js.map +1 -0
  151. package/dist/sap/ui/core/FormatSettings.d.ts +10 -0
  152. package/dist/sap/ui/core/FormatSettings.js +14 -0
  153. package/dist/sap/ui/core/FormatSettings.js.map +1 -0
  154. package/dist/sap/ui/core/Locale.js +13 -0
  155. package/dist/sap/ui/core/LocaleData.js +107 -6
  156. package/dist/sap/ui/core/date/Buddhist.js +0 -6
  157. package/dist/sap/ui/core/date/CalendarUtils.js +36 -0
  158. package/dist/sap/ui/core/date/CalendarWeekNumbering.js +7 -0
  159. package/dist/sap/ui/core/date/Islamic.js +3 -3
  160. package/dist/sap/ui/core/date/Japanese.js +4 -4
  161. package/dist/sap/ui/core/date/UniversalDate.js +79 -22
  162. package/dist/sap/ui/core/format/DateFormat.js +496 -201
  163. package/dist/sap/ui/core/format/TimezoneUtil.js +94 -0
  164. package/{package-scripts.js → package-scripts.cjs} +7 -10
  165. package/package.json +7 -5
  166. package/tsconfig.json +14 -0
  167. package/used-modules.txt +4 -1
  168. package/hash.txt +0 -1
  169. package/src/Assets.js +0 -2
  170. package/src/DateFormat.js +0 -3
  171. package/src/LocaleData.js +0 -3
  172. package/src/dates/CalendarDate.js +0 -223
  173. package/src/dates/ExtremeDates.js +0 -39
  174. package/src/dates/calculateWeekNumber.js +0 -51
  175. package/src/dates/getRoundedTimestamp.js +0 -14
  176. package/src/dates/getTodayUTCTimestamp.js +0 -9
  177. package/src/dates/modifyDateBy.js +0 -42
  178. package/src/getCachedLocaleDataInstance.js +0 -13
  179. package/src/locale/getLocaleData.js +0 -27
  180. package/src/sap/base/util/LoaderExtensions.js +0 -17
  181. package/src/sap/ui/core/Core.js +0 -38
  182. /package/{config/.eslintrc.js → .eslintrc.cjs} +0 -0
  183. /package/{src/features/calendar/Buddhist.js → dist/features/calendar/Buddhist.d.ts} +0 -0
  184. /package/{src/features/calendar/Gregorian.js → dist/features/calendar/Gregorian.d.ts} +0 -0
  185. /package/{src/features/calendar/Islamic.js → dist/features/calendar/Islamic.d.ts} +0 -0
  186. /package/{src/features/calendar/Japanese.js → dist/features/calendar/Japanese.d.ts} +0 -0
  187. /package/{src/features/calendar/Persian.js → dist/features/calendar/Persian.d.ts} +0 -0
@@ -1,213 +1,182 @@
1
- import UniversalDate from "../sap/ui/core/date/UniversalDate.js";
2
-
1
+ import UniversalDate from "./UniversalDate.js";
3
2
  class CalendarDate {
4
- constructor() {
5
- let aArgs = arguments, // eslint-disable-line
6
- oJSDate,
7
- oNow,
8
- sCalendarType;
9
-
10
- switch (aArgs.length) {
11
- case 0: // defaults to the current date
12
- oNow = new Date();
13
- return this.constructor(oNow.getFullYear(), oNow.getMonth(), oNow.getDate());
14
-
15
- case 1: // CalendarDate
16
- case 2: // CalendarDate, sCalendarType
17
- if (!(aArgs[0] instanceof CalendarDate)) {
18
- throw new Error("Invalid arguments: the first argument must be of type sap.ui.unified.calendar.CalendarDate.");
19
- }
20
- sCalendarType = aArgs[1] ? aArgs[1] : aArgs[0]._oUDate.sCalendarType;
21
- // Use source.valueOf() (returns the same point of time regardless calendar type) instead of
22
- // source's getters to avoid non-gregorian Year, Month and Date may be used to construct a Gregorian date
23
- oJSDate = new Date(aArgs[0].valueOf());
24
-
25
- // Make this date really local. Now getters are safe.
26
- oJSDate.setFullYear(oJSDate.getUTCFullYear(), oJSDate.getUTCMonth(), oJSDate.getUTCDate());
27
- oJSDate.setHours(oJSDate.getUTCHours(), oJSDate.getUTCMinutes(), oJSDate.getUTCSeconds(), oJSDate.getUTCMilliseconds());
28
-
29
- this._oUDate = createUniversalUTCDate(oJSDate, sCalendarType);
30
- break;
31
-
32
- case 3: // year, month, date
33
- 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
-
38
- 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.
40
-
41
- if (aArgs[3]) {
42
- sCalendarType = aArgs[3];
43
- }
44
- this._oUDate = createUniversalUTCDate(oJSDate, sCalendarType);
45
- break;
46
-
47
- default:
48
- throw new Error(`${"Invalid arguments. Accepted arguments are: 1) oCalendarDate, (optional)calendarType"
49
- + "or 2) year, month, date, (optional) calendarType"}${aArgs}`);
50
- }
51
- }
52
-
53
- getYear() {
54
- return this._oUDate.getUTCFullYear();
55
- }
56
-
57
- setYear(year) {
58
- checkNumericLike(year, `Invalid year: ${year}`);
59
- this._oUDate.setUTCFullYear(year);
60
- return this;
61
- }
62
-
63
- getMonth() {
64
- return this._oUDate.getUTCMonth();
65
- }
66
-
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) {
83
- checkNumericLike(month, `Invalid month: ${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
- }
90
- return this;
91
- }
92
-
93
- getDate() {
94
- return this._oUDate.getUTCDate();
95
- }
96
-
97
- setDate(date) {
98
- checkNumericLike(date, `Invalid date: ${date}`);
99
- this._oUDate.setUTCDate(date);
100
- return this;
101
- }
102
-
103
- getDay() {
104
- return this._oUDate.getUTCDay();
105
- }
106
-
107
- getCalendarType() {
108
- return this._oUDate.sCalendarType;
109
- }
110
-
111
- isBefore(oCalendarDate) {
112
- checkCalendarDate(oCalendarDate);
113
- return this.valueOf() < oCalendarDate.valueOf();
114
- }
115
-
116
- isAfter(oCalendarDate) {
117
- checkCalendarDate(oCalendarDate);
118
- return this.valueOf() > oCalendarDate.valueOf();
119
- }
120
-
121
- isSameOrBefore(oCalendarDate) {
122
- checkCalendarDate(oCalendarDate);
123
- return this.valueOf() <= oCalendarDate.valueOf();
124
- }
125
-
126
- isSameOrAfter(oCalendarDate) {
127
- checkCalendarDate(oCalendarDate);
128
- return this.valueOf() >= oCalendarDate.valueOf();
129
- }
130
-
131
- isSame(oCalendarDate) {
132
- checkCalendarDate(oCalendarDate);
133
- return this.valueOf() === oCalendarDate.valueOf();
134
- }
135
-
136
- toLocalJSDate() {
137
- // Use this._oUDate.getTime()(returns the same point of time regardless calendar type) instead of
138
- // this._oUDate's getters to avoid non-gregorian Year, Month and Date to be used to construct a Gregorian date
139
- const oLocalDate = new Date(this._oUDate.getTime());
140
-
141
- // Make this date really local. Now getters are safe.
142
- oLocalDate.setFullYear(oLocalDate.getUTCFullYear(), oLocalDate.getUTCMonth(), oLocalDate.getUTCDate());
143
- oLocalDate.setHours(0, 0, 0, 0);
144
-
145
- return oLocalDate;
146
- }
147
-
148
- toUTCJSDate() {
149
- // Use this._oUDate.getTime()(returns the same point of time regardless calendar type) instead of
150
- // this._oUDate's getters to avoid non-gregorian Year, Month and Date to be used to construct a Gregorian date
151
- const oUTCDate = new Date(this._oUDate.getTime());
152
- oUTCDate.setUTCHours(0, 0, 0, 0);
153
-
154
- return oUTCDate;
155
- }
156
-
157
- toString() {
158
- return `${this._oUDate.sCalendarType}: ${this.getYear()}/${this.getMonth() + 1}/${this.getDate()}`;
159
- }
160
-
161
- valueOf() {
162
- return this._oUDate.getTime();
163
- }
164
-
165
- static fromLocalJSDate(oJSDate, sCalendarType) {
166
- // Cross frame check for a date should be performed here otherwise setDateValue would fail in OPA tests
167
- // because Date object in the test is different than the Date object in the application (due to the iframe).
168
- // 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
171
- }
172
- if (!isValidDate(oJSDate)) {
173
- throw new Error(`Date parameter must be a JavaScript Date object: [${oJSDate}].`);
174
- }
175
- return new CalendarDate(oJSDate.getFullYear(), oJSDate.getMonth(), oJSDate.getDate(), sCalendarType);
176
- }
177
-
178
- static fromTimestamp(iTimestamp, sCalendarType) {
179
- const oCalDate = new CalendarDate(0, 0, 1);
180
- oCalDate._oUDate = UniversalDate.getInstance(new Date(iTimestamp), sCalendarType);
181
- return oCalDate;
182
- }
3
+ constructor(year, month, date, calendarType) {
4
+ let aArgs = arguments, // eslint-disable-line
5
+ oJSDate, oNow, sCalendarType;
6
+ switch (aArgs.length) {
7
+ case 0: // defaults to the current date
8
+ oNow = new Date();
9
+ return this.constructor(oNow.getFullYear(), oNow.getMonth(), oNow.getDate());
10
+ case 1: // CalendarDate
11
+ case 2: // CalendarDate, sCalendarType
12
+ if (!(aArgs[0] instanceof CalendarDate)) {
13
+ throw new Error("Invalid arguments: the first argument must be of type CalendarDate.");
14
+ }
15
+ sCalendarType = aArgs[1] ? aArgs[1] : aArgs[0]._oUDate.sCalendarType;
16
+ // Use source.valueOf() (returns the same point of time regardless calendar type) instead of
17
+ // source's getters to avoid non-gregorian Year, Month and Date may be used to construct a Gregorian date
18
+ oJSDate = new Date(aArgs[0].valueOf());
19
+ // Make this date really local. Now getters are safe.
20
+ oJSDate.setFullYear(oJSDate.getUTCFullYear(), oJSDate.getUTCMonth(), oJSDate.getUTCDate());
21
+ oJSDate.setHours(oJSDate.getUTCHours(), oJSDate.getUTCMinutes(), oJSDate.getUTCSeconds(), oJSDate.getUTCMilliseconds());
22
+ this._oUDate = createUniversalUTCDate(oJSDate, sCalendarType);
23
+ break;
24
+ case 3: // year, month, date
25
+ case 4: // year, month, date, sCalendarType
26
+ checkNumericLike(aArgs[0], `Invalid year: ${aArgs[0]}`);
27
+ checkNumericLike(aArgs[1], `Invalid month: ${aArgs[1]}`);
28
+ checkNumericLike(aArgs[2], `Invalid date: ${aArgs[2]}`);
29
+ oJSDate = new Date(0, 0, 1);
30
+ oJSDate.setFullYear(aArgs[0], aArgs[1], aArgs[2]); // 2 digits year is not supported. If so, it is considered as full year as well.
31
+ if (aArgs[3]) {
32
+ sCalendarType = aArgs[3];
33
+ }
34
+ this._oUDate = createUniversalUTCDate(oJSDate, sCalendarType);
35
+ break;
36
+ default:
37
+ throw new Error(`${"Invalid arguments. Accepted arguments are: 1) oCalendarDate, (optional)calendarType"
38
+ + "or 2) year, month, date, (optional) calendarType"}${aArgs}`);
39
+ }
40
+ }
41
+ getYear() {
42
+ return this._oUDate.getUTCFullYear();
43
+ }
44
+ setYear(year) {
45
+ checkNumericLike(year, `Invalid year: ${year}`);
46
+ this._oUDate.setUTCFullYear(year);
47
+ return this;
48
+ }
49
+ getMonth() {
50
+ return this._oUDate.getUTCMonth();
51
+ }
52
+ /**
53
+ * Sets the given month as ordinal month of the year.
54
+ * @param {int} month An integer between 0 and 11, representing the months January through December( or their
55
+ * equivalent month names for the given calendar).
56
+ * If the specified value is is outside of the expected range, this method attempts to update the date information
57
+ * accordingly. For example, if 12 is given as a month, the year will be incremented by 1, and 1 will be used for month.
58
+ * @param {int} [date] An integer between 1 and 31, representing the day of the month, but other values are allowed.
59
+ * 0 will result in the previous month's last day.
60
+ * -1 will result in the day before the previous month's last day.
61
+ * 32 will result in:
62
+ * - first day of the next month if the current month has 31 days.
63
+ * - second day of the next month if the current month has 30 days.
64
+ * Other value will result in adding or subtracting days according to the given value.
65
+ * @returns {sap.ui.unified.calendar.CalendarDate} <code>this</code> for method chaining.
66
+ */
67
+ setMonth(month, date) {
68
+ checkNumericLike(month, `Invalid month: ${month}`);
69
+ if (date || date === 0) {
70
+ checkNumericLike(date, `Invalid date: ${date}`);
71
+ this._oUDate.setUTCMonth(month, date);
72
+ }
73
+ else {
74
+ this._oUDate.setUTCMonth(month);
75
+ }
76
+ return this;
77
+ }
78
+ getDate() {
79
+ return this._oUDate.getUTCDate();
80
+ }
81
+ setDate(date) {
82
+ checkNumericLike(date, `Invalid date: ${date}`);
83
+ this._oUDate.setUTCDate(date);
84
+ return this;
85
+ }
86
+ getDay() {
87
+ return this._oUDate.getUTCDay();
88
+ }
89
+ getCalendarType() {
90
+ return this._oUDate.sCalendarType;
91
+ }
92
+ isBefore(oCalendarDate) {
93
+ checkCalendarDate(oCalendarDate);
94
+ return this.valueOf() < oCalendarDate.valueOf();
95
+ }
96
+ isAfter(oCalendarDate) {
97
+ checkCalendarDate(oCalendarDate);
98
+ return this.valueOf() > oCalendarDate.valueOf();
99
+ }
100
+ isSameOrBefore(oCalendarDate) {
101
+ checkCalendarDate(oCalendarDate);
102
+ return this.valueOf() <= oCalendarDate.valueOf();
103
+ }
104
+ isSameOrAfter(oCalendarDate) {
105
+ checkCalendarDate(oCalendarDate);
106
+ return this.valueOf() >= oCalendarDate.valueOf();
107
+ }
108
+ isSame(oCalendarDate) {
109
+ checkCalendarDate(oCalendarDate);
110
+ return this.valueOf() === oCalendarDate.valueOf();
111
+ }
112
+ toLocalJSDate() {
113
+ // Use this._oUDate.getTime()(returns the same point of time regardless calendar type) instead of
114
+ // this._oUDate's getters to avoid non-gregorian Year, Month and Date to be used to construct a Gregorian date
115
+ const oLocalDate = new Date(this._oUDate.getTime());
116
+ // Make this date really local. Now getters are safe.
117
+ oLocalDate.setFullYear(oLocalDate.getUTCFullYear(), oLocalDate.getUTCMonth(), oLocalDate.getUTCDate());
118
+ oLocalDate.setHours(0, 0, 0, 0);
119
+ return oLocalDate;
120
+ }
121
+ toUTCJSDate() {
122
+ // Use this._oUDate.getTime()(returns the same point of time regardless calendar type) instead of
123
+ // this._oUDate's getters to avoid non-gregorian Year, Month and Date to be used to construct a Gregorian date
124
+ const oUTCDate = new Date(this._oUDate.getTime());
125
+ oUTCDate.setUTCHours(0, 0, 0, 0);
126
+ return oUTCDate;
127
+ }
128
+ toString() {
129
+ return `${this._oUDate.sCalendarType}: ${this.getYear()}/${this.getMonth() + 1}/${this.getDate()}`;
130
+ }
131
+ valueOf() {
132
+ return this._oUDate.getTime();
133
+ }
134
+ static fromLocalJSDate(oJSDate, sCalendarType) {
135
+ // Cross frame check for a date should be performed here otherwise setDateValue would fail in OPA tests
136
+ // because Date object in the test is different than the Date object in the application (due to the iframe).
137
+ // We can use jQuery.type or this method:
138
+ function isValidDate(date) {
139
+ return date && Object.prototype.toString.call(date) === "[object Date]" && !isNaN(date); // eslint-disable-line
140
+ }
141
+ if (!isValidDate(oJSDate)) {
142
+ throw new Error(`Date parameter must be a JavaScript Date object: [${oJSDate}].`);
143
+ }
144
+ return new CalendarDate(oJSDate.getFullYear(), oJSDate.getMonth(), oJSDate.getDate(), sCalendarType);
145
+ }
146
+ static fromTimestamp(iTimestamp, sCalendarType) {
147
+ const oCalDate = new CalendarDate(0, 0, 1);
148
+ let oUDate;
149
+ try {
150
+ oUDate = UniversalDate.getInstance(new Date(iTimestamp), sCalendarType);
151
+ }
152
+ catch (e) {
153
+ oUDate = new Date(NaN); // UniversalDate.getInstance may now throw an Exception - keep the old behavior
154
+ }
155
+ oCalDate._oUDate = oUDate;
156
+ return oCalDate;
157
+ }
183
158
  }
184
-
185
159
  function createUniversalUTCDate(oDate, sCalendarType) {
186
- if (sCalendarType) {
187
- return UniversalDate.getInstance(createUTCDate(oDate), sCalendarType);
188
- }
189
- return new UniversalDate(createUTCDate(oDate).getTime());
160
+ if (sCalendarType) {
161
+ return UniversalDate.getInstance(createUTCDate(oDate), sCalendarType);
162
+ }
163
+ return new UniversalDate(createUTCDate(oDate).getTime());
190
164
  }
191
-
192
165
  /**
193
166
  * Creates a JavaScript UTC Date corresponding to the given JavaScript Date.
194
167
  * @param {Date} oDate JavaScript date object. Time related information is cut.
195
168
  * @returns {Date} JavaScript date created from the date object, but this time considered as UTC date information.
196
169
  */
197
170
  function createUTCDate(oDate) {
198
- const oUTCDate = new Date(Date.UTC(0, 0, 1));
199
-
200
- oUTCDate.setUTCFullYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate());
201
-
202
- return oUTCDate;
171
+ const oUTCDate = new Date(Date.UTC(0, 0, 1));
172
+ oUTCDate.setUTCFullYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate());
173
+ return oUTCDate;
203
174
  }
204
-
205
175
  function checkCalendarDate(oCalendarDate) {
206
- if (!(oCalendarDate instanceof CalendarDate)) {
207
- throw new Error(`Invalid calendar date: [${oCalendarDate}]. Expected: sap.ui.unified.calendar.CalendarDate`);
208
- }
176
+ if (!(oCalendarDate instanceof CalendarDate)) {
177
+ throw new Error(`Invalid calendar date: [${oCalendarDate}]. Expected: CalendarDate`);
178
+ }
209
179
  }
210
-
211
180
  /**
212
181
  * Verifies the given value is numeric like, i.e. 3, "3" and throws an error if it is not.
213
182
  * @param {any} value The value of any type to check. If null or undefined, this method throws an error.
@@ -215,9 +184,9 @@ function checkCalendarDate(oCalendarDate) {
215
184
  * @throws will throw an error if the value is null or undefined or is not like a number
216
185
  */
217
186
  function checkNumericLike(value, message) {
218
- if (value === undefined || value === Infinity || isNaN(value)) { // eslint-disable-line
219
- throw message;
220
- }
187
+ if (value === undefined || value === Infinity || isNaN(value)) { // eslint-disable-line
188
+ throw message;
189
+ }
221
190
  }
222
-
223
191
  export default CalendarDate;
192
+ //# sourceMappingURL=CalendarDate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CalendarDate.js","sourceRoot":"","sources":["../../src/dates/CalendarDate.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAE/C,MAAM,YAAY;IAGjB,YAAY,IAA4B,EAAE,KAAuB,EAAE,IAAa,EAAE,YAAqB;QACtG,IAAI,KAAK,GAAG,SAAS,EAAE,sBAAsB;QAC5C,OAAa,EACb,IAAU,EACV,aAA4B,CAAC;QAE9B,QAAQ,KAAK,CAAC,MAAM,EAAE;YACtB,KAAK,CAAC,EAAE,+BAA+B;gBACtC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;gBAClB,OAAQ,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,CAAkB,CAAC;YAEhG,KAAK,CAAC,CAAC,CAAC,eAAe;YACvB,KAAK,CAAC,EAAE,8BAA8B;gBACrC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,YAAY,CAAC,EAAE;oBACxC,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;iBACvF;gBACD,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,KAAK,CAAC,CAAC,CAAC,CAAC,OAAyB,CAAC,aAAa,CAAC;gBACxF,4FAA4F;gBAC5F,yGAAyG;gBACzG,OAAO,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;gBAEvC,qDAAqD;gBACrD,OAAO,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./UniversalDate.js\";\n\nclass CalendarDate {\n\t_oUDate!: Date | UniversalDate;\n\n\tconstructor(year?: number | CalendarDate, month?: number | string, date?: number, calendarType?: string) { // eslint-disable-line\n\t\tlet aArgs = arguments, // eslint-disable-line\n\t\t\toJSDate: Date,\n\t\t\toNow: Date,\n\t\t\tsCalendarType!: CalendarType;\n\n\t\tswitch (aArgs.length) {\n\t\tcase 0: // defaults to the current date\n\t\t\toNow = new Date();\n\t\t\treturn (this.constructor(oNow.getFullYear(), oNow.getMonth(), oNow.getDate()) as CalendarDate);\n\n\t\tcase 1: // CalendarDate\n\t\tcase 2: // CalendarDate, sCalendarType\n\t\t\tif (!(aArgs[0] instanceof CalendarDate)) {\n\t\t\t\tthrow new Error(\"Invalid arguments: the first argument must be of type CalendarDate.\");\n\t\t\t}\n\t\t\tsCalendarType = aArgs[1] ? aArgs[1] : (aArgs[0]._oUDate as UniversalDate).sCalendarType;\n\t\t\t// Use source.valueOf() (returns the same point of time regardless calendar type) instead of\n\t\t\t// source's getters to avoid non-gregorian Year, Month and Date may be used to construct a Gregorian date\n\t\t\toJSDate = new Date(aArgs[0].valueOf());\n\n\t\t\t// Make this date really local. Now getters are safe.\n\t\t\toJSDate.setFullYear(oJSDate.getUTCFullYear(), oJSDate.getUTCMonth(), oJSDate.getUTCDate());\n\t\t\toJSDate.setHours(oJSDate.getUTCHours(), oJSDate.getUTCMinutes(), oJSDate.getUTCSeconds(), oJSDate.getUTCMilliseconds());\n\n\t\t\tthis._oUDate = createUniversalUTCDate(oJSDate, sCalendarType);\n\t\t\tbreak;\n\n\t\tcase 3: // year, month, date\n\t\tcase 4: // year, month, date, sCalendarType\n\t\t\tcheckNumericLike(aArgs[0] as number, `Invalid year: ${aArgs[0] as number}`);\n\t\t\tcheckNumericLike(aArgs[1] as number, `Invalid month: ${aArgs[1] as number}`);\n\t\t\tcheckNumericLike(aArgs[2] as number, `Invalid date: ${aArgs[2] as number}`);\n\n\t\t\toJSDate = new Date(0, 0, 1);\n\t\t\toJSDate.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.\n\n\t\t\tif (aArgs[3]) {\n\t\t\t\tsCalendarType = aArgs[3];\n\t\t\t}\n\t\t\tthis._oUDate = createUniversalUTCDate(oJSDate, sCalendarType);\n\t\t\tbreak;\n\n\t\tdefault:\n\t\t\tthrow new Error(`${\"Invalid arguments. Accepted arguments are: 1) oCalendarDate, (optional)calendarType\"\n\t\t\t\t+ \"or 2) year, month, date, (optional) calendarType\"}${aArgs as unknown as string}`);\n\t\t}\n\t}\n\n\tgetYear() {\n\t\treturn this._oUDate.getUTCFullYear();\n\t}\n\n\tsetYear(year: number) {\n\t\tcheckNumericLike(year, `Invalid year: ${year}`);\n\t\tthis._oUDate.setUTCFullYear(year);\n\t\treturn this;\n\t}\n\n\tgetMonth() {\n\t\treturn this._oUDate.getUTCMonth();\n\t}\n\n\t/**\n\t * Sets the given month as ordinal month of the year.\n\t * @param {int} month An integer between 0 and 11, representing the months January through December( or their\n\t * equivalent month names for the given calendar).\n\t * If the specified value is is outside of the expected range, this method attempts to update the date information\n\t * accordingly. For example, if 12 is given as a month, the year will be incremented by 1, and 1 will be used for month.\n\t * @param {int} [date] An integer between 1 and 31, representing the day of the month, but other values are allowed.\n\t * 0 will result in the previous month's last day.\n\t * -1 will result in the day before the previous month's last day.\n\t * 32 will result in:\n\t * - first day of the next month if the current month has 31 days.\n\t * - second day of the next month if the current month has 30 days.\n\t * Other value will result in adding or subtracting days according to the given value.\n\t * @returns {sap.ui.unified.calendar.CalendarDate} <code>this</code> for method chaining.\n\t */\n\tsetMonth(month: number, date?: number) {\n\t\tcheckNumericLike(month, `Invalid month: ${month}`);\n\t\tif (date || date === 0) {\n\t\t\tcheckNumericLike(date, `Invalid date: ${date}`);\n\t\t\tthis._oUDate.setUTCMonth(month, date);\n\t\t} else {\n\t\t\tthis._oUDate.setUTCMonth(month);\n\t\t}\n\t\treturn this;\n\t}\n\n\tgetDate() {\n\t\treturn this._oUDate.getUTCDate();\n\t}\n\n\tsetDate(date: number) {\n\t\tcheckNumericLike(date, `Invalid date: ${date}`);\n\t\tthis._oUDate.setUTCDate(date);\n\t\treturn this;\n\t}\n\n\tgetDay() {\n\t\treturn this._oUDate.getUTCDay();\n\t}\n\n\tgetCalendarType() {\n\t\treturn (this._oUDate as UniversalDate).sCalendarType;\n\t}\n\n\tisBefore(oCalendarDate: CalendarDate) {\n\t\tcheckCalendarDate(oCalendarDate);\n\t\treturn this.valueOf() < oCalendarDate.valueOf();\n\t}\n\n\tisAfter(oCalendarDate: CalendarDate) {\n\t\tcheckCalendarDate(oCalendarDate);\n\t\treturn this.valueOf() > oCalendarDate.valueOf();\n\t}\n\n\tisSameOrBefore(oCalendarDate: CalendarDate) {\n\t\tcheckCalendarDate(oCalendarDate);\n\t\treturn this.valueOf() <= oCalendarDate.valueOf();\n\t}\n\n\tisSameOrAfter(oCalendarDate: CalendarDate) {\n\t\tcheckCalendarDate(oCalendarDate);\n\t\treturn this.valueOf() >= oCalendarDate.valueOf();\n\t}\n\n\tisSame(oCalendarDate: CalendarDate) {\n\t\tcheckCalendarDate(oCalendarDate);\n\t\treturn this.valueOf() === oCalendarDate.valueOf();\n\t}\n\n\ttoLocalJSDate() {\n\t\t// Use this._oUDate.getTime()(returns the same point of time regardless calendar type) instead of\n\t\t// this._oUDate's getters to avoid non-gregorian Year, Month and Date to be used to construct a Gregorian date\n\t\tconst oLocalDate = new Date(this._oUDate.getTime());\n\n\t\t// Make this date really local. Now getters are safe.\n\t\toLocalDate.setFullYear(oLocalDate.getUTCFullYear(), oLocalDate.getUTCMonth(), oLocalDate.getUTCDate());\n\t\toLocalDate.setHours(0, 0, 0, 0);\n\n\t\treturn oLocalDate;\n\t}\n\n\ttoUTCJSDate() {\n\t\t// Use this._oUDate.getTime()(returns the same point of time regardless calendar type) instead of\n\t\t// this._oUDate's getters to avoid non-gregorian Year, Month and Date to be used to construct a Gregorian date\n\t\tconst oUTCDate = new Date(this._oUDate.getTime());\n\t\toUTCDate.setUTCHours(0, 0, 0, 0);\n\n\t\treturn oUTCDate;\n\t}\n\n\ttoString() {\n\t\treturn `${(this._oUDate as UniversalDate).sCalendarType}: ${this.getYear()}/${this.getMonth() + 1}/${this.getDate()}`;\n\t}\n\n\tvalueOf() {\n\t\treturn this._oUDate.getTime();\n\t}\n\n\tstatic fromLocalJSDate(oJSDate: Date, sCalendarType?: CalendarType) {\n\t\t// Cross frame check for a date should be performed here otherwise setDateValue would fail in OPA tests\n\t\t// because Date object in the test is different than the Date object in the application (due to the iframe).\n\t\t// We can use jQuery.type or this method:\n\t\tfunction isValidDate(date: Date) {\n\t\t\treturn date && Object.prototype.toString.call(date) === \"[object Date]\" && !isNaN(date as unknown as number); // eslint-disable-line\n\t\t}\n\t\tif (!isValidDate(oJSDate)) {\n\t\t\tthrow new Error(`Date parameter must be a JavaScript Date object: [${oJSDate as unknown as string}].`);\n\t\t}\n\t\treturn new CalendarDate(oJSDate.getFullYear(), oJSDate.getMonth(), oJSDate.getDate(), sCalendarType);\n\t}\n\n\tstatic fromTimestamp(iTimestamp: number, sCalendarType?: CalendarType) {\n\t\tconst oCalDate = new CalendarDate(0, 0, 1);\n\t\tlet oUDate;\n\t\ttry {\n\t\t\toUDate = UniversalDate.getInstance(new Date(iTimestamp), sCalendarType);\n\t\t} catch (e) {\n\t\t\toUDate = new Date(NaN); // UniversalDate.getInstance may now throw an Exception - keep the old behavior\n\t\t}\n\t\toCalDate._oUDate = oUDate;\n\t\treturn oCalDate;\n\t}\n}\n\nfunction createUniversalUTCDate(oDate: Date, sCalendarType: CalendarType) {\n\tif (sCalendarType) {\n\t\treturn UniversalDate.getInstance(createUTCDate(oDate), sCalendarType);\n\t}\n\treturn new UniversalDate(createUTCDate(oDate).getTime());\n}\n\n/**\n * Creates a JavaScript UTC Date corresponding to the given JavaScript Date.\n * @param {Date} oDate JavaScript date object. Time related information is cut.\n * @returns {Date} JavaScript date created from the date object, but this time considered as UTC date information.\n */\nfunction createUTCDate(oDate: Date) {\n\tconst oUTCDate = new Date(Date.UTC(0, 0, 1));\n\n\toUTCDate.setUTCFullYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate());\n\n\treturn oUTCDate;\n}\n\nfunction checkCalendarDate(oCalendarDate: CalendarDate) {\n\tif (!(oCalendarDate instanceof CalendarDate)) {\n\t\tthrow new Error(`Invalid calendar date: [${oCalendarDate as unknown as string}]. Expected: CalendarDate`);\n\t}\n}\n\n/**\n * Verifies the given value is numeric like, i.e. 3, \"3\" and throws an error if it is not.\n * @param {any} value The value of any type to check. If null or undefined, this method throws an error.\n * @param {string} message The message to be used if an error is to be thrown\n * @throws will throw an error if the value is null or undefined or is not like a number\n */\nfunction checkNumericLike(value: any, message: string) {\n\tif (value === undefined || value === Infinity || isNaN(value)) { // eslint-disable-line\n\t\tthrow message;\n\t}\n}\n\nexport default CalendarDate;\n"]}
@@ -0,0 +1,5 @@
1
+ import CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
2
+ import CalendarDate from "./CalendarDate.js";
3
+ declare const getMinCalendarDate: (primaryCalendarType: CalendarType) => CalendarDate;
4
+ declare const getMaxCalendarDate: (primaryCalendarType: CalendarType) => CalendarDate;
5
+ export { getMinCalendarDate, getMaxCalendarDate, };
@@ -1,39 +1,29 @@
1
1
  import CalendarDate from "./CalendarDate.js";
2
-
3
2
  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);
3
+ const getMinCalendarDate = (primaryCalendarType) => {
4
+ const key = `min ${primaryCalendarType}`;
5
+ if (!cache.has(key)) {
6
+ const minDate = new CalendarDate(1, 0, 1, primaryCalendarType);
7
+ minDate.setYear(1);
8
+ minDate.setMonth(0);
9
+ minDate.setDate(1);
10
+ cache.set(key, minDate);
11
+ }
12
+ return cache.get(key);
17
13
  };
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,
14
+ const getMaxCalendarDate = (primaryCalendarType) => {
15
+ const key = `max ${primaryCalendarType}`;
16
+ if (!cache.has(key)) {
17
+ const maxDate = new CalendarDate(1, 0, 1, primaryCalendarType);
18
+ maxDate.setYear(9999);
19
+ maxDate.setMonth(11);
20
+ const tempDate = new CalendarDate(maxDate, primaryCalendarType);
21
+ tempDate.setDate(1);
22
+ tempDate.setMonth(tempDate.getMonth() + 1, 0);
23
+ maxDate.setDate(tempDate.getDate()); // 31st for Gregorian Calendar
24
+ cache.set(key, maxDate);
25
+ }
26
+ return cache.get(key);
39
27
  };
28
+ export { getMinCalendarDate, getMaxCalendarDate, };
29
+ //# sourceMappingURL=ExtremeDates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExtremeDates.js","sourceRoot":"","sources":["../../src/dates/ExtremeDates.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAE7C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAwB,CAAC;AAE9C,MAAM,kBAAkB,GAAG,CAAC,mBAAiC,EAAE,EAAE;IAChE,MAAM,GAAG,GAAG,OAAO,mBAAmB,EAAE,CAAC;IAEzC,IAAI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C;AAEF,OAAO,EACN,kBAAkB,EAClB,kBAAkB,GAClB,CAAC","sourcesContent":["import CalendarType from \"@ui5/webcomponents-base/dist/types/CalendarType.js\";\nimport CalendarDate from \"./CalendarDate.js\";\n\nconst cache = new Map<string, CalendarDate>();\n\nconst getMinCalendarDate = (primaryCalendarType: CalendarType) => {\n\tconst key = `min ${primaryCalendarType}`;\n\n\tif (!cache.has(key)) {\n\t\tconst minDate = new CalendarDate(1, 0, 1, primaryCalendarType);\n\t\tminDate.setYear(1);\n\t\tminDate.setMonth(0);\n\t\tminDate.setDate(1);\n\t\tcache.set(key, minDate);\n\t}\n\n\treturn cache.get(key)!;\n};\n\nconst getMaxCalendarDate = (primaryCalendarType: CalendarType) => {\n\tconst key = `max ${primaryCalendarType}`;\n\n\tif (!cache.has(key)) {\n\t\tconst maxDate = new CalendarDate(1, 0, 1, primaryCalendarType);\n\t\tmaxDate.setYear(9999);\n\t\tmaxDate.setMonth(11);\n\t\tconst tempDate = new CalendarDate(maxDate, primaryCalendarType);\n\t\ttempDate.setDate(1);\n\t\ttempDate.setMonth(tempDate.getMonth() + 1, 0);\n\t\tmaxDate.setDate(tempDate.getDate());// 31st for Gregorian Calendar\n\t\tcache.set(key, maxDate);\n\t}\n\n\treturn cache.get(key)!;\n};\n\nexport {\n\tgetMinCalendarDate,\n\tgetMaxCalendarDate,\n};\n"]}
@@ -0,0 +1,46 @@
1
+ import type CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
2
+ type UniversalDate = {
3
+ new (time: number): UniversalDate;
4
+ oDate: Date;
5
+ sCalendarType: string;
6
+ getInstance: (oDate: Date, sCalendarType?: CalendarType) => UniversalDate;
7
+ getDate: () => number;
8
+ getMonth: () => number;
9
+ getFullYear: () => number;
10
+ getYear: () => number;
11
+ getDay: () => number;
12
+ getHours: () => number;
13
+ getMinutes: () => number;
14
+ getSeconds: () => number;
15
+ getMilliseconds: () => number;
16
+ getUTCDate: () => number;
17
+ getUTCMonth: () => number;
18
+ getUTCFullYear: () => number;
19
+ getUTCDay: () => number;
20
+ getUTCHours: () => number;
21
+ getUTCMinutes: () => number;
22
+ getUTCSeconds: () => number;
23
+ getUTCMilliseconds: () => number;
24
+ getTime: () => number;
25
+ valueOf: () => number;
26
+ getTimezoneOffset: () => number;
27
+ toString: () => string;
28
+ toDateString: () => string;
29
+ setDate: (dayValue: number) => number;
30
+ setFullYear: (yearValue: number, monthValue?: number, dateValue?: number) => number;
31
+ setYear: (yearValue: number) => number;
32
+ setMonth: (monthValue: number, dayValue?: number) => number;
33
+ setHours: (hoursValue: number, minutesValue?: number, secondsValue?: number, msValue?: number) => number;
34
+ setMinutes: (minutesValue: number, secondsValue?: number, msValue?: number) => number;
35
+ setSeconds: (secondsValue: number, msValue?: number) => number;
36
+ setMilliseconds: (setMilliseconds: number) => number;
37
+ setUTCDate: (dayValue: number) => number;
38
+ setUTCFullYear: (yearValue: number, monthValue?: number, dayValue?: number) => number;
39
+ setUTCMonth: (monthValue: number, dayValue?: number) => number;
40
+ setUTCHours: (hoursValue: number, minutesValue?: number, secondsValue?: number, msValue?: number) => number;
41
+ setUTCMinutes: (minutesValue: number, secondsValue?: number, msValue?: number) => number;
42
+ setUTCSeconds: (secondsValue: number, msValue?: number) => number;
43
+ setUTCMilliseconds: (setMilliseconds: number) => number;
44
+ };
45
+ declare const UniversalDate: UniversalDate;
46
+ export default UniversalDate;
@@ -0,0 +1,5 @@
1
+ // @ts-ignore
2
+ import UniversalDateNative from "../sap/ui/core/date/UniversalDate.js";
3
+ const UniversalDate = UniversalDateNative;
4
+ export default UniversalDate;
5
+ //# sourceMappingURL=UniversalDate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UniversalDate.js","sourceRoot":"","sources":["../../src/dates/UniversalDate.ts"],"names":[],"mappings":"AACA,aAAa;AACb,OAAO,mBAAmB,MAAM,sCAAsC,CAAC;AA8CvE,MAAM,aAAa,GAAkB,mBAAmB,CAAC;AAEzD,eAAe,aAAa,CAAC","sourcesContent":["import type CalendarType from \"@ui5/webcomponents-base/dist/types/CalendarType.js\";\n// @ts-ignore\nimport UniversalDateNative from \"../sap/ui/core/date/UniversalDate.js\";\n\ntype UniversalDate = {\n new (time: number): UniversalDate;\n oDate: Date,\n sCalendarType: string,\n getInstance: (oDate: Date, sCalendarType?: CalendarType) => UniversalDate,\n getDate: () => number,\n getMonth: () => number,\n getFullYear: () => number,\n getYear: () => number,\n getDay: () => number,\n getHours: () => number,\n getMinutes: () => number,\n getSeconds: () => number,\n getMilliseconds: () => number,\n getUTCDate: () => number,\n getUTCMonth: () => number,\n getUTCFullYear: () => number,\n getUTCDay: () => number,\n getUTCHours: () => number,\n getUTCMinutes: () => number,\n getUTCSeconds: () => number,\n getUTCMilliseconds: () => number,\n getTime: () => number,\n valueOf: () => number,\n getTimezoneOffset: () => number,\n toString: () => string,\n toDateString: () => string,\n setDate: (dayValue: number) => number,\n setFullYear: (yearValue: number, monthValue?: number, dateValue?: number) => number,\n setYear: (yearValue: number) => number,\n setMonth: (monthValue: number, dayValue?: number) => number,\n setHours: (hoursValue: number, minutesValue?: number, secondsValue?: number, msValue?: number) => number,\n setMinutes: (minutesValue: number, secondsValue?: number, msValue?: number) => number,\n setSeconds: (secondsValue: number, msValue?: number) => number,\n setMilliseconds: (setMilliseconds: number) => number,\n setUTCDate:(dayValue: number) => number,\n setUTCFullYear: (yearValue: number, monthValue?: number, dayValue?: number) => number,\n setUTCMonth: (monthValue: number, dayValue?: number) => number,\n setUTCHours: (hoursValue: number, minutesValue?: number, secondsValue?: number, msValue?: number) => number,\n setUTCMinutes: (minutesValue: number, secondsValue?: number, msValue?: number) => number,\n setUTCSeconds: (secondsValue: number, msValue?: number) => number,\n setUTCMilliseconds: (setMilliseconds: number) => number,\n}\n\nconst UniversalDate: UniversalDate = UniversalDateNative;\n\nexport default UniversalDate;\n"]}
@@ -0,0 +1,4 @@
1
+ import type Locale from "@ui5/webcomponents-base/dist/locale/Locale.js";
2
+ import type LocaleData from "../LocaleData.js";
3
+ declare const calculateWeekNumber: (confFirstDayOfWeek: number | undefined, oDate: Date, iYear: number, oLocale: Locale, oLocaleData: LocaleData) => number;
4
+ export default calculateWeekNumber;