From fa0a190277ce66b8f5e4ad2e93188faf53a31ce5 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Fri, 13 Dec 2013 16:10:36 -0500 Subject: [PATCH] Prevent division by zero if show lengths end up being zero --- airtime_mvc/application/models/Show.php | 8 ++++++-- airtime_mvc/application/models/ShowInstance.php | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 2065ed425..4a72d854d 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1061,8 +1061,12 @@ SQL; { $durationSeconds = (strtotime($p_ends) - strtotime($p_starts)); $time_filled = Application_Model_Schedule::WallTimeToMillisecs($p_time_filled) / 1000; - $percent = ceil(( $time_filled / $durationSeconds) * 100); - + + if ($durationSeconds != 0) { //Prevent division by zero if zero length show occurs. + $percent = ceil(( $time_filled / $durationSeconds) * 100); + } else { + $percent = 0; + } return $percent; } diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index 810c33348..279748035 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -550,9 +550,12 @@ SQL; { $durationSeconds = $this->getDurationSecs(); $timeSeconds = $this->getTimeScheduledSecs(); - - $percent = ceil(($timeSeconds / $durationSeconds) * 100); - + + if ($durationSeconds != 0) { //Prevent division by zero if the show duration is somehow zero. + $percent = ceil(($timeSeconds / $durationSeconds) * 100); + } else { + $percent = 0; + } return $percent; }