@ui5/webcomponents-localization 1.3.1 → 1.6.0
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 +27 -0
- package/README.md +5 -6
- package/dist/dates/CalendarDate.js +7 -1
- package/dist/dates/convertMonthNumbersToMonthNames.js +33 -0
- package/dist/dates/getDaysInMonth.js +11 -0
- package/dist/dates/transformDateToSecondaryType.js +20 -0
- package/dist/generated/assets/cldr/en_AU.json +1 -1
- package/dist/sap/ui/core/Core.js +2 -0
- package/dist/sap/ui/core/Locale.js +10 -0
- package/dist/sap/ui/core/LocaleData.js +29 -3
- package/dist/sap/ui/core/date/UniversalDate.js +6 -0
- package/dist/sap/ui/core/format/DateFormat.js +362 -167
- package/dist/sap/ui/core/format/TimezoneUtil.js +83 -0
- package/package-scripts.js +1 -6
- package/package.json +5 -5
- package/src/dates/CalendarDate.js +7 -1
- package/src/dates/convertMonthNumbersToMonthNames.js +33 -0
- package/src/dates/getDaysInMonth.js +11 -0
- package/src/dates/transformDateToSecondaryType.js +20 -0
- package/src/sap/ui/core/Core.js +2 -0
- package/used-modules.txt +1 -0
- package/hash.txt +0 -1
@@ -0,0 +1,83 @@
|
|
1
|
+
var TimezoneUtil = {};
|
2
|
+
var sLocalTimezone = "";
|
3
|
+
var oIntlDateTimeFormatCache = {
|
4
|
+
_oCache: new Map(),
|
5
|
+
_iCacheLimit: 10,
|
6
|
+
get: function (sTimezone) {
|
7
|
+
var cacheEntry = this._oCache.get(sTimezone);
|
8
|
+
if (cacheEntry) {
|
9
|
+
return cacheEntry;
|
10
|
+
}
|
11
|
+
var oOptions = {
|
12
|
+
hourCycle: "h23",
|
13
|
+
hour: "2-digit",
|
14
|
+
minute: "2-digit",
|
15
|
+
second: "2-digit",
|
16
|
+
fractionalSecondDigits: 3,
|
17
|
+
day: "2-digit",
|
18
|
+
month: "2-digit",
|
19
|
+
year: "numeric",
|
20
|
+
timeZone: sTimezone,
|
21
|
+
timeZoneName: "short",
|
22
|
+
era: "narrow"
|
23
|
+
};
|
24
|
+
var oInstance = new Intl.DateTimeFormat("en-US", oOptions);
|
25
|
+
if (this._oCache.size === this._iCacheLimit) {
|
26
|
+
this._oCache = new Map();
|
27
|
+
}
|
28
|
+
this._oCache.set(sTimezone, oInstance);
|
29
|
+
return oInstance;
|
30
|
+
}
|
31
|
+
};
|
32
|
+
TimezoneUtil.isValidTimezone = function (sTimezone) {
|
33
|
+
if (!sTimezone) {
|
34
|
+
return false;
|
35
|
+
}
|
36
|
+
try {
|
37
|
+
oIntlDateTimeFormatCache.get(sTimezone);
|
38
|
+
return true;
|
39
|
+
} catch (oError) {
|
40
|
+
return false;
|
41
|
+
}
|
42
|
+
};
|
43
|
+
TimezoneUtil.convertToTimezone = function (oDate, sTargetTimezone) {
|
44
|
+
var oFormatParts = this._getParts(oDate, sTargetTimezone);
|
45
|
+
return TimezoneUtil._getDateFromParts(oFormatParts);
|
46
|
+
};
|
47
|
+
TimezoneUtil._getParts = function (oDate, sTargetTimezone) {
|
48
|
+
var oIntlDate = oIntlDateTimeFormatCache.get(sTargetTimezone);
|
49
|
+
var oParts = oIntlDate.formatToParts(new Date(oDate.getTime()));
|
50
|
+
var oDateParts = Object.create(null);
|
51
|
+
for (var sKey in oParts) {
|
52
|
+
var oPart = oParts[sKey];
|
53
|
+
if (oPart.type !== "literal") {
|
54
|
+
oDateParts[oPart.type] = oPart.value;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
return oDateParts;
|
58
|
+
};
|
59
|
+
TimezoneUtil._getDateFromParts = function (oParts) {
|
60
|
+
var oDate = new Date(0);
|
61
|
+
var iUTCYear = parseInt(oParts.year);
|
62
|
+
if (oParts.era === "B") {
|
63
|
+
iUTCYear = iUTCYear * -1 + 1;
|
64
|
+
}
|
65
|
+
oDate.setUTCFullYear(iUTCYear, parseInt(oParts.month) - 1, parseInt(oParts.day));
|
66
|
+
oDate.setUTCHours(parseInt(oParts.hour), parseInt(oParts.minute), parseInt(oParts.second), parseInt(oParts.fractionalSecond));
|
67
|
+
return oDate;
|
68
|
+
};
|
69
|
+
TimezoneUtil.calculateOffset = function (oDate, sTimezoneSource) {
|
70
|
+
var oFirstGuess = this.convertToTimezone(oDate, sTimezoneSource);
|
71
|
+
var iInitialOffset = oDate.getTime() - oFirstGuess.getTime();
|
72
|
+
var oDateSource = new Date(oDate.getTime() + iInitialOffset);
|
73
|
+
var oDateTarget = this.convertToTimezone(oDateSource, sTimezoneSource);
|
74
|
+
return (oDateSource.getTime() - oDateTarget.getTime()) / 1000;
|
75
|
+
};
|
76
|
+
TimezoneUtil.getLocalTimezone = function () {
|
77
|
+
if (sLocalTimezone) {
|
78
|
+
return sLocalTimezone;
|
79
|
+
}
|
80
|
+
sLocalTimezone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
81
|
+
return sLocalTimezone;
|
82
|
+
};
|
83
|
+
export default TimezoneUtil;
|
package/package-scripts.js
CHANGED
@@ -1,17 +1,13 @@
|
|
1
1
|
const resolve = require("resolve");
|
2
|
-
const generateHash = resolve.sync("@ui5/webcomponents-tools/lib/hash/generate.js");
|
3
|
-
const hashIsUpToDate = resolve.sync("@ui5/webcomponents-tools/lib/hash/upToDate.js");
|
4
2
|
const copyUsedModules = resolve.sync("@ui5/webcomponents-tools/lib/copy-list/index.js");
|
5
3
|
const replaceGlobalCore = resolve.sync("@ui5/webcomponents-tools/lib/replace-global-core/index.js");
|
6
4
|
const esmAbsToRel = resolve.sync("@ui5/webcomponents-tools/lib/esm-abs-to-rel/index.js");
|
7
|
-
const UP_TO_DATE = `node "${hashIsUpToDate}" dist/ hash.txt && echo "Up to date."`;
|
8
5
|
|
9
6
|
const scripts = {
|
10
7
|
clean: "rimraf dist",
|
11
8
|
lint: "eslint . --config config/.eslintrc.js",
|
12
9
|
build: {
|
13
|
-
"default":
|
14
|
-
all: "nps lint clean copy.used-modules copy.cldr copy.overlay build.replace-amd build.replace-export-true build.replace-export-false build.amd-to-es6 build.replace-global-core-usage build.esm-abs-to-rel build.jsonImports copy.src",
|
10
|
+
"default": "nps lint clean copy.used-modules copy.cldr copy.overlay build.replace-amd build.replace-export-true build.replace-export-false build.amd-to-es6 build.replace-global-core-usage build.esm-abs-to-rel build.jsonImports copy.src",
|
15
11
|
"replace-amd": "replace-in-file sap.ui.define define dist/**/*.js",
|
16
12
|
"replace-export-true": `replace-in-file ", /* bExport= */ true" "" dist/**/*.js`,
|
17
13
|
"replace-export-false": `replace-in-file ", /* bExport= */ false" "" dist/**/*.js`,
|
@@ -31,7 +27,6 @@ const scripts = {
|
|
31
27
|
src: `nps "copy.src --watch --skip-initial-copy"`,
|
32
28
|
},
|
33
29
|
start: "nps watch",
|
34
|
-
hash: `node ${generateHash} dist/ hash.txt`
|
35
30
|
};
|
36
31
|
|
37
32
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ui5/webcomponents-localization",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.6.0",
|
4
4
|
"description": "Localization for UI5 Web Components",
|
5
5
|
"author": "SAP SE (https://www.sap.com)",
|
6
6
|
"license": "Apache-2.0",
|
@@ -24,16 +24,16 @@
|
|
24
24
|
"lint": "nps lint",
|
25
25
|
"start": "nps start",
|
26
26
|
"build": "nps build",
|
27
|
-
"hash": "nps hash",
|
28
27
|
"prepublishOnly": "npm run clean && npm run build"
|
29
28
|
},
|
30
29
|
"devDependencies": {
|
31
|
-
"@
|
32
|
-
"
|
30
|
+
"@openui5/sap.ui.core": "1.101.0",
|
31
|
+
"@ui5/webcomponents-tools": "1.6.0",
|
32
|
+
"chromedriver": "102.0.0",
|
33
33
|
"mkdirp": "^1.0.4",
|
34
34
|
"resolve": "^1.20.0"
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@ui5/webcomponents-base": "1.
|
37
|
+
"@ui5/webcomponents-base": "1.6.0"
|
38
38
|
}
|
39
39
|
}
|
@@ -177,7 +177,13 @@ class CalendarDate {
|
|
177
177
|
|
178
178
|
static fromTimestamp(iTimestamp, sCalendarType) {
|
179
179
|
const oCalDate = new CalendarDate(0, 0, 1);
|
180
|
-
|
180
|
+
let oUDate;
|
181
|
+
try {
|
182
|
+
oUDate = UniversalDate.getInstance(new Date(iTimestamp), sCalendarType);
|
183
|
+
} catch (e) {
|
184
|
+
oUDate = new Date(NaN); // UniversalDate.getInstance may now throw an Exception - keep the old behavior
|
185
|
+
}
|
186
|
+
oCalDate._oUDate = oUDate;
|
181
187
|
return oCalDate;
|
182
188
|
}
|
183
189
|
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js";
|
2
|
+
import getCachedLocaleDataInstance from "../getCachedLocaleDataInstance.js";
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Convert month number to month name (text).
|
6
|
+
* If the numbers of the two months are the same you will get the name of the month,
|
7
|
+
* otherwise you will get the two names separated by a dash
|
8
|
+
*
|
9
|
+
* @param firstMonth CalendarDate Month
|
10
|
+
* @param lastMonth CalendarDate Month
|
11
|
+
* @param calendarType calendar type
|
12
|
+
* @returns {String}
|
13
|
+
*/
|
14
|
+
const convertMonthNumbersToMonthNames = (firstMonth, lastMonth, calendarType) => {
|
15
|
+
const localeData = getCachedLocaleDataInstance(getLocale());
|
16
|
+
const pattern = localeData.getIntervalPattern();
|
17
|
+
const secondaryMonthsNames = localeData.getMonthsStandAlone("abbreviated", calendarType);
|
18
|
+
const secondaryMonthsNamesWide = localeData.getMonthsStandAlone("wide", calendarType);
|
19
|
+
|
20
|
+
if (firstMonth === lastMonth) {
|
21
|
+
return {
|
22
|
+
text: localeData.getMonths("abbreviated", calendarType)[firstMonth],
|
23
|
+
textInfo: localeData.getMonths("wide", calendarType)[firstMonth],
|
24
|
+
};
|
25
|
+
}
|
26
|
+
|
27
|
+
return {
|
28
|
+
text: pattern.replace(/\{0\}/, secondaryMonthsNames[firstMonth]).replace(/\{1\}/, secondaryMonthsNames[lastMonth]),
|
29
|
+
textInfo: pattern.replace(/\{0\}/, secondaryMonthsNamesWide[firstMonth]).replace(/\{1\}/, secondaryMonthsNamesWide[lastMonth]),
|
30
|
+
};
|
31
|
+
};
|
32
|
+
|
33
|
+
export default convertMonthNumbersToMonthNames;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import CalendarDate from "./CalendarDate.js";
|
2
|
+
|
3
|
+
const getDaysInMonth = date => {
|
4
|
+
const tempCalendarDate = new CalendarDate(date);
|
5
|
+
tempCalendarDate.setDate(1);
|
6
|
+
tempCalendarDate.setMonth(tempCalendarDate.getMonth() + 1);
|
7
|
+
tempCalendarDate.setDate(0);
|
8
|
+
return tempCalendarDate.getDate();
|
9
|
+
};
|
10
|
+
|
11
|
+
export default getDaysInMonth;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import CalendarDate from "./CalendarDate.js";
|
2
|
+
import getDaysInMonth from "./getDaysInMonth.js";
|
3
|
+
|
4
|
+
const transformDateToSecondaryType = (primaryCalendarType, secondaryCalendarType, timeStamp, hasYearPicker) => {
|
5
|
+
let firstDate = CalendarDate.fromLocalJSDate(new Date(timeStamp * 1000), primaryCalendarType);
|
6
|
+
let lastDate = CalendarDate.fromLocalJSDate(new Date(timeStamp * 1000), primaryCalendarType);
|
7
|
+
firstDate.setDate(1);
|
8
|
+
|
9
|
+
if (hasYearPicker) {
|
10
|
+
firstDate.setMonth(0);
|
11
|
+
lastDate.setMonth(11);
|
12
|
+
}
|
13
|
+
|
14
|
+
lastDate.setDate(getDaysInMonth(lastDate));
|
15
|
+
firstDate = new CalendarDate(firstDate, secondaryCalendarType);
|
16
|
+
lastDate = new CalendarDate(lastDate, secondaryCalendarType);
|
17
|
+
return { firstDate, lastDate };
|
18
|
+
};
|
19
|
+
|
20
|
+
export default transformDateToSecondaryType;
|
package/src/sap/ui/core/Core.js
CHANGED
@@ -2,6 +2,7 @@ import { getLanguage } from "@ui5/webcomponents-base/dist/config/Language.js";
|
|
2
2
|
import { getCalendarType } from "@ui5/webcomponents-base/dist/config/CalendarType.js";
|
3
3
|
import getDesigntimePropertyAsArray from "@ui5/webcomponents-base/dist/util/getDesigntimePropertyAsArray.js";
|
4
4
|
import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js";
|
5
|
+
import TimezoneUtil from "./format/TimezoneUtil.js";
|
5
6
|
|
6
7
|
const emptyFn = () => {};
|
7
8
|
|
@@ -24,6 +25,7 @@ const Configuration = {
|
|
24
25
|
getSupportedLanguages: () => getDesigntimePropertyAsArray("$core-i18n-locales:,ar,bg,ca,cs,da,de,el,en,es,et,fi,fr,hi,hr,hu,it,iw,ja,ko,lt,lv,nl,no,pl,pt,ro,ru,sh,sk,sl,sv,th,tr,uk,vi,zh_CN,zh_TW$"),
|
25
26
|
getOriginInfo: emptyFn,
|
26
27
|
getFormatSettings: () => FormatSettings,
|
28
|
+
getTimezone: () => TimezoneUtil.getLocalTimezone(),
|
27
29
|
};
|
28
30
|
|
29
31
|
/**
|
package/used-modules.txt
CHANGED
package/hash.txt
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
WxDe3QUtrOjzNXLHZ65GIiIMnKU=
|