From 04e452b70f3aedc32f2fdc5d6037a299e49cc3c2 Mon Sep 17 00:00:00 2001 From: Niclas Date: Tue, 17 Dec 2024 11:58:37 +0100 Subject: [PATCH 1/2] fix: correct event duration --- source/php/Helper/SingleEventData.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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); From 2ac92da7335e5b77241640146132dba5f8a0de61 Mon Sep 17 00:00:00 2001 From: Thor Brink Date: Wed, 18 Dec 2024 09:49:24 +0000 Subject: [PATCH 2/2] test: add unit test for getFormattedTimeDiff() in SingleEventData --- .../phpunit/tests/Helper/SingleEventData.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/phpunit/tests/Helper/SingleEventData.php 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