@ui5/webcomponents-localization 0.0.0-cc312800a → 0.0.0-cddf8ba1c

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 (284) hide show
  1. package/.eslintignore +2 -1
  2. package/.npsrc.json +3 -0
  3. package/CHANGELOG.md +751 -0
  4. package/README.md +37 -6
  5. package/dist/.tsbuildinfo +1 -0
  6. package/{src/Assets-static.js → dist/Assets-static.d.ts} +0 -1
  7. package/dist/Assets-static.js +1 -0
  8. package/dist/Assets-static.js.map +1 -0
  9. package/dist/Assets.d.ts +1 -0
  10. package/dist/Assets.js +1 -0
  11. package/dist/Assets.js.map +1 -0
  12. package/dist/DateFormat.d.ts +6 -0
  13. package/dist/DateFormat.js +6 -2
  14. package/dist/DateFormat.js.map +1 -0
  15. package/dist/LocaleData.d.ts +6 -0
  16. package/dist/LocaleData.js +6 -2
  17. package/dist/LocaleData.js.map +1 -0
  18. package/dist/dates/CalendarDate.d.ts +43 -0
  19. package/dist/dates/CalendarDate.js +171 -201
  20. package/dist/dates/CalendarDate.js.map +1 -0
  21. package/dist/dates/ExtremeDates.d.ts +5 -0
  22. package/dist/dates/ExtremeDates.js +25 -35
  23. package/dist/dates/ExtremeDates.js.map +1 -0
  24. package/dist/dates/UI5Date.d.ts +6 -0
  25. package/dist/dates/UI5Date.js +7 -0
  26. package/dist/dates/UI5Date.js.map +1 -0
  27. package/dist/dates/UniversalDate.d.ts +47 -0
  28. package/dist/dates/UniversalDate.js +5 -0
  29. package/dist/dates/UniversalDate.js.map +1 -0
  30. package/dist/dates/calculateWeekNumber.d.ts +5 -0
  31. package/dist/dates/calculateWeekNumber.js +42 -48
  32. package/dist/dates/calculateWeekNumber.js.map +1 -0
  33. package/dist/dates/convertMonthNumbersToMonthNames.d.ts +16 -0
  34. package/dist/dates/convertMonthNumbersToMonthNames.js +30 -0
  35. package/dist/dates/convertMonthNumbersToMonthNames.js.map +1 -0
  36. package/dist/dates/getDaysInMonth.d.ts +3 -0
  37. package/dist/dates/getDaysInMonth.js +10 -0
  38. package/dist/dates/getDaysInMonth.js.map +1 -0
  39. package/dist/dates/getRoundedTimestamp.d.ts +7 -0
  40. package/dist/dates/getRoundedTimestamp.js +10 -9
  41. package/dist/dates/getRoundedTimestamp.js.map +1 -0
  42. package/dist/dates/getTodayUTCTimestamp.d.ts +7 -0
  43. package/dist/dates/getTodayUTCTimestamp.js +3 -3
  44. package/dist/dates/getTodayUTCTimestamp.js.map +1 -0
  45. package/dist/dates/modifyDateBy.d.ts +14 -0
  46. package/dist/dates/modifyDateBy.js +42 -29
  47. package/dist/dates/modifyDateBy.js.map +1 -0
  48. package/dist/dates/transformDateToSecondaryType.d.ts +7 -0
  49. package/dist/dates/transformDateToSecondaryType.js +18 -0
  50. package/dist/dates/transformDateToSecondaryType.js.map +1 -0
  51. package/dist/features/calendar/Buddhist.js +1 -0
  52. package/dist/features/calendar/Buddhist.js.map +1 -0
  53. package/dist/features/calendar/Gregorian.js +1 -0
  54. package/dist/features/calendar/Gregorian.js.map +1 -0
  55. package/dist/features/calendar/Islamic.js +1 -0
  56. package/dist/features/calendar/Islamic.js.map +1 -0
  57. package/dist/features/calendar/Japanese.js +1 -0
  58. package/dist/features/calendar/Japanese.js.map +1 -0
  59. package/dist/features/calendar/Persian.js +1 -0
  60. package/dist/features/calendar/Persian.js.map +1 -0
  61. package/dist/generated/assets/cldr/ar.json +5531 -5906
  62. package/dist/generated/assets/cldr/ar_EG.json +5531 -5906
  63. package/dist/generated/assets/cldr/ar_SA.json +5530 -5906
  64. package/dist/generated/assets/cldr/bg.json +4452 -4979
  65. package/dist/generated/assets/cldr/ca.json +4440 -4996
  66. package/dist/generated/assets/cldr/cs.json +4960 -5498
  67. package/dist/generated/assets/cldr/cy.json +5211 -5884
  68. package/dist/generated/assets/cldr/da.json +4308 -4888
  69. package/dist/generated/assets/cldr/de.json +4313 -4916
  70. package/dist/generated/assets/cldr/de_AT.json +4314 -4917
  71. package/dist/generated/assets/cldr/de_CH.json +4312 -4915
  72. package/dist/generated/assets/cldr/el.json +4281 -4883
  73. package/dist/generated/assets/cldr/el_CY.json +4281 -4883
  74. package/dist/generated/assets/cldr/en.json +4316 -4970
  75. package/dist/generated/assets/cldr/en_AU.json +4319 -4962
  76. package/dist/generated/assets/cldr/en_GB.json +4329 -4971
  77. package/dist/generated/assets/cldr/en_HK.json +4337 -4977
  78. package/dist/generated/assets/cldr/en_IE.json +4328 -4971
  79. package/dist/generated/assets/cldr/en_IN.json +4333 -4972
  80. package/dist/generated/assets/cldr/en_NZ.json +4328 -4971
  81. package/dist/generated/assets/cldr/en_PG.json +4329 -4972
  82. package/dist/generated/assets/cldr/en_SG.json +4333 -4973
  83. package/dist/generated/assets/cldr/en_ZA.json +4329 -4972
  84. package/dist/generated/assets/cldr/es.json +4331 -4912
  85. package/dist/generated/assets/cldr/es_AR.json +4334 -4914
  86. package/dist/generated/assets/cldr/es_BO.json +4333 -4913
  87. package/dist/generated/assets/cldr/es_CL.json +4334 -4914
  88. package/dist/generated/assets/cldr/es_CO.json +4333 -4913
  89. package/dist/generated/assets/cldr/es_MX.json +4335 -4915
  90. package/dist/generated/assets/cldr/es_PE.json +4333 -4913
  91. package/dist/generated/assets/cldr/es_UY.json +4335 -4915
  92. package/dist/generated/assets/cldr/es_VE.json +4334 -4914
  93. package/dist/generated/assets/cldr/et.json +4340 -4967
  94. package/dist/generated/assets/cldr/fa.json +4367 -4883
  95. package/dist/generated/assets/cldr/fi.json +4463 -5008
  96. package/dist/generated/assets/cldr/fr.json +4357 -4979
  97. package/dist/generated/assets/cldr/fr_BE.json +4357 -4979
  98. package/dist/generated/assets/cldr/fr_CA.json +4351 -4973
  99. package/dist/generated/assets/cldr/fr_CH.json +4375 -4997
  100. package/dist/generated/assets/cldr/fr_LU.json +4357 -4979
  101. package/dist/generated/assets/cldr/he.json +4869 -5378
  102. package/dist/generated/assets/cldr/hi.json +4295 -4829
  103. package/dist/generated/assets/cldr/hr.json +4583 -4919
  104. package/dist/generated/assets/cldr/hu.json +4364 -4856
  105. package/dist/generated/assets/cldr/id.json +4060 -4658
  106. package/dist/generated/assets/cldr/it.json +4299 -4950
  107. package/dist/generated/assets/cldr/it_CH.json +4299 -4950
  108. package/dist/generated/assets/cldr/ja.json +4211 -4830
  109. package/dist/generated/assets/cldr/kk.json +4339 -4725
  110. package/dist/generated/assets/cldr/ko.json +4189 -4738
  111. package/dist/generated/assets/cldr/lt.json +4850 -5481
  112. package/dist/generated/assets/cldr/lv.json +4587 -5112
  113. package/dist/generated/assets/cldr/ms.json +4021 -4515
  114. package/dist/generated/assets/cldr/nb.json +4335 -4977
  115. package/dist/generated/assets/cldr/nl.json +4294 -4884
  116. package/dist/generated/assets/cldr/nl_BE.json +4294 -4884
  117. package/dist/generated/assets/cldr/pl.json +4667 -5176
  118. package/dist/generated/assets/cldr/pt.json +4235 -4805
  119. package/dist/generated/assets/cldr/pt_PT.json +4372 -4940
  120. package/dist/generated/assets/cldr/ro.json +4563 -5090
  121. package/dist/generated/assets/cldr/ru.json +4909 -5407
  122. package/dist/generated/assets/cldr/ru_UA.json +4909 -5407
  123. package/dist/generated/assets/cldr/sk.json +4939 -5370
  124. package/dist/generated/assets/cldr/sl.json +4910 -5340
  125. package/dist/generated/assets/cldr/sr.json +4585 -5126
  126. package/dist/generated/assets/cldr/sr_Latn.json +4574 -5127
  127. package/dist/generated/assets/cldr/sv.json +4362 -5011
  128. package/dist/generated/assets/cldr/th.json +4214 -4797
  129. package/dist/generated/assets/cldr/tr.json +4400 -4979
  130. package/dist/generated/assets/cldr/uk.json +4858 -5353
  131. package/dist/generated/assets/cldr/vi.json +4070 -4673
  132. package/dist/generated/assets/cldr/zh_CN.json +4100 -4632
  133. package/dist/generated/assets/cldr/zh_HK.json +4108 -4640
  134. package/dist/generated/assets/cldr/zh_SG.json +4108 -4640
  135. package/dist/generated/assets/cldr/zh_TW.json +4131 -4728
  136. package/dist/generated/json-imports/LocaleData-static.d.ts +1 -0
  137. package/dist/generated/json-imports/LocaleData-static.js +10 -11
  138. package/dist/generated/json-imports/LocaleData-static.js.map +1 -0
  139. package/dist/generated/json-imports/LocaleData.d.ts +1 -0
  140. package/dist/generated/json-imports/LocaleData.js +86 -87
  141. package/dist/generated/json-imports/LocaleData.js.map +1 -0
  142. package/dist/getCachedLocaleDataInstance.d.ts +4 -0
  143. package/dist/getCachedLocaleDataInstance.js +6 -9
  144. package/dist/getCachedLocaleDataInstance.js.map +1 -0
  145. package/dist/locale/getLocaleData.d.ts +11 -0
  146. package/dist/locale/getLocaleData.js +13 -17
  147. package/dist/locale/getLocaleData.js.map +1 -0
  148. package/dist/sap/base/Log.js +28 -37
  149. package/dist/sap/base/assert.js +5 -10
  150. package/dist/sap/base/i18n/LanguageTag.js +35 -0
  151. package/dist/sap/base/i18n/Localization.d.ts +4 -0
  152. package/dist/sap/base/i18n/Localization.js +12 -0
  153. package/dist/sap/base/i18n/Localization.js.map +1 -0
  154. package/dist/sap/base/i18n/date/CalendarType.js +8 -0
  155. package/dist/sap/base/i18n/date/CalendarWeekNumbering.js +30 -0
  156. package/dist/sap/base/i18n/date/TimezoneUtils.js +89 -0
  157. package/dist/sap/base/util/LoaderExtensions.d.ts +4 -0
  158. package/dist/sap/base/util/LoaderExtensions.js +9 -12
  159. package/dist/sap/base/util/LoaderExtensions.js.map +1 -0
  160. package/dist/sap/base/util/deepEqual.js +1 -5
  161. package/dist/sap/ui/base/Interface.js +1 -3
  162. package/dist/sap/ui/base/Metadata.js +20 -9
  163. package/dist/sap/ui/base/Object.js +26 -2
  164. package/dist/sap/ui/core/CalendarType.js +2 -8
  165. package/dist/sap/ui/core/Configuration.d.ts +18 -0
  166. package/dist/sap/ui/core/Configuration.js +23 -0
  167. package/dist/sap/ui/core/Configuration.js.map +1 -0
  168. package/dist/sap/ui/core/Core.d.ts +27 -0
  169. package/dist/sap/ui/core/Core.js +7 -32
  170. package/dist/sap/ui/core/Core.js.map +1 -0
  171. package/dist/sap/ui/core/FormatSettings.d.ts +10 -0
  172. package/dist/sap/ui/core/FormatSettings.js +14 -0
  173. package/dist/sap/ui/core/FormatSettings.js.map +1 -0
  174. package/dist/sap/ui/core/Locale.js +28 -110
  175. package/dist/sap/ui/core/LocaleData.js +215 -1537
  176. package/dist/sap/ui/core/date/Buddhist.js +0 -6
  177. package/dist/sap/ui/core/date/CalendarUtils.js +25 -0
  178. package/dist/sap/ui/core/date/CalendarWeekNumbering.js +2 -0
  179. package/dist/sap/ui/core/date/Islamic.js +3 -3
  180. package/dist/sap/ui/core/date/Japanese.js +4 -4
  181. package/dist/sap/ui/core/date/UI5Date.js +305 -0
  182. package/dist/sap/ui/core/date/UniversalDate.js +73 -26
  183. package/dist/sap/ui/core/format/DateFormat.js +849 -494
  184. package/dist/sap/ui/core/format/TimezoneUtil.js +2 -0
  185. package/package-scripts.cjs +32 -0
  186. package/package.json +15 -15
  187. package/src/generated/assets/cldr/ar.json +5533 -0
  188. package/src/generated/assets/cldr/ar_EG.json +5533 -0
  189. package/src/generated/assets/cldr/ar_SA.json +5532 -0
  190. package/src/generated/assets/cldr/bg.json +4454 -0
  191. package/src/generated/assets/cldr/ca.json +4442 -0
  192. package/src/generated/assets/cldr/cs.json +4962 -0
  193. package/src/generated/assets/cldr/cy.json +5213 -0
  194. package/src/generated/assets/cldr/da.json +4310 -0
  195. package/src/generated/assets/cldr/de.json +4315 -0
  196. package/src/generated/assets/cldr/de_AT.json +4316 -0
  197. package/src/generated/assets/cldr/de_CH.json +4314 -0
  198. package/src/generated/assets/cldr/el.json +4283 -0
  199. package/src/generated/assets/cldr/el_CY.json +4283 -0
  200. package/src/generated/assets/cldr/en.json +4318 -0
  201. package/src/generated/assets/cldr/en_AU.json +4321 -0
  202. package/src/generated/assets/cldr/en_GB.json +4331 -0
  203. package/src/generated/assets/cldr/en_HK.json +4339 -0
  204. package/src/generated/assets/cldr/en_IE.json +4330 -0
  205. package/src/generated/assets/cldr/en_IN.json +4335 -0
  206. package/src/generated/assets/cldr/en_NZ.json +4330 -0
  207. package/src/generated/assets/cldr/en_PG.json +4331 -0
  208. package/src/generated/assets/cldr/en_SG.json +4335 -0
  209. package/src/generated/assets/cldr/en_ZA.json +4331 -0
  210. package/src/generated/assets/cldr/es.json +4333 -0
  211. package/src/generated/assets/cldr/es_AR.json +4336 -0
  212. package/src/generated/assets/cldr/es_BO.json +4335 -0
  213. package/src/generated/assets/cldr/es_CL.json +4336 -0
  214. package/src/generated/assets/cldr/es_CO.json +4335 -0
  215. package/src/generated/assets/cldr/es_MX.json +4337 -0
  216. package/src/generated/assets/cldr/es_PE.json +4335 -0
  217. package/src/generated/assets/cldr/es_UY.json +4337 -0
  218. package/src/generated/assets/cldr/es_VE.json +4336 -0
  219. package/src/generated/assets/cldr/et.json +4342 -0
  220. package/src/generated/assets/cldr/fa.json +4369 -0
  221. package/src/generated/assets/cldr/fi.json +4465 -0
  222. package/src/generated/assets/cldr/fr.json +4359 -0
  223. package/src/generated/assets/cldr/fr_BE.json +4359 -0
  224. package/src/generated/assets/cldr/fr_CA.json +4353 -0
  225. package/src/generated/assets/cldr/fr_CH.json +4377 -0
  226. package/src/generated/assets/cldr/fr_LU.json +4359 -0
  227. package/src/generated/assets/cldr/he.json +4871 -0
  228. package/src/generated/assets/cldr/hi.json +4297 -0
  229. package/src/generated/assets/cldr/hr.json +4585 -0
  230. package/src/generated/assets/cldr/hu.json +4366 -0
  231. package/src/generated/assets/cldr/id.json +4062 -0
  232. package/src/generated/assets/cldr/it.json +4301 -0
  233. package/src/generated/assets/cldr/it_CH.json +4301 -0
  234. package/src/generated/assets/cldr/ja.json +4213 -0
  235. package/src/generated/assets/cldr/kk.json +4341 -0
  236. package/src/generated/assets/cldr/ko.json +4191 -0
  237. package/src/generated/assets/cldr/lt.json +4852 -0
  238. package/src/generated/assets/cldr/lv.json +4589 -0
  239. package/src/generated/assets/cldr/ms.json +4023 -0
  240. package/src/generated/assets/cldr/nb.json +4337 -0
  241. package/src/generated/assets/cldr/nl.json +4296 -0
  242. package/src/generated/assets/cldr/nl_BE.json +4296 -0
  243. package/src/generated/assets/cldr/pl.json +4669 -0
  244. package/src/generated/assets/cldr/pt.json +4237 -0
  245. package/src/generated/assets/cldr/pt_PT.json +4374 -0
  246. package/src/generated/assets/cldr/ro.json +4565 -0
  247. package/src/generated/assets/cldr/ru.json +4911 -0
  248. package/src/generated/assets/cldr/ru_UA.json +4911 -0
  249. package/src/generated/assets/cldr/sk.json +4941 -0
  250. package/src/generated/assets/cldr/sl.json +4912 -0
  251. package/src/generated/assets/cldr/sr.json +4587 -0
  252. package/src/generated/assets/cldr/sr_Latn.json +4576 -0
  253. package/src/generated/assets/cldr/sv.json +4364 -0
  254. package/src/generated/assets/cldr/th.json +4216 -0
  255. package/src/generated/assets/cldr/tr.json +4402 -0
  256. package/src/generated/assets/cldr/uk.json +4860 -0
  257. package/src/generated/assets/cldr/vi.json +4072 -0
  258. package/src/generated/assets/cldr/zh_CN.json +4102 -0
  259. package/src/generated/assets/cldr/zh_HK.json +4110 -0
  260. package/src/generated/assets/cldr/zh_SG.json +4110 -0
  261. package/src/generated/assets/cldr/zh_TW.json +4133 -0
  262. package/tsconfig.json +23 -0
  263. package/used-modules.txt +9 -1
  264. package/hash.txt +0 -1
  265. package/package-scripts.js +0 -37
  266. package/src/Assets.js +0 -2
  267. package/src/DateFormat.js +0 -3
  268. package/src/LocaleData.js +0 -3
  269. package/src/dates/CalendarDate.js +0 -223
  270. package/src/dates/ExtremeDates.js +0 -39
  271. package/src/dates/calculateWeekNumber.js +0 -51
  272. package/src/dates/getRoundedTimestamp.js +0 -14
  273. package/src/dates/getTodayUTCTimestamp.js +0 -9
  274. package/src/dates/modifyDateBy.js +0 -42
  275. package/src/getCachedLocaleDataInstance.js +0 -13
  276. package/src/locale/getLocaleData.js +0 -27
  277. package/src/sap/base/util/LoaderExtensions.js +0 -17
  278. package/src/sap/ui/core/Core.js +0 -38
  279. /package/{config/.eslintrc.js → .eslintrc.cjs} +0 -0
  280. /package/{src/features/calendar/Buddhist.js → dist/features/calendar/Buddhist.d.ts} +0 -0
  281. /package/{src/features/calendar/Gregorian.js → dist/features/calendar/Gregorian.d.ts} +0 -0
  282. /package/{src/features/calendar/Islamic.js → dist/features/calendar/Islamic.d.ts} +0 -0
  283. /package/{src/features/calendar/Japanese.js → dist/features/calendar/Japanese.d.ts} +0 -0
  284. /package/{src/features/calendar/Persian.js → dist/features/calendar/Persian.d.ts} +0 -0
