@fr0st/datetime 8.0.1 → 8.0.3

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/README.md CHANGED
@@ -398,7 +398,7 @@ DateTime.clearDataCache();
398
398
 
399
399
  ```bash
400
400
  npm test
401
- npm run js-lint
401
+ npm run lint
402
402
  npm run build
403
403
  ```
404
404
 
@@ -141,7 +141,8 @@
141
141
  second: 60,
142
142
  };
143
143
 
144
- /** @typedef {import('./date-time.js').default} DateTime */
144
+ /** @import DateTime from './date-time.js' */
145
+
145
146
 
146
147
  /**
147
148
  * DateTime Helpers
@@ -1711,6 +1712,12 @@
1711
1712
  * An immutable date and time object with locale-aware formatting and time-zone support.
1712
1713
  */
1713
1714
  class DateTime {
1715
+ #date;
1716
+ #dynamicTz;
1717
+ #locale;
1718
+ #offset;
1719
+ #timeZone;
1720
+
1714
1721
  /**
1715
1722
  * Clears cached formatter and locale data.
1716
1723
  */
@@ -2094,8 +2101,8 @@
2094
2101
  throw new Error('Invalid date supplied');
2095
2102
  }
2096
2103
 
2097
- this._date = new Date(timestamp);
2098
- this._dynamicTz = false;
2104
+ this.#date = new Date(timestamp);
2105
+ this.#dynamicTz = false;
2099
2106
  this.isValid = true;
2100
2107
 
2101
2108
  let timeZone = options.timeZone;
@@ -2110,37 +2117,37 @@
2110
2117
 
2111
2118
  const match = timeZone.match(offsetRegExp);
