Commit 311f1297 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge "Bug 1536439 Show timelapse for comments if they are less than 1 day old"

parents a56663b1 4241b640
......@@ -732,9 +732,11 @@ class ArtefactTypeComment extends ArtefactType {
foreach ($data->data as &$item) {
$item->ts = strtotime($item->ctime);
$item->date = format_date($item->ts, 'strftimedatetime');
$timelapse = format_timelapse($item->ts);
$item->date = ($timelapse) ? $timelapse : format_date($item->ts, 'strftimedatetime');
if ($item->ts < strtotime($item->lastcontentupdate)) {
$item->updated = format_date(strtotime($item->lastcontentupdate), 'strftimedatetime');
$timelapseupdated = format_timelapse(strtotime($item->lastcontentupdate));
$item->updated = ($timelapseupdated) ? $timelapseupdated : format_date(strtotime($item->lastcontentupdate), 'strftimedatetime');
}
$item->isauthor = $item->author && $item->author == $USER->get('id');
if (!empty($item->attachments)) {
......
......@@ -630,6 +630,23 @@ $string['datepicker_timezoneText'] = 'Timezone';
$string['datepicker_amNames'] = "['AM', 'A']";
$string['datepicker_pmNames'] = "['PM', 'P']";
$string['timelapsestringhour'] = array(
0 => '%2$s hour %s min ago',
1 => '%2$s hour %s mins ago'
);
$string['timelapsestringhours'] = array(
0 => '%2$s hours %s min ago',
1 => '%2$s hours %s mins ago'
);
$string['timelapsestringminute'] = array(
0 => '%s min ago',
1 => '%s mins ago'
);
$string['timelapsestringseconds'] = array(
0 => '%s sec ago',
1 => '%s secs ago',
);
// Site content pages
$string['sitecontentnotfound'] = '%s text not available';
......
......@@ -2142,6 +2142,52 @@ function format_date($date, $formatkey='strftimedatetime', $notspecifiedkey='str
return strftime(get_string($formatkey), $date);
}
/**
* Formats the difference of two unix timestamps as time lapsed.
*
* @param int $timestamp1 Older unix timestamp to compare
* @param int $timestamp2 Newer unix timestamp or current time if not supplied
*
* @return formatted time difference or false
*/
function format_timelapse($timestamp1, $timestamp2 = NULL) {
if (!is_numeric($timestamp2)) {
$timestamp2 = time();
}
$datetime1 = date_create_from_format('U', $timestamp2);
$datetime2 = date_create_from_format('U', $timestamp1); // a timestamp to test against first timestamp
$interval = date_diff($datetime1, $datetime2);
if ($interval->invert == 0 && $interval->s != 0) {
// We are in the future so exit
return false;
}
else if ($interval->invert == 0) {
// We are at exact current time - this can happen when adding something
// so we will make it 1 sec in the past for display purposes
$interval->s = 1;
}
if ($interval->days < 1) {
if ($interval->h != 0) {
if ($interval->h < 2) {
return get_string('timelapsestringhour', 'mahara', $interval->i, $interval->h, $interval->i);
}
else {
return get_string('timelapsestringhours', 'mahara', $interval->i, $interval->h, $interval->i);
}
}
else if ($interval->i != 0) {
return get_string('timelapsestringminute', 'mahara', $interval->i, $interval->i);
}
else {
return get_string('timelapsestringseconds', 'mahara', $interval->s, $interval->s);
}
}
return false;
}
/**
* Returns a random string suitable for registration/change password requests
*
......
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