@@ -14,20 +14,48 @@ async function getCachedEateries(): Promise<EateryWithEvents[]> {
1414 }
1515}
1616
17- export const getAllEateries = async ( days : number = 0 ) => {
17+ export const getAllEateries = async ( days ? : number ) => {
1818 const cachedEateries = await getCachedEateries ( ) ;
1919
20- // Calculate date range for filtering events
21- // days=0 means today, days=1 means tomorrow, etc.
20+ // If no days parameter provided, return all eateries with all events
21+ if ( days === undefined ) {
22+ return cachedEateries ;
23+ }
24+
25+ // Calculate date range for filtering events using UTC to match event timestamps
26+ // days=0 means today, days=1 means tomorrow, days=2 means day after tomorrow, etc.
2227 const now = new Date ( ) ;
23- const targetDay = new Date ( now ) ;
24- targetDay . setDate ( now . getDate ( ) + days ) ;
2528
26- const startOfDay = new Date ( targetDay ) ;
27- startOfDay . setHours ( 0 , 0 , 0 , 0 ) ;
29+ // Add days by adding milliseconds (avoids timezone issues)
30+ const msPerDay = 24 * 60 * 60 * 1000 ;
31+ const targetTimestamp = now . getTime ( ) + days * msPerDay ;
32+ const targetDate = new Date ( targetTimestamp ) ;
33+
34+ // Set to start of day in UTC
35+ const startOfDay = new Date (
36+ Date . UTC (
37+ targetDate . getUTCFullYear ( ) ,
38+ targetDate . getUTCMonth ( ) ,
39+ targetDate . getUTCDate ( ) ,
40+ 0 ,
41+ 0 ,
42+ 0 ,
43+ 0 ,
44+ ) ,
45+ ) ;
2846
29- const endOfDay = new Date ( targetDay ) ;
30- endOfDay . setHours ( 23 , 59 , 59 , 999 ) ;
47+ // Set to end of day in UTC
48+ const endOfDay = new Date (
49+ Date . UTC (
50+ targetDate . getUTCFullYear ( ) ,
51+ targetDate . getUTCMonth ( ) ,
52+ targetDate . getUTCDate ( ) ,
53+ 23 ,
54+ 59 ,
55+ 59 ,
56+ 999 ,
57+ ) ,
58+ ) ;
3159
3260 // Filter events to only include those on the specified day
3361 const filteredEateries = cachedEateries . map ( ( eatery ) => ( {
0 commit comments