(date: Date, timezone?: string)
| 58 | * @returns A formatted date string in the format "MMM D, YYYY h:mm A" |
| 59 | */ |
| 60 | export function formatDateTime(date: Date, timezone?: string): string { |
| 61 | const formattedDate = date.toLocaleString('en-US', { |
| 62 | month: 'short', |
| 63 | day: 'numeric', |
| 64 | year: 'numeric', |
| 65 | hour: 'numeric', |
| 66 | minute: '2-digit', |
| 67 | hour12: true, |
| 68 | timeZone: timezone || undefined, |
| 69 | }) |
| 70 | |
| 71 | if (timezone) { |
| 72 | const tzAbbr = getTimezoneAbbreviation(timezone, date) |
| 73 | return `${formattedDate} ${tzAbbr}` |
| 74 | } |
| 75 | |
| 76 | return formattedDate |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Format a date into a short format |
no test coverage detected