nhb-toolbox 4.30.10 → 4.30.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
  All notable changes to the package will be documented here.
6
6
 
7
+ ## [4.30.11] - 2026-05-17
8
+
9
+ - **Updated** the *time-zone* abbreviation matching logic of *Chronos plugin method* `getTimeZoneNameShort()` (alias: `getTimeZoneNameAbbr()`) and fixed the caching issue.
10
+
7
11
  ## [4.30.10] - 2026-05-16
8
12
 
9
13
  - **Added** new *utility types*: `PropertyOptional<T, Keys>` and `PropertyRequired<T, Keys>`.
@@ -48,10 +48,14 @@ const timeZonePlugin = ($Chronos) => {
48
48
  }
49
49
  return tzIds;
50
50
  }, new Map()));
51
- const TZ_NAME_ABBR_MAP = new Map(Object.entries(timezone_1.TIME_ZONES).map(([tzAbbr, { offset, tzName }]) => [
52
- offset,
53
- { tzAbbr, tzName },
54
- ]));
51
+ const _buildTzNameAbbrMap = () => {
52
+ const result = [];
53
+ for (const [tzAbbr, { offset, tzName }] of Object.entries(timezone_1.TIME_ZONES)) {
54
+ result.unshift([offset, { tzAbbr, tzName }]);
55
+ }
56
+ return result;
57
+ };
58
+ const TZ_NAME_ABBR_MAP = new Map(_buildTzNameAbbrMap());
55
59
  const _getTimeZoneId = (utc) => {
56
60
  const tzIds = TZ_ID_MAP.get(utc);
57
61
  if (!tzIds || tzIds?.length === 0)
@@ -121,12 +125,13 @@ const timeZonePlugin = ($Chronos) => {
121
125
  if (!utc && tracker && _isValidTzAbbr(tracker))
122
126
  return tracker;
123
127
  if ((0, guards_1.isValidUTCOffset)(tzMapKey)) {
124
- if (TZ_ABBR_CACHE.has(tzMapKey))
128
+ if (TZ_ABBR_CACHE.has(tzMapKey)) {
125
129
  return TZ_ABBR_CACHE.get(tzMapKey);
126
- if (TZ_NAME_ABBR_MAP.has(tzMapKey)) {
127
- return TZ_NAME_ABBR_MAP.get(tzMapKey)?.tzAbbr;
128
130
  }
129
131
  const tzName = _resolveTzName(tzMapKey);
132
+ if (!tzName && TZ_NAME_ABBR_MAP.has(tzMapKey)) {
133
+ return TZ_NAME_ABBR_MAP.get(tzMapKey)?.tzAbbr;
134
+ }
130
135
  if (tzName) {
131
136
  const tzAbbr = _abbreviate(tzName);
132
137
  TZ_ABBR_CACHE.set(tzMapKey, tzAbbr);
@@ -134,10 +139,12 @@ const timeZonePlugin = ($Chronos) => {
134
139
  }
135
140
  }
136
141
  const zone = _getTimeZoneName(tzMapKey, $Date(this)) ?? UTC;
137
- if (TZ_ABBR_CACHE.has(`name-${zone}`))
138
- return TZ_ABBR_CACHE.get(zone);
142
+ const fallbackKey = `name-${zone}`;
143
+ if (TZ_ABBR_CACHE.has(fallbackKey)) {
144
+ return TZ_ABBR_CACHE.get(fallbackKey);
145
+ }
139
146
  const customAbbr = (0, guards_1.isValidUTCOffset)(zone) ? zone : _abbreviate(zone);
140
- TZ_ABBR_CACHE.set(`name-${zone}`, customAbbr);
147
+ TZ_ABBR_CACHE.set(fallbackKey, customAbbr);
141
148
  return customAbbr;
142
149
  };
143
150
  $Chronos.prototype.getTimeZoneNameAbbr = function (utc) {
@@ -45,10 +45,14 @@ export const timeZonePlugin = ($Chronos) => {
45
45
  }
46
46
  return tzIds;
47
47
  }, new Map()));
48
- const TZ_NAME_ABBR_MAP = new Map(Object.entries(TIME_ZONES).map(([tzAbbr, { offset, tzName }]) => [
49
- offset,
50
- { tzAbbr, tzName },
51
- ]));
48
+ const _buildTzNameAbbrMap = () => {
49
+ const result = [];
50
+ for (const [tzAbbr, { offset, tzName }] of Object.entries(TIME_ZONES)) {
51
+ result.unshift([offset, { tzAbbr, tzName }]);
52
+ }
53
+ return result;
54
+ };
55
+ const TZ_NAME_ABBR_MAP = new Map(_buildTzNameAbbrMap());
52
56
  const _getTimeZoneId = (utc) => {
53
57
  const tzIds = TZ_ID_MAP.get(utc);
54
58
  if (!tzIds || tzIds?.length === 0)
@@ -118,12 +122,13 @@ export const timeZonePlugin = ($Chronos) => {
118
122
  if (!utc && tracker && _isValidTzAbbr(tracker))
119
123
  return tracker;
120
124
  if (isValidUTCOffset(tzMapKey)) {
121
- if (TZ_ABBR_CACHE.has(tzMapKey))
125
+ if (TZ_ABBR_CACHE.has(tzMapKey)) {
122
126
  return TZ_ABBR_CACHE.get(tzMapKey);
123
- if (TZ_NAME_ABBR_MAP.has(tzMapKey)) {
124
- return TZ_NAME_ABBR_MAP.get(tzMapKey)?.tzAbbr;
125
127
  }
126
128
  const tzName = _resolveTzName(tzMapKey);
129
+ if (!tzName && TZ_NAME_ABBR_MAP.has(tzMapKey)) {
130
+ return TZ_NAME_ABBR_MAP.get(tzMapKey)?.tzAbbr;
131
+ }
127
132
  if (tzName) {
128
133
  const tzAbbr = _abbreviate(tzName);
129
134
  TZ_ABBR_CACHE.set(tzMapKey, tzAbbr);
@@ -131,10 +136,12 @@ export const timeZonePlugin = ($Chronos) => {
131
136
  }
132
137
  }
133
138
  const zone = _getTimeZoneName(tzMapKey, $Date(this)) ?? UTC;
134
- if (TZ_ABBR_CACHE.has(`name-${zone}`))
135
- return TZ_ABBR_CACHE.get(zone);
139
+ const fallbackKey = `name-${zone}`;
140
+ if (TZ_ABBR_CACHE.has(fallbackKey)) {
141
+ return TZ_ABBR_CACHE.get(fallbackKey);
142
+ }
136
143
  const customAbbr = isValidUTCOffset(zone) ? zone : _abbreviate(zone);
137
- TZ_ABBR_CACHE.set(`name-${zone}`, customAbbr);
144
+ TZ_ABBR_CACHE.set(fallbackKey, customAbbr);
138
145
  return customAbbr;
139
146
  };
140
147
  $Chronos.prototype.getTimeZoneNameAbbr = function (utc) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "4.30.10",
3
+ "version": "4.30.11",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",