diff --git a/spotify-recent-oauth.php b/spotify-recent-oauth.php index 9c8679d..40c1f21 100644 --- a/spotify-recent-oauth.php +++ b/spotify-recent-oauth.php @@ -99,14 +99,32 @@ function sro_render_block() { $artist = $item['track']['artists'][0]['name']; $img = $item['track']['album']['images'][0]['url']; + /* gammal version $played = strtotime($item['played_at']); $mins = floor((time() - $played) / 60); + */ + $played = strtotime($item['played_at']); + $diff = time() - $played; + + // Räkna ut dagar, timmar, minuter + $days = floor($diff / 86400); // 86400 sek per dag + $hours = floor(($diff % 86400) / 3600); + $minutes = floor(($diff % 3600) / 60); + + // Välj rätt utskrift + if ($days > 0) { + $time_ago = $days . " dagar sedan"; + } elseif ($hours > 0) { + $time_ago = $hours . " timmar sedan"; + } else { + $time_ago = $minutes . " minuter sedan"; + } return "