Skip to content

Commit 5dd1536

Browse files
committed
Show date range on monthly report page
The report covers the last 30 days but the page didn't say so — now it displays "Mar 4 – Apr 3" (or equivalent) above the total.
1 parent 19fc7fb commit 5dd1536

4 files changed

Lines changed: 24 additions & 2 deletions

File tree

app.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,10 @@ def monthly_report(
662662
for r in db.fetchall()
663663
]
664664
total_ms = sum(t["total_ms"] for t in tasks)
665-
return {"tasks": tasks, "total_ms": total_ms}
665+
from datetime import datetime, timezone
666+
period_start = datetime.fromtimestamp(thirty_days_ago_ms / 1000, tz=timezone.utc).strftime("%Y-%m-%d")
667+
period_end = datetime.now(timezone.utc).strftime("%Y-%m-%d")
668+
return {"tasks": tasks, "total_ms": total_ms, "period_start": period_start, "period_end": period_end}
666669

667670

668671
def count_today_sessions(user_id: int, db) -> int:

static/app.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,9 @@ async function initReportPage() {
22632263
.filter(t => t.total_ms > 0)
22642264
.sort((a, b) => b.total_ms - a.total_ms);
22652265
const total_ms = tasks.reduce((a, t) => a + t.total_ms, 0);
2266-
renderReport(contentEl, { tasks, total_ms });
2266+
const period_start = new Date(thirtyDaysAgo).toISOString().slice(0, 10);
2267+
const period_end = new Date().toISOString().slice(0, 10);
2268+
renderReport(contentEl, { tasks, total_ms, period_start, period_end });
22672269
return;
22682270
}
22692271

@@ -2307,7 +2309,16 @@ function renderReport(el, data) {
23072309
</div>`;
23082310
}).join('');
23092311

2312+
const fmtDate = iso => {
2313+
const d = new Date(iso + 'T12:00:00');
2314+
return d.toLocaleDateString(undefined, { month: 'short', day: 'numeric' });
2315+
};
2316+
const periodLabel = data.period_start && data.period_end
2317+
? `${fmtDate(data.period_start)}${fmtDate(data.period_end)}`
2318+
: 'Last 30 days';
2319+
23102320
el.innerHTML = `
2321+
<div class="report-period">${periodLabel}</div>
23112322
<div class="report-total">
23122323
<span class="report-total-label">Total</span>
23132324
<span class="report-total-time">${fmtHM(data.total_ms)}</span>

static/style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,12 @@ html[data-theme="dark"] .sl-date-input { color-scheme: dark; }
16051605
margin-bottom: 24px;
16061606
}
16071607

1608+
.report-period {
1609+
font-size: 14px;
1610+
color: var(--dimmer);
1611+
margin-bottom: 8px;
1612+
}
1613+
16081614
.report-total {
16091615
display: flex;
16101616
justify-content: space-between;

tests/test_report.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def test_report_empty(client, alice):
3131
body = r.json()
3232
assert body["tasks"] == []
3333
assert body["total_ms"] == 0
34+
assert "period_start" in body
35+
assert "period_end" in body
3436

3537

3638
def test_report_includes_recent_sessions(client, alice):

0 commit comments

Comments
 (0)