Skip to content
Extraits de code Groupes Projets
Valider 6f775e05 rédigé par Ritvik Gautam's avatar Ritvik Gautam Validation de Ritvik Gautam
Parcourir les fichiers

Update Formatter.php

Update Formatter.php

Update Formatter.php

Made changes in the coding style, added translation for 'days'.

Update FormatterTest.php

Made some changes in the expected array.

Update Formatter.php

Code style.

Made the last seen time more human readable by incorporating days in the time format.
parent 1de540f1
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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);
......
......@@ -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
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter