diff options
Diffstat (limited to 'src/lib/shared/temporal.ts')
| -rw-r--r-- | src/lib/shared/temporal.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lib/shared/temporal.ts b/src/lib/shared/temporal.ts new file mode 100644 index 0000000..7097ba3 --- /dev/null +++ b/src/lib/shared/temporal.ts @@ -0,0 +1,27 @@ +// Shared Temporal display helpers. Storage and logic stay in ISO instants; +// these format one for the viewer in their own timezone. + +/** Format an ISO instant in the viewer's timezone. */ +export function formatInstant( + iso: string, + options: Intl.DateTimeFormatOptions, +): string { + return Temporal.Instant.from(iso) + .toZonedDateTimeISO(Temporal.Now.timeZoneId()) + .toLocaleString('fr-FR', options); +} + +/** Short day-month stamp ("8 sept."). */ + +export function formatDayMonth(iso: string): string { + return formatInstant(iso, { day: 'numeric', month: 'short' }); +} + +/** Day-month-year stamp ("8 sept. 2026"). */ +export function formatDayMonthYear(iso: string): string { + return formatInstant(iso, { + day: 'numeric', + month: 'short', + year: 'numeric', + }); +} |