@@ -1,51 +1,45 @@
1
- import UniversalDate from "../sap/ui/core/date/UniversalDate.js";
2
-
1
+ import UniversalDate from "./UniversalDate.js";
3
2
  const calculateWeekNumber = (confFirstDayOfWeek, oDate, iYear, oLocale, oLocaleData) => {
4
- let iWeekNum = 0;
5
- let iWeekDay = 0;
6
- const iFirstDayOfWeek = Number.isInteger(confFirstDayOfWeek) ? confFirstDayOfWeek : oLocaleData.getFirstDayOfWeek();
7
-
8
- // search Locale for containing "en-US", since sometimes
9
- // when any user settings have been defined, subtag "sapufmt" is added to the locale name
10
- // this is described inside sap.ui.core.Configuration file
11
- if (oLocale && (oLocale.getLanguage() === "en" && oLocale.getRegion() === "US")) {
12
- /*
13
- * in US the week starts with Sunday
14
- * The first week of the year starts with January 1st. But Dec. 31 is still in the last year
15
- * So the week beginning in December and ending in January has 2 week numbers
16
- */
17
- const oJanFirst = new UniversalDate(oDate.getTime());
18
- oJanFirst.setUTCFullYear(iYear, 0, 1);
19
- iWeekDay = oJanFirst.getUTCDay();
20
-
21
- // get the date for the same weekday like jan 1.
22
- const oCheckDate = new UniversalDate(oDate.getTime());
23
- oCheckDate.setUTCDate(oCheckDate.getUTCDate() - oCheckDate.getUTCDay() + iWeekDay);
24
-
25
- iWeekNum = Math.round((oCheckDate.getTime() - oJanFirst.getTime()) / 86400000 / 7) + 1;
26
- } else {
27
- // normally the first week of the year is the one where the first Thursday of the year is
28
- // find Thursday of this week
29
- // if the checked day is before the 1. day of the week use a day of the previous week to check
30
- const oThursday = new UniversalDate(oDate.getTime());
31
- oThursday.setUTCDate(oThursday.getUTCDate() - iFirstDayOfWeek);
32
- iWeekDay = oThursday.getUTCDay();
33
- oThursday.setUTCDate(oThursday.getUTCDate() - iWeekDay + 4);
34
-
35
- const oFirstDayOfYear = new UniversalDate(oThursday.getTime());
36
- oFirstDayOfYear.setUTCMonth(0, 1);
37
- iWeekDay = oFirstDayOfYear.getUTCDay();
38
- let iAddDays = 0;
39
- if (iWeekDay > 4) {
40
- iAddDays = 7; // first day of year is after Thursday, so first Thursday is in the next week
41
- }
42
- const oFirstThursday = new UniversalDate(oFirstDayOfYear.getTime());
43
- oFirstThursday.setUTCDate(1 - iWeekDay + 4 + iAddDays);
44
-
45
- iWeekNum = Math.round((oThursday.getTime() - oFirstThursday.getTime()) / 86400000 / 7) + 1;
46
- }
47
-
48
- return iWeekNum;
3
+ let iWeekNum = 0;
4
+ let iWeekDay = 0;
5
+ const iFirstDayOfWeek = Number.isInteger(confFirstDayOfWeek) ? confFirstDayOfWeek : oLocaleData.getFirstDayOfWeek();
6
+ // search Locale for containing "en-US", since sometimes
7
+ // when any user settings have been defined, subtag "sapufmt" is added to the locale name
8
+ // this is described inside sap.ui.core.Configuration file
9
+ if (oLocale && (oLocale.getLanguage() === "en" && oLocale.getRegion() === "US")) {
10
+ /*
11
+ * in US the week starts with Sunday
12
+ * The first week of the year starts with January 1st. But Dec. 31 is still in the last year
13
+ * So the week beginning in December and ending in January has 2 week numbers
14
+ */
15
+ const oJanFirst = new UniversalDate(oDate.getTime());
16
+ oJanFirst.setUTCFullYear(iYear, 0, 1);
17
+ iWeekDay = oJanFirst.getUTCDay();
18
+ // get the date for the same weekday like jan 1.
19
+ const oCheckDate = new UniversalDate(oDate.getTime());
20
+ oCheckDate.setUTCDate(oCheckDate.getUTCDate() - oCheckDate.getUTCDay() + iWeekDay);
21
+ iWeekNum = Math.round((oCheckDate.getTime() - oJanFirst.getTime()) / 86400000 / 7) + 1;
22
+ }
23
+ else {
24
+ // normally the first week of the year is the one where the first Thursday of the year is
25
+ // find Thursday of this week
26
+ // if the checked day is before the 1. day of the week use a day of the previous week to check
27
+ const oThursday = new UniversalDate(oDate.getTime());
28
+ oThursday.setUTCDate(oThursday.getUTCDate() - iFirstDayOfWeek);
29
+ iWeekDay = oThursday.getUTCDay();
30
+ oThursday.setUTCDate(oThursday.getUTCDate() - iWeekDay + 4);
31
+ const oFirstDayOfYear = new UniversalDate(oThursday.getTime());
32
+ oFirstDayOfYear.setUTCMonth(0, 1);
33
+ iWeekDay = oFirstDayOfYear.getUTCDay();
34
+ let iAddDays = 0;
35
+ if (iWeekDay > 4) {
36
+ iAddDays = 7; // first day of year is after Thursday, so first Thursday is in the next week
37
+ }
38
+ const oFirstThursday = new UniversalDate(oFirstDayOfYear.getTime());
39
+ oFirstThursday.setUTCDate(1 - iWeekDay + 4 + iAddDays);
40
+ iWeekNum = Math.round((oThursday.getTime() - oFirstThursday.getTime()) / 86400000 / 7) + 1;
41
+ }
42
+ return iWeekNum;
49
43
  };
