@ui5/webcomponents-localization 1.22.0-rc.1 → 1.22.0-rc.3

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 (129) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/generated/assets/cldr/ar.json +102 -62
  4. package/dist/generated/assets/cldr/ar_EG.json +102 -62
  5. package/dist/generated/assets/cldr/ar_SA.json +102 -62
  6. package/dist/generated/assets/cldr/bg.json +364 -325
  7. package/dist/generated/assets/cldr/ca.json +491 -453
  8. package/dist/generated/assets/cldr/cs.json +431 -324
  9. package/dist/generated/assets/cldr/cy.json +608 -340
  10. package/dist/generated/assets/cldr/da.json +290 -227
  11. package/dist/generated/assets/cldr/de.json +348 -241
  12. package/dist/generated/assets/cldr/de_AT.json +348 -241
  13. package/dist/generated/assets/cldr/de_CH.json +347 -240
  14. package/dist/generated/assets/cldr/el.json +128 -100
  15. package/dist/generated/assets/cldr/el_CY.json +128 -100
  16. package/dist/generated/assets/cldr/en.json +538 -512
  17. package/dist/generated/assets/cldr/en_AU.json +583 -520
  18. package/dist/generated/assets/cldr/en_GB.json +485 -441
  19. package/dist/generated/assets/cldr/en_HK.json +519 -474
  20. package/dist/generated/assets/cldr/en_IE.json +485 -440
  21. package/dist/generated/assets/cldr/en_IN.json +465 -420
  22. package/dist/generated/assets/cldr/en_NZ.json +505 -460
  23. package/dist/generated/assets/cldr/en_PG.json +505 -460
  24. package/dist/generated/assets/cldr/en_SG.json +505 -460
  25. package/dist/generated/assets/cldr/en_ZA.json +485 -440
  26. package/dist/generated/assets/cldr/es.json +709 -456
  27. package/dist/generated/assets/cldr/es_AR.json +687 -434
  28. package/dist/generated/assets/cldr/es_BO.json +721 -468
  29. package/dist/generated/assets/cldr/es_CL.json +567 -422
  30. package/dist/generated/assets/cldr/es_CO.json +485 -339
  31. package/dist/generated/assets/cldr/es_MX.json +734 -481
  32. package/dist/generated/assets/cldr/es_PE.json +409 -372
  33. package/dist/generated/assets/cldr/es_UY.json +433 -396
  34. package/dist/generated/assets/cldr/es_VE.json +453 -416
  35. package/dist/generated/assets/cldr/et.json +340 -307
  36. package/dist/generated/assets/cldr/fa.json +96 -34
  37. package/dist/generated/assets/cldr/fi.json +359 -308
  38. package/dist/generated/assets/cldr/fr.json +347 -321
  39. package/dist/generated/assets/cldr/fr_BE.json +347 -321
  40. package/dist/generated/assets/cldr/fr_CA.json +458 -432
  41. package/dist/generated/assets/cldr/fr_CH.json +290 -264
  42. package/dist/generated/assets/cldr/fr_LU.json +347 -321
  43. package/dist/generated/assets/cldr/he.json +241 -130
  44. package/dist/generated/assets/cldr/hi.json +103 -53
  45. package/dist/generated/assets/cldr/hr.json +467 -410
  46. package/dist/generated/assets/cldr/hu.json +246 -195
  47. package/dist/generated/assets/cldr/id.json +478 -406
  48. package/dist/generated/assets/cldr/it.json +418 -362
  49. package/dist/generated/assets/cldr/it_CH.json +418 -362
  50. package/dist/generated/assets/cldr/ja.json +58 -18
  51. package/dist/generated/assets/cldr/kk.json +562 -398
  52. package/dist/generated/assets/cldr/ko.json +36 -15
  53. package/dist/generated/assets/cldr/lt.json +320 -231
  54. package/dist/generated/assets/cldr/lv.json +184 -120
  55. package/dist/generated/assets/cldr/ms.json +460 -388
  56. package/dist/generated/assets/cldr/nb.json +160 -92
  57. package/dist/generated/assets/cldr/nl.json +621 -373
  58. package/dist/generated/assets/cldr/nl_BE.json +621 -373
  59. package/dist/generated/assets/cldr/pl.json +590 -279
  60. package/dist/generated/assets/cldr/pt.json +696 -334
  61. package/dist/generated/assets/cldr/pt_PT.json +730 -454
  62. package/dist/generated/assets/cldr/ro.json +409 -339
  63. package/dist/generated/assets/cldr/ru.json +317 -279
  64. package/dist/generated/assets/cldr/ru_UA.json +312 -274
  65. package/dist/generated/assets/cldr/sk.json +454 -413
  66. package/dist/generated/assets/cldr/sl.json +118 -80
  67. package/dist/generated/assets/cldr/sr.json +294 -142
  68. package/dist/generated/assets/cldr/sr_Latn.json +972 -824
  69. package/dist/generated/assets/cldr/sv.json +382 -338
  70. package/dist/generated/assets/cldr/th.json +56 -36
  71. package/dist/generated/assets/cldr/tr.json +371 -320
  72. package/dist/generated/assets/cldr/uk.json +340 -290
  73. package/dist/generated/assets/cldr/vi.json +352 -328
  74. package/dist/generated/assets/cldr/zh_CN.json +34 -10
  75. package/dist/generated/assets/cldr/zh_HK.json +33 -9
  76. package/dist/generated/assets/cldr/zh_SG.json +33 -9
  77. package/dist/generated/assets/cldr/zh_TW.json +32 -8
  78. package/dist/sap/base/Event.js +59 -0
  79. package/dist/sap/base/Eventing.js +146 -0
  80. package/dist/sap/base/Log.js +2 -239
  81. package/dist/sap/base/assert.js +28 -1
  82. package/dist/sap/base/config/MemoryConfigurationProvider.js +20 -0
  83. package/dist/sap/base/config.js +17 -0
  84. package/dist/sap/base/i18n/Formatting.js +1130 -0
  85. package/dist/sap/base/i18n/LanguageTag.js +168 -30
  86. package/dist/sap/base/i18n/date/CalendarType.js +36 -1
  87. package/dist/sap/base/i18n/date/CalendarWeekNumbering.js +76 -1
  88. package/dist/sap/base/i18n/date/TimezoneUtils.js +242 -12
  89. package/dist/sap/base/strings/camelize.js +30 -0
  90. package/dist/sap/base/strings/formatMessage.js +88 -15
  91. package/dist/sap/base/util/ObjectPath.d.ts +4 -0
  92. package/dist/sap/base/util/ObjectPath.js +4 -33
  93. package/dist/sap/base/util/ObjectPath.js.map +1 -0
  94. package/dist/sap/base/util/Version.js +157 -0
  95. package/dist/sap/base/util/_merge.js +83 -26
  96. package/dist/sap/base/util/array/uniqueSort.js +37 -15
  97. package/dist/sap/base/util/deepClone.js +102 -0
  98. package/dist/sap/base/util/deepEqual.js +75 -51
  99. package/dist/sap/base/util/extend.js +58 -7
  100. package/dist/sap/base/util/isEmptyObject.js +34 -0
  101. package/dist/sap/base/util/isPlainObject.js +35 -1
  102. package/dist/sap/base/util/now.js +24 -3
  103. package/dist/sap/base/util/resolveReference.js +157 -0
  104. package/dist/sap/base/util/uid.js +27 -0
  105. package/dist/sap/ui/base/DataType.js +657 -0
  106. package/dist/sap/ui/base/Interface.js +47 -1
  107. package/dist/sap/ui/base/Metadata.js +433 -180
  108. package/dist/sap/ui/base/Object.js +284 -48
  109. package/dist/sap/ui/core/CalendarType.js +23 -1
  110. package/dist/sap/ui/core/Locale.js +189 -57
  111. package/dist/sap/ui/core/LocaleData.js +2670 -1380
  112. package/dist/sap/ui/core/Supportability.js +5 -0
  113. package/dist/sap/ui/core/Theming.js +539 -0
  114. package/dist/sap/ui/core/date/Buddhist.js +162 -87
  115. package/dist/sap/ui/core/date/CalendarUtils.js +61 -21
  116. package/dist/sap/ui/core/date/CalendarWeekNumbering.js +29 -1
  117. package/dist/sap/ui/core/date/Gregorian.js +25 -10
  118. package/dist/sap/ui/core/date/Islamic.js +298 -185
  119. package/dist/sap/ui/core/date/Japanese.js +210 -115
  120. package/dist/sap/ui/core/date/Persian.js +324 -195
  121. package/dist/sap/ui/core/date/UI5Date.js +923 -237
  122. package/dist/sap/ui/core/date/UniversalDate.js +1238 -245
  123. package/dist/sap/ui/core/date/_Calendars.js +10 -1
  124. package/dist/sap/ui/core/format/DateFormat.js +3163 -2145
  125. package/dist/sap/ui/core/format/TimezoneUtil.js +23 -1
  126. package/package-scripts.cjs +4 -10
  127. package/package.json +11 -7
  128. package/used-modules.txt +20 -1
  129. package/dist/sap/ui/Device.js +0 -5
