@ui5/webcomponents-localization 0.0.0-d849bec2c → 0.0.0-dc3ccac50

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 (110) hide show
  1. package/.eslintignore +1 -0
  2. package/CHANGELOG.md +72 -0
  3. package/README.md +32 -1
  4. package/dist/Assets-static.js +2 -0
  5. package/dist/dates/CalendarDate.js +22 -2
  6. package/dist/dates/ExtremeDates.js +39 -0
  7. package/dist/dates/getRoundedTimestamp.js +14 -0
  8. package/dist/dates/getTodayUTCTimestamp.js +9 -0
  9. package/dist/dates/modifyDateBy.js +42 -0
  10. package/dist/generated/assets/cldr/ar.json +5 -3
  11. package/dist/generated/assets/cldr/ar_EG.json +5 -3
  12. package/dist/generated/assets/cldr/ar_SA.json +5 -3
  13. package/dist/generated/assets/cldr/bg.json +5 -3
  14. package/dist/generated/assets/cldr/ca.json +5 -3
  15. package/dist/generated/assets/cldr/cs.json +5 -3
  16. package/dist/generated/assets/cldr/cy.json +5886 -0
  17. package/dist/generated/assets/cldr/da.json +5 -3
  18. package/dist/generated/assets/cldr/de.json +5 -3
  19. package/dist/generated/assets/cldr/de_AT.json +5 -3
  20. package/dist/generated/assets/cldr/de_CH.json +5 -3
  21. package/dist/generated/assets/cldr/el.json +5 -3
  22. package/dist/generated/assets/cldr/el_CY.json +5 -3
  23. package/dist/generated/assets/cldr/en.json +6 -3
  24. package/dist/generated/assets/cldr/en_AU.json +5 -3
  25. package/dist/generated/assets/cldr/en_GB.json +5 -3
  26. package/dist/generated/assets/cldr/en_HK.json +5 -3
  27. package/dist/generated/assets/cldr/en_IE.json +5 -3
  28. package/dist/generated/assets/cldr/en_IN.json +5 -3
  29. package/dist/generated/assets/cldr/en_NZ.json +5 -3
  30. package/dist/generated/assets/cldr/en_PG.json +5 -3
  31. package/dist/generated/assets/cldr/en_SG.json +5 -3
  32. package/dist/generated/assets/cldr/en_ZA.json +5 -3
  33. package/dist/generated/assets/cldr/es.json +5 -3
  34. package/dist/generated/assets/cldr/es_AR.json +5 -3
  35. package/dist/generated/assets/cldr/es_BO.json +5 -3
  36. package/dist/generated/assets/cldr/es_CL.json +5 -3
  37. package/dist/generated/assets/cldr/es_CO.json +5 -3
  38. package/dist/generated/assets/cldr/es_MX.json +5 -3
  39. package/dist/generated/assets/cldr/es_PE.json +5 -3
  40. package/dist/generated/assets/cldr/es_UY.json +5 -3
  41. package/dist/generated/assets/cldr/es_VE.json +5 -3
  42. package/dist/generated/assets/cldr/et.json +5 -3
  43. package/dist/generated/assets/cldr/fa.json +5 -3
  44. package/dist/generated/assets/cldr/fi.json +5 -3
  45. package/dist/generated/assets/cldr/fr.json +5 -3
  46. package/dist/generated/assets/cldr/fr_BE.json +5 -3
  47. package/dist/generated/assets/cldr/fr_CA.json +5 -3
  48. package/dist/generated/assets/cldr/fr_CH.json +5 -3
  49. package/dist/generated/assets/cldr/fr_LU.json +5 -3
  50. package/dist/generated/assets/cldr/he.json +5 -3
  51. package/dist/generated/assets/cldr/hi.json +5 -3
  52. package/dist/generated/assets/cldr/hr.json +5 -3
  53. package/dist/generated/assets/cldr/hu.json +5 -3
  54. package/dist/generated/assets/cldr/id.json +5 -3
  55. package/dist/generated/assets/cldr/it.json +5 -3
  56. package/dist/generated/assets/cldr/it_CH.json +5 -3
  57. package/dist/generated/assets/cldr/ja.json +5 -3
  58. package/dist/generated/assets/cldr/kk.json +5 -3
  59. package/dist/generated/assets/cldr/ko.json +5 -3
  60. package/dist/generated/assets/cldr/lt.json +5 -3
  61. package/dist/generated/assets/cldr/lv.json +5 -3
  62. package/dist/generated/assets/cldr/ms.json +5 -3
  63. package/dist/generated/assets/cldr/nb.json +5 -3
  64. package/dist/generated/assets/cldr/nl.json +5 -3
  65. package/dist/generated/assets/cldr/nl_BE.json +5 -3
  66. package/dist/generated/assets/cldr/pl.json +5 -3
  67. package/dist/generated/assets/cldr/pt.json +5 -3
  68. package/dist/generated/assets/cldr/pt_PT.json +5 -3
  69. package/dist/generated/assets/cldr/ro.json +5 -3
  70. package/dist/generated/assets/cldr/ru.json +5 -3
  71. package/dist/generated/assets/cldr/ru_UA.json +5 -3
  72. package/dist/generated/assets/cldr/sk.json +5 -3
  73. package/dist/generated/assets/cldr/sl.json +5 -3
  74. package/dist/generated/assets/cldr/sr.json +5 -3
  75. package/dist/generated/assets/cldr/sr_Latn.json +5129 -0
  76. package/dist/generated/assets/cldr/sv.json +5 -3
  77. package/dist/generated/assets/cldr/th.json +5 -3
  78. package/dist/generated/assets/cldr/tr.json +5 -3
  79. package/dist/generated/assets/cldr/uk.json +5 -3
  80. package/dist/generated/assets/cldr/vi.json +5 -3
  81. package/dist/generated/assets/cldr/zh_CN.json +5 -3
  82. package/dist/generated/assets/cldr/zh_HK.json +5 -3
  83. package/dist/generated/assets/cldr/zh_SG.json +5 -3
  84. package/dist/generated/assets/cldr/zh_TW.json +5 -3
  85. package/dist/generated/json-imports/LocaleData-static.js +89 -0
  86. package/dist/generated/json-imports/LocaleData.js +87 -91
  87. package/dist/getCachedLocaleDataInstance.js +13 -0
  88. package/dist/sap/base/Log.js +2 -10
  89. package/dist/sap/base/assert.js +1 -5
  90. package/dist/sap/base/util/LoaderExtensions.js +12 -2
  91. package/dist/sap/base/util/array/uniqueSort.js +7 -7
  92. package/dist/sap/base/util/deepEqual.js +1 -5
  93. package/dist/sap/ui/base/Interface.js +3 -5
  94. package/dist/sap/ui/base/Metadata.js +1 -3
  95. package/dist/sap/ui/base/Object.js +26 -2
  96. package/dist/sap/ui/core/Locale.js +57 -31
  97. package/dist/sap/ui/core/LocaleData.js +28 -1502
  98. package/dist/sap/ui/core/date/UniversalDate.js +7 -5
  99. package/dist/sap/ui/core/format/DateFormat.js +40 -27
  100. package/hash.txt +1 -0
  101. package/package-scripts.js +14 -5
  102. package/package.json +12 -14
  103. package/src/Assets-static.js +2 -0
  104. package/src/dates/CalendarDate.js +22 -2
  105. package/src/dates/ExtremeDates.js +39 -0
  106. package/src/dates/getRoundedTimestamp.js +14 -0
  107. package/src/dates/getTodayUTCTimestamp.js +9 -0
  108. package/src/dates/modifyDateBy.js +42 -0
  109. package/src/getCachedLocaleDataInstance.js +13 -0
  110. package/src/sap/base/util/LoaderExtensions.js +12 -2
