@@ -17,21 +17,12 @@ const getEventsFromCalendar = async url => {
1717 * @returns {Promise<Date> } The date of the next meeting
1818 */
1919export const findNextMeetingDate = async ( { properties } ) => {
20- const now = new Date ( ) ;
20+ const start = new Date ( ) ;
21+ start . setUTCHours ( 0 , 0 , 0 , 0 ) ;
2122
22- // Calculate the start of the current week (Saturday 00:00:00 UTC)
23- // This handles the scenario where we want a full week from Saturday to Friday
24- const daysSinceStartOfWeek = ( now . getUTCDay ( ) + 1 ) % 7 ; // Saturday = 0, Sunday = 1, ..., Friday = 6
25- const weekStart = new Date ( now ) ;
26-
27- weekStart . setUTCDate ( now . getUTCDate ( ) - daysSinceStartOfWeek ) ;
28- weekStart . setUTCHours ( 0 , 0 , 0 , 0 ) ;
29-
30- // Calculate the end of the week (Friday 23:59:59 UTC)
31- const weekEnd = new Date ( weekStart ) ;
32-
33- weekEnd . setUTCDate ( weekStart . getUTCDate ( ) + 6 ) ;
34- weekEnd . setUTCHours ( 23 , 59 , 59 , 999 ) ;
23+ // One week from today
24+ const end = new Date ( start ) ;
25+ end . setUTCDate ( start . getUTCDate ( ) + 7 ) ;
3526
3627 const allEvents = await getEventsFromCalendar ( properties . ICAL_URL ) ;
3728
@@ -46,16 +37,16 @@ export const findNextMeetingDate = async ({ properties }) => {
4637 for ( const event of filteredEvents ) {
4738 // Get all recurrences in our timeframe
4839 event . rrule . options . tzid = event . tzid ;
49- const duringOurTimeframe = event . rrule . between ( weekStart , weekEnd ) ;
40+ const duringOurTimeframe = event . rrule . between ( start , end ) ;
5041
5142 if ( duringOurTimeframe . length > 0 ) {
5243 return duringOurTimeframe [ 0 ] ;
5344 }
5445 }
5546
56- throw new Error (
47+ console . error (
5748 `No meeting found for ${ properties . GROUP_NAME || 'this group' } ` +
58- `in the current week (${ weekStart . toISOString ( ) . split ( 'T' ) [ 0 ] } to ${ weekEnd . toISOString ( ) . split ( 'T' ) [ 0 ] } ). ` +
49+ `in the next week (${ start . toISOString ( ) . split ( 'T' ) [ 0 ] } to ${ end . toISOString ( ) . split ( 'T' ) [ 0 ] } ). ` +
5950 `This is expected for bi-weekly meetings or meetings that don't occur every week.`
6051 ) ;
6152} ;
0 commit comments