nhb-toolbox 4.26.44 → 4.26.46-beta.1
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
|
@@ -6,9 +6,13 @@ All notable changes to the package will be documented here.
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [4.26.45] - 2025-11-13
|
|
10
|
+
|
|
11
|
+
- **Removed** *time zone id* `'Factory'` from `TIME_ZONE_IDS` and **replaced** `'EDT'` with `'EST5EDT'` to fix the *issue with getting time zone details* using `Intl` API.
|
|
12
|
+
|
|
9
13
|
## [4.26.44] - 2025-11-13
|
|
10
14
|
|
|
11
|
-
- **Fixed** issues with passing optional *time zone id* in `Chronos` method `$getNativeTimeZoneName` and `getTimeZoneDetails` utility
|
|
15
|
+
- **Fixed** issues with passing optional *time zone id* in `Chronos` method `$getNativeTimeZoneName` and `getTimeZoneDetails` utility.
|
|
12
16
|
|
|
13
17
|
## [4.26.41] - 2025-11-12
|
|
14
18
|
|
|
@@ -10,6 +10,25 @@ const timeZonePlugin = (ChronosClass) => {
|
|
|
10
10
|
const _isGMT = (factor) => {
|
|
11
11
|
return factor === 'UTC+00:00' || factor === 'UTC-00:00';
|
|
12
12
|
};
|
|
13
|
+
const _getTimeZoneDetails = (tzId, date) => {
|
|
14
|
+
const TZ_NAME_TYPES = ['long', 'longOffset'];
|
|
15
|
+
const obj = { tzId };
|
|
16
|
+
for (const type of TZ_NAME_TYPES) {
|
|
17
|
+
const parts = new Intl.DateTimeFormat('en', {
|
|
18
|
+
timeZone: tzId,
|
|
19
|
+
timeZoneName: type,
|
|
20
|
+
}).formatToParts(date);
|
|
21
|
+
const tzPart = parts.find((p) => p.type === 'timeZoneName');
|
|
22
|
+
const key = type === 'long' ? 'tzName' : 'offset';
|
|
23
|
+
const value = type === 'longOffset' ?
|
|
24
|
+
tzPart?.value === 'GMT' ?
|
|
25
|
+
'UTC+00:00'
|
|
26
|
+
: tzPart?.value?.replace(/^GMT/, 'UTC')
|
|
27
|
+
: tzPart?.value;
|
|
28
|
+
obj[key] = value;
|
|
29
|
+
}
|
|
30
|
+
return obj;
|
|
31
|
+
};
|
|
13
32
|
const TZ_NAME_ABBR_MAP = new Map(Object.entries(timezone_1.TIME_ZONES).map(([tzAbbr, { offset, tzName }]) => [
|
|
14
33
|
offset,
|
|
15
34
|
{ tzAbbr, tzName },
|
|
@@ -17,6 +36,9 @@ const timeZonePlugin = (ChronosClass) => {
|
|
|
17
36
|
const _isLabelKey = (offset) => {
|
|
18
37
|
return offset in timezone_1.TIME_ZONE_LABELS;
|
|
19
38
|
};
|
|
39
|
+
const _isValidTzAbbr = (tz) => {
|
|
40
|
+
return tz in timezone_1.TIME_ZONES;
|
|
41
|
+
};
|
|
20
42
|
const _resolveTzName = (offset) => {
|
|
21
43
|
if (_isLabelKey(offset)) {
|
|
22
44
|
return timezone_1.TIME_ZONE_LABELS[offset];
|
|
@@ -33,21 +55,16 @@ const timeZonePlugin = (ChronosClass) => {
|
|
|
33
55
|
}
|
|
34
56
|
return tzName;
|
|
35
57
|
}
|
|
36
|
-
else if ((
|
|
37
|
-
|
|
38
|
-
const { tzNameLongOffset, tzNameLong } = (0, utils_1.getTimeZoneDetails)(zone, date);
|
|
39
|
-
const convertedOffset = tzNameLongOffset?.replace(/^GMT/, 'UTC') ?? '';
|
|
40
|
-
const resolvedName = _resolveTzName(offset);
|
|
41
|
-
const priorityName = convertedOffset === offset ? tzNameLong : resolvedName;
|
|
42
|
-
return tzName || priorityName || resolvedName || tzNameLong;
|
|
58
|
+
else if (_isValidTzAbbr(zone)) {
|
|
59
|
+
return timezone_1.TIME_ZONES[zone].tzName;
|
|
43
60
|
}
|
|
44
61
|
else {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
: _resolveTzName(timezone_1.TIME_ZONES[zone]?.offset);
|
|
62
|
+
const { offset, tzName } = _getTimeZoneDetails(zone, date);
|
|
63
|
+
return tzName || _resolveTzName(offset);
|
|
48
64
|
}
|
|
49
65
|
};
|
|
50
|
-
const TZ_ID_MAP = new Map(
|
|
66
|
+
const TZ_ID_MAP = new Map(Intl.supportedValuesOf('timeZone').reduce((acc, id) => {
|
|
67
|
+
const { offset } = _getTimeZoneDetails(id);
|
|
51
68
|
const arr = acc.get(offset) ?? [];
|
|
52
69
|
arr.push(id);
|
|
53
70
|
acc.set(offset, arr);
|
|
@@ -68,13 +85,13 @@ const timeZonePlugin = (ChronosClass) => {
|
|
|
68
85
|
offset = zone;
|
|
69
86
|
tzId = _getTimeZoneId(offset) || offset;
|
|
70
87
|
}
|
|
71
|
-
else if ((
|
|
72
|
-
offset = timezone_1.
|
|
73
|
-
tzId =
|
|
88
|
+
else if (_isValidTzAbbr(zone)) {
|
|
89
|
+
offset = timezone_1.TIME_ZONES[zone].offset;
|
|
90
|
+
tzId = _getTimeZoneId(offset) || offset;
|
|
74
91
|
}
|
|
75
92
|
else {
|
|
76
|
-
offset = zone
|
|
77
|
-
tzId =
|
|
93
|
+
offset = _getTimeZoneDetails(zone, $Date(this)).offset;
|
|
94
|
+
tzId = zone;
|
|
78
95
|
}
|
|
79
96
|
const $zone = zone || offset;
|
|
80
97
|
const tzName = _getTimeZoneName($zone, $Date(this)) ?? offset;
|
|
@@ -121,7 +138,7 @@ const timeZonePlugin = (ChronosClass) => {
|
|
|
121
138
|
const zone = _getTimeZoneName(tzMapKey, $Date(this)) ?? UTC;
|
|
122
139
|
if (TZ_ABBR_CACHE.has(`name-${zone}`))
|
|
123
140
|
return TZ_ABBR_CACHE.get(zone);
|
|
124
|
-
const customAbbr = (0, guards_1.isValidUTCOffset)(zone)
|
|
141
|
+
const customAbbr = (0, guards_1.isValidUTCOffset)(zone) ? zone : _abbreviate(zone);
|
|
125
142
|
TZ_ABBR_CACHE.set(`name-${zone}`, customAbbr);
|
|
126
143
|
return customAbbr;
|
|
127
144
|
};
|
|
@@ -2461,9 +2461,9 @@ exports.TIME_ZONE_IDS = /* @__PURE__ */ Object.freeze({
|
|
|
2461
2461
|
tzName: 'Eastern Standard Time',
|
|
2462
2462
|
offset: 'UTC-05:00',
|
|
2463
2463
|
},
|
|
2464
|
-
|
|
2465
|
-
tzName: 'Eastern
|
|
2466
|
-
offset: 'UTC-
|
|
2464
|
+
EST5EDT: {
|
|
2465
|
+
tzName: 'Eastern Standard Tim',
|
|
2466
|
+
offset: 'UTC-05:00',
|
|
2467
2467
|
},
|
|
2468
2468
|
'Etc/GMT': {
|
|
2469
2469
|
tzName: 'Greenwich Mean Time',
|
|
@@ -2861,10 +2861,6 @@ exports.TIME_ZONE_IDS = /* @__PURE__ */ Object.freeze({
|
|
|
2861
2861
|
tzName: 'Central European Time',
|
|
2862
2862
|
offset: 'UTC+01:00',
|
|
2863
2863
|
},
|
|
2864
|
-
Factory: {
|
|
2865
|
-
tzName: undefined,
|
|
2866
|
-
offset: 'UTC+00:00',
|
|
2867
|
-
},
|
|
2868
2864
|
GB: {
|
|
2869
2865
|
tzName: 'Greenwich Mean Time',
|
|
2870
2866
|
offset: 'UTC+00:00',
|
|
@@ -849,7 +849,7 @@ export declare const TIME_ZONES: Readonly<{
|
|
|
849
849
|
readonly offset: "UTC+05:00";
|
|
850
850
|
};
|
|
851
851
|
}>;
|
|
852
|
-
/** Record of unique standard time-zone labels/names for their corresponding UTC offsets as (`{
|
|
852
|
+
/** Record of unique standard time-zone labels/names for their corresponding UTC offsets as (`{ utcOffset: timeZoneName }`). */
|
|
853
853
|
export declare const TIME_ZONE_LABELS: Readonly<{
|
|
854
854
|
readonly 'UTC-12:00': "Baker Island Time";
|
|
855
855
|
readonly 'UTC-11:00': "Samoa Standard Time";
|
|
@@ -895,7 +895,7 @@ export declare const TIME_ZONE_LABELS: Readonly<{
|
|
|
895
895
|
readonly 'UTC+13:00': "Phoenix Island Time";
|
|
896
896
|
readonly 'UTC+14:00': "Line Islands Time";
|
|
897
897
|
}>;
|
|
898
|
-
/** Record of timezone identifiers (from {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones IANA TZ Database on Wikipedia}) against their corresponding UTC offsets and full timezone names. */
|
|
898
|
+
/** Record of 597 timezone identifiers (from {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones IANA TZ Database on Wikipedia}) against their corresponding UTC offsets and full timezone names. */
|
|
899
899
|
export declare const TIME_ZONE_IDS: Readonly<{
|
|
900
900
|
readonly 'Africa/Abidjan': {
|
|
901
901
|
readonly tzName: "Greenwich Mean Time";
|
|
@@ -2461,9 +2461,9 @@ export declare const TIME_ZONE_IDS: Readonly<{
|
|
|
2461
2461
|
readonly tzName: "Eastern Standard Time";
|
|
2462
2462
|
readonly offset: "UTC-05:00";
|
|
2463
2463
|
};
|
|
2464
|
-
readonly
|
|
2465
|
-
readonly tzName: "Eastern
|
|
2466
|
-
readonly offset: "UTC-
|
|
2464
|
+
readonly EST5EDT: {
|
|
2465
|
+
readonly tzName: "Eastern Standard Tim";
|
|
2466
|
+
readonly offset: "UTC-05:00";
|
|
2467
2467
|
};
|
|
2468
2468
|
readonly 'Etc/GMT': {
|
|
2469
2469
|
readonly tzName: "Greenwich Mean Time";
|
|
@@ -2861,10 +2861,6 @@ export declare const TIME_ZONE_IDS: Readonly<{
|
|
|
2861
2861
|
readonly tzName: "Central European Time";
|
|
2862
2862
|
readonly offset: "UTC+01:00";
|
|
2863
2863
|
};
|
|
2864
|
-
readonly Factory: {
|
|
2865
|
-
readonly tzName: undefined;
|
|
2866
|
-
readonly offset: "UTC+00:00";
|
|
2867
|
-
};
|
|
2868
2864
|
readonly GB: {
|
|
2869
2865
|
readonly tzName: "Greenwich Mean Time";
|
|
2870
2866
|
readonly offset: "UTC+00:00";
|
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
import { INTERNALS } from '../constants.js';
|
|
2
|
-
import {
|
|
3
|
-
import { TIME_ZONES,
|
|
4
|
-
import {
|
|
2
|
+
import { isValidUTCOffset } from '../guards.js';
|
|
3
|
+
import { TIME_ZONES, TIME_ZONE_LABELS } from '../timezone.js';
|
|
4
|
+
import { extractMinutesFromUTC } from '../utils.js';
|
|
5
5
|
export const timeZonePlugin = (ChronosClass) => {
|
|
6
6
|
const { internalDate: $Date, withOrigin } = ChronosClass[INTERNALS];
|
|
7
7
|
const _isGMT = (factor) => {
|
|
8
8
|
return factor === 'UTC+00:00' || factor === 'UTC-00:00';
|
|
9
9
|
};
|
|
10
|
+
const _getTimeZoneDetails = (tzId, date) => {
|
|
11
|
+
const TZ_NAME_TYPES = ['long', 'longOffset'];
|
|
12
|
+
const obj = { tzId };
|
|
13
|
+
for (const type of TZ_NAME_TYPES) {
|
|
14
|
+
const parts = new Intl.DateTimeFormat('en', {
|
|
15
|
+
timeZone: tzId,
|
|
16
|
+
timeZoneName: type,
|
|
17
|
+
}).formatToParts(date);
|
|
18
|
+
const tzPart = parts.find((p) => p.type === 'timeZoneName');
|
|
19
|
+
const key = type === 'long' ? 'tzName' : 'offset';
|
|
20
|
+
const value = type === 'longOffset' ?
|
|
21
|
+
tzPart?.value === 'GMT' ?
|
|
22
|
+
'UTC+00:00'
|
|
23
|
+
: tzPart?.value?.replace(/^GMT/, 'UTC')
|
|
24
|
+
: tzPart?.value;
|
|
25
|
+
obj[key] = value;
|
|
26
|
+
}
|
|
27
|
+
return obj;
|
|
28
|
+
};
|
|
10
29
|
const TZ_NAME_ABBR_MAP = new Map(Object.entries(TIME_ZONES).map(([tzAbbr, { offset, tzName }]) => [
|
|
11
30
|
offset,
|
|
12
31
|
{ tzAbbr, tzName },
|
|
@@ -14,6 +33,9 @@ export const timeZonePlugin = (ChronosClass) => {
|
|
|
14
33
|
const _isLabelKey = (offset) => {
|
|
15
34
|
return offset in TIME_ZONE_LABELS;
|
|
16
35
|
};
|
|
36
|
+
const _isValidTzAbbr = (tz) => {
|
|
37
|
+
return tz in TIME_ZONES;
|
|
38
|
+
};
|
|
17
39
|
const _resolveTzName = (offset) => {
|
|
18
40
|
if (_isLabelKey(offset)) {
|
|
19
41
|
return TIME_ZONE_LABELS[offset];
|
|
@@ -30,21 +52,16 @@ export const timeZonePlugin = (ChronosClass) => {
|
|
|
30
52
|
}
|
|
31
53
|
return tzName;
|
|
32
54
|
}
|
|
33
|
-
else if (
|
|
34
|
-
|
|
35
|
-
const { tzNameLongOffset, tzNameLong } = getTimeZoneDetails(zone, date);
|
|
36
|
-
const convertedOffset = tzNameLongOffset?.replace(/^GMT/, 'UTC') ?? '';
|
|
37
|
-
const resolvedName = _resolveTzName(offset);
|
|
38
|
-
const priorityName = convertedOffset === offset ? tzNameLong : resolvedName;
|
|
39
|
-
return tzName || priorityName || resolvedName || tzNameLong;
|
|
55
|
+
else if (_isValidTzAbbr(zone)) {
|
|
56
|
+
return TIME_ZONES[zone].tzName;
|
|
40
57
|
}
|
|
41
58
|
else {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
: _resolveTzName(TIME_ZONES[zone]?.offset);
|
|
59
|
+
const { offset, tzName } = _getTimeZoneDetails(zone, date);
|
|
60
|
+
return tzName || _resolveTzName(offset);
|
|
45
61
|
}
|
|
46
62
|
};
|
|
47
|
-
const TZ_ID_MAP = new Map(
|
|
63
|
+
const TZ_ID_MAP = new Map(Intl.supportedValuesOf('timeZone').reduce((acc, id) => {
|
|
64
|
+
const { offset } = _getTimeZoneDetails(id);
|
|
48
65
|
const arr = acc.get(offset) ?? [];
|
|
49
66
|
arr.push(id);
|
|
50
67
|
acc.set(offset, arr);
|
|
@@ -65,13 +82,13 @@ export const timeZonePlugin = (ChronosClass) => {
|
|
|
65
82
|
offset = zone;
|
|
66
83
|
tzId = _getTimeZoneId(offset) || offset;
|
|
67
84
|
}
|
|
68
|
-
else if (
|
|
69
|
-
offset =
|
|
70
|
-
tzId =
|
|
85
|
+
else if (_isValidTzAbbr(zone)) {
|
|
86
|
+
offset = TIME_ZONES[zone].offset;
|
|
87
|
+
tzId = _getTimeZoneId(offset) || offset;
|
|
71
88
|
}
|
|
72
89
|
else {
|
|
73
|
-
offset = zone
|
|
74
|
-
tzId =
|
|
90
|
+
offset = _getTimeZoneDetails(zone, $Date(this)).offset;
|
|
91
|
+
tzId = zone;
|
|
75
92
|
}
|
|
76
93
|
const $zone = zone || offset;
|
|
77
94
|
const tzName = _getTimeZoneName($zone, $Date(this)) ?? offset;
|
|
@@ -118,7 +135,7 @@ export const timeZonePlugin = (ChronosClass) => {
|
|
|
118
135
|
const zone = _getTimeZoneName(tzMapKey, $Date(this)) ?? UTC;
|
|
119
136
|
if (TZ_ABBR_CACHE.has(`name-${zone}`))
|
|
120
137
|
return TZ_ABBR_CACHE.get(zone);
|
|
121
|
-
const customAbbr = isValidUTCOffset(zone)
|
|
138
|
+
const customAbbr = isValidUTCOffset(zone) ? zone : _abbreviate(zone);
|
|
122
139
|
TZ_ABBR_CACHE.set(`name-${zone}`, customAbbr);
|
|
123
140
|
return customAbbr;
|
|
124
141
|
};
|
|
@@ -2458,9 +2458,9 @@ export const TIME_ZONE_IDS = /* @__PURE__ */ Object.freeze({
|
|
|
2458
2458
|
tzName: 'Eastern Standard Time',
|
|
2459
2459
|
offset: 'UTC-05:00',
|
|
2460
2460
|
},
|
|
2461
|
-
|
|
2462
|
-
tzName: 'Eastern
|
|
2463
|
-
offset: 'UTC-
|
|
2461
|
+
EST5EDT: {
|
|
2462
|
+
tzName: 'Eastern Standard Tim',
|
|
2463
|
+
offset: 'UTC-05:00',
|
|
2464
2464
|
},
|
|
2465
2465
|
'Etc/GMT': {
|
|
2466
2466
|
tzName: 'Greenwich Mean Time',
|
|
@@ -2858,10 +2858,6 @@ export const TIME_ZONE_IDS = /* @__PURE__ */ Object.freeze({
|
|
|
2858
2858
|
tzName: 'Central European Time',
|
|
2859
2859
|
offset: 'UTC+01:00',
|
|
2860
2860
|
},
|
|
2861
|
-
Factory: {
|
|
2862
|
-
tzName: undefined,
|
|
2863
|
-
offset: 'UTC+00:00',
|
|
2864
|
-
},
|
|
2865
2861
|
GB: {
|
|
2866
2862
|
tzName: 'Greenwich Mean Time',
|
|
2867
2863
|
offset: 'UTC+00:00',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nhb-toolbox",
|
|
3
|
-
"version": "4.26.
|
|
3
|
+
"version": "4.26.46-beta.1",
|
|
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",
|