@@ -20,7 +20,7 @@ UniversalDate.prototype.createDate = function (clDate, aArgs) {
20
20
  case 0:
21
21
  return new clDate();
22
22
  case 1:
23
- return new clDate(aArgs[0]);
23
+ return new clDate(aArgs[0] instanceof Date ? aArgs[0].getTime() : aArgs[0]);
24
24
  case 2:
25
25
  return new clDate(aArgs[0], aArgs[1]);
26
26
  case 3:
@@ -39,6 +39,8 @@ UniversalDate.getInstance = function (oDate, sCalendarType) {
39
39
  var clDate, oInstance;
40
40
  if (oDate instanceof UniversalDate) {
41
41
  oDate = oDate.getJSDate();
42
+ } else if (!oDate) {
43
+ oDate = new Date();
42
44
  }
43
45
  if (!sCalendarType) {
44
46
  sCalendarType = Core.getConfiguration().getCalendarType();
@@ -160,8 +162,8 @@ UniversalDate.prototype.getTimezoneLong = function () {
160
162
  };
161
163
  var iMillisecondsInWeek = 7 * 24 * 60 * 60 * 1000;
162
164
  UniversalDate.getWeekByDate = function (sCalendarType, iYear, iMonth, iDay) {
163
- var oLocale = Core.getConfiguration().getFormatSettings().getFormatLocale(), clDate = this.getClass(sCalendarType), oFirstDay = getFirstDayOfFirstWeek(clDate, iYear), oDate = new clDate(clDate.UTC(iYear, iMonth, iDay)), iWeek, iLastYear, iNextYear, oLastFirstDay, oNextFirstDay;
164
- if (oLocale.getRegion() === 'US') {
165
+ var oLocale = Core.getConfiguration().getFormatSettings().getFormatLocale(), oLocaleData = LocaleData.getInstance(oLocale), clDate = this.getClass(sCalendarType), oFirstDay = getFirstDayOfFirstWeek(clDate, iYear), oDate = new clDate(clDate.UTC(iYear, iMonth, iDay)), iWeek, iLastYear, iNextYear, oLastFirstDay, oNextFirstDay;
166
+ if (oLocaleData.firstDayStartsFirstWeek()) {
165
167
  iWeek = calculateWeeks(oFirstDay, oDate);
166
168
  } else {
167
169
  iLastYear = iYear - 1;
@@ -184,8 +186,8 @@ UniversalDate.getWeekByDate = function (sCalendarType, iYear, iMonth, iDay) {
184
186
  };
185
187
  };
186
188
  UniversalDate.getFirstDateOfWeek = function (sCalendarType, iYear, iWeek) {
187
- var oLocale = Core.getConfiguration().getFormatSettings().getFormatLocale(), clDate = this.getClass(sCalendarType), oFirstDay = getFirstDayOfFirstWeek(clDate, iYear), oDate = new clDate(oFirstDay.valueOf() + iWeek * iMillisecondsInWeek);
188
- if (oLocale.getRegion() === 'US' && iWeek === 0 && oFirstDay.getUTCFullYear() < iYear) {
189
+ var oLocale = Core.getConfiguration().getFormatSettings().getFormatLocale(), oLocaleData = LocaleData.getInstance(oLocale), clDate = this.getClass(sCalendarType), oFirstDay = getFirstDayOfFirstWeek(clDate, iYear), oDate = new clDate(oFirstDay.valueOf() + iWeek * iMillisecondsInWeek), bIsRegionUS = oLocaleData.firstDayStartsFirstWeek();
190
+ if (bIsRegionUS && iWeek === 0 && oFirstDay.getUTCFullYear() < iYear) {
189
191
  return {
190
192
  year: iYear,
191
193
  month: 0,
@@ -350,7 +350,7 @@ var oParseHelper = {
350
350
  value: iFoundIndex === -1 ? null : aList[iFoundIndex]
351
351
  };
352
352
  },
353
- parseTZ: function (sValue, bISO) {
353
+ parseTZ: function (sValue, bColonSeparated) {
354
354
  var iLength = 0;
355
355
  var iTZFactor = sValue.charAt(0) == '+' ? -1 : 1;
356
356
  var sPart;
@@ -358,12 +358,15 @@ var oParseHelper = {
358
358
  sPart = this.findNumbers(sValue.substr(iLength), 2);
359
359
  var iTZDiffHour = parseInt(sPart);
360
360
  iLength += 2;
361
- if (bISO) {
361
+ if (bColonSeparated) {
362
362
  iLength++;
363
363
  }
364
364
  sPart = this.findNumbers(sValue.substr(iLength), 2);
365
- iLength += 2;
366
- var iTZDiff = parseInt(sPart);
365
+ var iTZDiff = 0;
366
+ if (sPart) {
367
+ iLength += 2;
368
+ iTZDiff = parseInt(sPart);
369
+ }
367
370
  return {
368
371
  length: iLength,
369
372
  tzDiff: (iTZDiff + 60 * iTZDiffHour) * iTZFactor
@@ -937,13 +940,17 @@ DateFormat.prototype.oSymbols = {
937
940
  var bPM;
938
941
  var iLength;
939
942
  var sAM = oFormat.aDayPeriods[0], sPM = oFormat.aDayPeriods[1];
940
- var rAMPM = /[aApP](?:\.)?[mM](?:\.)?/;
943
+ var rAMPM = /[aApP](?:\.)?[\x20\xA0]?[mM](?:\.)?/;
941
944
  var aMatch = sValue.match(rAMPM);
942
945
  var bVariant = aMatch && aMatch.index === 0;
943
946
  if (bVariant) {
944
- sValue = aMatch[0].replace(/\./g, '').toLowerCase() + sValue.substring(aMatch[0].length);
947
+ sValue = aMatch[0];
948
+ sAM = sAM.replace(/[\x20\xA0]/g, '');
949
+ sPM = sPM.replace(/[\x20\xA0]/g, '');
950
+ sValue = sValue.replace(/[\x20\xA0]/g, '');
945
951
  sAM = sAM.replace(/\./g, '').toLowerCase();
946
952
  sPM = sPM.replace(/\./g, '').toLowerCase();
953
+ sValue = sValue.replace(/\./g, '').toLowerCase();
947
954
  }
948
955
  if (sValue.indexOf(sAM) === 0) {
949
956
  bPM = false;
@@ -1127,9 +1134,9 @@ DateFormat.prototype.oSymbols = {
1127
1134
  'z': {
1128
1135
  name: 'timezoneGeneral',
1129
1136
  format: function (oField, oDate, bUTC, oFormat) {
1130
- if (oField.digits > 3 && oDate.getTimezoneLong()) {
1137
+ if (oField.digits > 3 && oDate.getTimezoneLong && oDate.getTimezoneLong()) {
1131
1138
  return oDate.getTimezoneLong();
1132
- } else if (oDate.getTimezoneShort()) {
1139
+ } else if (oDate.getTimezoneShort && oDate.getTimezoneShort()) {
1133
1140
  return oDate.getTimezoneShort();
1134
1141
  }
1135
1142
  var sTimeZone = 'GMT';
@@ -1155,13 +1162,13 @@ DateFormat.prototype.oSymbols = {
1155
1162
  iLength = 3;
1156
1163
  } else if (sValue.substring(0, 2) === 'UT') {
1157
1164
  iLength = 2;
1158
- } else if (sValue.charAt(0) == 'Z') {
1165
+ } else if (sValue.charAt(0) === 'Z') {
1159
1166
  iLength = 1;
1160
1167
  iTZDiff = 0;
1161
1168
  } else {
1162
- return { error: 'cannot be parsed correcly by sap.ui.core.format.DateFormat: The given timezone is not supported!' };
1169
+ return { error: 'cannot be parsed correctly by sap.ui.core.format.DateFormat: The given timezone is not supported!' };
1163
1170
  }
1164
- if (sValue.charAt(0) != 'Z') {
1171
+ if (sValue.charAt(0) !== 'Z') {
1165
1172
  var oParsedTZ = oParseHelper.parseTZ(sValue.substr(iLength), true);
1166
1173
  iLength += oParsedTZ.length;
1167
1174
  iTZDiff = oParsedTZ.tzDiff;
@@ -1180,7 +1187,7 @@ DateFormat.prototype.oSymbols = {
1180
1187
  var iHourOffset = Math.floor(iTZOffset / 60);
1181
1188
  var iMinuteOffset = iTZOffset % 60;
1182
1189
  var sTimeZone = '';
1183
- if (!bUTC && iTZOffset != 0) {
1190
+ if (!bUTC) {
1184
1191
  sTimeZone += bPositiveOffset ? '-' : '+';
1185
1192
  sTimeZone += String(iHourOffset).padStart(2, '0');
1186
1193
  sTimeZone += String(iMinuteOffset).padStart(2, '0');
@@ -1202,21 +1209,25 @@ DateFormat.prototype.oSymbols = {
1202
1209
  if (!bUTC && iTZOffset != 0) {
1203
1210
  sTimeZone += bPositiveOffset ? '-' : '+';
1204
1211
  sTimeZone += String(iHourOffset).padStart(2, '0');
1205
- sTimeZone += ':';
1206
- sTimeZone += String(iMinuteOffset).padStart(2, '0');
1212
+ if (oField.digits > 1 || iMinuteOffset > 0) {
1213
+ if (oField.digits === 3 || oField.digits === 5) {
1214
+ sTimeZone += ':';
1215
+ }
1216
+ sTimeZone += String(iMinuteOffset).padStart(2, '0');
1217
+ }
1207
1218
  } else {
1208
1219
  sTimeZone += 'Z';
1209
1220
  }
1210
1221
  return sTimeZone;
1211
1222
  },
1212
1223
  parse: function (sValue, oPart, oFormat, oConfig) {
1213
- if (sValue.charAt(0) == 'Z') {
1224
+ if (sValue.charAt(0) === 'Z') {
1214
1225
  return {
1215
1226
  length: 1,
1216
1227
  tzDiff: 0
1217
1228
  };
1218
1229
  } else {
1219
- return oParseHelper.parseTZ(sValue, true);
1230
+ return oParseHelper.parseTZ(sValue, oPart.digits === 3 || oPart.digits === 5);
1220
1231
  }
1221
1232
  }
1222
1233
  }
@@ -1818,10 +1829,12 @@ function cutDateFields(oDate, iStartIndex) {
1818
1829
  'Seconds',
1819
1830
  'Milliseconds'
1820
1831
  ], sMethodName;
1832
+ var oDateCopy = new Date(oDate.getTime());
1821
1833
  for (var i = iStartIndex; i < aFields.length; i++) {
1822
1834
  sMethodName = 'set' + aFields[iStartIndex];
1823
- oDate[sMethodName].apply(oDate, [0]);
1835
+ oDateCopy[sMethodName].apply(oDateCopy, [0]);
1824
1836
  }
1837
+ return oDateCopy;
1825
1838
  }
1826
1839
  var mRelativeDiffs = {
1827
1840
  year: function (oFromDate, oToDate) {
@@ -1833,28 +1846,28 @@ var mRelativeDiffs = {
1833
1846
  week: function (oFromDate, oToDate, oFormat) {
1834
1847
  var iFromDay = oFormat._adaptDayOfWeek(oFromDate.getDay());
1835
1848
  var iToDay = oFormat._adaptDayOfWeek(oToDate.getDay());
1836
- cutDateFields(oFromDate, 3);
1837
- cutDateFields(oToDate, 3);
1849
+ oFromDate = cutDateFields(oFromDate, 3);
1850
+ oToDate = cutDateFields(oToDate, 3);
1838
1851
  return (oToDate.getTime() - oFromDate.getTime() - (iToDay - iFromDay) * oFormat._mScales.day * 1000) / (oFormat._mScales.week * 1000);
1839
1852
  },
1840
1853
  day: function (oFromDate, oToDate, oFormat) {
1841
- cutDateFields(oFromDate, 3);
1842
- cutDateFields(oToDate, 3);
1854
+ oFromDate = cutDateFields(oFromDate, 3);
1855
+ oToDate = cutDateFields(oToDate, 3);
1843
1856
  return (oToDate.getTime() - oFromDate.getTime()) / (oFormat._mScales.day * 1000);
1844
1857
  },
1845
1858
  hour: function (oFromDate, oToDate, oFormat) {
1846
- cutDateFields(oFromDate, 4);
1847
- cutDateFields(oToDate, 4);
1859
+ oFromDate = cutDateFields(oFromDate, 4);
1860
+ oToDate = cutDateFields(oToDate, 4);
1848
1861
  return (oToDate.getTime() - oFromDate.getTime()) / (oFormat._mScales.hour * 1000);
1849
1862
  },
1850
1863
  minute: function (oFromDate, oToDate, oFormat) {
1851
- cutDateFields(oFromDate, 5);
1852
- cutDateFields(oToDate, 5);
1864
+ oFromDate = cutDateFields(oFromDate, 5);
1865
+ oToDate = cutDateFields(oToDate, 5);
1853
1866
  return (oToDate.getTime() - oFromDate.getTime()) / (oFormat._mScales.minute * 1000);
1854
1867
  },
1855
1868
  second: function (oFromDate, oToDate, oFormat) {
1856
- cutDateFields(oFromDate, 6);
1857
- cutDateFields(oToDate, 6);
1869
+ oFromDate = cutDateFields(oFromDate, 6);
1870
+ oToDate = cutDateFields(oToDate, 6);
1858
1871
  return (oToDate.getTime() - oFromDate.getTime()) / (oFormat._mScales.second * 1000);
1859
1872
  }
1860
1873
  };
package/hash.txt ADDED
@@ -0,0 +1 @@
1
+ 65ggwN6ZkFOPO38ZE2UOXXibHi8=
@@ -1,19 +1,27 @@
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
+ const copyUsedModules = resolve.sync("@ui5/webcomponents-tools/lib/copy-list/index.js");
5
+ const replaceGlobalCore = resolve.sync("@ui5/webcomponents-tools/lib/replace-global-core/index.js");
6
+ 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
+
1
9
  const scripts = {
2
10
  clean: "rimraf dist",
3
11
  lint: "eslint . --config config/.eslintrc.js",
4
12
  build: {
5
- "default": "path-exists dist/ || nps build.all",
13
+ "default": `${UP_TO_DATE} || nps build.all hash`,
6
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",
7
15
  "replace-amd": "replace-in-file sap.ui.define define dist/**/*.js",
8
16
  "replace-export-true": `replace-in-file ", /* bExport= */ true" "" dist/**/*.js`,
9
17
  "replace-export-false": `replace-in-file ", /* bExport= */ false" "" dist/**/*.js`,
10
18
  "amd-to-es6": "amdtoes6 --src=dist --replace --glob=**/*.js",
11
- "replace-global-core-usage": "node ./lib/replace-global-core/index.js dist/",
12
- "esm-abs-to-rel": "node ./lib/esm-abs-to-rel/index.js dist/",
13
- jsonImports: "node ./lib/generate-json-imports/cldr.js",
19
+ "replace-global-core-usage": `node "${replaceGlobalCore}" dist/`,
20
+ "esm-abs-to-rel": `node "${esmAbsToRel}" dist/`,
21
+ jsonImports: "node ./lib/generate-json-imports/cldr.js"
14
22
  },
15
23
  copy: {
16
- "used-modules": "node ./lib/copy-list/index.js ./used-modules.txt dist/",
24
+ "used-modules": `node "${copyUsedModules}" ./used-modules.txt dist/`,
17
25
  cldr: `copy-and-watch "../../node_modules/@openui5/sap.ui.core/src/sap/ui/core/cldr/*.json" dist/generated/assets/cldr/`,
18
26
  overlay: `copy-and-watch "overlay/**/*.js" dist/`,
19
27
  src: `copy-and-watch "src/**/*.js" dist/`,
@@ -23,6 +31,7 @@ const scripts = {
23
31
  src: `nps "copy.src --watch --skip-initial-copy"`,
24
32
  },
25
33
  start: "nps watch",
34
+ hash: `node ${generateHash} dist/ hash.txt`
26
35
  };
27
36
 
28
37
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/webcomponents-localization",
3
- "version": "0.0.0-d849bec2c",
3
+ "version": "0.0.0-dc3ccac50",
4
4
  "description": "Localization for UI5 Web Components",
5
5
  "author": "SAP SE (https://www.sap.com)",
6
6
  "license": "Apache-2.0",
@@ -14,28 +14,26 @@
14
14
  "url": "https://github.com/SAP/ui5-webcomponents.git",
15
15
  "directory": "packages/localization"
16
16
  },
17
+ "exports": {
18
+ "./dist/*": "./dist/*",
19
+ "./package.json": "./package.json",
20
+ "./*": "./dist/*"
21
+ },
17
22
  "scripts": {
18
23
  "clean": "nps clean",
19
24
  "lint": "nps lint",
20
25
  "start": "nps start",
21
26
  "build": "nps build",
27
+ "hash": "nps hash",
22
28
  "prepublishOnly": "npm run clean && npm run build"
23
29
  },
24
30
  "devDependencies": {
25
- "@buxlabs/amd-to-es6": "^0.15.0",
26
- "@openui5/sap.ui.core": "1.76.0",
27
- "@ui5/webcomponents-tools": "0.0.0-d849bec2c",
28
- "chromedriver": "latest",
29
- "copy-and-watch": "^0.1.4",
30
- "escodegen": "^1.11.0",
31
- "esprima": "^4.0.1",
32
- "glob": "^7.1.3",
33
- "mkdirp": "^0.5.1",
34
- "path-exists-cli": "^1.0.0",
35
- "replace-in-file": "^3.4.2",
36
- "rimraf": "^2.6.2"
31
+ "@ui5/webcomponents-tools": "0.0.0-dc3ccac50",
32
+ "chromedriver": "95.0.0",
33
+ "mkdirp": "^1.0.4",
34
+ "resolve": "^1.20.0"
37
35
  },
38
36
  "dependencies": {
39
- "@ui5/webcomponents-base": "0.0.0-d849bec2c"
37
+ "@ui5/webcomponents-base": "0.0.0-dc3ccac50"
40
38
  }
41
39
  }
@@ -0,0 +1,2 @@
1
+ // Currently the base package provides CLDR assets only
2
+ import "./generated/json-imports/LocaleData-static.js";
@@ -64,9 +64,29 @@ class CalendarDate {
64
64
  return this._oUDate.getUTCMonth();
65
65
  }
66
66
 
67
- setMonth(month) {
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) {
68
83
  checkNumericLike(month, `Invalid month: ${month}`);
69
- this._oUDate.setUTCMonth(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
+ }
70
90
  return this;
71
91
  }
72
92
 
@@ -0,0 +1,39 @@
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
+ };
@@ -0,0 +1,14 @@
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;
@@ -0,0 +1,9 @@
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;
@@ -0,0 +1,42 @@
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;
@@ -0,0 +1,13 @@
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;
@@ -1,7 +1,17 @@
1
- import { getModuleContent } from "@ui5/webcomponents-base/dist/asset-registries/LocaleData.js";
1
+ import { getLocaleData } from "@ui5/webcomponents-base/dist/asset-registries/LocaleData.js";
2
+
3
+ const loadResource = moduleName => {
4
+ const moduleFormat = moduleName.match(/sap\/ui\/core\/cldr\/(\w+)\.json/);
5
+ if (!moduleFormat) {
6
+ throw new Error(`Unknown module "${moduleName}"`);
7
+ }
8
+
9
+ const localeId = moduleFormat[1];
10
+ return getLocaleData(localeId);
11
+ };
2
12
 
3
13
  const LoaderExtensions = {
4
- loadResource: getModuleContent,
14
+ loadResource,
5
15
  };
6
16
 
7
17
  export default LoaderExtensions;