50
-
51
44
  export default calculateWeekNumber;
45
+ //# sourceMappingURL=calculateWeekNumber.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculateWeekNumber.js","sourceRoot":"","sources":["../../src/dates/calculateWeekNumber.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAI/C,MAAM,mBAAmB,GAAG,CAAC,kBAAsC,EAAE,KAAqB,EAAE,KAAa,EAAE,OAAe,EAAE,WAAuB,EAAE,EAAE;IACtJ,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,MAAM,eAAe,GAAG,MAAM,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,kBAAmB,CAAC,CAAC,CAAC,WAAW,CAAC,iBAAiB,EAAE,CAAC;IAErH,wDAAwD;IACxD,yFAAyF;IACzF,0DAA0D;IAC1D,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,IAAI,IAAI,OAAO,CAAC,SAAS,EAAE,KAAK,IAAI,CAAC,EAAE;QAChF;;;;cAIG;QACH,MAAM,SAAS,GAAG,IAAI,aAAa,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACrD,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACtC,QAAQ,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC;QAEjC,gDAAgD;QAChD,MAAM,UAAU,GAAG,IAAI,aAAa,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACtD,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,UAAU,EAAE,GAAG,UAAU,CAAC,SAAS,EAAE,GAAG,QAAQ,CAAC,CAAC;QAEnF,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;KACvF;SAAM;QACN,yFAAyF;QACzF,6BAA6B;QAC7B,8FAA8F;QAC9F,MAAM,SAAS,GAAG,IAAI,aAAa,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACrD,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,EAAE,GAAG,eAAe,CAAC,CAAC;QAC/D,QAAQ,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC;QACjC,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,EAAE,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC;QAE5D,MAAM,eAAe,GAAG,IAAI,aAAa,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;QAC/D,eAAe,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAClC,QAAQ,GAAG,eAAe,CAAC,SAAS,EAAE,CAAC;QACvC,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,IAAI,QAAQ,GAAG,CAAC,EAAE;YACjB,QAAQ,GAAG,CAAC,CAAC,CAAC,6EAA6E;SAC3F;QACD,MAAM,cAAc,GAAG,IAAI,aAAa,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QACpE,cAAc,CAAC,UAAU,CAAC,CAAC,GAAG,QAAQ,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;QAEvD,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC,OAAO,EAAE,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;KAC3F;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC;AAEF,eAAe,mBAAmB,CAAC","sourcesContent":["import type Locale from \"@ui5/webcomponents-base/dist/locale/Locale.js\";\nimport UniversalDate from \"./UniversalDate.js\";\nimport type LocaleData from \"../LocaleData.js\";\nimport type UI5Date from \"./UI5Date.js\";\n\nconst calculateWeekNumber = (confFirstDayOfWeek: number | undefined, oDate: Date | UI5Date, iYear: number, oLocale: Locale, oLocaleData: LocaleData) => {\n\tlet iWeekNum = 0;\n\tlet iWeekDay = 0;\n\tconst iFirstDayOfWeek = Number.isInteger(confFirstDayOfWeek) ? confFirstDayOfWeek! : oLocaleData.getFirstDayOfWeek();\n\n\t// search Locale for containing \"en-US\", since sometimes\n\t// when any user settings have been defined, subtag \"sapufmt\" is added to the locale name\n\t// this is described inside sap.ui.core.Configuration file\n\tif (oLocale && (oLocale.getLanguage() === \"en\" && oLocale.getRegion() === \"US\")) {\n\t\t/*\n\t\t\t* in US the week starts with Sunday\n\t\t\t* The first week of the year starts with January 1st. But Dec. 31 is still in the last year\n\t\t\t* So the week beginning in December and ending in January has 2 week numbers\n\t\t\t*/\n\t\tconst oJanFirst = new UniversalDate(oDate.getTime());\n\t\toJanFirst.setUTCFullYear(iYear, 0, 1);\n\t\tiWeekDay = oJanFirst.getUTCDay();\n\n\t\t// get the date for the same weekday like jan 1.\n\t\tconst oCheckDate = new UniversalDate(oDate.getTime());\n\t\toCheckDate.setUTCDate(oCheckDate.getUTCDate() - oCheckDate.getUTCDay() + iWeekDay);\n\n\t\tiWeekNum = Math.round((oCheckDate.getTime() - oJanFirst.getTime()) / 86400000 / 7) + 1;\n\t} else {\n\t\t// normally the first week of the year is the one where the first Thursday of the year is\n\t\t// find Thursday of this week\n\t\t// if the checked day is before the 1. day of the week use a day of the previous week to check\n\t\tconst oThursday = new UniversalDate(oDate.getTime());\n\t\toThursday.setUTCDate(oThursday.getUTCDate() - iFirstDayOfWeek);\n\t\tiWeekDay = oThursday.getUTCDay();\n\t\toThursday.setUTCDate(oThursday.getUTCDate() - iWeekDay + 4);\n\n\t\tconst oFirstDayOfYear = new UniversalDate(oThursday.getTime());\n\t\toFirstDayOfYear.setUTCMonth(0, 1);\n\t\tiWeekDay = oFirstDayOfYear.getUTCDay();\n\t\tlet iAddDays = 0;\n\t\tif (iWeekDay > 4) {\n\t\t\tiAddDays = 7; // first day of year is after Thursday, so first Thursday is in the next week\n\t\t}\n\t\tconst oFirstThursday = new UniversalDate(oFirstDayOfYear.getTime());\n\t\toFirstThursday.setUTCDate(1 - iWeekDay + 4 + iAddDays);\n\n\t\tiWeekNum = Math.round((oThursday.getTime() - oFirstThursday.getTime()) / 86400000 / 7) + 1;\n\t}\n\n\treturn iWeekNum;\n};\n\nexport default calculateWeekNumber;\n"]}
@@ -0,0 +1,16 @@
1
+ import type CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
2
+ /**
3
+ * Convert month number to month name (text).
4
+ * If the numbers of the two months are the same you will get the name of the month,
5
+ * otherwise you will get the two names separated by a dash
6
+ *
7
+ * @param firstMonth CalendarDate Month
8
+ * @param lastMonth CalendarDate Month
9
+ * @param calendarType calendar type
10
+ * @returns {String}
11
+ */
12
+ declare const convertMonthNumbersToMonthNames: (firstMonth: number, lastMonth: number, calendarType?: `${CalendarType}`) => {
13
+ text: any;
14
+ textInfo: any;
15
+ };
16
+ export default convertMonthNumbersToMonthNames;
@@ -0,0 +1,30 @@
1
+ import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js";
2
+ import getCachedLocaleDataInstance from "../getCachedLocaleDataInstance.js";
3
+ /**
4
+ * Convert month number to month name (text).
5
+ * If the numbers of the two months are the same you will get the name of the month,
6
+ * otherwise you will get the two names separated by a dash
7
+ *
8
+ * @param firstMonth CalendarDate Month
9
+ * @param lastMonth CalendarDate Month
10
+ * @param calendarType calendar type
11
+ * @returns {String}
12
+ */
13
+ const convertMonthNumbersToMonthNames = (firstMonth, lastMonth, calendarType) => {
14
+ const localeData = getCachedLocaleDataInstance(getLocale());
15
+ const pattern = localeData.getIntervalPattern("");
16
+ const secondaryMonthsNames = localeData.getMonthsStandAlone("abbreviated", calendarType);
17
+ const secondaryMonthsNamesWide = localeData.getMonthsStandAlone("wide", calendarType);
18
+ if (firstMonth === lastMonth) {
19
+ return {
20
+ text: localeData.getMonths("abbreviated", calendarType)[firstMonth],
21
+ textInfo: localeData.getMonths("wide", calendarType)[firstMonth],
22
+ };
23
+ }
24
+ return {
25
+ text: pattern.replace(/\{0\}/, secondaryMonthsNames[firstMonth]).replace(/\{1\}/, secondaryMonthsNames[lastMonth]),
26
+ textInfo: pattern.replace(/\{0\}/, secondaryMonthsNamesWide[firstMonth]).replace(/\{1\}/, secondaryMonthsNamesWide[lastMonth]),
27
+ };
28
+ };
29
+ export default convertMonthNumbersToMonthNames;
30
+ //# sourceMappingURL=convertMonthNumbersToMonthNames.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertMonthNumbersToMonthNames.js","sourceRoot":"","sources":["../../src/dates/convertMonthNumbersToMonthNames.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,kDAAkD,CAAC;AAEzE,OAAO,2BAA2B,MAAM,mCAAmC,CAAC;AAE5E;;;;;;;;;GASG;AACH,MAAM,+BAA+B,GAAG,CAAC,UAAkB,EAAE,SAAiB,EAAE,YAAgC,EAAE,EAAE;IACnH,MAAM,UAAU,GAAG,2BAA2B,CAAC,SAAS,EAAE,CAAC,CAAC;IAC5D,MAAM,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;IAClD,MAAM,oBAAoB,GAAG,UAAU,CAAC,mBAAmB,CAAC,aAAa,EAAE,YAAY,CAAkB,CAAC;IAC1G,MAAM,wBAAwB,GAAG,UAAU,CAAC,mBAAmB,CAAC,MAAM,EAAE,YAAY,CAAkB,CAAC;IAEvG,IAAI,UAAU,KAAK,SAAS,EAAE;QAC7B,OAAO;YACN,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC,UAAU,CAAC;YACnE,QAAQ,EAAE,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,UAAU,CAAC;SAChE,CAAC;KACF;IAED,OAAO;QACN,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;QAClH,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,wBAAwB,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,wBAAwB,CAAC,SAAS,CAAC,CAAC;KAC9H,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,+BAA+B,CAAC","sourcesContent":["import getLocale from \"@ui5/webcomponents-base/dist/locale/getLocale.js\";\nimport type CalendarType from \"@ui5/webcomponents-base/dist/types/CalendarType.js\";\nimport getCachedLocaleDataInstance from \"../getCachedLocaleDataInstance.js\";\n\n/**\n * Convert month number to month name (text).\n * If the numbers of the two months are the same you will get the name of the month,\n * otherwise you will get the two names separated by a dash\n *\n * @param firstMonth CalendarDate Month\n * @param lastMonth CalendarDate Month\n * @param calendarType calendar type\n * @returns {String}\n */\nconst convertMonthNumbersToMonthNames = (firstMonth: number, lastMonth: number, calendarType?: `${CalendarType}`) => {\n\tconst localeData = getCachedLocaleDataInstance(getLocale());\n\tconst pattern = localeData.getIntervalPattern(\"\");\n\tconst secondaryMonthsNames = localeData.getMonthsStandAlone(\"abbreviated\", calendarType) as Array<string>;\n\tconst secondaryMonthsNamesWide = localeData.getMonthsStandAlone(\"wide\", calendarType) as Array<string>;\n\n\tif (firstMonth === lastMonth) {\n\t\treturn {\n\t\t\ttext: localeData.getMonths(\"abbreviated\", calendarType)[firstMonth],\n\t\t\ttextInfo: localeData.getMonths(\"wide\", calendarType)[firstMonth],\n\t\t};\n\t}\n\n\treturn {\n\t\ttext: pattern.replace(/\\{0\\}/, secondaryMonthsNames[firstMonth]).replace(/\\{1\\}/, secondaryMonthsNames[lastMonth]),\n\t\ttextInfo: pattern.replace(/\\{0\\}/, secondaryMonthsNamesWide[firstMonth]).replace(/\\{1\\}/, secondaryMonthsNamesWide[lastMonth]),\n\t};\n};\n\nexport default convertMonthNumbersToMonthNames;\n"]}
@@ -0,0 +1,3 @@
1
+ import CalendarDate from "./CalendarDate.js";
2
+ declare const getDaysInMonth: (date: CalendarDate) => number;
3
+ export default getDaysInMonth;
@@ -0,0 +1,10 @@
1
+ import CalendarDate from "./CalendarDate.js";
2
+ const getDaysInMonth = (date) => {
3
+ const tempCalendarDate = new CalendarDate(date);
4
+ tempCalendarDate.setDate(1);
5
+ tempCalendarDate.setMonth(tempCalendarDate.getMonth() + 1);
6
+ tempCalendarDate.setDate(0);
7
+ return tempCalendarDate.getDate();
8
+ };
9
+ export default getDaysInMonth;
10
+ //# sourceMappingURL=getDaysInMonth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDaysInMonth.js","sourceRoot":"","sources":["../../src/dates/getDaysInMonth.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAE7C,MAAM,cAAc,GAAG,CAAC,IAAkB,EAAE,EAAE;IAC7C,MAAM,gBAAgB,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IAChD,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5B,gBAAgB,CAAC,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3D,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5B,OAAO,gBAAgB,CAAC,OAAO,EAAE,CAAC;AACnC,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import CalendarDate from \"./CalendarDate.js\";\n\nconst getDaysInMonth = (date: CalendarDate) => {\n\tconst tempCalendarDate = new CalendarDate(date);\n\ttempCalendarDate.setDate(1);\n\ttempCalendarDate.setMonth(tempCalendarDate.getMonth() + 1);\n\ttempCalendarDate.setDate(0);\n\treturn tempCalendarDate.getDate();\n};\n\nexport default getDaysInMonth;\n"]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns a timestamp with only the year, month and day (with zero hours, minutes and seconds) and without 000 for milliseconds
3
+ * @param { number } millisecondsUTC
4
+ * @returns { number }
5
+ */
6
+ declare const getRoundedTimestamp: (millisecondsUTC: number) => number;
7
+ export default getRoundedTimestamp;
@@ -1,14 +1,15 @@
1
1
  /**
2
2
  * Returns a timestamp with only the year, month and day (with zero hours, minutes and seconds) and without 000 for milliseconds
3
- * @param millisecondsUTC
4
- * @returns {number}
3
+ * @param { number } millisecondsUTC
4
+ * @returns { number }
5
5
  */
