diff --git a/core/Metrics/Formatter.php b/core/Metrics/Formatter.php index 077646ba00186d3ca2e5dd41ec16ed6c5e43c42d..d62db65f31cf5a7f3f570f586bab0e3b97deab45 100644 --- a/core/Metrics/Formatter.php +++ b/core/Metrics/Formatter.php @@ -72,10 +72,15 @@ class Formatter // Display 01:45:17 time format if ($displayTimeAsSentence === false) { - $hours = floor($numberOfSeconds / 3600); - $minutes = floor(($reminder = ($numberOfSeconds - $hours * 3600)) / 60); + $days = floor($numberOfSeconds / 86400); + $hours = floor(($reminder = ($numberOfSeconds - $days * 86400)) / 3600); + $minutes = floor(($reminder = ($reminder - $hours * 3600)) / 60); $seconds = floor($reminder - $minutes * 60); - $time = sprintf("%02s", $hours) . ':' . sprintf("%02s", $minutes) . ':' . sprintf("%02s", $seconds); + if ($days == 0) { + $time = sprintf("%02s", $hours) . ':' . sprintf("%02s", $minutes) . ':' . sprintf("%02s", $seconds); + } else { + $time = sprintf(Piwik::translate('Intl_NDays'), $days) . " " . sprintf("%02s", $hours) . ':' . sprintf("%02s", $minutes) . ':' . sprintf("%02s", $seconds); + } $centiSeconds = ($numberOfSeconds * 100) % 100; if ($centiSeconds) { $time .= '.' . sprintf("%02s", $centiSeconds); diff --git a/tests/PHPUnit/Unit/Metrics/FormatterTest.php b/tests/PHPUnit/Unit/Metrics/FormatterTest.php index 0bcef84c5faecf05c295de6e3401623ffda24a3f..d9ccc18c6dae62e25712dcd1275cb5c7746b7dba 100644 --- a/tests/PHPUnit/Unit/Metrics/FormatterTest.php +++ b/tests/PHPUnit/Unit/Metrics/FormatterTest.php @@ -190,9 +190,9 @@ class FormatterTest extends \PHPUnit_Framework_TestCase array(100, array('1 min 40s', '00:01:40')), array(3600, array('1 hours 0 min', '01:00:00')), array(3700, array('1 hours 1 min', '01:01:40')), - array(86400 + 3600 * 10, array('1 days 10 hours', '34:00:00')), - array(86400 * 365, array('365 days 0 hours', '8760:00:00')), - array((86400 * (365.25 + 10)), array('1 years 10 days', '9006:00:00')), + array(86400 + 3600 * 10, array('1 days 10 hours', '1 days 10:00:00')), + array(86400 * 365, array('365 days 0 hours', '365 days 00:00:00')), + array((86400 * (365.25 + 10)), array('1 years 10 days', '375 days 06:00:00')), array(1.342, array('1.34s', '00:00:01.34')), array(.342, array('0.34s', '00:00:00.34')), array(.02, array('0.02s', '00:00:00.02')), @@ -202,7 +202,7 @@ class FormatterTest extends \PHPUnit_Framework_TestCase array(1.2, array('1.2s', '00:00:01.20')), array(122.1, array('2 min 2.1s', '00:02:02.10')), array(-122.1, array('-2 min 2.1s', '-00:02:02.10')), - array(86400 * -365, array('-365 days 0 hours', '-8760:00:00')) + array(86400 * -365, array('-365 days 0 hours', '-365 days 00:00:00')) ); } @@ -222,4 +222,4 @@ class FormatterTest extends \PHPUnit_Framework_TestCase SitesManagerAPI::setSingletonInstance($mock); } -} \ No newline at end of file +}