@fr0st/datetime 8.0.1 → 8.0.2
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/dist/frost-datetime.js +34 -28
- package/dist/frost-datetime.js.map +1 -1
- package/dist/frost-datetime.min.js +1 -1
- package/dist/frost-datetime.min.js.map +1 -1
- package/package.json +1 -1
- package/src/date-time.js +34 -28
package/dist/frost-datetime.js
CHANGED
|
@@ -1711,6 +1711,12 @@
|
|
|
1711
1711
|
* An immutable date and time object with locale-aware formatting and time-zone support.
|
|
1712
1712
|
*/
|
|
1713
1713
|
class DateTime {
|
|
1714
|
+
#date;
|
|
1715
|
+
#dynamicTz;
|
|
1716
|
+
#locale;
|
|
1717
|
+
#offset;
|
|
1718
|
+
#timeZone;
|
|
1719
|
+
|
|
1714
1720
|
/**
|
|
1715
1721
|
* Clears cached formatter and locale data.
|
|
1716
1722
|
*/
|
|
@@ -2094,8 +2100,8 @@
|
|
|
2094
2100
|
throw new Error('Invalid date supplied');
|
|
2095
2101
|
}
|
|
2096
2102
|
|
|
2097
|
-
this
|
|
2098
|
-
this
|
|
2103
|
+
this.#date = new Date(timestamp);
|
|
2104
|
+
this.#dynamicTz = false;
|
|
2099
2105
|
this.isValid = true;
|
|
2100
2106
|
|
|
2101
2107
|
let timeZone = options.timeZone;
|
|
@@ -2110,37 +2116,37 @@
|
|
|
2110
2116
|
|
|
2111
2117
|
const match = timeZone.match(offsetRegExp);
|
|
2112
2118
|
if (match) {
|
|
2113
|
-
this
|
|
2119
|
+
this.#offset =
|
|
2114
2120
|
match[2] * 60 +
|
|
2115
2121
|
parseInt(match[4] || 0, 10) +
|
|
2116
2122
|
parseInt(match[5] || 0, 10) / 60;
|
|
2117
|
-
if (this
|
|
2118
|
-
this
|
|
2123
|
+
if (this.#offset && match[1] === '+') {
|
|
2124
|
+
this.#offset *= -1;
|
|
2119
2125
|
}
|
|
2120
2126
|
|
|
2121
|
-
if (this
|
|
2122
|
-
this
|
|
2127
|
+
if (this.#offset) {
|
|
2128
|
+
this.#timeZone = formatOffset(this.#offset);
|
|
2123
2129
|
} else {
|
|
2124
|
-
this
|
|
2125
|
-
this
|
|
2130
|
+
this.#dynamicTz = true;
|
|
2131
|
+
this.#timeZone = 'UTC';
|
|
2126
2132
|
}
|
|
2127
2133
|
} else {
|
|
2128
|
-
this
|
|
2129
|
-
this
|
|
2134
|
+
this.#dynamicTz = true;
|
|
2135
|
+
this.#timeZone = timeZone;
|
|
2130
2136
|
}
|
|
2131
2137
|
|
|
2132
|
-
this
|
|
2138
|
+
this.#locale = 'locale' in options ?
|
|
2133
2139
|
options.locale :
|
|
2134
2140
|
config.defaultLocale;
|
|
2135
2141
|
|
|
2136
|
-
if (this
|
|
2137
|
-
this
|
|
2142
|
+
if (this.#dynamicTz) {
|
|
2143
|
+
this.#offset = getOffset(this);
|
|
2138
2144
|
}
|
|
2139
2145
|
|
|
2140
|
-
if (adjustOffset && this
|
|
2146
|
+
if (adjustOffset && this.#offset) {
|
|
2141
2147
|
const resolvedDate = setOffsetTime(this, timestamp);
|
|
2142
|
-
this.
|
|
2143
|
-
this
|
|
2148
|
+
this.#date.setTime(resolvedDate.getTime());
|
|
2149
|
+
this.#offset = resolvedDate.getTimeZoneOffset();
|
|
2144
2150
|
}
|
|
2145
2151
|
}
|
|
2146
2152
|
|
|
@@ -2571,7 +2577,7 @@
|
|
|
2571
2577
|
* @returns {string} The locale.
|
|
2572
2578
|
*/
|
|
2573
2579
|
getLocale() {
|
|
2574
|
-
return this
|
|
2580
|
+
return this.#locale;
|
|
2575
2581
|
}
|
|
2576
2582
|
|
|
2577
2583
|
/**
|
|
@@ -2619,7 +2625,7 @@
|
|
|
2619
2625
|
* @returns {number} The number of milliseconds since the UNIX epoch.
|
|
2620
2626
|
*/
|
|
2621
2627
|
getTime() {
|
|
2622
|
-
return this.
|
|
2628
|
+
return this.#date.getTime();
|
|
2623
2629
|
}
|
|
2624
2630
|
|
|
2625
2631
|
/**
|
|
@@ -2635,7 +2641,7 @@
|
|
|
2635
2641
|
* @returns {string} The time zone.
|
|
2636
2642
|
*/
|
|
2637
2643
|
getTimeZone() {
|
|
2638
|
-
return this
|
|
2644
|
+
return this.#timeZone;
|
|
2639
2645
|
}
|
|
2640
2646
|
|
|
2641
2647
|
/**
|
|
@@ -2643,7 +2649,7 @@
|
|
|
2643
2649
|
* @returns {number} The UTC offset in minutes.
|
|
2644
2650
|
*/
|
|
2645
2651
|
getTimeZoneOffset() {
|
|
2646
|
-
return this
|
|
2652
|
+
return this.#offset;
|
|
2647
2653
|
}
|
|
2648
2654
|
|
|
2649
2655
|
/**
|
|
@@ -3017,7 +3023,7 @@
|
|
|
3017
3023
|
* @returns {boolean} Whether the current time is in daylight saving time.
|
|
3018
3024
|
*/
|
|
3019
3025
|
isDst() {
|
|
3020
|
-
if (!this
|
|
3026
|
+
if (!this.#dynamicTz) {
|
|
3021
3027
|
return false;
|
|
3022
3028
|
}
|
|
3023
3029
|
|
|
@@ -3472,7 +3478,7 @@
|
|
|
3472
3478
|
* @returns {string} The name of the time zone.
|
|
3473
3479
|
*/
|
|
3474
3480
|
timeZoneName(type = 'long') {
|
|
3475
|
-
return this
|
|
3481
|
+
return this.#dynamicTz ?
|
|
3476
3482
|
formatTimeZoneName(this.getLocale(), this.getTime(), this.getTimeZone(), type) :
|
|
3477
3483
|
'GMT' + formatOffset(this.getTimeZoneOffset(), true, type === 'short');
|
|
3478
3484
|
}
|
|
@@ -3616,7 +3622,7 @@
|
|
|
3616
3622
|
withLocale(locale) {
|
|
3617
3623
|
return new this.constructor(this.getTime(), {
|
|
3618
3624
|
locale,
|
|
3619
|
-
timeZone: this
|
|
3625
|
+
timeZone: this.#timeZone,
|
|
3620
3626
|
});
|
|
3621
3627
|
}
|
|
3622
3628
|
|
|
@@ -3711,8 +3717,8 @@
|
|
|
3711
3717
|
*/
|
|
3712
3718
|
withTime(time) {
|
|
3713
3719
|
return new this.constructor(time, {
|
|
3714
|
-
locale: this
|
|
3715
|
-
timeZone: this
|
|
3720
|
+
locale: this.#locale,
|
|
3721
|
+
timeZone: this.#timeZone,
|
|
3716
3722
|
});
|
|
3717
3723
|
}
|
|
3718
3724
|
|
|
@@ -3732,7 +3738,7 @@
|
|
|
3732
3738
|
*/
|
|
3733
3739
|
withTimeZone(timeZone) {
|
|
3734
3740
|
return new this.constructor(this.getTime(), {
|
|
3735
|
-
locale: this
|
|
3741
|
+
locale: this.#locale,
|
|
3736
3742
|
timeZone,
|
|
3737
3743
|
});
|
|
3738
3744
|
}
|
|
@@ -3744,7 +3750,7 @@
|
|
|
3744
3750
|
*/
|
|
3745
3751
|
withTimeZoneOffset(offset) {
|
|
3746
3752
|
return new this.constructor(this.getTime(), {
|
|
3747
|
-
locale: this
|
|
3753
|
+
locale: this.#locale,
|
|
3748
3754
|
timeZone: formatOffset(offset),
|
|
3749
3755
|
});
|
|
3750
3756
|
}
|