Retrieves the most recent skip timestamp from a track's history

Identifies the most recent time a track was skipped by analyzing and sorting all recorded skip timestamps. Handles both ISO string and numeric timestamp formats for maximum compatibility.

Falls back to lastSkipped field if detailed history is unavailable.

export const getMostRecentTimestamp = (track: SkippedTrack): string => {
if (track.skipTimestamps && track.skipTimestamps.length > 0) {
// Sort timestamps in descending order (newest first)
const sortedTimestamps = [...track.skipTimestamps].sort((a, b) => {
const dateA = isNaN(Number(a)) ? new Date(a).getTime() : Number(a);
const dateB = isNaN(Number(b)) ? new Date(b).getTime() : Number(b);
return dateB - dateA;
});
return sortedTimestamps[0];
}

// Fallback to lastSkipped
return track.lastSkipped || "";
};