Skip to content

Commit

Permalink
Use setTimeZone if this method exists.
Browse files Browse the repository at this point in the history
The php version is not a critical factor to choose the method, but we have to use setTimeZone, if it exists.
  • Loading branch information
dropfen authored and fabpot committed Sep 13, 2013
1 parent 7d7b583 commit 0d6af5c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/DateType.php
Expand Up @@ -267,8 +267,10 @@ private function formatTimestamps(\IntlDateFormatter $formatter, $regex, array $
{
$pattern = $formatter->getPattern();
$timezone = $formatter->getTimezoneId();
// Use it, if exists.
$setTimeZone = method_exists($formatter, 'setTimeZone');

if (version_compare(\PHP_VERSION, '5.5.0-dev', '>=')) {
if ($setTimeZone) {
$formatter->setTimeZone('UTC');
} else {
$formatter->setTimeZoneId('UTC');
Expand All @@ -286,7 +288,7 @@ private function formatTimestamps(\IntlDateFormatter $formatter, $regex, array $
$formatter->setPattern($pattern);
}

if (version_compare(\PHP_VERSION, '5.5.0-dev', '>=')) {
if ($setTimeZone) {
$formatter->setTimeZone($timezone);
} else {
$formatter->setTimeZoneId($timezone);
Expand Down

0 comments on commit 0d6af5c

Please sign in to comment.