@ui5/webcomponents-localization 0.0.0-0fcda382e → 0.0.0-10f3c0dc7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +2 -0
- package/.npsrc.json +3 -0
- package/CHANGELOG.md +2427 -0
- package/LICENSE.txt +201 -0
- package/README.md +38 -10
- package/dist/.tsbuildinfo +1 -0
- package/dist/Assets-fetch.d.ts +1 -0
- package/dist/Assets-fetch.js +3 -0
- package/dist/Assets-fetch.js.map +1 -0
- package/dist/Assets-node.d.ts +11 -0
- package/dist/Assets-node.js +12 -0
- package/dist/Assets-node.js.map +1 -0
- package/dist/Assets.d.ts +1 -0
- package/dist/Assets.js +1 -0
- package/dist/Assets.js.map +1 -0
- package/dist/CalendarUtils.d.ts +3 -0
- package/dist/CalendarUtils.js +6 -0
- package/dist/CalendarUtils.js.map +1 -0
- package/dist/DateFormat.d.ts +28 -0
- package/dist/DateFormat.js +22 -2
- package/dist/DateFormat.js.map +1 -0
- package/dist/Locale.d.ts +5 -0
- package/dist/Locale.js +7 -0
- package/dist/Locale.js.map +1 -0
- package/dist/LocaleData.d.ts +5 -0
- package/dist/LocaleData.js +6 -2
- package/dist/LocaleData.js.map +1 -0
- package/dist/NumberFormat.d.ts +5 -0
- package/dist/NumberFormat.js +7 -0
- package/dist/NumberFormat.js.map +1 -0
- package/dist/dates/CalendarDate.d.ts +42 -0
- package/dist/dates/CalendarDate.js +171 -181
- package/dist/dates/CalendarDate.js.map +1 -0
- package/dist/dates/ExtremeDates.d.ts +5 -0
- package/dist/dates/ExtremeDates.js +29 -0
- package/dist/dates/ExtremeDates.js.map +1 -0
- package/dist/dates/UI5Date.d.ts +5 -0
- package/dist/dates/UI5Date.js +7 -0
- package/dist/dates/UI5Date.js.map +1 -0
- package/dist/dates/UniversalDate.d.ts +47 -0
- package/dist/dates/UniversalDate.js +5 -0
- package/dist/dates/UniversalDate.js.map +1 -0
- package/dist/dates/convertMonthNumbersToMonthNames.d.ts +16 -0
- package/dist/dates/convertMonthNumbersToMonthNames.js +30 -0
- package/dist/dates/convertMonthNumbersToMonthNames.js.map +1 -0
- package/dist/dates/getDaysInMonth.d.ts +3 -0
- package/dist/dates/getDaysInMonth.js +10 -0
- package/dist/dates/getDaysInMonth.js.map +1 -0
- package/dist/dates/getRoundedTimestamp.d.ts +7 -0
- package/dist/dates/getRoundedTimestamp.js +15 -0
- package/dist/dates/getRoundedTimestamp.js.map +1 -0
- package/dist/dates/getTodayUTCTimestamp.d.ts +7 -0
- package/dist/dates/getTodayUTCTimestamp.js +9 -0
- package/dist/dates/getTodayUTCTimestamp.js.map +1 -0
- package/dist/dates/modifyDateBy.d.ts +14 -0
- package/dist/dates/modifyDateBy.js +55 -0
- package/dist/dates/modifyDateBy.js.map +1 -0
- package/dist/dates/transformDateToSecondaryType.d.ts +7 -0
- package/dist/dates/transformDateToSecondaryType.js +18 -0
- package/dist/dates/transformDateToSecondaryType.js.map +1 -0
- package/dist/features/calendar/Buddhist.js +1 -0
- package/dist/features/calendar/Buddhist.js.map +1 -0
- package/dist/features/calendar/Gregorian.js +1 -0
- package/dist/features/calendar/Gregorian.js.map +1 -0
- package/dist/features/calendar/Islamic.js +1 -0
- package/dist/features/calendar/Islamic.js.map +1 -0
- package/dist/features/calendar/Japanese.js +1 -0
- package/dist/features/calendar/Japanese.js.map +1 -0
- package/dist/features/calendar/Persian.js +1 -0
- package/dist/features/calendar/Persian.js.map +1 -0
- package/dist/generated/assets/cldr/Unicode-Data-Files-LICENSE.txt +39 -0
- package/dist/generated/assets/cldr/ar.json +2179 -728
- package/dist/generated/assets/cldr/ar_EG.json +2179 -728
- package/dist/generated/assets/cldr/ar_SA.json +2275 -825
- package/dist/generated/assets/cldr/bg.json +1924 -798
- package/dist/generated/assets/cldr/ca.json +2027 -816
- package/dist/generated/assets/cldr/cnr.json +6476 -0
- package/dist/generated/assets/cldr/cs.json +1865 -842
- package/dist/generated/assets/cldr/cy.json +6566 -0
- package/dist/generated/assets/cldr/da.json +1844 -682
- package/dist/generated/assets/cldr/de.json +1806 -546
- package/dist/generated/assets/cldr/de_AT.json +1797 -537
- package/dist/generated/assets/cldr/de_CH.json +1879 -611
- package/dist/generated/assets/cldr/el.json +1497 -383
- package/dist/generated/assets/cldr/el_CY.json +1497 -383
- package/dist/generated/assets/cldr/en.json +1990 -563
- package/dist/generated/assets/cldr/en_AU.json +2339 -763
- package/dist/generated/assets/cldr/en_GB.json +2170 -621
- package/dist/generated/assets/cldr/en_HK.json +2076 -628
- package/dist/generated/assets/cldr/en_IE.json +2038 -593
- package/dist/generated/assets/cldr/en_IN.json +2336 -704
- package/dist/generated/assets/cldr/en_NZ.json +2056 -611
- package/dist/generated/assets/cldr/en_PG.json +2049 -604
- package/dist/generated/assets/cldr/en_SG.json +2041 -593
- package/dist/generated/assets/cldr/en_ZA.json +2046 -599
- package/dist/generated/assets/cldr/es.json +2197 -881
- package/dist/generated/assets/cldr/es_AR.json +2167 -819
- package/dist/generated/assets/cldr/es_BO.json +2210 -863
- package/dist/generated/assets/cldr/es_CL.json +2087 -848
- package/dist/generated/assets/cldr/es_CO.json +1947 -707
- package/dist/generated/assets/cldr/es_MX.json +2446 -1091
- package/dist/generated/assets/cldr/es_PE.json +1912 -773
- package/dist/generated/assets/cldr/es_UY.json +1926 -795
- package/dist/generated/assets/cldr/es_VE.json +1920 -789
- package/dist/generated/assets/cldr/et.json +1761 -544
- package/dist/generated/assets/cldr/fa.json +1872 -566
- package/dist/generated/assets/cldr/fi.json +1959 -526
- package/dist/generated/assets/cldr/fr.json +1711 -460
- package/dist/generated/assets/cldr/fr_BE.json +1710 -459
- package/dist/generated/assets/cldr/fr_CA.json +2087 -814
- package/dist/generated/assets/cldr/fr_CH.json +1669 -418
- package/dist/generated/assets/cldr/fr_LU.json +1711 -460
- package/dist/generated/assets/cldr/he.json +2018 -1033
- package/dist/generated/assets/cldr/hi.json +1619 -348
- package/dist/generated/assets/cldr/hr.json +1855 -569
- package/dist/generated/assets/cldr/hu.json +1764 -551
- package/dist/generated/assets/cldr/id.json +1924 -601
- package/dist/generated/assets/cldr/it.json +1821 -666
- package/dist/generated/assets/cldr/it_CH.json +1827 -672
- package/dist/generated/assets/cldr/ja.json +1426 -109
- package/dist/generated/assets/cldr/kk.json +2251 -737
- package/dist/generated/assets/cldr/ko.json +1484 -196
- package/dist/generated/assets/cldr/lt.json +1714 -734
- package/dist/generated/assets/cldr/lv.json +1686 -682
- package/dist/generated/assets/cldr/mk.json +6177 -0
- package/dist/generated/assets/cldr/ms.json +1903 -595
- package/dist/generated/assets/cldr/nb.json +1548 -369
- package/dist/generated/assets/cldr/nl.json +1935 -511
- package/dist/generated/assets/cldr/nl_BE.json +1955 -531
- package/dist/generated/assets/cldr/pl.json +1873 -586
- package/dist/generated/assets/cldr/pt.json +2184 -753
- package/dist/generated/assets/cldr/pt_PT.json +2149 -778
- package/dist/generated/assets/cldr/ro.json +1847 -765
- package/dist/generated/assets/cldr/ru.json +2082 -755
- package/dist/generated/assets/cldr/ru_UA.json +2076 -749
- package/dist/generated/assets/cldr/sk.json +1860 -972
- package/dist/generated/assets/cldr/sl.json +1861 -920
- package/dist/generated/assets/cldr/sr.json +1829 -767
- package/dist/generated/assets/cldr/sr_Latn.json +6173 -0
- package/dist/generated/assets/cldr/sv.json +1789 -587
- package/dist/generated/assets/cldr/th.json +1704 -373
- package/dist/generated/assets/cldr/tr.json +1855 -587
- package/dist/generated/assets/cldr/uk.json +2166 -711
- package/dist/generated/assets/cldr/vi.json +2054 -709
- package/dist/generated/assets/cldr/zh_CN.json +1736 -397
- package/dist/generated/assets/cldr/zh_HK.json +1713 -374
- package/dist/generated/assets/cldr/zh_SG.json +1723 -384
- package/dist/generated/assets/cldr/zh_TW.json +1678 -371
- package/dist/generated/json-imports/LocaleData-fetch.d.ts +1 -0
- package/dist/generated/json-imports/LocaleData-fetch.js +93 -0
- package/dist/generated/json-imports/LocaleData-fetch.js.map +1 -0
- package/dist/generated/json-imports/LocaleData-node.d.ts +1 -0
- package/dist/generated/json-imports/LocaleData-node.js +93 -0
- package/dist/generated/json-imports/LocaleData-node.js.map +1 -0
- package/dist/generated/json-imports/LocaleData.d.ts +1 -0
- package/dist/generated/json-imports/LocaleData.js +92 -95
- package/dist/generated/json-imports/LocaleData.js.map +1 -0
- package/dist/getCachedLocaleDataInstance.d.ts +4 -0
- package/dist/getCachedLocaleDataInstance.js +12 -0
- package/dist/getCachedLocaleDataInstance.js.map +1 -0
- package/dist/locale/getLocaleData.d.ts +11 -0
- package/dist/locale/getLocaleData.js +15 -17
- package/dist/locale/getLocaleData.js.map +1 -0
- package/dist/sap/base/Event.js +59 -0
- package/dist/sap/base/Eventing.js +147 -0
- package/dist/sap/base/Log.js +2 -248
- package/dist/sap/base/assert.js +31 -9
- package/dist/sap/base/config/MemoryConfigurationProvider.js +20 -0
- package/dist/sap/base/config.js +17 -0
- package/dist/sap/base/future.js +12 -0
- package/dist/sap/base/i18n/Formatting.d.ts +13 -0
- package/dist/sap/base/i18n/Formatting.js +18 -0
- package/dist/sap/base/i18n/Formatting.js.map +1 -0
- package/dist/sap/base/i18n/LanguageTag.js +179 -0
- package/dist/sap/base/i18n/Localization.d.ts +7 -0
- package/dist/sap/base/i18n/Localization.js +17 -0
- package/dist/sap/base/i18n/Localization.js.map +1 -0
- package/dist/sap/base/i18n/ResourceBundle.js +20 -0
- package/dist/sap/base/i18n/date/CalendarType.js +44 -0
- package/dist/sap/base/i18n/date/CalendarWeekNumbering.js +106 -0
- package/dist/sap/base/i18n/date/TimezoneUtils.js +471 -0
- package/dist/sap/base/i18n/date/_EnumHelper.js +37 -0
- package/dist/sap/base/strings/camelize.js +30 -0
- package/dist/sap/base/strings/formatMessage.js +93 -15
- package/dist/sap/base/util/LoaderExtensions.d.ts +4 -0
- package/dist/sap/base/util/LoaderExtensions.js +11 -4
- package/dist/sap/base/util/LoaderExtensions.js.map +1 -0
- package/dist/sap/base/util/ObjectPath.d.ts +4 -0
- package/dist/sap/base/util/ObjectPath.js +4 -33
- package/dist/sap/base/util/ObjectPath.js.map +1 -0
- package/dist/sap/base/util/Properties.js +12 -0
- package/dist/sap/base/util/Version.js +163 -0
- package/dist/sap/base/util/_merge.js +83 -26
- package/dist/sap/base/util/array/uniqueSort.js +37 -15
- package/dist/sap/base/util/deepClone.js +102 -0
- package/dist/sap/base/util/deepEqual.js +75 -55
- package/dist/sap/base/util/deepExtend.js +60 -0
- package/dist/sap/base/util/extend.js +58 -7
- package/dist/sap/base/util/fetch.js +8 -0
- package/dist/sap/base/util/isEmptyObject.js +34 -0
- package/dist/sap/base/util/isPlainObject.js +35 -1
- package/dist/sap/base/util/merge.js +57 -0
- package/dist/sap/base/util/mixedFetch.js +3 -0
- package/dist/sap/base/util/now.js +22 -7
- package/dist/sap/base/util/resolveReference.js +3 -0
- package/dist/sap/base/util/uid.js +27 -0
- package/dist/sap/ui/Device.js +25 -3
- package/dist/sap/ui/Global.js +1 -0
- package/dist/sap/ui/VersionInfo.js +14 -0
- package/dist/sap/ui/base/DataType.js +708 -0
- package/dist/sap/ui/base/DesignTime.js +11 -0
- package/dist/sap/ui/base/EventProvider.js +21 -0
- package/dist/sap/ui/base/Interface.js +50 -6
- package/dist/sap/ui/base/Metadata.js +470 -173
- package/dist/sap/ui/base/Object.js +287 -27
- package/dist/sap/ui/base/OwnStatics.js +6 -0
- package/dist/sap/ui/base/SyncPromise.js +98 -0
- package/dist/sap/ui/core/AnimationMode.js +42 -0
- package/dist/sap/ui/core/CalendarType.js +24 -8
- package/dist/sap/ui/core/Configuration.d.ts +17 -0
- package/dist/sap/ui/core/Configuration.js +23 -0
- package/dist/sap/ui/core/Configuration.js.map +1 -0
- package/dist/sap/ui/core/ControlBehavior.js +11 -0
- package/dist/sap/ui/core/Core.d.ts +25 -0
- package/dist/sap/ui/core/Core.js +7 -32
- package/dist/sap/ui/core/Core.js.map +1 -0
- package/dist/sap/ui/core/FormatSettings.d.ts +9 -0
- package/dist/sap/ui/core/FormatSettings.js +12 -0
- package/dist/sap/ui/core/FormatSettings.js.map +1 -0
- package/dist/sap/ui/core/Lib.js +41 -0
- package/dist/sap/ui/core/Locale.js +190 -116
- package/dist/sap/ui/core/LocaleData.js +2837 -2683
- package/dist/sap/ui/core/Supportability.js +5 -0
- package/dist/sap/ui/core/Theming.js +39 -0
- package/dist/sap/ui/core/_UrlResolver.js +11 -0
- package/dist/sap/ui/core/date/Buddhist.js +162 -93
- package/dist/sap/ui/core/date/CalendarUtils.js +67 -0
- package/dist/sap/ui/core/date/CalendarWeekNumbering.js +30 -0
- package/dist/sap/ui/core/date/Gregorian.js +25 -10
- package/dist/sap/ui/core/date/Islamic.js +298 -185
- package/dist/sap/ui/core/date/Japanese.js +212 -117
- package/dist/sap/ui/core/date/Persian.js +324 -195
- package/dist/sap/ui/core/date/UI5Date.js +1039 -0
- package/dist/sap/ui/core/date/UniversalDate.js +1241 -217
- package/dist/sap/ui/core/date/_Calendars.js +10 -1
- package/dist/sap/ui/core/format/DateFormat.js +3160 -1781
- package/dist/sap/ui/core/format/FormatUtils.js +30 -0
- package/dist/sap/ui/core/format/NumberFormat.js +3164 -0
- package/dist/sap/ui/core/format/TimezoneUtil.js +93 -0
- package/dist/sap/ui/core/getCompatibilityVersion.js +7 -0
- package/dist/sap/ui/core/theming/ThemeHelper.js +14 -0
- package/dist/sap/ui/security/Security.js +12 -0
- package/dist/sap/ui/util/XMLHelper.js +11 -0
- package/dist/sap/ui/util/_URL.js +1 -0
- package/dist/ui5loader-autoconfig.js +1 -0
- package/package-scripts.cjs +35 -0
- package/package.json +27 -21
- package/tsconfig.json +24 -0
- package/used-modules.txt +33 -1
- package/dist/dates/calculateWeekNumber.js +0 -51
- package/package-scripts.js +0 -31
- package/src/Assets.js +0 -2
- package/src/DateFormat.js +0 -3
- package/src/LocaleData.js +0 -3
- package/src/dates/CalendarDate.js +0 -203
- package/src/dates/calculateWeekNumber.js +0 -51
- package/src/locale/getLocaleData.js +0 -27
- package/src/sap/base/util/LoaderExtensions.js +0 -7
- package/src/sap/ui/core/Core.js +0 -38
- /package/{config/.eslintrc.js → .eslintrc.cjs} +0 -0
- /package/{src/features/calendar/Buddhist.js → dist/features/calendar/Buddhist.d.ts} +0 -0
- /package/{src/features/calendar/Gregorian.js → dist/features/calendar/Gregorian.d.ts} +0 -0
- /package/{src/features/calendar/Islamic.js → dist/features/calendar/Islamic.d.ts} +0 -0
- /package/{src/features/calendar/Japanese.js → dist/features/calendar/Japanese.d.ts} +0 -0
- /package/{src/features/calendar/Persian.js → dist/features/calendar/Persian.d.ts} +0 -0
|
@@ -0,0 +1,1039 @@
|
|
|
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
|
+
*/
|
|
38
|
+
function addLeadingZeros(iValue, iLength) {
|
|
39
|
+
return (iValue < 0 ? "-" : "") + Math.abs(iValue).toString().padStart(iLength, "0");
|
|
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
|
+
*/
|
|
74
|
+
function UI5Date(vDateParts, sTimezoneID) {
|
|
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
|
|
88
|
+
}
|
|
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
|
+
}
|
|
131
|
+
}
|
|
132
|
+
this._setParts(aAllParts, aLocalDateParts);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
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
|
+
*/
|
|
153
|
+
UI5Date.prototype._getPart = function (sPart) {
|
|
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;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return iResult;
|
|
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
|
+
*/
|
|
187
|
+
UI5Date.prototype._setParts = function (aParts, aValues) {
|
|
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);
|
|
206
|
+
}
|
|
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
|
+
}
|
|
216
|
+
}
|
|
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);
|
|
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
|
+
*/
|
|
252
|
+
UI5Date.prototype.clone = function () {
|
|
253
|
+
return UI5Date.getInstance(this);
|
|
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
|
+
*/
|
|
266
|
+
UI5Date.prototype.getDate = function () {
|
|
267
|
+
return this._getPart("day");
|
|
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
|
+
*/
|
|
280
|
+
UI5Date.prototype.getDay = function () {
|
|
281
|
+
return this._getPart("weekday");
|
|
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
|
+
*/
|
|
292
|
+
UI5Date.prototype.getFullYear = function () {
|
|
293
|
+
return this._getPart("year");
|
|
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
|
+
*/
|
|
306
|
+
UI5Date.prototype.getHours = function () {
|
|
307
|
+
return this._getPart("hour");
|
|
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
|
+
*/
|
|
320
|
+
UI5Date.prototype.getMilliseconds = function () {
|
|
321
|
+
return this._getPart("fractionalSecond");
|
|
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
|
+
*/
|
|
334
|
+
UI5Date.prototype.getMinutes = function () {
|
|
335
|
+
return this._getPart("minute");
|
|
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
|
+
*/
|
|
348
|
+
UI5Date.prototype.getMonth = function () {
|
|
349
|
+
return this._getPart("month");
|
|
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
|
+
*/
|
|
362
|
+
UI5Date.prototype.getSeconds = function () {
|
|
363
|
+
return this._getPart("second");
|
|
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
|
+
*/
|
|
375
|
+
UI5Date.prototype.getTimezoneOffset = function () {
|
|
376
|
+
return TimezoneUtils.calculateOffset(this.oDate, this.sTimezoneID) / 60;
|
|
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
|
+
*/
|
|
390
|
+
UI5Date.prototype.getYear = function () {
|
|
391
|
+
return this._getPart("year") - 1900;
|
|
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
|
+
*/
|
|
406
|
+
UI5Date.prototype.setDate = function (iDay) {
|
|
407
|
+
return this._setParts(["day"], arguments);
|
|
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
|
+
*/
|
|
423
|
+
UI5Date.prototype.setFullYear = function (iYear, iMonth, iDay) {
|
|
424
|
+
return this._setParts(["year", "month", "day"], arguments);
|
|
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
|
+
*/
|
|
441
|
+
UI5Date.prototype.setHours = function (iHours, iMinutes, iSeconds, iMilliseconds) {
|
|
442
|
+
return this._setParts(["hour", "minute", "second", "fractionalSecond"], arguments);
|
|
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
|
+
*/
|
|
456
|
+
UI5Date.prototype.setMilliseconds = function (iMilliseconds) {
|
|
457
|
+
return this._setParts(["fractionalSecond"], arguments);
|
|
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
|
+
*/
|
|
473
|
+
UI5Date.prototype.setMinutes = function (iMinutes, iSeconds, iMilliseconds) {
|
|
474
|
+
return this._setParts(["minute", "second", "fractionalSecond"], arguments);
|
|
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
|
+
*/
|
|
489
|
+
UI5Date.prototype.setMonth = function (iMonth, iDay) {
|
|
490
|
+
return this._setParts(["month", "day"], arguments);
|
|
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
|
+
*/
|
|
505
|
+
UI5Date.prototype.setSeconds = function (iSeconds, iMilliseconds) {
|
|
506
|
+
return this._setParts(["second", "fractionalSecond"], arguments);
|
|
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
|
+
*/
|
|
521
|
+
UI5Date.prototype.setTime = function (iTime) {
|
|
522
|
+
this.oDateParts = undefined;
|
|
523
|
+
return this.oDate.setTime(iTime);
|
|
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
|
+
*/
|
|
541
|
+
UI5Date.prototype.setYear = function (iYear) {
|
|
542
|
+
var iValue = parseInt(iYear);
|
|
543
|
+
iValue = iValue < 0 || iValue > 99 ? iValue : iValue + 1900;
|
|
544
|
+
return this._setParts(["year"], [iValue]);
|
|
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
|
+
*/
|
|
813
|
+
UI5Date.prototype.toDateString = function () {
|
|
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);
|
|
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
|
+
*/
|
|
893
|
+
UI5Date.prototype.toString = function () {
|
|
894
|
+
if (isNaN(this.oDate)) {
|
|
895
|
+
return this.oDate.toString();
|
|
896
|
+
}
|
|
897
|
+
return this.toDateString() + " " + this.toTimeString();
|
|
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
|
+
*/
|
|
908
|
+
UI5Date.prototype.toTimeString = function () {
|
|
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);
|
|
920
|
+
};
|
|
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
|
+
};
|
|
949
|
+
});
|
|
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
|
+
};
|
|
956
|
+
});
|
|
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
|
+
};
|
|
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
|
+
*/
|
|
977
|
+
UI5Date._createDateInstance = function (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)))();
|
|
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
|
+
*/
|
|
1011
|
+
UI5Date.getInstance = function () {
|
|
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);
|
|
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
|
+
*/
|
|
1031
|
+
UI5Date.checkDate = function (oDate) {
|
|
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
|
+
}
|
|
1038
|
+
};
|
|
1039
|
+
export default UI5Date;
|