forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

child-homework.ts20 lines, 822 bytesHistoryRawDownload
1import type { HomeworkReportEntry } from "@/api/client";
2
3const WEEK_MS = 7 * 24 * 60 * 60 * 1000;
4
5export type ChildHomeworkSummary = {
6 /** Past due and not handed in, most overdue first. */
7 missing: HomeworkReportEntry[];
8 /** Not handed in and due within the next seven days, soonest first. */
9 dueSoon: HomeworkReportEntry[];
10};
11
12/** A parent's view of a child's homework report: what is late and what is next. */
13export function summarizeChildHomework(entries: HomeworkReportEntry[], now: number): ChildHomeworkSummary {
14 return {
15 missing: entries.filter((entry) => entry.missing).sort((a, b) => a.due_at - b.due_at),
16 dueSoon: entries
17 .filter((entry) => !entry.submitted && !entry.missing && entry.due_at >= now && entry.due_at < now + WEEK_MS)
18 .sort((a, b) => a.due_at - b.due_at),
19 };
20}