@ui5/webcomponents-localization 0.0.0-0fcda382e → 0.0.0-10f3c0dc7

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 (275) hide show
  1. package/.eslintignore +2 -0
  2. package/.npsrc.json +3 -0
  3. package/CHANGELOG.md +2427 -0
  4. package/LICENSE.txt +201 -0
  5. package/README.md +38 -10
  6. package/dist/.tsbuildinfo +1 -0
  7. package/dist/Assets-fetch.d.ts +1 -0
  8. package/dist/Assets-fetch.js +3 -0
  9. package/dist/Assets-fetch.js.map +1 -0
  10. package/dist/Assets-node.d.ts +11 -0
  11. package/dist/Assets-node.js +12 -0
  12. package/dist/Assets-node.js.map +1 -0
  13. package/dist/Assets.d.ts +1 -0
  14. package/dist/Assets.js +1 -0
  15. package/dist/Assets.js.map +1 -0
  16. package/dist/CalendarUtils.d.ts +3 -0
  17. package/dist/CalendarUtils.js +6 -0
  18. package/dist/CalendarUtils.js.map +1 -0
  19. package/dist/DateFormat.d.ts +28 -0
  20. package/dist/DateFormat.js +22 -2
  21. package/dist/DateFormat.js.map +1 -0
  22. package/dist/Locale.d.ts +5 -0
  23. package/dist/Locale.js +7 -0
  24. package/dist/Locale.js.map +1 -0
  25. package/dist/LocaleData.d.ts +5 -0
  26. package/dist/LocaleData.js +6 -2
  27. package/dist/LocaleData.js.map +1 -0
  28. package/dist/NumberFormat.d.ts +5 -0
  29. package/dist/NumberFormat.js +7 -0
  30. package/dist/NumberFormat.js.map +1 -0
  31. package/dist/dates/CalendarDate.d.ts +42 -0
  32. package/dist/dates/CalendarDate.js +171 -181
  33. package/dist/dates/CalendarDate.js.map +1 -0
  34. package/dist/dates/ExtremeDates.d.ts +5 -0
  35. package/dist/dates/ExtremeDates.js +29 -0
  36. package/dist/dates/ExtremeDates.js.map +1 -0
  37. package/dist/dates/UI5Date.d.ts +5 -0
  38. package/dist/dates/UI5Date.js +7 -0
  39. package/dist/dates/UI5Date.js.map +1 -0
  40. package/dist/dates/UniversalDate.d.ts +47 -0
  41. package/dist/dates/UniversalDate.js +5 -0
  42. package/dist/dates/UniversalDate.js.map +1 -0
  43. package/dist/dates/convertMonthNumbersToMonthNames.d.ts +16 -0
  44. package/dist/dates/convertMonthNumbersToMonthNames.js +30 -0
  45. package/dist/dates/convertMonthNumbersToMonthNames.js.map +1 -0
  46. package/dist/dates/getDaysInMonth.d.ts +3 -0
  47. package/dist/dates/getDaysInMonth.js +10 -0
  48. package/dist/dates/getDaysInMonth.js.map +1 -0
  49. package/dist/dates/getRoundedTimestamp.d.ts +7 -0
  50. package/dist/dates/getRoundedTimestamp.js +15 -0
  51. package/dist/dates/getRoundedTimestamp.js.map +1 -0
  52. package/dist/dates/getTodayUTCTimestamp.d.ts +7 -0
  53. package/dist/dates/getTodayUTCTimestamp.js +9 -0
  54. package/dist/dates/getTodayUTCTimestamp.js.map +1 -0
  55. package/dist/dates/modifyDateBy.d.ts +14 -0
  56. package/dist/dates/modifyDateBy.js +55 -0
  57. package/dist/dates/modifyDateBy.js.map +1 -0
  58. package/dist/dates/transformDateToSecondaryType.d.ts +7 -0
  59. package/dist/dates/transformDateToSecondaryType.js +18 -0
  60. package/dist/dates/transformDateToSecondaryType.js.map +1 -0
  61. package/dist/features/calendar/Buddhist.js +1 -0
  62. package/dist/features/calendar/Buddhist.js.map +1 -0
  63. package/dist/features/calendar/Gregorian.js +1 -0
  64. package/dist/features/calendar/Gregorian.js.map +1 -0
  65. package/dist/features/calendar/Islamic.js +1 -0
  66. package/dist/features/calendar/Islamic.js.map +1 -0
  67. package/dist/features/calendar/Japanese.js +1 -0
  68. package/dist/features/calendar/Japanese.js.map +1 -0
  69. package/dist/features/calendar/Persian.js +1 -0
  70. package/dist/features/calendar/Persian.js.map +1 -0
  71. package/dist/generated/assets/cldr/Unicode-Data-Files-LICENSE.txt +39 -0
  72. package/dist/generated/assets/cldr/ar.json +2179 -728
  73. package/dist/generated/assets/cldr/ar_EG.json +2179 -728
  74. package/dist/generated/assets/cldr/ar_SA.json +2275 -825
  75. package/dist/generated/assets/cldr/bg.json +1924 -798
  76. package/dist/generated/assets/cldr/ca.json +2027 -816
  77. package/dist/generated/assets/cldr/cnr.json +6476 -0
  78. package/dist/generated/assets/cldr/cs.json +1865 -842
  79. package/dist/generated/assets/cldr/cy.json +6566 -0
  80. package/dist/generated/assets/cldr/da.json +1844 -682
  81. package/dist/generated/assets/cldr/de.json +1806 -546
  82. package/dist/generated/assets/cldr/de_AT.json +1797 -537
  83. package/dist/generated/assets/cldr/de_CH.json +1879 -611
  84. package/dist/generated/assets/cldr/el.json +1497 -383
  85. package/dist/generated/assets/cldr/el_CY.json +1497 -383
  86. package/dist/generated/assets/cldr/en.json +1990 -563
  87. package/dist/generated/assets/cldr/en_AU.json +2339 -763
  88. package/dist/generated/assets/cldr/en_GB.json +2170 -621
  89. package/dist/generated/assets/cldr/en_HK.json +2076 -628
  90. package/dist/generated/assets/cldr/en_IE.json +2038 -593
  91. package/dist/generated/assets/cldr/en_IN.json +2336 -704
  92. package/dist/generated/assets/cldr/en_NZ.json +2056 -611
  93. package/dist/generated/assets/cldr/en_PG.json +2049 -604
  94. package/dist/generated/assets/cldr/en_SG.json +2041 -593
  95. package/dist/generated/assets/cldr/en_ZA.json +2046 -599
  96. package/dist/generated/assets/cldr/es.json +2197 -881
  97. package/dist/generated/assets/cldr/es_AR.json +2167 -819
  98. package/dist/generated/assets/cldr/es_BO.json +2210 -863
  99. package/dist/generated/assets/cldr/es_CL.json +2087 -848
  100. package/dist/generated/assets/cldr/es_CO.json +1947 -707
  101. package/dist/generated/assets/cldr/es_MX.json +2446 -1091
  102. package/dist/generated/assets/cldr/es_PE.json +1912 -773
  103. package/dist/generated/assets/cldr/es_UY.json +1926 -795
  104. package/dist/generated/assets/cldr/es_VE.json +1920 -789
  105. package/dist/generated/assets/cldr/et.json +1761 -544
  106. package/dist/generated/assets/cldr/fa.json +1872 -566
  107. package/dist/generated/assets/cldr/fi.json +1959 -526
  108. package/dist/generated/assets/cldr/fr.json +1711 -460
  109. package/dist/generated/assets/cldr/fr_BE.json +1710 -459
  110. package/dist/generated/assets/cldr/fr_CA.json +2087 -814
  111. package/dist/generated/assets/cldr/fr_CH.json +1669 -418
  112. package/dist/generated/assets/cldr/fr_LU.json +1711 -460
  113. package/dist/generated/assets/cldr/he.json +2018 -1033
  114. package/dist/generated/assets/cldr/hi.json +1619 -348
  115. package/dist/generated/assets/cldr/hr.json +1855 -569
  116. package/dist/generated/assets/cldr/hu.json +1764 -551
  117. package/dist/generated/assets/cldr/id.json +1924 -601
  118. package/dist/generated/assets/cldr/it.json +1821 -666
  119. package/dist/generated/assets/cldr/it_CH.json +1827 -672
  120. package/dist/generated/assets/cldr/ja.json +1426 -109
  121. package/dist/generated/assets/cldr/kk.json +2251 -737
  122. package/dist/generated/assets/cldr/ko.json +1484 -196
  123. package/dist/generated/assets/cldr/lt.json +1714 -734
  124. package/dist/generated/assets/cldr/lv.json +1686 -682
  125. package/dist/generated/assets/cldr/mk.json +6177 -0
  126. package/dist/generated/assets/cldr/ms.json +1903 -595
  127. package/dist/generated/assets/cldr/nb.json +1548 -369
  128. package/dist/generated/assets/cldr/nl.json +1935 -511
  129. package/dist/generated/assets/cldr/nl_BE.json +1955 -531
  130. package/dist/generated/assets/cldr/pl.json +1873 -586
  131. package/dist/generated/assets/cldr/pt.json +2184 -753
  132. package/dist/generated/assets/cldr/pt_PT.json +2149 -778
  133. package/dist/generated/assets/cldr/ro.json +1847 -765
  134. package/dist/generated/assets/cldr/ru.json +2082 -755
  135. package/dist/generated/assets/cldr/ru_UA.json +2076 -749
  136. package/dist/generated/assets/cldr/sk.json +1860 -972
  137. package/dist/generated/assets/cldr/sl.json +1861 -920
  138. package/dist/generated/assets/cldr/sr.json +1829 -767
  139. package/dist/generated/assets/cldr/sr_Latn.json +6173 -0
  140. package/dist/generated/assets/cldr/sv.json +1789 -587
  141. package/dist/generated/assets/cldr/th.json +1704 -373
  142. package/dist/generated/assets/cldr/tr.json +1855 -587
  143. package/dist/generated/assets/cldr/uk.json +2166 -711
  144. package/dist/generated/assets/cldr/vi.json +2054 -709
  145. package/dist/generated/assets/cldr/zh_CN.json +1736 -397
  146. package/dist/generated/assets/cldr/zh_HK.json +1713 -374
  147. package/dist/generated/assets/cldr/zh_SG.json +1723 -384
  148. package/dist/generated/assets/cldr/zh_TW.json +1678 -371
  149. package/dist/generated/json-imports/LocaleData-fetch.d.ts +1 -0
  150. package/dist/generated/json-imports/LocaleData-fetch.js +93 -0
  151. package/dist/generated/json-imports/LocaleData-fetch.js.map +1 -0
  152. package/dist/generated/json-imports/LocaleData-node.d.ts +1 -0
  153. package/dist/generated/json-imports/LocaleData-node.js +93 -0
  154. package/dist/generated/json-imports/LocaleData-node.js.map +1 -0
  155. package/dist/generated/json-imports/LocaleData.d.ts +1 -0
  156. package/dist/generated/json-imports/LocaleData.js +92 -95
  157. package/dist/generated/json-imports/LocaleData.js.map +1 -0
  158. package/dist/getCachedLocaleDataInstance.d.ts +4 -0
  159. package/dist/getCachedLocaleDataInstance.js +12 -0
  160. package/dist/getCachedLocaleDataInstance.js.map +1 -0
  161. package/dist/locale/getLocaleData.d.ts +11 -0
  162. package/dist/locale/getLocaleData.js +15 -17
  163. package/dist/locale/getLocaleData.js.map +1 -0
  164. package/dist/sap/base/Event.js +59 -0
  165. package/dist/sap/base/Eventing.js +147 -0
  166. package/dist/sap/base/Log.js +2 -248
  167. package/dist/sap/base/assert.js +31 -9
  168. package/dist/sap/base/config/MemoryConfigurationProvider.js +20 -0
  169. package/dist/sap/base/config.js +17 -0
  170. package/dist/sap/base/future.js +12 -0
  171. package/dist/sap/base/i18n/Formatting.d.ts +13 -0
  172. package/dist/sap/base/i18n/Formatting.js +18 -0
  173. package/dist/sap/base/i18n/Formatting.js.map +1 -0
  174. package/dist/sap/base/i18n/LanguageTag.js +179 -0
  175. package/dist/sap/base/i18n/Localization.d.ts +7 -0
  176. package/dist/sap/base/i18n/Localization.js +17 -0
  177. package/dist/sap/base/i18n/Localization.js.map +1 -0
  178. package/dist/sap/base/i18n/ResourceBundle.js +20 -0
  179. package/dist/sap/base/i18n/date/CalendarType.js +44 -0
  180. package/dist/sap/base/i18n/date/CalendarWeekNumbering.js +106 -0
  181. package/dist/sap/base/i18n/date/TimezoneUtils.js +471 -0
  182. package/dist/sap/base/i18n/date/_EnumHelper.js +37 -0
  183. package/dist/sap/base/strings/camelize.js +30 -0
  184. package/dist/sap/base/strings/formatMessage.js +93 -15
  185. package/dist/sap/base/util/LoaderExtensions.d.ts +4 -0
  186. package/dist/sap/base/util/LoaderExtensions.js +11 -4
  187. package/dist/sap/base/util/LoaderExtensions.js.map +1 -0
  188. package/dist/sap/base/util/ObjectPath.d.ts +4 -0
  189. package/dist/sap/base/util/ObjectPath.js +4 -33
  190. package/dist/sap/base/util/ObjectPath.js.map +1 -0
  191. package/dist/sap/base/util/Properties.js +12 -0
  192. package/dist/sap/base/util/Version.js +163 -0
  193. package/dist/sap/base/util/_merge.js +83 -26
  194. package/dist/sap/base/util/array/uniqueSort.js +37 -15
  195. package/dist/sap/base/util/deepClone.js +102 -0
  196. package/dist/sap/base/util/deepEqual.js +75 -55
  197. package/dist/sap/base/util/deepExtend.js +60 -0
  198. package/dist/sap/base/util/extend.js +58 -7
  199. package/dist/sap/base/util/fetch.js +8 -0
  200. package/dist/sap/base/util/isEmptyObject.js +34 -0
  201. package/dist/sap/base/util/isPlainObject.js +35 -1
  202. package/dist/sap/base/util/merge.js +57 -0
  203. package/dist/sap/base/util/mixedFetch.js +3 -0
  204. package/dist/sap/base/util/now.js +22 -7
  205. package/dist/sap/base/util/resolveReference.js +3 -0
  206. package/dist/sap/base/util/uid.js +27 -0
  207. package/dist/sap/ui/Device.js +25 -3
  208. package/dist/sap/ui/Global.js +1 -0
  209. package/dist/sap/ui/VersionInfo.js +14 -0
  210. package/dist/sap/ui/base/DataType.js +708 -0
  211. package/dist/sap/ui/base/DesignTime.js +11 -0
  212. package/dist/sap/ui/base/EventProvider.js +21 -0
  213. package/dist/sap/ui/base/Interface.js +50 -6
  214. package/dist/sap/ui/base/Metadata.js +470 -173
  215. package/dist/sap/ui/base/Object.js +287 -27
  216. package/dist/sap/ui/base/OwnStatics.js +6 -0
  217. package/dist/sap/ui/base/SyncPromise.js +98 -0
  218. package/dist/sap/ui/core/AnimationMode.js +42 -0
  219. package/dist/sap/ui/core/CalendarType.js +24 -8
  220. package/dist/sap/ui/core/Configuration.d.ts +17 -0
  221. package/dist/sap/ui/core/Configuration.js +23 -0
  222. package/dist/sap/ui/core/Configuration.js.map +1 -0
  223. package/dist/sap/ui/core/ControlBehavior.js +11 -0
  224. package/dist/sap/ui/core/Core.d.ts +25 -0
  225. package/dist/sap/ui/core/Core.js +7 -32
  226. package/dist/sap/ui/core/Core.js.map +1 -0
  227. package/dist/sap/ui/core/FormatSettings.d.ts +9 -0
  228. package/dist/sap/ui/core/FormatSettings.js +12 -0
  229. package/dist/sap/ui/core/FormatSettings.js.map +1 -0
  230. package/dist/sap/ui/core/Lib.js +41 -0
  231. package/dist/sap/ui/core/Locale.js +190 -116
  232. package/dist/sap/ui/core/LocaleData.js +2837 -2683
  233. package/dist/sap/ui/core/Supportability.js +5 -0
  234. package/dist/sap/ui/core/Theming.js +39 -0
  235. package/dist/sap/ui/core/_UrlResolver.js +11 -0
  236. package/dist/sap/ui/core/date/Buddhist.js +162 -93
  237. package/dist/sap/ui/core/date/CalendarUtils.js +67 -0
  238. package/dist/sap/ui/core/date/CalendarWeekNumbering.js +30 -0
  239. package/dist/sap/ui/core/date/Gregorian.js +25 -10
  240. package/dist/sap/ui/core/date/Islamic.js +298 -185
  241. package/dist/sap/ui/core/date/Japanese.js +212 -117
  242. package/dist/sap/ui/core/date/Persian.js +324 -195
  243. package/dist/sap/ui/core/date/UI5Date.js +1039 -0
  244. package/dist/sap/ui/core/date/UniversalDate.js +1241 -217
  245. package/dist/sap/ui/core/date/_Calendars.js +10 -1
  246. package/dist/sap/ui/core/format/DateFormat.js +3160 -1781
  247. package/dist/sap/ui/core/format/FormatUtils.js +30 -0
  248. package/dist/sap/ui/core/format/NumberFormat.js +3164 -0
  249. package/dist/sap/ui/core/format/TimezoneUtil.js +93 -0
  250. package/dist/sap/ui/core/getCompatibilityVersion.js +7 -0
  251. package/dist/sap/ui/core/theming/ThemeHelper.js +14 -0
  252. package/dist/sap/ui/security/Security.js +12 -0
  253. package/dist/sap/ui/util/XMLHelper.js +11 -0
  254. package/dist/sap/ui/util/_URL.js +1 -0
  255. package/dist/ui5loader-autoconfig.js +1 -0
  256. package/package-scripts.cjs +35 -0
  257. package/package.json +27 -21
  258. package/tsconfig.json +24 -0
  259. package/used-modules.txt +33 -1
  260. package/dist/dates/calculateWeekNumber.js +0 -51
  261. package/package-scripts.js +0 -31
  262. package/src/Assets.js +0 -2
  263. package/src/DateFormat.js +0 -3
  264. package/src/LocaleData.js +0 -3
  265. package/src/dates/CalendarDate.js +0 -203
  266. package/src/dates/calculateWeekNumber.js +0 -51
  267. package/src/locale/getLocaleData.js +0 -27
  268. package/src/sap/base/util/LoaderExtensions.js +0 -7
  269. package/src/sap/ui/core/Core.js +0 -38
  270. /package/{config/.eslintrc.js → .eslintrc.cjs} +0 -0
  271. /package/{src/features/calendar/Buddhist.js → dist/features/calendar/Buddhist.d.ts} +0 -0
  272. /package/{src/features/calendar/Gregorian.js → dist/features/calendar/Gregorian.d.ts} +0 -0
  273. /package/{src/features/calendar/Islamic.js → dist/features/calendar/Islamic.d.ts} +0 -0
  274. /package/{src/features/calendar/Japanese.js → dist/features/calendar/Japanese.d.ts} +0 -0
  275. /package/{src/features/calendar/Persian.js → dist/features/calendar/Persian.d.ts} +0 -0
