@ui5/webcomponents-localization 0.0.0-cf50976ce → 0.0.0-d479b681b

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.
Files changed (190) hide show
  1. package/.eslintignore +1 -1
  2. package/.npsrc.json +3 -0
  3. package/CHANGELOG.md +205 -0
  4. package/{src/Assets-static.js → dist/Assets-static.d.ts} +0 -1
  5. package/dist/Assets-static.js +1 -0
  6. package/dist/Assets-static.js.map +1 -0
  7. package/dist/Assets.d.ts +1 -0
  8. package/dist/Assets.js +1 -0
  9. package/dist/Assets.js.map +1 -0
  10. package/dist/DateFormat.d.ts +6 -0
  11. package/dist/DateFormat.js +6 -2
  12. package/dist/DateFormat.js.map +1 -0
  13. package/dist/LocaleData.d.ts +6 -0
  14. package/dist/LocaleData.js +6 -2
  15. package/dist/LocaleData.js.map +1 -0
  16. package/dist/dates/CalendarDate.d.ts +43 -0
  17. package/dist/dates/CalendarDate.js +171 -207
  18. package/dist/dates/CalendarDate.js.map +1 -0
  19. package/dist/dates/ExtremeDates.d.ts +5 -0
  20. package/dist/dates/ExtremeDates.js +25 -35
  21. package/dist/dates/ExtremeDates.js.map +1 -0
  22. package/dist/dates/UI5Date.d.ts +6 -0
  23. package/dist/dates/UI5Date.js +7 -0
  24. package/dist/dates/UI5Date.js.map +1 -0
  25. package/dist/dates/UniversalDate.d.ts +47 -0
  26. package/dist/dates/UniversalDate.js +5 -0
  27. package/dist/dates/UniversalDate.js.map +1 -0
  28. package/dist/dates/calculateWeekNumber.d.ts +5 -0
  29. package/dist/dates/calculateWeekNumber.js +42 -48
  30. package/dist/dates/calculateWeekNumber.js.map +1 -0
  31. package/dist/dates/convertMonthNumbersToMonthNames.d.ts +16 -0
  32. package/dist/dates/convertMonthNumbersToMonthNames.js +15 -18
  33. package/dist/dates/convertMonthNumbersToMonthNames.js.map +1 -0
  34. package/dist/dates/getDaysInMonth.d.ts +3 -0
  35. package/dist/dates/getDaysInMonth.js +7 -8
  36. package/dist/dates/getDaysInMonth.js.map +1 -0
  37. package/dist/dates/getRoundedTimestamp.d.ts +7 -0
  38. package/dist/dates/getRoundedTimestamp.js +10 -9
  39. package/dist/dates/getRoundedTimestamp.js.map +1 -0
  40. package/dist/dates/getTodayUTCTimestamp.d.ts +7 -0
  41. package/dist/dates/getTodayUTCTimestamp.js +3 -3
  42. package/dist/dates/getTodayUTCTimestamp.js.map +1 -0
  43. package/dist/dates/modifyDateBy.d.ts +13 -0
  44. package/dist/dates/modifyDateBy.js +27 -29
  45. package/dist/dates/modifyDateBy.js.map +1 -0
  46. package/dist/dates/transformDateToSecondaryType.d.ts +7 -0
  47. package/dist/dates/transformDateToSecondaryType.js +13 -15
  48. package/dist/dates/transformDateToSecondaryType.js.map +1 -0
  49. package/dist/features/calendar/Buddhist.js +1 -0
  50. package/dist/features/calendar/Buddhist.js.map +1 -0
  51. package/dist/features/calendar/Gregorian.js +1 -0
  52. package/dist/features/calendar/Gregorian.js.map +1 -0
  53. package/dist/features/calendar/Islamic.js +1 -0
  54. package/dist/features/calendar/Islamic.js.map +1 -0
  55. package/dist/features/calendar/Japanese.js +1 -0
  56. package/dist/features/calendar/Japanese.js.map +1 -0
  57. package/dist/features/calendar/Persian.js +1 -0
  58. package/dist/features/calendar/Persian.js.map +1 -0
  59. package/dist/generated/assets/cldr/ar.json +2816 -5906
  60. package/dist/generated/assets/cldr/ar_EG.json +2816 -5906
  61. package/dist/generated/assets/cldr/ar_SA.json +2815 -5906
  62. package/dist/generated/assets/cldr/bg.json +2733 -4979
  63. package/dist/generated/assets/cldr/ca.json +2680 -4996
  64. package/dist/generated/assets/cldr/cs.json +2716 -5498
  65. package/dist/generated/assets/cldr/cy.json +2797 -5884
  66. package/dist/generated/assets/cldr/da.json +2597 -4888
  67. package/dist/generated/assets/cldr/de.json +2614 -4916
  68. package/dist/generated/assets/cldr/de_AT.json +2614 -4917
  69. package/dist/generated/assets/cldr/de_CH.json +2614 -4915
  70. package/dist/generated/assets/cldr/el.json +2595 -4883
  71. package/dist/generated/assets/cldr/el_CY.json +2595 -4883
  72. package/dist/generated/assets/cldr/en.json +2583 -4971
  73. package/dist/generated/assets/cldr/en_AU.json +2592 -4962
  74. package/dist/generated/assets/cldr/en_GB.json +2584 -4971
  75. package/dist/generated/assets/cldr/en_HK.json +2593 -4977
  76. package/dist/generated/assets/cldr/en_IE.json +2584 -4971
  77. package/dist/generated/assets/cldr/en_IN.json +2588 -4972
  78. package/dist/generated/assets/cldr/en_NZ.json +2584 -4971
  79. package/dist/generated/assets/cldr/en_PG.json +2584 -4972
  80. package/dist/generated/assets/cldr/en_SG.json +2588 -4973
  81. package/dist/generated/assets/cldr/en_ZA.json +2584 -4972
  82. package/dist/generated/assets/cldr/es.json +2640 -4912
  83. package/dist/generated/assets/cldr/es_AR.json +2645 -4914
  84. package/dist/generated/assets/cldr/es_BO.json +2645 -4913
  85. package/dist/generated/assets/cldr/es_CL.json +2645 -4914
  86. package/dist/generated/assets/cldr/es_CO.json +2644 -4913
  87. package/dist/generated/assets/cldr/es_MX.json +2645 -4915
  88. package/dist/generated/assets/cldr/es_PE.json +2645 -4913
  89. package/dist/generated/assets/cldr/es_UY.json +2645 -4915
  90. package/dist/generated/assets/cldr/es_VE.json +2645 -4914
  91. package/dist/generated/assets/cldr/et.json +2599 -4967
  92. package/dist/generated/assets/cldr/fa.json +2618 -4883
  93. package/dist/generated/assets/cldr/fi.json +2726 -5008
  94. package/dist/generated/assets/cldr/fr.json +2590 -4979
  95. package/dist/generated/assets/cldr/fr_BE.json +2590 -4979
  96. package/dist/generated/assets/cldr/fr_CA.json +2605 -4973
  97. package/dist/generated/assets/cldr/fr_CH.json +2607 -4997
  98. package/dist/generated/assets/cldr/fr_LU.json +2590 -4979
  99. package/dist/generated/assets/cldr/he.json +2711 -5378
  100. package/dist/generated/assets/cldr/hi.json +2602 -4829
  101. package/dist/generated/assets/cldr/hr.json +2652 -4919
  102. package/dist/generated/assets/cldr/hu.json +2598 -4856
  103. package/dist/generated/assets/cldr/id.json +2544 -4658
  104. package/dist/generated/assets/cldr/it.json +2590 -4950
  105. package/dist/generated/assets/cldr/it_CH.json +2590 -4950
  106. package/dist/generated/assets/cldr/ja.json +2663 -4830
  107. package/dist/generated/assets/cldr/kk.json +2589 -4725
  108. package/dist/generated/assets/cldr/ko.json +2641 -4738
  109. package/dist/generated/assets/cldr/lt.json +2720 -5481
  110. package/dist/generated/assets/cldr/lv.json +2644 -5112
  111. package/dist/generated/assets/cldr/ms.json +2538 -4515
  112. package/dist/generated/assets/cldr/nb.json +2621 -4977
  113. package/dist/generated/assets/cldr/nl.json +2601 -4884
  114. package/dist/generated/assets/cldr/nl_BE.json +2601 -4884
  115. package/dist/generated/assets/cldr/pl.json +2723 -5176
  116. package/dist/generated/assets/cldr/pt.json +2607 -4805
  117. package/dist/generated/assets/cldr/pt_PT.json +2658 -4940
  118. package/dist/generated/assets/cldr/ro.json +2645 -5090
  119. package/dist/generated/assets/cldr/ru.json +2704 -5407
  120. package/dist/generated/assets/cldr/ru_UA.json +2704 -5407
  121. package/dist/generated/assets/cldr/sk.json +2726 -5370
  122. package/dist/generated/assets/cldr/sl.json +2688 -5340
  123. package/dist/generated/assets/cldr/sr.json +2663 -5126
  124. package/dist/generated/assets/cldr/sr_Latn.json +2666 -5127
  125. package/dist/generated/assets/cldr/sv.json +2631 -5011
  126. package/dist/generated/assets/cldr/th.json +2635 -4797
  127. package/dist/generated/assets/cldr/tr.json +2612 -4979
  128. package/dist/generated/assets/cldr/uk.json +2684 -5353
  129. package/dist/generated/assets/cldr/vi.json +2555 -4673
  130. package/dist/generated/assets/cldr/zh_CN.json +2555 -4632
  131. package/dist/generated/assets/cldr/zh_HK.json +2563 -4640
  132. package/dist/generated/assets/cldr/zh_SG.json +2562 -4640
  133. package/dist/generated/assets/cldr/zh_TW.json +2587 -4728
  134. package/dist/getCachedLocaleDataInstance.d.ts +4 -0
  135. package/dist/getCachedLocaleDataInstance.js +6 -9
  136. package/dist/getCachedLocaleDataInstance.js.map +1 -0
  137. package/dist/locale/getLocaleData.d.ts +11 -0
  138. package/dist/locale/getLocaleData.js +12 -16
  139. package/dist/locale/getLocaleData.js.map +1 -0
  140. package/dist/sap/base/Log.js +28 -29
  141. package/dist/sap/base/assert.js +5 -6
  142. package/dist/sap/base/util/LoaderExtensions.d.ts +4 -0
  143. package/dist/sap/base/util/LoaderExtensions.js +9 -12
  144. package/dist/sap/base/util/LoaderExtensions.js.map +1 -0
  145. package/dist/sap/ui/core/Configuration.d.ts +17 -0
  146. package/dist/sap/ui/core/Configuration.js +21 -0
  147. package/dist/sap/ui/core/Configuration.js.map +1 -0
  148. package/dist/sap/ui/core/Core.d.ts +26 -0
  149. package/dist/sap/ui/core/Core.js +7 -34
  150. package/dist/sap/ui/core/Core.js.map +1 -0
  151. package/dist/sap/ui/core/FormatSettings.d.ts +10 -0
  152. package/dist/sap/ui/core/FormatSettings.js +14 -0
  153. package/dist/sap/ui/core/FormatSettings.js.map +1 -0
  154. package/dist/sap/ui/core/Locale.js +3 -0
  155. package/dist/sap/ui/core/LocaleData.js +151 -22
  156. package/dist/sap/ui/core/date/Buddhist.js +0 -6
  157. package/dist/sap/ui/core/date/CalendarUtils.js +36 -0
  158. package/dist/sap/ui/core/date/CalendarWeekNumbering.js +7 -0
  159. package/dist/sap/ui/core/date/Islamic.js +3 -3
  160. package/dist/sap/ui/core/date/Japanese.js +4 -4
  161. package/dist/sap/ui/core/date/UI5Date.js +305 -0
  162. package/dist/sap/ui/core/date/UniversalDate.js +79 -27
  163. package/dist/sap/ui/core/format/DateFormat.js +463 -349
  164. package/dist/sap/ui/core/format/TimezoneUtil.js +19 -13
  165. package/{package-scripts.js → package-scripts.cjs} +7 -5
  166. package/package.json +7 -5
  167. package/tsconfig.json +14 -0
  168. package/used-modules.txt +4 -1
  169. package/src/Assets.js +0 -2
  170. package/src/DateFormat.js +0 -3
  171. package/src/LocaleData.js +0 -3
  172. package/src/dates/CalendarDate.js +0 -229
  173. package/src/dates/ExtremeDates.js +0 -39
  174. package/src/dates/calculateWeekNumber.js +0 -51
  175. package/src/dates/convertMonthNumbersToMonthNames.js +0 -33
  176. package/src/dates/getDaysInMonth.js +0 -11
  177. package/src/dates/getRoundedTimestamp.js +0 -14
  178. package/src/dates/getTodayUTCTimestamp.js +0 -9
  179. package/src/dates/modifyDateBy.js +0 -42
  180. package/src/dates/transformDateToSecondaryType.js +0 -20
  181. package/src/getCachedLocaleDataInstance.js +0 -13
  182. package/src/locale/getLocaleData.js +0 -27
  183. package/src/sap/base/util/LoaderExtensions.js +0 -17
  184. package/src/sap/ui/core/Core.js +0 -40
  185. /package/{config/.eslintrc.js → .eslintrc.cjs} +0 -0
  186. /package/{src/features/calendar/Buddhist.js → dist/features/calendar/Buddhist.d.ts} +0 -0
  187. /package/{src/features/calendar/Gregorian.js → dist/features/calendar/Gregorian.d.ts} +0 -0
  188. /package/{src/features/calendar/Islamic.js → dist/features/calendar/Islamic.d.ts} +0 -0
  189. /package/{src/features/calendar/Japanese.js → dist/features/calendar/Japanese.d.ts} +0 -0
  190. /package/{src/features/calendar/Persian.js → dist/features/calendar/Persian.d.ts} +0 -0
