@@ -29,9 +29,13 @@ export const getUserStats = createServerFn({ method: 'POST' }).handler(
2929
3030 const totalUsers = totalUsersResult [ 0 ] ?. count ?? 0
3131
32- // Get users created in last 7 days (for daily breakdown)
33- const sevenDaysAgo = new Date ( )
34- sevenDaysAgo . setDate ( sevenDaysAgo . getDate ( ) - 7 )
32+ // Get users created in last 7 days (for daily breakdown) - using UTC
33+ const nowForSevenDays = new Date ( )
34+ const sevenDaysAgo = new Date ( Date . UTC (
35+ nowForSevenDays . getUTCFullYear ( ) ,
36+ nowForSevenDays . getUTCMonth ( ) ,
37+ nowForSevenDays . getUTCDate ( ) - 7
38+ ) )
3539
3640 const recentUsers = await db . query . users . findMany ( {
3741 where : gte ( users . createdAt , sevenDaysAgo ) ,
@@ -56,16 +60,16 @@ export const getUserStats = createServerFn({ method: 'POST' }).handler(
5660 }
5761 } )
5862
59- // Get daily signup counts (aggregated by day)
63+ // Get daily signup counts (aggregated by day) - using UTC for consistency
6064 // This gives us efficient per-day data that can be used for both daily and cumulative charts
6165 const dailySignupsData = await db
6266 . select ( {
63- date : sql < string > `DATE(${ users . createdAt } )` . as ( 'date' ) ,
67+ date : sql < string > `DATE(${ users . createdAt } AT TIME ZONE 'UTC' )` . as ( 'date' ) ,
6468 count : sql < number > `COUNT(*)::int` . as ( 'count' ) ,
6569 } )
6670 . from ( users )
67- . groupBy ( sql `DATE(${ users . createdAt } )` )
68- . orderBy ( sql `DATE(${ users . createdAt } )` )
71+ . groupBy ( sql `DATE(${ users . createdAt } AT TIME ZONE 'UTC' )` )
72+ . orderBy ( sql `DATE(${ users . createdAt } AT TIME ZONE 'UTC' )` )
6973
7074 // Convert to array of objects with proper date strings
7175 const signupsPerDay = dailySignupsData . map ( ( row ) => ( {
@@ -108,9 +112,13 @@ export const getUserStats = createServerFn({ method: 'POST' }).handler(
108112 const waitlistWithAdsDisabledCount =
109113 waitlistWithAdsDisabledResult [ 0 ] ?. count ?? 0
110114
111- // Calculate average signups per day (last 30 days)
112- const thirtyDaysAgo = new Date ( )
113- thirtyDaysAgo . setDate ( thirtyDaysAgo . getDate ( ) - 30 )
115+ // Calculate average signups per day (last 30 days) - using UTC
116+ const nowForThirtyDays = new Date ( )
117+ const thirtyDaysAgo = new Date ( Date . UTC (
118+ nowForThirtyDays . getUTCFullYear ( ) ,
119+ nowForThirtyDays . getUTCMonth ( ) ,
120+ nowForThirtyDays . getUTCDate ( ) - 30
121+ ) )
114122
115123 const last30DaysResult = await db
116124 . select ( { count : sql < number > `count(*)::int` } )
@@ -120,9 +128,9 @@ export const getUserStats = createServerFn({ method: 'POST' }).handler(
120128 const last30DaysCount = last30DaysResult [ 0 ] ?. count ?? 0
121129 const avgSignupsPerDay = Math . round ( last30DaysCount / 30 )
122130
123- // Calculate today's signups
124- const todayStart = new Date ( )
125- todayStart . setHours ( 0 , 0 , 0 , 0 )
131+ // Calculate today's signups (using UTC for consistency with charts)
132+ const now = new Date ( )
133+ const todayStart = new Date ( Date . UTC ( now . getUTCFullYear ( ) , now . getUTCMonth ( ) , now . getUTCDate ( ) ) )
126134
127135 const todayResult = await db
128136 . select ( { count : sql < number > `count(*)::int` } )
@@ -131,9 +139,8 @@ export const getUserStats = createServerFn({ method: 'POST' }).handler(
131139
132140 const todaySignups = todayResult [ 0 ] ?. count ?? 0
133141
134- // Calculate yesterday's signups
135- const yesterdayStart = new Date ( todayStart )
136- yesterdayStart . setDate ( yesterdayStart . getDate ( ) - 1 )
142+ // Calculate yesterday's signups (using UTC)
143+ const yesterdayStart = new Date ( Date . UTC ( now . getUTCFullYear ( ) , now . getUTCMonth ( ) , now . getUTCDate ( ) - 1 ) )
137144
138145 const yesterdayResult = await db
139146 . select ( { count : sql < number > `count(*)::int` } )
0 commit comments