diff --git a/application/models/Nowplaying.php b/application/models/Nowplaying.php index dc4c4e7aa..8b02c0f74 100644 --- a/application/models/Nowplaying.php +++ b/application/models/Nowplaying.php @@ -27,7 +27,7 @@ class Application_Model_Nowplaying $arrayIndexOffset = 0; if ($n < 2) - return; + return $rows; for ($i=1; $i<$n; $i++){ if ($rows[$i-1][3] != $rows[$i][2]) diff --git a/application/models/Schedule.php b/application/models/Schedule.php index 037093c3e..12f661cda 100644 --- a/application/models/Schedule.php +++ b/application/models/Schedule.php @@ -586,14 +586,18 @@ class Schedule { public static function GetNextShow($timeNow) { global $CC_CONFIG, $CC_DBC; - - $sql = "SELECT current_date + sd.start_time as start_timestamp, current_date + sd.end_time as end_timestamp, s.name, s.id" - ." FROM $CC_CONFIG[showDays] sd, $CC_CONFIG[showTable] s" - ." WHERE sd.show_id = s.id" - ." AND (sd.first_show + sd.start_time) >= TIMESTAMP '$timeNow'" - ." ORDER BY (sd.first_show + sd.start_time)" - ." LIMIT 1"; + $datetime = explode(" ", $timeNow); + + $sql = "SELECT *, (current_date + start_time) as start_timestamp, (current_date + end_time) as end_timestamp FROM " + ." $CC_CONFIG[showDays] sd, $CC_CONFIG[showTable] s" + ." WHERE sd.show_id = s.id" + ." AND ((sd.last_show + sd.end_time) > TIMESTAMP '$timeNow' OR sd.last_show = NULL)" + ." AND TIME '$datetime[1]' < sd.start_time " + ." AND sd.day = EXTRACT(DOW FROM TIMESTAMP '$timeNow')" + ." ORDER BY sd.start_time" + ." LIMIT 1"; + $rows = $CC_DBC->GetAll($sql); return $rows; } diff --git a/public/js/playlist/playlist.js b/public/js/playlist/playlist.js index 84e18524b..71f0618b2 100644 --- a/public/js/playlist/playlist.js +++ b/public/js/playlist/playlist.js @@ -104,17 +104,23 @@ function updateProgressBarValue(){ //calculate how much time left to next song if there is any if (nextSongs.length > 0 && nextSongPrepare){ - if (nextSongs[0].songStartPosixTime - estimatedSchedulePosixTime < serverUpdateInterval){ + var diff = nextSongs[0].songStartPosixTime - estimatedSchedulePosixTime; + if (diff < serverUpdateInterval && diff >= 0){ nextSongPrepare = false; - setTimeout(newSongStart, nextSongs[0].songStartPosixTime - estimatedSchedulePosixTime); + setTimeout(newSongStart, diff); + } else if (diff < 0){ + alert ("Warning: estimatedSchedulePosixTime > songStartPosixTime"); } } //calculate how much time left to next show if there is any if (nextShow.length > 0 && nextShowPrepare){ - if (nextShow[0].showStartPosixTime - estimatedSchedulePosixTime < serverUpdateInterval){ + var diff = nextShow[0].showStartPosixTime - estimatedSchedulePosixTime; + if (diff < serverUpdateInterval && diff >= 0){ nextShowPrepare = false; - setTimeout(nextShowStart, nextShow[0].showStartPosixTime - estimatedSchedulePosixTime); + setTimeout(nextShowStart, diff); + } else if (diff < 0){ + alert ("Warning: estimatedSchedulePosixTime > showStartPosixTime"); } } @@ -185,6 +191,12 @@ function calcAdditionalShowData(show){ if (show.length > 0){ show[0].showStartPosixTime = convertDateToPosixTime(show[0].start_timestamp); show[0].showEndPosixTime = convertDateToPosixTime(show[0].end_timestamp); + + //hack to fix case where show end is next day, but we have it set + //as the same day. + if (show[0].showEndPosixTime - show[0].showStartPosixTime < 0) + show[0].showEndPosixTime += 1000*3600*24; + show[0].showLengthMs = show[0].showEndPosixTime - show[0].showStartPosixTime; } }