@@ -1,35 +1,173 @@
1
+ /**
2
+ * A regular expression that describes language tags according to BCP-47.
3
+ * @see BCP47 "Tags for Identifying Languages" (http://www.ietf.org/rfc/bcp/bcp47.txt)
4
+ *
5
+ * The matching groups are
6
+ * 0=all
7
+ * 1=language (shortest ISO639 code + ext. language sub tags | 4digits (reserved) | registered language sub tags)
8
+ * 2=script (4 letters)
9
+ * 3=region (2 letter language or 3 digits)
10
+ * 4=variants (separated by '-', Note: capturing group contains leading '-' to shorten the regex!)
11
+ * 5=extensions (including leading singleton, multiple extensions separated by '-'.Note: capturing group contains leading '-' to shorten the regex!)
12
+ * 6=private use section (including leading 'x', multiple sections separated by '-')
13
+ *
14
+ * [-------------------- language ----------------------][--- script ---][------- region --------][------------- variants --------------][----------- extensions ------------][------ private use -------]
15
+ */ /*!
16
+ * OpenUI5
17
+ * (c) Copyright 2009-2024 SAP SE or an SAP affiliate company.
18
+ * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
19
+ */
20
+
21
+ //Provides the LanguageTag object module:sap/base/i18n/LanguageTag
22
+
1
23
  var rLanguageTag = /^((?:[A-Z]{2,3}(?:-[A-Z]{3}){0,3})|[A-Z]{4}|[A-Z]{5,8})(?:-([A-Z]{4}))?(?:-([A-Z]{2}|[0-9]{3}))?((?:-[0-9A-Z]{5,8}|-[0-9][0-9A-Z]{3})*)((?:-[0-9A-WYZ](?:-[0-9A-Z]{2,8})+)*)(?:-(X(?:-[0-9A-Z]{1,8})+))?$/i;
