Number of days to look back
Tracks within the timeframe (including non-skipped tracks)
export function filterSkippedTracksByTimeframe(
days: number = 30,
): SkippedTrack[] {
const tracks = getSkippedTracks();
if (tracks.length === 0) return [];
const cutoffDate = new Date();
cutoffDate.setDate(cutoffDate.getDate() - days);
return tracks.filter((track) => {
// Always include tracks that have never been skipped but were fully played
if (!track.skipCount || track.skipCount === 0) {
return true;
}
// For tracks with no skip timestamps, check the lastSkipped date
if (!track.skipTimestamps || track.skipTimestamps.length === 0) {
if (!track.lastSkipped) return true; // Include if no timestamp available
const lastSkippedDate = parseTimestamp(track.lastSkipped);
return lastSkippedDate && lastSkippedDate >= cutoffDate;
}
// Check if any skip timestamps are within the timeframe
return track.skipTimestamps.some((timestamp) => {
const skipDate = parseTimestamp(timestamp);
return skipDate && skipDate >= cutoffDate;
});
});
}
Filters skipped tracks by a specified timeframe