2112
2119
  if (match) {
2113
- this._offset =
2120
+ this.#offset =
2114
2121
  match[2] * 60 +
2115
2122
  parseInt(match[4] || 0, 10) +
2116
2123
  parseInt(match[5] || 0, 10) / 60;
2117
- if (this._offset && match[1] === '+') {
2118
- this._offset *= -1;
2124
+ if (this.#offset && match[1] === '+') {
2125
+ this.#offset *= -1;
2119
2126
  }
2120
2127
 
2121
- if (this._offset) {
2122
- this._timeZone = formatOffset(this._offset);
2128
+ if (this.#offset) {
2129
+ this.#timeZone = formatOffset(this.#offset);
2123
2130
  } else {
2124
- this._dynamicTz = true;
2125
- this._timeZone = 'UTC';
2131
+ this.#dynamicTz = true;
2132
+ this.#timeZone = 'UTC';
2126
2133
  }
2127
2134
  } else {
2128
- this._dynamicTz = true;
2129
- this._timeZone = timeZone;
2135
+ this.#dynamicTz = true;
2136
+ this.#timeZone = timeZone;
2130
2137
  }
2131
2138
 
2132
- this._locale = 'locale' in options ?
2139
+ this.#locale = 'locale' in options ?
2133
2140
  options.locale :
2134
2141
  config.defaultLocale;
2135
2142
 
2136
- if (this._dynamicTz) {
2137
- this._offset = getOffset(this);
2143
+ if (this.#dynamicTz) {
2144
+ this.#offset = getOffset(this);
2138
2145
  }
2139
2146
 
2140
- if (adjustOffset && this._offset) {
2147
+ if (adjustOffset && this.#offset) {
2141
2148
  const resolvedDate = setOffsetTime(this, timestamp);
2142
- this._date.setTime(resolvedDate.getTime());
2143
- this._offset = resolvedDate.getTimeZoneOffset();
2149
+ this.#date.setTime(resolvedDate.getTime());
2150
+ this.#offset = resolvedDate.getTimeZoneOffset();
2144
2151
  }
2145
2152
  }
2146
2153
 
@@ -2571,7 +2578,7 @@
2571
2578
  * @returns {string} The locale.
2572
2579
  */
2573
2580
  getLocale() {
2574
- return this._locale;
2581
+ return this.#locale;
2575
2582
  }
2576
2583
 
2577
2584
  /**
@@ -2619,7 +2626,7 @@
2619
2626
  * @returns {number} The number of milliseconds since the UNIX epoch.
2620
2627
  */
2621
2628
  getTime() {
2622
- return this._date.getTime();
2629
+ return this.#date.getTime();
2623
2630
  }
2624
2631
 
2625
2632
  /**
@@ -2635,7 +2642,7 @@
2635
2642
  * @returns {string} The time zone.
2636
2643
  */
2637
2644
  getTimeZone() {
2638
- return this._timeZone;
2645
+ return this.#timeZone;
2639
2646
  }
2640
2647
 
2641
2648
  /**
@@ -2643,7 +2650,7 @@
2643
2650
  * @returns {number} The UTC offset in minutes.
2644
2651
  */
2645
2652
  getTimeZoneOffset() {
2646
- return this._offset;
2653
+ return this.#offset;
2647
2654
  }
2648
2655
 
2649
2656
  /**
@@ -3017,7 +3024,7 @@
3017
3024
  * @returns {boolean} Whether the current time is in daylight saving time.
3018
3025
  */
3019
3026
  isDst() {
3020
- if (!this._dynamicTz) {
3027
+ if (!this.#dynamicTz) {
3021
3028
  return false;
3022
3029
  }
3023
3030
 
@@ -3472,7 +3479,7 @@
3472
3479
  * @returns {string} The name of the time zone.
3473
3480
  */
3474
3481
  timeZoneName(type = 'long') {
3475
- return this._dynamicTz ?
3482
+ return this.#dynamicTz ?
3476
3483
  formatTimeZoneName(this.getLocale(), this.getTime(), this.getTimeZone(), type) :
3477
3484
  'GMT' + formatOffset(this.getTimeZoneOffset(), true, type === 'short');
3478
3485
  }
@@ -3595,10 +3602,8 @@
3595
3602
 
3596
3603
  /**
3597
3604
  * Returns a copy with the hours changed in the current time zone.
3598
- * @param {number} hours The hours. (0-23)
3599
- * @param {number} [minutes] The minutes. (0-59)
3600
- * @param {number} [seconds] The seconds. (0-59)
3601
- * @param {number} [milliseconds] The milliseconds.
3605
+ * @param {...number} args The hours (0-23), optionally followed by minutes
3606
+ * (0-59), seconds (0-59), and milliseconds.
3602
3607
  * @returns {DateTime} A new DateTime instance.
3603
3608
  */
3604
3609
  withHours(...args) {
@@ -3616,7 +3621,7 @@
3616
3621
  withLocale(locale) {
3617
3622
  return new this.constructor(this.getTime(), {
3618
3623
  locale,
3619
- timeZone: this._timeZone,
3624
+ timeZone: this.#timeZone,
3620
3625
  });
3621
3626
  }
3622
3627
 
@@ -3634,9 +3639,8 @@
3634
3639
 
3635
3640
  /**
3636
3641
  * Returns a copy with the minutes changed in the current time zone.
3637
- * @param {number} minutes The minutes. (0-59)
3638
- * @param {number} [seconds] The seconds. (0-59)
3639
- * @param {number} [milliseconds] The milliseconds.
3642
+ * @param {...number} args The minutes (0-59), optionally followed by seconds
3643
+ * (0-59) and milliseconds.
3640
3644
  * @returns {DateTime} A new DateTime instance.
3641
3645
  */
3642
3646
  withMinutes(...args) {
@@ -3693,8 +3697,8 @@
3693
3697
 
3694
3698
  /**
3695
3699
  * Returns a copy with the seconds changed in the current time zone.
3696
- * @param {number} seconds The seconds. (0-59)
3697
- * @param {number} [milliseconds] The milliseconds.
3700
+ * @param {...number} args The seconds (0-59), optionally followed by
3701
+ * milliseconds.
3698
3702
  * @returns {DateTime} A new DateTime instance.
3699
3703
  */
3700
3704
  withSeconds(...args) {
@@ -3711,8 +3715,8 @@
3711
3715
  */
3712
3716
  withTime(time) {
3713
3717
  return new this.constructor(time, {
3714
- locale: this._locale,
3715
- timeZone: this._timeZone,
3718
+ locale: this.#locale,
3719
+ timeZone: this.#timeZone,
3716
3720
  });
3717
3721
  }
3718
3722
 
@@ -3732,7 +3736,7 @@
3732
3736
  */
3733
3737
  withTimeZone(timeZone) {
3734
3738
  return new this.constructor(this.getTime(), {
3735
- locale: this._locale,
3739
+ locale: this.#locale,
3736
3740
  timeZone,
3737
3741
  });
3738
3742
  }
@@ -3744,7 +3748,7 @@
3744
3748
  */
3745
3749
  withTimeZoneOffset(offset) {
3746
3750
  return new this.constructor(this.getTime(), {
3747
- locale: this._locale,
3751
+ locale: this.#locale,
3748
3752
  timeZone: formatOffset(offset),
3749
3753
  });
3750
3754
  }