Complete reading history.
Time range to filter by.
Filtered entries within the time range.
export function filterHistoryByTimeRange(
history: ReadingHistory,
timeRange: TimeRange,
): ReadingHistoryEntry[] {
if (timeRange === "all") {
return history.entries;
}
const now = Date.now();
const ranges = {
"7d": 7 * 24 * 60 * 60 * 1000,
"30d": 30 * 24 * 60 * 60 * 1000,
"90d": 90 * 24 * 60 * 60 * 1000,
};
const cutoff = now - ranges[timeRange];
return history.entries.filter((entry) => entry.timestamp >= cutoff);
}
Filters reading history entries by time range.