@ui5/webcomponents-localization 1.2.6 → 1.4.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.
@@ -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;
@@ -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": `${UP_TO_DATE} || nps build.all hash`,
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.2.6",
3
+ "version": "1.4.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
- "@ui5/webcomponents-tools": "1.2.6",
32
- "chromedriver": "99.0.0",
30
+ "@openui5/sap.ui.core": "1.101.0",
31
+ "@ui5/webcomponents-tools": "1.4.0",
32
+ "chromedriver": "101.0.0",
33
33
  "mkdirp": "^1.0.4",
34
34
  "resolve": "^1.20.0"
35
35
  },
36
36
  "dependencies": {
37
- "@ui5/webcomponents-base": "1.2.6"
37
+ "@ui5/webcomponents-base": "1.4.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
- oCalDate._oUDate = UniversalDate.getInstance(new Date(iTimestamp), sCalendarType);
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
  }
@@ -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
@@ -22,4 +22,5 @@ sap/ui/core/date/Islamic.js
22
22
  sap/ui/core/date/Japanese.js
23
23
  sap/ui/core/date/Persian.js
24
24
  sap/ui/core/date/UniversalDate.js
25
+ sap/ui/core/format/TimezoneUtil.js
25
26
  sap/ui/core/format/DateFormat.js
package/hash.txt DELETED
@@ -1 +0,0 @@
1
- WxDe3QUtrOjzNXLHZ65GIiIMnKU=