[Pkg-owncloud-commits] [owncloud] 08/18: When guessing the timezone, the offset might only be valid on a given timestamp

David Prévot taffit at moszumanska.debian.org
Thu Apr 16 02:06:13 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit dfd302178a654aaafa23d137214b8533427b2b42
Author: Joas Schilling <nickvergessen at owncloud.com>
Date:   Tue Apr 7 10:13:06 2015 +0200

    When guessing the timezone, the offset might only be valid on a given timestamp
---
 lib/private/datetimezone.php | 16 ++++++++++++----
 lib/public/idatetimezone.php |  3 ++-
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/lib/private/datetimezone.php b/lib/private/datetimezone.php
index 727ce32..fcf1883 100644
--- a/lib/private/datetimezone.php
+++ b/lib/private/datetimezone.php
@@ -38,13 +38,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();
 		}
@@ -64,9 +65,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
@@ -83,7 +85,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 fb4c895..24dc70a 100644
--- a/lib/public/idatetimezone.php
+++ b/lib/public/idatetimezone.php
@@ -15,7 +15,8 @@ namespace OCP;
 
 interface IDateTimeZone {
 	/**
+	 * @param bool|int $timestamp
 	 * @return \DateTimeZone
 	 */
-	public function getTimeZone();
+	public function getTimeZone($timestamp = false);
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list