@ui5/webcomponents-localization 0.0.0-0f0e49a22 → 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 (226) hide show
  1. package/.eslintignore +2 -1
  2. package/CHANGELOG.md +1935 -0
  3. package/LICENSE.txt +201 -0
  4. package/README.md +7 -9
  5. package/dist/.tsbuildinfo +1 -0
  6. package/dist/Assets-fetch.d.ts +1 -0
  7. package/dist/Assets-fetch.js +3 -0
  8. package/dist/Assets-fetch.js.map +1 -0
  9. package/dist/Assets-node.d.ts +11 -0
  10. package/dist/Assets-node.js +12 -0
  11. package/dist/Assets-node.js.map +1 -0
  12. package/dist/CalendarUtils.d.ts +3 -0
  13. package/dist/CalendarUtils.js +6 -0
  14. package/dist/CalendarUtils.js.map +1 -0
  15. package/dist/DateFormat.d.ts +23 -1
  16. package/dist/DateFormat.js +16 -0
  17. package/dist/DateFormat.js.map +1 -1
  18. package/dist/Locale.d.ts +5 -0
  19. package/dist/Locale.js +7 -0
  20. package/dist/Locale.js.map +1 -0
  21. package/dist/LocaleData.d.ts +0 -1
  22. package/dist/NumberFormat.d.ts +5 -0
  23. package/dist/NumberFormat.js +7 -0
  24. package/dist/NumberFormat.js.map +1 -0
  25. package/dist/dates/CalendarDate.d.ts +0 -1
  26. package/dist/dates/CalendarDate.js.map +1 -1
  27. package/dist/dates/ExtremeDates.d.ts +1 -1
  28. package/dist/dates/ExtremeDates.js.map +1 -1
  29. package/dist/dates/UI5Date.d.ts +0 -1
  30. package/dist/dates/convertMonthNumbersToMonthNames.d.ts +2 -2
  31. package/dist/dates/convertMonthNumbersToMonthNames.js.map +1 -1
  32. package/dist/dates/getRoundedTimestamp.js.map +1 -1
  33. package/dist/dates/modifyDateBy.d.ts +2 -1
  34. package/dist/dates/modifyDateBy.js +34 -19
  35. package/dist/dates/modifyDateBy.js.map +1 -1
  36. package/dist/dates/transformDateToSecondaryType.js.map +1 -1
  37. package/dist/generated/assets/cldr/Unicode-Data-Files-LICENSE.txt +39 -0
  38. package/dist/generated/assets/cldr/ar.json +7355 -5531
  39. package/dist/generated/assets/cldr/ar_EG.json +7355 -5531
  40. package/dist/generated/assets/cldr/ar_SA.json +7354 -5530
  41. package/dist/generated/assets/cldr/bg.json +6103 -4452
  42. package/dist/generated/assets/cldr/ca.json +6205 -4440
  43. package/dist/generated/assets/cldr/cnr.json +6476 -0
  44. package/dist/generated/assets/cldr/cs.json +6519 -4960
  45. package/dist/generated/assets/cldr/cy.json +6564 -5211
  46. package/dist/generated/assets/cldr/da.json +6048 -4308
  47. package/dist/generated/assets/cldr/de.json +6174 -4313
  48. package/dist/generated/assets/cldr/de_AT.json +6175 -4314
  49. package/dist/generated/assets/cldr/de_CH.json +6181 -4312
  50. package/dist/generated/assets/cldr/el.json +5995 -4281
  51. package/dist/generated/assets/cldr/el_CY.json +5995 -4281
  52. package/dist/generated/assets/cldr/en.json +6395 -4316
  53. package/dist/generated/assets/cldr/en_AU.json +6536 -4319
  54. package/dist/generated/assets/cldr/en_GB.json +6518 -4329
  55. package/dist/generated/assets/cldr/en_HK.json +6423 -4337
  56. package/dist/generated/assets/cldr/en_IE.json +6414 -4328
  57. package/dist/generated/assets/cldr/en_IN.json +6602 -4333
  58. package/dist/generated/assets/cldr/en_NZ.json +6414 -4328
  59. package/dist/generated/assets/cldr/en_PG.json +6415 -4329
  60. package/dist/generated/assets/cldr/en_SG.json +6419 -4333
  61. package/dist/generated/assets/cldr/en_ZA.json +6417 -4329
  62. package/dist/generated/assets/cldr/es.json +6226 -4331
  63. package/dist/generated/assets/cldr/es_AR.json +6260 -4334
  64. package/dist/generated/assets/cldr/es_BO.json +6258 -4333
  65. package/dist/generated/assets/cldr/es_CL.json +6151 -4334
  66. package/dist/generated/assets/cldr/es_CO.json +6151 -4333
  67. package/dist/generated/assets/cldr/es_MX.json +6268 -4335
  68. package/dist/generated/assets/cldr/es_PE.json +6050 -4333
  69. package/dist/generated/assets/cldr/es_UY.json +6044 -4335
  70. package/dist/generated/assets/cldr/es_VE.json +6043 -4334
  71. package/dist/generated/assets/cldr/et.json +6182 -4340
  72. package/dist/generated/assets/cldr/fa.json +6187 -4367
  73. package/dist/generated/assets/cldr/fi.json +6439 -4463
  74. package/dist/generated/assets/cldr/fr.json +6228 -4357
  75. package/dist/generated/assets/cldr/fr_BE.json +6228 -4357
  76. package/dist/generated/assets/cldr/fr_CA.json +6244 -4351
  77. package/dist/generated/assets/cldr/fr_CH.json +6246 -4375
  78. package/dist/generated/assets/cldr/fr_LU.json +6228 -4357
  79. package/dist/generated/assets/cldr/he.json +6361 -4869
  80. package/dist/generated/assets/cldr/hi.json +6098 -4295
  81. package/dist/generated/assets/cldr/hr.json +6203 -4583
  82. package/dist/generated/assets/cldr/hu.json +6067 -4364
  83. package/dist/generated/assets/cldr/id.json +5979 -4060
  84. package/dist/generated/assets/cldr/it.json +6103 -4299
  85. package/dist/generated/assets/cldr/it_CH.json +6103 -4299
  86. package/dist/generated/assets/cldr/ja.json +6145 -4211
  87. package/dist/generated/assets/cldr/kk.json +6237 -4339
  88. package/dist/generated/assets/cldr/ko.json +6024 -4189
  89. package/dist/generated/assets/cldr/lt.json +6459 -4850
  90. package/dist/generated/assets/cldr/lv.json +6114 -4587
  91. package/dist/generated/assets/cldr/mk.json +6177 -0
  92. package/dist/generated/assets/cldr/ms.json +5821 -4021
  93. package/dist/generated/assets/cldr/nb.json +6154 -4335
  94. package/dist/generated/assets/cldr/nl.json +6306 -4294
  95. package/dist/generated/assets/cldr/nl_BE.json +6306 -4294
  96. package/dist/generated/assets/cldr/pl.json +6461 -4667
  97. package/dist/generated/assets/cldr/pt.json +6234 -4235
  98. package/dist/generated/assets/cldr/pt_PT.json +6309 -4372
  99. package/dist/generated/assets/cldr/ro.json +6170 -4563
  100. package/dist/generated/assets/cldr/ru.json +6732 -4909
  101. package/dist/generated/assets/cldr/ru_UA.json +6732 -4909
  102. package/dist/generated/assets/cldr/sk.json +6256 -4939
  103. package/dist/generated/assets/cldr/sl.json +6279 -4910
  104. package/dist/generated/assets/cldr/sr.json +6186 -4585
  105. package/dist/generated/assets/cldr/sr_Latn.json +6171 -4574
  106. package/dist/generated/assets/cldr/sv.json +6211 -4362
  107. package/dist/generated/assets/cldr/th.json +6126 -4214
  108. package/dist/generated/assets/cldr/tr.json +6245 -4400
  109. package/dist/generated/assets/cldr/uk.json +6806 -4858
  110. package/dist/generated/assets/cldr/vi.json +6016 -4070
  111. package/dist/generated/assets/cldr/zh_CN.json +5969 -4100
  112. package/dist/generated/assets/cldr/zh_HK.json +5977 -4108
  113. package/dist/generated/assets/cldr/zh_SG.json +5977 -4108
  114. package/dist/generated/assets/cldr/zh_TW.json +6033 -4131
  115. package/dist/generated/json-imports/LocaleData-fetch.d.ts +1 -0
  116. package/dist/generated/json-imports/LocaleData-fetch.js +93 -0
  117. package/dist/generated/json-imports/LocaleData-fetch.js.map +1 -0
  118. package/dist/generated/json-imports/LocaleData-node.d.ts +1 -0
  119. package/dist/generated/json-imports/LocaleData-node.js +93 -0
  120. package/dist/generated/json-imports/LocaleData-node.js.map +1 -0
  121. package/dist/generated/json-imports/LocaleData.d.ts +1 -0
  122. package/dist/generated/json-imports/LocaleData.js +89 -89
  123. package/dist/generated/json-imports/LocaleData.js.map +1 -0
  124. package/dist/getCachedLocaleDataInstance.js +2 -0
  125. package/dist/getCachedLocaleDataInstance.js.map +1 -1
  126. package/dist/locale/getLocaleData.js +2 -0
  127. package/dist/locale/getLocaleData.js.map +1 -1
  128. package/dist/sap/base/Event.js +59 -0
  129. package/dist/sap/base/Eventing.js +147 -0
  130. package/dist/sap/base/Log.js +2 -239
  131. package/dist/sap/base/assert.js +28 -1
  132. package/dist/sap/base/config/MemoryConfigurationProvider.js +20 -0
  133. package/dist/sap/base/config.js +17 -0
  134. package/dist/sap/base/future.js +12 -0
  135. package/dist/sap/base/i18n/Formatting.d.ts +13 -0
  136. package/dist/sap/base/i18n/Formatting.js +18 -0
  137. package/dist/sap/base/i18n/Formatting.js.map +1 -0
  138. package/dist/sap/base/i18n/LanguageTag.js +179 -0
  139. package/dist/sap/base/i18n/Localization.d.ts +7 -0
  140. package/dist/sap/base/i18n/Localization.js +17 -0
  141. package/dist/sap/base/i18n/Localization.js.map +1 -0
  142. package/dist/sap/base/i18n/ResourceBundle.js +20 -0
  143. package/dist/sap/base/i18n/date/CalendarType.js +44 -0
  144. package/dist/sap/base/i18n/date/CalendarWeekNumbering.js +106 -0
  145. package/dist/sap/base/i18n/date/TimezoneUtils.js +471 -0
  146. package/dist/sap/base/i18n/date/_EnumHelper.js +37 -0
  147. package/dist/sap/base/strings/camelize.js +30 -0
  148. package/dist/sap/base/strings/formatMessage.js +93 -15
  149. package/dist/sap/base/util/LoaderExtensions.js.map +1 -1
  150. package/dist/sap/base/util/ObjectPath.d.ts +4 -0
  151. package/dist/sap/base/util/ObjectPath.js +4 -33
  152. package/dist/sap/base/util/ObjectPath.js.map +1 -0
  153. package/dist/sap/base/util/Properties.js +12 -0
  154. package/dist/sap/base/util/Version.js +163 -0
  155. package/dist/sap/base/util/_merge.js +83 -26
  156. package/dist/sap/base/util/array/uniqueSort.js +37 -15
  157. package/dist/sap/base/util/deepClone.js +102 -0
  158. package/dist/sap/base/util/deepEqual.js +75 -51
  159. package/dist/sap/base/util/deepExtend.js +60 -0
  160. package/dist/sap/base/util/extend.js +58 -7
  161. package/dist/sap/base/util/fetch.js +8 -0
  162. package/dist/sap/base/util/isEmptyObject.js +34 -0
  163. package/dist/sap/base/util/isPlainObject.js +35 -1
  164. package/dist/sap/base/util/merge.js +57 -0
  165. package/dist/sap/base/util/mixedFetch.js +3 -0
  166. package/dist/sap/base/util/now.js +22 -7
  167. package/dist/sap/base/util/resolveReference.js +3 -0
  168. package/dist/sap/base/util/uid.js +27 -0
  169. package/dist/sap/ui/Device.js +25 -3
  170. package/dist/sap/ui/Global.js +1 -0
  171. package/dist/sap/ui/VersionInfo.js +14 -0
  172. package/dist/sap/ui/base/DataType.js +708 -0
  173. package/dist/sap/ui/base/DesignTime.js +11 -0
  174. package/dist/sap/ui/base/EventProvider.js +21 -0
  175. package/dist/sap/ui/base/Interface.js +47 -1
  176. package/dist/sap/ui/base/Metadata.js +470 -171
  177. package/dist/sap/ui/base/Object.js +284 -48
  178. package/dist/sap/ui/base/OwnStatics.js +6 -0
  179. package/dist/sap/ui/base/SyncPromise.js +98 -0
  180. package/dist/sap/ui/core/AnimationMode.js +42 -0
  181. package/dist/sap/ui/core/CalendarType.js +24 -8
  182. package/dist/sap/ui/core/Configuration.d.ts +2 -2
  183. package/dist/sap/ui/core/Configuration.js +2 -0
  184. package/dist/sap/ui/core/Configuration.js.map +1 -1
  185. package/dist/sap/ui/core/ControlBehavior.js +11 -0
  186. package/dist/sap/ui/core/Core.d.ts +3 -4
  187. package/dist/sap/ui/core/FormatSettings.d.ts +1 -2
  188. package/dist/sap/ui/core/FormatSettings.js +0 -2
  189. package/dist/sap/ui/core/FormatSettings.js.map +1 -1
  190. package/dist/sap/ui/core/Lib.js +41 -0
  191. package/dist/sap/ui/core/Locale.js +190 -155
  192. package/dist/sap/ui/core/LocaleData.js +2824 -1351
  193. package/dist/sap/ui/core/Supportability.js +5 -0
  194. package/dist/sap/ui/core/Theming.js +39 -0
  195. package/dist/sap/ui/core/_UrlResolver.js +11 -0
  196. package/dist/sap/ui/core/date/Buddhist.js +162 -87
  197. package/dist/sap/ui/core/date/CalendarUtils.js +63 -32
  198. package/dist/sap/ui/core/date/CalendarWeekNumbering.js +30 -7
  199. package/dist/sap/ui/core/date/Gregorian.js +25 -10
  200. package/dist/sap/ui/core/date/Islamic.js +298 -185
  201. package/dist/sap/ui/core/date/Japanese.js +210 -115
  202. package/dist/sap/ui/core/date/Persian.js +324 -195
  203. package/dist/sap/ui/core/date/UI5Date.js +970 -236
  204. package/dist/sap/ui/core/date/UniversalDate.js +1228 -264
  205. package/dist/sap/ui/core/date/_Calendars.js +10 -1
  206. package/dist/sap/ui/core/format/DateFormat.js +3168 -2111
  207. package/dist/sap/ui/core/format/FormatUtils.js +30 -0
  208. package/dist/sap/ui/core/format/NumberFormat.js +3164 -0
  209. package/dist/sap/ui/core/format/TimezoneUtil.js +93 -89
  210. package/dist/sap/ui/core/getCompatibilityVersion.js +7 -0
  211. package/dist/sap/ui/core/theming/ThemeHelper.js +14 -0
  212. package/dist/sap/ui/security/Security.js +12 -0
  213. package/dist/sap/ui/util/XMLHelper.js +11 -0
  214. package/dist/sap/ui/util/_URL.js +1 -0
  215. package/dist/ui5loader-autoconfig.js +1 -0
  216. package/package-scripts.cjs +22 -24
  217. package/package.json +20 -15
  218. package/tsconfig.json +20 -10
  219. package/used-modules.txt +30 -2
  220. package/dist/Assets-static.d.ts +0 -1
  221. package/dist/Assets-static.js +0 -3
  222. package/dist/Assets-static.js.map +0 -1
  223. package/dist/dates/calculateWeekNumber.d.ts +0 -5
  224. package/dist/dates/calculateWeekNumber.js +0 -45
  225. package/dist/dates/calculateWeekNumber.js.map +0 -1
  226. package/dist/generated/json-imports/LocaleData-static.js +0 -90
