@ui5/webcomponents-localization 1.13.0-rc.0 → 1.13.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/dates/CalendarDate.d.ts +6 -4
- package/dist/dates/CalendarDate.js +8 -7
- package/dist/dates/CalendarDate.js.map +1 -1
- package/dist/dates/UI5Date.d.ts +6 -0
- package/dist/dates/UI5Date.js +7 -0
- package/dist/dates/UI5Date.js.map +1 -0
- package/dist/dates/UniversalDate.d.ts +2 -1
- package/dist/dates/UniversalDate.js.map +1 -1
- package/dist/dates/calculateWeekNumber.d.ts +2 -1
- package/dist/dates/calculateWeekNumber.js.map +1 -1
- package/dist/dates/getRoundedTimestamp.js +1 -0
- package/dist/dates/getRoundedTimestamp.js.map +1 -1
- package/dist/dates/getTodayUTCTimestamp.js +2 -1
- package/dist/dates/getTodayUTCTimestamp.js.map +1 -1
- package/dist/dates/transformDateToSecondaryType.js +3 -2
- package/dist/dates/transformDateToSecondaryType.js.map +1 -1
- package/dist/generated/assets/cldr/ar.json +173 -161
- package/dist/generated/assets/cldr/ar_EG.json +173 -161
- package/dist/generated/assets/cldr/ar_SA.json +172 -161
- package/dist/generated/assets/cldr/bg.json +131 -125
- package/dist/generated/assets/cldr/ca.json +29 -19
- package/dist/generated/assets/cldr/cs.json +8 -2
- package/dist/generated/assets/cldr/cy.json +92 -86
- package/dist/generated/assets/cldr/da.json +238 -232
- package/dist/generated/assets/cldr/de.json +28 -22
- package/dist/generated/assets/cldr/de_AT.json +18 -12
- package/dist/generated/assets/cldr/de_CH.json +28 -22
- package/dist/generated/assets/cldr/el.json +61 -55
- package/dist/generated/assets/cldr/el_CY.json +61 -55
- package/dist/generated/assets/cldr/en.json +8 -2
- package/dist/generated/assets/cldr/en_AU.json +160 -154
- package/dist/generated/assets/cldr/en_GB.json +132 -126
- package/dist/generated/assets/cldr/en_HK.json +160 -151
- package/dist/generated/assets/cldr/en_IE.json +159 -153
- package/dist/generated/assets/cldr/en_IN.json +159 -150
- package/dist/generated/assets/cldr/en_NZ.json +159 -153
- package/dist/generated/assets/cldr/en_PG.json +159 -153
- package/dist/generated/assets/cldr/en_SG.json +148 -139
- package/dist/generated/assets/cldr/en_ZA.json +156 -150
- package/dist/generated/assets/cldr/es.json +296 -289
- package/dist/generated/assets/cldr/es_AR.json +213 -206
- package/dist/generated/assets/cldr/es_BO.json +216 -209
- package/dist/generated/assets/cldr/es_CL.json +176 -169
- package/dist/generated/assets/cldr/es_CO.json +176 -169
- package/dist/generated/assets/cldr/es_MX.json +271 -264
- package/dist/generated/assets/cldr/es_PE.json +141 -134
- package/dist/generated/assets/cldr/es_UY.json +144 -137
- package/dist/generated/assets/cldr/es_VE.json +144 -137
- package/dist/generated/assets/cldr/et.json +175 -169
- package/dist/generated/assets/cldr/fa.json +245 -233
- package/dist/generated/assets/cldr/fi.json +148 -57
- package/dist/generated/assets/cldr/fr.json +19 -12
- package/dist/generated/assets/cldr/fr_BE.json +19 -12
- package/dist/generated/assets/cldr/fr_CA.json +18 -11
- package/dist/generated/assets/cldr/fr_CH.json +17 -10
- package/dist/generated/assets/cldr/fr_LU.json +19 -12
- package/dist/generated/assets/cldr/he.json +98 -86
- package/dist/generated/assets/cldr/hi.json +57 -48
- package/dist/generated/assets/cldr/hr.json +10 -4
- package/dist/generated/assets/cldr/hu.json +11 -5
- package/dist/generated/assets/cldr/id.json +83 -77
- package/dist/generated/assets/cldr/it.json +28 -21
- package/dist/generated/assets/cldr/it_CH.json +28 -21
- package/dist/generated/assets/cldr/ja.json +20 -12
- package/dist/generated/assets/cldr/kk.json +8 -2
- package/dist/generated/assets/cldr/ko.json +84 -75
- package/dist/generated/assets/cldr/lt.json +8 -2
- package/dist/generated/assets/cldr/lv.json +97 -91
- package/dist/generated/assets/cldr/ms.json +112 -106
- package/dist/generated/assets/cldr/nb.json +21 -15
- package/dist/generated/assets/cldr/nl.json +9 -3
- package/dist/generated/assets/cldr/nl_BE.json +9 -3
- package/dist/generated/assets/cldr/pl.json +28 -22
- package/dist/generated/assets/cldr/pt.json +255 -248
- package/dist/generated/assets/cldr/pt_PT.json +281 -274
- package/dist/generated/assets/cldr/ro.json +11 -5
- package/dist/generated/assets/cldr/ru.json +71 -65
- package/dist/generated/assets/cldr/ru_UA.json +70 -64
- package/dist/generated/assets/cldr/sk.json +9 -3
- package/dist/generated/assets/cldr/sl.json +197 -191
- package/dist/generated/assets/cldr/sr.json +67 -61
- package/dist/generated/assets/cldr/sr_Latn.json +70 -62
- package/dist/generated/assets/cldr/sv.json +189 -183
- package/dist/generated/assets/cldr/th.json +129 -120
- package/dist/generated/assets/cldr/tr.json +24 -18
- package/dist/generated/assets/cldr/uk.json +125 -119
- package/dist/generated/assets/cldr/vi.json +17 -11
- package/dist/generated/assets/cldr/zh_CN.json +185 -171
- package/dist/generated/assets/cldr/zh_HK.json +163 -149
- package/dist/generated/assets/cldr/zh_SG.json +162 -148
- package/dist/generated/assets/cldr/zh_TW.json +156 -125
- package/dist/sap/ui/core/Configuration.js +2 -1
- package/dist/sap/ui/core/Configuration.js.map +1 -1
- package/dist/sap/ui/core/LocaleData.js +73 -19
- package/dist/sap/ui/core/date/UI5Date.js +305 -0
- package/dist/sap/ui/core/date/UniversalDate.js +7 -6
- package/dist/sap/ui/core/format/DateFormat.js +307 -293
- package/dist/sap/ui/core/format/TimezoneUtil.js +7 -12
- package/package.json +7 -7
- package/used-modules.txt +1 -0
@@ -6,6 +6,16 @@ import Locale from './Locale.js';
|
|
6
6
|
import assert from '../../base/assert.js';
|
7
7
|
import LoaderExtensions from '../../base/util/LoaderExtensions.js';
|
8
8
|
import Configuration from './Configuration.js';
|
9
|
+
var rEIgnoreCase = /e/i, mLegacyUnit2CurrentUnit = {
|
10
|
+
'acceleration-meter-per-second-squared': 'acceleration-meter-per-square-second',
|
11
|
+
'concentr-milligram-per-deciliter': 'concentr-milligram-ofglucose-per-deciliter',
|
12
|
+
'concentr-part-per-million': 'concentr-permillion',
|
13
|
+
'consumption-liter-per-100kilometers': 'consumption-liter-per-100-kilometer',
|
14
|
+
'pressure-millimeter-of-mercury': 'pressure-millimeter-ofhg',
|
15
|
+
'pressure-pound-per-square-inch': 'pressure-pound-force-per-square-inch',
|
16
|
+
'pressure-inch-hg': 'pressure-inch-ofhg',
|
17
|
+
'torque-pound-foot': 'torque-pound-force-foot'
|
18
|
+
}, rNumberInScientificNotation = /^([+-]?)((\d+)(?:\.(\d+))?)[eE]([+-]?\d+)$/, rTrailingZeroes = /0+$/;
|
9
19
|
var LocaleData = BaseObject.extend('sap.ui.core.LocaleData', {
|
10
20
|
constructor: function (oLocale) {
|
11
21
|
this.oLocale = oLocale;
|
@@ -642,11 +652,14 @@ var LocaleData = BaseObject.extend('sap.ui.core.LocaleData', {
|
|
642
652
|
oTimeEntry = oScale[sEntry];
|
643
653
|
iSign = sEntry.substr(18) === 'past' ? -1 : 1;
|
644
654
|
aPluralCategories.forEach(function (sKey) {
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
655
|
+
var sPattern = oTimeEntry['relativeTimePattern-count-' + sKey];
|
656
|
+
if (sPattern) {
|
657
|
+
aPatterns.push({
|
658
|
+
scale: sScale,
|
659
|
+
sign: iSign,
|
660
|
+
pattern: sPattern
|
661
|
+
});
|
662
|
+
}
|
650
663
|
});
|
651
664
|
}
|
652
665
|
}
|
@@ -769,7 +782,11 @@ var LocaleData = BaseObject.extend('sap.ui.core.LocaleData', {
|
|
769
782
|
return this.getUnitFormat(sUnit);
|
770
783
|
},
|
771
784
|
getUnitFormat: function (sUnit) {
|
772
|
-
|
785
|
+
var oResult = this._get('units', 'short', sUnit);
|
786
|
+
if (!oResult && mLegacyUnit2CurrentUnit[sUnit]) {
|
787
|
+
oResult = this._get('units', 'short', mLegacyUnit2CurrentUnit[sUnit]);
|
788
|
+
}
|
789
|
+
return oResult;
|
773
790
|
},
|
774
791
|
getUnitFormats: function () {
|
775
792
|
return this._getMerged('units', 'short');
|
@@ -801,7 +818,7 @@ var LocaleData = BaseObject.extend('sap.ui.core.LocaleData', {
|
|
801
818
|
return this.oLocale.getLanguage() === 'en' && this.oLocale.getRegion() === 'US';
|
802
819
|
},
|
803
820
|
getPreferredCalendarType: function () {
|
804
|
-
var
|
821
|
+
var sCalendarName, sType, i, aCalendars = this._get('calendarPreference') || [];
|
805
822
|
for (i = 0; i < aCalendars.length; i++) {
|
806
823
|
sCalendarName = aCalendars[i].split('-')[0];
|
807
824
|
for (sType in CalendarType) {
|
@@ -834,14 +851,14 @@ var LocaleData = BaseObject.extend('sap.ui.core.LocaleData', {
|
|
834
851
|
fnTest = this._parsePluralRule(oPlurals[sCategory]);
|
835
852
|
this._pluralTest[sCategory] = fnTest;
|
836
853
|
}
|
837
|
-
if (fnTest(sNumber)) {
|
854
|
+
if (fnTest(sNumber).bMatch) {
|
838
855
|
return sCategory;
|
839
856
|
}
|
840
857
|
}
|
841
858
|
return 'other';
|
842
859
|
},
|
843
860
|
_parsePluralRule: function (sRule) {
|
844
|
-
var OP_OR = 'or', OP_AND = 'and', OP_MOD = '%', OP_EQ = '=', OP_NEQ = '!=', OPD_N = 'n', OPD_I = 'i', OPD_F = 'f', OPD_T = 't', OPD_V = 'v', OPD_W = 'w', RANGE = '..', SEP = ',';
|
861
|
+
var OP_OR = 'or', OP_AND = 'and', OP_MOD = '%', OP_EQ = '=', OP_NEQ = '!=', OPD_N = 'n', OPD_I = 'i', OPD_F = 'f', OPD_T = 't', OPD_V = 'v', OPD_W = 'w', OPD_C = 'c', OPD_E = 'e', RANGE = '..', SEP = ',';
|
845
862
|
var i = 0, aTokens;
|
846
863
|
aTokens = sRule.split(' ');
|
847
864
|
function accept(sToken) {
|
@@ -935,6 +952,14 @@ var LocaleData = BaseObject.extend('sap.ui.core.LocaleData', {
|
|
935
952
|
return function (o) {
|
936
953
|
return o.w;
|
937
954
|
};
|
955
|
+
} else if (accept(OPD_C)) {
|
956
|
+
return function (o) {
|
957
|
+
return o.c;
|
958
|
+
};
|
959
|
+
} else if (accept(OPD_E)) {
|
960
|
+
return function (o) {
|
961
|
+
return o.c;
|
962
|
+
};
|
938
963
|
} else {
|
939
964
|
throw new Error('Unknown operand: ' + consume());
|
940
965
|
}
|
@@ -962,28 +987,57 @@ var LocaleData = BaseObject.extend('sap.ui.core.LocaleData', {
|
|
962
987
|
throw new Error('Not completely parsed');
|
963
988
|
}
|
964
989
|
return function (sValue) {
|
965
|
-
var iDotPos
|
990
|
+
var iDotPos, iExponent, sFraction, sFractionNoZeros, sInteger, o, iExponentPos = sValue.search(rEIgnoreCase);
|
991
|
+
iExponent = iExponentPos < 0 ? 0 : parseInt(sValue.slice(iExponentPos + 1));
|
992
|
+
sValue = LocaleData.convertToDecimal(sValue);
|
993
|
+
iDotPos = sValue.indexOf('.');
|
966
994
|
if (iDotPos === -1) {
|
967
|
-
|
995
|
+
sInteger = sValue;
|
968
996
|
sFraction = '';
|
969
997
|
sFractionNoZeros = '';
|
970
998
|
} else {
|
971
|
-
|
972
|
-
sFraction = sValue.
|
973
|
-
sFractionNoZeros = sFraction.replace(
|
999
|
+
sInteger = sValue.slice(0, iDotPos);
|
1000
|
+
sFraction = sValue.slice(iDotPos + 1);
|
1001
|
+
sFractionNoZeros = sFraction.replace(rTrailingZeroes, '');
|
974
1002
|
}
|
975
1003
|
o = {
|
976
1004
|
n: parseFloat(sValue),
|
977
|
-
i: parseInt(
|
1005
|
+
i: parseInt(sInteger),
|
978
1006
|
v: sFraction.length,
|
979
1007
|
w: sFractionNoZeros.length,
|
980
|
-
f: parseInt(sFraction),
|
981
|
-
t: parseInt(sFractionNoZeros)
|
1008
|
+
f: sFraction === '' ? 0 : parseInt(sFraction),
|
1009
|
+
t: sFractionNoZeros === '' ? 0 : parseInt(sFractionNoZeros),
|
1010
|
+
c: iExponent
|
1011
|
+
};
|
1012
|
+
return {
|
1013
|
+
bMatch: fnOr(o),
|
1014
|
+
oOperands: o
|
982
1015
|
};
|
983
|
-
return fnOr(o);
|
984
1016
|
};
|
985
1017
|
}
|
986
1018
|
});
|
1019
|
+
LocaleData.convertToDecimal = function (vValue) {
|
1020
|
+
var iIntegerLength, iExponent, iFractionLength, bNegative, iNewIntegerLength, aResult, sValue = String(vValue);
|
1021
|
+
if (!sValue.includes('e') && !sValue.includes('E')) {
|
1022
|
+
return sValue;
|
1023
|
+
}
|
1024
|
+
aResult = sValue.match(rNumberInScientificNotation);
|
1025
|
+
bNegative = aResult[1] === '-';
|
1026
|
+
sValue = aResult[2].replace('.', '');
|
1027
|
+
iIntegerLength = aResult[3] ? aResult[3].length : 0;
|
1028
|
+
iFractionLength = aResult[4] ? aResult[4].length : 0;
|
1029
|
+
iExponent = parseInt(aResult[5]);
|
1030
|
+
iNewIntegerLength = iIntegerLength + iExponent;
|
1031
|
+
if (iExponent > 0) {
|
1032
|
+
sValue = iExponent < iFractionLength ? sValue.slice(0, iNewIntegerLength) + '.' + sValue.slice(iNewIntegerLength) : sValue = sValue.padEnd(iNewIntegerLength, '0');
|
1033
|
+
} else {
|
1034
|
+
sValue = -iExponent < iIntegerLength ? sValue = sValue.slice(0, iNewIntegerLength) + '.' + sValue.slice(iNewIntegerLength) : sValue = '0.' + sValue.padStart(iFractionLength - iExponent, '0');
|
1035
|
+
}
|
1036
|
+
if (bNegative) {
|
1037
|
+
sValue = '-' + sValue;
|
1038
|
+
}
|
1039
|
+
return sValue;
|
1040
|
+
};
|
987
1041
|
var mCLDRSymbolGroups = {
|
988
1042
|
'Era': {
|
989
1043
|
field: 'era',
|
@@ -1267,7 +1321,7 @@ function getData(oLocale) {
|
|
1267
1321
|
obj[name] = fallbackValue;
|
1268
1322
|
} else if (value === null) {
|
1269
1323
|
delete obj[name];
|
1270
|
-
} else if (typeof value === 'object' && typeof fallbackValue === 'object') {
|
1324
|
+
} else if (typeof value === 'object' && typeof fallbackValue === 'object' && !Array.isArray(value)) {
|
1271
1325
|
merge(value, fallbackValue);
|
1272
1326
|
}
|
1273
1327
|
}
|
@@ -0,0 +1,305 @@
|
|
1
|
+
import Configuration from '../Configuration.js';
|
2
|
+
import TimezoneUtil from '../format/TimezoneUtil.js';
|
3
|
+
var aAllParts = [
|
4
|
+
'year',
|
5
|
+
'month',
|
6
|
+
'day',
|
7
|
+
'hour',
|
8
|
+
'minute',
|
9
|
+
'second',
|
10
|
+
'fractionalSecond'
|
11
|
+
], rIsUTCString = /Z|GMT|:.*[\+|\-]|^([\+|\-]\d{2})?\d{4}(-\d{2}){0,2}$/, aWeekday = [
|
12
|
+
'Sun',
|
13
|
+
'Mon',
|
14
|
+
'Tue',
|
15
|
+
'Wed',
|
16
|
+
'Thu',
|
17
|
+
'Fri',
|
18
|
+
'Sat'
|
19
|
+
], aMonths = [
|
20
|
+
'Jan',
|
21
|
+
'Feb',
|
22
|
+
'Mar',
|
23
|
+
'Apr',
|
24
|
+
'May',
|
25
|
+
'Jun',
|
26
|
+
'Jul',
|
27
|
+
'Aug',
|
28
|
+
'Sep',
|
29
|
+
'Oct',
|
30
|
+
'Nov',
|
31
|
+
'Dec'
|
32
|
+
], mWeekdayToDay = {
|
33
|
+
Sun: 0,
|
34
|
+
Mon: 1,
|
35
|
+
Tue: 2,
|
36
|
+
Wed: 3,
|
37
|
+
Thu: 4,
|
38
|
+
Fri: 5,
|
39
|
+
Sat: 6
|
40
|
+
};
|
41
|
+
function addLeadingZeros(iValue, iLength) {
|
42
|
+
return (iValue < 0 ? '-' : '') + Math.abs(iValue).toString().padStart(iLength, '0');
|
43
|
+
}
|
44
|
+
function UI5Date(vDateParts, sTimezoneID) {
|
45
|
+
var oDateInstance = UI5Date._createDateInstance(vDateParts);
|
46
|
+
Object.defineProperties(this, {
|
47
|
+
sTimezoneID: { value: sTimezoneID },
|
48
|
+
oDate: {
|
49
|
+
value: oDateInstance,
|
50
|
+
writable: true
|
51
|
+
},
|
52
|
+
oDateParts: {
|
53
|
+
value: undefined,
|
54
|
+
writable: true
|
55
|
+
}
|
56
|
+
});
|
57
|
+
if (isNaN(oDateInstance)) {
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
if (vDateParts.length > 1 || vDateParts.length === 1 && typeof vDateParts[0] === 'string' && !rIsUTCString.test(vDateParts[0])) {
|
61
|
+
this._setParts(aAllParts, [
|
62
|
+
oDateInstance.getFullYear(),
|
63
|
+
oDateInstance.getMonth(),
|
64
|
+
oDateInstance.getDate(),
|
65
|
+
oDateInstance.getHours(),
|
66
|
+
oDateInstance.getMinutes(),
|
67
|
+
oDateInstance.getSeconds(),
|
68
|
+
oDateInstance.getMilliseconds()
|
69
|
+
]);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
UI5Date.prototype = Object.create(Date.prototype, { constructor: { value: Date } });
|
73
|
+
UI5Date.prototype[Symbol.toStringTag] = 'Date';
|
74
|
+
UI5Date.prototype._getPart = function (sPart) {
|
75
|
+
var iResult;
|
76
|
+
if (isNaN(this.oDate)) {
|
77
|
+
return NaN;
|
78
|
+
}
|
79
|
+
this.oDateParts = this.oDateParts || TimezoneUtil._getParts(this.oDate, this.sTimezoneID);
|
80
|
+
if (sPart === 'weekday') {
|
81
|
+
return mWeekdayToDay[this.oDateParts.weekday];
|
82
|
+
}
|
83
|
+
iResult = parseInt(this.oDateParts[sPart]);
|
84
|
+
if (sPart === 'month') {
|
85
|
+
iResult -= 1;
|
86
|
+
} else if (sPart === 'year') {
|
87
|
+
if (this.oDateParts.era === 'B') {
|
88
|
+
iResult = 1 - iResult;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
return iResult;
|
92
|
+
};
|
93
|
+
UI5Date.prototype._setParts = function (aParts, aValues) {
|
94
|
+
var i, oCurrentDateParts, oNewDateAsUTCTimestamp, iNewTimestamp, sPart, vValue, oDateParts = {}, iMaxLength = Math.min(aParts.length, aValues.length);
|
95
|
+
if (iMaxLength === 0) {
|
96
|
+
return this.setTime(NaN);
|
97
|
+
}
|
98
|
+
for (i = 0; i < iMaxLength; i += 1) {
|
99
|
+
vValue = parseInt(+aValues[i]);
|
100
|
+
sPart = aParts[i];
|
101
|
+
if (isNaN(vValue)) {
|
102
|
+
return this.setTime(NaN);
|
103
|
+
}
|
104
|
+
if (sPart === 'month') {
|
105
|
+
vValue += 1;
|
106
|
+
} else if (sPart === 'year') {
|
107
|
+
if (vValue <= 0) {
|
108
|
+
vValue = 1 - vValue;
|
109
|
+
oDateParts.era = 'B';
|
110
|
+
} else {
|
111
|
+
oDateParts.era = 'A';
|
112
|
+
}
|
113
|
+
}
|
114
|
+
oDateParts[sPart] = vValue.toString();
|
115
|
+
}
|
116
|
+
if (this.oDateParts) {
|
117
|
+
oCurrentDateParts = this.oDateParts;
|
118
|
+
} else if (isNaN(this.oDate)) {
|
119
|
+
oCurrentDateParts = {
|
120
|
+
day: '1',
|
121
|
+
fractionalSecond: '0',
|
122
|
+
hour: '0',
|
123
|
+
minute: '0',
|
124
|
+
month: '1',
|
125
|
+
second: '0'
|
126
|
+
};
|
127
|
+
} else {
|
128
|
+
oCurrentDateParts = TimezoneUtil._getParts(this.oDate, this.sTimezoneID);
|
129
|
+
}
|
130
|
+
oDateParts = Object.assign({}, oCurrentDateParts, oDateParts);
|
131
|
+
oNewDateAsUTCTimestamp = TimezoneUtil._getDateFromParts(oDateParts);
|
132
|
+
if (isNaN(oNewDateAsUTCTimestamp)) {
|
133
|
+
return this.setTime(NaN);
|
134
|
+
}
|
135
|
+
iNewTimestamp = oNewDateAsUTCTimestamp.getTime() + TimezoneUtil.calculateOffset(oNewDateAsUTCTimestamp, this.sTimezoneID) * 1000;
|
136
|
+
return this.setTime(iNewTimestamp);
|
137
|
+
};
|
138
|
+
UI5Date.prototype.clone = function () {
|
139
|
+
return UI5Date.getInstance(this);
|
140
|
+
};
|
141
|
+
UI5Date.prototype.getDate = function () {
|
142
|
+
return this._getPart('day');
|
143
|
+
};
|
144
|
+
UI5Date.prototype.getDay = function () {
|
145
|
+
return this._getPart('weekday');
|
146
|
+
};
|
147
|
+
UI5Date.prototype.getFullYear = function () {
|
148
|
+
return this._getPart('year');
|
149
|
+
};
|
150
|
+
UI5Date.prototype.getHours = function () {
|
151
|
+
return this._getPart('hour');
|
152
|
+
};
|
153
|
+
UI5Date.prototype.getMilliseconds = function () {
|
154
|
+
return this._getPart('fractionalSecond');
|
155
|
+
};
|
156
|
+
UI5Date.prototype.getMinutes = function () {
|
157
|
+
return this._getPart('minute');
|
158
|
+
};
|
159
|
+
UI5Date.prototype.getMonth = function () {
|
160
|
+
return this._getPart('month');
|
161
|
+
};
|
162
|
+
UI5Date.prototype.getSeconds = function () {
|
163
|
+
return this._getPart('second');
|
164
|
+
};
|
165
|
+
UI5Date.prototype.getTimezoneOffset = function () {
|
166
|
+
return TimezoneUtil.calculateOffset(this.oDate, this.sTimezoneID) / 60;
|
167
|
+
};
|
168
|
+
UI5Date.prototype.getYear = function () {
|
169
|
+
return this._getPart('year') - 1900;
|
170
|
+
};
|
171
|
+
UI5Date.prototype.setDate = function (iDay) {
|
172
|
+
return this._setParts(['day'], arguments);
|
173
|
+
};
|
174
|
+
UI5Date.prototype.setFullYear = function (iYear, iMonth, iDay) {
|
175
|
+
return this._setParts([
|
176
|
+
'year',
|
177
|
+
'month',
|
178
|
+
'day'
|
179
|
+
], arguments);
|
180
|
+
};
|
181
|
+
UI5Date.prototype.setHours = function (iHours, iMinutes, iSeconds, iMilliseconds) {
|
182
|
+
return this._setParts([
|
183
|
+
'hour',
|
184
|
+
'minute',
|
185
|
+
'second',
|
186
|
+
'fractionalSecond'
|
187
|
+
], arguments);
|
188
|
+
};
|
189
|
+
UI5Date.prototype.setMilliseconds = function (iMilliseconds) {
|
190
|
+
return this._setParts(['fractionalSecond'], arguments);
|
191
|
+
};
|
192
|
+
UI5Date.prototype.setMinutes = function (iMinutes, iSeconds, iMilliseconds) {
|
193
|
+
return this._setParts([
|
194
|
+
'minute',
|
195
|
+
'second',
|
196
|
+
'fractionalSecond'
|
197
|
+
], arguments);
|
198
|
+
};
|
199
|
+
UI5Date.prototype.setMonth = function (iMonth, iDay) {
|
200
|
+
return this._setParts([
|
201
|
+
'month',
|
202
|
+
'day'
|
203
|
+
], arguments);
|
204
|
+
};
|
205
|
+
UI5Date.prototype.setSeconds = function (iSeconds, iMilliseconds) {
|
206
|
+
return this._setParts([
|
207
|
+
'second',
|
208
|
+
'fractionalSecond'
|
209
|
+
], arguments);
|
210
|
+
};
|
211
|
+
UI5Date.prototype.setTime = function (iTime) {
|
212
|
+
this.oDateParts = undefined;
|
213
|
+
return this.oDate.setTime(iTime);
|
214
|
+
};
|
215
|
+
UI5Date.prototype.setYear = function (iYear) {
|
216
|
+
return this._setParts(['year'], [parseInt(iYear) + 1900]);
|
217
|
+
};
|
218
|
+
UI5Date.prototype.toDateString = function () {
|
219
|
+
if (isNaN(this.oDate)) {
|
220
|
+
return this.oDate.toDateString();
|
221
|
+
}
|
222
|
+
return aWeekday[this.getDay()] + ' ' + aMonths[this.getMonth()] + ' ' + addLeadingZeros(this.getDate(), 2) + ' ' + addLeadingZeros(this.getFullYear(), 4);
|
223
|
+
};
|
224
|
+
UI5Date.prototype.toString = function () {
|
225
|
+
if (isNaN(this.oDate)) {
|
226
|
+
return this.oDate.toString();
|
227
|
+
}
|
228
|
+
return this.toDateString() + ' ' + this.toTimeString();
|
229
|
+
};
|
230
|
+
UI5Date.prototype.toTimeString = function () {
|
231
|
+
var iHours, iMinutes, sSign, iTimeZoneOffset;
|
232
|
+
if (isNaN(this.oDate)) {
|
233
|
+
return this.oDate.toTimeString();
|
234
|
+
}
|
235
|
+
iTimeZoneOffset = this.getTimezoneOffset();
|
236
|
+
sSign = iTimeZoneOffset > 0 ? '-' : '+';
|
237
|
+
iHours = Math.floor(Math.abs(iTimeZoneOffset) / 60);
|
238
|
+
iMinutes = Math.abs(iTimeZoneOffset) % 60;
|
239
|
+
return addLeadingZeros(this.getHours(), 2) + ':' + addLeadingZeros(this.getMinutes(), 2) + ':' + addLeadingZeros(this.getSeconds(), 2) + ' GMT' + sSign + addLeadingZeros(iHours, 2) + addLeadingZeros(iMinutes, 2);
|
240
|
+
};
|
241
|
+
[
|
242
|
+
'getTime',
|
243
|
+
'getUTCDate',
|
244
|
+
'getUTCDay',
|
245
|
+
'getUTCFullYear',
|
246
|
+
'getUTCHours',
|
247
|
+
'getUTCMilliseconds',
|
248
|
+
'getUTCMinutes',
|
249
|
+
'getUTCMonth',
|
250
|
+
'getUTCSeconds',
|
251
|
+
'toGMTString',
|
252
|
+
'toISOString',
|
253
|
+
'toJSON',
|
254
|
+
'toUTCString',
|
255
|
+
'valueOf'
|
256
|
+
].forEach(function (sMethod) {
|
257
|
+
UI5Date.prototype[sMethod] = function () {
|
258
|
+
return this.oDate[sMethod].apply(this.oDate, arguments);
|
259
|
+
};
|
260
|
+
});
|
261
|
+
[
|
262
|
+
'toLocaleDateString',
|
263
|
+
'toLocaleString',
|
264
|
+
'toLocaleTimeString'
|
265
|
+
].forEach(function (sMethod) {
|
266
|
+
UI5Date.prototype[sMethod] = function (sLocale, oOptions) {
|
267
|
+
return this.oDate[sMethod](sLocale || Configuration.getLanguageTag(), Object.assign({ timeZone: this.sTimezoneID }, oOptions));
|
268
|
+
};
|
269
|
+
});
|
270
|
+
[
|
271
|
+
'setUTCDate',
|
272
|
+
'setUTCFullYear',
|
273
|
+
'setUTCHours',
|
274
|
+
'setUTCMilliseconds',
|
275
|
+
'setUTCMinutes',
|
276
|
+
'setUTCMonth',
|
277
|
+
'setUTCSeconds'
|
278
|
+
].forEach(function (sMethod) {
|
279
|
+
UI5Date.prototype[sMethod] = function () {
|
280
|
+
this.oDateParts = undefined;
|
281
|
+
return this.oDate[sMethod].apply(this.oDate, arguments);
|
282
|
+
};
|
283
|
+
});
|
284
|
+
UI5Date._createDateInstance = function (vParts) {
|
285
|
+
if (vParts[0] instanceof Date) {
|
286
|
+
vParts[0] = vParts[0].valueOf();
|
287
|
+
}
|
288
|
+
return new (Function.prototype.bind.apply(Date, [].concat.apply([null], vParts)))();
|
289
|
+
};
|
290
|
+
UI5Date.getInstance = function () {
|
291
|
+
var sTimezone = Configuration.getTimezone();
|
292
|
+
if (sTimezone !== TimezoneUtil.getLocalTimezone()) {
|
293
|
+
return new UI5Date(arguments, sTimezone);
|
294
|
+
}
|
295
|
+
return UI5Date._createDateInstance(arguments);
|
296
|
+
};
|
297
|
+
UI5Date.checkDate = function (oDate) {
|
298
|
+
if (isNaN(oDate.getTime())) {
|
299
|
+
throw new Error('The given Date is not valid');
|
300
|
+
}
|
301
|
+
if (!(oDate instanceof UI5Date) && Configuration.getTimezone() !== TimezoneUtil.getLocalTimezone()) {
|
302
|
+
throw new Error('Configured time zone requires the parameter \'oDate\' to be an instance of' + ' sap.ui.core.date.UI5Date');
|
303
|
+
}
|
304
|
+
};
|
305
|
+
export default UI5Date;
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import BaseObject from '../../base/Object.js';
|
2
2
|
import Configuration from '../Configuration.js';
|
3
|
-
import Locale from '../Locale.js';
|
4
3
|
import LocaleData from '../LocaleData.js';
|
5
4
|
import _Calendars from './_Calendars.js';
|
6
5
|
import CalendarUtils from './CalendarUtils.js';
|
7
6
|
import CalendarWeekNumbering from './CalendarWeekNumbering.js';
|
7
|
+
import UI5Date from './UI5Date.js';
|
8
8
|
var UniversalDate = BaseObject.extend('sap.ui.core.date.UniversalDate', {
|
9
9
|
constructor: function () {
|
10
10
|
var clDate = UniversalDate.getClass();
|
@@ -19,6 +19,9 @@ UniversalDate.now = function () {
|
|
19
19
|
return Date.now();
|
20
20
|
};
|
21
21
|
UniversalDate.prototype.createDate = function (clDate, aArgs) {
|
22
|
+
if (clDate === Date) {
|
23
|
+
return UI5Date.getInstance.apply(null, aArgs);
|
24
|
+
}
|
22
25
|
switch (aArgs.length) {
|
23
26
|
case 0:
|
24
27
|
return new clDate();
|
@@ -42,10 +45,8 @@ UniversalDate.getInstance = function (oDate, sCalendarType) {
|
|
42
45
|
var clDate, oInstance;
|
43
46
|
if (oDate instanceof UniversalDate) {
|
44
47
|
oDate = oDate.getJSDate();
|
45
|
-
} else if (!oDate) {
|
46
|
-
oDate = new Date();
|
47
48
|
}
|
48
|
-
if (isNaN(oDate.getTime())) {
|
49
|
+
if (oDate && isNaN(oDate.getTime())) {
|
49
50
|
throw new Error('The given date object is invalid');
|
50
51
|
}
|
51
52
|
if (!sCalendarType) {
|
@@ -53,7 +54,7 @@ UniversalDate.getInstance = function (oDate, sCalendarType) {
|
|
53
54
|
}
|
54
55
|
clDate = UniversalDate.getClass(sCalendarType);
|
55
56
|
oInstance = Object.create(clDate.prototype);
|
56
|
-
oInstance.oDate = oDate;
|
57
|
+
oInstance.oDate = oDate ? UI5Date.getInstance(oDate) : UI5Date.getInstance();
|
57
58
|
oInstance.sCalendarType = sCalendarType;
|
58
59
|
return oInstance;
|
59
60
|
};
|
@@ -288,7 +289,7 @@ UniversalDate.getEraByDate = function (sCalendarType, iYear, iMonth, iDay) {
|
|
288
289
|
}
|
289
290
|
};
|
290
291
|
UniversalDate.getCurrentEra = function (sCalendarType) {
|
291
|
-
var oNow =
|
292
|
+
var oNow = UI5Date.getInstance();
|
292
293
|
return this.getEraByDate(sCalendarType, oNow.getFullYear(), oNow.getMonth(), oNow.getDate());
|
293
294
|
};
|
294
295
|
UniversalDate.getEraStartDate = function (sCalendarType, iEra) {
|