@@ -1,5 +1,6 @@
1
1
  var TimezoneUtil = {};
2
2
  var sLocalTimezone = "";
3
+ var aSupportedTimezoneIDs;
3
4
  var oIntlDateTimeFormatCache = {
4
5
  _oCache: new Map(),
5
6
  _iCacheLimit: 10,
@@ -19,7 +20,8 @@ var oIntlDateTimeFormatCache = {
19
20
  year: "numeric",
20
21
  timeZone: sTimezone,
21
22
  timeZoneName: "short",
22
- era: "narrow"
23
+ era: "narrow",
24
+ weekday: "short"
23
25
  };
24
26
  var oInstance = new Intl.DateTimeFormat("en-US", oOptions);
25
27
  if (this._oCache.size === this._iCacheLimit) {
@@ -33,6 +35,16 @@ TimezoneUtil.isValidTimezone = function (sTimezone) {
33
35
  if (!sTimezone) {
34
36
  return false;
35
37
  }
38
+ if (Intl.supportedValuesOf) {
39
+ try {
40
+ aSupportedTimezoneIDs = aSupportedTimezoneIDs || Intl.supportedValuesOf("timeZone");
41
+ if (aSupportedTimezoneIDs.includes(sTimezone)) {
42
+ return true;
43
+ }
44
+ } catch (oError) {
45
+ aSupportedTimezoneIDs = [];
46
+ }
47
+ }
36
48
  try {
37
49
  oIntlDateTimeFormatCache.get(sTimezone);
38
50
  return true;
@@ -45,11 +57,9 @@ TimezoneUtil.convertToTimezone = function (oDate, sTargetTimezone) {
45
57
  return TimezoneUtil._getDateFromParts(oFormatParts);
46
58
  };
47
59
  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];
60
+ var sKey, oPart, oDateParts = Object.create(null), oIntlDate = oIntlDateTimeFormatCache.get(sTargetTimezone), oParts = oIntlDate.formatToParts(new Date(oDate.getTime()));
61
+ for (sKey in oParts) {
62
+ oPart = oParts[sKey];
53
63
  if (oPart.type !== "literal") {
54
64
  oDateParts[oPart.type] = oPart.value;
55
65
  }
@@ -57,20 +67,16 @@ TimezoneUtil._getParts = function (oDate, sTargetTimezone) {
57
67
  return oDateParts;
58
68
  };
59
69
  TimezoneUtil._getDateFromParts = function (oParts) {
60
- var oDate = new Date(0);
61
- var iUTCYear = parseInt(oParts.year);
70
+ var oDate = new Date(0), iUTCYear = parseInt(oParts.year);
62
71
  if (oParts.era === "B") {
63
72
  iUTCYear = iUTCYear * -1 + 1;
64
73
  }
65
74
  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));
75
+ oDate.setUTCHours(parseInt(oParts.hour), parseInt(oParts.minute), parseInt(oParts.second), parseInt(oParts.fractionalSecond || 0));
67
76
  return oDate;
68
77
  };
69
78
  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);
79
+ var oFirstGuess = this.convertToTimezone(oDate, sTimezoneSource), iInitialOffset = oDate.getTime() - oFirstGuess.getTime(), oDateSource = new Date(oDate.getTime() + iInitialOffset), oDateTarget = this.convertToTimezone(oDateSource, sTimezoneSource);
74
80
  return (oDateSource.getTime() - oDateTarget.getTime()) / 1000;
75
81
  };
