Files
Convivo/apps/convivo/src/lib/time.ts
T
Lago c0fbf495dc feat: sync GridSmart agendas and use event-relative demo time
Support script and URL sources, automatic Sessionize polling, staff-linked service sessions, chronological agenda blocks, and inline Placeholders. Fix demo mode to use the active event date and document deployed behavior with regression coverage.
2026-10-11 08:39:15 +02:00

47 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Slot } from './types';
export function demoNow(eventDate: string): Date {
return new Date(`${eventDate}T10:20:00`);
}
export type SlotStatus = 'done' | 'now' | 'next';
function at(dateStr: string, time: string): Date {
return new Date(`${dateStr}T${time}`);
}
export function slotStart(slot: Slot): Date {
return at(slot.slot_date, slot.start_time);
}
export function slotEnd(slot: Slot): Date {
return at(slot.slot_date, slot.end_time);
}
export function slotStatus(slot: Slot, now: Date): SlotStatus {
if (now >= slotEnd(slot)) return 'done';
if (now >= slotStart(slot)) return 'now';
return 'next';
}
/** "09:00" from "09:00:00". */
export function fmtTime(time: string): string {
return time.slice(0, 5);
}
export function fmtRange(slot: Slot): string {
return `${fmtTime(slot.start_time)}–${fmtTime(slot.end_time)}`;
}
export function greeting(now: Date): string {
const h = now.getHours();
if (h < 12) return 'Good morning';
if (h < 18) return 'Good afternoon';
return 'Good evening';
}
/** "lunch_break" → "Lunch Break" (capitalize each word). */
export function capWords(s: string): string {
return s.replace(/_/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
}