Prevent division by zero if show lengths end up being zero

This commit is contained in:
Albert Santoni 2013-12-13 16:10:36 -05:00
parent 1577b7c41e
commit fa0a190277
2 changed files with 12 additions and 5 deletions

View file

@ -1061,8 +1061,12 @@ SQL;
{ {
$durationSeconds = (strtotime($p_ends) - strtotime($p_starts)); $durationSeconds = (strtotime($p_ends) - strtotime($p_starts));
$time_filled = Application_Model_Schedule::WallTimeToMillisecs($p_time_filled) / 1000; $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; return $percent;
} }

View file

@ -550,9 +550,12 @@ SQL;
{ {
$durationSeconds = $this->getDurationSecs(); $durationSeconds = $this->getDurationSecs();
$timeSeconds = $this->getTimeScheduledSecs(); $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; return $percent;
} }