nhb-toolbox 4.26.51 → 4.26.54
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 +6 -0
- package/dist/cjs/constants.js +4 -1
- package/dist/cjs/date/Chronos.js +27 -23
- package/dist/cjs/date/guards.js +5 -1
- package/dist/cjs/date/plugins/roundPlugin.js +1 -1
- package/dist/cjs/date/plugins/timeZonePlugin.js +2 -4
- package/dist/cjs/date/timezone.js +2274 -1
- package/dist/cjs/index.js +19 -18
- package/dist/dts/constants.d.ts +1 -1
- package/dist/dts/date/Chronos.d.ts +21 -13
- package/dist/dts/date/guards.d.ts +21 -4
- package/dist/dts/date/plugins/timeZonePlugin.d.ts +11 -4
- package/dist/dts/date/timezone.d.ts +1679 -2
- package/dist/dts/date/types.d.ts +11 -6
- package/dist/dts/index.d.ts +6 -6
- package/dist/esm/constants.js +1 -1
- package/dist/esm/date/Chronos.js +27 -23
- package/dist/esm/date/guards.js +5 -2
- package/dist/esm/date/plugins/roundPlugin.js +1 -1
- package/dist/esm/date/plugins/timeZonePlugin.js +2 -4
- package/dist/esm/date/timezone.js +2273 -0
- package/dist/esm/index.js +6 -6
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,12 @@ All notable changes to the package will be documented here.
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [4.26.54] - 2025-11-15
|
|
10
|
+
|
|
11
|
+
- **Added** new *guard* utility: `isNativeTimeZoneId` with new constant for type interfaces using `Intl` API.
|
|
12
|
+
- **Updated** `isValidTimeZoneId` *guard* with new *array constant* for checking.
|
|
13
|
+
- **Updated** tsdoc: **added** *remarks* and **fixed** *reference links* in some *functions* and `Chronos` *methods*.
|
|
14
|
+
|
|
9
15
|
## [4.26.50-51] - 2025-11-14
|
|
10
16
|
|
|
11
17
|
- **Updated** `TimeZoneIdentifier` type: now **excludes** `Factory` and *time zone abbreviations* already present in `TimeZone` literal type. **Created** new `$TimeZoneIdentifier` type as *replacement*.
|
package/dist/cjs/constants.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.STATUS_CODES = exports.HTTP_STATUS_CODES = exports.HTTP_STATUS = exports.HTTP_CODES = exports.COUNTRIES = exports.CATEGORIZED_UNITS = exports.LOWERCASED_WORDS = exports.LOCALE_CODES = exports.GENERAL_UNITS = exports.FRANKFURTER_CURRENCIES = exports.CURRENCY_LOCALES = exports.CURRENCY_CODES = exports.CSS_COLORS = exports.NUMBER_COLOR_PALETTE = exports.ALPHABET_COLOR_PALETTE = exports.WESTERN_SEASONS = exports.US_ACADEMIC_SEASONS = exports.SEASON_PRESETS = exports.PHILIPPINES_SEASONS = exports.JAPAN_SEASONS = exports.INDIA_VEDIC_SEASONS = exports.INDIA_TAMIL_SEASONS = exports.INDIA_IMD_SEASONS = exports.ETHIOPIA_SEASONS = exports.BANGLADESH_SEASONS = exports.AUSTRALIA_SEASONS = exports.TIME_ZONES = exports.TIME_ZONE_LABELS = exports.TIME_ZONE_IDS = exports.WESTERN_ZODIAC_SIGNS = exports.WEEK_DAYS = exports.VEDIC_ZODIAC_SIGNS = exports.MONTHS = void 0;
|
|
3
|
+
exports.STATUS_CODES = exports.HTTP_STATUS_CODES = exports.HTTP_STATUS = exports.HTTP_CODES = exports.COUNTRIES = exports.CATEGORIZED_UNITS = exports.LOWERCASED_WORDS = exports.LOCALE_CODES = exports.GENERAL_UNITS = exports.FRANKFURTER_CURRENCIES = exports.CURRENCY_LOCALES = exports.CURRENCY_CODES = exports.CSS_COLORS = exports.NUMBER_COLOR_PALETTE = exports.ALPHABET_COLOR_PALETTE = exports.WESTERN_SEASONS = exports.US_ACADEMIC_SEASONS = exports.SEASON_PRESETS = exports.PHILIPPINES_SEASONS = exports.JAPAN_SEASONS = exports.INDIA_VEDIC_SEASONS = exports.INDIA_TAMIL_SEASONS = exports.INDIA_IMD_SEASONS = exports.ETHIOPIA_SEASONS = exports.BANGLADESH_SEASONS = exports.AUSTRALIA_SEASONS = exports.TZ_ABBREVIATIONS = exports.TIME_ZONES_NATIVE = exports.TIME_ZONES = exports.TIME_ZONE_LABELS = exports.TIME_ZONE_IDS = exports.IANA_TZ_IDS = exports.WESTERN_ZODIAC_SIGNS = exports.WEEK_DAYS = exports.VEDIC_ZODIAC_SIGNS = exports.MONTHS = void 0;
|
|
4
4
|
var constants_1 = require("./date/constants");
|
|
5
5
|
Object.defineProperty(exports, "MONTHS", { enumerable: true, get: function () { return constants_1.MONTHS; } });
|
|
6
6
|
Object.defineProperty(exports, "VEDIC_ZODIAC_SIGNS", { enumerable: true, get: function () { return constants_1.VEDIC_ZODIAC_SIGNS; } });
|
|
7
7
|
Object.defineProperty(exports, "WEEK_DAYS", { enumerable: true, get: function () { return constants_1.DAYS; } });
|
|
8
8
|
Object.defineProperty(exports, "WESTERN_ZODIAC_SIGNS", { enumerable: true, get: function () { return constants_1.WESTERN_ZODIAC_SIGNS; } });
|
|
9
9
|
var timezone_1 = require("./date/timezone");
|
|
10
|
+
Object.defineProperty(exports, "IANA_TZ_IDS", { enumerable: true, get: function () { return timezone_1.IANA_TZ_IDS; } });
|
|
10
11
|
Object.defineProperty(exports, "TIME_ZONE_IDS", { enumerable: true, get: function () { return timezone_1.TIME_ZONE_IDS; } });
|
|
11
12
|
Object.defineProperty(exports, "TIME_ZONE_LABELS", { enumerable: true, get: function () { return timezone_1.TIME_ZONE_LABELS; } });
|
|
12
13
|
Object.defineProperty(exports, "TIME_ZONES", { enumerable: true, get: function () { return timezone_1.TIME_ZONES; } });
|
|
14
|
+
Object.defineProperty(exports, "TIME_ZONES_NATIVE", { enumerable: true, get: function () { return timezone_1.TIME_ZONES_NATIVE; } });
|
|
15
|
+
Object.defineProperty(exports, "TZ_ABBREVIATIONS", { enumerable: true, get: function () { return timezone_1.TIME_ZONES; } });
|
|
13
16
|
var seasons_1 = require("./date/seasons");
|
|
14
17
|
Object.defineProperty(exports, "AUSTRALIA_SEASONS", { enumerable: true, get: function () { return seasons_1.AUSTRALIA_SEASONS; } });
|
|
15
18
|
Object.defineProperty(exports, "BANGLADESH_SEASONS", { enumerable: true, get: function () { return seasons_1.BANGLADESH_SEASONS; } });
|
package/dist/cjs/date/Chronos.js
CHANGED
|
@@ -121,7 +121,7 @@ class Chronos {
|
|
|
121
121
|
case 'utc':
|
|
122
122
|
return this.#toLocalISOString().replace(this.getUTCOffset(), 'Z');
|
|
123
123
|
default:
|
|
124
|
-
return this.#toLocalISOString();
|
|
124
|
+
return this.#toLocalISOString(this.#offset);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
get [Symbol.isConcatSpreadable]() {
|
|
@@ -234,9 +234,9 @@ class Chronos {
|
|
|
234
234
|
}
|
|
235
235
|
return result;
|
|
236
236
|
}
|
|
237
|
-
#toLocalISOString() {
|
|
237
|
+
#toLocalISOString(offset) {
|
|
238
238
|
const pad = (n, p = 2) => String(n).padStart(p, '0');
|
|
239
|
-
return `${this.year}-${pad(this.month + 1)}-${pad(this.date)}T${pad(this.hour)}:${pad(this.minute)}:${pad(this.second)}.${pad(this.millisecond, 3)}${this.getUTCOffset()}`;
|
|
239
|
+
return `${this.year}-${pad(this.month + 1)}-${pad(this.date)}T${pad(this.hour)}:${pad(this.minute)}:${pad(this.second)}.${pad(this.millisecond, 3)}${offset ? offset.slice(3) : this.getUTCOffset()}`;
|
|
240
240
|
}
|
|
241
241
|
#removeUTCFromISO(local = false) {
|
|
242
242
|
return local ?
|
|
@@ -310,8 +310,12 @@ class Chronos {
|
|
|
310
310
|
const chronos = this.addMinutes(offset);
|
|
311
311
|
return new Date(chronos.#date);
|
|
312
312
|
}
|
|
313
|
-
default:
|
|
314
|
-
|
|
313
|
+
default: {
|
|
314
|
+
const offset = -(0, utils_1.extractMinutesFromUTC)(this.#offset) - this.#date.getTimezoneOffset();
|
|
315
|
+
const newDate = new Date(this.#date);
|
|
316
|
+
newDate.setMinutes(newDate.getMinutes() + offset);
|
|
317
|
+
return new Date(newDate);
|
|
318
|
+
}
|
|
315
319
|
}
|
|
316
320
|
}
|
|
317
321
|
toString() {
|
|
@@ -341,7 +345,7 @@ class Chronos {
|
|
|
341
345
|
toISOString() {
|
|
342
346
|
switch (this.#ORIGIN) {
|
|
343
347
|
case 'timeZone':
|
|
344
|
-
return this.#toLocalISOString(
|
|
348
|
+
return this.#toLocalISOString(this.#offset);
|
|
345
349
|
case 'toUTC':
|
|
346
350
|
case 'utc':
|
|
347
351
|
return this.#toLocalISOString().replace(this.getUTCOffset(), 'Z');
|
|
@@ -372,37 +376,37 @@ class Chronos {
|
|
|
372
376
|
addSeconds(seconds) {
|
|
373
377
|
const newDate = new Date(this.#date);
|
|
374
378
|
newDate.setSeconds(newDate.getSeconds() + seconds);
|
|
375
|
-
return new _a(newDate).#withOrigin('addSeconds');
|
|
379
|
+
return new _a(newDate).#withOrigin('addSeconds', this.#offset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
376
380
|
}
|
|
377
381
|
addMinutes(minutes) {
|
|
378
382
|
const newDate = new Date(this.#date);
|
|
379
383
|
newDate.setMinutes(newDate.getMinutes() + minutes);
|
|
380
|
-
return new _a(newDate).#withOrigin('addMinutes');
|
|
384
|
+
return new _a(newDate).#withOrigin('addMinutes', this.#offset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
381
385
|
}
|
|
382
386
|
addHours(hours) {
|
|
383
387
|
const newDate = new Date(this.#date);
|
|
384
388
|
newDate.setHours(newDate.getHours() + hours);
|
|
385
|
-
return new _a(newDate).#withOrigin('addHours');
|
|
389
|
+
return new _a(newDate).#withOrigin('addHours', this.#offset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
386
390
|
}
|
|
387
391
|
addDays(days) {
|
|
388
392
|
const newDate = new Date(this.#date);
|
|
389
393
|
newDate.setDate(newDate.getDate() + days);
|
|
390
|
-
return new _a(newDate).#withOrigin('addDays');
|
|
394
|
+
return new _a(newDate).#withOrigin('addDays', this.#offset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
391
395
|
}
|
|
392
396
|
addWeeks(weeks) {
|
|
393
397
|
const newDate = new Date(this.#date);
|
|
394
398
|
newDate.setDate(newDate.getDate() + weeks * 7);
|
|
395
|
-
return new _a(newDate).#withOrigin('addWeeks');
|
|
399
|
+
return new _a(newDate).#withOrigin('addWeeks', this.#offset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
396
400
|
}
|
|
397
401
|
addMonths(months) {
|
|
398
402
|
const newDate = new Date(this.#date);
|
|
399
403
|
newDate.setMonth(newDate.getMonth() + months);
|
|
400
|
-
return new _a(newDate).#withOrigin('addMonths');
|
|
404
|
+
return new _a(newDate).#withOrigin('addMonths', this.#offset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
401
405
|
}
|
|
402
406
|
addYears(years) {
|
|
403
407
|
const newDate = new Date(this.#date);
|
|
404
408
|
newDate.setFullYear(newDate.getFullYear() + years);
|
|
405
|
-
return new _a(newDate).#withOrigin('addYears');
|
|
409
|
+
return new _a(newDate).#withOrigin('addYears', this.#offset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
406
410
|
}
|
|
407
411
|
isLeapYear(year) {
|
|
408
412
|
return (0, guards_1.isLeapYear)(year ?? this.year);
|
|
@@ -473,13 +477,13 @@ class Chronos {
|
|
|
473
477
|
const year = this.#date.getFullYear();
|
|
474
478
|
const month = this.#date.getMonth();
|
|
475
479
|
const lastDate = new Date(year, month, 1);
|
|
476
|
-
return new _a(lastDate).#withOrigin('firstDayOfMonth');
|
|
480
|
+
return new _a(lastDate).#withOrigin('firstDayOfMonth', this.#offset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
477
481
|
}
|
|
478
482
|
lastDayOfMonth() {
|
|
479
483
|
const year = this.#date.getFullYear();
|
|
480
484
|
const month = this.#date.getMonth() + 1;
|
|
481
485
|
const lastDate = new Date(year, month, 0);
|
|
482
|
-
return new _a(lastDate).#withOrigin('lastDayOfMonth');
|
|
486
|
+
return new _a(lastDate).#withOrigin('lastDayOfMonth', this.#offset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
483
487
|
}
|
|
484
488
|
startOf(unit, weekStartsOn = 0) {
|
|
485
489
|
const d = new Date(this.#date);
|
|
@@ -514,13 +518,13 @@ class Chronos {
|
|
|
514
518
|
case 'millisecond':
|
|
515
519
|
break;
|
|
516
520
|
}
|
|
517
|
-
return new _a(d).#withOrigin('startOf');
|
|
521
|
+
return new _a(d).#withOrigin('startOf', this.#offset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
518
522
|
}
|
|
519
523
|
endOf(unit, weekStartsOn = 0) {
|
|
520
524
|
return this.startOf(unit, weekStartsOn)
|
|
521
525
|
.add(1, unit)
|
|
522
526
|
.add(-1, 'millisecond')
|
|
523
|
-
.#withOrigin('endOf');
|
|
527
|
+
.#withOrigin('endOf', this.#offset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
524
528
|
}
|
|
525
529
|
add(number, unit) {
|
|
526
530
|
const d = new Date(this.#date);
|
|
@@ -550,10 +554,10 @@ class Chronos {
|
|
|
550
554
|
d.setFullYear(d.getFullYear() + number);
|
|
551
555
|
break;
|
|
552
556
|
}
|
|
553
|
-
return new _a(d).#withOrigin('add');
|
|
557
|
+
return new _a(d).#withOrigin('add', this.#offset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
554
558
|
}
|
|
555
559
|
subtract(number, unit) {
|
|
556
|
-
return this.add(-number, unit).#withOrigin('subtract');
|
|
560
|
+
return this.add(-number, unit).#withOrigin('subtract', this.#offset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
557
561
|
}
|
|
558
562
|
get(unit) {
|
|
559
563
|
switch (unit) {
|
|
@@ -602,7 +606,7 @@ class Chronos {
|
|
|
602
606
|
d.setMilliseconds(value);
|
|
603
607
|
break;
|
|
604
608
|
}
|
|
605
|
-
return new _a(d).#withOrigin('set');
|
|
609
|
+
return new _a(d).#withOrigin('set', this.#offset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
606
610
|
}
|
|
607
611
|
diff(other, unit) {
|
|
608
612
|
const time = other instanceof _a ? other : new _a(other);
|
|
@@ -692,7 +696,7 @@ class Chronos {
|
|
|
692
696
|
d.setFullYear(weekStart.getFullYear());
|
|
693
697
|
d.setMonth(weekStart.getMonth());
|
|
694
698
|
d.setDate(weekStart.getDate());
|
|
695
|
-
return new _a(d).#withOrigin('setWeek');
|
|
699
|
+
return new _a(d).#withOrigin('setWeek', this.#offset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
696
700
|
}
|
|
697
701
|
getWeek() {
|
|
698
702
|
const target = this.startOf('week', 1).add(3, 'day');
|
|
@@ -888,11 +892,11 @@ class Chronos {
|
|
|
888
892
|
static utc(dateLike) {
|
|
889
893
|
const chronos = new _a(dateLike);
|
|
890
894
|
if (chronos.#offset === 'UTC+00:00') {
|
|
891
|
-
return chronos.#withOrigin('utc', 'UTC+00:00', 'Greenwich Mean Time');
|
|
895
|
+
return chronos.#withOrigin('utc', 'UTC+00:00', 'Greenwich Mean Time', 'UTC');
|
|
892
896
|
}
|
|
893
897
|
const offset = chronos.getTimeZoneOffsetMinutes();
|
|
894
898
|
const utc = new Date(chronos.#date.getTime() - offset * 60 * 1000);
|
|
895
|
-
return new _a(utc).#withOrigin('utc', 'UTC+00:00', 'Greenwich Mean Time');
|
|
899
|
+
return new _a(utc).#withOrigin('utc', 'UTC+00:00', 'Greenwich Mean Time', 'UTC');
|
|
896
900
|
}
|
|
897
901
|
static formatTimePart(time, format) {
|
|
898
902
|
function normalizeOffset(timeStr) {
|
package/dist/cjs/date/guards.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isValidTime = isValidTime;
|
|
4
4
|
exports.isValidUTCOffset = isValidUTCOffset;
|
|
5
5
|
exports.isValidTimeZoneId = isValidTimeZoneId;
|
|
6
|
+
exports.isNativeTimeZoneId = isNativeTimeZoneId;
|
|
6
7
|
exports.isLeapYear = isLeapYear;
|
|
7
8
|
exports.isDateLike = isDateLike;
|
|
8
9
|
const primitives_1 = require("../guards/primitives");
|
|
@@ -23,7 +24,10 @@ function isValidUTCOffset(value) {
|
|
|
23
24
|
return (0, primitives_1.isString)(value) ? /^UTC[+-]?\d{1,2}:\d{2}$/.test(value) : false;
|
|
24
25
|
}
|
|
25
26
|
function isValidTimeZoneId(value) {
|
|
26
|
-
return (0, primitives_1.isString)(value) ?
|
|
27
|
+
return (0, primitives_1.isString)(value) ? [...timezone_1.IANA_TZ_IDS].includes(value) : false;
|
|
28
|
+
}
|
|
29
|
+
function isNativeTimeZoneId(value) {
|
|
30
|
+
return (0, primitives_1.isString)(value) ? Intl.supportedValuesOf('timeZone').includes(value) : false;
|
|
27
31
|
}
|
|
28
32
|
function isLeapYear(year) {
|
|
29
33
|
const $year = (0, utilities_1.normalizeNumber)(year);
|
|
@@ -78,7 +78,7 @@ const roundPlugin = (ChronosClass) => {
|
|
|
78
78
|
default:
|
|
79
79
|
return this;
|
|
80
80
|
}
|
|
81
|
-
return withOrigin(new ChronosClass(date), 'round');
|
|
81
|
+
return withOrigin(new ChronosClass(date), 'round', this.utcOffset, this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
82
82
|
};
|
|
83
83
|
};
|
|
84
84
|
exports.roundPlugin = roundPlugin;
|
|
@@ -103,9 +103,7 @@ const timeZonePlugin = (ChronosClass) => {
|
|
|
103
103
|
}
|
|
104
104
|
const $zone = zone || offset;
|
|
105
105
|
const tzName = _getTimeZoneName($zone, $Date(this)) ?? offset;
|
|
106
|
-
const
|
|
107
|
-
const previousOffset = this.getTimeZoneOffsetMinutes();
|
|
108
|
-
const relativeOffset = targetOffset - previousOffset;
|
|
106
|
+
const relativeOffset = (0, utils_1.extractMinutesFromUTC)(offset) - this.getTimeZoneOffsetMinutes();
|
|
109
107
|
const adjustedTime = new Date($Date(this).getTime() + relativeOffset * 60 * 1000);
|
|
110
108
|
const instance = new ChronosClass(adjustedTime);
|
|
111
109
|
return withOrigin(instance, `timeZone`, offset, tzName, tzId, $zone);
|
|
@@ -128,7 +126,7 @@ const timeZonePlugin = (ChronosClass) => {
|
|
|
128
126
|
const tzMapKey = utc || tracker || this.utcOffset;
|
|
129
127
|
if (_isGMT(tzMapKey))
|
|
130
128
|
return 'GMT';
|
|
131
|
-
if (!utc && tracker && tracker
|
|
129
|
+
if (!utc && tracker && _isValidTzAbbr(tracker))
|
|
132
130
|
return tracker;
|
|
133
131
|
if ((0, guards_1.isValidUTCOffset)(tzMapKey)) {
|
|
134
132
|
if (TZ_ABBR_CACHE.has(tzMapKey))
|