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/util.php | |
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/util.php')
-rw-r--r-- | lib/private/util.php | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/lib/private/util.php b/lib/private/util.php index d28fa80160c..6ccb9dba087 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -435,27 +435,20 @@ class OC_Util { * @param bool $dateOnly option to omit time from the result * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to * @return string timestamp - * @description adjust to clients timezone if we know it + * + * @deprecated Use \OC::$server->query('DateTimeFormatter') instead */ public static function formatDate($timestamp, $dateOnly = false, $timeZone = null) { - if (is_null($timeZone)) { - if (\OC::$server->getSession()->exists('timezone')) { - $systemTimeZone = intval(date('O')); - $systemTimeZone = (round($systemTimeZone / 100, 0) * 60) + ($systemTimeZone % 100); - $clientTimeZone = \OC::$server->getSession()->get('timezone') * 60; - $offset = $clientTimeZone - $systemTimeZone; - $timestamp = $timestamp + $offset * 60; - } - } else { - if (!$timeZone instanceof DateTimeZone) { - $timeZone = new DateTimeZone($timeZone); - } - $dt = new DateTime("@$timestamp"); - $offset = $timeZone->getOffset($dt); - $timestamp += $offset; + if ($timeZone !== null && !$timeZone instanceof \DateTimeZone) { + $timeZone = new \DateTimeZone($timeZone); } - $l = \OC::$server->getL10N('lib'); - return $l->l($dateOnly ? 'date' : 'datetime', $timestamp); + + /** @var \OC\DateTimeFormatter $formatter */ + $formatter = \OC::$server->query('DateTimeFormatter'); + if ($dateOnly) { + return $formatter->formatDate($timestamp, 'long', $timeZone); + } + return $formatter->formatDateTime($timestamp, 'long', 'long', $timeZone); } /** |