Commit 8a49be8b 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>
(cherry picked from commit 9dd5c16d)
parent 5f39e8f0
......@@ -976,6 +976,8 @@ function useractivity_stats_table($limit, $offset, $extra, $institution, $urllin
}
$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) {
foreach ($aggregates['aggregations']['UsrId']['buckets'] as $item) {
$obj = new stdClass();
......@@ -994,14 +996,12 @@ function useractivity_stats_table($limit, $offset, $extra, $institution, $urllin
$obj->lastactivity = ($lastactivity) ? get_string($lastactivity, 'statistics') : '';
$obj->profileurl = profile_url($item['key']);
$date = $item['LastLogin']['value'] / 1000; // convert from UTC milliseconds
$timezone = new DateTimeZone(date_default_timezone_get()); // get timezone we are in
$offsettime = $timezone->getOffset(new DateTime("now")); // work out offset in seconds
if ($offset < 0) {
$date -= $offsettime;
}
if ($offset > 0) {
if ($offsettime < 0) {
$date += $offsettime;
}
if ($offsettime > 0) {
$date -= $offsettime;
}
$obj->lastlogin = $item['LastLogin']['value'] ? date('d F Y, H:i a', $date) : '';
$obj->actions = $item['doc_count'];
$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