@arsedizioni/ars-utils 22.0.82 → 22.0.83

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.
@@ -1748,22 +1748,30 @@ class SystemUtils {
1748
1748
  }
1749
1749
  }
1750
1750
  /**
1751
- * Return an italian local date
1752
- * @param value : the date
1753
- * @returns : the new date
1751
+ * Converts a Date, timestamp or ISO string into a Europe/Rome Date whose JSON serialisation
1752
+ * emits a naive local datetime string ("yyyy-MM-dd'T'HH:mm:ss"), with no timezone designator,
1753
+ * so the wall-clock value round-trips to the server unchanged. Use this instead of `new Date(...)`
1754
+ * when reviving dates received from the API, to stay consistent with the DateFnsAdapter (values
1755
+ * entered through the datepicker already behave this way).
1756
+ * @param value : the source Date, Unix timestamp (ms) or ISO string
1757
+ * @returns : a Europe/Rome Date serialising as naive local time, or undefined for empty/invalid input
1754
1758
  */
1755
1759
  static toLocalDate(value) {
1756
- // No value at all
1757
- if (!value)
1760
+ if (value == null || value === '')
1758
1761
  return undefined;
1759
- // A string
1760
- if (typeof value === 'string' || value instanceof String)
1761
- value = this.parseDate(value);
1762
- // Not a date
1763
- if (!this.isValidDate(value))
1762
+ const ms = value instanceof Date ? value.getTime()
1763
+ : typeof value === 'number' ? value
1764
+ : new Date(value).getTime();
1765
+ if (isNaN(ms))
1764
1766
  return undefined;
1765
- // Update date
1766
- return new TZDate(value, "Europe/Rome");
1767
+ const t = new TZDate(ms, 'Europe/Rome');
1768
+ Object.defineProperty(t, 'toJSON', {
1769
+ value: () => format(t, "yyyy-MM-dd'T'HH:mm:ss"),
1770
+ enumerable: false,
1771
+ configurable: true,
1772
+ writable: true,
1773
+ });
1774
+ return t;
1767
1775
  }
1768
1776
  /**
1769
1777
  * Update a DateInterval object according to a string