6
- const getRoundedTimestamp = millisecondsUTC => {
7
- if (!millisecondsUTC) {
8
- millisecondsUTC = new Date().getTime();
9
- }
10
- const rounded = millisecondsUTC - (millisecondsUTC % (24 * 60 * 60 * 1000));
11
- return rounded / 1000;
6
+ const getRoundedTimestamp = (millisecondsUTC) => {
7
+ if (!millisecondsUTC) {
8
+ // no need to replace with UI5Date, as we don't use any non-UTC functions
9
+ millisecondsUTC = new Date().getTime();
10
+ }
11
+ const rounded = millisecondsUTC - (millisecondsUTC % (24 * 60 * 60 * 1000));
12
+ return rounded / 1000;
12
13
  };
13
-
14
14
  export default getRoundedTimestamp;
15
+ //# sourceMappingURL=getRoundedTimestamp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRoundedTimestamp.js","sourceRoot":"","sources":["../../src/dates/getRoundedTimestamp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,mBAAmB,GAAG,CAAC,eAAuB,EAAE,EAAE;IACvD,IAAI,CAAC,eAAe,EAAE;QACrB,yEAAyE;QACzE,eAAe,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;KACvC;IACD,MAAM,OAAO,GAAG,eAAe,GAAG,CAAC,eAAe,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IAC5E,OAAO,OAAO,GAAG,IAAI,CAAC;AACvB,CAAC,CAAC;AAEF,eAAe,mBAAmB,CAAC","sourcesContent":["/**\n * Returns a timestamp with only the year, month and day (with zero hours, minutes and seconds) and without 000 for milliseconds\n * @param { number } millisecondsUTC\n * @returns { number }\n */\nconst getRoundedTimestamp = (millisecondsUTC: number) => {\n\tif (!millisecondsUTC) {\n\t\t// no need to replace with UI5Date, as we don't use any non-UTC functions\n\t\tmillisecondsUTC = new Date().getTime();\n\t}\n\tconst rounded = millisecondsUTC - (millisecondsUTC % (24 * 60 * 60 * 1000));\n\treturn rounded / 1000;\n};\n\nexport default getRoundedTimestamp;\n"]}
@@ -0,0 +1,7 @@
1
+ import type CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
2
+ /**
3
+ * Returns a UTC timestamp representing today
4
+ * @public
5
+ */
6
+ declare const getTodayUTCTimestamp: (primaryCalendarType: `${CalendarType}`) => number;
7
+ export default getTodayUTCTimestamp;
@@ -1,9 +1,9 @@
1
1
  import CalendarDate from "./CalendarDate.js";
2
-
2
+ import UI5Date from "./UI5Date.js";
3
3
  /**
4
4
  * Returns a UTC timestamp representing today
5
5
  * @public
6
6
  */
7
- const getTodayUTCTimestamp = primaryCalendarType => CalendarDate.fromLocalJSDate(new Date(), primaryCalendarType).valueOf() / 1000;
8
-
7
+ const getTodayUTCTimestamp = (primaryCalendarType) => CalendarDate.fromLocalJSDate(UI5Date.getInstance(), primaryCalendarType).valueOf() / 1000;
9
8
  export default getTodayUTCTimestamp;
9
+ //# sourceMappingURL=getTodayUTCTimestamp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getTodayUTCTimestamp.js","sourceRoot":"","sources":["../../src/dates/getTodayUTCTimestamp.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAC7C,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC;;;GAGG;AACH,MAAM,oBAAoB,GAAG,CAAC,mBAAsC,EAAE,EAAE,CAAC,YAAY,CAAC,eAAe,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,mBAAmB,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;AAEnK,eAAe,oBAAoB,CAAC","sourcesContent":["import type CalendarType from \"@ui5/webcomponents-base/dist/types/CalendarType.js\";\nimport CalendarDate from \"./CalendarDate.js\";\nimport UI5Date from \"./UI5Date.js\";\n\n/**\n * Returns a UTC timestamp representing today\n * @public\n */\nconst getTodayUTCTimestamp = (primaryCalendarType: `${CalendarType}`) => CalendarDate.fromLocalJSDate(UI5Date.getInstance(), primaryCalendarType).valueOf() / 1000;\n\nexport default getTodayUTCTimestamp;\n"]}
@@ -0,0 +1,14 @@
1
+ import CalendarDate from "./CalendarDate.js";
2
+ /**
3
+ * Adds or subtracts a given amount of days/months/years from a date.
4
+ * If minDate or maxDate are given, the result will be enforced within these limits
5
+ *
6
+ * @param date CalendarDate instance
7
+ * @param amount how many days/months/years to add (can be a negative number)
8
+ * @param unit what to modify: "day", "month" or "year"
9
+ * @param preserveDate whether to preserve the day of the month (f.e. 15th of March + 1 month = 15th of April)
10
+ * @param minDate minimum date to enforce
11
+ * @param maxDate maximum date to enforce
12
+ */
13
+ declare const modifyDateBy: (date: CalendarDate, amount: number, unit: string, preserveDate?: boolean, minDate?: CalendarDate, maxDate?: CalendarDate) => CalendarDate;
14
+ export default modifyDateBy;
@@ -1,5 +1,4 @@
1
1
  import CalendarDate from "./CalendarDate.js";
2
-
3
2
  /**
4
3
  * Adds or subtracts a given amount of days/months/years from a date.
5
4
  * If minDate or maxDate are given, the result will be enforced within these limits
@@ -7,36 +6,50 @@ import CalendarDate from "./CalendarDate.js";
7
6
  * @param date CalendarDate instance
8
7
  * @param amount how many days/months/years to add (can be a negative number)
9
8
  * @param unit what to modify: "day", "month" or "year"
9
+ * @param preserveDate whether to preserve the day of the month (f.e. 15th of March + 1 month = 15th of April)
10
10
  * @param minDate minimum date to enforce
11
11
  * @param maxDate maximum date to enforce
12
12
  */
13
- const modifyDateBy = (date, amount, unit, minDate = null, maxDate = null) => {
14
- const newDate = new CalendarDate(date);
15
- if (unit === "day") {
16
- newDate.setDate(date.getDate() + amount);
17
- } else if (unit === "month") {
18
- newDate.setMonth(date.getMonth() + amount);
19
- const stillSameMonth = amount === -1 && newDate.getMonth() === date.getMonth(); // f.e. PageUp remained in the same month
20
- const monthSkipped = amount === 1 && newDate.getMonth() - date.getMonth() > 1; // f.e. PageDown skipped a whole month
21
- if (stillSameMonth || monthSkipped) { // Select the last day of the month in any of these 2 scenarios
22
- newDate.setDate(0);
23
- }
24
- } else {
25
- newDate.setYear(date.getYear() + amount);
26
- if (newDate.getMonth() !== date.getMonth()) { // f.e. 29th Feb to next/prev year
27
- newDate.setDate(0); // Select the last day of the month
28
- }
29
- }
30
-
31
- if (minDate && newDate.valueOf() < minDate.valueOf()) {
32
- return new CalendarDate(minDate);
33
- }
34
-
35
- if (maxDate && newDate.valueOf() > maxDate.valueOf()) {
36
- return new CalendarDate(maxDate);
37
- }
38
-
39
- return newDate;
13
+ const modifyDateBy = (date, amount, unit, preserveDate = true, minDate, maxDate) => {
14
+ const newDate = new CalendarDate(date);
15
+ switch (unit) {
16
+ case "day":
17
+ newDate.setDate(date.getDate() + amount);
18
+ break;
19
+ case "month":
20
+ if (preserveDate) {
21
+ newDate.setMonth(date.getMonth() + amount);
22
+ const stillSameMonth = amount === -1 && newDate.getMonth() === date.getMonth(); // f.e. PageUp remained in the same month
23
+ const monthSkipped = amount === 1 && newDate.getMonth() - date.getMonth() > 1; // f.e. PageDown skipped a whole month
24
+ if (stillSameMonth || monthSkipped) { // Select the last day of the month in any of these 2 scenarios
25
+ newDate.setDate(0);
26
+ }
27
+ }
28
+ else {
29
+ if (amount === 1) {
30
+ newDate.setMonth(newDate.getMonth() + 1, 1);
31
+ }
32
+ if (amount === -1) {
33
+ newDate.setDate(0);
34
+ }
35
+ }
36
+ break;
37
+ case "year":
38
+ newDate.setYear(date.getYear() + amount);
39
+ if (newDate.getMonth() !== date.getMonth()) { // f.e. 29th Feb to next/prev year
40
+ newDate.setDate(0); // Select the last day of the month
41
+ }
42
+ break;
43
+ default:
44
+ break;
45
+ }
46
+ if (minDate && newDate.isBefore(minDate)) {
47
+ return new CalendarDate(minDate);
48
+ }
49
+ if (maxDate && newDate.isAfter(maxDate)) {
50
+ return new CalendarDate(maxDate);
51
+ }
52
+ return newDate;
40
53
  };
41
-
42
54
  export default modifyDateBy;
55
+ //# sourceMappingURL=modifyDateBy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modifyDateBy.js","sourceRoot":"","sources":["../../src/dates/modifyDateBy.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAE7C;;;;;;;;;;GAUG;AACH,MAAM,YAAY,GAAG,CAAC,IAAkB,EAAE,MAAc,EAAE,IAAY,EAAE,YAAY,GAAG,IAAI,EAAE,OAAsB,EAAE,OAAsB,EAAE,EAAE;IAC9I,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IAEvC,QAAQ,IAAI,EAAE;QACd,KAAK,KAAK;YACT,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC;YACzC,MAAM;QACP,KAAK,OAAO;YACX,IAAI,YAAY,EAAE;gBACjB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,CAAC;gBAC3C,MAAM,cAAc,GAAG,MAAM,KAAK,CAAC,CAAC,IAAI,OAAO,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,yCAAyC;gBACzH,MAAM,YAAY,GAAG,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,sCAAsC;gBACrH,IAAI,cAAc,IAAI,YAAY,EAAE,EAAE,+DAA+D;oBACpG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;iBACnB;aACD;iBAAM;gBACN,IAAI,MAAM,KAAK,CAAC,EAAE;oBACjB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;iBAC5C;gBACD,IAAI,MAAM,KAAK,CAAC,CAAC,EAAE;oBAClB,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;iBACnB;aACD;YACD,MAAM;QACP,KAAK,MAAM;YACV,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC;YACzC,IAAI,OAAO,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC,QAAQ,EAAE,EAAE,EAAE,kCAAkC;gBAC/E,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,mCAAmC;aACvD;YACD,MAAM;QACP;YACC,MAAM;KACN;IAED,IAAI,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACzC,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;KACjC;IAED,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QACxC,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;KACjC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import CalendarDate from \"./CalendarDate.js\";\n\n/**\n * Adds or subtracts a given amount of days/months/years from a date.\n * If minDate or maxDate are given, the result will be enforced within these limits\n *\n * @param date CalendarDate instance\n * @param amount how many days/months/years to add (can be a negative number)\n * @param unit what to modify: \"day\", \"month\" or \"year\"\n * @param preserveDate whether to preserve the day of the month (f.e. 15th of March + 1 month = 15th of April)\n * @param minDate minimum date to enforce\n * @param maxDate maximum date to enforce\n */\nconst modifyDateBy = (date: CalendarDate, amount: number, unit: string, preserveDate = true, minDate?: CalendarDate, maxDate?: CalendarDate) => {\n\tconst newDate = new CalendarDate(date);\n\n\tswitch (unit) {\n\tcase \"day\":\n\t\tnewDate.setDate(date.getDate() + amount);\n\t\tbreak;\n\tcase \"month\":\n\t\tif (preserveDate) {\n\t\t\tnewDate.setMonth(date.getMonth() + amount);\n\t\t\tconst stillSameMonth = amount === -1 && newDate.getMonth() === date.getMonth(); // f.e. PageUp remained in the same month\n\t\t\tconst monthSkipped = amount === 1 && newDate.getMonth() - date.getMonth() > 1; // f.e. PageDown skipped a whole month\n\t\t\tif (stillSameMonth || monthSkipped) { // Select the last day of the month in any of these 2 scenarios\n\t\t\t\tnewDate.setDate(0);\n\t\t\t}\n\t\t} else {\n\t\t\tif (amount === 1) {\n\t\t\t\tnewDate.setMonth(newDate.getMonth() + 1, 1);\n\t\t\t}\n\t\t\tif (amount === -1) {\n\t\t\t\tnewDate.setDate(0);\n\t\t\t}\n\t\t}\n\t\tbreak;\n\tcase \"year\":\n\t\tnewDate.setYear(date.getYear() + amount);\n\t\tif (newDate.getMonth() !== date.getMonth()) { // f.e. 29th Feb to next/prev year\n\t\t\tnewDate.setDate(0); // Select the last day of the month\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tbreak;\n\t}\n\n\tif (minDate && newDate.isBefore(minDate)) {\n\t\treturn new CalendarDate(minDate);\n\t}\n\n\tif (maxDate && newDate.isAfter(maxDate)) {\n\t\treturn new CalendarDate(maxDate);\n\t}\n\n\treturn newDate;\n};\n\nexport default modifyDateBy;\n"]}
@@ -0,0 +1,7 @@
1
+ import type CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
2
+ import CalendarDate from "./CalendarDate.js";
3
+ declare const transformDateToSecondaryType: (primaryCalendarType: `${CalendarType}` | undefined, secondaryCalendarType: `${CalendarType}` | undefined, timeStamp: number, hasYearPicker?: boolean) => {
4
+ firstDate: CalendarDate;
5
+ lastDate: CalendarDate;
6
+ };
7
+ export default transformDateToSecondaryType;
@@ -0,0 +1,18 @@
1
+ import CalendarDate from "./CalendarDate.js";
2
+ import getDaysInMonth from "./getDaysInMonth.js";
3
+ import UI5Date from "./UI5Date.js";
4
+ const transformDateToSecondaryType = (primaryCalendarType, secondaryCalendarType, timeStamp, hasYearPicker) => {
5
+ let firstDate = CalendarDate.fromLocalJSDate(UI5Date.getInstance(timeStamp * 1000), primaryCalendarType);
6
+ let lastDate = CalendarDate.fromLocalJSDate(UI5Date.getInstance(timeStamp * 1000), primaryCalendarType);
7
+ firstDate.setDate(1);
8
+ if (hasYearPicker) {
9
+ firstDate.setMonth(0);
10
+ lastDate.setMonth(11);
11
+ }
12
+ lastDate.setDate(getDaysInMonth(lastDate));
13
+ firstDate = new CalendarDate(firstDate, secondaryCalendarType);
14
+ lastDate = new CalendarDate(lastDate, secondaryCalendarType);
15
+ return { firstDate, lastDate };
16
+ };
17
+ export default transformDateToSecondaryType;
18
+ //# sourceMappingURL=transformDateToSecondaryType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformDateToSecondaryType.js","sourceRoot":"","sources":["../../src/dates/transformDateToSecondaryType.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAC7C,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,MAAM,4BAA4B,GAAG,CAAC,mBAAkD,EAAE,qBAAmD,EAAE,SAAiB,EAAE,aAAuB,EAAE,EAAE;IAC5L,IAAI,SAAS,GAAG,YAAY,CAAC,eAAe,CAAC,OAAO,CAAC,WAAW,CAAC,SAAS,GAAG,IAAI,CAAC,EAAE,mBAAmB,CAAC,CAAC;IACzG,IAAI,QAAQ,GAAG,YAAY,CAAC,eAAe,CAAC,OAAO,CAAC,WAAW,CAAC,SAAS,GAAG,IAAI,CAAC,EAAE,mBAAmB,CAAC,CAAC;IACxG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAErB,IAAI,aAAa,EAAE;QAClB,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;KACtB;IAED,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3C,SAAS,GAAG,IAAI,YAAY,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;IAC/D,QAAQ,GAAG,IAAI,YAAY,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;IAC7D,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AAChC,CAAC,CAAC;AAEF,eAAe,4BAA4B,CAAC","sourcesContent":["import type CalendarType from \"@ui5/webcomponents-base/dist/types/CalendarType.js\";\nimport CalendarDate from \"./CalendarDate.js\";\nimport getDaysInMonth from \"./getDaysInMonth.js\";\nimport UI5Date from \"./UI5Date.js\";\n\nconst transformDateToSecondaryType = (primaryCalendarType: `${CalendarType}` | undefined, secondaryCalendarType: `${CalendarType}`| undefined, timeStamp: number, hasYearPicker?: boolean) => {\n\tlet firstDate = CalendarDate.fromLocalJSDate(UI5Date.getInstance(timeStamp * 1000), primaryCalendarType);\n\tlet lastDate = CalendarDate.fromLocalJSDate(UI5Date.getInstance(timeStamp * 1000), primaryCalendarType);\n\tfirstDate.setDate(1);\n\n\tif (hasYearPicker) {\n\t\tfirstDate.setMonth(0);\n\t\tlastDate.setMonth(11);\n\t}\n\n\tlastDate.setDate(getDaysInMonth(lastDate));\n\tfirstDate = new CalendarDate(firstDate, secondaryCalendarType);\n\tlastDate = new CalendarDate(lastDate, secondaryCalendarType);\n\treturn { firstDate, lastDate };\n};\n\nexport default transformDateToSecondaryType;\n"]}
@@ -1 +1,2 @@
1
1
  import "../../sap/ui/core/date/Buddhist.js";
2
+ //# sourceMappingURL=Buddhist.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Buddhist.js","sourceRoot":"","sources":["../../../src/features/calendar/Buddhist.ts"],"names":[],"mappings":"AAAA,OAAO,oCAAoC,CAAC","sourcesContent":["import \"../../sap/ui/core/date/Buddhist.js\";\n"]}
@@ -1 +1,2 @@
1
1
  import "../../sap/ui/core/date/Gregorian.js";
2
+ //# sourceMappingURL=Gregorian.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Gregorian.js","sourceRoot":"","sources":["../../../src/features/calendar/Gregorian.ts"],"names":[],"mappings":"AAAA,OAAO,qCAAqC,CAAC","sourcesContent":["import \"../../sap/ui/core/date/Gregorian.js\";\n"]}
@@ -1 +1,2 @@
1
1
  import "../../sap/ui/core/date/Islamic.js";
2
+ //# sourceMappingURL=Islamic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Islamic.js","sourceRoot":"","sources":["../../../src/features/calendar/Islamic.ts"],"names":[],"mappings":"AAAA,OAAO,mCAAmC,CAAC","sourcesContent":["import \"../../sap/ui/core/date/Islamic.js\";\n"]}
@@ -1 +1,2 @@
1
1
  import "../../sap/ui/core/date/Japanese.js";
2
+ //# sourceMappingURL=Japanese.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Japanese.js","sourceRoot":"","sources":["../../../src/features/calendar/Japanese.ts"],"names":[],"mappings":"AAAA,OAAO,oCAAoC,CAAC","sourcesContent":["import \"../../sap/ui/core/date/Japanese.js\";\n"]}
@@ -1 +1,2 @@
1
1
  import "../../sap/ui/core/date/Persian.js";
2
+ //# sourceMappingURL=Persian.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Persian.js","sourceRoot":"","sources":["../../../src/features/calendar/Persian.ts"],"names":[],"mappings":"AAAA,OAAO,mCAAmC,CAAC","sourcesContent":["import \"../../sap/ui/core/date/Persian.js\";\n"]}