diff --git a/app.py b/app.py index a7efbcf..26094b9 100644 --- a/app.py +++ b/app.py @@ -662,7 +662,10 @@ def monthly_report( for r in db.fetchall() ] total_ms = sum(t["total_ms"] for t in tasks) - return {"tasks": tasks, "total_ms": total_ms} + from datetime import datetime, timezone + period_start = datetime.fromtimestamp(thirty_days_ago_ms / 1000, tz=timezone.utc).strftime("%Y-%m-%d") + period_end = datetime.now(timezone.utc).strftime("%Y-%m-%d") + return {"tasks": tasks, "total_ms": total_ms, "period_start": period_start, "period_end": period_end} def count_today_sessions(user_id: int, db) -> int: diff --git a/static/app.js b/static/app.js index f3baad2..08f6667 100644 --- a/static/app.js +++ b/static/app.js @@ -2263,7 +2263,9 @@ async function initReportPage() { .filter(t => t.total_ms > 0) .sort((a, b) => b.total_ms - a.total_ms); const total_ms = tasks.reduce((a, t) => a + t.total_ms, 0); - renderReport(contentEl, { tasks, total_ms }); + const period_start = new Date(thirtyDaysAgo).toISOString().slice(0, 10); + const period_end = new Date().toISOString().slice(0, 10); + renderReport(contentEl, { tasks, total_ms, period_start, period_end }); return; } @@ -2307,7 +2309,16 @@ function renderReport(el, data) { `; }).join(''); + const fmtDate = iso => { + const d = new Date(iso + 'T12:00:00'); + return d.toLocaleDateString(undefined, { month: 'short', day: 'numeric' }); + }; + const periodLabel = data.period_start && data.period_end + ? `${fmtDate(data.period_start)} – ${fmtDate(data.period_end)}` + : 'Last 30 days'; + el.innerHTML = ` +