Öffentliche Speisekarte: Heute-Button, mobile Tages-/Wochenansicht
- "Heute" springt direkt zur aktuellen Woche - Unter dem sm-Breakpoint umschaltbar zwischen Tag (Standard) und Woche statt der Tabelle; Desktop bleibt vollständig serverseitig gerendert, nur der mobile Umschalter ist eine Client-Komponente
This commit is contained in:
+28
@@ -2,6 +2,8 @@
|
||||
// Alle Berechnungen laufen über UTC, damit Server und Browser
|
||||
// unabhängig von der Zeitzone dieselbe Woche ermitteln.
|
||||
|
||||
import type { MenuEntry } from "./types";
|
||||
|
||||
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
||||
|
||||
function toDate(iso: string): Date {
|
||||
@@ -31,7 +33,19 @@ export function addDays(iso: string, days: number): string {
|
||||
return toISO(d);
|
||||
}
|
||||
|
||||
/** Heutiges Datum als YYYY-MM-DD (UTC). */
|
||||
export function todayISO(): string {
|
||||
return toISO(new Date());
|
||||
}
|
||||
|
||||
/** Index (0=Montag…4=Freitag) von `iso` innerhalb seiner Woche, sonst -1 (Wochenende). */
|
||||
export function weekdayIndex(iso: string): number {
|
||||
const day = (toDate(iso).getUTCDay() + 6) % 7;
|
||||
return day <= 4 ? day : -1;
|
||||
}
|
||||
|
||||
export const WEEKDAYS = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag"];
|
||||
export const WEEKDAYS_SHORT = ["Mo", "Di", "Mi", "Do", "Fr"];
|
||||
|
||||
/** z. B. "13. Juli 2026" */
|
||||
export function formatDateLong(iso: string): string {
|
||||
@@ -47,3 +61,17 @@ export function formatDateLong(iso: string): string {
|
||||
export function formatPrice(price: number | string): string {
|
||||
return Number(price).toFixed(2).replace(".", ",") + "€";
|
||||
}
|
||||
|
||||
/** Allergen-/Zusatzstoff-Kürzel eines Gerichts, z. B. "A,G,2" */
|
||||
export function dishCodes(dish: { allergens: string[]; additives: string[] }): string {
|
||||
return [...(dish.allergens ?? []), ...(dish.additives ?? [])].join(",");
|
||||
}
|
||||
|
||||
/** Einträge eines Tages/Bereichs aus der geladenen Wochenliste herausfiltern. */
|
||||
export function entriesFor(
|
||||
entries: MenuEntry[],
|
||||
iso: string,
|
||||
sectionKey: string
|
||||
): MenuEntry[] {
|
||||
return entries.filter((e) => e.menu_date === iso && e.section_key === sectionKey);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user