diff options
Diffstat (limited to 'lib/private/template')
-rw-r--r-- | lib/private/template/functions.php | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/lib/private/template/functions.php b/lib/private/template/functions.php index 4172d47ba61..288b7838ca2 100644 --- a/lib/private/template/functions.php +++ b/lib/private/template/functions.php @@ -205,36 +205,16 @@ function strip_time($timestamp){ * @param int $timestamp timestamp to format * @param int $fromTime timestamp to compare from, defaults to current time * @param bool $dateOnly whether to strip time information - * @return OC_L10N_String timestamp + * @return string timestamp */ function relative_modified_date($timestamp, $fromTime = null, $dateOnly = false) { - $l = \OC::$server->getL10N('lib'); - if (!isset($fromTime) || $fromTime === null){ - $fromTime = time(); - } + /** @var \OC\DateTimeFormatter $formatter */ + $formatter = \OC::$server->query('DateTimeFormatter'); + if ($dateOnly){ - $fromTime = strip_time($fromTime); - $timestamp = strip_time($timestamp); + return $formatter->formatDateSpan($timestamp, $fromTime); } - $timediff = $fromTime - $timestamp; - $diffminutes = round($timediff/60); - $diffhours = round($diffminutes/60); - $diffdays = round($diffhours/24); - $diffmonths = round($diffdays/31); - - if(!$dateOnly && $timediff < 60) { return $l->t('seconds ago'); } - else if(!$dateOnly && $timediff < 3600) { return $l->n('%n minute ago', '%n minutes ago', $diffminutes); } - else if(!$dateOnly && $timediff < 86400) { return $l->n('%n hour ago', '%n hours ago', $diffhours); } - else if((date('G', $fromTime)-$diffhours) >= 0) { return $l->t('today'); } - else if((date('G', $fromTime)-$diffhours) >= -24) { return $l->t('yesterday'); } - // 86400 * 31 days = 2678400 - else if($timediff < 2678400) { return $l->n('%n day go', '%n days ago', $diffdays); } - // 86400 * 60 days = 518400 - else if($timediff < 5184000) { return $l->t('last month'); } - else if((date('n', $fromTime)-$diffmonths) > 0) { return $l->n('%n month ago', '%n months ago', $diffmonths); } - // 86400 * 365.25 days * 2 = 63113852 - else if($timediff < 63113852) { return $l->t('last year'); } - else { return $l->t('years ago'); } + return $formatter->formatTimeSpan($timestamp, $fromTime); } function html_select_options($options, $selected, $params=array()) { |