@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fr0st/datetime",
3
- "version": "8.0.1",
3
+ "version": "8.0.2",
4
4
  "private": false,
5
5
  "description": "Immutable date and time handling for JavaScript with locale-aware formatting, parsing, calendar math, and IANA or fixed-offset time zones.",
6
6
  "keywords": [
package/src/date-time.js CHANGED
@@ -38,6 +38,12 @@ import {
38
38
  * An immutable date and time object with locale-aware formatting and time-zone support.
39
39
  */
40
40
  export default class DateTime {
41
+ #date;
42
+ #dynamicTz;
43
+ #locale;
44
+ #offset;
45
+ #timeZone;
46
+
41
47
  /**
42
48
  * Clears cached formatter and locale data.
43
49
  */
@@ -421,8 +427,8 @@ export default class DateTime {
421
427
  throw new Error('Invalid date supplied');
422
428
  }
423
429
 
424
- this._date = new Date(timestamp);
425
- this._dynamicTz = false;
430
+ this.#date = new Date(timestamp);
431
+ this.#dynamicTz = false;
426
432
  this.isValid = true;
427
433
 
428
434
  let timeZone = options.timeZone;
@@ -437,37 +443,37 @@ export default class DateTime {
437
443
 
438
444
  const match = timeZone.match(offsetRegExp);
439
445
  if (match) {
440
- this._offset =
446
+ this.#offset =
441
447
  match[2] * 60 +
442
448
  parseInt(match[4] || 0, 10) +
443
449
  parseInt(match[5] || 0, 10) / 60;
444
- if (this._offset && match[1] === '+') {
445
- this._offset *= -1;
450
+ if (this.#offset && match[1] === '+') {
451
+ this.#offset *= -1;
446
452
  }
447
453
 
448
- if (this._offset) {
449
- this._timeZone = formatOffset(this._offset);
454
+ if (this.#offset) {
455
+ this.#timeZone = formatOffset(this.#offset);
450
456
  } else {
451
- this._dynamicTz = true;
452
- this._timeZone = 'UTC';
457
+ this.#dynamicTz = true;
458
+ this.#timeZone = 'UTC';
453
459
  }
454
460
  } else {
455
- this._dynamicTz = true;
456
- this._timeZone = timeZone;
461
+ this.#dynamicTz = true;
462
+ this.#timeZone = timeZone;
457
463
  }
458
464
 
459
- this._locale = 'locale' in options ?
465
+ this.#locale = 'locale' in options ?
460
466
  options.locale :
461
467
  config.defaultLocale;
462
468
 
463
- if (this._dynamicTz) {
464
- this._offset = getOffset(this);
469
+ if (this.#dynamicTz) {
470
+ this.#offset = getOffset(this);
465
471
  }
466
472
 
467
- if (adjustOffset && this._offset) {
473
+ if (adjustOffset && this.#offset) {
468
474
  const resolvedDate = setOffsetTime(this, timestamp);
469
- this._date.setTime(resolvedDate.getTime());
470
- this._offset = resolvedDate.getTimeZoneOffset();
475
+ this.#date.setTime(resolvedDate.getTime());
476
+ this.#offset = resolvedDate.getTimeZoneOffset();
471
477
  }
472
478
  }
473
479
 
@@ -898,7 +904,7 @@ export default class DateTime {
898
904
  * @returns {string} The locale.
899
905
  */
900
906
  getLocale() {
901
- return this._locale;
907
+ return this.#locale;
902
908
  }
903
909
 
904
910
  /**
@@ -946,7 +952,7 @@ export default class DateTime {
946
952
  * @returns {number} The number of milliseconds since the UNIX epoch.
947
953
  */
948
954
  getTime() {
949
- return this._date.getTime();
955
+ return this.#date.getTime();
950
956
  }
951
957
 
952
958
  /**
@@ -962,7 +968,7 @@ export default class DateTime {
962
968
  * @returns {string} The time zone.
963
969
  */
964
970
  getTimeZone() {
965
- return this._timeZone;
971
+ return this.#timeZone;
966
972
  }
967
973
 
968
974
  /**
@@ -970,7 +976,7 @@ export default class DateTime {
970
976
  * @returns {number} The UTC offset in minutes.
971
977
  */
972
978
  getTimeZoneOffset() {
973
- return this._offset;
979
+ return this.#offset;
974
980
  }
975
981
 
976
982
  /**
@@ -1344,7 +1350,7 @@ export default class DateTime {
1344
1350
  * @returns {boolean} Whether the current time is in daylight saving time.
1345
1351
  */
1346
1352
  isDst() {
1347
- if (!this._dynamicTz) {
1353
+ if (!this.#dynamicTz) {
1348
1354
  return false;
1349
1355
  }
1350
1356
 
@@ -1799,7 +1805,7 @@ export default class DateTime {
1799
1805
  * @returns {string} The name of the time zone.
1800
1806
  */
1801
1807
  timeZoneName(type = 'long') {
1802
- return this._dynamicTz ?
1808
+ return this.#dynamicTz ?
1803
1809
  formatTimeZoneName(this.getLocale(), this.getTime(), this.getTimeZone(), type) :
1804
1810
  'GMT' + formatOffset(this.getTimeZoneOffset(), true, type === 'short');
1805
1811
  }
@@ -1943,7 +1949,7 @@ export default class DateTime {
1943
1949
  withLocale(locale) {
1944
1950
  return new this.constructor(this.getTime(), {
1945
1951
  locale,
1946
- timeZone: this._timeZone,
1952
+ timeZone: this.#timeZone,
1947
1953
  });
1948
1954
  }
1949
1955
 
@@ -2038,8 +2044,8 @@ export default class DateTime {
2038
2044
  */
2039
2045
  withTime(time) {
2040
2046
  return new this.constructor(time, {
2041
- locale: this._locale,
2042
- timeZone: this._timeZone,
2047
+ locale: this.#locale,
2048
+ timeZone: this.#timeZone,
2043
2049
  });
2044
2050
  }
2045
2051
 
@@ -2059,7 +2065,7 @@ export default class DateTime {
2059
2065
  */
2060
2066
  withTimeZone(timeZone) {
2061
2067
  return new this.constructor(this.getTime(), {
2062
- locale: this._locale,
2068
+ locale: this.#locale,
2063
2069
  timeZone,
2064
2070
  });
2065
2071
  }
@@ -2071,7 +2077,7 @@ export default class DateTime {
2071
2077
  */
2072
2078
  withTimeZoneOffset(offset) {
2073
2079
  return new this.constructor(this.getTime(), {
2074
- locale: this._locale,
2080
+ locale: this.#locale,
2075
2081
  timeZone: formatOffset(offset),
2076
2082
  });
2077
2083
  }