Show dates, times and prices in a European format and the studio's timezone

Formatting with the default locale rendered US dates (MM/DD/YYYY, 12-hour)
on the server. Everything shown to people now uses DISPLAY_LOCALE (en-GB)
and booking times use SITE_TIMEZONE. The public layout reloads on every
navigation so places left are never stale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
This commit is contained in:
agent 2026-10-24 09:32:56 +00:00
parent 7075ab7883
commit 214db95186
5 changed files with 47 additions and 21 deletions

View file

@ -142,6 +142,7 @@ To add an email block type: add to `EmailBlockType` in `packages/shared/src/type
- Create/edit forms open in `$lib/admin/Modal.svelte`; destructive submits use `confirmSubmit()` from `$lib/admin/confirm` (returning `false` from a handler does not cancel).
- Server actions wrap PocketBase writes in `attempt()` from `$lib/server/actions` so failures show as an error banner, not a 500.
- Editors with unsaved state use `use:enhance` + `warnOnUnsavedChanges()`.
- **Dates, times and prices shown to people** use `DISPLAY_LOCALE` (`en-GB`: day-month-year, 24-hour clock) and the helpers in `$shared/calendar` (`formatInstant`, `formatPrice`, `formatDateTime`) — never `toLocale*(undefined)`, which renders US formats on the server. Booking times on the public site are shown in `SITE_TIMEZONE` too (layout data `timezone`, read by blocks via `page.data.timezone`). Native `<input type="date">` fields follow the visitor's browser language and can't be changed from the page.
- **Dates/times in admin**: entered and displayed in `SITE_TIMEZONE` (layout data `timezone`), via `toZonedDatetimeInput`, `zonedInputToIso`, `formatDateTime` in `$shared/calendar`. Never `new Date(localInput)` on the server — the container runs in UTC.
- **Prose**: `.prose-wellness` class for rich text content styling

View file

@ -3,6 +3,7 @@
import { page } from '$app/state';
import type { HeaderGlobal } from '$lib/types';
import { getBasketContext } from '$lib/basket.svelte';
import { formatPrice } from '$shared/calendar';
let { header } = $props<{ header: HeaderGlobal }>();
@ -29,9 +30,7 @@
return href === '/' ? path === '/' : path === href || path.startsWith(href + '/');
}
function formatTotal(amount: number) {
return new Intl.NumberFormat(undefined, { style: 'currency', currency: 'EUR' }).format(amount);
}
const formatTotal = formatPrice;
</script>
{#snippet basketIcon()}

View file

@ -2,6 +2,8 @@ import { defaultColors, defaultFooter, defaultHeader } from '$lib/types';
import type { ItemRecord, SlotRecord } from '$lib/types';
import { BASKET_COOKIE, getBasket } from '$lib/server/shop';
import { loadShopData } from '$shared/server/shop';
import { DEFAULT_TIMEZONE } from '$shared/calendar';
import { env } from '$env/dynamic/private';
import type { LayoutServerLoad } from './$types';
async function getGlobal(pb: App.Locals['pb'], key: string, fallback: unknown) {
@ -13,7 +15,12 @@ async function getGlobal(pb: App.Locals['pb'], key: string, fallback: unknown) {
}
}
export const load: LayoutServerLoad = async ({ locals, cookies }) => {
export const load: LayoutServerLoad = async ({ locals, cookies, url }) => {
// Reading the path makes this load run again on every navigation, so the
// slots and basket are fresh on each page — places free up or get taken
// (holds lapse, other customers book) while the visitor browses.
void url.pathname;
const [header, footer, colors] = await Promise.all([
getGlobal(locals.pb, 'header', defaultHeader),
getGlobal(locals.pb, 'footer', defaultFooter),
@ -35,5 +42,8 @@ export const load: LayoutServerLoad = async ({ locals, cookies }) => {
const items: ItemRecord[] = shop?.items ?? [];
const slots: SlotRecord[] = shop?.slots ?? [];
return { header, footer, colors, user: locals.user, basket, items, slots };
// Booking times are shown in the studio's timezone, wherever the visitor is.
const timezone = env.SITE_TIMEZONE || DEFAULT_TIMEZONE;
return { header, footer, colors, user: locals.user, basket, items, slots, timezone };
};

View file

@ -1,21 +1,12 @@
<script lang="ts">
import { onMount } from 'svelte';
import { formatInstant, formatPrice } from '$shared/calendar';
let { data } = $props();
// "Friday 15 January, 10:00" in the studio's timezone.
function formatSlotDate(iso?: string | null) {
if (!iso) return '';
return new Date(iso).toLocaleString(undefined, {
weekday: 'long',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
}
function formatPrice(amount: number) {
return new Intl.NumberFormat(undefined, { style: 'currency', currency: 'EUR' }).format(amount);
return formatInstant(iso, data.timezone, { weekday: 'long', day: 'numeric', month: 'long', hour: '2-digit', minute: '2-digit' });
}
</script>

View file

@ -48,6 +48,31 @@ export function dateInputToPocketBase(value: string, allDay = true, timeZone = '
return `${value.slice(0, 10)} 00:00:00.000Z`;
}
/**
* Locale for every date, time and price shown to people: day-month-year and
* a 24-hour clock. Fixed (not the visitor's or server's default, which is
* en-US in the container) so the server render and the browser agree.
*/
export const DISPLAY_LOCALE = 'en-GB';
/** Fallback when no SITE_TIMEZONE reaches the page. */
export const DEFAULT_TIMEZONE = 'Europe/Oslo';
export function formatPrice(amount: number) {
return new Intl.NumberFormat(DISPLAY_LOCALE, { style: 'currency', currency: 'EUR' }).format(amount);
}
/** Format an instant in `timeZone` with the display locale. */
export function formatInstant(value: string | null | undefined, timeZone: string, options: Intl.DateTimeFormatOptions) {
const date = parseInstant(value);
return date ? new Intl.DateTimeFormat(DISPLAY_LOCALE, { ...options, timeZone }).format(date) : '';
}
/** The calendar date (`YYYY-MM-DD`) of an instant in `timeZone`. */
export function zonedDateKey(value: string | null | undefined, timeZone: string) {
return toZonedDatetimeInput(value, timeZone).slice(0, 10);
}
// ── Site-timezone helpers ──────────────────────────────────────────────
// Admin forms and listings work in the site's timezone (SITE_TIMEZONE), so
// what the admin types is what customers book, and the server render (UTC
@ -114,14 +139,14 @@ export function toZonedDatetimeInput(value: string | null | undefined, timeZone:
export function formatDateTime(value: string | null | undefined, timeZone: string) {
const date = parseInstant(value);
if (!date) return '';
return new Intl.DateTimeFormat('en-GB', { timeZone, dateStyle: 'medium', timeStyle: 'short' }).format(date);
return new Intl.DateTimeFormat(DISPLAY_LOCALE, { timeZone, dateStyle: 'medium', timeStyle: 'short' }).format(date);
}
/** "10:00" in `timeZone`. */
export function formatTime(value: string | null | undefined, timeZone: string) {
const date = parseInstant(value);
if (!date) return '';
return new Intl.DateTimeFormat('en-GB', { timeZone, timeStyle: 'short' }).format(date);
return new Intl.DateTimeFormat(DISPLAY_LOCALE, { timeZone, timeStyle: 'short' }).format(date);
}
export function parseEventDate(value?: string | null) {
@ -184,7 +209,7 @@ export function createCalendarMonth(monthDate: Date, reference = new Date(), wee
return {
date: first,
label: first.toLocaleDateString(undefined, { month: 'long', year: 'numeric' }),
label: first.toLocaleDateString(DISPLAY_LOCALE, { month: 'long', year: 'numeric' }),
days
};
}
@ -264,7 +289,7 @@ export function formatEventDateRange(event: CalendarEventRecord) {
const start = parseEventDate(event.start);
const end = parseEventDate(event.end);
if (!start) return '';
const formatter = new Intl.DateTimeFormat(undefined, { month: 'short', day: 'numeric' });
const formatter = new Intl.DateTimeFormat(DISPLAY_LOCALE, { month: 'short', day: 'numeric' });
if (!end || dateKey(start) === dateKey(end)) return formatter.format(start);
return `${formatter.format(start)} – ${formatter.format(end)}`;
}