aboutsummaryrefslogtreecommitdiff
path: root/src/lib/shared/temporal.ts
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-09-08 17:06:51 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-09-08 17:06:51 +0200
commitbd2f982c489b15ce1165c051fdedf35af979f784 (patch)
tree5c76d07f94b34f6b7b31be6a133793b2cdaccd79 /src/lib/shared/temporal.ts
parent6d69c7b1e6a8051338e052cc9d1836f4f1a20f51 (diff)
Migrate date handling from Date to Temporal API
Routine scheduling, health series, service stamps, session expiry, and date formatting move to native Temporal (Instant / ZonedDateTime in UTC), with ISO strings kept at DB and chart boundaries. Ambient types in src/temporal-ambient.d.ts cover the native runtime; no polyfill. Observable behavior and stored formats are unchanged.
Diffstat (limited to 'src/lib/shared/temporal.ts')
-rw-r--r--src/lib/shared/temporal.ts27
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',
+ });
+}