@ui5/webcomponents-localization 1.22.0-rc.0 → 1.22.0-rc.2

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