* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Intl\DateFormatter\DateFormat; use Symfony\Component\Intl\Exception\NotImplementedException; /** * Parser and formatter for time zone format. * * @author Igor Wiedler * * @internal */ class TimezoneTransformer extends Transformer { /** * {@inheritdoc} * * @throws NotImplementedException When time zone is different than UTC or GMT (Etc/GMT) */ public function format(\DateTime $dateTime, $length) { $timeZone = substr($dateTime->getTimezone()->getName(), 0, 3); if (!in_array($timeZone, array('Etc', 'UTC', 'GMT'))) { throw new NotImplementedException('Time zone different than GMT or UTC is not supported as a formatting output.'); } if ('Etc' === $timeZone) { // i.e. Etc/GMT+1, Etc/UTC, Etc/Zulu $timeZone = substr($dateTime->getTimezone()->getName(), 4); } // From ICU >= 59.1 GMT and UTC are no longer unified if (in_array($timeZone, array('UTC', 'UCT', 'Universal', 'Zulu'))) { // offset is not supported with UTC return $length > 3 ? 'Coordinated Universal Time' : 'UTC'; } $offset = (int) $dateTime->format('O'); // From ICU >= 4.8, the zero offset is no more used, example: GMT instead of GMT+00:00 if (0 === $offset) { return $length > 3 ? 'Greenwich Mean Time' : 'GMT'; } if ($length > 3) { return $dateTime->format('\G\M\TP'); } return sprintf('GMT%s%d', ($offset >= 0 ? '+' : ''), $offset / 100); } /** * {@inheritdoc} */ public function getReverseMatchingRegExp($length) { return 'GMT[+-]\d{2}:?\d{2}'; } /** * {@inheritdoc} */ public function extractDateOptions($matched, $length) { return array( 'timezone' => self::getEtcTimeZoneId($matched), ); } /** * Get an Etc/GMT timezone identifier for the specified timezone. * * The PHP documentation for timezones states to not use the 'Other' time zones because them exists * "for backwards compatibility". However all Etc/GMT time zones are in the tz database 'etcetera' file, * which indicates they are not deprecated (neither are old names). * * Only GMT, Etc/Universal, Etc/Zulu, Etc/Greenwich, Etc/GMT-0, Etc/GMT+0 and Etc/GMT0 are old names and * are linked to Etc/GMT or Etc/UTC. * * @param string $formattedTimeZone A GMT timezone string (GMT-03:00, e.g.) * * @return string A timezone identifier * * @see http://php.net/manual/en/timezones.others.php * @see http://www.twinsun.com/tz/tz-link.htm * * @throws NotImplementedException When the GMT time zone have minutes offset different than zero * @throws \InvalidArgumentException When the value can not be matched with pattern */ public static function getEtcTimeZoneId($formattedTimeZone) { if (preg_match('/GMT(?P[+-])(?P\d{2}):?(?P\d{2})/', $formattedTimeZone, $matches)) { $hours = (int) $matches['hours']; $minutes = (int) $matches['minutes']; $signal = '-' == $matches['signal'] ? '+' : '-'; if (0 < $minutes) { throw new NotImplementedException(sprintf( 'It is not possible to use a GMT time zone with minutes offset different than zero (0). GMT time zone tried: %s.', $formattedTimeZone )); } return 'Etc/GMT'.(0 !== $hours ? $signal.$hours : ''); } throw new \InvalidArgumentException(sprintf('The GMT time zone "%s" does not match with the supported formats GMT[+-]HH:MM or GMT[+-]HHMM.', $formattedTimeZone)); } } __halt_compiler();----SIGNATURE:----OvN4krlqlFwQBlobi3qxqFXwGvbmyx+fpJnp7Az8bcxthDAcn0ozVzlQ8hFdml8WSWCRHPrv8dWuXDtks5nEu4l2jfbeSm0Ik6BsseqlJxJism+K1Q7ia5xE13mbdv96Kd6oWZvh/ODiXqR0u32nR+MdGb9X5Qofuw9krbf/wl1ujvOBPn4H3cxB2zoOEfsxXu+XplrpWNuIJ9unAjUX9qJP3vAcXzUf+bcf8jHEZZewyy4vQzqiCm7x5Zkay/tSUaLr3rzy7v5xh97WH7M25Iz7oJaYr1qjRbu49CKs/UFRcYAhCgi10i2syuYPqQFP/fMGo2mEWnGa3GgggDpfBBJ92ikNF6O8+JYaIsHoBdKhBm8nkXPHga3eCXj8n9uUvCNjOr+v3VBjpRZ+eO9ne4qzfAQzuz3rC0eFzJuszx8Zz4b95HHkE/W8tAlq7M9Y4hRhDNXagbusaoq98RQD2CA3L23v8HX4KGIqVYfsZN3P8bhThWk4eIApryNo/Ni6LaW1gM27XLMNW6owEuDe5mlAAW9CGmETPAMyuGh13Vqtl17kWN2aoYcMHqPOGUDY0mlVIMtDELbS9Q+7el8u2z5XOAjoixlvTZ/Kqx7q2rhmej/S1o8HMm1bjs1l2EpnJ9PIIv1INF9hbM+LU33CQKHMM2fvGX7BafQ5jac1tv0=----ATTACHMENT:----Mzk3OTU4NjMwMTkwMDQxOCA5MzY5NzY3OTQzODc0ODI1IDExMDc3ODQ3MzY4Nzk3MzE=