diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-11-24 16:37:04 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-12-10 11:58:56 +0100 |
commit | 4d232e536eb03895863c0d7d7fe703c41d433f70 (patch) | |
tree | 2adb86d986c986f4c34fac9fedb287f9a51191d5 /lib/private/template | |
parent | 681caf882a5f28b0b6f7cb9a1f16b3dea26ff5f2 (diff) | |
download | nextcloud-server-4d232e536eb03895863c0d7d7fe703c41d433f70.tar.gz nextcloud-server-4d232e536eb03895863c0d7d7fe703c41d433f70.zip |
Deprecate Util::formatDate()
Make DateTimeFormatter a service and adjust tests that have been inaccurate
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()) { |