Add opt-in date grouping for the All Notes list

This commit is contained in:
Yuri Karamian
2026-06-24 22:38:23 +02:00
parent 3ef0e14581
commit 987b1b9ed7
5 changed files with 83 additions and 6 deletions
+17
View File
@@ -24,3 +24,20 @@ export function formatDate(dateStr: string): string {
minute: '2-digit'
});
}
// Relative-date bucket label for grouping the notes list:
// Today / Yesterday / Previous 7 Days / Previous 30 Days / "June" (this year) / "June 2025".
// Buckets are contiguous, so a list already sorted by date groups by consecutive label.
export function dateBucketLabel(dateStr: string, now: Date = new Date()): string {
const d = new Date(dateStr);
const dayMs = 86400000;
const startOfDay = (x: Date) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
const today = startOfDay(now);
const day = startOfDay(d);
if (day >= today) return 'Today';
if (day >= today - dayMs) return 'Yesterday';
if (day >= today - 7 * dayMs) return 'Previous 7 Days';
if (day >= today - 30 * dayMs) return 'Previous 30 Days';
if (d.getFullYear() === now.getFullYear()) return d.toLocaleDateString(undefined, { month: 'long' });
return d.toLocaleDateString(undefined, { month: 'long', year: 'numeric' });
}