import { clsx, type ClassValue } from "clsx" import { twMerge } from "tailwind-merge" export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)) } // REMOVED: `convertToLocalTime`, `convertToIST` and `getRelativeTime`. // // All three were Rudy-era, all three had ZERO call sites, and all three were WRONG for a US product: // - `convertToIST` - hardcoded India's +5:30 offset. // - `getRelativeTime` - hardcoded `Asia/Kolkata` twice in its body. // - `convertToLocalTime` - labelled "FIXED: Proper timezone conversion", but re-shifted a Date that // `new Date(isoString)` already returns in local time. Double-shifted. // // They were deleted rather than corrected because the danger was never the arithmetic - it was that a // session with a timezone problem greps for a helper, finds one commented "FIXED", and trusts it. // had just made timezone handling something sessions go looking for, which is what turned dead code into a // live hazard. The practice's timezone now lives in `src/utils/practiceTimezone.ts`; use that. export const formatDateForDisplay = (dateString: string): string => { if (!dateString) return ""; const [year, month, day] = dateString.split("-").map(Number); let date = new Date(year, month - 1, day); if(!(date instanceof Date && !isNaN(date.getTime()))) { date = new Date(dateString); } return date.toLocaleDateString("en-US", { weekday: "long", year: "numeric", month: "long", day: "numeric", }); }; export const formatTimeForDisplay = (dateString: string): string => { if (!dateString) return ""; const date = new Date(dateString); const userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; return date.toLocaleTimeString("en-US", { hour: "2-digit", minute: "2-digit", hour12: true, timeZone: userTimeZone }); }; // COMMENT CORRECTED, code untouched. It previously read "FIXED: Use India timezone for // accurate day difference" - it does NOT use India's timezone; it uses the VIEWER's, resolved below. The // behaviour was right and the label was wrong, which is the same trap that made the deleted helpers // dangerous: this file's comments have been trusted over its code before. // The viewer's timezone is the correct basis for "Today / Tomorrow" on a patient's own screen, but note // it is the VIEWER's, not the PRACTICE's - see for where that distinction does matter. export const getDaysDifference = (dateString: string): string => { if (!dateString) return ""; const appointmentDate = new Date(dateString); const now = new Date(); const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; const appointmentDateIST = appointmentDate.toLocaleString("en-US", { timeZone }); const nowLocal = now.toLocaleString("en-US", { timeZone }); // Create new dates from India timezone strings const appDate = new Date(appointmentDateIST); const currentDate = new Date(nowLocal); // Set both dates to start of day const appDateStart = new Date( appDate.getFullYear(), appDate.getMonth(), appDate.getDate() ); const currentDateStart = new Date( currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate() ); const diffTime = appDateStart.getTime() - currentDateStart.getTime(); const diffDays = Math.round(diffTime / (1000 * 60 * 60 * 24)); if (diffDays === 0) return "Today"; if (diffDays === 1) return "Tomorrow"; if (diffDays > 1) return `In ${diffDays} days`; if (diffDays === -1) return "Yesterday"; return `${Math.abs(diffDays)} days ago`; };