Counts track skips within a specified timeframe

Analyzes a track's skip history to determine how many times it has been skipped within the configured timeframe. Uses timestamp parsing to ensure accurate date comparison regardless of timestamp format.

Handles tracks with missing timestamp data by falling back to total skip count.

export const getRecentSkipCount = (
track: SkippedTrack,
timeframeInDays: number,
): number => {
if (!track.skipTimestamps || track.skipTimestamps.length === 0) {
return track.skipCount || 0;
}

const cutoffDate = new Date();
cutoffDate.setDate(cutoffDate.getDate() - timeframeInDays);

return track.skipTimestamps.filter((timestamp) => {
const skipDate = parseTimestamp(timestamp);
return skipDate && skipDate >= cutoffDate;
}).length;
};
  • Parameters

    • track: SkippedTrack

      Track data object containing skip history

    • timeframeInDays: number

      Analysis window in days (e.g., 30 for last month)

    Returns number

    Number of times the track was skipped within the timeframe