From 0197ca79fd7b481e471c88f244bcfabf10d0d8da Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Sun, 9 Oct 2016 05:54:32 +0200 Subject: [PATCH] use the date command for the other dates as well trim against leading space from %k (range of ' 0' to '23') and strtolower for AM/PM that %p outputs as uppercase, while 'a' (-> am/pm) was used before --- data.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/data.php b/data.php index bceff3d7..2515f7b8 100644 --- a/data.php +++ b/data.php @@ -2,7 +2,6 @@ $log = array(); $ipv6 = parse_ini_file("/etc/pihole/setupVars.conf")['piholeIPv6'] != ""; $hosts = file_exists("/etc/hosts") ? file("/etc/hosts") : array(); - date_default_timezone_set('UTC'); /******* Public Members ********/ function getSummaryData() { @@ -126,7 +125,7 @@ $hostname = trim(file_get_contents("/etc/hostname"), "\x00..\x1F"); foreach ($dns_queries as $query) { - $time = date_create(substr($query, 0, 16)); + $time = exec("date --date='" . trim(substr($query, 0, 16)) . "' +'%Y-%m-%d\%Z%H:%M:%S'"); $exploded = explode(" ", trim($query)); $tmp = $exploded[count($exploded)-4]; $status = ""; @@ -146,7 +145,7 @@ if ( $status != ""){ array_push($allQueries['data'], array( - $time->format('Y-m-d\TH:i:s'), + $time, $type, $domain, hasHostName($client), @@ -213,8 +212,7 @@ function overTime($entries) { $byTime = array(); foreach ($entries as $entry) { - $time = date_create(substr($entry, 0, 16)); - $hour = $time->format('G'); + $hour = trim(exec("date --date='" . trim(substr($entry, 0, 16)) . "' +'%k'")); if (isset($byTime[$hour])) { $byTime[$hour]++; @@ -248,8 +246,7 @@ foreach (array_slice($queries, -$qty) as $query) { $queryArray = array(); $exploded = explode(" ", $query); - $time = date_create(substr($query, 0, 16)); - $queryArray['time'] = $time->format('h:i:s a'); + $queryArray['time'] = strtolower(exec("date --date='" . trim(substr($query, 0, 16)) . "' +'%I:%M:%S %p'")); $queryArray['domain'] = trim($exploded[count($exploded) - 3]); $queryArray['ip'] = trim($exploded[count($exploded)-1]); array_push($recent, $queryArray);