/**
  * Set the formatter's timezone identifier.
  *
  * @param string $timeZoneId The time zone ID string of the time zone to use.
  *                           If NULL or the empty string, the default time zone for the
  *                           runtime is used.
  *
  * @return bool true on success or false on failure
  *
  * @see http://www.php.net/manual/en/intldateformatter.settimezoneid.php
  */
 public function setTimeZoneId($timeZoneId)
 {
     if (null === $timeZoneId) {
         // In PHP 5.5 if $timeZoneId is null it fallbacks to `date_default_timezone_get()` method
         if (PHP_VERSION_ID >= 50500) {
             $timeZoneId = date_default_timezone_get();
         } else {
             // TODO: changes were made to ext/intl in PHP 5.4.4 release that need to be investigated since it will
             // use ini's date.timezone when the time zone is not provided. As a not well tested workaround, uses UTC.
             // See the first two items of the commit message for more information:
             // https://github.com/php/php-src/commit/eb346ef0f419b90739aadfb6cc7b7436c5b521d9
             $timeZoneId = getenv('TZ') ?: 'UTC';
         }
         $this->unitializedTimeZoneId = true;
     }
     // Backup original passed time zone
     $timeZone = $timeZoneId;
     // Get an Etc/GMT time zone that is accepted for \DateTimeZone
     if ('GMT' !== $timeZoneId && 0 === strpos($timeZoneId, 'GMT')) {
         try {
             $timeZoneId = DateFormat\TimeZoneTransformer::getEtcTimeZoneId($timeZoneId);
         } catch (\InvalidArgumentException $e) {
             // Does nothing, will fallback to UTC
         }
     }
     try {
         $this->dateTimeZone = new \DateTimeZone($timeZoneId);
     } catch (\Exception $e) {
         $this->dateTimeZone = new \DateTimeZone('UTC');
     }
     $this->timeZoneId = $timeZone;
     return true;
 }
Beispiel #2
0
 /**
  * Set the formatter's timezone identifier.
  *
  * @param string $timeZoneId The time zone ID string of the time zone to use.
  *                           If NULL or the empty string, the default time zone for the
  *                           runtime is used.
  *
  * @return bool true on success or false on failure
  *
  * @see http://www.php.net/manual/en/intldateformatter.settimezoneid.php
  */
 public function setTimeZoneId($timeZoneId)
 {
     if (null === $timeZoneId) {
         $timeZoneId = date_default_timezone_get();
         $this->uninitializedTimeZoneId = true;
     }
     // Backup original passed time zone
     $timeZone = $timeZoneId;
     // Get an Etc/GMT time zone that is accepted for \DateTimeZone
     if ('GMT' !== $timeZoneId && 0 === strpos($timeZoneId, 'GMT')) {
         try {
             $timeZoneId = DateFormat\TimeZoneTransformer::getEtcTimeZoneId($timeZoneId);
         } catch (\InvalidArgumentException $e) {
             // Does nothing, will fallback to UTC
         }
     }
     try {
         $this->dateTimeZone = new \DateTimeZone($timeZoneId);
     } catch (\Exception $e) {
         $this->dateTimeZone = new \DateTimeZone('UTC');
     }
     $this->timeZoneId = $timeZone;
     return true;
 }