lib/private/DateTimeZone.php
/**
	 * Guess the DateTimeZone for a given offset
	 *
	 * We first try to find a Etc/GMT* timezone, if that does not exist,
	 * we try to find it manually, before falling back to UTC.
	 *
	 * @param mixed $offset
	 * @param bool|int $timestamp
	 * @return \DateTimeZone
	 */
Guess the DateTimeZone for a given offset
We first try to find a Etc/GMT* timezone, if that does not exist,
we try to find it manually, before falling back to UTC.

@param mixed $offset
@param bool|int $timestamp
@return \DateTimeZone
Guess the DateTimeZone for a given offset We first try to find a Etc / GMT * timezone if that does not exist we try to find it manually before falling back to UTC . @param mixed $offset @param bool|int $timestamp @return \ DateTimeZone
protected function guessTimeZoneFromOffset($offset, $timestamp) {
		try {
			if ($offset > 0) {
				$timeZone = 'Etc/GMT-' . $offset;
			} else {
				$timeZone = 'Etc/GMT+' . abs($offset);
			}
			return new \DateTimeZone($timeZone);
		} catch (\Exception $e) {
			foreach (\DateTimeZone::listIdentifiers() as $timeZone) {
				$dtz = new \DateTimeZone($timeZone);
				$dateTime = new \DateTime();
				if ($timestamp !== false) {
					$dateTime->setTimestamp($timestamp);
				}
				$dtOffset = $dtz->getOffset($dateTime);
				if ($dtOffset == 3600 * $offset) {
					return $dtz;
				}
			}
			\OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG);
			return new \DateTimeZone($this->getDefaultTimeZone());
		}
	}
protected function guessTimeZoneFromOffset ( $ offset , $ timestamp ) { try { if ( $ offset > 0 ) { $ timeZone = 'Etc/GMT-' . $ offset ; } else { $ timeZone = 'Etc/GMT+' . abs ( $ offset ) ; } return new \ DateTimeZone ( $ timeZone ) ; } catch ( \ Exception $ e ) { foreach ( \ DateTimeZone :: listIdentifiers ( ) as $ timeZone ) { $ dtz = new \ DateTimeZone ( $ timeZone ) ; $ dateTime = new \ DateTime ( ) ; if ( $ timestamp !== false ) { $ dateTime -> setTimestamp ( $ timestamp ) ; } $ dtOffset = $ dtz -> getOffset ( $ dateTime ) ; if ( $ dtOffset == 3600 * $ offset ) { return $ dtz ; } } \ OCP \ Util :: writeLog ( 'datetimezone' , 'Failed to find DateTimeZone for offset "' . $ offset . " ' " , \ OCP \ Util :: DEBUG ) ; return new \ DateTimeZone ( $ this -> getDefaultTimeZone ( ) ) ; } }
Guess the DateTimeZone for a given offset
 We first try to find a Etc/GMT* timezone, if that does not exist,
 we try to find it manually, before falling back to UTC.
Guess the DateTimeZone for a given offset We first try to find a Etc / GMT * timezone if that does not exist we try to find it manually before falling back to UTC .
// Note: the timeZone name is the inverse to the offset, // so a positive offset means negative timeZone // and the other way around. // If the offset has no Etc/GMT* timezone, // we try to guess one timezone that has the same offset // No timezone found, fallback to UTC