76
82
  TimezoneUtil.getLocalTimezone = function () {
@@ -5,31 +5,33 @@ const esmAbsToRel = resolve.sync("@ui5/webcomponents-tools/lib/esm-abs-to-rel/in
5
5
 
6
6
  const scripts = {
7
7
  clean: "rimraf dist",
8
- lint: "eslint . --config config/.eslintrc.js",
8
+ lint: "eslint .",
9
9
  build: {
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",
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 build.typescript copy.src",
11
11
  "replace-amd": "replace-in-file sap.ui.define define dist/**/*.js",
12
12
  "replace-export-true": `replace-in-file ", /* bExport= */ true" "" dist/**/*.js`,
13
13
  "replace-export-false": `replace-in-file ", /* bExport= */ false" "" dist/**/*.js`,
14
14
  "amd-to-es6": "amdtoes6 --src=dist --replace --glob=**/*.js",
15
15
  "replace-global-core-usage": `node "${replaceGlobalCore}" dist/`,
16
16
  "esm-abs-to-rel": `node "${esmAbsToRel}" dist/`,
17
+ typescript: "tsc",
17
18
  jsonImports: "node ./lib/generate-json-imports/cldr.js"
18
19
  },
20
+ typescript: "tsc",
19
21
  copy: {
20
22
  "used-modules": `node "${copyUsedModules}" ./used-modules.txt dist/`,
21
- cldr: `copy-and-watch "../../node_modules/@openui5/sap.ui.core/src/sap/ui/core/cldr/*.json" dist/generated/assets/cldr/`,
23
+ cldr: `node ./lib/copy-and-strip-cldr/index.js "../../node_modules/@openui5/sap.ui.core/src/sap/ui/core/cldr/" dist/generated/assets/cldr/`,
22
24
  overlay: `copy-and-watch "overlay/**/*.js" dist/`,
23
25
  src: `copy-and-watch "src/**/*.js" dist/`,
24
26
  },
25
27
  watch: {
26
- default: 'nps watch.src',
28
+ default: 'concurrently "nps watch.src" "nps watch.typescript" ',
29
+ typescript: "tsc --watch",
27
30
  src: `nps "copy.src --watch --skip-initial-copy"`,
28
31
  },
29
32
  start: "nps watch",
30
33
  };
31
34
 
32
-
33
35
  module.exports = {
34
36
  scripts,
35
37
  };
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@ui5/webcomponents-localization",
3
- "version": "0.0.0-cf50976ce",
3
+ "version": "0.0.0-d479b681b",
4
4
  "description": "Localization for UI5 Web Components",
5
5
  "author": "SAP SE (https://www.sap.com)",
6
6
  "license": "Apache-2.0",
7
+ "type": "module",
7
8
  "keywords": [
8
9
  "openui5",
9
10
  "sapui5",
@@ -27,13 +28,14 @@
27
28
  "prepublishOnly": "npm run clean && npm run build"
28
29
  },
29
30
  "devDependencies": {
30
- "@openui5/sap.ui.core": "1.101.0",
31
- "@ui5/webcomponents-tools": "0.0.0-cf50976ce",
32
- "chromedriver": "104.0.0",
31
+ "@openui5/sap.ui.core": "1.112.0",
32
+ "@ui5/webcomponents-tools": "0.0.0-d479b681b",
33
+ "chromedriver": "112.0.0",
33
34
  "mkdirp": "^1.0.4",
34
35
  "resolve": "^1.20.0"
35
36
  },
36
37
  "dependencies": {
37
- "@ui5/webcomponents-base": "0.0.0-cf50976ce"
38
+ "@types/openui5": "^1.112.0",
39
+ "@ui5/webcomponents-base": "0.0.0-d479b681b"
38
40
  }
39
41
  }
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "include": ["src/**/*"],
3
+ "compilerOptions": {
4
+ "target": "ES2021",
5
+ // Generate d.ts files
6
+ "declaration": true,
7
+ "outDir": "dist",
8
+ "skipLibCheck": true,
9
+ "sourceMap": true,
10
+ "inlineSources": true,
11
+ "strict": true,
12
+ "moduleResolution": "node",
13
+ },
14
+ }
package/used-modules.txt CHANGED
@@ -17,10 +17,13 @@ sap/ui/core/CalendarType.js
17
17
  sap/ui/core/Locale.js