@@ -1,305 +1,1039 @@
1
- import Configuration from '../Configuration.js';
2
- import TimezoneUtil from '../format/TimezoneUtil.js';
3
- var aAllParts = [
4
- 'year',
5
- 'month',
6
- 'day',
7
- 'hour',
8
- 'minute',
9
- 'second',
10
- 'fractionalSecond'
11
- ], rIsUTCString = /Z|GMT|:.*[\+|\-]|^([\+|\-]\d{2})?\d{4}(-\d{2}){0,2}$/, aWeekday = [
12
- 'Sun',
13
- 'Mon',
14
- 'Tue',
15
- 'Wed',
16
- 'Thu',
17
- 'Fri',
18
- 'Sat'
19
- ], aMonths = [
20
- 'Jan',
21
- 'Feb',
22
- 'Mar',
23
- 'Apr',
24
- 'May',
25
- 'Jun',
26
- 'Jul',
27
- 'Aug',
28
- 'Sep',
29
- 'Oct',
30
- 'Nov',
31
- 'Dec'
32
- ], mWeekdayToDay = {
33
- Sun: 0,
34
- Mon: 1,
35
- Tue: 2,
36
- Wed: 3,
37
- Thu: 4,
38
- Fri: 5,
39
- Sat: 6
40
- };
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
+ import Log from "../../../base/Log.js";
7
+ import Localization from "../../../base/i18n/Localization.js";
8
+ import TimezoneUtils from "../../../base/i18n/date/TimezoneUtils.js";
9
+ var aAllParts = ["year", "month", "day", "hour", "minute", "second", "fractionalSecond"],
10
+ // "2023", "2023-01", "2023-01-20", "+002023-01-20" are parsed by JavaScript Date as UTC
11
+ // timestamps, whereas "798", "2023-1", "2023-01-5" are parsed as local dates.
12
+ // If "Z", "GMT" or a time zone offset (e.g. 00:00+0530) is included in the input string,
13
+ // the string is parsed as a UTC related timestamp
14
+ rIsUTCString = /Z|GMT|:.*[\+|\-]|^([\+|\-]\d{2})?\d{4}(-\d{2}){0,2}$/,
15
+ aWeekday = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
16
+ aMonths = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
17
+ mWeekdayToDay = {
18
+ Sun: 0,
19
+ Mon: 1,
20
+ Tue: 2,
21
+ Wed: 3,
22
+ Thu: 4,
23
+ Fri: 5,
24
+ Sat: 6
25
+ };
26
+ // Regular expression for local date string parts around the switch to Daylight Saving Time; the date part has to
27
+ // exist, time part parts may be optional; e.g. "2023-03-31T02:00" or "2023-3-31 2:00"
28
+ const rLocalDate = /^(\d{1,4})-(\d{1,2})-(\d{1,2})(?:[T ](\d{1,2})(?::(\d{1,2})(?::(\d{1,2})(?:\.(\d{1,3}))?)?)?)?$/;
29
+
30
+ /**
31
+ * Pads the start of the absolute given value with zeros up to the given length. If the given
32
+ * value is negative the leading minus is added in front of the zeros.
33
+ *
34
+ * @param {int} iValue The value to be padded
35
+ * @param {int} iLength The minimal length of the resulting string excluding the minus sign
36
+ * @returns {string} The padded string
37
+ */
41
38
  function addLeadingZeros(iValue, iLength) {
42
- return (iValue < 0 ? '-' : '') + Math.abs(iValue).toString().padStart(iLength, '0');
39
+ return (iValue < 0 ? "-" : "") + Math.abs(iValue).toString().padStart(iLength, "0");
43
40
  }
