@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.
@@ -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._date = new Date(timestamp);
2098
- this._dynamicTz = false;
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._offset =
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._offset && match[1] === '+') {
2118
- this._offset *= -1;
2123
+ if (this.#offset && match[1] === '+') {
2124
+ this.#offset *= -1;
2119
2125
  }
2120
2126
 
2121
- if (this._offset) {
2122
- this._timeZone = formatOffset(this._offset);
2127
+ if (this.#offset) {
2128
+ this.#timeZone = formatOffset(this.#offset);
2123
2129
  } else {
2124
- this._dynamicTz = true;
2125
- this._timeZone = 'UTC';
2130
+ this.#dynamicTz = true;
2131
+ this.#timeZone = 'UTC';
2126
2132
  }
2127
2133
  } else {
2128
- this._dynamicTz = true;
2129
- this._timeZone = timeZone;
2134
+ this.#dynamicTz = true;
2135
+ this.#timeZone = timeZone;
2130
2136
  }
2131
2137
 
2132
- this._locale = 'locale' in options ?
2138
+ this.#locale = 'locale' in options ?
2133
2139
  options.locale :
2134
2140
  config.defaultLocale;
2135
2141
 
2136
- if (this._dynamicTz) {
2137
- this._offset = getOffset(this);
2142
+ if (this.#dynamicTz) {
2143
+ this.#offset = getOffset(this);
2138
2144
  }
2139
2145
 
2140
- if (adjustOffset && this._offset) {
2146
+ if (adjustOffset && this.#offset) {
2141
2147
  const resolvedDate = setOffsetTime(this, timestamp);
2142
- this._date.setTime(resolvedDate.getTime());
2143
- this._offset = resolvedDate.getTimeZoneOffset();
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._locale;
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._date.getTime();
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._timeZone;
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._offset;
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._dynamicTz) {
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._dynamicTz ?
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._timeZone,
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._locale,
3715
- timeZone: this._timeZone,
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._locale,
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._locale,
3753
+ locale: this.#locale,
3748
3754
  timeZone: formatOffset(offset),
3749
3755
  });
3750
3756
  }