Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/MetricsFormatter.php15
-rw-r--r--tests/PHPUnit/Integration/Core/PiwikTest.php4
2 files changed, 18 insertions, 1 deletions
diff --git a/core/MetricsFormatter.php b/core/MetricsFormatter.php
index 5fd464ff8d..8f58e52588 100644
--- a/core/MetricsFormatter.php
+++ b/core/MetricsFormatter.php
@@ -56,6 +56,12 @@ class MetricsFormatter
{
$numberOfSeconds = $round ? (int)$numberOfSeconds : (float)$numberOfSeconds;
+ $isNegative = false;
+ if ($numberOfSeconds < 0) {
+ $numberOfSeconds = -1 * $numberOfSeconds;
+ $isNegative = true;
+ }
+
// Display 01:45:17 time format
if ($displayTimeAsSentence === false) {
$hours = floor($numberOfSeconds / 3600);
@@ -66,9 +72,13 @@ class MetricsFormatter
if ($centiSeconds) {
$time .= '.' . sprintf("%02s", $centiSeconds);
}
+ if ($isNegative) {
+ $time = '-' . $time;
+ }
return $time;
}
$secondsInYear = 86400 * 365.25;
+
$years = floor($numberOfSeconds / $secondsInYear);
$minusYears = $numberOfSeconds - $years * $secondsInYear;
$days = floor($minusYears / 86400);
@@ -94,6 +104,11 @@ class MetricsFormatter
} else {
$return = sprintf(Piwik::translate('General_Seconds'), $seconds);
}
+
+ if ($isNegative) {
+ $return = '-' . $return;
+ }
+
if ($isHtml) {
return str_replace(' ', '&nbsp;', $return);
}
diff --git a/tests/PHPUnit/Integration/Core/PiwikTest.php b/tests/PHPUnit/Integration/Core/PiwikTest.php
index 1f289fde94..1c49070681 100644
--- a/tests/PHPUnit/Integration/Core/PiwikTest.php
+++ b/tests/PHPUnit/Integration/Core/PiwikTest.php
@@ -149,7 +149,9 @@ class Core_PiwikTest extends DatabaseTestCase
array(1.002, array('1s', '00:00:01')),
array(1.02, array('1.02s', '00:00:01.02')),
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(-122.1, array('-2 min 2.1s', '-00:02:02.10')),
+ array(86400 * -365, array('-365 days 0 hours', '-8760:00:00'))
);
}