diff --git a/source/php/Helper/SingleEventData.php b/source/php/Helper/SingleEventData.php index 4dbf1705..43534a58 100644 --- a/source/php/Helper/SingleEventData.php +++ b/source/php/Helper/SingleEventData.php @@ -106,7 +106,7 @@ public static function singleEventDate($postId = null, $dateTime = null) */ public static function getFormattedTimeDiff($start, $end) { - $diff = ($end - $start) / 60 / 60; + $diff = ($end - $start) / 3600; $singleEventData = new SingleEventData(); @@ -122,8 +122,8 @@ public static function getFormattedTimeDiff($start, $end) public function eventOccasionDuration($from, $to) { $diff = (int)abs($to - $from); if ($diff < DAY_IN_SECONDS && $diff >= HOUR_IN_SECONDS) { - $hours = round($diff / HOUR_IN_SECONDS ); - $mins = round($diff / MINUTE_IN_SECONDS) - ($hours * 60); + $hours = floor($diff / HOUR_IN_SECONDS ); + $mins = floor($diff / MINUTE_IN_SECONDS) - ($hours * 60); $formattedDiff = sprintf(_n('%s hour', '%s hours', $hours), $hours); if ($mins > 0) { $formattedMins = sprintf(_n('%s min', '%s mins', $mins), $mins); diff --git a/tests/phpunit/tests/Helper/SingleEventData.php b/tests/phpunit/tests/Helper/SingleEventData.php new file mode 100644 index 00000000..e20e786d --- /dev/null +++ b/tests/phpunit/tests/Helper/SingleEventData.php @@ -0,0 +1,22 @@ +assertEquals('1 hour 31 mins', SingleEventData::getFormattedTimeDiff($start, $end)); + } +} \ No newline at end of file