@aiaiai-pt/design-system 0.46.0 → 0.46.1
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.
|
@@ -38,15 +38,27 @@ export declare function isIsoTimestamp(value: unknown): value is string;
|
|
|
38
38
|
/** Locale date for an ISO timestamp (date-only, UTC-stable so SSR == hydrate);
|
|
39
39
|
* the raw string when unparseable. */
|
|
40
40
|
export declare function formatTimestamp(value: string, locale: string): string;
|
|
41
|
+
/** Locale date+time for an ISO timestamp (UTC-stable so SSR == hydrate); the
|
|
42
|
+
* raw string when unparseable. Unlike `formatTimestamp` (date-only), this keeps
|
|
43
|
+
* the time — for a schema `datetime` field the staff admin renders the full
|
|
44
|
+
* instant (incl. 00:00), since a datetime's time is meaningful data (SLA
|
|
45
|
+
* stamps, acknowledgements). A `date`-typed field uses `formatTimestamp`. */
|
|
46
|
+
export declare function formatDateTime(value: string, locale: string): string;
|
|
41
47
|
/**
|
|
42
48
|
* The single display boundary for list cells / detail values. Formats a value
|
|
43
|
-
* as a locale date when it's a timestamp —
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
49
|
+
* as a locale date/datetime when it's a timestamp — the caller drives which
|
|
50
|
+
* from the schema FIELD TYPE (not a value-shape guess):
|
|
51
|
+
* - `treatAsDate` → date-only (a `date`-typed field)
|
|
52
|
+
* - `treatAsDateTime` → date+time (a `datetime`-typed field; time is data)
|
|
53
|
+
* - neither → value-shape: an ISO-timestamp STRING renders
|
|
54
|
+
* date-only (the portal, whose public schema strips
|
|
55
|
+
* typed created_at/updated_at). Unchanged.
|
|
56
|
+
* Everything else goes through `formatScalar` (with the host's object policy).
|
|
57
|
+
* `treatAsDate` wins if a caller mistakenly sets both.
|
|
47
58
|
*/
|
|
48
59
|
export declare function displayCell(value: unknown, locale: string, opts?: {
|
|
49
60
|
treatAsDate?: boolean;
|
|
61
|
+
treatAsDateTime?: boolean;
|
|
50
62
|
objectFallback?: ObjectFallback;
|
|
51
63
|
}): string;
|
|
52
64
|
/** Operator copy for a status value (falls back to the raw value). `labels` is
|
|
@@ -92,20 +92,49 @@ export function formatTimestamp(value: string, locale: string): string {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
/** Locale date+time for an ISO timestamp (UTC-stable so SSR == hydrate); the
|
|
96
|
+
* raw string when unparseable. Unlike `formatTimestamp` (date-only), this keeps
|
|
97
|
+
* the time — for a schema `datetime` field the staff admin renders the full
|
|
98
|
+
* instant (incl. 00:00), since a datetime's time is meaningful data (SLA
|
|
99
|
+
* stamps, acknowledgements). A `date`-typed field uses `formatTimestamp`. */
|
|
100
|
+
export function formatDateTime(value: string, locale: string): string {
|
|
101
|
+
const parsed = new Date(value);
|
|
102
|
+
if (Number.isNaN(parsed.getTime())) return value;
|
|
103
|
+
try {
|
|
104
|
+
return new Intl.DateTimeFormat(locale || "en", {
|
|
105
|
+
dateStyle: "medium",
|
|
106
|
+
timeStyle: "short",
|
|
107
|
+
timeZone: "UTC",
|
|
108
|
+
}).format(parsed);
|
|
109
|
+
} catch {
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
95
114
|
/**
|
|
96
115
|
* The single display boundary for list cells / detail values. Formats a value
|
|
97
|
-
* as a locale date when it's a timestamp —
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
116
|
+
* as a locale date/datetime when it's a timestamp — the caller drives which
|
|
117
|
+
* from the schema FIELD TYPE (not a value-shape guess):
|
|
118
|
+
* - `treatAsDate` → date-only (a `date`-typed field)
|
|
119
|
+
* - `treatAsDateTime` → date+time (a `datetime`-typed field; time is data)
|
|
120
|
+
* - neither → value-shape: an ISO-timestamp STRING renders
|
|
121
|
+
* date-only (the portal, whose public schema strips
|
|
122
|
+
* typed created_at/updated_at). Unchanged.
|
|
123
|
+
* Everything else goes through `formatScalar` (with the host's object policy).
|
|
124
|
+
* `treatAsDate` wins if a caller mistakenly sets both.
|
|
101
125
|
*/
|
|
102
126
|
export function displayCell(
|
|
103
127
|
value: unknown,
|
|
104
128
|
locale: string,
|
|
105
|
-
opts: {
|
|
129
|
+
opts: {
|
|
130
|
+
treatAsDate?: boolean;
|
|
131
|
+
treatAsDateTime?: boolean;
|
|
132
|
+
objectFallback?: ObjectFallback;
|
|
133
|
+
} = {},
|
|
106
134
|
): string {
|
|
107
|
-
if (
|
|
108
|
-
return formatTimestamp(value, locale);
|
|
135
|
+
if (typeof value === "string" && value) {
|
|
136
|
+
if (opts.treatAsDate) return formatTimestamp(value, locale);
|
|
137
|
+
if (opts.treatAsDateTime) return formatDateTime(value, locale);
|
|
109
138
|
}
|
|
110
139
|
if (isIsoTimestamp(value)) return formatTimestamp(value, locale);
|
|
111
140
|
return formatScalar(value, { objectFallback: opts.objectFallback });
|