From 6f775e056c9f20769d4a44f1354d85aa0222a370 Mon Sep 17 00:00:00 2001
From: Ritvik Gautam <ritvik1392@gmail.com>
Date: Wed, 28 Oct 2015 16:41:54 +0530
Subject: [PATCH] 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.
---
 core/Metrics/Formatter.php                   | 11 ++++++++---
 tests/PHPUnit/Unit/Metrics/FormatterTest.php | 10 +++++-----
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/core/Metrics/Formatter.php b/core/Metrics/Formatter.php
index 077646ba00..d62db65f31 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 0bcef84c5f..d9ccc18c6d 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
+}
-- 
GitLab