/** Today as YYYY-MM-DD in a time zone, so a practice in Chicago does not start tomorrow at 7pm. */ export const todayIn = (timeZone: string, now: Date = new Date()): string => new Intl.DateTimeFormat('en-CA', { timeZone, year: 'numeric', month: '2-digit', day: '2-digit' }).format(now); /** * A new clinician's first schedule: from today for 12 calendar months, ending the day before the * anniversary. It is bounded because the overlap check cannot compare an open-ended schedule. */ export const initialScheduleHorizon = (today: string): { start: string; end: string } => { const [year, month, day] = today.split('-').map(Number); const anniversary = new Date(Date.UTC(year + 1, month - 1, day)); // A 29 February start has no anniversary date; Date rolls to 1 March, so the day before is 28 February. anniversary.setUTCDate(anniversary.getUTCDate() - 1); return { start: today, end: anniversary.toISOString().slice(0, 10) }; }; /** A schedule date for a sentence, e.g. 23 September 2027, day first like formatDayMonthYear. */ export const formatScheduleDate = (date: string): string => new Date(`${date}T12:00:00Z`).toLocaleDateString('en-GB', { month: 'long', day: 'numeric', year: 'numeric', timeZone: 'UTC' });