* Formats a CalendarEventTime into a human-readable string. * All-day events use the date field; timed events use dateTime.
(eventTime?: CalendarEventTime)
| 49 | * All-day events use the date field; timed events use dateTime. |
| 50 | */ |
| 51 | function formatEventTime(eventTime?: CalendarEventTime): string { |
| 52 | if (!eventTime) return 'Unknown' |
| 53 | if (eventTime.dateTime) { |
| 54 | const date = new Date(eventTime.dateTime) |
| 55 | return date.toLocaleString('en-US', { |
| 56 | weekday: 'long', |
| 57 | year: 'numeric', |
| 58 | month: 'long', |
| 59 | day: 'numeric', |
| 60 | hour: 'numeric', |
| 61 | minute: '2-digit', |
| 62 | timeZoneName: 'short', |
| 63 | timeZone: eventTime.timeZone || undefined, |
| 64 | }) |
| 65 | } |
| 66 | if (eventTime.date) { |
| 67 | const date = new Date(`${eventTime.date}T00:00:00`) |
| 68 | return date.toLocaleDateString('en-US', { |
| 69 | weekday: 'long', |
| 70 | year: 'numeric', |
| 71 | month: 'long', |
| 72 | day: 'numeric', |
| 73 | }) |
| 74 | } |
| 75 | return 'Unknown' |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Determines whether the event is all-day based on whether `date` (not `dateTime`) is used. |