@ui5/webcomponents-localization 0.0.0-f9b9eadb8 → 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 -0
  2. package/.npsrc.json +3 -0
  3. package/CHANGELOG.md +378 -0
  4. package/README.md +36 -6
  5. package/dist/Assets-static.d.ts +1 -0
  6. package/dist/Assets-static.js +3 -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 +29 -0
  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 +14 -0
  37. package/dist/dates/getRoundedTimestamp.js.map +1 -0
  38. package/dist/dates/getTodayUTCTimestamp.d.ts +7 -0
  39. package/dist/dates/getTodayUTCTimestamp.js +8 -0
  40. package/dist/dates/getTodayUTCTimestamp.js.map +1 -0
  41. package/dist/dates/modifyDateBy.d.ts +13 -0
  42. package/dist/dates/modifyDateBy.js +40 -0
  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 -5904
  58. package/dist/generated/assets/cldr/ar_EG.json +2804 -5904
  59. package/dist/generated/assets/cldr/ar_SA.json +2804 -5904
  60. package/dist/generated/assets/cldr/bg.json +2727 -4977
  61. package/dist/generated/assets/cldr/ca.json +2670 -4994
  62. package/dist/generated/assets/cldr/cs.json +2710 -5496
  63. package/dist/generated/assets/cldr/cy.json +2793 -0
  64. package/dist/generated/assets/cldr/da.json +2591 -4886
  65. package/dist/generated/assets/cldr/de.json +2608 -4914
  66. package/dist/generated/assets/cldr/de_AT.json +2608 -4915
  67. package/dist/generated/assets/cldr/de_CH.json +2608 -4913
  68. package/dist/generated/assets/cldr/el.json +2589 -4881
  69. package/dist/generated/assets/cldr/el_CY.json +2589 -4881
  70. package/dist/generated/assets/cldr/en.json +2577 -4968
  71. package/dist/generated/assets/cldr/en_AU.json +2586 -4960
  72. package/dist/generated/assets/cldr/en_GB.json +2578 -4969
  73. package/dist/generated/assets/cldr/en_HK.json +2584 -4975
  74. package/dist/generated/assets/cldr/en_IE.json +2578 -4969
  75. package/dist/generated/assets/cldr/en_IN.json +2579 -4970
  76. package/dist/generated/assets/cldr/en_NZ.json +2578 -4969
  77. package/dist/generated/assets/cldr/en_PG.json +2578 -4970
  78. package/dist/generated/assets/cldr/en_SG.json +2579 -4971
  79. package/dist/generated/assets/cldr/en_ZA.json +2578 -4970
  80. package/dist/generated/assets/cldr/es.json +2633 -4910
  81. package/dist/generated/assets/cldr/es_AR.json +2638 -4912
  82. package/dist/generated/assets/cldr/es_BO.json +2638 -4911
  83. package/dist/generated/assets/cldr/es_CL.json +2638 -4912
  84. package/dist/generated/assets/cldr/es_CO.json +2637 -4911
  85. package/dist/generated/assets/cldr/es_MX.json +2638 -4913
  86. package/dist/generated/assets/cldr/es_PE.json +2638 -4911
  87. package/dist/generated/assets/cldr/es_UY.json +2638 -4913
  88. package/dist/generated/assets/cldr/es_VE.json +2638 -4912
  89. package/dist/generated/assets/cldr/et.json +2593 -4965
  90. package/dist/generated/assets/cldr/fa.json +2606 -4881
  91. package/dist/generated/assets/cldr/fi.json +2635 -5006
  92. package/dist/generated/assets/cldr/fr.json +2583 -4977
  93. package/dist/generated/assets/cldr/fr_BE.json +2583 -4977
  94. package/dist/generated/assets/cldr/fr_CA.json +2598 -4971
  95. package/dist/generated/assets/cldr/fr_CH.json +2600 -4995
  96. package/dist/generated/assets/cldr/fr_LU.json +2583 -4977
  97. package/dist/generated/assets/cldr/he.json +2699 -5376
  98. package/dist/generated/assets/cldr/hi.json +2593 -4827
  99. package/dist/generated/assets/cldr/hr.json +2646 -4917
  100. package/dist/generated/assets/cldr/hu.json +2592 -4854
  101. package/dist/generated/assets/cldr/id.json +2538 -4656
  102. package/dist/generated/assets/cldr/it.json +2583 -4948
  103. package/dist/generated/assets/cldr/it_CH.json +2583 -4948
  104. package/dist/generated/assets/cldr/ja.json +2655 -4828
  105. package/dist/generated/assets/cldr/kk.json +2583 -4723
  106. package/dist/generated/assets/cldr/ko.json +2632 -4736
  107. package/dist/generated/assets/cldr/lt.json +2714 -5479
  108. package/dist/generated/assets/cldr/lv.json +2638 -5110
  109. package/dist/generated/assets/cldr/ms.json +2532 -4513
  110. package/dist/generated/assets/cldr/nb.json +2615 -4975
  111. package/dist/generated/assets/cldr/nl.json +2595 -4882
  112. package/dist/generated/assets/cldr/nl_BE.json +2595 -4882
  113. package/dist/generated/assets/cldr/pl.json +2717 -5174
  114. package/dist/generated/assets/cldr/pt.json +2600 -4803
  115. package/dist/generated/assets/cldr/pt_PT.json +2651 -4938
  116. package/dist/generated/assets/cldr/ro.json +2639 -5088
  117. package/dist/generated/assets/cldr/ru.json +2698 -5405
  118. package/dist/generated/assets/cldr/ru_UA.json +2698 -5405
  119. package/dist/generated/assets/cldr/sk.json +2720 -5368
  120. package/dist/generated/assets/cldr/sl.json +2682 -5338
  121. package/dist/generated/assets/cldr/sr.json +2657 -5124
  122. package/dist/generated/assets/cldr/sr_Latn.json +2660 -0
  123. package/dist/generated/assets/cldr/sv.json +2625 -5009
  124. package/dist/generated/assets/cldr/th.json +2626 -4795
  125. package/dist/generated/assets/cldr/tr.json +2606 -4977
  126. package/dist/generated/assets/cldr/uk.json +2678 -5351
  127. package/dist/generated/assets/cldr/vi.json +2549 -4671
  128. package/dist/generated/assets/cldr/zh_CN.json +2541 -4630
  129. package/dist/generated/assets/cldr/zh_HK.json +2549 -4638
  130. package/dist/generated/assets/cldr/zh_SG.json +2548 -4638
  131. package/dist/generated/assets/cldr/zh_TW.json +2556 -4726
  132. package/dist/generated/json-imports/LocaleData-static.js +90 -0
  133. package/dist/generated/json-imports/LocaleData.js +88 -91
  134. package/dist/getCachedLocaleDataInstance.d.ts +4 -0
  135. package/dist/getCachedLocaleDataInstance.js +10 -0
  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 -37
  141. package/dist/sap/base/assert.js +5 -10
  142. package/dist/sap/base/util/LoaderExtensions.d.ts +4 -0
  143. package/dist/sap/base/util/LoaderExtensions.js +11 -4
  144. package/dist/sap/base/util/LoaderExtensions.js.map +1 -0
  145. package/dist/sap/base/util/array/uniqueSort.js +7 -7
  146. package/dist/sap/base/util/deepEqual.js +1 -5
  147. package/dist/sap/ui/base/Interface.js +3 -5
  148. package/dist/sap/ui/base/Metadata.js +1 -3
  149. package/dist/sap/ui/base/Object.js +26 -2
  150. package/dist/sap/ui/core/Configuration.d.ts +17 -0
  151. package/dist/sap/ui/core/Configuration.js +20 -0
  152. package/dist/sap/ui/core/Configuration.js.map +1 -0
  153. package/dist/sap/ui/core/Core.d.ts +26 -0
  154. package/dist/sap/ui/core/Core.js +7 -32
  155. package/dist/sap/ui/core/Core.js.map +1 -0
  156. package/dist/sap/ui/core/FormatSettings.d.ts +10 -0
  157. package/dist/sap/ui/core/FormatSettings.js +14 -0
  158. package/dist/sap/ui/core/FormatSettings.js.map +1 -0
  159. package/dist/sap/ui/core/Locale.js +70 -31
  160. package/dist/sap/ui/core/LocaleData.js +133 -1506
  161. package/dist/sap/ui/core/date/Buddhist.js +0 -6
  162. package/dist/sap/ui/core/date/CalendarUtils.js +36 -0
  163. package/dist/sap/ui/core/date/CalendarWeekNumbering.js +7 -0
  164. package/dist/sap/ui/core/date/Islamic.js +3 -3
  165. package/dist/sap/ui/core/date/Japanese.js +4 -4
  166. package/dist/sap/ui/core/date/UniversalDate.js +82 -23
  167. package/dist/sap/ui/core/format/DateFormat.js +530 -222
  168. package/dist/sap/ui/core/format/TimezoneUtil.js +94 -0
  169. package/package-scripts.cjs +37 -0
  170. package/package.json +14 -14
  171. package/tsconfig.json +14 -0
  172. package/used-modules.txt +4 -1
  173. package/package-scripts.js +0 -31
  174. package/src/Assets.js +0 -2
  175. package/src/DateFormat.js +0 -3
  176. package/src/LocaleData.js +0 -3
  177. package/src/dates/CalendarDate.js +0 -223
  178. package/src/dates/calculateWeekNumber.js +0 -51
  179. package/src/locale/getLocaleData.js +0 -27
  180. package/src/sap/base/util/LoaderExtensions.js +0 -7
  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,CAAC,WAAW,CAAC,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AE;YACX,MAAM,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,+EAA+E;SACvG;QACD,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC;QAC1B,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD;AAED,SAAS,sBAAsB,CAAC,KAAW,EAAE,aAA2B;IACvE,IAAI,aAAa,EAAE;QAClB,OAAO,aAAa,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,CAAC;KACtE;IACD,OAAO,IAAI,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,KAAW;IACjC,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAE7C,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAEhF,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED,SAAS,iBAAiB,CAAC,aAA2B;IACrD,IAAI,CAAC,CAAC,aAAa,YAAY,YAAY,CAAC,EAAE;QAC7C,MAAM,IAAI,KAAK,CAAC,2BAA2B,aAAkC,2BAA2B,CAAC,CAAC;KAC1G;AACF,CAAC;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,KAAU,EAAE,OAAe;IACpD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,sBAAsB;QACtF,MAAM,OAAO,CAAC;KACd;AACF,CAAC;AAED,eAAe,YAAY,CAAC","sourcesContent":["import type CalendarType from \"@ui5/webcomponents-base/dist/types/CalendarType.js\";\nimport UniversalDate from \"./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, };
@@ -0,0 +1,29 @@
1
+ import CalendarDate from "./CalendarDate.js";
2
+ const cache = new Map();
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);
13
+ };
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);
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,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QACpB,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,mBAAmB,CAAC,CAAC;QAC/D,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACnB,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACpB,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACnB,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;KACxB;IAED,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,mBAAiC,EAAE,EAAE;IAChE,MAAM,GAAG,GAAG,OAAO,mBAAmB,EAAE,CAAC;IAEzC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QACpB,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,mBAAmB,CAAC,CAAC;QAC/D,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACtB,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACrB,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;QAChE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACpB,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QAC9C,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA,8BAA8B;QAClE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;KACxB;IAED,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;AACxB,CAAC,CAAC;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;