@ui5/webcomponents-localization 0.0.0-037d08c67
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 +6 -0
- package/.eslintrc.cjs +3 -0
- package/.npsrc.json +3 -0
- package/CHANGELOG.md +2261 -0
- package/LICENSE.txt +201 -0
- package/README.md +51 -0
- 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 +3 -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 +5 -0
- package/dist/DateFormat.js +7 -0
- package/dist/DateFormat.js.map +1 -0
- package/dist/LocaleData.d.ts +5 -0
- package/dist/LocaleData.js +7 -0
- 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 +193 -0
- 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.d.ts +1 -0
- package/dist/features/calendar/Buddhist.js +2 -0
- package/dist/features/calendar/Buddhist.js.map +1 -0
- package/dist/features/calendar/Gregorian.d.ts +1 -0
- package/dist/features/calendar/Gregorian.js +2 -0
- package/dist/features/calendar/Gregorian.js.map +1 -0
- package/dist/features/calendar/Islamic.d.ts +1 -0
- package/dist/features/calendar/Islamic.js +2 -0
- package/dist/features/calendar/Islamic.js.map +1 -0
- package/dist/features/calendar/Japanese.d.ts +1 -0
- package/dist/features/calendar/Japanese.js +2 -0
- package/dist/features/calendar/Japanese.js.map +1 -0
- package/dist/features/calendar/Persian.d.ts +1 -0
- package/dist/features/calendar/Persian.js +2 -0
- package/dist/features/calendar/Persian.js.map +1 -0
- package/dist/generated/assets/cldr/Unicode-Data-Files-LICENSE.txt +27 -0
- package/dist/generated/assets/cldr/ar.json +7087 -0
- package/dist/generated/assets/cldr/ar_EG.json +7087 -0
- package/dist/generated/assets/cldr/ar_SA.json +7086 -0
- package/dist/generated/assets/cldr/bg.json +5981 -0
- package/dist/generated/assets/cldr/ca.json +6083 -0
- package/dist/generated/assets/cldr/cnr.json +6169 -0
- package/dist/generated/assets/cldr/cs.json +6709 -0
- package/dist/generated/assets/cldr/cy.json +6932 -0
- package/dist/generated/assets/cldr/da.json +5927 -0
- package/dist/generated/assets/cldr/de.json +6048 -0
- package/dist/generated/assets/cldr/de_AT.json +6049 -0
- package/dist/generated/assets/cldr/de_CH.json +6047 -0
- package/dist/generated/assets/cldr/el.json +5832 -0
- package/dist/generated/assets/cldr/el_CY.json +5832 -0
- package/dist/generated/assets/cldr/en.json +6044 -0
- package/dist/generated/assets/cldr/en_AU.json +6084 -0
- package/dist/generated/assets/cldr/en_GB.json +6075 -0
- package/dist/generated/assets/cldr/en_HK.json +6084 -0
- package/dist/generated/assets/cldr/en_IE.json +6075 -0
- package/dist/generated/assets/cldr/en_IN.json +6080 -0
- package/dist/generated/assets/cldr/en_NZ.json +6075 -0
- package/dist/generated/assets/cldr/en_PG.json +6076 -0
- package/dist/generated/assets/cldr/en_SG.json +6080 -0
- package/dist/generated/assets/cldr/en_ZA.json +6076 -0
- package/dist/generated/assets/cldr/es.json +6103 -0
- package/dist/generated/assets/cldr/es_AR.json +6106 -0
- package/dist/generated/assets/cldr/es_BO.json +6105 -0
- package/dist/generated/assets/cldr/es_CL.json +5998 -0
- package/dist/generated/assets/cldr/es_CO.json +5998 -0
- package/dist/generated/assets/cldr/es_MX.json +6107 -0
- package/dist/generated/assets/cldr/es_PE.json +5889 -0
- package/dist/generated/assets/cldr/es_UY.json +5891 -0
- package/dist/generated/assets/cldr/es_VE.json +5890 -0
- package/dist/generated/assets/cldr/et.json +6027 -0
- package/dist/generated/assets/cldr/fa.json +5950 -0
- package/dist/generated/assets/cldr/fi.json +6195 -0
- package/dist/generated/assets/cldr/fr.json +5997 -0
- package/dist/generated/assets/cldr/fr_BE.json +5997 -0
- package/dist/generated/assets/cldr/fr_CA.json +5991 -0
- package/dist/generated/assets/cldr/fr_CH.json +6015 -0
- package/dist/generated/assets/cldr/fr_LU.json +5997 -0
- package/dist/generated/assets/cldr/he.json +6541 -0
- package/dist/generated/assets/cldr/hi.json +5859 -0
- package/dist/generated/assets/cldr/hr.json +6196 -0
- package/dist/generated/assets/cldr/hu.json +5945 -0
- package/dist/generated/assets/cldr/id.json +5730 -0
- package/dist/generated/assets/cldr/it.json +5986 -0
- package/dist/generated/assets/cldr/it_CH.json +5986 -0
- package/dist/generated/assets/cldr/ja.json +5889 -0
- package/dist/generated/assets/cldr/kk.json +5939 -0
- package/dist/generated/assets/cldr/ko.json +5770 -0
- package/dist/generated/assets/cldr/lt.json +6578 -0
- package/dist/generated/assets/cldr/lv.json +6114 -0
- package/dist/generated/assets/cldr/mk.json +6045 -0
- package/dist/generated/assets/cldr/ms.json +5564 -0
- package/dist/generated/assets/cldr/nb.json +6035 -0
- package/dist/generated/assets/cldr/nl.json +6202 -0
- package/dist/generated/assets/cldr/nl_BE.json +6202 -0
- package/dist/generated/assets/cldr/pl.json +6589 -0
- package/dist/generated/assets/cldr/pt.json +6115 -0
- package/dist/generated/assets/cldr/pt_PT.json +6180 -0
- package/dist/generated/assets/cldr/ro.json +6200 -0
- package/dist/generated/assets/cldr/ru.json +6503 -0
- package/dist/generated/assets/cldr/ru_UA.json +6503 -0
- package/dist/generated/assets/cldr/sk.json +6432 -0
- package/dist/generated/assets/cldr/sl.json +6444 -0
- package/dist/generated/assets/cldr/sr.json +6241 -0
- package/dist/generated/assets/cldr/sr_Latn.json +6226 -0
- package/dist/generated/assets/cldr/sv.json +6076 -0
- package/dist/generated/assets/cldr/th.json +5875 -0
- package/dist/generated/assets/cldr/tr.json +6094 -0
- package/dist/generated/assets/cldr/uk.json +6454 -0
- package/dist/generated/assets/cldr/vi.json +5669 -0
- package/dist/generated/assets/cldr/zh_CN.json +5717 -0
- package/dist/generated/assets/cldr/zh_HK.json +5726 -0
- package/dist/generated/assets/cldr/zh_SG.json +5726 -0
- package/dist/generated/assets/cldr/zh_TW.json +5793 -0
- 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 +93 -0
- package/dist/generated/json-imports/LocaleData.js.map +1 -0
- package/dist/getCachedLocaleDataInstance.d.ts +4 -0
- package/dist/getCachedLocaleDataInstance.js +10 -0
- package/dist/getCachedLocaleDataInstance.js.map +1 -0
- package/dist/locale/getLocaleData.d.ts +11 -0
- package/dist/locale/getLocaleData.js +23 -0
- package/dist/locale/getLocaleData.js.map +1 -0
- package/dist/sap/base/Event.js +59 -0
- package/dist/sap/base/Eventing.js +146 -0
- package/dist/sap/base/Log.js +3 -0
- package/dist/sap/base/assert.js +34 -0
- package/dist/sap/base/config/MemoryConfigurationProvider.js +20 -0
- package/dist/sap/base/config.js +17 -0
- package/dist/sap/base/i18n/Formatting.d.ts +8 -0
- package/dist/sap/base/i18n/Formatting.js +11 -0
- package/dist/sap/base/i18n/Formatting.js.map +1 -0
- package/dist/sap/base/i18n/LanguageTag.js +173 -0
- package/dist/sap/base/i18n/Localization.d.ts +4 -0
- package/dist/sap/base/i18n/Localization.js +12 -0
- package/dist/sap/base/i18n/Localization.js.map +1 -0
- package/dist/sap/base/i18n/date/CalendarType.js +43 -0
- package/dist/sap/base/i18n/date/CalendarWeekNumbering.js +105 -0
- package/dist/sap/base/i18n/date/TimezoneUtils.js +319 -0
- package/dist/sap/base/strings/camelize.js +30 -0
- package/dist/sap/base/strings/formatMessage.js +93 -0
- package/dist/sap/base/util/LoaderExtensions.d.ts +4 -0
- package/dist/sap/base/util/LoaderExtensions.js +14 -0
- 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 +6 -0
- package/dist/sap/base/util/ObjectPath.js.map +1 -0
- package/dist/sap/base/util/Version.js +157 -0
- package/dist/sap/base/util/_merge.js +89 -0
- package/dist/sap/base/util/array/uniqueSort.js +41 -0
- package/dist/sap/base/util/deepClone.js +102 -0
- package/dist/sap/base/util/deepEqual.js +83 -0
- package/dist/sap/base/util/extend.js +61 -0
- package/dist/sap/base/util/isEmptyObject.js +34 -0
- package/dist/sap/base/util/isPlainObject.js +52 -0
- package/dist/sap/base/util/now.js +28 -0
- package/dist/sap/base/util/resolveReference.js +3 -0
- package/dist/sap/base/util/uid.js +27 -0
- package/dist/sap/ui/base/DataType.js +657 -0
- package/dist/sap/ui/base/Interface.js +72 -0
- package/dist/sap/ui/base/Metadata.js +483 -0
- package/dist/sap/ui/base/Object.js +300 -0
- package/dist/sap/ui/core/CalendarType.js +24 -0
- 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/Core.d.ts +25 -0
- package/dist/sap/ui/core/Core.js +13 -0
- 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/Locale.js +194 -0
- package/dist/sap/ui/core/LocaleData.js +2717 -0
- package/dist/sap/ui/core/Supportability.js +5 -0
- package/dist/sap/ui/core/Theming.js +539 -0
- package/dist/sap/ui/core/date/Buddhist.js +196 -0
- package/dist/sap/ui/core/date/CalendarUtils.js +65 -0
- package/dist/sap/ui/core/date/CalendarWeekNumbering.js +30 -0
- package/dist/sap/ui/core/date/Gregorian.js +32 -0
- package/dist/sap/ui/core/date/Islamic.js +367 -0
- package/dist/sap/ui/core/date/Japanese.js +257 -0
- package/dist/sap/ui/core/date/Persian.js +394 -0
- package/dist/sap/ui/core/date/UI5Date.js +991 -0
- package/dist/sap/ui/core/date/UniversalDate.js +1324 -0
- package/dist/sap/ui/core/date/_Calendars.js +22 -0
- package/dist/sap/ui/core/format/DateFormat.js +3310 -0
- package/dist/sap/ui/core/format/NumberFormat.js +2835 -0
- package/dist/sap/ui/core/format/TimezoneUtil.js +24 -0
- package/package-scripts.cjs +35 -0
- package/package.json +46 -0
- package/tsconfig.json +24 -0
- package/used-modules.txt +52 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static collection of utility functions to handle time zone related conversions
|
|
3
|
+
*
|
|
4
|
+
* @author SAP SE
|
|
5
|
+
* @version 1.120.17
|
|
6
|
+
* @namespace
|
|
7
|
+
* @alias module:sap/base/i18n/date/TimezoneUtils
|
|
8
|
+
* @private
|
|
9
|
+
* @ui5-restricted sap.ui.core.Configuration, sap/base/i18n/format/DateFormat
|
|
10
|
+
*/ /*!
|
|
11
|
+
* OpenUI5
|
|
12
|
+
* (c) Copyright 2009-2024 SAP SE or an SAP affiliate company.
|
|
13
|
+
* Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
var TimezoneUtils = {};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Cache for the (browser's) local IANA timezone ID
|
|
20
|
+
*
|
|
21
|
+
* @type {string}
|
|
22
|
+
*/
|
|
23
|
+
var sLocalTimezone = "";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Cache for valid time zones provided by <code>Intl.supportedValuesOf("timeZone")</code>
|
|
27
|
+
*
|
|
28
|
+
* @type {Array}
|
|
29
|
+
*/
|
|
30
|
+
var aSupportedTimezoneIDs;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Cache for Intl.DateTimeFormat instances
|
|
34
|
+
*/
|
|
35
|
+
var oIntlDateTimeFormatCache = {
|
|
36
|
+
_oCache: new Map(),
|
|
37
|
+
/**
|
|
38
|
+
* When cache limit is reached, it gets cleared
|
|
39
|
+
*/
|
|
40
|
+
_iCacheLimit: 10,
|
|
41
|
+
/**
|
|
42
|
+
* Creates or gets an instance of Intl.DateTimeFormat.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} sTimezone IANA timezone ID
|
|
45
|
+
* @returns {Intl.DateTimeFormat} Intl.DateTimeFormat instance
|
|
46
|
+
*/
|
|
47
|
+
get: function (sTimezone) {
|
|
48
|
+
var cacheEntry = this._oCache.get(sTimezone);
|
|
49
|
+
if (cacheEntry) {
|
|
50
|
+
return cacheEntry;
|
|
51
|
+
}
|
|
52
|
+
var oOptions = {
|
|
53
|
+
hourCycle: "h23",
|
|
54
|
+
hour: "2-digit",
|
|
55
|
+
minute: "2-digit",
|
|
56
|
+
second: "2-digit",
|
|
57
|
+
fractionalSecondDigits: 3,
|
|
58
|
+
day: "2-digit",
|
|
59
|
+
month: "2-digit",
|
|
60
|
+
year: "numeric",
|
|
61
|
+
timeZone: sTimezone,
|
|
62
|
+
timeZoneName: 'short',
|
|
63
|
+
era: 'narrow',
|
|
64
|
+
weekday: "short"
|
|
65
|
+
};
|
|
66
|
+
var oInstance = new Intl.DateTimeFormat("en-US", oOptions);
|
|
67
|
+
|
|
68
|
+
// only store a limited number of entries in the cache
|
|
69
|
+
if (this._oCache.size === this._iCacheLimit) {
|
|
70
|
+
this._oCache = new Map();
|
|
71
|
+
}
|
|
72
|
+
this._oCache.set(sTimezone, oInstance);
|
|
73
|
+
return oInstance;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Uses the <code>Intl.supportedValuesOf('timeZone')</code> and <code>Intl.DateTimeFormat</code>
|
|
79
|
+
* API to check if the browser can handle the given IANA timezone ID.
|
|
80
|
+
* <code>Intl.supportedValuesOf('timeZone')</code> offers direct access to the list of supported
|
|
81
|
+
* time zones. It is not yet supported by all browsers but if it is supported and the given time
|
|
82
|
+
* zone is in the list it is faster than probing.
|
|
83
|
+
*
|
|
84
|
+
* <code>Intl.supportedValuesOf('timeZone')</code> does not return all IANA timezone IDs which
|
|
85
|
+
* the <code>Intl.DateTimeFormat</code> can handle, e.g. "Japan", "Etc/UTC".
|
|
86
|
+
*
|
|
87
|
+
* @param {string} sTimezone The IANA timezone ID which is checked, e.g <code>"Europe/Berlin"</code>
|
|
88
|
+
* @returns {boolean} Whether the time zone is a valid IANA timezone ID
|
|
89
|
+
* @private
|
|
90
|
+
* @ui5-restricted sap.ui.core.Configuration, sap.ui.core.format.DateFormat
|
|
91
|
+
*/
|
|
92
|
+
TimezoneUtils.isValidTimezone = function (sTimezone) {
|
|
93
|
+
if (!sTimezone) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
if (Intl.supportedValuesOf) {
|
|
97
|
+
try {
|
|
98
|
+
aSupportedTimezoneIDs = aSupportedTimezoneIDs || Intl.supportedValuesOf('timeZone');
|
|
99
|
+
if (aSupportedTimezoneIDs.includes(sTimezone)) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
// although not contained in the supportedValues it still can be valid, therefore continue
|
|
103
|
+
} catch (oError) {
|
|
104
|
+
// ignore error
|
|
105
|
+
aSupportedTimezoneIDs = [];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
oIntlDateTimeFormatCache.get(sTimezone);
|
|
110
|
+
return true;
|
|
111
|
+
} catch (oError) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Converts a date to a specific time zone.
|
|
118
|
+
* The resulting date reflects the given time zone such that the "UTC" Date methods
|
|
119
|
+
* can be used, e.g. Date#getUTCHours() to display the hours in the given time zone.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* var oDate = new Date("2021-10-13T15:22:33Z"); // UTC
|
|
123
|
+
* // time zone difference UTC-4 (DST)
|
|
124
|
+
* TimezoneUtils.convertToTimezone(oDate, "America/New_York");
|
|
125
|
+
* // result is:
|
|
126
|
+
* // 2021-10-13 11:22:33 in America/New_York
|
|
127
|
+
* // same as new Date("2021-10-13T11:22:33Z"); // UTC
|
|
128
|
+
*
|
|
129
|
+
* @param {Date} oDate The date which should be converted.
|
|
130
|
+
* @param {string} sTargetTimezone The target IANA timezone ID, e.g <code>"Europe/Berlin"</code>
|
|
131
|
+
* @returns {Date} The new date in the target time zone.
|
|
132
|
+
* @private
|
|
133
|
+
* @ui5-restricted sap.ui.core.format.DateFormat, sap.ui.unified, sap.m
|
|
134
|
+
*/
|
|
135
|
+
TimezoneUtils.convertToTimezone = function (oDate, sTargetTimezone) {
|
|
136
|
+
var oFormatParts = this._getParts(oDate, sTargetTimezone);
|
|
137
|
+
return TimezoneUtils._getDateFromParts(oFormatParts);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Uses the <code>Intl.DateTimeFormat</code> API to convert a date to a specific time zone.
|
|
142
|
+
*
|
|
143
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts
|
|
144
|
+
* @param {Date} oDate The date which should be converted.
|
|
145
|
+
* @param {string} sTargetTimezone The target IANA timezone ID, e.g <code>"Europe/Berlin"</code>
|
|
146
|
+
* @returns {{
|
|
147
|
+
* day: string,
|
|
148
|
+
* era: string,
|
|
149
|
+
* fractionalSecond: string,
|
|
150
|
+
* hour: string,
|
|
151
|
+
* minute: string,
|
|
152
|
+
* month: string,
|
|
153
|
+
* second: string,
|
|
154
|
+
* timeZoneName: string,
|
|
155
|
+
* weekday: string,
|
|
156
|
+
* year: string
|
|
157
|
+
* }} An object containing the date and time fields considering the target time zone.
|
|
158
|
+
* @private
|
|
159
|
+
*/
|
|
160
|
+
TimezoneUtils._getParts = function (oDate, sTargetTimezone) {
|
|
161
|
+
var sKey,
|
|
162
|
+
oPart,
|
|
163
|
+
oDateParts = Object.create(null),
|
|
164
|
+
oIntlDate = oIntlDateTimeFormatCache.get(sTargetTimezone),
|
|
165
|
+
// clone the date object before passing it to the Intl API, to ensure that no
|
|
166
|
+
// UniversalDate gets passed to it;
|
|
167
|
+
// no need to use UI5Date.getInstance as only the UTC timestamp is used
|
|
168
|
+
oParts = oIntlDate.formatToParts(new Date(oDate.getTime()));
|
|
169
|
+
for (sKey in oParts) {
|
|
170
|
+
oPart = oParts[sKey];
|
|
171
|
+
if (oPart.type !== "literal") {
|
|
172
|
+
oDateParts[oPart.type] = oPart.value;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return oDateParts;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Creates a Date from the provided date parts.
|
|
180
|
+
*
|
|
181
|
+
* @param {object} oParts Separated date and time fields as object, see {@link #_getParts}.
|
|
182
|
+
* @returns {Date} Returns the date object created from the provided parts.
|
|
183
|
+
* @private
|
|
184
|
+
*/
|
|
185
|
+
TimezoneUtils._getDateFromParts = function (oParts) {
|
|
186
|
+
// no need to use UI5Date.getInstance as only the UTC timestamp is used
|
|
187
|
+
var oDate = new Date(0),
|
|
188
|
+
iUTCYear = parseInt(oParts.year);
|
|
189
|
+
if (oParts.era === "B") {
|
|
190
|
+
// The JS Date uses astronomical year numbering which supports year zero and negative
|
|
191
|
+
// year numbers.
|
|
192
|
+
// The Intl.DateTimeFormat API uses eras (no year zero and no negative year numbers).
|
|
193
|
+
// years around zero overview:
|
|
194
|
+
// | Astronomical | In Era
|
|
195
|
+
// | 2 | 2 Anno Domini (era: "A")
|
|
196
|
+
// | 1 | 1 Anno Domini (era: "A")
|
|
197
|
+
// | 0 | 1 Before Christ (era: "B")
|
|
198
|
+
// | -1 | 2 Before Christ (era: "B")
|
|
199
|
+
// | -2 | 3 Before Christ (era: "B")
|
|
200
|
+
// For the conversion to the JS Date the parts returned by the Intl.DateTimeFormat API
|
|
201
|
+
// need to be adapted.
|
|
202
|
+
iUTCYear = iUTCYear * -1 + 1;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Date.UTC cannot be used here to be able to support dates before the UNIX epoch
|
|
206
|
+
oDate.setUTCFullYear(iUTCYear, parseInt(oParts.month) - 1, parseInt(oParts.day));
|
|
207
|
+
oDate.setUTCHours(parseInt(oParts.hour), parseInt(oParts.minute), parseInt(oParts.second), parseInt(oParts.fractionalSecond || 0)); // some older browsers don't support fractionalSecond, e.g. Safari < 14.1 */
|
|
208
|
+
|
|
209
|
+
return oDate;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Gets the offset to UTC in seconds for a given date in the time zone specified.
|
|
214
|
+
*
|
|
215
|
+
* For non-unique points in time, the daylight saving time takes precedence over the standard
|
|
216
|
+
* time shortly after the switch back (e.g. clock gets set back 1 hour, duplicate hour).
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* var oDate = new Date("2021-10-13T13:22:33Z");
|
|
220
|
+
* TimezoneUtils.calculateOffset(oDate, "America/New_York");
|
|
221
|
+
* // => +14400 seconds (4 * 60 * 60 seconds)
|
|
222
|
+
*
|
|
223
|
+
* TimezoneUtils.calculateOffset(oDate, "Europe/Berlin");
|
|
224
|
+
* // => -7200 seconds (-2 * 60 * 60 seconds)
|
|
225
|
+
*
|
|
226
|
+
* // daylight saving time (2018 Sun, 25 Mar, 02:00 CET → CEST +1 hour (DST start) UTC+2h)
|
|
227
|
+
* // the given date is taken as it is in the time zone
|
|
228
|
+
* TimezoneUtils.calculateOffset(new Date("2018-03-25T00:00:00Z"), "Europe/Berlin");
|
|
229
|
+
* // => -3600 seconds (-1 * 60 * 60 seconds), interpreted as: 2018-03-25 00:00:00 (CET)
|
|
230
|
+
*
|
|
231
|
+
* TimezoneUtils.calculateOffset(new Date("2018-03-25T03:00:00Z"), "Europe/Berlin");
|
|
232
|
+
* // => -7200 seconds (-2 * 60 * 60 seconds)
|
|
233
|
+
*
|
|
234
|
+
* var oHistoricalDate = new Date("1800-10-13T13:22:33Z");
|
|
235
|
+
* TimezoneUtils.calculateOffset(oHistoricalDate, "Europe/Berlin");
|
|
236
|
+
* // => -3208 seconds (-3208 seconds)
|
|
237
|
+
*
|
|
238
|
+
* @param {Date} oDate The date in the time zone used to calculate the offset to UTC.
|
|
239
|
+
* @param {string} sTimezoneSource The source IANA timezone ID, e.g <code>"Europe/Berlin"</code>
|
|
240
|
+
* @returns {number} The difference to UTC between the date in the time zone.
|
|
241
|
+
* @private
|
|
242
|
+
* @ui5-restricted sap.ui.core.format.DateFormat
|
|
243
|
+
*/
|
|
244
|
+
TimezoneUtils.calculateOffset = function (oDate, sTimezoneSource) {
|
|
245
|
+
const oDateInTimezone = TimezoneUtils.convertToTimezone(oDate, sTimezoneSource);
|
|
246
|
+
const iGivenTimestamp = oDate.getTime();
|
|
247
|
+
const iInitialOffset = iGivenTimestamp - oDateInTimezone.getTime();
|
|
248
|
+
// no need to use UI5Date.getInstance as only the UTC timestamp is used
|
|
249
|
+
const oFirstGuess = new Date(iGivenTimestamp + iInitialOffset);
|
|
250
|
+
const oFirstGuessInTimezone = TimezoneUtils.convertToTimezone(oFirstGuess, sTimezoneSource);
|
|
251
|
+
const iFirstGuessInTimezoneTimestamp = oFirstGuessInTimezone.getTime();
|
|
252
|
+
const iSecondOffset = oFirstGuess.getTime() - iFirstGuessInTimezoneTimestamp;
|
|
253
|
+
let iTimezoneOffset = iSecondOffset;
|
|
254
|
+
if (iInitialOffset !== iSecondOffset) {
|
|
255
|
+
const oSecondGuess = new Date(iGivenTimestamp + iSecondOffset);
|
|
256
|
+
const oSecondGuessInTimezone = TimezoneUtils.convertToTimezone(oSecondGuess, sTimezoneSource);
|
|
257
|
+
const iSecondGuessInTimezoneTimestamp = oSecondGuessInTimezone.getTime();
|
|
258
|
+
// if time is different, the given date/time does not exist in the target time zone (switch to Daylight
|
|
259
|
+
// Saving Time) -> take the offset for the greater date
|
|
260
|
+
if (iSecondGuessInTimezoneTimestamp !== iGivenTimestamp && iFirstGuessInTimezoneTimestamp > iSecondGuessInTimezoneTimestamp) {
|
|
261
|
+
iTimezoneOffset = iInitialOffset;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return iTimezoneOffset / 1000;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Map outdated IANA timezone IDs used in CLDR to correct and up-to-date IANA IDs as maintained in ABAP systems.
|
|
269
|
+
*
|
|
270
|
+
* @private
|
|
271
|
+
*/
|
|
272
|
+
TimezoneUtils.mCLDR2ABAPTimezones = {
|
|
273
|
+
"America/Buenos_Aires": "America/Argentina/Buenos_Aires",
|
|
274
|
+
"America/Catamarca": "America/Argentina/Catamarca",
|
|
275
|
+
"America/Cordoba": "America/Argentina/Cordoba",
|
|
276
|
+
"America/Jujuy": "America/Argentina/Jujuy",
|
|
277
|
+
"America/Mendoza": "America/Argentina/Mendoza",
|
|
278
|
+
"America/Indianapolis": "America/Indiana/Indianapolis",
|
|
279
|
+
"America/Louisville": "America/Kentucky/Louisville",
|
|
280
|
+
"Africa/Asmera": "Africa/Asmara",
|
|
281
|
+
"Asia/Katmandu": "Asia/Kathmandu",
|
|
282
|
+
"Asia/Calcutta": "Asia/Kolkata",
|
|
283
|
+
"Atlantic/Faeroe": "Atlantic/Faroe",
|
|
284
|
+
"Pacific/Ponape": "Pacific/Pohnpei",
|
|
285
|
+
"Asia/Rangoon": "Asia/Yangon",
|
|
286
|
+
"Pacific/Truk": "Pacific/Chuuk",
|
|
287
|
+
"America/Godthab": "America/Nuuk",
|
|
288
|
+
"Asia/Saigon": "Asia/Ho_Chi_Minh",
|
|
289
|
+
"America/Coral_Harbour": "America/Atikokan"
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Retrieves the browser's local IANA timezone ID; if the browser's timezone ID is not the up-to-date IANA
|
|
294
|
+
* timezone ID, the corresponding IANA timezone ID is returned.
|
|
295
|
+
*
|
|
296
|
+
* @returns {string} The local IANA timezone ID of the browser as up-to-date IANA timezone ID,
|
|
297
|
+
* e.g. <code>"Europe/Berlin"</code> or <code>"Asia/Kolkata"</code>
|
|
298
|
+
*
|
|
299
|
+
* @private
|
|
300
|
+
* @ui5-restricted sap.ui.core.Configuration,sap.m.DateTimeField
|
|
301
|
+
*/
|
|
302
|
+
TimezoneUtils.getLocalTimezone = function () {
|
|
303
|
+
if (sLocalTimezone === "") {
|
|
304
|
+
// timezone may be undefined, only value "" means empty cache
|
|
305
|
+
sLocalTimezone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
306
|
+
sLocalTimezone = TimezoneUtils.mCLDR2ABAPTimezones[sLocalTimezone] || sLocalTimezone;
|
|
307
|
+
}
|
|
308
|
+
return sLocalTimezone;
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Clears the cache for the browser's local IANA timezone ID.
|
|
313
|
+
*
|
|
314
|
+
* @private
|
|
315
|
+
*/
|
|
316
|
+
TimezoneUtils._clearLocalTimezoneCache = function () {
|
|
317
|
+
sLocalTimezone = "";
|
|
318
|
+
};
|
|
319
|
+
export default TimezoneUtils;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*!
|
|
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
|
+
|
|
7
|
+
var rCamelCase = /-(.)/ig;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Transforms a hyphen separated string to a camel case string.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* sap.ui.require(["sap/base/strings/camelize"], function(camelize){
|
|
14
|
+
* camelize("foo-bar"); // "fooBar"
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* @function
|
|
18
|
+
* @since 1.58
|
|
19
|
+
* @alias module:sap/base/strings/camelize
|
|
20
|
+
* @param {string} sString Hyphen separated string
|
|
21
|
+
* @returns {string} The transformed string
|
|
22
|
+
* @public
|
|
23
|
+
* @SecPassthrough {0|return}
|
|
24
|
+
*/
|
|
25
|
+
var fnCamelize = function (sString) {
|
|
26
|
+
return sString.replace(rCamelCase, function (sMatch, sChar) {
|
|
27
|
+
return sChar.toUpperCase();
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
export default fnCamelize;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/*!
|
|
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
|
+
import assert from "../assert.js";
|
|
7
|
+
/**
|
|
8
|
+
* Pattern to analyze MessageFormat strings.
|
|
9
|
+
*
|
|
10
|
+
* Group 1: captures doubled single quotes within the string
|
|
11
|
+
* Group 2: captures quoted fragments within the string.
|
|
12
|
+
* Note that java.util.MessageFormat silently forgives a missing single quote at
|
|
13
|
+
* the end of a pattern. This special case is handled by the RegEx as well.
|
|
14
|
+
* Group 3: captures placeholders
|
|
15
|
+
* Checks only for numerical argument index, any remainder is ignored up to the next
|
|
16
|
+
* closing curly brace. Nested placeholders are not accepted!
|
|
17
|
+
* Group 4: captures any remaining curly braces and indicates syntax errors
|
|
18
|
+
*
|
|
19
|
+
* [-1] [----- quoted string -----] [------ placeholder ------] [--]
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
var rMessageFormat = /('')|'([^']+(?:''[^']*)*)(?:'|$)|\{([0-9]+(?:\s*,[^{}]*)?)\}|[{}]/g;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Creates a string from a pattern by replacing placeholders with concrete values.
|
|
26
|
+
*
|
|
27
|
+
* The syntax of the pattern is inspired by (but not fully equivalent to) the
|
|
28
|
+
* java.util.MessageFormat.
|
|
29
|
+
*
|
|
30
|
+
* Placeholders have the form <code>{ integer }</code>, where any occurrence of
|
|
31
|
+
* <code>{0}</code> is replaced by the value with index 0 in <code>aValues</code>,
|
|
32
|
+
* <code>{1}</code> by the value with index 1 in <code>aValues</code> etc.
|
|
33
|
+
*
|
|
34
|
+
* To avoid interpretation of curly braces as placeholders, any non-placeholder fragment
|
|
35
|
+
* of the pattern can be enclosed in single quotes. The surrounding single quotes will be
|
|
36
|
+
* omitted from the result. Single quotes that are not meant to escape a fragment and
|
|
37
|
+
* that should appear in the result, need to be doubled. In the result, only a single
|
|
38
|
+
* single quote will occur.
|
|
39
|
+
*
|
|
40
|
+
* Example: Pattern Strings
|
|
41
|
+
* <pre>
|
|
42
|
+
* formatMessage("Say {0}", ["Hello"]) -> "Say Hello" // normal use case
|
|
43
|
+
* formatMessage("Say '{0}'", ["Hello"]) -> "Say {0}" // escaped placeholder
|
|
44
|
+
* formatMessage("Say ''{0}''", ["Hello"]) -> "Say 'Hello'" // doubled single quote
|
|
45
|
+
* formatMessage("Say '{0}'''", ["Hello"]) -> "Say {0}'" // doubled single quote in quoted fragment
|
|
46
|
+
* </pre>
|
|
47
|
+
* In contrast to java.util.MessageFormat, format types or format styles are not supported.
|
|
48
|
+
* Everything after the argument index and up to the first closing curly brace is ignored.
|
|
49
|
+
* Nested placeholders (as supported by java.lang.MessageFormat for the format type choice)
|
|
50
|
+
* are not ignored but reported as a parse error.
|
|
51
|
+
*
|
|
52
|
+
* This method throws an Error when the pattern syntax is not fulfilled (e.g. unbalanced curly
|
|
53
|
+
* braces, nested placeholders or a non-numerical argument index).
|
|
54
|
+
*
|
|
55
|
+
* This method can also be used as a formatter within a binding. The first part of a composite binding
|
|
56
|
+
* will be used as pattern, the following parts as aValues. If there is only one value and this
|
|
57
|
+
* value is an array it will be handled like the default described above.
|
|
58
|
+
*
|
|
59
|
+
* @function
|
|
60
|
+
* @since 1.58
|
|
61
|
+
* @alias module:sap/base/strings/formatMessage
|
|
62
|
+
* @param {string} sPattern A pattern string in the described syntax
|
|
63
|
+
* @param {any[]} [aValues=[]] The values to be used instead of the placeholders.
|
|
64
|
+
* @returns {string} The formatted result string
|
|
65
|
+
* @SecPassthrough {*|return}
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
var fnFormatMessage = function (sPattern, aValues) {
|
|
69
|
+
assert(typeof sPattern === "string" || sPattern instanceof String, "pattern must be string");
|
|
70
|
+
if (arguments.length > 2 || aValues != null && !Array.isArray(aValues)) {
|
|
71
|
+
aValues = Array.prototype.slice.call(arguments, 1);
|
|
72
|
+
}
|
|
73
|
+
aValues = aValues || [];
|
|
74
|
+
return sPattern.replace(rMessageFormat, function ($0, $1, $2, $3, offset) {
|
|
75
|
+
if ($1) {
|
|
76
|
+
// a doubled single quote in a normal string fragment
|
|
77
|
+
// --> emit a single quote
|
|
78
|
+
return "'";
|
|
79
|
+
} else if ($2) {
|
|
80
|
+
// a quoted sequence of chars, potentially containing doubled single quotes again
|
|
81
|
+
// --> emit with doubled single quotes replaced by a single quote
|
|
82
|
+
return $2.replace(/''/g, "'");
|
|
83
|
+
} else if ($3) {
|
|
84
|
+
// a welformed curly brace
|
|
85
|
+
// --> emit the argument but ignore other parameters
|
|
86
|
+
return String(aValues[parseInt($3)]);
|
|
87
|
+
}
|
|
88
|
+
// e.g. malformed curly braces
|
|
89
|
+
// --> throw Error
|
|
90
|
+
throw new Error("formatMessage: pattern syntax error at pos. " + offset);
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
export default fnFormatMessage;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getLocaleData } from "@ui5/webcomponents-base/dist/asset-registries/LocaleData.js";
|
|
2
|
+
const loadResource = (moduleName) => {
|
|
3
|
+
const moduleFormat = moduleName.match(/sap\/ui\/core\/cldr\/(\w+)\.json/);
|
|
4
|
+
if (!moduleFormat) {
|
|
5
|
+
throw new Error(`Unknown module "${moduleName}"`);
|
|
6
|
+
}
|
|
7
|
+
const localeId = moduleFormat[1];
|
|
8
|
+
return getLocaleData(localeId);
|
|
9
|
+
};
|
|
10
|
+
const LoaderExtensions = {
|
|
11
|
+
loadResource,
|
|
12
|
+
};
|
|
13
|
+
export default LoaderExtensions;
|
|
14
|
+
//# sourceMappingURL=LoaderExtensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoaderExtensions.js","sourceRoot":"","sources":["../../../../src/sap/base/util/LoaderExtensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6DAA6D,CAAC;AAE5F,MAAM,YAAY,GAAG,CAAC,UAAkB,EAAE,EAAE;IAC3C,MAAM,YAAY,GAAG,UAAU,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;IAC1E,IAAI,CAAC,YAAY,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,mBAAmB,UAAU,GAAG,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,QAAQ,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IACjC,OAAO,aAAa,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG;IACxB,YAAY;CACZ,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import { getLocaleData } from \"@ui5/webcomponents-base/dist/asset-registries/LocaleData.js\";\n\nconst loadResource = (moduleName: string) => {\n\tconst moduleFormat = moduleName.match(/sap\\/ui\\/core\\/cldr\\/(\\w+)\\.json/);\n\tif (!moduleFormat) {\n\t\tthrow new Error(`Unknown module \"${moduleName}\"`);\n\t}\n\n\tconst localeId = moduleFormat[1];\n\treturn getLocaleData(localeId);\n};\n\nconst LoaderExtensions = {\n\tloadResource,\n};\n\nexport default LoaderExtensions;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObjectPath.js","sourceRoot":"","sources":["../../../../src/sap/base/util/ObjectPath.ts"],"names":[],"mappings":"AAAA,qEAAqE;AAErE,MAAM,UAAU,GAAG;IAClB,GAAG,KAAI,CAAC;CACR,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["// ObjectPath is accessing window which breaks SSR, hence the overlay\n\nconst ObjectPath = {\n\tset() {},\n};\n\nexport default ObjectPath;\n"]}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// @evo-todo make it a simple object with immutable properties (Object.defineProperties)
|
|
2
|
+
|
|
3
|
+
// -------------------------- VERSION -------------------------------------
|
|
4
|
+
/*!
|
|
5
|
+
* OpenUI5
|
|
6
|
+
* (c) Copyright 2009-2024 SAP SE or an SAP affiliate company.
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var rVersion = /^[0-9]+(?:\.([0-9]+)(?:\.([0-9]+))?)?(.*)$/;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns a Version instance created from the given parameters.
|
|
14
|
+
*
|
|
15
|
+
* This function can either be called as a constructor (using <code>new</code>) or as a normal function.
|
|
16
|
+
* It always returns an immutable Version instance.
|
|
17
|
+
*
|
|
18
|
+
* The parts of the version number (major, minor, patch, suffix) can be provided in several ways:
|
|
19
|
+
* <ul>
|
|
20
|
+
* <li>Version("1.2.3-SNAPSHOT") - as a dot-separated string. Any non-numerical char or a dot followed
|
|
21
|
+
* by a non-numerical char starts the suffix portion. Any missing major,
|
|
22
|
+
* minor or patch versions will be set to 0.</li>
|
|
23
|
+
* <li>Version(1,2,3,"-SNAPSHOT") - as individual parameters. Major, minor and patch must be integer numbers
|
|
24
|
+
* or empty, suffix must be a string not starting with digits.</li>
|
|
25
|
+
* <li>Version([1,2,3,"-SNAPSHOT"]) - as an array with the individual parts. The same type restrictions apply
|
|
26
|
+
* as before.</li>
|
|
27
|
+
* <li>Version(otherVersion) - as a Version instance (cast operation). Returns the given instance instead
|
|
28
|
+
* of creating a new one.</li>
|
|
29
|
+
* </ul>
|
|
30
|
+
*
|
|
31
|
+
* To keep the code size small, this implementation mainly validates the single string variant.
|
|
32
|
+
* All other variants are only validated to some degree. It is the responsibility of the caller to
|
|
33
|
+
* provide proper parts.
|
|
34
|
+
*
|
|
35
|
+
* @param {int|string|any[]|module:sap/base/util/Version} vMajor the major part of the version (int) or any of the single
|
|
36
|
+
* parameter variants explained above.
|
|
37
|
+
* @param {int} iMinor the minor part of the version number
|
|
38
|
+
* @param {int} iPatch the patch part of the version number
|
|
39
|
+
* @param {string} sSuffix the suffix part of the version number
|
|
40
|
+
* @class Represents a version consisting of major, minor, patch version, and suffix, for example '1.2.7-SNAPSHOT'.
|
|
41
|
+
* @since 1.58
|
|
42
|
+
* @alias module:sap/base/util/Version
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
function Version(vMajor, iMinor, iPatch, sSuffix) {
|
|
46
|
+
if (vMajor instanceof Version) {
|
|
47
|
+
// note: even a constructor may return a value different from 'this'
|
|
48
|
+
return vMajor;
|
|
49
|
+
}
|
|
50
|
+
if (!(this instanceof Version)) {
|
|
51
|
+
// act as a cast operator when called as function (not as a constructor)
|
|
52
|
+
return new Version(vMajor, iMinor, iPatch, sSuffix);
|
|
53
|
+
}
|
|
54
|
+
var m;
|
|
55
|
+
if (typeof vMajor === "string") {
|
|
56
|
+
m = rVersion.exec(vMajor);
|
|
57
|
+
} else if (Array.isArray(vMajor)) {
|
|
58
|
+
m = vMajor;
|
|
59
|
+
} else {
|
|
60
|
+
m = arguments;
|
|
61
|
+
}
|
|
62
|
+
m = m || [];
|
|
63
|
+
function norm(v) {
|
|
64
|
+
v = parseInt(v);
|
|
65
|
+
return isNaN(v) ? 0 : v;
|
|
66
|
+
}
|
|
67
|
+
vMajor = norm(m[0]);
|
|
68
|
+
iMinor = norm(m[1]);
|
|
69
|
+
iPatch = norm(m[2]);
|
|
70
|
+
sSuffix = String(m[3] || "");
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Returns a string representation of this version.
|
|
74
|
+
*
|
|
75
|
+
* @return {string} a string representation of this version.
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
this.toString = function () {
|
|
79
|
+
return vMajor + "." + iMinor + "." + iPatch + sSuffix;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Returns the major version part of this version.
|
|
84
|
+
*
|
|
85
|
+
* @return {int} the major version part of this version
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
this.getMajor = function () {
|
|
89
|
+
return vMajor;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Returns the minor version part of this version.
|
|
94
|
+
*
|
|
95
|
+
* @return {int} the minor version part of this version
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
this.getMinor = function () {
|
|
99
|
+
return iMinor;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Returns the patch (or micro) version part of this version.
|
|
104
|
+
*
|
|
105
|
+
* @return {int} the patch version part of this version
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
this.getPatch = function () {
|
|
109
|
+
return iPatch;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Returns the version suffix of this version.
|
|
114
|
+
*
|
|
115
|
+
* @return {string} the version suffix of this version
|
|
116
|
+
* @public
|
|
117
|
+
*/
|
|
118
|
+
this.getSuffix = function () {
|
|
119
|
+
return sSuffix;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Compares this version with a given one.
|
|
124
|
+
*
|
|
125
|
+
* The version with which this version should be compared can be given as a <code>sap/base/util/Version</code> instance,
|
|
126
|
+
* as a string (e.g. <code>v.compareto("1.4.5")</code>). Or major, minor, patch and suffix values can be given as
|
|
127
|
+
* separate parameters (e.g. <code>v.compareTo(1, 4, 5)</code>) or in an array (e.g. <code>v.compareTo([1, 4, 5])</code>).
|
|
128
|
+
*
|
|
129
|
+
* @return {int} 0, if the given version is equal to this version, a negative value if the given other version is greater
|
|
130
|
+
* and a positive value otherwise
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
this.compareTo = function () {
|
|
134
|
+
var vOther = Version.apply(window, arguments);
|
|
135
|
+
/*eslint-disable no-nested-ternary */
|
|
136
|
+
return vMajor - vOther.getMajor() || iMinor - vOther.getMinor() || iPatch - vOther.getPatch() || (sSuffix < vOther.getSuffix() ? -1 : sSuffix === vOther.getSuffix() ? 0 : 1);
|
|
137
|
+
/*eslint-enable no-nested-ternary */
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Checks whether this version is in the range of the given interval (start inclusive, end exclusive).
|
|
143
|
+
*
|
|
144
|
+
* The boundaries against which this version should be checked can be given as <code>sap/base/util/Version</code>
|
|
145
|
+
* instances (e.g. <code>v.inRange(v1, v2)</code>), as strings (e.g. <code>v.inRange("1.4", "2.7")</code>)
|
|
146
|
+
* or as arrays (e.g. <code>v.inRange([1,4], [2,7])</code>).
|
|
147
|
+
*
|
|
148
|
+
* @param {string|any[]|module:sap/base/util/Version} vMin the start of the range (inclusive)
|
|
149
|
+
* @param {string|any[]|module:sap/base/util/Version} vMax the end of the range (exclusive)
|
|
150
|
+
* @return {boolean} <code>true</code> if this version is greater or equal to <code>vMin</code> and smaller
|
|
151
|
+
* than <code>vMax</code>, <code>false</code> otherwise.
|
|
152
|
+
* @public
|
|
153
|
+
*/
|
|
154
|
+
Version.prototype.inRange = function (vMin, vMax) {
|
|
155
|
+
return this.compareTo(vMin) >= 0 && this.compareTo(vMax) < 0;
|
|
156
|
+
};
|
|
157
|
+
export default Version;
|