aboutsummaryrefslogtreecommitdiff
path: root/src/routes
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/routes
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/routes')
-rw-r--r--src/routes/+page.server.ts2
-rw-r--r--src/routes/projects/[id]/+page.server.ts2
-rw-r--r--src/routes/projects/[id]/+page.svelte10
-rw-r--r--src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts4
-rw-r--r--src/routes/projects/[projectId]/routine/[routineId]/+page.svelte28
5 files changed, 19 insertions, 27 deletions
diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts
index fc160df..fe9b4e3 100644
--- a/src/routes/+page.server.ts
+++ b/src/routes/+page.server.ts
@@ -5,7 +5,7 @@ import { parseFormString } from '$lib/server/services/validation';
import type { Actions, PageServerLoad } from './$types';
export const load: PageServerLoad = async () => {
- return loadOverview(Date.now());
+ return loadOverview(Temporal.Now.instant());
};
export const actions: Actions = {
diff --git a/src/routes/projects/[id]/+page.server.ts b/src/routes/projects/[id]/+page.server.ts
index 7cb90ff..19aea9b 100644
--- a/src/routes/projects/[id]/+page.server.ts
+++ b/src/routes/projects/[id]/+page.server.ts
@@ -26,7 +26,7 @@ export const load: PageServerLoad = async ({ params }) => {
if (!project || project.archived) {
throw error(404, 'Projet introuvable');
}
- const dashboard = await loadProjectDashboard(id, Date.now());
+ const dashboard = await loadProjectDashboard(id, Temporal.Now.instant());
const archived = await loadArchived(id);
return {
project: { id: project.id, name: project.name },
diff --git a/src/routes/projects/[id]/+page.svelte b/src/routes/projects/[id]/+page.svelte
index a58aeba..9931f40 100644
--- a/src/routes/projects/[id]/+page.svelte
+++ b/src/routes/projects/[id]/+page.svelte
@@ -9,6 +9,7 @@
parseIntervalToDays,
type RoutineState,
} from '$lib/shared/routine-metrics';
+ import { formatDayMonth } from '$lib/shared/temporal';
let { data, form } = $props();
@@ -30,11 +31,6 @@
: matchItems(data.archived, archiveFilter).map((m) => m.obj),
);
- const dateFormatter = new Intl.DateTimeFormat('fr-FR', {
- day: 'numeric',
- month: 'short',
- });
-
function sorted(routines: RoutineState[]): RoutineState[] {
return [...routines].sort(
(a, b) => b.overdueRatio - a.overdueRatio || a.name.localeCompare(b.name),
@@ -182,7 +178,7 @@
<span class="routine-meta">
{formatFrequency(routine.frequencyDays)}
{#if routine.lastDoneAt}
- · fait le {dateFormatter.format(new Date(routine.lastDoneAt))}
+ · fait le {formatDayMonth(routine.lastDoneAt)}
{:else}
· jamais fait
{/if}
@@ -244,7 +240,7 @@
>
<span class="archived-date">
{formatFrequency(routine.frequencyDays)} · archivée le
- {dateFormatter.format(new Date(routine.archivedAt))}
+ {formatDayMonth(routine.archivedAt)}
</span>
</li>
{/each}
diff --git a/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts b/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts
index df4c2cc..bdfa452 100644
--- a/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts
+++ b/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts
@@ -26,7 +26,9 @@ export const load: PageServerLoad = async ({ params }) => {
const completions = await loadCompletions(routineId);
// An archived routine is frozen at its archive instant: state and chart
// stop there instead of now.
- const at = routine.archivedAt ? Date.parse(routine.archivedAt) : Date.now();
+ const at = routine.archivedAt
+ ? Temporal.Instant.from(routine.archivedAt)
+ : Temporal.Now.instant();
return {
project: { id: project.id, name: project.name },
routine,
diff --git a/src/routes/projects/[projectId]/routine/[routineId]/+page.svelte b/src/routes/projects/[projectId]/routine/[routineId]/+page.svelte
index ab2644d..e593ad1 100644
--- a/src/routes/projects/[projectId]/routine/[routineId]/+page.svelte
+++ b/src/routes/projects/[projectId]/routine/[routineId]/+page.svelte
@@ -8,6 +8,7 @@
parseIntervalToDays,
computeHealthSeries,
} from '$lib/shared/routine-metrics';
+ import { formatDayMonth, formatDayMonthYear } from '$lib/shared/temporal';
let { data, form } = $props();
let name = $state('');
let frequency = $state('');
@@ -27,24 +28,19 @@
}
});
const frequencyDays = $derived(parseIntervalToDays(frequency));
- const dateFormatter = new Intl.DateTimeFormat('fr-FR', {
- day: 'numeric',
- month: 'short',
- });
- const dateTimeFormatter = new Intl.DateTimeFormat('fr-FR', {
- day: 'numeric',
- month: 'short',
- year: 'numeric',
- });
const frozenAt = $derived(
data.routine.archived
- ? Date.parse(data.routine.archivedAt ?? data.routine.createdAt)
- : Date.now(),
+ ? Temporal.Instant.from(data.routine.archivedAt ?? data.routine.createdAt)
+ : Temporal.Now.instant(),
);
const series = $derived(
computeHealthSeries(data.routine, data.completions, frozenAt),
);
- const markers = $derived(data.completions.map((c) => Date.parse(c.doneAt)));
+ const markers = $derived(
+ data.completions.map(
+ (c) => Temporal.Instant.from(c.doneAt).epochMilliseconds,
+ ),
+ );
</script>
<main>
@@ -60,9 +56,7 @@
{#if data.routine.archived}
<p class="archived-badge">
Archivée le
- {dateTimeFormatter.format(
- new Date(data.routine.archivedAt ?? data.routine.createdAt),
- )}
+ {formatDayMonthYear(data.routine.archivedAt ?? data.routine.createdAt)}
</p>
{/if}
@@ -144,7 +138,7 @@
<span class="chart-meta">
{formatFrequency(data.routine.frequencyDays)}
{#if data.state.lastDoneAt}
- · fait le {dateFormatter.format(new Date(data.state.lastDoneAt))}
+ · fait le {formatDayMonth(data.state.lastDoneAt)}
{:else}
· jamais fait
{/if}
@@ -182,7 +176,7 @@
{#each data.completions as c (c.id)}
<li class="item-row item-row--card completion-row">
<span class="completion-date">
- {dateTimeFormatter.format(new Date(c.doneAt))}
+ {formatDayMonthYear(c.doneAt)}
</span>
{#if c.note}
<span class="completion-note">{c.note}</span>