aboutsummaryrefslogtreecommitdiff
path: root/src/lib/shared/temporal.ts
blob: 103f2096bed0f4101f14ec3d670e46943ad5eb24 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

// Temporal display helpers: format ISO instants for the viewer's 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',
	});
}