2
- var LanguageTag = function (sLanguageTag) {
3
- var aResult = rLanguageTag.exec(sLanguageTag.replace(/_/g, "-"));
4
- if (aResult === null) {
5
- throw new TypeError("The given language tag'" + sLanguageTag + "' does not adhere to BCP-47.");
24
+
25
+ /**
26
+ * Creates an LanguageTag instance.
27
+ * LanguageTag represents a BCP-47 language tag, consisting of a language, script, region, variants, extensions and private use section.
28
+ *
29
+ * @class
30
+ *
31
+ * @param {string} sLanguageTag the language tag identifier, in format en-US or en_US.
32
+ *
33
+ * @author SAP SE
34
+ * @version 1.120.3
35
+ * @public
36
+ * @alias module:sap/base/i18n/LanguageTag
37
+ */
38
+ class LanguageTag {
39
+ /**
40
+ * Get the language.
41
+ *
42
+ * Note that the case might differ from the original script tag
43
+ * (Lower case is enforced as recommended by BCP47/ISO639).
44
+ *
45
+ * @type {string}
46
+ * @public
47
+ */
48
+ language;
49
+
50
+ /**
51
+ * Get the script or <code>null</code> if none was specified.
52
+ *
53
+ * Note that the case might differ from the original language tag
54
+ * (Upper case first letter and lower case reminder enforced as
55
+ * recommended by BCP47/ISO15924)
56
+ *
57
+ * @type {string|null}
58
+ * @public
59
+ */
60
+ script;
61
+
62
+ /**
63
+ * Get the region or <code>null</code> if none was specified.
64
+ *
65
+ * Note that the case might differ from the original script tag
66
+ * (Upper case is enforced as recommended by BCP47/ISO3166-1).
67
+ *
68
+ * @type {string}
69
+ * @public
70
+ */
71
+ region;
72
+
73
+ /**
74
+ * Get the variants as a single string or <code>null</code>.
75
+ *
76
+ * Multiple variants are separated by a dash '-'.
77
+ *
78
+ * @type {string|null}
79
+ * @public
80
+ */
81
+ variant;
82
+
83
+ /**
84
+ * Get the variants as an array of individual variants.
85
+ *
86
+ * The separating dashes are not part of the result.
87
+ * If there is no variant section in the language tag, an empty array is returned.
88
+ *
89
+ * @type {string[]}
90
+ * @public
91
+ */
92
+ variantSubtags;
93
+
94
+ /**
95
+ * Get the extension as a single string or <code>null</code>.
96
+ *
97
+ * The extension always consists of a singleton character (not 'x'),
98
+ * a dash '-' and one or more extension token, each separated
99
+ * again with a dash.
100
+ *
101
+ * @type {string|null}
102
+ * @public
103
+ */
104
+ extension;
105
+
106
+ /**
107
+ * Get the extensions as an array of tokens.
108
+ *
109
+ * The leading singleton and the separating dashes are not part of the result.
110
+ * If there is no extensions section in the language tag, an empty array is returned.
111
+ *
112
+ * @type {string[]}
113
+ * @public
114
+ */
115
+ extensionSubtags;
116
+
117
+ /**
118
+ * Get the private use section or <code>null</code>.
119
+ *
120
+ * @type {string}
121
+ */
122
+ privateUse;
123
+
124
+ /**
125
+ * Get the private use section as an array of tokens.
126
+ *
127
+ * The leading singleton and the separating dashes are not part of the result.
128
+ * If there is no private use section in the language tag, an empty array is returned.
129
+ *
130
+ * @type {string[]}
131
+ */
132
+ privateUseSubtags;
133
+ constructor(sLanguageTag) {
134
+ var aResult = rLanguageTag.exec(sLanguageTag.replace(/_/g, "-"));
135
+ // If the given language tag string cannot be parsed by the regular expression above,
136
+ // we should at least tell the developer why the Core fails to load.
137
+ if (aResult === null) {
138
+ throw new TypeError("The given language tag'" + sLanguageTag + "' does not adhere to BCP-47.");
139
+ }
140
+ this.language = aResult[1] || null;
141
+ this.script = aResult[2] || null;
142
+ this.region = aResult[3] || null;
143
+ this.variant = aResult[4] && aResult[4].slice(1) || null; // remove leading dash from capturing group
144
+ this.variantSubtags = this.variant ? this.variant.split('-') : [];
145
+ this.extension = aResult[5] && aResult[5].slice(1) || null; // remove leading dash from capturing group
146
+ this.extensionSubtags = this.variant ? this.variant.split('-') : [];
147
+ this.privateUse = aResult[6] || null;
148
+ this.privateUseSubtags = this.privateUse ? this.privateUse.slice(2).split('-') : [];
149
+ // convert subtags according to the BCP47 recommendations
150
+ // - language: all lower case
151
+ // - script: lower case with the first letter capitalized
152
+ // - region: all upper case
153
+ if (this.language) {
154
+ this.language = this.language.toLowerCase();
155
+ }
156
+ if (this.script) {
157
+ this.script = this.script.toLowerCase().replace(/^[a-z]/, function ($) {
158
+ return $.toUpperCase();
159
+ });
160
+ }
161
+ if (this.region) {
162
+ this.region = this.region.toUpperCase();
163
+ }
164
+ Object.freeze(this);
6
165
  }
7
- this.language = aResult[1] || null;
8
- this.script = aResult[2] || null;
9
- this.region = aResult[3] || null;
10
- this.variant = aResult[4] && aResult[4].slice(1) || null;
11
- this.variantSubtags = this.variant ? this.variant.split("-") : [];
12
- this.extension = aResult[5] && aResult[5].slice(1) || null;
13
- this.extensionSubtags = this.variant ? this.variant.split("-") : [];
14
- this.privateUse = aResult[6] || null;
15
- this.privateUseSubtags = this.privateUse ? this.privateUse.slice(2).split("-") : [];
16
- if (this.language) {
17
- this.language = this.language.toLowerCase();
166
+ toString() {
167
+ return this.#join(this.language, this.script, this.region, this.variant, this.extension, this.privateUse);
18
168
  }
19
- if (this.script) {
20
- this.script = this.script.toLowerCase().replace(/^[a-z]/, function ($) {
21
- return $.toUpperCase();
22
- });
169
+ #join() {
170
+ return Array.prototype.filter.call(arguments, Boolean).join("-");
23
171
  }
24
- if (this.region) {
25
- this.region = this.region.toUpperCase();
26
- }
27
- Object.freeze(this);
28
- };
29
- LanguageTag.prototype.toString = function () {
30
- return join(this.language, this.script, this.region, this.variant, this.extension, this.privateUse);
31
- };
32
- function join() {
33
- return Array.prototype.filter.call(arguments, Boolean).join("-");
34
172
  }
35
- export default LanguageTag;
173
+ export default LanguageTag;
@@ -1,8 +1,43 @@
1
+ /**
2
+ * The types of <code>Calendar</code>.
3
+ *
4
+ * @enum {string}
5
+ * @alias module:sap/base/i18n/date/CalendarType
6
+ * @public
7
+ * @since 1.120
8
+ */ /*!
9
+ * OpenUI5
10
+ * (c) Copyright 2009-2024 SAP SE or an SAP affiliate company.
11
+ * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
12
+ */
13
+
14
+ // Provides type module:sap/base/i18n/date/CalendarType.
15
+
1
16
  var CalendarType = {
17
+ /**
18
+ * The Gregorian calendar
19
+ * @public
20
+ */
2
21
  Gregorian: "Gregorian",
22
+ /**
23
+ * The Islamic calendar
24
+ * @public
25
+ */
3
26
  Islamic: "Islamic",
27
+ /**
28
+ * The Japanese emperor calendar
29
+ * @public
30
+ */
4
31
  Japanese: "Japanese",
32
+ /**
33
+ * The Persian Jalali calendar
34
+ * @public
35
+ */
5
36
  Persian: "Persian",
37
+ /**
38
+ * The Thai buddhist calendar
39
+ * @public
40
+ */
6
41
  Buddhist: "Buddhist"
7
42
  };
8
- export default CalendarType;
43
+ export default CalendarType;
@@ -1,10 +1,84 @@
1
+ /**
2
+ * The <code>CalendarWeekNumbering</code> enum defines how to calculate calendar weeks. Each
3
+ * value defines:
4
+ * <ul>
5
+ * <li>The first day of the week,</li>
6
+ * <li>the first week of the year.</li>
7
+ * </ul>
8
+ *
9
+ * @enum {string}
10
+ * @public
11
+ * @alias module:sap/base/i18n/date/CalendarWeekNumbering
12
+ * @since 1.120
13
+ */ /*!
14
+ * OpenUI5
15
+ * (c) Copyright 2009-2024 SAP SE or an SAP affiliate company.
16
+ * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
17
+ */
18
+
19
+ // Provides type module:sap/base/i18n/date/CalendarWeekNumbering.
20
+
1
21
  var CalendarWeekNumbering = {
22
+ /**
23
+ * The default calendar week numbering:
24
+ *
25
+ * The framework determines the week numbering scheme; currently it is derived from the
26
+ * active format locale. Future versions of UI5 might select a different week numbering
27
+ * scheme.
28
+ *
29
+ * @public
30
+ */
2
31
  Default: "Default",
32
+ /**
33
+ * Official calendar week numbering in most of Europe (ISO 8601 standard):
34
+ * <ul>
35
+ * <li>Monday is first day of the week,
36
+ * <li>the week containing January 4th is first week of the year.
37
+ * </ul>
38
+ *
39
+ * @public
40
+ */
3
41
  ISO_8601: "ISO_8601",
42
+ /**
43
+ * Official calendar week numbering in much of the Middle East (Middle Eastern calendar):
44
+ * <ul>
45
+ * <li>Saturday is first day of the week,
46
+ * <li>the week containing January 1st is first week of the year.
47
+ * </ul>
48
+ *
49
+ * @public
50
+ */
4
51
  MiddleEastern: "MiddleEastern",
52
+ /**
53
+ * Official calendar week numbering in the United States, Canada, Brazil, Israel, Japan, and
54
+ * other countries (Western traditional calendar):
55
+ * <ul>
56
+ * <li>Sunday is first day of the week,
57
+ * <li>the week containing January 1st is first week of the year.
58
+ * </ul>
59
+ *
60
+ * @public
61
+ */
5
62
  WesternTraditional: "WesternTraditional"
6
63
  };
64
+
65
+ /**
66
+ * Returns an object containing the week configuration values for the given calendar week
67
+ * numbering algorithm.
68
+ *
69
+ * @param {module:sap/base/i18n/date/CalendarWeekNumbering} [sCalendarWeekNumbering=Default]
70
+ * The calendar week numbering algorithm
71
+ * @returns {{firstDayOfWeek: 0|1|2|3|4|5|6, minimalDaysInFirstWeek: 1|2|3|4|5|6|7}|undefined}
72
+ * The week configuration values or <code>undefined</code> if the given calendar week
73
+ * numbering algorithm is "Default"
74
+ *
75
+ * @function
76
+ * @name module:sap/base/i18n/date/CalendarWeekNumbering.getWeekConfigurationValues
77
+ * @private
78
+ */
7
79
  Object.defineProperty(CalendarWeekNumbering, "getWeekConfigurationValues", {
80
+ // configurable : false,
81
+ // enumerable : false,
8
82
  value: function (sCalendarWeekNumbering) {
9
83
  switch (sCalendarWeekNumbering) {
10
84
  case CalendarWeekNumbering.ISO_8601:
@@ -26,5 +100,6 @@ Object.defineProperty(CalendarWeekNumbering, "getWeekConfigurationValues", {
26
100
  return undefined;
27
101
  }
28
102
  }
103
+ // writable : false
29
104
  });
30
- export default CalendarWeekNumbering;
105
+ export default CalendarWeekNumbering;
@@ -1,9 +1,49 @@
1
+ /**
2
+ * Static collection of utility functions to handle time zone related conversions
3
+ *
4
+ * @author SAP SE
5
+ * @version 1.120.3
6
+ * @namespace
7
+ * @alias module:sap/base/i18n/date/TimezoneUtils
8
+ * @private
9
+ * @ui5-restricted sap.ui.core.Configuration, sap/base/i18n/format/DateFormat
10
+ */ /*!
11
+ * OpenUI5
12
+ * (c) Copyright 2009-2024 SAP SE or an SAP affiliate company.
13
+ * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
14
+ */
15
+
1
16
  var TimezoneUtils = {};
17
+
18
+ /**
19
+ * Cache for the (browser's) local IANA timezone ID
20
+ *
21
+ * @type {string}
22
+ */
2
23
  var sLocalTimezone = "";
24
+
25
+ /**
26
+ * Cache for valid time zones provided by <code>Intl.supportedValuesOf("timeZone")</code>
27
+ *
28
+ * @type {Array}
29
+ */
3
30
  var aSupportedTimezoneIDs;
31
+
32
+ /**
33
+ * Cache for Intl.DateTimeFormat instances
34
+ */
4
35
  var oIntlDateTimeFormatCache = {
5
36
  _oCache: new Map(),
37
+ /**
38
+ * When cache limit is reached, it gets cleared
39
+ */
6
40
  _iCacheLimit: 10,
41
+ /**
42
+ * Creates or gets an instance of Intl.DateTimeFormat.
43
+ *
44
+ * @param {string} sTimezone IANA timezone ID
45
+ * @returns {Intl.DateTimeFormat} Intl.DateTimeFormat instance
46
+ */
7
47
  get: function (sTimezone) {
8
48
  var cacheEntry = this._oCache.get(sTimezone);
9
49
  if (cacheEntry) {
@@ -19,11 +59,13 @@ var oIntlDateTimeFormatCache = {
19
59
  month: "2-digit",
20
60
  year: "numeric",
21
61
  timeZone: sTimezone,
22
- timeZoneName: "short",
23
- era: "narrow",
62
+ timeZoneName: 'short',
63
+ era: 'narrow',
24
64
  weekday: "short"
25
65
  };
26
66
  var oInstance = new Intl.DateTimeFormat("en-US", oOptions);
67
+
68
+ // only store a limited number of entries in the cache
27
69
  if (this._oCache.size === this._iCacheLimit) {
28
70
  this._oCache = new Map();
29
71
  }
@@ -31,17 +73,35 @@ var oIntlDateTimeFormatCache = {
31
73
  return oInstance;
32
74
  }
33
75
  };
76
+
77
+ /**
78
+ * Uses the <code>Intl.supportedValuesOf('timeZone')</code> and <code>Intl.DateTimeFormat</code>
79
+ * API to check if the browser can handle the given IANA timezone ID.
80
+ * <code>Intl.supportedValuesOf('timeZone')</code> offers direct access to the list of supported
81
+ * time zones. It is not yet supported by all browsers but if it is supported and the given time
82
+ * zone is in the list it is faster than probing.
83
+ *
84
+ * <code>Intl.supportedValuesOf('timeZone')</code> does not return all IANA timezone IDs which
85
+ * the <code>Intl.DateTimeFormat</code> can handle, e.g. "Japan", "Etc/UTC".
86
+ *
87
+ * @param {string} sTimezone The IANA timezone ID which is checked, e.g <code>"Europe/Berlin"</code>
88
+ * @returns {boolean} Whether the time zone is a valid IANA timezone ID
89
+ * @private
90
+ * @ui5-restricted sap.ui.core.Configuration, sap.ui.core.format.DateFormat
91
+ */
34
92
  TimezoneUtils.isValidTimezone = function (sTimezone) {
35
93
  if (!sTimezone) {
36
94
  return false;
37
95
  }
38
96
  if (Intl.supportedValuesOf) {
39
97
  try {
40
- aSupportedTimezoneIDs = aSupportedTimezoneIDs || Intl.supportedValuesOf("timeZone");
98
+ aSupportedTimezoneIDs = aSupportedTimezoneIDs || Intl.supportedValuesOf('timeZone');
41
99
  if (aSupportedTimezoneIDs.includes(sTimezone)) {
42
100
  return true;
43
101
  }
102
+ // although not contained in the supportedValues it still can be valid, therefore continue
44
103
  } catch (oError) {
104
+ // ignore error
45
105
  aSupportedTimezoneIDs = [];
46
106
  }
47
107
  }
@@ -52,12 +112,60 @@ TimezoneUtils.isValidTimezone = function (sTimezone) {
52
112
  return false;
53
113
  }
54
114
  };
115
+
116
+ /**
117
+ * Converts a date to a specific time zone.
118
+ * The resulting date reflects the given time zone such that the "UTC" Date methods
119
+ * can be used, e.g. Date#getUTCHours() to display the hours in the given time zone.
120
+ *
121
+ * @example
122
+ * var oDate = new Date("2021-10-13T15:22:33Z"); // UTC
123
+ * // time zone difference UTC-4 (DST)
124
+ * TimezoneUtils.convertToTimezone(oDate, "America/New_York");
125
+ * // result is:
126
+ * // 2021-10-13 11:22:33 in America/New_York
127
+ * // same as new Date("2021-10-13T11:22:33Z"); // UTC
128
+ *
129
+ * @param {Date} oDate The date which should be converted.
130
+ * @param {string} sTargetTimezone The target IANA timezone ID, e.g <code>"Europe/Berlin"</code>
131
+ * @returns {Date} The new date in the target time zone.
132
+ * @private
133
+ * @ui5-restricted sap.ui.core.format.DateFormat, sap.ui.unified, sap.m
134
+ */
55
135
  TimezoneUtils.convertToTimezone = function (oDate, sTargetTimezone) {
56
136
  var oFormatParts = this._getParts(oDate, sTargetTimezone);
57
137
  return TimezoneUtils._getDateFromParts(oFormatParts);
58
138
  };
139
+
140
+ /**
141
+ * Uses the <code>Intl.DateTimeFormat</code> API to convert a date to a specific time zone.
142
+ *
143
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts
144
+ * @param {Date} oDate The date which should be converted.
145
+ * @param {string} sTargetTimezone The target IANA timezone ID, e.g <code>"Europe/Berlin"</code>
146
+ * @returns {{
147
+ * day: string,
148
+ * era: string,
149
+ * fractionalSecond: string,
150
+ * hour: string,
151
+ * minute: string,
152
+ * month: string,
153
+ * second: string,
154
+ * timeZoneName: string,
155
+ * weekday: string,
156
+ * year: string
157
+ * }} An object containing the date and time fields considering the target time zone.
158
+ * @private
159
+ */
59
160
  TimezoneUtils._getParts = function (oDate, sTargetTimezone) {
60
- var sKey, oPart, oDateParts = Object.create(null), oIntlDate = oIntlDateTimeFormatCache.get(sTargetTimezone), oParts = oIntlDate.formatToParts(new Date(oDate.getTime()));
161
+ var sKey,
162
+ oPart,
163
+ oDateParts = Object.create(null),
164
+ oIntlDate = oIntlDateTimeFormatCache.get(sTargetTimezone),
165
+ // clone the date object before passing it to the Intl API, to ensure that no
166
+ // UniversalDate gets passed to it;
167
+ // no need to use UI5Date.getInstance as only the UTC timestamp is used
168
+ oParts = oIntlDate.formatToParts(new Date(oDate.getTime()));
61
169
  for (sKey in oParts) {
62
170
  oPart = oParts[sKey];
63
171
  if (oPart.type !== "literal") {
@@ -66,24 +174,146 @@ TimezoneUtils._getParts = function (oDate, sTargetTimezone) {
66
174
  }
67
175
  return oDateParts;
68
176
  };
177
+
178
+ /**
179
+ * Creates a Date from the provided date parts.
180
+ *
181
+ * @param {object} oParts Separated date and time fields as object, see {@link #_getParts}.
182
+ * @returns {Date} Returns the date object created from the provided parts.
183
+ * @private
184
+ */
69
185
  TimezoneUtils._getDateFromParts = function (oParts) {
70
- var oDate = new Date(0), iUTCYear = parseInt(oParts.year);
186
+ // no need to use UI5Date.getInstance as only the UTC timestamp is used
187
+ var oDate = new Date(0),
188
+ iUTCYear = parseInt(oParts.year);
71
189
  if (oParts.era === "B") {
190
+ // The JS Date uses astronomical year numbering which supports year zero and negative
191
+ // year numbers.
192
+ // The Intl.DateTimeFormat API uses eras (no year zero and no negative year numbers).
193
+ // years around zero overview:
194
+ // | Astronomical | In Era
195
+ // | 2 | 2 Anno Domini (era: "A")
196
+ // | 1 | 1 Anno Domini (era: "A")
197
+ // | 0 | 1 Before Christ (era: "B")
198
+ // | -1 | 2 Before Christ (era: "B")
199
+ // | -2 | 3 Before Christ (era: "B")
200
+ // For the conversion to the JS Date the parts returned by the Intl.DateTimeFormat API
201
+ // need to be adapted.
72
202
  iUTCYear = iUTCYear * -1 + 1;
73
203
  }
204
+
205
+ // Date.UTC cannot be used here to be able to support dates before the UNIX epoch
74
206
  oDate.setUTCFullYear(iUTCYear, parseInt(oParts.month) - 1, parseInt(oParts.day));
75
- oDate.setUTCHours(parseInt(oParts.hour), parseInt(oParts.minute), parseInt(oParts.second), parseInt(oParts.fractionalSecond || 0));
207
+ oDate.setUTCHours(parseInt(oParts.hour), parseInt(oParts.minute), parseInt(oParts.second), parseInt(oParts.fractionalSecond || 0)); // some older browsers don't support fractionalSecond, e.g. Safari < 14.1 */
208
+
76
209
  return oDate;
77
210
  };
211
+
212
+ /**
213
+ * Gets the offset to UTC in seconds for a given date in the time zone specified.
214
+ *
215
+ * For non-unique points in time, the daylight saving time takes precedence over the standard
216
+ * time shortly after the switch back (e.g. clock gets set back 1 hour, duplicate hour).
217
+ *
218
+ * @example
219
+ * var oDate = new Date("2021-10-13T13:22:33Z");
220
+ * TimezoneUtils.calculateOffset(oDate, "America/New_York");
221
+ * // => +14400 seconds (4 * 60 * 60 seconds)
222
+ *
223
+ * TimezoneUtils.calculateOffset(oDate, "Europe/Berlin");
224
+ * // => -7200 seconds (-2 * 60 * 60 seconds)
225
+ *
226
+ * // daylight saving time (2018 Sun, 25 Mar, 02:00 CET → CEST +1 hour (DST start) UTC+2h)
227
+ * // the given date is taken as it is in the time zone
228
+ * TimezoneUtils.calculateOffset(new Date("2018-03-25T00:00:00Z"), "Europe/Berlin");
229
+ * // => -3600 seconds (-1 * 60 * 60 seconds), interpreted as: 2018-03-25 00:00:00 (CET)
230
+ *
231
+ * TimezoneUtils.calculateOffset(new Date("2018-03-25T03:00:00Z"), "Europe/Berlin");
232
+ * // => -7200 seconds (-2 * 60 * 60 seconds)
233
+ *
234
+ * var oHistoricalDate = new Date("1800-10-13T13:22:33Z");
235
+ * TimezoneUtils.calculateOffset(oHistoricalDate, "Europe/Berlin");
236
+ * // => -3208 seconds (-3208 seconds)
237
+ *
238
+ * @param {Date} oDate The date in the time zone used to calculate the offset to UTC.
239
+ * @param {string} sTimezoneSource The source IANA timezone ID, e.g <code>"Europe/Berlin"</code>
240
+ * @returns {number} The difference to UTC between the date in the time zone.
241
+ * @private
242
+ * @ui5-restricted sap.ui.core.format.DateFormat
243
+ */
78
244
  TimezoneUtils.calculateOffset = function (oDate, sTimezoneSource) {
79
- var oFirstGuess = this.convertToTimezone(oDate, sTimezoneSource), iInitialOffset = oDate.getTime() - oFirstGuess.getTime(), oDateSource = new Date(oDate.getTime() + iInitialOffset), oDateTarget = this.convertToTimezone(oDateSource, sTimezoneSource);
80
- return (oDateSource.getTime() - oDateTarget.getTime()) / 1000;
245
+ const oDateInTimezone = TimezoneUtils.convertToTimezone(oDate, sTimezoneSource);
246
+ const iGivenTimestamp = oDate.getTime();
247
+ const iInitialOffset = iGivenTimestamp - oDateInTimezone.getTime();
248
+ // no need to use UI5Date.getInstance as only the UTC timestamp is used
249
+ const oFirstGuess = new Date(iGivenTimestamp + iInitialOffset);
250
+ const oFirstGuessInTimezone = TimezoneUtils.convertToTimezone(oFirstGuess, sTimezoneSource);
251
+ const iFirstGuessInTimezoneTimestamp = oFirstGuessInTimezone.getTime();
252
+ const iSecondOffset = oFirstGuess.getTime() - iFirstGuessInTimezoneTimestamp;
253
+ let iTimezoneOffset = iSecondOffset;
254
+ if (iInitialOffset !== iSecondOffset) {
255
+ const oSecondGuess = new Date(iGivenTimestamp + iSecondOffset);
256
+ const oSecondGuessInTimezone = TimezoneUtils.convertToTimezone(oSecondGuess, sTimezoneSource);
257
+ const iSecondGuessInTimezoneTimestamp = oSecondGuessInTimezone.getTime();
258
+ // if time is different, the given date/time does not exist in the target time zone (switch to Daylight
259
+ // Saving Time) -> take the offset for the greater date
260
+ if (iSecondGuessInTimezoneTimestamp !== iGivenTimestamp && iFirstGuessInTimezoneTimestamp > iSecondGuessInTimezoneTimestamp) {
261
+ iTimezoneOffset = iInitialOffset;
262
+ }
263
+ }
264
+ return iTimezoneOffset / 1000;
81
265
  };
266
+
267
+ /**
268
+ * Map outdated IANA timezone IDs used in CLDR to correct and up-to-date IANA IDs as maintained in ABAP systems.
269
+ *
270
+ * @private
271
+ */
272
+ TimezoneUtils.mCLDR2ABAPTimezones = {
273
+ "America/Buenos_Aires": "America/Argentina/Buenos_Aires",
274
+ "America/Catamarca": "America/Argentina/Catamarca",
275
+ "America/Cordoba": "America/Argentina/Cordoba",
276
+ "America/Jujuy": "America/Argentina/Jujuy",
277
+ "America/Mendoza": "America/Argentina/Mendoza",
278
+ "America/Indianapolis": "America/Indiana/Indianapolis",
279
+ "America/Louisville": "America/Kentucky/Louisville",
280
+ "Africa/Asmera": "Africa/Asmara",
281
+ "Asia/Katmandu": "Asia/Kathmandu",
282
+ "Asia/Calcutta": "Asia/Kolkata",
283
+ "Atlantic/Faeroe": "Atlantic/Faroe",
284
+ "Pacific/Ponape": "Pacific/Pohnpei",
285
+ "Asia/Rangoon": "Asia/Yangon",
286
+ "Pacific/Truk": "Pacific/Chuuk",
287
+ "America/Godthab": "America/Nuuk",
288
+ "Asia/Saigon": "Asia/Ho_Chi_Minh",
289
+ "America/Coral_Harbour": "America/Atikokan"
290
+ };
291
+
292
+ /**
293
+ * Retrieves the browser's local IANA timezone ID; if the browser's timezone ID is not the up-to-date IANA
294
+ * timezone ID, the corresponding IANA timezone ID is returned.
295
+ *
296
+ * @returns {string} The local IANA timezone ID of the browser as up-to-date IANA timezone ID,
297
+ * e.g. <code>"Europe/Berlin"</code> or <code>"Asia/Kolkata"</code>
298
+ *
299
+ * @private
300
+ * @ui5-restricted sap.ui.core.Configuration,sap.m.DateTimeField
301
+ */
82
302
  TimezoneUtils.getLocalTimezone = function () {
83
- if (sLocalTimezone) {
84
- return sLocalTimezone;
303
+ if (sLocalTimezone === "") {
304
+ // timezone may be undefined, only value "" means empty cache
305
+ sLocalTimezone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
306
+ sLocalTimezone = TimezoneUtils.mCLDR2ABAPTimezones[sLocalTimezone] || sLocalTimezone;
85
307
  }
86
- sLocalTimezone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
87
308
  return sLocalTimezone;
88
309
  };
89
- export default TimezoneUtils;
310
+
311
+ /**
312
+ * Clears the cache for the browser's local IANA timezone ID.
313
+ *
314
+ * @private
315
+ */
316
+ TimezoneUtils._clearLocalTimezoneCache = function () {
317
+ sLocalTimezone = "";
318
+ };
319
+ export default TimezoneUtils;
@@ -0,0 +1,30 @@
1
+ /*!
2
+ * OpenUI5
3
+ * (c) Copyright 2009-2024 SAP SE or an SAP affiliate company.
4
+ * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
5
+ */
6
+
7
+ var rCamelCase = /-(.)/ig;
8
+
9
+ /**
10
+ * Transforms a hyphen separated string to a camel case string.
11
+ *
12
+ * @example
13
+ * require(["sap/base/strings/camelize"], function(camelize){
14
+ * camelize("foo-bar"); // "fooBar"
15
+ * });
16
+ *
17
+ * @function
18
+ * @since 1.58
19
+ * @alias module:sap/base/strings/camelize
20
+ * @param {string} sString Hyphen separated string
21
+ * @returns {string} The transformed string
22
+ * @public
23
+ * @SecPassthrough {0|return}
24
+ */
25
+ var fnCamelize = function (sString) {
26
+ return sString.replace(rCamelCase, function (sMatch, sChar) {
27
+ return sChar.toUpperCase();
28
+ });
29
+ };
30
+ export default fnCamelize;