mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-09-20 01:47:29 +02:00
Add opt-in date grouping for the All Notes list
This commit is contained in:
@@ -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' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user