diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-04-07 10:13:06 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-04-07 10:13:06 +0200 |
commit | 3bde7c2f67e1791bf9de5d4c10f2b1825b726536 (patch) | |
tree | 517b2bb400947dd4c877d844edfda7d962cef150 /lib/private/datetimezone.php | |
parent | e16d61e293b26be1ba3b1a7b803f20f00481bde8 (diff) | |
download | nextcloud-server-3bde7c2f67e1791bf9de5d4c10f2b1825b726536.tar.gz nextcloud-server-3bde7c2f67e1791bf9de5d4c10f2b1825b726536.zip |
When guessing the timezone, the offset might only be valid on a given timestamp
Diffstat (limited to 'lib/private/datetimezone.php')
-rw-r--r-- | lib/private/datetimezone.php | 16 |
1 files changed, 12 insertions, 4 deletions
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; } |