From b8aa1dd2330e40ecdde94be1da1cae01cb5144e9 Mon Sep 17 00:00:00 2001 From: Daniel Thee Roperto Date: Wed, 14 Dec 2016 12:29:27 +1100 Subject: [PATCH] Issue #86 - Added relative time on manage outage tables. --- classes/output/manage/base_table.php | 8 ++++++++ classes/output/manage/history_table.php | 4 ++-- classes/output/manage/planned_table.php | 2 +- lang/en/auth_outage.php | 3 +++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/classes/output/manage/base_table.php b/classes/output/manage/base_table.php index b2dee58..a5387d5 100644 --- a/classes/output/manage/base_table.php +++ b/classes/output/manage/base_table.php @@ -48,6 +48,14 @@ class base_table extends flexible_table { */ private static $autoid = 0; + protected static function create_starttime_string($starttime) { + $absolute = userdate($starttime, get_string('datetimeformat', 'auth_outage')); + $relative = $starttime - time(); + $format = ($relative < 0) ? 'tablestarttimepastformat' : 'tablestarttimefutureformat'; + $relative = format_time($relative); + return get_string($format, 'auth_outage', compact('absolute', 'relative')); + } + /** * Constructor * @param string|null $id to be used by the table, autogenerated if null. diff --git a/classes/output/manage/history_table.php b/classes/output/manage/history_table.php index 412139a..720a7f0 100644 --- a/classes/output/manage/history_table.php +++ b/classes/output/manage/history_table.php @@ -50,7 +50,7 @@ class history_table extends base_table { $this->define_headers([ get_string('tableheaderwarnbefore', 'auth_outage'), - get_string('tableheaderstarttime', 'auth_outage'), + get_string('tableheaderstartedtime', 'auth_outage'), get_string('tableheaderdurationplanned', 'auth_outage'), get_string('tableheaderdurationactual', 'auth_outage'), get_string('tableheadertitle', 'auth_outage'), @@ -71,7 +71,7 @@ class history_table extends base_table { $finished = is_null($finished) ? '-' : format_time($finished); $this->add_data([ format_time($outage->get_warning_duration()), - userdate($outage->starttime, get_string('datetimeformat', 'auth_outage')), + self::create_starttime_string($outage->starttime), format_time($outage->get_duration_planned()), $finished, $outage->get_title(), diff --git a/classes/output/manage/planned_table.php b/classes/output/manage/planned_table.php index 8275b07..a183147 100644 --- a/classes/output/manage/planned_table.php +++ b/classes/output/manage/planned_table.php @@ -75,7 +75,7 @@ class planned_table extends base_table { $this->add_data([ format_time($outage->get_warning_duration()), - userdate($outage->starttime, get_string('datetimeformat', 'auth_outage')), + self::create_starttime_string($outage->starttime), format_time($outage->get_duration_planned()), $title, $this->create_data_buttons($outage, true), diff --git a/lang/en/auth_outage.php b/lang/en/auth_outage.php index bf6f256..b6ca9da 100644 --- a/lang/en/auth_outage.php +++ b/lang/en/auth_outage.php @@ -128,8 +128,11 @@ $string['tableheaderduration'] = 'Duration'; $string['tableheaderdurationplanned'] = 'Planned duration'; $string['tableheaderdurationactual'] = 'Actual duration'; $string['tableheaderstarttime'] = 'Starts on'; +$string['tableheaderstartedtime'] = 'Started on'; $string['tableheaderwarnbefore'] = 'Warns before'; $string['tableheadertitle'] = 'Title'; +$string['tablestarttimefutureformat'] = '{$a->absolute}
In {$a->relative}'; +$string['tablestarttimepastformat'] = '{$a->absolute}
{$a->relative} ago'; $string['taskupdatestaticpage'] = 'Update static outage page'; $string['textplaceholdershint'] = 'You can use {{start}}, {{stop}} and {{duration}} as placeholders on the title and description.'; $string['titleerrorinvalid'] = 'Title cannot be left blank.';