Commit 9dd5c16d authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1723784: Fixing 'Last login' date to display in correct timezone



As elasticsearch records dates in UTC milliseconds

behatnotneeded

Change-Id: I98f1a92c2cccd795e5009cf334530aa0eecc28ba
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent cdc8966f
...@@ -976,6 +976,8 @@ function useractivity_stats_table($limit, $offset, $extra, $institution, $urllin ...@@ -976,6 +976,8 @@ function useractivity_stats_table($limit, $offset, $extra, $institution, $urllin
} }
$data = array(); $data = array();
$timezone = new DateTimeZone(date_default_timezone_get()); // get timezone we are in
$offsettime = $timezone->getOffset(new DateTime("now")); // work out offset in seconds
if ($aggregates['totalresults'] > 0) { if ($aggregates['totalresults'] > 0) {
foreach ($aggregates['aggregations']['UsrId']['buckets'] as $item) { foreach ($aggregates['aggregations']['UsrId']['buckets'] as $item) {
$obj = new stdClass(); $obj = new stdClass();
...@@ -994,14 +996,12 @@ function useractivity_stats_table($limit, $offset, $extra, $institution, $urllin ...@@ -994,14 +996,12 @@ function useractivity_stats_table($limit, $offset, $extra, $institution, $urllin
$obj->lastactivity = ($lastactivity) ? get_string($lastactivity, 'statistics') : ''; $obj->lastactivity = ($lastactivity) ? get_string($lastactivity, 'statistics') : '';
$obj->profileurl = profile_url($item['key']); $obj->profileurl = profile_url($item['key']);
$date = $item['LastLogin']['value'] / 1000; // convert from UTC milliseconds $date = $item['LastLogin']['value'] / 1000; // convert from UTC milliseconds
$timezone = new DateTimeZone(date_default_timezone_get()); // get timezone we are in if ($offsettime < 0) {
$offsettime = $timezone->getOffset(new DateTime("now")); // work out offset in seconds
if ($offset < 0) {
$date -= $offsettime;
}
if ($offset > 0) {
$date += $offsettime; $date += $offsettime;
} }
if ($offsettime > 0) {
$date -= $offsettime;
}
$obj->lastlogin = $item['LastLogin']['value'] ? date('d F Y, H:i a', $date) : ''; $obj->lastlogin = $item['LastLogin']['value'] ? date('d F Y, H:i a', $date) : '';
$obj->actions = $item['doc_count']; $obj->actions = $item['doc_count'];
$data[] = $obj; $data[] = $obj;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment