← arena
Last week in review
SeniorTypeScriptdate-fnsCron
REP-58the ticket
Weekly activity digest
A cron job runs every Monday at 06:00 UTC and emails each user a digest of the week that just ended.
The week runs Monday 00:00 to Sunday 23:59 in the user's own timezone — we store timeZone on the user for exactly this. Users in Auckland and Los Angeles should each see their own Monday.
the agent’s descriptionagent · sonnet-class model
Used date-fns startOfWeek/endOfWeek to get the week boundaries, then a single range query on createdAt. The per-day breakdown is grouped in the user's timezone so the email reads correctly wherever they are.
Spot-checked my own account against the events table and the totals line up.
Written by the agent that opened the PR. Fluent, specific, and not evidence of anything.
src/server/reports/weekly.ts25 lines
1
import { startOfWeek, endOfWeek, format } from "date-fns";2
import { db } from "@/server/db";3
import { groupByDay } from "./group-by-day";4
5
type ReportUser = { id: string; timeZone: string };6
7
export async function weeklyReport(user: ReportUser) {8
const now = new Date();9
10
const from = startOfWeek(now);11
const to = endOfWeek(now);12
13
const events = await db.event.findMany({14
where: {15
userId: user.id,16
createdAt: { gte: from, lte: to },17
},18
});19
20
return {21
range: format(from, "MMM d") + " - " + format(to, "MMM d"),22
total: events.length,23
byDay: groupByDay(events, user.timeZone),24
};25
}