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.
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
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());
|
||
}
|