41
+
42
+ // eslint-disable-next-line valid-jsdoc
43
+ /**
44
+ * DO NOT call the constructor for UI5Date directly; use <code>UI5Date.getInstance</code>.
45
+ *
46
+ * @param {object} vDateParts
47
+ * An array like object containing the arguments as passed to
48
+ * <code>UI5Date.getInstance</code>
49
+ * @param {string} sTimezoneID
50
+ * The time zone ID to use for local methods of <code>Date</code>
51
+ *
52
+ * @alias module:sap/ui/core/date/UI5Date
53
+ * @author SAP SE
54
+ * @extends Date
55
+ * @class A date implementation considering the configured time zone
56
+ *
57
+ * A subclass of JavaScript <code>Date</code> that considers the configured time zone, see
58
+ * {@link module:sap/base/i18n/Localization.getTimezone Localization.getTimezone}. All JavaScript
59
+ * <code>Date</code> functions that use the local browser time zone, like <code>getDate</code>,
60
+ * <code>setDate</code>, and <code>toString</code>, are overwritten and use the
61
+ * configured time zone to compute the values.
62
+ *
63
+ * Use {@link module:sap/ui/core/date/UI5Date.getInstance} to create new date instances.
64
+ *
65
+ * <b>Note:</b> Adjusting the time zone in a running application can lead to unexpected data
66
+ * inconsistencies. For more information, see
67
+ * {@link module:sap/base/i18n/Localization.setTimezone Localization.setTimezone}.
68
+ *
69
+ * @hideconstructor
70
+ * @public
71
+ * @since 1.111.0
72
+ * @version 1.146.0
73
+ */
44
74
  function UI5Date(vDateParts, sTimezoneID) {
45
- var oDateInstance = UI5Date._createDateInstance(vDateParts);
46
- Object.defineProperties(this, {
47
- sTimezoneID: { value: sTimezoneID },
48
- oDate: {
49
- value: oDateInstance,
50
- writable: true
51
- },
52
- oDateParts: {
53
- value: undefined,
54
- writable: true
55
- }
56
- });
57
- if (isNaN(oDateInstance)) {
58
- return;
75
+ var oDateInstance = UI5Date._createDateInstance(vDateParts);
76
+ // mark internal properties not enumerable -> deepEqual handles this as a Date instance
77
+ Object.defineProperties(this, {
78
+ sTimezoneID: {
79
+ value: sTimezoneID
80
+ },
81
+ oDate: {
82
+ value: oDateInstance,
83
+ writable: true
84
+ },
85
+ oDateParts: {
86
+ value: undefined,
87
+ writable: true
59
88
  }
60
- if (vDateParts.length > 1 || vDateParts.length === 1 && typeof vDateParts[0] === 'string' && !rIsUTCString.test(vDateParts[0])) {
61
- this._setParts(aAllParts, [
62
- oDateInstance.getFullYear(),
63
- oDateInstance.getMonth(),
64
- oDateInstance.getDate(),
65
- oDateInstance.getHours(),
66
- oDateInstance.getMinutes(),
67
- oDateInstance.getSeconds(),
68
- oDateInstance.getMilliseconds()
69
- ]);
89
+ });
90
+ if (isNaN(oDateInstance)) {
91
+ return;
92
+ }
93
+ if (vDateParts.length > 1 || vDateParts.length === 1 && typeof vDateParts[0] === "string" && !rIsUTCString.test(vDateParts[0])) {
94
+ // JavaScript Date parsed the arguments already in local browser time zone
95
+ const aLocalDateParts = [oDateInstance.getFullYear(), oDateInstance.getMonth(), oDateInstance.getDate(), oDateInstance.getHours(), oDateInstance.getMinutes(), oDateInstance.getSeconds(), oDateInstance.getMilliseconds()];
96
+ // If the given local timestamp does not exist in the current browser time zone (switch to Daylight Saving
97
+ // Time) the values in aLocalDateParts don't match the input and have to be corrected
98
+ const iLocalTimezoneOffset = oDateInstance.getTimezoneOffset();
99
+ // the maximum time shift is 2 hours, so check whether 2 hours ago is in another time zone
100
+ const iTimezoneOffset2hAgo = new Date(oDateInstance.getTime() - 7200000).getTimezoneOffset();
101
+ // only the switch to the Daylight Saving Time needs to be fixed (e.g. from GMT+1 with the offset -60 to
102
+ // GMT+2 with the offset -120, or from GMT-5 with the offset 300 to GMT-4 with the offset 240);
103
+ // in the other case aLocalDateParts contain already the expected date/time parts
104
+ if (iLocalTimezoneOffset < iTimezoneOffset2hAgo) {
105
+ // year, seconds and milliseconds don't change when switching to Daylight Saving Time; update the other
106
+ // parts
107
+ if (vDateParts.length > 1) {
108
+ // timestamp near switch to Daylight Saving Time -> take the original values for month, day, hours,
109
+ // minutes (other parts are not modified by Daylight Saving Time switch)
110
+ aLocalDateParts[1] = vDateParts[1] || 0;
111
+ aLocalDateParts[2] = vDateParts[2] !== undefined ? vDateParts[2] : 1;
112
+ aLocalDateParts[3] = vDateParts[3] !== undefined ? vDateParts[3] : 0;
113
+ aLocalDateParts[4] = vDateParts[4] !== undefined ? vDateParts[4] : 0;
114
+ } else {
115
+ // vDateParts.length === 1
116
+ // string based local input near the switch to Daylight Saving Time can only be handled in the ISO
117
+ // format
118
+ const aDateParts = rLocalDate.exec(vDateParts[0]);
119
+ if (aDateParts) {
120
+ aLocalDateParts[1] = +aDateParts[2] - 1; // use + operator to get the value as used by Date
121
+ aLocalDateParts[2] = aDateParts[3];
122
+ aLocalDateParts[3] = aDateParts[4] !== undefined ? aDateParts[4] : 0;
123
+ aLocalDateParts[4] = aDateParts[5] !== undefined ? aDateParts[5] : 0;
124
+ } else {
125
+ // other string based local input near the switch to Daylight Saving Time cannot be handled
126
+ // without re-implementing parse logic of JavaScript Date -> recommend to use the constructor
127
+ // with more than 1 argument or to use the ISO format
128
+ Log.warning("UI5Date for '" + vDateParts[0] + "' cannot be ensured to be correct as it is near" + " the change from standard time to daylight saving time in the current browser locale;" + " use the constructor with more than 1 arguments or use the ISO format instead", oDateInstance, "sap.ui.core.date.UI5Date");
129
+ }
130
+ }
70
131
  }
132
+ this._setParts(aAllParts, aLocalDateParts);
133
+ }
71
134
  }
72
- UI5Date.prototype = Object.create(Date.prototype, { constructor: { value: Date } });
73
- UI5Date.prototype[Symbol.toStringTag] = 'Date';
135
+ UI5Date.prototype = Object.create(Date.prototype, {
136
+ constructor: {
137
+ value: Date
138
+ }
139
+ });
140
+ // QUnit uses Object.prototype.toString.call and expects "[object Date]" for dates; UI5Date
141
+ // shall be treated as a JavaScript Date so Symbol.toStringTag has to be "Date"
142
+ UI5Date.prototype[Symbol.toStringTag] = "Date";
143
+
144
+ /**
145
+ * Returns the value for the requested date part (e.g. "month", "year", "hour") of this date
146
+ * according to the configured time zone.
147
+ *
148
+ * @param {string} sPart The date part name
149
+ * @returns {int} The value of the date part
150
+ *
151
+ * @private
152
+ */
74
153
  UI5Date.prototype._getPart = function (sPart) {
75
- var iResult;
76
- if (isNaN(this.oDate)) {
77
- return NaN;
78
- }
79
- this.oDateParts = this.oDateParts || TimezoneUtil._getParts(this.oDate, this.sTimezoneID);
80
- if (sPart === 'weekday') {
81
- return mWeekdayToDay[this.oDateParts.weekday];
82
- }
83
- iResult = parseInt(this.oDateParts[sPart]);
84
- if (sPart === 'month') {
85
- iResult -= 1;
86
- } else if (sPart === 'year') {
87
- if (this.oDateParts.era === 'B') {
88
- iResult = 1 - iResult;
89
- }
154
+ var iResult;
155
+ if (isNaN(this.oDate)) {
156
+ return NaN;
157
+ }
158
+ this.oDateParts = this.oDateParts || TimezoneUtils._getParts(this.oDate, this.sTimezoneID);
159
+ if (sPart === "weekday") {
160
+ return mWeekdayToDay[this.oDateParts.weekday];
161
+ }
162
+ iResult = parseInt(this.oDateParts[sPart]);
163
+ if (sPart === "month") {
164
+ iResult -= 1;
165
+ } else if (sPart === "year") {
166
+ if (this.oDateParts.era === "B") {
167
+ iResult = 1 - iResult;
90
168
  }
91
- return iResult;
169
+ }
170
+ return iResult;
92
171
  };
172
+
173
+ /**
174
+ * Updates this date instance by setting the given parts in the configured time zone.
175
+ *
176
+ * @param {string[]} aParts
177
+ * The names of the date parts to be updated, supported names are: "year", "month", "day",
178
+ * "hour", "minute", "second", "fractionalSecond"
179
+ * @param {object} aValues
180
+ * The arguments object of the local setters
181
+ * @returns {int}
182
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
183
+ * timestamp could not be created
184
+ *
185
+ * @private
186
+ */
93
187
  UI5Date.prototype._setParts = function (aParts, aValues) {
94
- var i, oCurrentDateParts, oNewDateAsUTCTimestamp, iNewTimestamp, sPart, vValue, oDateParts = {}, iMaxLength = Math.min(aParts.length, aValues.length);
95
- if (iMaxLength === 0) {
96
- return this.setTime(NaN);
97
- }
98
- for (i = 0; i < iMaxLength; i += 1) {
99
- vValue = parseInt(+aValues[i]);
100
- sPart = aParts[i];
101
- if (isNaN(vValue)) {
102
- return this.setTime(NaN);
103
- }
104
- if (sPart === 'month') {
105
- vValue += 1;
106
- } else if (sPart === 'year') {
107
- if (vValue <= 0) {
108
- vValue = 1 - vValue;
109
- oDateParts.era = 'B';
110
- } else {
111
- oDateParts.era = 'A';
112
- }
113
- }
114
- oDateParts[sPart] = vValue.toString();
115
- }
116
- if (this.oDateParts) {
117
- oCurrentDateParts = this.oDateParts;
118
- } else if (isNaN(this.oDate)) {
119
- oCurrentDateParts = {
120
- day: '1',
121
- fractionalSecond: '0',
122
- hour: '0',
123
- minute: '0',
124
- month: '1',
125
- second: '0'
126
- };
127
- } else {
128
- oCurrentDateParts = TimezoneUtil._getParts(this.oDate, this.sTimezoneID);
188
+ var i,
189
+ oCurrentDateParts,
190
+ oNewDateAsUTCTimestamp,
191
+ iNewTimestamp,
192
+ sPart,
193
+ vValue,
194
+ oDateParts = {},
195
+ iMaxLength = Math.min(aParts.length, aValues.length);
196
+ if (iMaxLength === 0) {
197
+ return this.setTime(NaN);
198
+ }
199
+ for (i = 0; i < iMaxLength; i += 1) {
200
+ // convert the value to number as JavaScript Date does it;
201
+ // +"" -> 0, +null -> 0, +undefined -> NaN, +"foo" -> NaN, +"4" -> 4
202
+ vValue = parseInt(+aValues[i]);
203
+ sPart = aParts[i];
204
+ if (isNaN(vValue)) {
205
+ return this.setTime(NaN);
129
206
  }
130
- oDateParts = Object.assign({}, oCurrentDateParts, oDateParts);
131
- oNewDateAsUTCTimestamp = TimezoneUtil._getDateFromParts(oDateParts);
132
- if (isNaN(oNewDateAsUTCTimestamp)) {
133
- return this.setTime(NaN);
207
+ if (sPart === "month") {
208
+ vValue += 1;
209
+ } else if (sPart === "year") {
210
+ if (vValue <= 0) {
211
+ vValue = 1 - vValue;
212
+ oDateParts.era = "B";
213
+ } else {
214
+ oDateParts.era = "A";
215
+ }
134
216
  }
135
- iNewTimestamp = oNewDateAsUTCTimestamp.getTime() + TimezoneUtil.calculateOffset(oNewDateAsUTCTimestamp, this.sTimezoneID) * 1000;
136
- return this.setTime(iNewTimestamp);
217
+ oDateParts[sPart] = vValue.toString();
218
+ }
219
+ if (this.oDateParts) {
220
+ oCurrentDateParts = this.oDateParts;
221
+ } else if (isNaN(this.oDate)) {
222
+ //era and year are given at least
223
+ oCurrentDateParts = {
224
+ day: "1",
225
+ fractionalSecond: "0",
226
+ hour: "0",
227
+ minute: "0",
228
+ month: "1",
229
+ second: "0"
230
+ };
231
+ } else {
232
+ oCurrentDateParts = TimezoneUtils._getParts(this.oDate, this.sTimezoneID);
233
+ }
234
+ oDateParts = Object.assign({}, oCurrentDateParts, oDateParts);
235
+
236
+ // NaN may happen if no year is given if current date is invalid
237
+ oNewDateAsUTCTimestamp = TimezoneUtils._getDateFromParts(oDateParts);
238
+ if (isNaN(oNewDateAsUTCTimestamp)) {
239
+ return this.setTime(NaN);
240
+ }
241
+ iNewTimestamp = oNewDateAsUTCTimestamp.getTime() + TimezoneUtils.calculateOffset(oNewDateAsUTCTimestamp, this.sTimezoneID) * 1000;
242
+ return this.setTime(iNewTimestamp);
137
243
  };
244
+
245
+ /**
246
+ * Clones this UI5Date instance.
247
+ *
248
+ * @returns {Date|module:sap/ui/core/date/UI5Date} The cloned date instance
249
+ *
250
+ * @private
251
+ */
138
252
  UI5Date.prototype.clone = function () {
139
- return UI5Date.getInstance(this);
253
+ return UI5Date.getInstance(this);
140
254
  };
255
+
256
+ /**
257
+ * Returns the day of the month of this date instance according to the configured time zone,
258
+ * see <code>Date.prototype.getDate</code>.
259
+ *
260
+ * @returns {int}
261
+ * A number between 1 and 31 representing the day of the month of this date instance according
262
+ * to the configured time zone
263
+ *
264
+ * @public
265
+ */
141
266
  UI5Date.prototype.getDate = function () {
142
- return this._getPart('day');
267
+ return this._getPart("day");
143
268
  };
269
+
270
+ /**
271
+ * Returns the day of the week of this date instance according to the configured time zone,
272
+ * see <code>Date.prototype.getDay</code>.
273
+ *
274
+ * @returns {int}
275
+ * A number between 0 (Sunday) and 6 (Saturday) representing the day of the week of this date
276
+ * instance according to the configured time zone
277
+ *
278
+ * @public
279
+ */
144
280
  UI5Date.prototype.getDay = function () {
145
- return this._getPart('weekday');
281
+ return this._getPart("weekday");
146
282
  };
283
+
284
+ /**
285
+ * Returns the year of this date instance according to the configured time zone,
286
+ * see <code>Date.prototype.getFullYear</code>.
287
+ *
288
+ * @returns {int} The year of this date instance according to the configured time zone
289
+ *
290
+ * @public
291
+ */
147
292
  UI5Date.prototype.getFullYear = function () {
148
- return this._getPart('year');
293
+ return this._getPart("year");
149
294
  };
295
+
296
+ /**
297
+ * Returns the hours of this date instance according to the configured time zone, see
298
+ * <code>Date.prototype.getHours</code>.
299
+ *
300
+ * @returns {int}
301
+ * A number between 0 and 23 representing the hours of this date instance according to the
302
+ * configured time zone
303
+ *
304
+ * @public
305
+ */
150
306
  UI5Date.prototype.getHours = function () {
151
- return this._getPart('hour');
307
+ return this._getPart("hour");
152
308
  };
309
+
310
+ /**
311
+ * Returns the milliseconds of this date instance according to the configured time zone,
312
+ * see <code>Date.prototype.getMilliseconds</code>.
313
+ *
314
+ * @returns {int}
315
+ * A number between 0 and 999 representing the milliseconds of this date instance according to
316
+ * the configured time zone
317
+ *
318
+ * @public
319
+ */
153
320
  UI5Date.prototype.getMilliseconds = function () {
154
- return this._getPart('fractionalSecond');
321
+ return this._getPart("fractionalSecond");
155
322
  };
323
+
324
+ /**
325
+ * Returns the minutes of this date instance according to the configured time zone,
326
+ * see <code>Date.prototype.getMinutes</code>.
327
+ *
328
+ * @returns {int}
329
+ * A number between 0 and 59 representing the minutes of this date instance according to the
330
+ * configured time zone
331
+ *
332
+ * @public
333
+ */
156
334
  UI5Date.prototype.getMinutes = function () {
157
- return this._getPart('minute');
335
+ return this._getPart("minute");
158
336
  };
337
+
338
+ /**
339
+ * Returns the month index of this date instance according to the configured time zone,
340
+ * see <code>Date.prototype.getMonth</code>.
341
+ *
342
+ * @returns {int}
343
+ * The month index between 0 (January) and 11 (December) of this date instance according to
344
+ * the configured time zone
345
+ *
346
+ * @public
347
+ */
159
348
  UI5Date.prototype.getMonth = function () {
160
- return this._getPart('month');
349
+ return this._getPart("month");
161
350
  };
351
+
352
+ /**
353
+ * Returns the seconds of this date instance according to the configured time zone,
354
+ * see <code>Date.prototype.getSeconds</code>.
355
+ *
356
+ * @returns {int}
357
+ * A number between 0 and 59 representing the seconds of this date instance according to the
358
+ * configured time zone
359
+ *
360
+ * @public
361
+ */
162
362
  UI5Date.prototype.getSeconds = function () {
163
- return this._getPart('second');
363
+ return this._getPart("second");
164
364
  };
365
+
366
+ /**
367
+ * Returns the difference in minutes between the UTC and the configured time zone for this date,
368
+ * see <code>Date.prototype.getTimezoneOffset</code>.
369
+ *
370
+ * @returns {int}
371
+ * The difference in minutes between the UTC and the configured time zone for this date
372
+ *
373
+ * @public
374
+ */
165
375
  UI5Date.prototype.getTimezoneOffset = function () {
166
- return TimezoneUtil.calculateOffset(this.oDate, this.sTimezoneID) / 60;
376
+ return TimezoneUtils.calculateOffset(this.oDate, this.sTimezoneID) / 60;
167
377
  };
378
+
379
+ /**
380
+ * Returns the year of this date instance minus 1900 according to the configured time zone,
381
+ * see <code>Date.prototype.getYear</code>.
382
+ *
383
+ * @returns {int}
384
+ * The year of this date instance minus 1900 according to the configured time zone
385
+ *
386
+ * @deprecated As of version 1.111 as it is deprecated in the base class JavaScript Date; use
387
+ * {@link #getFullYear} instead
388
+ * @public
389
+ */
168
390
  UI5Date.prototype.getYear = function () {
169
- return this._getPart('year') - 1900;
391
+ return this._getPart("year") - 1900;
170
392
  };
393
+
394
+ /**
395
+ * Sets the day of the month for this date instance considering the configured time zone,
396
+ * see <code>Date.prototype.setDate</code>.
397
+ *
398
+ * @param {int} iDay
399
+ * An integer representing the new day value, see <code>Date.prototype.setDate</code>
400
+ * @returns {int}
401
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
402
+ * timestamp could not be updated
403
+ *
404
+ * @public
405
+ */
171
406
  UI5Date.prototype.setDate = function (iDay) {
172
- return this._setParts(['day'], arguments);
407
+ return this._setParts(["day"], arguments);
173
408
  };
409
+
410
+ /**
411
+ * Sets the year, month and day for this date instance considering the configured time zone,
412
+ * see <code>Date.prototype.setFullYear</code>.
413
+ *
414
+ * @param {int} iYear An integer representing the new year value
415
+ * @param {int} [iMonth] An integer representing the new month index
416
+ * @param {int} [iDay] An integer representing the new day value
417
+ * @returns {int}
418
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
419
+ * timestamp could not be updated
420
+ *
421
+ * @public
422
+ */
174
423
  UI5Date.prototype.setFullYear = function (iYear, iMonth, iDay) {
175
- return this._setParts([
176
- 'year',
177
- 'month',
178
- 'day'
179
- ], arguments);
424
+ return this._setParts(["year", "month", "day"], arguments);
180
425
  };
426
+
427
+ /**
428
+ * Sets the hours, minutes, seconds and milliseconds for this date instance considering the
429
+ * configured time zone, see <code>Date.prototype.setHours</code>.
430
+ *
431
+ * @param {int} iHours An integer representing the new hour value
432
+ * @param {int} [iMinutes] An integer representing the new minutes value
433
+ * @param {int} [iSeconds] An integer representing the new seconds value
434
+ * @param {int} [iMilliseconds] An integer representing the new milliseconds value
435
+ * @returns {int}
436
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
437
+ * timestamp could not be updated
438
+ *
439
+ * @public
440
+ */
181
441
  UI5Date.prototype.setHours = function (iHours, iMinutes, iSeconds, iMilliseconds) {
182
- return this._setParts([
183
- 'hour',
184
- 'minute',
185
- 'second',
186
- 'fractionalSecond'
187
- ], arguments);
442
+ return this._setParts(["hour", "minute", "second", "fractionalSecond"], arguments);
188
443
  };
444
+
445
+ /**
446
+ * Sets the milliseconds for this date instance considering the configured time zone, see
447
+ * <code>Date.prototype.setMilliseconds</code>.
448
+ *
449
+ * @param {int} iMilliseconds An integer representing the new milliseconds value
450
+ * @returns {int}
451
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
452
+ * timestamp could not be updated
453
+ *
454
+ * @public
455
+ */
189
456
  UI5Date.prototype.setMilliseconds = function (iMilliseconds) {
190
- return this._setParts(['fractionalSecond'], arguments);
457
+ return this._setParts(["fractionalSecond"], arguments);
191
458
  };
459
+
460
+ /**
461
+ * Sets the minutes, seconds and milliseconds for this date instance considering the configured
462
+ * time zone, see <code>Date.prototype.setMinutes</code>.
463
+ *
464
+ * @param {int} iMinutes An integer representing the new minutes value
465
+ * @param {int} [iSeconds] An integer representing the new seconds value
466
+ * @param {int} [iMilliseconds] An integer representing the new milliseconds value
467
+ * @returns {int}
468
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
469
+ * timestamp could not be updated
470
+ *
471
+ * @public
472
+ */
192
473
  UI5Date.prototype.setMinutes = function (iMinutes, iSeconds, iMilliseconds) {
193
- return this._setParts([
194
- 'minute',
195
- 'second',
196
- 'fractionalSecond'
197
- ], arguments);
474
+ return this._setParts(["minute", "second", "fractionalSecond"], arguments);
198
475
  };
476
+
477
+ /**
478
+ * Sets the month and day for this date instance considering the configured time zone,
479
+ * see <code>Date.prototype.setMonth</code>.
480
+ *
481
+ * @param {int} iMonth An integer representing the new month index
482
+ * @param {int} [iDay] An integer representing the new day value
483
+ * @returns {int}
484
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
485
+ * timestamp could not be updated
486
+ *
487
+ * @public
488
+ */
199
489
  UI5Date.prototype.setMonth = function (iMonth, iDay) {
200
- return this._setParts([
201
- 'month',
202
- 'day'
203
- ], arguments);
490
+ return this._setParts(["month", "day"], arguments);
204
491
  };
492
+
493
+ /**
494
+ * Sets the seconds and milliseconds for this date instance considering the configured time zone,
495
+ * see <code>Date.prototype.setSeconds</code>.
496
+ *
497
+ * @param {int} iSeconds An integer representing the new seconds value
498
+ * @param {int} [iMilliseconds] An integer representing the new milliseconds value
499
+ * @returns {int}
500
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
501
+ * timestamp could not be updated
502
+ *
503
+ * @public
504
+ */
205
505
  UI5Date.prototype.setSeconds = function (iSeconds, iMilliseconds) {
206
- return this._setParts([
207
- 'second',
208
- 'fractionalSecond'
209
- ], arguments);
506
+ return this._setParts(["second", "fractionalSecond"], arguments);
210
507
  };
508
+
509
+ /**
510
+ * Sets this date object to the given time represented by a number of milliseconds based on the
511
+ * UNIX epoch and resets the previously set date parts, see
512
+ * <code>Date.prototype.setTime</code>.
513
+ *
514
+ * @param {int} iTime The date time in milliseconds based in the UNIX epoch
515
+ * @returns {int}
516
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
517
+ * timestamp could not be updated
518
+ *
519
+ * @public
520
+ */
211
521
  UI5Date.prototype.setTime = function (iTime) {
212
- this.oDateParts = undefined;
213
- return this.oDate.setTime(iTime);
522
+ this.oDateParts = undefined;
523
+ return this.oDate.setTime(iTime);
214
524
  };
525
+
526
+ /**
527
+ * Sets the year for this date instance plus 1900 considering the configured time zone, see
528
+ * <code>Date.prototype.setYear</code>.
529
+ *
530
+ * @param {int} iYear The year which is to be set for this date. If iYear is a number between 0
531
+ * and 99 (inclusive), then the year for this date is set to 1900 + iYear. Otherwise, the year
532
+ * for this date is set to iYear.
533
+ * @returns {int}
534
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
535
+ * timestamp could not be updated
536
+ *
537
+ * @deprecated As of version 1.111 as it is deprecated in the base class JavaScript Date; use
538
+ * {@link #setFullYear} instead
539
+ * @public
540
+ */
215
541
  UI5Date.prototype.setYear = function (iYear) {
216
- return this._setParts(['year'], [parseInt(iYear) + 1900]);
542
+ var iValue = parseInt(iYear);
543
+ iValue = iValue < 0 || iValue > 99 ? iValue : iValue + 1900;
544
+ return this._setParts(["year"], [iValue]);
217
545
  };
546
+
547
+ /**
548
+ * Returns this date object to the given time represented by a number of milliseconds based on the
549
+ * UNIX epoch, see <code>Date.prototype.getTime</code>.
550
+ *
551
+ * @returns {int}
552
+ * The timestamp in milliseconds of this date based on the UNIX epoch, or <code>NaN</code> if
553
+ * the date is an invalid date
554
+ *
555
+ * @function
556
+ * @name module:sap/ui/core/date/UI5Date.prototype.getTime
557
+ * @public
558
+ */
559
+
560
+ /**
561
+ * Returns the day of the month of this date instance according to universal time,
562
+ * see <code>Date.prototype.getUTCDate</code>.
563
+ *
564
+ * @returns {int}
565
+ * A number between 1 and 31 representing the day of the month of this date instance according
566
+ * to universal time
567
+ *
568
+ * @function
569
+ * @name module:sap/ui/core/date/UI5Date.prototype.getUTCDate
570
+ * @public
571
+ */
572
+
573
+ /**
574
+ *
575
+ * Returns the day of the week of this date instance according to universal time,
576
+ * see <code>Date.prototype.getUTCDay</code>.
577
+ *
578
+ * @returns {int}
579
+ * A number between 0 (Sunday) and 6 (Saturday) representing the day of the week of this date
580
+ * instance according to universal time
581
+ *
582
+ * @function
583
+ * @name module:sap/ui/core/date/UI5Date.prototype.getUTCDay
584
+ * @public
585
+ */
586
+
587
+ /**
588
+ * Returns the year of this date instance according to universal time, see
589
+ * <code>Date.prototype.getUTCFullYear</code>.
590
+ *
591
+ * @returns {int} The year of this date instance according to universal time
592
+ *
593
+ * @function
594
+ * @name module:sap/ui/core/date/UI5Date.prototype.getUTCFullYear
595
+ * @public
596
+ */
597
+
598
+ /**
599
+ * Returns the hours of this date instance according to universal time, see
600
+ * <code>Date.prototype.getUTCHours</code>.
601
+ *
602
+ * @returns {int}
603
+ * A number between 0 and 23 representing the hours of this date instance according to
604
+ * universal time
605
+ *
606
+ * @function
607
+ * @name module:sap/ui/core/date/UI5Date.prototype.getUTCHours
608
+ * @public
609
+ */
610
+
611
+ /**
612
+ * Returns the milliseconds of this date instance according to universal time,
613
+ * see <code>Date.prototype.getUTCMilliseconds</code>.
614
+ *
615
+ * @returns {int}
616
+ * A number between 0 and 999 representing the milliseconds of this date instance according to
617
+ * universal time
618
+ *
619
+ * @function
620
+ * @name module:sap/ui/core/date/UI5Date.prototype.getUTCMilliseconds
621
+ * @public
622
+ */
623
+
624
+ /**
625
+ * Returns the minutes of this date instance according to universal time, see
626
+ * <code>Date.prototype.getUTCMinutes</code>.
627
+ *
628
+ * @returns {int}
629
+ * A number between 0 and 59 representing the minutes of this date instance according to
630
+ * universal time
631
+ *
632
+ * @function
633
+ * @name module:sap/ui/core/date/UI5Date.prototype.getUTCMinutes
634
+ * @public
635
+ */
636
+
637
+ /**
638
+ * Returns the month index of this date instance according to universal time, see
639
+ * <code>Date.prototype.getUTCMonth</code>.
640
+ *
641
+ * @returns {int}
642
+ * The month index between 0 (January) and 11 (December) of this date instance according to
643
+ * universal time
644
+ *
645
+ * @function
646
+ * @name module:sap/ui/core/date/UI5Date.prototype.getUTCMonth
647
+ * @public
648
+ */
649
+
650
+ /**
651
+ * Returns the seconds of this date instance according to universal time, see
652
+ * <code>Date.prototype.getUTCSeconds</code>.
653
+ *
654
+ * @returns {int}
655
+ * A number between 0 and 59 representing the seconds of this date instance according to
656
+ * universal time
657
+ *
658
+ * @function
659
+ * @name module:sap/ui/core/date/UI5Date.prototype.getUTCSeconds
660
+ * @public
661
+ */
662
+
663
+ /**
664
+ * Sets the day of the month for this date instance according to universal time,
665
+ * see <code>Date.prototype.setUTCDate</code>.
666
+ *
667
+ * @param {int} iDay
668
+ * An integer representing the new day value, see <code>Date.prototype.setUTCDate</code>
669
+ * @returns {int}
670
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
671
+ * timestamp could not be updated
672
+ *
673
+ * @function
674
+ * @name module:sap/ui/core/date/UI5Date.prototype.setUTCDate
675
+ * @public
676
+ */
677
+
678
+ /**
679
+ * Sets the year, month and day for this date instance according to universal time,
680
+ * see <code>Date.prototype.setUTCFullYear</code>.
681
+ *
682
+ * @param {int} iYear An integer representing the new year value
683
+ * @param {int} [iMonth] An integer representing the new month index
684
+ * @param {int} [iDay] An integer representing the new day value
685
+ * @returns {int}
686
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
687
+ * timestamp could not be updated
688
+ *
689
+ * @function
690
+ * @name module:sap/ui/core/date/UI5Date.prototype.setUTCFullYear
691
+ * @public
692
+ */
693
+
694
+ /**
695
+ * Sets the hours, minutes, seconds and milliseconds for this date instance according to
696
+ * universal time, see <code>Date.prototype.setUTCHours</code>.
697
+ *
698
+ * @param {int} iHours An integer representing the new hour value
699
+ * @param {int} [iMinutes] An integer representing the new minutes value
700
+ * @param {int} [iSeconds] An integer representing the new seconds value
701
+ * @param {int} [iMilliseconds] An integer representing the new milliseconds value
702
+ * @returns {int}
703
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
704
+ * timestamp could not be updated
705
+ *
706
+ * @function
707
+ * @name module:sap/ui/core/date/UI5Date.prototype.setUTCHours
708
+ * @public
709
+ */
710
+
711
+ /**
712
+ * Sets the milliseconds for this date instance according to universal time, see
713
+ * <code>Date.prototype.setUTCMilliseconds</code>.
714
+ *
715
+ * @param {int} iMilliseconds An integer representing the new milliseconds value
716
+ * @returns {int}
717
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
718
+ * timestamp could not be updated
719
+ *
720
+ * @function
721
+ * @name module:sap/ui/core/date/UI5Date.prototype.setUTCMilliseconds
722
+ * @public
723
+ */
724
+
725
+ /**
726
+ * Sets the minutes, seconds and milliseconds for this date instance according to universal
727
+ * time, see <code>Date.prototype.setUTCMinutes</code>.
728
+ *
729
+ * @param {int} iMinutes An integer representing the new minutes value
730
+ * @param {int} [iSeconds] An integer representing the new seconds value
731
+ * @param {int} [iMilliseconds] An integer representing the new milliseconds value
732
+ * @returns {int}
733
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
734
+ * timestamp could not be updated
735
+ *
736
+ * @function
737
+ * @name module:sap/ui/core/date/UI5Date.prototype.setUTCMinutes
738
+ * @public
739
+ */
740
+
741
+ /**
742
+ * Sets the month and day for this date instance according to universal time,
743
+ * see <code>Date.prototype.setUTCMonth</code>.
744
+ *
745
+ * @param {int} iMonth An integer representing the new month index
746
+ * @param {int} [iDay] An integer representing the new day value
747
+ * @returns {int}
748
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
749
+ * timestamp could not be updated
750
+ *
751
+ * @function
752
+ * @name module:sap/ui/core/date/UI5Date.prototype.setUTCMonth
753
+ * @public
754
+ */
755
+
756
+ /**
757
+ * Sets the seconds and milliseconds for this date instance according to universal time,
758
+ * see <code>Date.prototype.setUTCSeconds</code>.
759
+ *
760
+ * @param {int} iSeconds An integer representing the new seconds value
761
+ * @param {int} [iMilliseconds] An integer representing the new milliseconds value
762
+ * @returns {int}
763
+ * The milliseconds of the new timestamp based on the UNIX epoch, or <code>NaN</code> if the
764
+ * timestamp could not be updated
765
+ *
766
+ * @function
767
+ * @name module:sap/ui/core/date/UI5Date.prototype.setUTCSeconds
768
+ * @public
769
+ */
770
+
771
+ /**
772
+ * Converts this date to a string, interpreting it in the UTC time zone, see
773
+ * <code>Date.prototype.toGMTString</code>.
774
+ *
775
+ * @returns {string} The converted date as string in the UTC time zone
776
+ *
777
+ * @function
778
+ * @name module:sap/ui/core/date/UI5Date.prototype.toGMTString
779
+ * @public
780
+ */
781
+
782
+ /**
783
+ * Converts this date to a string in ISO format in the UTC offset zero time zone, as denoted
784
+ * by the suffix <code>Z</code>, see <code>Date.prototype.toISOString</code>.
785
+ *
786
+ * @returns {string}
787
+ * The converted date as a string in ISO format, in the UTC offset zero time zone
788
+ *
789
+ * @function
790
+ * @name module:sap/ui/core/date/UI5Date.prototype.toISOString
791
+ * @public
792
+ */
793
+
794
+ /**
795
+ * Returns a string representation of this date object, see <code>Date.prototype.toJSON</code>.
796
+ *
797
+ * @returns {string} The date object representation as a string
798
+ *
799
+ * @function
800
+ * @name module:sap/ui/core/date/UI5Date.prototype.toJSON
801
+ * @public
802
+ */
803
+
804
+ /**
805
+ * Returns the date portion of this date object interpreted in the configured time zone in
806
+ * English, see <code>Date.prototype.toDateString</code>.
807
+ *
808
+ * @returns {string}
809
+ * The date portion of this date object interpreted in the configured time zone in English
810
+ *
811
+ * @public
812
+ */
218
813
  UI5Date.prototype.toDateString = function () {
219
- if (isNaN(this.oDate)) {
220
- return this.oDate.toDateString();
221
- }
222
- return aWeekday[this.getDay()] + ' ' + aMonths[this.getMonth()] + ' ' + addLeadingZeros(this.getDate(), 2) + ' ' + addLeadingZeros(this.getFullYear(), 4);
814
+ if (isNaN(this.oDate)) {
815
+ return this.oDate.toDateString();
816
+ }
817
+ return aWeekday[this.getDay()] + " " + aMonths[this.getMonth()] + " " + addLeadingZeros(this.getDate(), 2) + " " + addLeadingZeros(this.getFullYear(), 4);
223
818
  };
819
+
820
+ /**
821
+ * Returns a string with a language-dependent representation of the date part of this date
822
+ * object interpreted by default in the configured time zone, see
823
+ * <code>Date.prototype.toLocaleDateString</code>.
824
+ *
825
+ * @param {string} [sLocale]
826
+ * The locale used for formatting; by default, the string representation of
827
+ * {@link module:sap/base/i18n/Localization.getLanguageTag Localization.getLanguageTag}
828
+ * @param {object} [oOptions]
829
+ * The options object used for formatting, corresponding to the options parameter of the
830
+ * <code>Intl.DateTimeFormat</code> constructor
831
+ * @param {string} [oOptions.timeZone]
832
+ * The IANA time zone ID; by default
833
+ * {@link module:sap/base/i18n/Localization.getTimezone Localization.getTimezone}
834
+ * @returns {string}
835
+ * The language-dependent representation of the date part of this date object
836
+ *
837
+ * @function
838
+ * @name module:sap/ui/core/date/UI5Date.prototype.toLocaleDateString
839
+ * @public
840
+ */
841
+
842
+ /**
843
+ * Returns a string with a language-dependent representation of this date object interpreted by
844
+ * default in the configured time zone, see <code>Date.prototype.toLocaleString</code>.
845
+ *
846
+ * @param {string} [sLocale]
847
+ * The locale used for formatting; by default, the string representation of
848
+ * {@link module:sap/base/i18n/Localization.getLanguageTag Localization.getLanguageTag}
849
+ * @param {object} [oOptions]
850
+ * The options object used for formatting, corresponding to the options parameter of the
851
+ * <code>Intl.DateTimeFormat</code> constructor
852
+ * @param {string} [oOptions.timeZone]
853
+ * The IANA time zone ID; by default
854
+ * {@link module:sap/base/i18n/Localization.getTimezone Localization.getTimezone}
855
+ * @returns {string}
856
+ * The language-dependent representation of this date object
857
+ *
858
+ * @function
859
+ * @name module:sap/ui/core/date/UI5Date.prototype.toLocaleString
860
+ * @public
861
+ */
862
+
863
+ /**
864
+ * Returns a string with a language-dependent representation of the time part of this date
865
+ * object interpreted by default in the configured time zone, see
866
+ * <code>Date.prototype.toLocaleTimeString</code>.
867
+ *
868
+ * @param {string} [sLocale]
869
+ * The locale used for formatting; by default, the string representation of
870
+ * {@link module:sap/base/i18n/Localization.getLanguageTag Localization.getLanguageTag}
871
+ * @param {object} [oOptions]
872
+ * The options object used for formatting, corresponding to the options parameter of the
873
+ * <code>Intl.DateTimeFormat</code> constructor
874
+ * @param {string} [oOptions.timeZone]
875
+ * The IANA time zone ID; by default
876
+ * {@link module:sap/base/i18n/Localization.getTimezone Localization.getTimezone}
877
+ * @returns {string}
878
+ * The language-dependent representation of the time part of this date object
879
+ *
880
+ * @function
881
+ * @name module:sap/ui/core/date/UI5Date.prototype.toLocaleTimeString
882
+ * @public
883
+ */
884
+
885
+ /**
886
+ * Returns a string representing this date object interpreted in the configured time zone.
887
+ *
888
+ * @returns {string}
889
+ * A string representing this date object interpreted in the configured time zone
890
+ *
891
+ * @public
892
+ */
224
893
  UI5Date.prototype.toString = function () {
225
- if (isNaN(this.oDate)) {
226
- return this.oDate.toString();
227
- }
228
- return this.toDateString() + ' ' + this.toTimeString();
894
+ if (isNaN(this.oDate)) {
895
+ return this.oDate.toString();
896
+ }
897
+ return this.toDateString() + " " + this.toTimeString();
229
898
  };
899
+
900
+ /**
901
+ * Returns the time portion of this date object interpreted in the configured time zone in English.
902
+ *
903
+ * @returns {string}
904
+ * The time portion of this date object interpreted in the configured time zone in English
905
+ *
906
+ * @public
907
+ */
230
908
  UI5Date.prototype.toTimeString = function () {
231
- var iHours, iMinutes, sSign, iTimeZoneOffset;
232
- if (isNaN(this.oDate)) {
233
- return this.oDate.toTimeString();
234
- }
235
- iTimeZoneOffset = this.getTimezoneOffset();
236
- sSign = iTimeZoneOffset > 0 ? '-' : '+';
237
- iHours = Math.floor(Math.abs(iTimeZoneOffset) / 60);
238
- iMinutes = Math.abs(iTimeZoneOffset) % 60;
239
- return addLeadingZeros(this.getHours(), 2) + ':' + addLeadingZeros(this.getMinutes(), 2) + ':' + addLeadingZeros(this.getSeconds(), 2) + ' GMT' + sSign + addLeadingZeros(iHours, 2) + addLeadingZeros(iMinutes, 2);
909
+ var iHours, iMinutes, sSign, iTimeZoneOffset;
910
+ if (isNaN(this.oDate)) {
911
+ return this.oDate.toTimeString();
912
+ }
913
+ iTimeZoneOffset = this.getTimezoneOffset();
914
+ sSign = iTimeZoneOffset > 0 ? "-" : "+";
915
+ iHours = Math.floor(Math.abs(iTimeZoneOffset) / 60);
916
+ iMinutes = Math.abs(iTimeZoneOffset) % 60;
917
+
918
+ // ommit the optional, implementation dependent time zone name
919
+ return addLeadingZeros(this.getHours(), 2) + ":" + addLeadingZeros(this.getMinutes(), 2) + ":" + addLeadingZeros(this.getSeconds(), 2) + " GMT" + sSign + addLeadingZeros(iHours, 2) + addLeadingZeros(iMinutes, 2);
240
920
  };
241
- [
242
- 'getTime',
243
- 'getUTCDate',
244
- 'getUTCDay',
245
- 'getUTCFullYear',
246
- 'getUTCHours',
247
- 'getUTCMilliseconds',
248
- 'getUTCMinutes',
249
- 'getUTCMonth',
250
- 'getUTCSeconds',
251
- 'toGMTString',
252
- 'toISOString',
253
- 'toJSON',
254
- 'toUTCString',
255
- 'valueOf'
256
- ].forEach(function (sMethod) {
257
- UI5Date.prototype[sMethod] = function () {
258
- return this.oDate[sMethod].apply(this.oDate, arguments);
259
- };
921
+
922
+ /**
923
+ * Converts this date to a string, interpreting it in the UTC time zone, see
924
+ * <code>Date.prototype.toUTCString</code>.
925
+ *
926
+ * @returns {string} The converted date as a string in the UTC time zone
927
+ *
928
+ * @function
929
+ * @name module:sap/ui/core/date/UI5Date.prototype.toUTCString
930
+ * @public
931
+ */
932
+
933
+ /**
934
+ * Returns the value of this date object in milliseconds based on the UNIX epoch, see
935
+ * <code>Date.prototype.valueOf</code>.
936
+ *
937
+ * @returns {int} The primitive value of this date object in milliseconds based on the UNIX epoch
938
+ *
939
+ * @function
940
+ * @name module:sap/ui/core/date/UI5Date.prototype.valueOf
941
+ * @public
942
+ */
943
+
944
+ // functions that simply delegate to the inner date instance
945
+ ["getTime", "getUTCDate", "getUTCDay", "getUTCFullYear", "getUTCHours", "getUTCMilliseconds", "getUTCMinutes", "getUTCMonth", "getUTCSeconds", "toGMTString", "toISOString", "toJSON", "toUTCString", "valueOf"].forEach(function (sMethod) {
946
+ UI5Date.prototype[sMethod] = function () {
947
+ return this.oDate[sMethod].apply(this.oDate, arguments);
948
+ };
260
949
  });
261
- [
262
- 'toLocaleDateString',
263
- 'toLocaleString',
264
- 'toLocaleTimeString'
265
- ].forEach(function (sMethod) {
266
- UI5Date.prototype[sMethod] = function (sLocale, oOptions) {
267
- return this.oDate[sMethod](sLocale || Configuration.getLanguageTag(), Object.assign({ timeZone: this.sTimezoneID }, oOptions));
268
- };
950
+ ["toLocaleDateString", "toLocaleString", "toLocaleTimeString"].forEach(function (sMethod) {
951
+ UI5Date.prototype[sMethod] = function (sLocale, oOptions) {
952
+ return this.oDate[sMethod](sLocale || Localization.getLanguageTag().toString(), Object.assign({
953
+ timeZone: this.sTimezoneID
954
+ }, oOptions));
955
+ };
269
956
  });
270
- [
271
- 'setUTCDate',
272
- 'setUTCFullYear',
273
- 'setUTCHours',
274
- 'setUTCMilliseconds',
275
- 'setUTCMinutes',
276
- 'setUTCMonth',
277
- 'setUTCSeconds'
278
- ].forEach(function (sMethod) {
279
- UI5Date.prototype[sMethod] = function () {
280
- this.oDateParts = undefined;
281
- return this.oDate[sMethod].apply(this.oDate, arguments);
282
- };
957
+
958
+ // before delegating to the inner date instance clear the cached date parts
959
+ ["setUTCDate", "setUTCFullYear", "setUTCHours", "setUTCMilliseconds", "setUTCMinutes", "setUTCMonth", "setUTCSeconds"].forEach(function (sMethod) {
960
+ UI5Date.prototype[sMethod] = function () {
961
+ this.oDateParts = undefined;
962
+ return this.oDate[sMethod].apply(this.oDate, arguments);
963
+ };
283
964
  });
965
+
966
+ /**
967
+ * Creates a JavaScript Date instance.
968
+ *
969
+ * @param {object} vParts
970
+ * The <code>arguments</code> object which is given to
971
+ * <code>module:sap/ui/core/date/UI5Date.getInstance</code>
972
+ * @returns {Date}
973
+ * A JavaScript Date instance
974
+ *
975
+ * @private
976
+ */
284
977
  UI5Date._createDateInstance = function (vParts) {
285
- if (vParts[0] instanceof Date) {
286
- vParts[0] = vParts[0].valueOf();
287
- }
288
- return new (Function.prototype.bind.apply(Date, [].concat.apply([null], vParts)))();
978
+ if (vParts[0] instanceof Date) {
979
+ vParts[0] = vParts[0].valueOf();
980
+ }
981
+
982
+ // ES5 variant of new Date(...vParts)
983
+ return new (Function.prototype.bind.apply(Date, [].concat.apply([null], vParts)))();
289
984
  };
985
+
986
+ /**
987
+ * Creates a date instance (either JavaScript Date or <code>UI5Date</code>) which considers the
988
+ * configured time zone wherever JavaScript Date uses the local browser time zone, for example
989
+ * in <code>getDate</code>, <code>toString</code>, or <code>setHours</code>. The supported
990
+ * parameters are the same as the ones supported by the JavaScript Date constructor.
991
+ *
992
+ * <b>Note:</b> Adjusting the time zone in a running application can lead to unexpected data
993
+ * inconsistencies. For more information, see
994
+ * {@link module:sap/base/i18n/Localization.setTimezone Localization.setTimezone}.
995
+ *
996
+ * @param {int|string|Date|module:sap/ui/core/date/UI5Date|null} [vYearOrValue]
997
+ * Same meaning as in the JavaScript Date constructor
998
+ * @param {int|string} [vMonthIndex]
999
+ * Same meaning as in the JavaScript Date constructor
1000
+ * @param {int|string} [vDay=1] Same meaning as in the JavaScript Date constructor
1001
+ * @param {int|string} [vHours=0] Same meaning as in the JavaScript Date constructor
1002
+ * @param {int|string} [vMinutes=0] Same meaning as in the JavaScript Date constructor
1003
+ * @param {int|string} [vSeconds=0] Same meaning as in the JavaScript Date constructor
1004
+ * @param {int|string} [vMilliseconds=0] Same meaning as in the JavaScript Date constructor
1005
+ * @returns {Date|module:sap/ui/core/date/UI5Date}
1006
+ * The date instance that considers the configured time zone in all local getters and setters.
1007
+ *
1008
+ * @public
1009
+ * @see module:sap/base/i18n/Localization.getTimezone
1010
+ */
290
1011
  UI5Date.getInstance = function () {
291
- var sTimezone = Configuration.getTimezone();
292
- if (sTimezone !== TimezoneUtil.getLocalTimezone()) {
293
- return new UI5Date(arguments, sTimezone);
294
- }
295
- return UI5Date._createDateInstance(arguments);
1012
+ var sTimezone = Localization.getTimezone();
1013
+ if (sTimezone !== TimezoneUtils.getLocalTimezone()) {
1014
+ return new UI5Date(arguments, sTimezone);
1015
+ }
1016
+ // time zones are equal -> use JavaScript Date as it is
1017
+ return UI5Date._createDateInstance(arguments);
296
1018
  };
1019
+
1020
+ /**
1021
+ * Checks whether the given date object is a valid date, considers the configured time zone
1022
+ * and throws an error otherwise.
1023
+ *
1024
+ * @param {Date|module:sap/ui/core/date/UI5Date} oDate
1025
+ * The date object created via <code>UI5Date.getInstance</code>
1026
+ * @throws {Error}
1027
+ * If the given date object is not valid or does not consider the configured time zone
1028
+ *
1029
+ * @private
1030
+ */
297
1031
  UI5Date.checkDate = function (oDate) {
298
- if (isNaN(oDate.getTime())) {
299
- throw new Error('The given Date is not valid');
300
- }
301
- if (!(oDate instanceof UI5Date) && Configuration.getTimezone() !== TimezoneUtil.getLocalTimezone()) {
302
- throw new Error('Configured time zone requires the parameter \'oDate\' to be an instance of' + ' sap.ui.core.date.UI5Date');
303
- }
1032
+ if (isNaN(oDate.getTime())) {
1033
+ throw new Error("The given Date is not valid");
1034
+ }
1035
+ if (!(oDate instanceof UI5Date) && Localization.getTimezone() !== TimezoneUtils.getLocalTimezone()) {
1036
+ throw new Error("Configured time zone requires the parameter 'oDate' to be an instance of" + " sap.ui.core.date.UI5Date");
1037
+ }
304
1038
  };
305
1039
  export default UI5Date;