@leaderty/utils 2.1.1 → 3.0.0

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
@@ -44,7 +44,8 @@ Formats a date as `dd/mm/aaaa`, or `dd/mm/aaaa hh:mm` (24-hour) with `time: true
44
44
 
45
45
  **Behavior:**
46
46
  - `'aaaa-mm-dd'` strings, and date-time strings without a time zone (`'2026-10-01T00:00:00'`), are read as written. `'2026-10-11'` gives `11/10/2026`, even though `new Date('2026-10-11')` is midnight UTC, which is still October 10 in Argentina.
47
- - `Date` objects and ISO strings with a time zone (`Z` or `±hh:mm`, as in `'2026-10-22T22:05:36.036Z'`) are shown in `America/Argentina/Buenos_Aires` time (UTC-3, no daylight saving time).
47
+ - `Date` objects are read in the system time zone, as their own getters do: `new Date(2026, 10, 1)` is November 1 in any system time zone.
48
+ - ISO strings with a time zone (`Z` or `±hh:mm`, as in `'2026-10-22T22:05:36.036Z'`) are shown in `America/Argentina/Buenos_Aires` time (UTC-3, no daylight saving time).
48
49
  - Any other string gives `'-'` (`'11/10/2026'`, `'2026-10'`, `'Oct 11 2026'`): `new Date()` would read it in the system time zone or guess the day/month order.
49
50
  - Also returns `'-'` for `null`, `undefined`, invalid dates and impossible dates such as `'2026-02-30'`.
50
51
 
@@ -58,14 +59,14 @@ Formats a date as `dd/mm/aaaa`, or `dd/mm/aaaa hh:mm` (24-hour) with `time: true
58
59
  ```typescript
59
60
  dateToShort('2026-10-11') // "11/10/2026"
60
61
  dateToShort('2026-10-01T00:00:00') // "01/10/2026"
61
- dateToShort(new Date('2026-10-22T22:05:36Z')) // "22/10/2026"
62
+ dateToShort(new Date(2026, 9, 22)) // "22/10/2026"
62
63
  dateToShort('2026-10-22T02:05:36Z', { time: true }) // "21/10/2026 23:05"
63
64
  dateToShort('11/10/2026') // "-"
64
65
  ```
65
66
 
66
67
  ### `dateToYMD(value)`
67
68
 
68
- Formats a date as `aaaa-mm-dd`, the value of an `<input type="date">`. Reads `value` like `dateToShort`, so `'2026-10-11'` stays the 11th and a `Date` is taken in Buenos Aires time.
69
+ Formats a date as `aaaa-mm-dd`, the value of an `<input type="date">`. Reads `value` like `dateToShort`, so `'2026-10-11'` stays the 11th and a `Date` is taken in the system time zone.
69
70
 
70
71
  **Parameters:**
71
72
  - `value` - `Date | string | null | undefined`
@@ -75,7 +76,7 @@ Formats a date as `aaaa-mm-dd`, the value of an `<input type="date">`. Reads `va
75
76
  **Examples:**
76
77
  ```typescript
77
78
  dateToYMD('2026-10-11') // "2026-10-11"
78
- dateToYMD(new Date('2026-10-22T02:05:36Z')) // "2026-10-21"
79
+ dateToYMD(new Date(2026, 9, 21)) // "2026-10-21"
79
80
  dateToYMD('11/10/2026') // ""
