@@ -94,10 +94,13 @@ export const formatDtstartToMidnight = (dtstart: string): string => {
9494
9595/**
9696 * Get date category for event grouping (today, tomorrow, later this week, later this month, later, past)
97+ * For multi-day events, checks if today falls within the event's date range
9798 */
98- export const getDateCategory = ( dateString : string ) : 'today' | 'tomorrow' | 'later this week' | 'later this month' | 'later' | 'past' => {
99+ export const getDateCategory = ( startDateString : string , endDateString ?: string | null ) : 'today' | 'tomorrow' | 'later this week' | 'later this month' | 'later' | 'past' => {
99100 try {
100- const eventDate = new Date ( removeTimezoneInfo ( dateString ) ) ;
101+ const eventStartDate = new Date ( removeTimezoneInfo ( startDateString ) ) ;
102+ const eventEndDate = endDateString ? new Date ( removeTimezoneInfo ( endDateString ) ) : null ;
103+
101104 const today = new Date ( ) ;
102105 const tomorrow = new Date ( today ) ;
103106 tomorrow . setDate ( today . getDate ( ) + 1 ) ;
@@ -111,21 +114,28 @@ export const getDateCategory = (dateString: string): 'today' | 'tomorrow' | 'lat
111114 const endOfMonth = new Date ( today . getFullYear ( ) , today . getMonth ( ) + 1 , 0 ) ;
112115
113116 // Reset time to start of day for comparison
114- const eventDateOnly = new Date ( eventDate . getFullYear ( ) , eventDate . getMonth ( ) , eventDate . getDate ( ) ) ;
117+ const eventStartDateOnly = new Date ( eventStartDate . getFullYear ( ) , eventStartDate . getMonth ( ) , eventStartDate . getDate ( ) ) ;
118+ const eventEndDateOnly = eventEndDate ? new Date ( eventEndDate . getFullYear ( ) , eventEndDate . getMonth ( ) , eventEndDate . getDate ( ) ) : eventStartDateOnly ;
115119 const todayOnly = new Date ( today . getFullYear ( ) , today . getMonth ( ) , today . getDate ( ) ) ;
116120 const tomorrowOnly = new Date ( tomorrow . getFullYear ( ) , tomorrow . getMonth ( ) , tomorrow . getDate ( ) ) ;
117121 const endOfWeekOnly = new Date ( endOfWeek . getFullYear ( ) , endOfWeek . getMonth ( ) , endOfWeek . getDate ( ) ) ;
118122 const endOfMonthOnly = new Date ( endOfMonth . getFullYear ( ) , endOfMonth . getMonth ( ) , endOfMonth . getDate ( ) ) ;
119123
120- if ( eventDateOnly . getTime ( ) === todayOnly . getTime ( ) ) {
124+ // Check if today falls within the event's date range (for multi-day events)
125+ const todayTime = todayOnly . getTime ( ) ;
126+ const isHappeningToday = todayTime >= eventStartDateOnly . getTime ( ) && todayTime <= eventEndDateOnly . getTime ( ) ;
127+ const isHappeningTomorrow = tomorrowOnly . getTime ( ) >= eventStartDateOnly . getTime ( ) && tomorrowOnly . getTime ( ) <= eventEndDateOnly . getTime ( ) ;
128+
129+ if ( isHappeningToday ) {
121130 return 'today' ;
122- } else if ( eventDateOnly . getTime ( ) === tomorrowOnly . getTime ( ) ) {
131+ } else if ( isHappeningTomorrow || eventStartDateOnly . getTime ( ) === tomorrowOnly . getTime ( ) ) {
123132 return 'tomorrow' ;
124- } else if ( eventDateOnly . getTime ( ) < todayOnly . getTime ( ) ) {
133+ } else if ( eventEndDateOnly . getTime ( ) < todayOnly . getTime ( ) ) {
134+ // Event has completely ended
125135 return 'past' ;
126- } else if ( eventDateOnly . getTime ( ) <= endOfWeekOnly . getTime ( ) ) {
136+ } else if ( eventStartDateOnly . getTime ( ) <= endOfWeekOnly . getTime ( ) ) {
127137 return 'later this week' ;
128- } else if ( eventDateOnly . getTime ( ) <= endOfMonthOnly . getTime ( ) ) {
138+ } else if ( eventStartDateOnly . getTime ( ) <= endOfMonthOnly . getTime ( ) ) {
129139 return 'later this month' ;
130140 } else {
131141 return 'later' ;
0 commit comments