/** * Constructor. * * @param string|DateTimeZone|PHPDateTimeZone|null $timezone [optional] The timezone as a string, or as * DateTimeZone or PHPDateTimeZone instance. Null to use the default timezone. * * @throws Exception Throws an exception on failure. */ public function __construct($timezone) { // Parse null if ($timezone === null) { $timezone = DateTimeZoneUtils::getDefaultTimezone(); } else { if ($timezone instanceof DateTime) { $timezone = $timezone->getTimezone(); } else { if ($timezone instanceof PHPDateTime) { $timezone = $timezone->getTimezone(); } } } // Parse DateTimeZone and PHPDateTimeZone instances if ($timezone instanceof parent) { parent::__construct($timezone->getName()); return $this; } // Check if this is a valid timezone ID if (DateTimeZoneUtils::isValidTimezoneId($timezone)) { parent::__construct($timezone); return $this; } // Invalid timezone, throw an exception throw new Exception('Invalid timezone (\'' . $timezone . '\' was given)'); }
/** * Initializes the {@link $name} property. * * @param string $timezone */ public function __construct($timezone) { parent::__construct($timezone); $name = $this->getName(); if ($name == 'utc') { $name = 'UTC'; } $this->name = $name; }
/** * CONSTRUCTOR * Build a new DateTimeZone object. * Store user timezone identifier in session. * * @since 0.0.1 * * @see getTimeZone() * * @access public * @param string|null $timezone Optional. Timezone identifier to use. Default: null * @return void */ public function __construct($timezone = null) { if (null === $timezone) { $timezone = self::getTimeZone(); } // Store timezone in session $_SESSION['timezone'] = $timezone; parent::__construct($timezone); }
public function __construct($in_dtz = null) { $this->tz_defined = false; if (!isset($in_dtz)) { return; } $olson = olson_from_tzstring($in_dtz); if (isset($olson)) { try { parent::__construct($olson); $this->tz_defined = $olson; } catch (Exception $e) { dbg_error_log('ERROR', 'Could not handle timezone "%s" (%s) - will use floating time', $in_dtz, $olson); parent::__construct('UTC'); $this->tz_defined = false; } } else { dbg_error_log('ERROR', 'Could not recognize timezone "%s" - will use floating time', $in_dtz); parent::__construct('UTC'); $this->tz_defined = false; } }