summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-04-07 11:13:05 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-04-07 11:13:05 +0200
commit1f8e6e78ccfb053388f9f4790ccbe74ef557889c (patch)
tree2671f7139f4796a21296dfef9874c22033220580
parent95e55aa4adb690947ff73f2c703dac7010ed2cae (diff)
parent0fcd273714a4dd75e2fa8a59fea0fe38cd5aa934 (diff)
downloadnextcloud-server-1f8e6e78ccfb053388f9f4790ccbe74ef557889c.tar.gz
nextcloud-server-1f8e6e78ccfb053388f9f4790ccbe74ef557889c.zip
Merge pull request #15424 from owncloud/failing-master-tests
Fix failing tests related to timezones on master
-rw-r--r--apps/files/tests/controller/apicontrollertest.php6
-rw-r--r--lib/private/datetimezone.php16
-rw-r--r--lib/public/idatetimezone.php3
-rw-r--r--tests/lib/util.php19
4 files changed, 28 insertions, 16 deletions
diff --git a/apps/files/tests/controller/apicontrollertest.php b/apps/files/tests/controller/apicontrollertest.php
index 5d32a693ad3..bbab711310c 100644
--- a/apps/files/tests/controller/apicontrollertest.php
+++ b/apps/files/tests/controller/apicontrollertest.php
@@ -110,7 +110,7 @@ class ApiControllerTest extends TestCase {
[
'id' => null,
'parentId' => null,
- 'date' => 'January 1, 1970 at 12:00:55 AM GMT+0',
+ 'date' => \OCP\Util::formatDate(55),
'mtime' => 55000,
'icon' => \OCA\Files\Helper::determineIcon($fileInfo),
'name' => 'root.txt',
@@ -175,7 +175,7 @@ class ApiControllerTest extends TestCase {
[
'id' => null,
'parentId' => null,
- 'date' => 'January 1, 1970 at 12:00:55 AM GMT+0',
+ 'date' => \OCP\Util::formatDate(55),
'mtime' => 55000,
'icon' => \OCA\Files\Helper::determineIcon($fileInfo1),
'name' => 'root.txt',
@@ -194,7 +194,7 @@ class ApiControllerTest extends TestCase {
[
'id' => null,
'parentId' => null,
- 'date' => 'January 1, 1970 at 12:16:39 AM GMT+0',
+ 'date' => \OCP\Util::formatDate(999),
'mtime' => 999000,
'icon' => \OCA\Files\Helper::determineIcon($fileInfo2),
'name' => 'root.txt',
diff --git a/lib/private/datetimezone.php b/lib/private/datetimezone.php
index acc956e66f3..512c39be3ea 100644
--- a/lib/private/datetimezone.php
+++ b/lib/private/datetimezone.php
@@ -48,13 +48,14 @@ class DateTimeZone implements IDateTimeZone {
/**
* Get the timezone of the current user, based on his session information and config data
*
+ * @param bool|int $timestamp
* @return \DateTimeZone
*/
- public function getTimeZone() {
+ public function getTimeZone($timestamp = false) {
$timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null);
if ($timeZone === null) {
if ($this->session->exists('timezone')) {
- return $this->guessTimeZoneFromOffset($this->session->get('timezone'));
+ return $this->guessTimeZoneFromOffset($this->session->get('timezone'), $timestamp);
}
$timeZone = $this->getDefaultTimeZone();
}
@@ -74,9 +75,10 @@ class DateTimeZone implements IDateTimeZone {
* we try to find it manually, before falling back to UTC.
*
* @param mixed $offset
+ * @param bool|int $timestamp
* @return \DateTimeZone
*/
- protected function guessTimeZoneFromOffset($offset) {
+ protected function guessTimeZoneFromOffset($offset, $timestamp) {
try {
// Note: the timeZone name is the inverse to the offset,
// so a positive offset means negative timeZone
@@ -93,7 +95,13 @@ class DateTimeZone implements IDateTimeZone {
// we try to guess one timezone that has the same offset
foreach (\DateTimeZone::listIdentifiers() as $timeZone) {
$dtz = new \DateTimeZone($timeZone);
- $dtOffset = $dtz->getOffset(new \DateTime());
+ $dateTime = new \DateTime();
+
+ if ($timestamp !== false) {
+ $dateTime->setTimestamp($timestamp);
+ }
+
+ $dtOffset = $dtz->getOffset($dateTime);
if ($dtOffset == 3600 * $offset) {
return $dtz;
}
diff --git a/lib/public/idatetimezone.php b/lib/public/idatetimezone.php
index 30fbde15ac8..eb74074aa46 100644
--- a/lib/public/idatetimezone.php
+++ b/lib/public/idatetimezone.php
@@ -25,7 +25,8 @@ namespace OCP;
interface IDateTimeZone {
/**
+ * @param bool|int $timestamp
* @return \DateTimeZone
*/
- public function getTimeZone();
+ public function getTimeZone($timestamp = false);
}
diff --git a/tests/lib/util.php b/tests/lib/util.php
index 49399c8cf01..e52a9fcc618 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -54,24 +54,27 @@ class Test_Util extends \Test\TestCase {
public function formatDateWithTZFromSessionData() {
return array(
- array(3, 'October 13, 2012 at 2:53:25 PM GMT+3'),
- array(15, 'October 13, 2012 at 11:53:25 AM GMT+0'),
- array(-13, 'October 13, 2012 at 11:53:25 AM GMT+0'),
- array(9.5, 'October 13, 2012 at 9:23:25 PM GMT+9:30'),
- array(-4.5, 'October 13, 2012 at 7:23:25 AM GMT-4:30'),
- array(15.5, 'October 13, 2012 at 11:53:25 AM GMT+0'),
+ array(3, 'October 13, 2012 at 2:53:25 PM GMT+3', 'Etc/GMT-3'),
+ array(15, 'October 13, 2012 at 11:53:25 AM GMT+0', 'UTC'),
+ array(-13, 'October 13, 2012 at 11:53:25 AM GMT+0', 'UTC'),
+ array(9.5, 'October 13, 2012 at 9:23:25 PM GMT+9:30', 'Australia/Darwin'),
+ array(-4.5, 'October 13, 2012 at 7:23:25 AM GMT-4:30', 'America/Caracas'),
+ array(15.5, 'October 13, 2012 at 11:53:25 AM GMT+0', 'UTC'),
);
}
/**
* @dataProvider formatDateWithTZFromSessionData
*/
- function testFormatDateWithTZFromSession($offset, $expected) {
+ function testFormatDateWithTZFromSession($offset, $expected, $expectedTimeZone) {
date_default_timezone_set("UTC");
$oldDateTimeFormatter = \OC::$server->query('DateTimeFormatter');
\OC::$server->getSession()->set('timezone', $offset);
- $newDateTimeFormatter = new \OC\DateTimeFormatter(\OC::$server->getDateTimeZone()->getTimeZone(), new \OC_L10N('lib', 'en'));
+
+ $selectedTimeZone = \OC::$server->getDateTimeZone()->getTimeZone(1350129205);
+ $this->assertEquals($expectedTimeZone, $selectedTimeZone->getName());
+ $newDateTimeFormatter = new \OC\DateTimeFormatter($selectedTimeZone, new \OC_L10N('lib', 'en'));
$this->setDateFormatter($newDateTimeFormatter);
$result = OC_Util::formatDate(1350129205, false);