80
81
  ```
81
82
 
package/dist/format.d.ts CHANGED
@@ -38,8 +38,9 @@ export declare function numberToMoney(amount: number | null | undefined, options
38
38
  * - `'aaaa-mm-dd'` strings, and date-time strings without a time zone (`'2026-10-01T00:00:00'`),
39
39
  * are read as written: `'2026-10-11'` is the 11th, never the 10th
40
40
  * (`new Date('2026-10-11')` is midnight UTC, which is still the 10th in Argentina).
41
- * - `Date` objects and ISO strings with a time zone (`'2026-10-22T22:05:36.036Z'`) are shown in
42
- * `America/Argentina/Buenos_Aires` time.
41
+ * - `Date` objects are read in the system time zone, as their own getters do: `new Date(2026, 10, 1)` is
42
+ * November 1 in any system time zone.
43
+ * - ISO strings with a time zone (`'2026-10-22T22:05:36.036Z'`) are shown in `America/Argentina/Buenos_Aires` time.
43
44
  * - Any other string (`'11/10/2026'`, `'2026-10'`, `'Oct 11 2026'`) gives `'-'`: the engine would parse it
44
45
  * in the system time zone, or guess the day/month order.
45
46
  *
@@ -49,7 +50,7 @@ export declare function numberToMoney(amount: number | null | undefined, options
49
50
  *
50
51
  * @example
51
52
  * dateToShort('2026-10-11') // "11/10/2026"
52
- * dateToShort(new Date('2026-10-22T22:05:36Z')) // "22/10/2026"
53
+ * dateToShort(new Date(2026, 9, 22)) // "22/10/2026"
53
54
  * dateToShort('2026-10-22T02:05:36Z', { time: true }) // "21/10/2026 23:05"
54
55
  */
55
56
  export declare function dateToShort(value: Date | string | null | undefined, options?: DateToShortOptions): string;
@@ -62,7 +63,7 @@ export declare function dateToShort(value: Date | string | null | undefined, opt
62
63
  * @example
63
64
  * dateToYMD('2026-10-11') // "2026-10-11"
64
65
  * dateToYMD('2026-10-11T00:00:00') // "2026-10-11"
65
- * dateToYMD(new Date('2026-10-22T02:05:36Z')) // "2026-10-21"
66
+ * dateToYMD(new Date(2026, 9, 21)) // "2026-10-21"
66
67
  * dateToYMD('11/10/2026') // ""
67
68
  */
68
69
  export declare function dateToYMD(value: Date | string | null | undefined): string;
package/dist/format.js CHANGED
@@ -59,8 +59,9 @@ export function numberToMoney(amount, options = {}) {
59
59
  * - `'aaaa-mm-dd'` strings, and date-time strings without a time zone (`'2026-10-01T00:00:00'`),
60
60
  * are read as written: `'2026-10-11'` is the 11th, never the 10th
61
61
  * (`new Date('2026-10-11')` is midnight UTC, which is still the 10th in Argentina).
62
- * - `Date` objects and ISO strings with a time zone (`'2026-10-22T22:05:36.036Z'`) are shown in
63
- * `America/Argentina/Buenos_Aires` time.
62
+ * - `Date` objects are read in the system time zone, as their own getters do: `new Date(2026, 10, 1)` is
63
+ * November 1 in any system time zone.
64
+ * - ISO strings with a time zone (`'2026-10-22T22:05:36.036Z'`) are shown in `America/Argentina/Buenos_Aires` time.
64
65
  * - Any other string (`'11/10/2026'`, `'2026-10'`, `'Oct 11 2026'`) gives `'-'`: the engine would parse it
65
66
  * in the system time zone, or guess the day/month order.
66
67
  *
@@ -70,7 +71,7 @@ export function numberToMoney(amount, options = {}) {
70
71
  *
71
72
  * @example
72
73
  * dateToShort('2026-10-11') // "11/10/2026"
73
- * dateToShort(new Date('2026-10-22T22:05:36Z')) // "22/10/2026"
74
+ * dateToShort(new Date(2026, 9, 22)) // "22/10/2026"
74
75
  * dateToShort('2026-10-22T02:05:36Z', { time: true }) // "21/10/2026 23:05"
75
76
  */
76
77
  export function dateToShort(value, options = {}) {
@@ -89,7 +90,7 @@ export function dateToShort(value, options = {}) {
89
90
  * @example
90
91
  * dateToYMD('2026-10-11') // "2026-10-11"
91
92
  * dateToYMD('2026-10-11T00:00:00') // "2026-10-11"
92
- * dateToYMD(new Date('2026-10-22T02:05:36Z')) // "2026-10-21"
93
+ * dateToYMD(new Date(2026, 9, 21)) // "2026-10-21"
93
94
  * dateToYMD('11/10/2026') // ""
94
95
  */
95
96
  export function dateToYMD(value) {
@@ -120,6 +121,17 @@ export function dateToMonthYearLong(value) {
120
121
  function toDateParts(value) {
121
122
  if (value === null || value === undefined)
122
123
  return null;
124
+ if (value instanceof Date) {
125
+ if (Number.isNaN(value.getTime()))
126
+ return null;
127
+ return {
128
+ year: value.getFullYear(),
129
+ month: value.getMonth() + 1,
130
+ day: value.getDate(),
131
+ hours: value.getHours(),
132
+ minutes: value.getMinutes(),
133
+ };
134
+ }
123
135
  if (typeof value === 'string') {
124
136
  const match = WALL_CLOCK_PATTERN.exec(value);
125
137
  if (match) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leaderty/utils",
3
- "version": "2.1.1",
3
+ "version": "3.0.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",