@@ -1,282 +1,1306 @@
1
- import Core from '../Core.js';
2
- import BaseObject from '../../base/Object.js';
3
- import LocaleData from '../LocaleData.js';
4
- import _Calendars from './_Calendars.js';
5
- var UniversalDate = BaseObject.extend('sap.ui.core.date.UniversalDate', {
6
- constructor: function () {
7
- var clDate = UniversalDate.getClass();
8
- return this.createDate(clDate, arguments);
9
- }
1
+ /*!
2
+ * OpenUI5
3
+ * (c) Copyright 2026 SAP SE or an SAP affiliate company.
4
+ * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
5
+ */
6
+ // Provides class sap.ui.core.date.UniversalDate
7
+ import Formatting from "../../../base/i18n/Formatting.js";
8
+ import CalendarWeekNumbering from "../../../base/i18n/date/CalendarWeekNumbering.js";
9
+ import BaseObject from "../../base/Object.js";
10
+ import Locale from "../Locale.js";
11
+ import LocaleData from "../LocaleData.js";
12
+ import _Calendars from "./_Calendars.js";
13
+ import CalendarUtils from "./CalendarUtils.js";
14
+ import UI5Date from "./UI5Date.js";
15
+ /**
16
+ * Constructor for UniversalDate.
17
+ *
18
+ * @class
19
+ * The UniversalDate is the base class of calendar date instances. It contains the static methods to create calendar
20
+ * specific instances.
21
+ *
22
+ * The member variable <code>this.oDate</code> contains a date instance
23
+ * (either JavaScript Date or <code>module:sap/ui/core/date/UI5Date</code>) which considers the
24
+ * configured time zone wherever JavaScript Date uses the local browser time zone; see
25
+ * {@link module:sap/ui/core/date/UI5Date#getInstance}. This is the source value of the date
26
+ * information. The prototype contains getters and setters of the Date and is delegating them
27
+ * to the internal date object. Implementations for specific calendars may override methods
28
+ * needed for their specific calendar (e.g. getYear and getEra for Japanese emperor calendar).
29
+ *
30
+ * @private
31
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
32
+ * @alias sap.ui.core.date.UniversalDate
33
+ */
34
+ var UniversalDate = BaseObject.extend("sap.ui.core.date.UniversalDate", /** @lends sap.ui.core.date.UniversalDate.prototype */{
35
+ constructor: function () {
36
+ var clDate = UniversalDate.getClass();
37
+ return this.createDate(clDate, arguments);
38
+ }
10
39
  });
40
+
41
+ /**
42
+ * Delegates this method to the calendar-specific implementation.
43
+ *
44
+ * @returns {int}
45
+ * The number of milliseconds since January 1, 1970, 00:00:00 UTC based on the Gregorian
46
+ * calendar, for the given calendar-specific arguments
47
+ *
48
+ * @private
49
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
50
+ */
11
51
  UniversalDate.UTC = function () {
12
- var clDate = UniversalDate.getClass();
13
- return clDate.UTC.apply(clDate, arguments);
52
+ var clDate = UniversalDate.getClass();
53
+ return clDate.UTC.apply(clDate, arguments);
14
54
  };
55
+
56
+ /**
57
+ * Returns a number representing the millisecond since January 1, 1970, 00:00:00 to the current date,
58
+ * see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now Date.now}.
59
+ *
60
+ * @returns {int} A number representing the millisecond since January 1, 1970, 00:00:00 to the current date
61
+ *
62
+ * @private
63
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
64
+ */
15
65
  UniversalDate.now = function () {
16
- return Date.now();
66
+ return Date.now();
17
67
  };
68
+
69
+ /**
70
+ * Creates an object of the provided date class and with the given arguments.
71
+ *
72
+ * @param {function} clDate
73
+ * The constructor function for either <code>Date</code> or an implementation of
74
+ * <code>sap.ui.core.date.UniversalDate</code>
75
+ * @param {object} aArgs
76
+ * The <code>arguments</code> object which is given to the constructor of the given date class
77
+ * to create the date object
78
+ * @returns {sap.ui.core.date.UniversalDate|module:sap/ui/core/date/UI5Date}
79
+ * The created date, either an UI5Date or UniversalDate instance
80
+ *
81
+ * @private
82
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
83
+ */
18
84
  UniversalDate.prototype.createDate = function (clDate, aArgs) {
19
- switch (aArgs.length) {
20
- case 0:
21
- return new clDate();
22
- case 1:
23
- return new clDate(aArgs[0]);
24
- case 2:
25
- return new clDate(aArgs[0], aArgs[1]);
26
- case 3:
27
- return new clDate(aArgs[0], aArgs[1], aArgs[2]);
28
- case 4:
29
- return new clDate(aArgs[0], aArgs[1], aArgs[2], aArgs[3]);
30
- case 5:
31
- return new clDate(aArgs[0], aArgs[1], aArgs[2], aArgs[3], aArgs[4]);
32
- case 6:
33
- return new clDate(aArgs[0], aArgs[1], aArgs[2], aArgs[3], aArgs[4], aArgs[5]);
34
- case 7:
35
- return new clDate(aArgs[0], aArgs[1], aArgs[2], aArgs[3], aArgs[4], aArgs[5], aArgs[6]);
36
- }
85
+ if (clDate === Date) {
86
+ return UI5Date.getInstance.apply(null, aArgs);
87
+ }
88
+ return new clDate(...aArgs);
37
89
  };
90
+
91
+ /**
92
+ * Returns an instance of UniversalDate, based on the calendar type from the configuration, or as explicitly
93
+ * defined by parameter. The object contains getters and setters of the JavaScript Date and is delegating them
94
+ * to an internal date object.
95
+ *
96
+ * Note: Prefer this method over calling <code>new UniversalDate</code> with an instance of <code>Date</code>.
97
+ *
98
+ * @param {Date|module:sap/ui/core/date/UI5Date|sap.ui.core.date.UniversalDate} [oDate]
99
+ * The date object, defaults to <code>UI5Date.getInstance()</code>
100
+ * @param {module:sap/base/i18n/date/CalendarType} [sCalendarType]
101
+ * The calendar type, defaults to <code>module:sap/base/i18n/Formatting.getCalendarType()</code>
102
+ * @returns {sap.ui.core.date.UniversalDate}
103
+ * An instance of <code>UniversalDate</code>
104
+ *
105
+ * @private
106
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
107
+ */
38
108
  UniversalDate.getInstance = function (oDate, sCalendarType) {
39
- var clDate, oInstance;
40
- if (oDate instanceof UniversalDate) {
41
- oDate = oDate.getJSDate();
42
- }
43
- if (!sCalendarType) {
44
- sCalendarType = Core.getConfiguration().getCalendarType();
45
- }
46
- clDate = UniversalDate.getClass(sCalendarType);
47
- oInstance = Object.create(clDate.prototype);
48
- oInstance.oDate = oDate;
49
- oInstance.sCalendarType = sCalendarType;
50
- return oInstance;
109
+ var clDate, oInstance;
110
+ if (oDate instanceof UniversalDate) {
111
+ oDate = oDate.getJSDate();
112
+ }
113
+ if (oDate && isNaN(oDate.getTime())) {
114
+ throw new Error("The given date object is invalid");
115
+ }
116
+ if (!sCalendarType) {
117
+ sCalendarType = Formatting.getCalendarType();
118
+ }
119
+ clDate = UniversalDate.getClass(sCalendarType);
120
+ oInstance = Object.create(clDate.prototype);
121
+ oInstance.oDate = oDate ? UI5Date.getInstance(oDate) : UI5Date.getInstance();
122
+ oInstance.sCalendarType = sCalendarType;
123
+ return oInstance;
51
124
  };
125
+
126
+ /**
127
+ * Returns the constructor function of a subclass of <code>UniversalDate</code> for the given calendar type.
128
+ * If no calendar type is given the globally configured calendar type is used.
129
+ *
130
+ * @param {module:sap/base/i18n/date/CalendarType} sCalendarType the type of the used calendar
131
+ *
132
+ * @returns {function}
133
+ * The class of the given <code>sCalendarType</code>. If <code>sCalendarType</code> is not
134
+ * provided, the class of the configured calendar type is returned.
135
+ *
136
+ * @private
137
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
138
+ */
52
139
  UniversalDate.getClass = function (sCalendarType) {
53
- if (!sCalendarType) {
54
- sCalendarType = Core.getConfiguration().getCalendarType();
55
- }
56
- return _Calendars.get(sCalendarType);
140
+ if (!sCalendarType) {
141
+ sCalendarType = Formatting.getCalendarType();
142
+ }
143
+ return _Calendars.get(sCalendarType);
57
144
  };
58
- [
59
- 'getDate',
60
- 'getMonth',
61
- 'getFullYear',
62
- 'getYear',
63
- 'getDay',
64
- 'getHours',
65
- 'getMinutes',
66
- 'getSeconds',
67
- 'getMilliseconds',
68
- 'getUTCDate',
69
- 'getUTCMonth',
70
- 'getUTCFullYear',
71
- 'getUTCDay',
72
- 'getUTCHours',
73
- 'getUTCMinutes',
74
- 'getUTCSeconds',
75
- 'getUTCMilliseconds',
76
- 'getTime',
77
- 'valueOf',
78
- 'getTimezoneOffset',
79
- 'toString',
80
- 'toDateString',
81
- 'setDate',
82
- 'setFullYear',
83
- 'setYear',
84
- 'setMonth',
85
- 'setHours',
86
- 'setMinutes',
87
- 'setSeconds',
88
- 'setMilliseconds',
89
- 'setUTCDate',
90
- 'setUTCFullYear',
91
- 'setUTCMonth',
92
- 'setUTCHours',
93
- 'setUTCMinutes',
94
- 'setUTCSeconds',
95
- 'setUTCMilliseconds'
96
- ].forEach(function (sName) {
97
- UniversalDate.prototype[sName] = function () {
98
- return this.oDate[sName].apply(this.oDate, arguments);
99
- };
145
+
146
+ /**
147
+ * Returns the day of the month of the embedded date instance according to the configured time
148
+ * zone and selected calendar.
149
+ *
150
+ * @returns {int}
151
+ * A number representing the day of the month of the embedded date instance according
152
+ * to the configured time zone and selected calendar
153
+ *
154
+ * @function
155
+ * @name sap.ui.core.date.UniversalDate.prototype.getDate
156
+ * @private
157
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
158
+ */
159
+
160
+ /**
161
+ * Returns the day of the week of the embedded date instance according to the configured time zone and
162
+ * selected calendar.
163
+ *
164
+ * @returns {int}
165
+ * A number representing the day of the week of the embedded date instance according to the configured
166
+ * time zone and selected calendar
167
+ *
168
+ * @function
169
+ * @name sap.ui.core.date.UniversalDate.prototype.getDay
170
+ * @private
171
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
172
+ */
173
+
174
+ /**
175
+ * Returns the year of the embedded date instance according to the configured time zone and selected calendar.
176
+ *
177
+ * @returns {int}
178
+ * The year of the embedded date instance according to the configured time zone and selected calendar
179
+ *
180
+ * @function
181
+ * @name sap.ui.core.date.UniversalDate.prototype.getFullYear
182
+ * @private
183
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
184
+ */
185
+
186
+ /**
187
+ * Returns the hours of the embedded date instance according to the configured time zone and selected
188
+ * calendar.
189
+ *
190
+ * @returns {int}
191
+ * A number representing the hours of the embedded date instance according to the configured time zone
192
+ * and selected calendar
193
+ *
194
+ * @function
195
+ * @name sap.ui.core.date.UniversalDate.prototype.getHours
196
+ * @private
197
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
198
+ */
199
+
200
+ /**
201
+ * Returns the milliseconds of the embedded date instance according to the configured time zone
202
+ * and selected calendar.
203
+ *
204
+ * @returns {int}
205
+ * A number between 0 and 999 representing the milliseconds of the embedded date instance according to
206
+ * the configured time zone and selected calendar
207
+ *
208
+ * @function
209
+ * @name sap.ui.core.date.UniversalDate.prototype.getMilliseconds
210
+ * @private
211
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
212
+ */
213
+
214
+ /**
215
+ * Returns the minutes of the embedded date instance according to the configured time zone and selected calendar.
216
+ *
217
+ * @returns {int}
218
+ * A number between 0 and 59 representing the minutes of the embedded date instance according to the
219
+ * configured time zone and selected calendar
220
+ *
221
+ * @function
222
+ * @name sap.ui.core.date.UniversalDate.prototype.getMinutes
223
+ * @private
224
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
225
+ */
226
+
227
+ /**
228
+ * Returns the month index of the embedded date instance according to the configured time zone
229
+ * and selected calendar.
230
+ *
231
+ * @returns {int}
232
+ * The month index of the embedded date instance according to the configured time zone and selected calendar
233
+ *
234
+ * @function
235
+ * @name sap.ui.core.date.UniversalDate.prototype.getMonth
236
+ * @private
237
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
238
+ */
239
+
240
+ /**
241
+ * Returns the seconds of the embedded date instance according to the configured time zone and selected calendar.
242
+ *
243
+ * @returns {int}
244
+ * A number between 0 and 59 representing the seconds of the embedded date instance according to the
245
+ * configured time zone and selected calendar
246
+ *
247
+ * @function
248
+ * @name sap.ui.core.date.UniversalDate.prototype.getSeconds
249
+ * @private
250
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
251
+ */
252
+
253
+ /**
254
+ * Returns the difference in minutes between the UTC and the configured time zone for the embedded date.
255
+ *
256
+ * @returns {int}
257
+ * The difference in minutes between the UTC and the configured time zone for the embedded date
258
+ *
259
+ * @function
260
+ * @name sap.ui.core.date.UniversalDate.prototype.getTimezoneOffset
261
+ * @private
262
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
263
+ */
264
+
265
+ /**
266
+ * Returns the year of the embedded date instance minus 1900 according to the configured time zone and
267
+ * selected calendar. In case of the Gregorian calendar the 1900 is subtracted from the year value.
268
+ *
269
+ * @returns {int}
270
+ * The year of the embedded date instance (minus 1900 if the Gregorian calendar is selected)
271
+ * according to the configured time zone and selected calendar
272
+ *
273
+ * @deprecated as of version 1.111.0 as it is deprecated in the base JavaScript <code>Date</code> class.
274
+ * Although it can be used with calendars other than the Gregorian calendar, use {@link #getFullYear} instead,
275
+ * regardless of the selected calendar.
276
+ *
277
+ * @function
278
+ * @name sap.ui.core.date.UniversalDate.prototype.getYear
279
+ * @private
280
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
281
+ */
282
+
283
+ /**
284
+ * Returns the timestamp in milliseconds of the embedded date based on the UNIX epoch.
285
+ *
286
+ * @returns {int}
287
+ * The timestamp in milliseconds of the embedded date based on the UNIX epoch, or <code>NaN</code> if
288
+ * the embedded date is an invalid date
289
+ *
290
+ * @function
291
+ * @name sap.ui.core.date.UniversalDate.prototype.getTime
292
+ * @private
293
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
294
+ */
295
+
296
+ /**
297
+ * Returns the day of the month of the embedded date instance according to universal time and
298
+ * selected calendar.
299
+ *
300
+ * @returns {int}
301
+ * A number representing the day of the month of the embedded date instance according
302
+ * to universal time and selected calendar
303
+ *
304
+ * @function
305
+ * @name sap.ui.core.date.UniversalDate.prototype.getUTCDate
306
+ * @private
307
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
308
+ */
309
+
310
+ /**
311
+ *
312
+ * Returns the day of the week of the embedded date instance according to universal time and
313
+ * selected calendar.
314
+ *
315
+ * @returns {int}
316
+ * A number representing the day of the week of the embedded date instance according to universal
317
+ * time and selected calendar
318
+ *
319
+ * @function
320
+ * @name sap.ui.core.date.UniversalDate.prototype.getUTCDay
321
+ * @private
322
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
323
+ */
324
+
325
+ /**
326
+ * Returns the year of the embedded date instance according to universal time and selected calendar.
327
+ *
328
+ * @returns {int}
329
+ * The year of the embedded date instance according to universal time and selected calendar
330
+ *
331
+ * @function
332
+ * @name sap.ui.core.date.UniversalDate.prototype.getUTCFullYear
333
+ * @private
334
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
335
+ */
336
+
337
+ /**
338
+ * Returns the hours of the embedded date instance according to universal time.
339
+ *
340
+ * @returns {int}
341
+ * A number representing the hours of the embedded date instance according to universal time
342
+ *
343
+ * @function
344
+ * @name sap.ui.core.date.UniversalDate.prototype.getUTCHours
345
+ * @private
346
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
347
+ */
348
+
349
+ /**
350
+ * Returns the milliseconds of the embedded date instance according to universal time.
351
+ *
352
+ * @returns {int}
353
+ * A number between 0 and 999 representing the milliseconds of the embedded date instance
354
+ * according to universal time
355
+ *
356
+ * @function
357
+ * @name sap.ui.core.date.UniversalDate.prototype.getUTCMilliseconds
358
+ * @private
359
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
360
+ */
361
+
362
+ /**
363
+ * Returns the minutes of the embedded date instance according to universal time.
364
+ *
365
+ * @returns {int}
366
+ * A number between 0 and 59 representing the minutes of the embedded date instance according
367
+ * to universal time
368
+ *
369
+ * @function
370
+ * @name sap.ui.core.date.UniversalDate.prototype.getUTCMinutes
371
+ * @private
372
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
373
+ */
374
+
375
+ /**
376
+ * Returns the month index of the embedded date instance according to universal time and
377
+ * selected calendar.
378
+ *
379
+ * @returns {int}
380
+ * The month index of the embedded date instance according to universal time and selected
381
+ * calendar
382
+ *
383
+ * @function
384
+ * @name sap.ui.core.date.UniversalDate.prototype.getUTCMonth
385
+ * @private
386
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
387
+ */
388
+
389
+ /**
390
+ * Returns the seconds of the embedded date instance according to universal time.
391
+ *
392
+ * @returns {int}
393
+ * A number between 0 and 59 representing the seconds of the embedded date instance according
394
+ * to universal time
395
+ *
396
+ * @function
397
+ * @name sap.ui.core.date.UniversalDate.prototype.getUTCSeconds
398
+ * @private
399
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
400
+ */
401
+
402
+ /**
403
+ * Sets the day of the month for the embedded date instance considering the configured time zone
404
+ * and selected calendar.
405
+ *
406
+ * @param {int} iDay
407
+ * An integer representing the new day value
408
+ * @returns {int}
409
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
410
+ * timestamp could not be updated. The new timestamp is a Gregorian timestamp.
411
+ *
412
+ * @function
413
+ * @name sap.ui.core.date.UniversalDate.prototype.setDate
414
+ * @private
415
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
416
+ */
417
+
418
+ /**
419
+ * Sets the year, month and day for the embedded date instance considering the configured time
420
+ * zone and selected calendar.
421
+ *
422
+ * @param {int} yearValue An integer representing the new year value
423
+ * @param {int} [monthValue] An integer representing the new month index
424
+ * @param {int} [dateValue] An integer representing the new day value
425
+ * @returns {int}
426
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
427
+ * timestamp could not be updated. The new timestamp is a Gregorian timestamp.
428
+ *
429
+ * @function
430
+ * @name sap.ui.core.date.UniversalDate.prototype.setFullYear
431
+ * @private
432
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
433
+ */
434
+
435
+ /**
436
+ * Sets the hours, minutes, seconds and milliseconds for the embedded date instance considering
437
+ * the configured time zone.
438
+ *
439
+ * @param {int} hoursValue An integer representing the new hours value
440
+ * @param {int} [minutesValue] An integer representing the new minutes value
441
+ * @param {int} [secondsValue] An integer representing the new seconds value
442
+ * @param {int} [msValue] An integer representing the new milliseconds value
443
+ * @returns {int}
444
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
445
+ * timestamp could not be updated. The new timestamp is a Gregorian timestamp.
446
+ *
447
+ * @function
448
+ * @name sap.ui.core.date.UniversalDate.prototype.setHours
449
+ * @private
450
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
451
+ */
452
+
453
+ /**
454
+ * Sets the milliseconds for the embedded date instance considering the configured time zone.
455
+ *
456
+ * @param {int} millisecondsValue An integer representing the new milliseconds value
457
+ * @returns {int}
458
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
459
+ * timestamp could not be updated. The new timestamp is a Gregorian timestamp.
460
+ *
461
+ * @function
462
+ * @name sap.ui.core.date.UniversalDate.prototype.setMilliseconds
463
+ * @private
464
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
465
+ */
466
+
467
+ /**
468
+ * Sets the minutes, seconds and milliseconds for the embedded date instance considering the configured
469
+ * time zone.
470
+ *
471
+ * @param {int} minutesValue An integer representing the new minutes value
472
+ * @param {int} [secondsValue] An integer representing the new seconds value
473
+ * @param {int} [msValue] An integer representing the new milliseconds value
474
+ * @returns {int}
475
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
476
+ * timestamp could not be updated. The new timestamp is a Gregorian timestamp.
477
+ *
478
+ * @function
479
+ * @name sap.ui.core.date.UniversalDate.prototype.setMinutes
480
+ * @private
481
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
482
+ */
483
+
484
+ /**
485
+ * Sets the month and day for the embedded date instance considering the configured time zone and
486
+ * selected calendar.
487
+ *
488
+ * @param {int} monthValue An integer representing the new month index
489
+ * @param {int} [dayValue] An integer representing the new day value
490
+ * @returns {int}
491
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
492
+ * timestamp could not be updated. The new timestamp is a Gregorian timestamp.
493
+ *
494
+ * @function
495
+ * @name sap.ui.core.date.UniversalDate.prototype.setMonth
496
+ * @private
497
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
498
+ */
499
+
500
+ /**
501
+ * Sets the seconds and milliseconds for the embedded date instance considering the configured time zone.
502
+ *
503
+ * @param {int} secondsValue An integer representing the new seconds value
504
+ * @param {int} [msValue] An integer representing the new milliseconds value
505
+ * @returns {int}
506
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
507
+ * timestamp could not be updated. The new timestamp is a Gregorian timestamp.
508
+ *
509
+ * @function
510
+ * @name sap.ui.core.date.UniversalDate.prototype.setSeconds
511
+ * @private
512
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
513
+ */
514
+
515
+ /**
516
+ * Sets the day of the month for the embedded date instance according to universal time and
517
+ * selected calendar.
518
+ *
519
+ * @param {int} dayValue
520
+ * An integer representing the new day value
521
+ * @returns {int}
522
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
523
+ * timestamp could not be updated. The new timestamp is a Gregorian timestamp.
524
+ *
525
+ * @function
526
+ * @name sap.ui.core.date.UniversalDate.prototype.setUTCDate
527
+ * @private
528
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
529
+ */
530
+
531
+ /**
532
+ * Sets the year, month and day for the embedded date instance according to universal time and
533
+ * selected calendar.
534
+ *
535
+ * @param {int} yearValue An integer representing the new year value
536
+ * @param {int} [monthValue] An integer representing the new month index
537
+ * @param {int} [dateValue] An integer representing the new day value
538
+ * @returns {int}
539
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
540
+ * timestamp could not be updated. The new timestamp is a Gregorian timestamp.
541
+ *
542
+ * @function
543
+ * @name sap.ui.core.date.UniversalDate.prototype.setUTCFullYear
544
+ * @private
545
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
546
+ */
547
+
548
+ /**
549
+ * Sets the hours, minutes, seconds and milliseconds for the embedded date instance according to
550
+ * universal time.
551
+ *
552
+ * @param {int} hoursValue An integer representing the new hours value
553
+ * @param {int} [minutesValue] An integer representing the new minutes value
554
+ * @param {int} [secondsValue] An integer representing the new seconds value
555
+ * @param {int} [msValue] An integer representing the new milliseconds value
556
+ * @returns {int}
557
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
558
+ * timestamp could not be updated. The new timestamp is a Gregorian timestamp.
559
+ *
560
+ * @function
561
+ * @name sap.ui.core.date.UniversalDate.prototype.setUTCHours
562
+ * @private
563
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
564
+ */
565
+
566
+ /**
567
+ * Sets the milliseconds for the embedded date instance according to universal time.
568
+ *
569
+ * @param {int} msValue An integer representing the new milliseconds value
570
+ * @returns {int}
571
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
572
+ * timestamp could not be updated. The new timestamp is a Gregorian timestamp.
573
+ *
574
+ * @function
575
+ * @name sap.ui.core.date.UniversalDate.prototype.setUTCMilliseconds
576
+ * @private
577
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
578
+ */
579
+
580
+ /**
581
+ * Sets the minutes, seconds and milliseconds for the embedded date instance according to universal
582
+ * time.
583
+ *
584
+ * @param {int} minutesValue An integer representing the new minutes value
585
+ * @param {int} [secondsValue] An integer representing the new seconds value
586
+ * @param {int} [msValue] An integer representing the new milliseconds value
587
+ * @returns {int}
588
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
589
+ * timestamp could not be updated. The new timestamp is a Gregorian timestamp.
590
+ *
591
+ * @function
592
+ * @name sap.ui.core.date.UniversalDate.prototype.setUTCMinutes
593
+ * @private
594
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
595
+ */
596
+
597
+ /**
598
+ * Sets the month and day for the embedded date instance according to universal time and
599
+ * selected calendar.
600
+ *
601
+ * @param {int} monthValue An integer representing the new month index
602
+ * @param {int} [dateValue] An integer representing the new day value
603
+ * @returns {int}
604
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
605
+ * timestamp could not be updated. The new timestamp is a Gregorian timestamp.
606
+ *
607
+ * @function
608
+ * @name sap.ui.core.date.UniversalDate.prototype.setUTCMonth
609
+ * @private
610
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
611
+ */
612
+
613
+ /**
614
+ * Sets the seconds and milliseconds for the embedded date instance according to universal time.
615
+ *
616
+ * @param {int} secondsValue An integer representing the new seconds value
617
+ * @param {int} [msValue] An integer representing the new milliseconds value
618
+ * @returns {int}
619
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
620
+ * timestamp could not be updated. The new timestamp is a Gregorian timestamp.
621
+ *
622
+ * @function
623
+ * @name sap.ui.core.date.UniversalDate.prototype.setUTCSeconds
624
+ * @private
625
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
626
+ */
627
+
628
+ /**
629
+ * Sets the year for the embedded date instance considering the configured time zone and the
630
+ * selected calendar. In case of the Gregorian calendar, 1900 is added to the year value
631
+ *
632
+ * @param {int} yearValue
633
+ * An integer representing the new year value (plus 1900 for the Gregorian calendar)
634
+ * @returns {int}
635
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
636
+ * timestamp could not be updated. The new timestamp is a Gregorian timestamp.
637
+ *
638
+ * @deprecated as of version 1.111.0 as it is deprecated in the base JavaScript <code>Date</code> class.
639
+ * Although it can be used with calendars other than the Gregorian calendar, use {@link #setFullYear} instead,
640
+ * regardless of the selected calendar.
641
+ *
642
+ * @function
643
+ * @name sap.ui.core.date.UniversalDate.prototype.setYear
644
+ * @private
645
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
646
+ */
647
+
648
+ /**
649
+ * Returns the date portion of the embedded date object interpreted in the configured time zone,
650
+ * independent on the selected calendar.
651
+ *
652
+ * @returns {string}
653
+ * The date portion of the embedded date object interpreted in the configured time zone
654
+ *
655
+ * @function
656
+ * @name sap.ui.core.date.UniversalDate.prototype.toDateString
657
+ * @private
658
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
659
+ */
660
+
661
+ /**
662
+ * Returns a string representing the embedded date object interpreted in the configured time
663
+ * zone, independent on the selected calendar.
664
+ *
665
+ * @returns {string}
666
+ * A string representing the embedded date object interpreted in the configured time zone
667
+ *
668
+ * @function
669
+ * @name sap.ui.core.date.UniversalDate.prototype.toString
670
+ * @private
671
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
672
+ */
673
+
674
+ /**
675
+ * Returns the value of the embedded date object in milliseconds based on the UNIX epoch.
676
+ *
677
+ * @returns {int} The primitive value of the embedded date object in milliseconds based on the UNIX epoch
678
+ *
679
+ * @function
680
+ * @name sap.ui.core.date.UniversalDate.prototype.valueOf
681
+ * @private
682
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
683
+ */
684
+ ["getDate", "getMonth", "getFullYear", "getYear", "getDay", "getHours", "getMinutes", "getSeconds", "getMilliseconds", "getUTCDate", "getUTCMonth", "getUTCFullYear", "getUTCDay", "getUTCHours", "getUTCMinutes", "getUTCSeconds", "getUTCMilliseconds", "getTime", "valueOf", "getTimezoneOffset", "toString", "toDateString", "setDate", "setFullYear", "setYear", "setMonth", "setHours", "setMinutes", "setSeconds", "setMilliseconds", "setUTCDate", "setUTCFullYear", "setUTCMonth", "setUTCHours", "setUTCMinutes", "setUTCSeconds", "setUTCMilliseconds"].forEach(function (sName) {
685
+ UniversalDate.prototype[sName] = function () {
686
+ return this.oDate[sName].apply(this.oDate, arguments);
687
+ };
100
688
  });
689
+
690
+ /**
691
+ * Returns the date object representing the current calendar date value.
692
+ *
693
+ * @returns {Date|module:sap/ui/core/date/UI5Date} The date object representing the current calendar date value
694
+ *
695
+ * @private
696
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
697
+ */
101
698
  UniversalDate.prototype.getJSDate = function () {
102
- return this.oDate;
699
+ return this.oDate;
103
700
  };
701
+
702
+ /**
703
+ * Returns the calendar type of the current instance of a UniversalDate.
704
+ *
705
+ * @returns {module:sap/base/i18n/date/CalendarType} The calendar type of the date
706
+ *
707
+ * @private
708
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
709
+ */
104
710
  UniversalDate.prototype.getCalendarType = function () {
105
- return this.sCalendarType;
711
+ return this.sCalendarType;
106
712
  };
713
+
714
+ /**
715
+ * Returns the era index of for the embedded date instance.
716
+ *
717
+ * @returns {int} The index of the era for the embedded date instance
718
+ *
719
+ * @private
720
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
721
+ */
107
722
  UniversalDate.prototype.getEra = function () {
108
- return UniversalDate.getEraByDate(this.sCalendarType, this.oDate.getFullYear(), this.oDate.getMonth(), this.oDate.getDate());
723
+ return UniversalDate.getEraByDate(this.sCalendarType, this.oDate.getFullYear(), this.oDate.getMonth(), this.oDate.getDate());
109
724
  };
725
+
726
+ /**
727
+ * Placeholder method which is overwritten by calendar specific implementations. General usage of
728
+ * this method is to use it to set the era for the embedded date instance.
729
+ *
730
+ * @param {int} iEra
731
+ * An number representing the era index which is to be set for the embedded date instance
732
+ *
733
+ * @private
734
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
735
+ */
110
736
  UniversalDate.prototype.setEra = function (iEra) {
737
+ // The default implementation does not support setting the era
111
738
  };
739
+
740
+ /**
741
+ * Returns the era index of for the embedded date instance in universal time.
742
+ *
743
+ * @returns {int} The index of the era for the embedded date instance in universal time
744
+ *
745
+ * @private
746
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
747
+ */
112
748
  UniversalDate.prototype.getUTCEra = function () {
113
- return UniversalDate.getEraByDate(this.sCalendarType, this.oDate.getUTCFullYear(), this.oDate.getUTCMonth(), this.oDate.getUTCDate());
749
+ return UniversalDate.getEraByDate(this.sCalendarType, this.oDate.getUTCFullYear(), this.oDate.getUTCMonth(), this.oDate.getUTCDate());
114
750
  };
751
+
752
+ /**
753
+ * Placeholder method which is overwritten by calendar specific implementations. General usage of
754
+ * this method is to use it to set the era for the embedded date instance in universal time.
755
+ *
756
+ * @param {int} iEra
757
+ * An number representing the era index which is to be set for the embedded date instance
758
+ * in universal time
759
+ *
760
+ * @private
761
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
762
+ */
115
763
  UniversalDate.prototype.setUTCEra = function (iEra) {
764
+ // The default implementation does not support setting the era
116
765
  };
117
- UniversalDate.prototype.getWeek = function () {
118
- return UniversalDate.getWeekByDate(this.sCalendarType, this.getFullYear(), this.getMonth(), this.getDate());
766
+
767
+ /**
768
+ * Retrieves the calendar week
769
+ *
770
+ * @param {sap.ui.core.Locale} [oLocale] the locale used to get the calendar week calculation properties, defaults to the formatLocale
771
+ * @param {module:sap/base/i18n/date/CalendarWeekNumbering|{firstDayOfWeek: int, minimalDaysInFirstWeek: int}} [vCalendarWeekNumbering]
772
+ * calendar week numbering or object with fields <code>firstDayOfWeek</code> and <code>minimalDaysInFirstWeek</code>,
773
+ * the default is derived from <code>oLocale</code> but this parameter has precedence over oLocale if both are provided.
774
+ * In case an object is provided, both properties <code>firstDayOfWeek</code> and <code>minimalDaysInFirstWeek</code> must be set, otherwise an error is thrown.
775
+ * If calendar week numbering is not determined from the locale then {@link LocaleData#firstDayStartsFirstWeek} is ignored.
776
+ * e.g. <code>{firstDayOfWeek: 1, minimalDaysInFirstWeek: 4}</code>
777
+ * @returns {{week: int, year: int}} resulting calendar week, note: week index starts with <code>0</code>
778
+ * @private
779
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
780
+ * @throws {TypeError} If:
781
+ * <ul>
782
+ * <li>vCalendarWeekNumbering is an object and the fields <code>firstDayOfWeek</code> or <code>minimalDaysInFirstWeek</code>) are missing or have a non-numeric value</li>
783
+ * <li>vCalendarWeekNumbering is a string and has an invalid week numbering value</li>
784
+ * </ul>
785
+ */
786
+ UniversalDate.prototype.getWeek = function (oLocale, vCalendarWeekNumbering) {
787
+ return UniversalDate.getWeekByDate(this.sCalendarType, this.getFullYear(), this.getMonth(), this.getDate(), oLocale, vCalendarWeekNumbering);
119
788
  };
120
- UniversalDate.prototype.setWeek = function (oWeek) {
121
- var oDate = UniversalDate.getFirstDateOfWeek(this.sCalendarType, oWeek.year || this.getFullYear(), oWeek.week);
122
- this.setFullYear(oDate.year, oDate.month, oDate.day);
789
+
790
+ /**
791
+ * Sets the calendar week
792
+ *
793
+ * @param {{week: int, year: int}} oWeek the calendar week, note: week index starts with <code>0</code>,
794
+ * <code>oWeek.year</code> is optional and defaults to {@link sap.ui.core.date.UniversalDate#getFullYear}
795
+ * @param {sap.ui.core.Locale} [oLocale] the locale used to get the calendar week calculation properties, defaults to the formatLocale
796
+ * @param {module:sap/base/i18n/date/CalendarWeekNumbering|{firstDayOfWeek: int, minimalDaysInFirstWeek: int}} [vCalendarWeekNumbering]
797
+ * calendar week numbering or object with fields <code>firstDayOfWeek</code> and <code>minimalDaysInFirstWeek</code>,
798
+ * the default is derived from <code>oLocale</code> but this parameter has precedence over oLocale if both are provided.
799
+ * In case an object is provided, both properties <code>firstDayOfWeek</code> and <code>minimalDaysInFirstWeek</code> must be set, otherwise an error is thrown.
800
+ * If calendar week numbering is not determined from the locale then {@link LocaleData#firstDayStartsFirstWeek} is ignored.
801
+ * e.g. <code>{firstDayOfWeek: 1, minimalDaysInFirstWeek: 4}</code>
802
+ * @private
803
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
804
+ * @throws {TypeError} If:
805
+ * <ul>
806
+ * <li>vCalendarWeekNumbering is an object and the fields <code>firstDayOfWeek</code> or <code>minimalDaysInFirstWeek</code>) are missing or have a non-numeric value</li>
807
+ * <li>vCalendarWeekNumbering is a string and has an invalid week numbering value</li>
808
+ * </ul>
809
+ */
810
+ UniversalDate.prototype.setWeek = function (oWeek, oLocale, vCalendarWeekNumbering) {
811
+ var oDate = UniversalDate.getFirstDateOfWeek(this.sCalendarType, oWeek.year || this.getFullYear(), oWeek.week, oLocale, vCalendarWeekNumbering);
812
+ this.setFullYear(oDate.year, oDate.month, oDate.day);
123
813
  };
124
- UniversalDate.prototype.getUTCWeek = function () {
125
- return UniversalDate.getWeekByDate(this.sCalendarType, this.getUTCFullYear(), this.getUTCMonth(), this.getUTCDate());
814
+
815
+ /**
816
+ * Retrieves the UTC calendar week
817
+ *
818
+ * @param {sap.ui.core.Locale} [oLocale] the locale used to get the calendar week calculation properties, defaults to the formatLocale
819
+ * @param {module:sap/base/i18n/date/CalendarWeekNumbering|{firstDayOfWeek: int, minimalDaysInFirstWeek: int}} [vCalendarWeekNumbering]
820
+ * calendar week numbering or object with fields <code>firstDayOfWeek</code> and <code>minimalDaysInFirstWeek</code>,
821
+ * the default is derived from <code>oLocale</code> but this parameter has precedence over oLocale if both are provided.
822
+ * In case an object is provided, both properties <code>firstDayOfWeek</code> and <code>minimalDaysInFirstWeek</code> must be set, otherwise an error is thrown.
823
+ * If calendar week numbering is not determined from the locale then {@link LocaleData#firstDayStartsFirstWeek} is ignored.
824
+ * e.g. <code>{firstDayOfWeek: 1, minimalDaysInFirstWeek: 4}</code>
825
+ * @returns {{week: int, year: int}} resulting calendar week, note: week index starts with <code>0</code>
826
+ * @private
827
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
828
+ * @throws {TypeError} If:
829
+ * <ul>
830
+ * <li>vCalendarWeekNumbering is an object and the fields <code>firstDayOfWeek</code> or <code>minimalDaysInFirstWeek</code>) are missing or have a non-numeric value</li>
831
+ * <li>vCalendarWeekNumbering is a string and has an invalid week numbering value</li>
832
+ * </ul>
833
+ */
834
+ UniversalDate.prototype.getUTCWeek = function (oLocale, vCalendarWeekNumbering) {
835
+ return UniversalDate.getWeekByDate(this.sCalendarType, this.getUTCFullYear(), this.getUTCMonth(), this.getUTCDate(), oLocale, vCalendarWeekNumbering);
126
836
  };
127
- UniversalDate.prototype.setUTCWeek = function (oWeek) {
128
- var oDate = UniversalDate.getFirstDateOfWeek(this.sCalendarType, oWeek.year || this.getFullYear(), oWeek.week);
129
- this.setUTCFullYear(oDate.year, oDate.month, oDate.day);
837
+
838
+ /**
839
+ * Sets the UTC calendar week
840
+ *
841
+ * @param {{week: int, year: int}} oWeek the calendar week, note: week index starts with <code>0</code>,
842
+ * <code>oWeek.year</code> is optional and defaults to {@link sap.ui.core.date.UniversalDate#getFullYear}
843
+ * @param {sap.ui.core.Locale} [oLocale] the locale used to get the calendar week calculation properties, defaults to the formatLocale
844
+ * @param {module:sap/base/i18n/date/CalendarWeekNumbering|{firstDayOfWeek: int, minimalDaysInFirstWeek: int}} [vCalendarWeekNumbering]
845
+ * calendar week numbering or object with fields <code>firstDayOfWeek</code> and <code>minimalDaysInFirstWeek</code>,
846
+ * the default is derived from <code>oLocale</code> but this parameter has precedence over oLocale if both are provided.
847
+ * In case an object is provided, both properties <code>firstDayOfWeek</code> and <code>minimalDaysInFirstWeek</code> must be set, otherwise an error is thrown.
848
+ * If calendar week numbering is not determined from the locale then {@link LocaleData#firstDayStartsFirstWeek} is ignored.
849
+ * e.g. <code>{firstDayOfWeek: 1, minimalDaysInFirstWeek: 4}</code>
850
+ * @private
851
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
852
+ * @throws {TypeError} If:
853
+ * <ul>
854
+ * <li>vCalendarWeekNumbering is an object and the fields <code>firstDayOfWeek</code> or <code>minimalDaysInFirstWeek</code>) are missing or have a non-numeric value</li>
855
+ * <li>vCalendarWeekNumbering is a string and has an invalid week numbering value</li>
856
+ * </ul>
857
+ */
858
+ UniversalDate.prototype.setUTCWeek = function (oWeek, oLocale, vCalendarWeekNumbering) {
859
+ var oDate = UniversalDate.getFirstDateOfWeek(this.sCalendarType, oWeek.year || this.getFullYear(), oWeek.week, oLocale, vCalendarWeekNumbering);
860
+ this.setUTCFullYear(oDate.year, oDate.month, oDate.day);
130
861
  };
862
+
863
+ /**
864
+ * Returns the current quarter of the embedded date instance
865
+ *
866
+ * @returns {int} The quarter of the embedded date instance
867
+ *
868
+ * @private
869
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
870
+ */
131
871
  UniversalDate.prototype.getQuarter = function () {
132
- return Math.floor(this.getMonth() / 3);
872
+ return Math.floor(this.getMonth() / 3);
133
873
  };
874
+
875
+ /**
876
+ * Returns the current quarter of the embedded date instance in universal time
877
+ *
878
+ * @returns {int} The quarter of the embedded date instance in universal time
879
+ *
880
+ * @private
881
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
882
+ */
134
883
  UniversalDate.prototype.getUTCQuarter = function () {
135
- return Math.floor(this.getUTCMonth() / 3);
884
+ return Math.floor(this.getUTCMonth() / 3);
136
885
  };
886
+
887
+ /**
888
+ * Returns an integer value depending on whether the embedded date instance time is set to the
889
+ * afternoon or morning.
890
+ *
891
+ * @returns {int}
892
+ * An integer value which indicates which day period the embedded date instance is set to. If,
893
+ * date time is set in the morning time 0 (i.e. 0:00 - 11:59) or 1 if date time is set in the
894
+ * afternoon (i.e. 12:00 - 23:59).
895
+ *
896
+ * @private
897
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
898
+ */
137
899
  UniversalDate.prototype.getDayPeriod = function () {
138
- if (this.getHours() < 12) {
139
- return 0;
140
- } else {
141
- return 1;
142
- }
900
+ if (this.getHours() < 12) {
901
+ return 0;
902
+ } else {
903
+ return 1;
904
+ }
143
905
  };
906
+
907
+ /**
908
+ * Returns an integer value depending on whether the embedded date instance time, is set to the
909
+ * afternoon or morning, in universal time.
910
+ *
911
+ * @returns {int}
912
+ * An integer value which indicates which day period the embedded date instance is set to, in
913
+ * universal time. If, universal date time is set in the morning time 0 (i.e. 0:00 - 11:59) or
914
+ * 1 if universal date time is set in the afternoon (i.e. 12:00 - 23:59).
915
+ *
916
+ * @private
917
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
918
+ */
144
919
  UniversalDate.prototype.getUTCDayPeriod = function () {
145
- if (this.getUTCHours() < 12) {
146
- return 0;
147
- } else {
148
- return 1;
149
- }
920
+ if (this.getUTCHours() < 12) {
921
+ return 0;
922
+ } else {
923
+ return 1;
924
+ }
150
925
  };
926
+
927
+ // TODO: These are currently needed for the DateFormat test, as the date used in the test
928
+ // has been enhanced with these methods. Should be implemented using CLDR data.
929
+ /**
930
+ * Returns the short version of the time zone name of the embedded date instance.
931
+ *
932
+ * @returns {string} The short version of the name, of the time zone of the embedded date instance
933
+ *
934
+ * @private
935
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
936
+ */
151
937
  UniversalDate.prototype.getTimezoneShort = function () {
152
- if (this.oDate.getTimezoneShort) {
153
- return this.oDate.getTimezoneShort();
154
- }
938
+ if (this.oDate.getTimezoneShort) {
939
+ return this.oDate.getTimezoneShort();
940
+ }
155
941
  };
942
+
943
+ /**
944
+ * Returns the long version of the time zone name of the embedded date instance.
945
+ *
946
+ * @returns {string} The long version of the name, of the time zone of the embedded date instance
947
+ *
948
+ * @private
949
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
950
+ */
156
951
  UniversalDate.prototype.getTimezoneLong = function () {
157
- if (this.oDate.getTimezoneLong) {
158
- return this.oDate.getTimezoneLong();
159
- }
952
+ if (this.oDate.getTimezoneLong) {
953
+ return this.oDate.getTimezoneLong();
954
+ }
160
955
  };
956
+
957
+ /*
958
+ * Helper methods for week calculations
959
+ */
161
960
  var iMillisecondsInWeek = 7 * 24 * 60 * 60 * 1000;
162
- UniversalDate.getWeekByDate = function (sCalendarType, iYear, iMonth, iDay) {
163
- var oLocale = Core.getConfiguration().getFormatSettings().getFormatLocale(), clDate = this.getClass(sCalendarType), oFirstDay = getFirstDayOfFirstWeek(clDate, iYear), oDate = new clDate(clDate.UTC(iYear, iMonth, iDay)), iWeek, iLastYear, iNextYear, oLastFirstDay, oNextFirstDay;
164
- if (oLocale.getRegion() === 'US') {
165
- iWeek = calculateWeeks(oFirstDay, oDate);
961
+
962
+ /**
963
+ * Retrieves the calendar week for a given date, specified by year, month, and day.
964
+ *
965
+ * @param {string} sCalendarType the calendar type, e.g. <code>"Gregorian"</code>
966
+ * @param {int} iYear year, e.g. <code>2016</code>
967
+ * @param {int} iMonth the month, e.g. <code>2</code>
968
+ * @param {int} iDay the date, e.g. <code>3</code>
969
+ * @param {sap.ui.core.Locale} [oLocale] the locale used for the week calculation, if oWeekConfig is not provided (falls back to the formatLocale)
970
+ * e.g. <code>new Locale("de-DE")</code>
971
+ * @param {module:sap/base/i18n/date/CalendarWeekNumbering|{firstDayOfWeek: int, minimalDaysInFirstWeek: int}} [vCalendarWeekNumbering]
972
+ * calendar week numbering or object with fields <code>firstDayOfWeek</code> and <code>minimalDaysInFirstWeek</code>,
973
+ * the default is derived from <code>oLocale</code> but this parameter has precedence over oLocale if both are provided.
974
+ * In case an object is provided, both properties <code>firstDayOfWeek</code> and <code>minimalDaysInFirstWeek</code> must be set, otherwise an error is thrown.
975
+ * If calendar week numbering is not determined from the locale then {@link LocaleData#firstDayStartsFirstWeek} is ignored.
976
+ * e.g. <code>{firstDayOfWeek: 1, minimalDaysInFirstWeek: 4}</code>
977
+ * @returns {{week: int, year: int}} resulting calendar week, note: week index starts with <code>0</code>, e.g. <code>{year: 2016, week: 8}</code>
978
+ * @private
979
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
980
+ * @throws {TypeError} If:
981
+ * <ul>
982
+ * <li>vCalendarWeekNumbering is an object and the fields <code>firstDayOfWeek</code> or <code>minimalDaysInFirstWeek</code>) are missing or have a non-numeric value</li>
983
+ * <li>vCalendarWeekNumbering is a string and has an invalid week numbering value</li>
984
+ * </ul>
985
+ */
986
+ UniversalDate.getWeekByDate = function (sCalendarType, iYear, iMonth, iDay, oLocale, vCalendarWeekNumbering) {
987
+ vCalendarWeekNumbering = vCalendarWeekNumbering || Formatting.getCalendarWeekNumbering();
988
+ checkWeekConfig(vCalendarWeekNumbering);
989
+ oLocale = oLocale || new Locale(Formatting.getLanguageTag());
990
+ var clDate = this.getClass(sCalendarType);
991
+ var oFirstDay = getFirstDayOfFirstWeek(clDate, iYear, oLocale, vCalendarWeekNumbering);
992
+ var oDate = new clDate(clDate.UTC(iYear, iMonth, iDay));
993
+ var iWeek, iLastYear, iNextYear, oLastFirstDay, oNextFirstDay;
994
+ var bSplitWeek = isSplitWeek(vCalendarWeekNumbering, oLocale);
995
+ if (bSplitWeek) {
996
+ iWeek = calculateWeeks(oFirstDay, oDate);
997
+ } else {
998
+ iLastYear = iYear - 1;
999
+ iNextYear = iYear + 1;
1000
+ oLastFirstDay = getFirstDayOfFirstWeek(clDate, iLastYear, oLocale, vCalendarWeekNumbering);
1001
+ oNextFirstDay = getFirstDayOfFirstWeek(clDate, iNextYear, oLocale, vCalendarWeekNumbering);
1002
+ if (oDate >= oNextFirstDay) {
1003
+ iYear = iNextYear;
1004
+ iWeek = 0;
1005
+ } else if (oDate < oFirstDay) {
1006
+ iYear = iLastYear;
1007
+ iWeek = calculateWeeks(oLastFirstDay, oDate);
166
1008
  } else {
167
- iLastYear = iYear - 1;
168
- iNextYear = iYear + 1;
169
- oLastFirstDay = getFirstDayOfFirstWeek(clDate, iLastYear);
170
- oNextFirstDay = getFirstDayOfFirstWeek(clDate, iNextYear);
171
- if (oDate >= oNextFirstDay) {
172
- iYear = iNextYear;
173
- iWeek = 0;
174
- } else if (oDate < oFirstDay) {
175
- iYear = iLastYear;
176
- iWeek = calculateWeeks(oLastFirstDay, oDate);
177
- } else {
178
- iWeek = calculateWeeks(oFirstDay, oDate);
179
- }
1009
+ iWeek = calculateWeeks(oFirstDay, oDate);
180
1010
  }
181
- return {
182
- year: iYear,
183
- week: iWeek
184
- };
1011
+ }
1012
+ return {
1013
+ year: iYear,
1014
+ week: iWeek
1015
+ };
185
1016
  };
186
- UniversalDate.getFirstDateOfWeek = function (sCalendarType, iYear, iWeek) {
187
- var oLocale = Core.getConfiguration().getFormatSettings().getFormatLocale(), clDate = this.getClass(sCalendarType), oFirstDay = getFirstDayOfFirstWeek(clDate, iYear), oDate = new clDate(oFirstDay.valueOf() + iWeek * iMillisecondsInWeek);
188
- if (oLocale.getRegion() === 'US' && iWeek === 0 && oFirstDay.getUTCFullYear() < iYear) {
189
- return {
190
- year: iYear,
191
- month: 0,
192
- day: 1
193
- };
194
- }
1017
+
1018
+ /**
1019
+ * Retrieves the first day's date of the given week in the given year.
1020
+ *
1021
+ * @param {string} sCalendarType the calendar type, e.g. <code>"Gregorian"</code>
1022
+ * @param {int} iYear year, e.g. <code>2016</code>
1023
+ * @param {int} iWeek the calendar week index, e.g. <code>8</code>
1024
+ * @param {sap.ui.core.Locale} [oLocale] the locale used for the week calculation, if oWeekConfig is not provided (falls back to the formatLocale)
1025
+ * e.g. <code>new Locale("de-DE")</code>
1026
+ * @param {module:sap/base/i18n/date/CalendarWeekNumbering|{firstDayOfWeek: int, minimalDaysInFirstWeek: int}} [vCalendarWeekNumbering]
1027
+ * calendar week numbering or object with fields <code>firstDayOfWeek</code> and <code>minimalDaysInFirstWeek</code>,
1028
+ * the default is derived from <code>oLocale</code> but this parameter has precedence over oLocale if both are provided.
1029
+ * In case an object is provided, both properties <code>firstDayOfWeek</code> and <code>minimalDaysInFirstWeek</code> must be set, otherwise an error is thrown.
1030
+ * If calendar week numbering is not determined from the locale then {@link LocaleData#firstDayStartsFirstWeek} is ignored.
1031
+ * e.g. <code>{firstDayOfWeek: 1, minimalDaysInFirstWeek: 4}</code>
1032
+ * @returns {{month: int, year: int, day: int}} the resulting date, e.g. <code>{year: 2016, month: 1, day: 29}</code>
1033
+ * @private
1034
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
1035
+ * @throws {TypeError} If:
1036
+ * <ul>
1037
+ * <li>vCalendarWeekNumbering is an object and the fields <code>firstDayOfWeek</code> or <code>minimalDaysInFirstWeek</code>) are missing or have a non-numeric value</li>
1038
+ * <li>vCalendarWeekNumbering is a string and has an invalid week numbering value</li>
1039
+ * </ul>
1040
+ */
1041
+ UniversalDate.getFirstDateOfWeek = function (sCalendarType, iYear, iWeek, oLocale, vCalendarWeekNumbering) {
1042
+ vCalendarWeekNumbering = vCalendarWeekNumbering || Formatting.getCalendarWeekNumbering();
1043
+ checkWeekConfig(vCalendarWeekNumbering);
1044
+ oLocale = oLocale || new Locale(Formatting.getLanguageTag());
1045
+ var clDate = this.getClass(sCalendarType);
1046
+ var oFirstDay = getFirstDayOfFirstWeek(clDate, iYear, oLocale, vCalendarWeekNumbering);
1047
+ var oDate = new clDate(oFirstDay.valueOf() + iWeek * iMillisecondsInWeek);
1048
+ var bSplitWeek = isSplitWeek(vCalendarWeekNumbering, oLocale);
1049
+ if (bSplitWeek && iWeek === 0 && oFirstDay.getUTCFullYear() < iYear) {
195
1050
  return {
196
- year: oDate.getUTCFullYear(),
197
- month: oDate.getUTCMonth(),
198
- day: oDate.getUTCDate()
1051
+ year: iYear,
1052
+ month: 0,
1053
+ day: 1
199
1054
  };
1055
+ }
1056
+ return {
1057
+ year: oDate.getUTCFullYear(),
1058
+ month: oDate.getUTCMonth(),
1059
+ day: oDate.getUTCDate()
1060
+ };
200
1061
  };
201
- function getFirstDayOfFirstWeek(clDate, iYear) {
202
- var oLocale = Core.getConfiguration().getFormatSettings().getFormatLocale(), oLocaleData = LocaleData.getInstance(oLocale), iMinDays = oLocaleData.getMinimalDaysInFirstWeek(), iFirstDayOfWeek = oLocaleData.getFirstDayOfWeek(), oFirstDay = new clDate(clDate.UTC(iYear, 0, 1)), iDayCount = 7;
203
- while (oFirstDay.getUTCDay() !== iFirstDayOfWeek) {
204
- oFirstDay.setUTCDate(oFirstDay.getUTCDate() - 1);
205
- iDayCount--;
206
- }
207
- if (iDayCount < iMinDays) {
208
- oFirstDay.setUTCDate(oFirstDay.getUTCDate() + 7);
1062
+
1063
+ /**
1064
+ * Determines if the split week algorithm should be applied (the first day of the first calendar
1065
+ * week of the year is January 1st).
1066
+ *
1067
+ * @param {module:sap/base/i18n/date/CalendarWeekNumbering|{firstDayOfWeek: int, minimalDaysInFirstWeek: int}} vCalendarWeekNumbering
1068
+ * calendar week numbering or object with fields <code>firstDayOfWeek</code> and
1069
+ * <code>minimalDaysInFirstWeek</code>
1070
+ * @param {sap.ui.core.Locale} oLocale the locale used for the week calculation
1071
+ * @returns {boolean} if the split week should be applied
1072
+ */
1073
+ function isSplitWeek(vCalendarWeekNumbering, oLocale) {
1074
+ var oLocaleData = LocaleData.getInstance(oLocale);
1075
+
1076
+ // only applies for en_US with default CalendarWeekNumbering (WesternTraditional is default in en_US)
1077
+ return (vCalendarWeekNumbering === CalendarWeekNumbering.Default || vCalendarWeekNumbering === CalendarWeekNumbering.WesternTraditional) && oLocaleData.firstDayStartsFirstWeek();
1078
+ }
1079
+
1080
+ /**
1081
+ * Checks the calendar week configuration
1082
+ *
1083
+ * @param {module:sap/base/i18n/date/CalendarWeekNumbering|{firstDayOfWeek: int, minimalDaysInFirstWeek: int}} vCalendarWeekNumbering
1084
+ * calendar week numbering or object with fields <code>firstDayOfWeek</code> and <code>minimalDaysInFirstWeek</code>
1085
+ * @throws {TypeError} If:
1086
+ * <ul>
1087
+ * <li>vCalendarWeekNumbering is an object and the fields <code>firstDayOfWeek</code> or <code>minimalDaysInFirstWeek</code>) are missing or have a non-numeric value</li>
1088
+ * <li>vCalendarWeekNumbering is a string and has an invalid week numbering value</li>
1089
+ * </ul>
1090
+ */
1091
+ function checkWeekConfig(vCalendarWeekNumbering) {
1092
+ if (typeof vCalendarWeekNumbering === "object") {
1093
+ if (typeof vCalendarWeekNumbering.firstDayOfWeek !== "number" || typeof vCalendarWeekNumbering.minimalDaysInFirstWeek !== "number") {
1094
+ throw new TypeError("Week config requires firstDayOfWeek and minimalDaysInFirstWeek to be set");
209
1095
  }
210
- return oFirstDay;
1096
+ } else if (!Object.values(CalendarWeekNumbering).includes(vCalendarWeekNumbering)) {
1097
+ throw new TypeError("Illegal format option calendarWeekNumbering: '" + vCalendarWeekNumbering + "'");
1098
+ }
211
1099
  }
1100
+
1101
+ /**
1102
+ * Resolves the calendar week configuration
1103
+ *
1104
+ * @param {module:sap/base/i18n/date/CalendarWeekNumbering|{firstDayOfWeek: int, minimalDaysInFirstWeek: int}} vCalendarWeekNumbering
1105
+ * calendar week numbering or object with fields <code>firstDayOfWeek</code> and <code>minimalDaysInFirstWeek</code>
1106
+ * @param {sap.ui.core.Locale} [oLocale] locale to be used
1107
+ * @returns {{firstDayOfWeek: int, minimalDaysInFirstWeek: int}} calendar week calculation configuration
1108
+ */
1109
+ function resolveCalendarWeekConfiguration(vCalendarWeekNumbering, oLocale) {
1110
+ // be backward compatible
1111
+ if (typeof vCalendarWeekNumbering === "object" && typeof vCalendarWeekNumbering.firstDayOfWeek === "number" && typeof vCalendarWeekNumbering.minimalDaysInFirstWeek === "number") {
1112
+ return vCalendarWeekNumbering;
1113
+ }
1114
+ return CalendarUtils.getWeekConfigurationValues(vCalendarWeekNumbering, oLocale);
1115
+ }
1116
+
1117
+ /**
1118
+ * Returns the first day of the first week in the given year.
1119
+ *
1120
+ * @param {UniversalDate} clDate the date class
1121
+ * @param {int} iYear year, e.g. <code>2016</code>
1122
+ * @param {sap.ui.core.Locale} [oLocale] the locale used for the week calculation, if oWeekConfig is not provided (falls back to the formatLocale)
1123
+ * e.g. <code>new Locale("de-DE")</code>
1124
+ * @param {module:sap/base/i18n/date/CalendarWeekNumbering|{firstDayOfWeek: int, minimalDaysInFirstWeek: int}} vCalendarWeekNumbering
1125
+ * calendar week numbering or object with fields <code>firstDayOfWeek</code> and <code>minimalDaysInFirstWeek</code>,
1126
+ * the default is derived from <code>oLocale</code> but this parameter has precedence over oLocale if both are provided.
1127
+ * e.g. <code>{firstDayOfWeek: 1, minimalDaysInFirstWeek: 4}</code>
1128
+ * @returns {Date} first day of the first week in the given year, e.g. <code>Mon Jan 04 2016 01:00:00 GMT+0100</code>
1129
+ */
1130
+ function getFirstDayOfFirstWeek(clDate, iYear, oLocale, vCalendarWeekNumbering) {
1131
+ oLocale = oLocale || new Locale(Formatting.getLanguageTag());
1132
+ var oWeekConfig = resolveCalendarWeekConfiguration(vCalendarWeekNumbering, oLocale);
1133
+ var iMinDays = oWeekConfig.minimalDaysInFirstWeek;
1134
+ var iFirstDayOfWeek = oWeekConfig.firstDayOfWeek;
1135
+ var oFirstDay = new clDate(clDate.UTC(iYear, 0, 1));
1136
+ var iDayCount = 7;
1137
+ if (isNaN(oFirstDay.getTime())) {
1138
+ throw new Error("Could not determine the first day of the week, because the date " + "object is invalid");
1139
+ }
1140
+ // Find the first day of the first week of the year
1141
+ while (oFirstDay.getUTCDay() !== iFirstDayOfWeek) {
1142
+ oFirstDay.setUTCDate(oFirstDay.getUTCDate() - 1);
1143
+ iDayCount--;
1144
+ }
1145
+ // If less than min days are left, first week is one week later
1146
+ if (iDayCount < iMinDays) {
1147
+ oFirstDay.setUTCDate(oFirstDay.getUTCDate() + 7);
1148
+ }
1149
+ return oFirstDay;
1150
+ }
1151
+
1152
+ /**
1153
+ * Returns the rounded amount of weeks a given time frame.
1154
+ *
1155
+ * @param {Date} oFromDate The beginning date of the time interval
1156
+ * @param {Date} oToDate The end date of the time interval
1157
+ * @returns {int} A rounded number which represents the amount of weeks in the given timer interval
1158
+ */
212
1159
  function calculateWeeks(oFromDate, oToDate) {
213
- return Math.floor((oToDate.valueOf() - oFromDate.valueOf()) / iMillisecondsInWeek);
1160
+ return Math.floor((oToDate.valueOf() - oFromDate.valueOf()) / iMillisecondsInWeek);
214
1161
  }
1162
+
1163
+ /*
1164
+ * Helper methods for era calculations
1165
+ */
215
1166
  var mEras = {};
1167
+
1168
+ /**
1169
+ * Returns an index of the era for the given date values in the given calendar. For
1170
+ * an index to be returned the date value has to be within the era time period, i.e. the
1171
+ * timestamp value of the date has to be bigger or equal than the start timestamp of the era
1172
+ * or smaller than the end of the end period.
1173
+ *
1174
+ * @param {string} sCalendarType The given calendar type which the eras available for selection
1175
+ * @param {int} iYear The year value for which the era is looked for
1176
+ * @param {int} iMonth The month value for which the era is looked for
1177
+ * @param {int} iDay The date value for which the era is looked for
1178
+ * @returns {int} The index of the found era for the given date values in the given calendar
1179
+ *
1180
+ * @private
1181
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
1182
+ */
216
1183
  UniversalDate.getEraByDate = function (sCalendarType, iYear, iMonth, iDay) {
217
- var aEras = getEras(sCalendarType), iTimestamp = new Date(0).setUTCFullYear(iYear, iMonth, iDay), oEra;
218
- for (var i = aEras.length - 1; i >= 0; i--) {
219
- oEra = aEras[i];
220
- if (!oEra) {
221
- continue;
222
- }
223
- if (oEra._start && iTimestamp >= oEra._startInfo.timestamp) {
224
- return i;
225
- }
226
- if (oEra._end && iTimestamp < oEra._endInfo.timestamp) {
227
- return i;
228
- }
1184
+ var aEras = getEras(sCalendarType),
1185
+ // no need to use UI5Date.getInstance as only the UTC timestamp is used
1186
+ iTimestamp = new Date(0).setUTCFullYear(iYear, iMonth, iDay),
1187
+ oEra;
1188
+ for (var i = aEras.length - 1; i >= 0; i--) {
1189
+ oEra = aEras[i];
1190
+ if (!oEra) {
1191
+ continue;
1192
+ }
1193
+ if (oEra._start && iTimestamp >= oEra._startInfo.timestamp) {
1194
+ return i;
229
1195
  }
1196
+ if (oEra._end && iTimestamp < oEra._endInfo.timestamp) {
1197
+ return i;
1198
+ }
1199
+ }
230
1200
  };
1201
+
1202
+ /**
1203
+ * Returns an index of the current era for the embedded date instance.
1204
+ *
1205
+ * @param {string} sCalendarType The calendar type which defines the available eras to select from
1206
+ * @returns {int} The index of the current era of the embedded date instance
1207
+ *
1208
+ * @private
1209
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
1210
+ */
231
1211
  UniversalDate.getCurrentEra = function (sCalendarType) {
232
- var oNow = new Date();
233
- return this.getEraByDate(sCalendarType, oNow.getFullYear(), oNow.getMonth(), oNow.getDate());
1212
+ var oNow = UI5Date.getInstance();
1213
+ return this.getEraByDate(sCalendarType, oNow.getFullYear(), oNow.getMonth(), oNow.getDate());
234
1214
  };
1215
+
1216
+ /**
1217
+ * Returns the start date of the selected era from the given era index, in the given calendar type.
1218
+ *
1219
+ * @param {string} sCalendarType The calendar type from which the era is to be picked
1220
+ * @param {int} iEra The given era index of the to be selected era
1221
+ * @returns {object|null}
1222
+ * The start date object of the selected era. If no era can be found for the given index the first
1223
+ * era of the selected calendar is chosen. If the chosen era does not have a start date defined
1224
+ * <code>null</code>
1225
+ *
1226
+ * @private
1227
+ * @ui5-restricted SAPUI5 Distribution Layer Libraries
1228
+ */
235
1229
  UniversalDate.getEraStartDate = function (sCalendarType, iEra) {
236
- var aEras = getEras(sCalendarType), oEra = aEras[iEra] || aEras[0];
237
- if (oEra._start) {
238
- return oEra._startInfo;
239
- }
1230
+ var aEras = getEras(sCalendarType),
1231
+ oEra = aEras[iEra] || aEras[0];
1232
+ if (oEra._start) {
1233
+ return oEra._startInfo;
1234
+ }
240
1235
  };
1236
+
1237
+ /**
1238
+ * Returns an array of era for the given calendar.
1239
+ *
1240
+ * @param {string} sCalendarType
1241
+ * The calendar type from which the the locale era data is taken from and the era array is
1242
+ * generated
1243
+ * @returns {array} An array of all available era in the given calendar
1244
+ */
241
1245
  function getEras(sCalendarType) {
242
- var oLocale = Core.getConfiguration().getFormatSettings().getFormatLocale(), oLocaleData = LocaleData.getInstance(oLocale), aEras = mEras[sCalendarType];
243
- if (!aEras) {
244
- var aEras = oLocaleData.getEraDates(sCalendarType);
245
- if (!aEras[0]) {
246
- aEras[0] = { _start: '1-1-1' };
247
- }
248
- for (var i = 0; i < aEras.length; i++) {
249
- var oEra = aEras[i];
250
- if (!oEra) {
251
- continue;
252
- }
253
- if (oEra._start) {
254
- oEra._startInfo = parseDateString(oEra._start);
255
- }
256
- if (oEra._end) {
257
- oEra._endInfo = parseDateString(oEra._end);
258
- }
259
- }
260
- mEras[sCalendarType] = aEras;
1246
+ var oLocale = new Locale(Formatting.getLanguageTag()),
1247
+ oLocaleData = LocaleData.getInstance(oLocale),
1248
+ aEras = mEras[sCalendarType];
1249
+ if (!aEras) {
1250
+ // Get eras from localedata, parse it and add it to the array
1251
+ var aEras = oLocaleData.getEraDates(sCalendarType);
1252
+ if (!aEras[0]) {
1253
+ aEras[0] = {
1254
+ _start: "1-1-1"
1255
+ };
261
1256
  }
262
- return aEras;
1257
+ for (var i = 0; i < aEras.length; i++) {
1258
+ var oEra = aEras[i];
1259
+ if (!oEra) {
1260
+ continue;
1261
+ }
1262
+ if (oEra._start) {
1263
+ oEra._startInfo = parseDateString(oEra._start);
1264
+ }
1265
+ if (oEra._end) {
1266
+ oEra._endInfo = parseDateString(oEra._end);
1267
+ }
1268
+ }
1269
+ mEras[sCalendarType] = aEras;
1270
+ }
1271
+ return aEras;
263
1272
  }
1273
+
1274
+ /**
1275
+ * Returns an object containing the date parts year, month, day of month and the date timestamp value
1276
+ * of the given date string.
1277
+ *
1278
+ * @param {string} sDateString The date string which is to be parsed
1279
+ * @returns {object}
1280
+ * An object containing the year, month, day of month and date timestamp values of the given
1281
+ * date string
1282
+ */
264
1283
  function parseDateString(sDateString) {
265
- var aParts = sDateString.split('-'), iYear, iMonth, iDay;
266
- if (aParts[0] == '') {
267
- iYear = -parseInt(aParts[1]);
268
- iMonth = parseInt(aParts[2]) - 1;
269
- iDay = parseInt(aParts[3]);
270
- } else {
271
- iYear = parseInt(aParts[0]);
272
- iMonth = parseInt(aParts[1]) - 1;
273
- iDay = parseInt(aParts[2]);
274
- }
275
- return {
276
- timestamp: new Date(0).setUTCFullYear(iYear, iMonth, iDay),
277
- year: iYear,
278
- month: iMonth,
279
- day: iDay
280
- };
1284
+ var aParts = sDateString.split("-"),
1285
+ iYear,
1286
+ iMonth,
1287
+ iDay;
1288
+ if (aParts[0] == "") {
1289
+ // negative year
1290
+ iYear = -parseInt(aParts[1]);
1291
+ iMonth = parseInt(aParts[2]) - 1;
1292
+ iDay = parseInt(aParts[3]);
1293
+ } else {
1294
+ iYear = parseInt(aParts[0]);
1295
+ iMonth = parseInt(aParts[1]) - 1;
1296
+ iDay = parseInt(aParts[2]);
1297
+ }
1298
+ return {
1299
+ // no need to use UI5Date.getInstance as only the UTC timestamp is used
1300
+ timestamp: new Date(0).setUTCFullYear(iYear, iMonth, iDay),
1301
+ year: iYear,
1302
+ month: iMonth,
1303
+ day: iDay
1304
+ };
281
1305
  }
282
1306
  export default UniversalDate;