18
18
  sap/ui/core/LocaleData.js
19
19
  sap/ui/core/date/Buddhist.js
20
+ sap/ui/core/date/CalendarUtils.js
21
+ sap/ui/core/date/CalendarWeekNumbering.js
20
22
  sap/ui/core/date/Gregorian.js
21
23
  sap/ui/core/date/Islamic.js
22
24
  sap/ui/core/date/Japanese.js
23
25
  sap/ui/core/date/Persian.js
26
+ sap/ui/core/date/UI5Date.js
24
27
  sap/ui/core/date/UniversalDate.js
25
28
  sap/ui/core/format/TimezoneUtil.js
26
- sap/ui/core/format/DateFormat.js
29
+ sap/ui/core/format/DateFormat.js
package/src/Assets.js DELETED
@@ -1,2 +0,0 @@
1
- // Currently the base package provides CLDR assets only
2
- import "./generated/json-imports/LocaleData.js";
package/src/DateFormat.js DELETED
@@ -1,3 +0,0 @@
1
- import DateFormat from "./sap/ui/core/format/DateFormat.js";
2
-
3
- export default DateFormat;
package/src/LocaleData.js DELETED
@@ -1,3 +0,0 @@
1
- import LocaleData from "./sap/ui/core/LocaleData.js";
2
-
3
- export default LocaleData;
@@ -1,229 +0,0 @@
1
- import UniversalDate from "../sap/ui/core/date/UniversalDate.js";
2
-
3
- class CalendarDate {
4
- constructor() {
5
- let aArgs = arguments, // eslint-disable-line
6
- oJSDate,
7
- oNow,
8
- sCalendarType;
9
-
10
- switch (aArgs.length) {
11
- case 0: // defaults to the current date
12
- oNow = new Date();
13
- return this.constructor(oNow.getFullYear(), oNow.getMonth(), oNow.getDate());
14
-
15
- case 1: // CalendarDate
16
- case 2: // CalendarDate, sCalendarType
17
- if (!(aArgs[0] instanceof CalendarDate)) {
18
- throw new Error("Invalid arguments: the first argument must be of type sap.ui.unified.calendar.CalendarDate.");
19
- }
20
- sCalendarType = aArgs[1] ? aArgs[1] : aArgs[0]._oUDate.sCalendarType;
21
- // Use source.valueOf() (returns the same point of time regardless calendar type) instead of
22
- // source's getters to avoid non-gregorian Year, Month and Date may be used to construct a Gregorian date
23
- oJSDate = new Date(aArgs[0].valueOf());
24
-
25
- // Make this date really local. Now getters are safe.
26
- oJSDate.setFullYear(oJSDate.getUTCFullYear(), oJSDate.getUTCMonth(), oJSDate.getUTCDate());
27
- oJSDate.setHours(oJSDate.getUTCHours(), oJSDate.getUTCMinutes(), oJSDate.getUTCSeconds(), oJSDate.getUTCMilliseconds());
28
-
29
- this._oUDate = createUniversalUTCDate(oJSDate, sCalendarType);
30
- break;
31
-
32
- case 3: // year, month, date
33
- case 4: // year, month, date, sCalendarType
34
- checkNumericLike(aArgs[0], `Invalid year: ${aArgs[0]}`);
35
- checkNumericLike(aArgs[1], `Invalid month: ${aArgs[1]}`);
36
- checkNumericLike(aArgs[2], `Invalid date: ${aArgs[2]}`);
37
-
38
- oJSDate = new Date(0, 0, 1);
39
- oJSDate.setFullYear(aArgs[0], aArgs[1], aArgs[2]); // 2 digits year is not supported. If so, it is considered as full year as well.
40
-
41
- if (aArgs[3]) {
42
- sCalendarType = aArgs[3];
43
- }
44
- this._oUDate = createUniversalUTCDate(oJSDate, sCalendarType);
45
- break;
46
-
47
- default:
48
- throw new Error(`${"Invalid arguments. Accepted arguments are: 1) oCalendarDate, (optional)calendarType"
49
- + "or 2) year, month, date, (optional) calendarType"}${aArgs}`);
50
- }
51
- }
52
-
53
- getYear() {
54
- return this._oUDate.getUTCFullYear();
55
- }
56
-
57
- setYear(year) {
58
- checkNumericLike(year, `Invalid year: ${year}`);
59
- this._oUDate.setUTCFullYear(year);
60
- return this;
61
- }
62
-
63
- getMonth() {
64
- return this._oUDate.getUTCMonth();
65
- }
66
-
67
- /**
68
- * Sets the given month as ordinal month of the year.
69
- * @param {int} month An integer between 0 and 11, representing the months January through December( or their
70
- * equivalent month names for the given calendar).
71
- * If the specified value is is outside of the expected range, this method attempts to update the date information
72
- * accordingly. For example, if 12 is given as a month, the year will be incremented by 1, and 1 will be used for month.
73
- * @param {int} [date] An integer between 1 and 31, representing the day of the month, but other values are allowed.
74
- * 0 will result in the previous month's last day.
75
- * -1 will result in the day before the previous month's last day.
76
- * 32 will result in:
77
- * - first day of the next month if the current month has 31 days.
78
- * - second day of the next month if the current month has 30 days.
79
- * Other value will result in adding or subtracting days according to the given value.
80
- * @returns {sap.ui.unified.calendar.CalendarDate} <code>this</code> for method chaining.
81
- */
82
- setMonth(month, date) {
83
- checkNumericLike(month, `Invalid month: ${month}`);
84
- if (date || date === 0) {
85
- checkNumericLike(date, `Invalid date: ${date}`);
86
- this._oUDate.setUTCMonth(month, date);
87
- } else {
88
- this._oUDate.setUTCMonth(month);
89
- }
90
- return this;
91
- }
92
-
93
- getDate() {
94
- return this._oUDate.getUTCDate();
95
- }
96
-
97
- setDate(date) {
98
- checkNumericLike(date, `Invalid date: ${date}`);
99
- this._oUDate.setUTCDate(date);
100
- return this;
101
- }
102
-
103
- getDay() {
104
- return this._oUDate.getUTCDay();
105
- }
106
-
107
- getCalendarType() {
108
- return this._oUDate.sCalendarType;
109
- }
110
-
111
- isBefore(oCalendarDate) {
112
- checkCalendarDate(oCalendarDate);
113
- return this.valueOf() < oCalendarDate.valueOf();
114
- }
115
-
116
- isAfter(oCalendarDate) {
117
- checkCalendarDate(oCalendarDate);
118
- return this.valueOf() > oCalendarDate.valueOf();
119
- }
120
-
121
- isSameOrBefore(oCalendarDate) {
122
- checkCalendarDate(oCalendarDate);
123
- return this.valueOf() <= oCalendarDate.valueOf();
124
- }
125
-
126
- isSameOrAfter(oCalendarDate) {
127
- checkCalendarDate(oCalendarDate);
128
- return this.valueOf() >= oCalendarDate.valueOf();
129
- }
130
-
131
- isSame(oCalendarDate) {
132
- checkCalendarDate(oCalendarDate);
133
- return this.valueOf() === oCalendarDate.valueOf();
134
- }
135
-
136
- toLocalJSDate() {
137
- // Use this._oUDate.getTime()(returns the same point of time regardless calendar type) instead of
138
- // this._oUDate's getters to avoid non-gregorian Year, Month and Date to be used to construct a Gregorian date
139
- const oLocalDate = new Date(this._oUDate.getTime());
140
-
141
- // Make this date really local. Now getters are safe.
142
- oLocalDate.setFullYear(oLocalDate.getUTCFullYear(), oLocalDate.getUTCMonth(), oLocalDate.getUTCDate());
143
- oLocalDate.setHours(0, 0, 0, 0);
144
-
145
- return oLocalDate;
146
- }
147
-
148
- toUTCJSDate() {
149
- // Use this._oUDate.getTime()(returns the same point of time regardless calendar type) instead of
150
- // this._oUDate's getters to avoid non-gregorian Year, Month and Date to be used to construct a Gregorian date
151
- const oUTCDate = new Date(this._oUDate.getTime());
152
- oUTCDate.setUTCHours(0, 0, 0, 0);
153
-
154
- return oUTCDate;
155
- }
156
-
157
- toString() {
158
- return `${this._oUDate.sCalendarType}: ${this.getYear()}/${this.getMonth() + 1}/${this.getDate()}`;
159
- }
160
-
161
- valueOf() {
162
- return this._oUDate.getTime();
163
- }
164
-
165
- static fromLocalJSDate(oJSDate, sCalendarType) {
166
- // Cross frame check for a date should be performed here otherwise setDateValue would fail in OPA tests
167
- // because Date object in the test is different than the Date object in the application (due to the iframe).
168
- // We can use jQuery.type or this method:
169
- function isValidDate(date) {
170
- return date && Object.prototype.toString.call(date) === "[object Date]" && !isNaN(date); // eslint-disable-line
171
- }
172
- if (!isValidDate(oJSDate)) {
173
- throw new Error(`Date parameter must be a JavaScript Date object: [${oJSDate}].`);
174
- }
175
- return new CalendarDate(oJSDate.getFullYear(), oJSDate.getMonth(), oJSDate.getDate(), sCalendarType);
176
- }
177
-
178
- static fromTimestamp(iTimestamp, sCalendarType) {
179
- const oCalDate = new CalendarDate(0, 0, 1);
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;
187
- return oCalDate;
188
- }
189
- }
190
-
191
- function createUniversalUTCDate(oDate, sCalendarType) {
192
- if (sCalendarType) {
193
- return UniversalDate.getInstance(createUTCDate(oDate), sCalendarType);
194
- }
195
- return new UniversalDate(createUTCDate(oDate).getTime());
196
- }
197
-
198
- /**
199
- * Creates a JavaScript UTC Date corresponding to the given JavaScript Date.
200
- * @param {Date} oDate JavaScript date object. Time related information is cut.
201
- * @returns {Date} JavaScript date created from the date object, but this time considered as UTC date information.
202
- */
203
- function createUTCDate(oDate) {
204
- const oUTCDate = new Date(Date.UTC(0, 0, 1));
205
-
206
- oUTCDate.setUTCFullYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate());
207
-
208
- return oUTCDate;
209
- }
210
-
211
- function checkCalendarDate(oCalendarDate) {
212
- if (!(oCalendarDate instanceof CalendarDate)) {
213
- throw new Error(`Invalid calendar date: [${oCalendarDate}]. Expected: sap.ui.unified.calendar.CalendarDate`);
214
- }
215
- }
216
-
217
- /**
218
- * Verifies the given value is numeric like, i.e. 3, "3" and throws an error if it is not.
219
- * @param {any} value The value of any type to check. If null or undefined, this method throws an error.
220
- * @param {string} message The message to be used if an error is to be thrown
221
- * @throws will throw an error if the value is null or undefined or is not like a number
222
- */
223
- function checkNumericLike(value, message) {
224
- if (value === undefined || value === Infinity || isNaN(value)) { // eslint-disable-line
225
- throw message;
226
- }
227
- }
228
-
229
- export default CalendarDate;
@@ -1,39 +0,0 @@
1
- import CalendarDate from "./CalendarDate.js";
2
-
3
- const cache = new Map();
4
-
5
- const getMinCalendarDate = primaryCalendarType => {
6
- const key = `min ${primaryCalendarType}`;
7
-
8
- if (!cache.has(key)) {
9
- const minDate = new CalendarDate(1, 0, 1, primaryCalendarType);
10
- minDate.setYear(1);
11
- minDate.setMonth(0);
12
- minDate.setDate(1);
13
- cache.set(key, minDate);
14
- }
15
-
16
- return cache.get(key);
17
- };
18
-
19
- const getMaxCalendarDate = primaryCalendarType => {
20
- const key = `max ${primaryCalendarType}`;
21
-
22
- if (!cache.has(key)) {
23
- const maxDate = new CalendarDate(1, 0, 1, primaryCalendarType);
24
- maxDate.setYear(9999);
25
- maxDate.setMonth(11);
26
- const tempDate = new CalendarDate(maxDate, primaryCalendarType);
27
- tempDate.setDate(1);
28
- tempDate.setMonth(tempDate.getMonth() + 1, 0);
29
- maxDate.setDate(tempDate.getDate());// 31st for Gregorian Calendar
30
- cache.set(key, maxDate);
31
- }
32
-
33
- return cache.get(key);
34
- };
35
-
36
- export {
37
- getMinCalendarDate,
38
- getMaxCalendarDate,
39
- };
@@ -1,51 +0,0 @@
1
- import UniversalDate from "../sap/ui/core/date/UniversalDate.js";
2
-
3
- const calculateWeekNumber = (confFirstDayOfWeek, oDate, iYear, oLocale, oLocaleData) => {
4
- let iWeekNum = 0;
5
- let iWeekDay = 0;
6
- const iFirstDayOfWeek = Number.isInteger(confFirstDayOfWeek) ? confFirstDayOfWeek : oLocaleData.getFirstDayOfWeek();
7
-
8
- // search Locale for containing "en-US", since sometimes
9
- // when any user settings have been defined, subtag "sapufmt" is added to the locale name
10
- // this is described inside sap.ui.core.Configuration file
11
- if (oLocale && (oLocale.getLanguage() === "en" && oLocale.getRegion() === "US")) {
12
- /*
13
- * in US the week starts with Sunday
14
- * The first week of the year starts with January 1st. But Dec. 31 is still in the last year
15
- * So the week beginning in December and ending in January has 2 week numbers
16
- */
17
- const oJanFirst = new UniversalDate(oDate.getTime());
18
- oJanFirst.setUTCFullYear(iYear, 0, 1);
19
- iWeekDay = oJanFirst.getUTCDay();
20
-
21
- // get the date for the same weekday like jan 1.
22
- const oCheckDate = new UniversalDate(oDate.getTime());
23
- oCheckDate.setUTCDate(oCheckDate.getUTCDate() - oCheckDate.getUTCDay() + iWeekDay);
24
-
25
- iWeekNum = Math.round((oCheckDate.getTime() - oJanFirst.getTime()) / 86400000 / 7) + 1;
26
- } else {
27
- // normally the first week of the year is the one where the first Thursday of the year is
28
- // find Thursday of this week
29
- // if the checked day is before the 1. day of the week use a day of the previous week to check
30
- const oThursday = new UniversalDate(oDate.getTime());
31
- oThursday.setUTCDate(oThursday.getUTCDate() - iFirstDayOfWeek);
32
- iWeekDay = oThursday.getUTCDay();
33
- oThursday.setUTCDate(oThursday.getUTCDate() - iWeekDay + 4);
34
-
35
- const oFirstDayOfYear = new UniversalDate(oThursday.getTime());
36
- oFirstDayOfYear.setUTCMonth(0, 1);
37
- iWeekDay = oFirstDayOfYear.getUTCDay();
38
- let iAddDays = 0;
39
- if (iWeekDay > 4) {
40
- iAddDays = 7; // first day of year is after Thursday, so first Thursday is in the next week
41
- }
42
- const oFirstThursday = new UniversalDate(oFirstDayOfYear.getTime());
43
- oFirstThursday.setUTCDate(1 - iWeekDay + 4 + iAddDays);
44
-
45
- iWeekNum = Math.round((oThursday.getTime() - oFirstThursday.getTime()) / 86400000 / 7) + 1;
46
- }
47
-
48
- return iWeekNum;
49
- };
50
-
51
- export default calculateWeekNumber;
@@ -1,33 +0,0 @@
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;
@@ -1,11 +0,0 @@
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;
@@ -1,14 +0,0 @@
1
- /**
2
- * Returns a timestamp with only the year, month and day (with zero hours, minutes and seconds) and without 000 for milliseconds
3
- * @param millisecondsUTC
4
- * @returns {number}
5
- */
6
- const getRoundedTimestamp = millisecondsUTC => {
7
- if (!millisecondsUTC) {
8
- millisecondsUTC = new Date().getTime();
9
- }
10
- const rounded = millisecondsUTC - (millisecondsUTC % (24 * 60 * 60 * 1000));
11
- return rounded / 1000;
12
- };
13
-
14
- export default getRoundedTimestamp;
@@ -1,9 +0,0 @@
1
- import CalendarDate from "./CalendarDate.js";
2
-
3
- /**
4
- * Returns a UTC timestamp representing today
5
- * @public
6
- */
7
- const getTodayUTCTimestamp = primaryCalendarType => CalendarDate.fromLocalJSDate(new Date(), primaryCalendarType).valueOf() / 1000;
8
-
9
- export default getTodayUTCTimestamp;
@@ -1,42 +0,0 @@
1
- import CalendarDate from "./CalendarDate.js";
2
-
3
- /**
4
- * Adds or subtracts a given amount of days/months/years from a date.
5
- * If minDate or maxDate are given, the result will be enforced within these limits
6
- *
7
- * @param date CalendarDate instance
8
- * @param amount how many days/months/years to add (can be a negative number)
9
- * @param unit what to modify: "day", "month" or "year"
10
- * @param minDate minimum date to enforce
11
- * @param maxDate maximum date to enforce
12
- */
13
- const modifyDateBy = (date, amount, unit, minDate = null, maxDate = null) => {
14
- const newDate = new CalendarDate(date);
15
- if (unit === "day") {
16
- newDate.setDate(date.getDate() + amount);
17
- } else if (unit === "month") {
18
- newDate.setMonth(date.getMonth() + amount);
19
- const stillSameMonth = amount === -1 && newDate.getMonth() === date.getMonth(); // f.e. PageUp remained in the same month
20
- const monthSkipped = amount === 1 && newDate.getMonth() - date.getMonth() > 1; // f.e. PageDown skipped a whole month
21
- if (stillSameMonth || monthSkipped) { // Select the last day of the month in any of these 2 scenarios
22
- newDate.setDate(0);
23
- }
24
- } else {
25
- newDate.setYear(date.getYear() + amount);
26
- if (newDate.getMonth() !== date.getMonth()) { // f.e. 29th Feb to next/prev year
27
- newDate.setDate(0); // Select the last day of the month
28
- }
29
- }
30
-
31
- if (minDate && newDate.valueOf() < minDate.valueOf()) {
32
- return new CalendarDate(minDate);
33
- }
34
-
35
- if (maxDate && newDate.valueOf() > maxDate.valueOf()) {
36
- return new CalendarDate(maxDate);
37
- }
38
-
39
- return newDate;
40
- };
41
-
42
- export default modifyDateBy;
@@ -1,20 +0,0 @@
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;
@@ -1,13 +0,0 @@
1
- import LocaleData from "./LocaleData.js";
2
-
3
- const cache = new Map();
4
-
5
- const getCachedLocaleDataInstance = locale => {
6
- if (!cache.has(locale)) {
7
- cache.set(locale, LocaleData.getInstance(locale));
8
- }
9
-
10
- return cache.get(locale);
11
- };
12
-
13
- export default getCachedLocaleDataInstance;