8000 merged 2.0 · jeremymarc/symfony@df1050f · GitHub
[go: up one dir, main page]

Skip to content

Commit df1050f

Browse files
committed
merged 2.0
2 parents 8ebe624 + 997bcfc commit df1050f

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

src/Symfony/Bridge/Swiftmailer/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.3",
20-
"swiftmailer/swiftmailer": ">=4.1.2,<4.2-dev"
20+
"swiftmailer/swiftmailer": ">=4.1.2,<4.3-dev"
2121
},
2222
"suggest": {
2323
"symfony/http-kernel": "self.version"

src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,12 @@ public function setPattern($pattern)
458458
public function setTimeZoneId($timeZoneId)
459459
{
460460
if (null === $timeZoneId) {
461-
$timeZoneId = date_default_timezone_get();
461+
// TODO: changes were made to ext/intl in PHP 5.4.4 release that need to be investigated since it will
462+
// use ini's date.timezone when the time zone is not provided. As a not well tested workaround, uses UTC.
463+
// See the first two items of the commit message for more information:
464+
// https://github.com/php/php-src/commit/eb346ef0f419b90739aadfb6cc7b7436c5b521d9
465+
$timeZoneId = getenv('TZ') ?: 'UTC';
466+
462467
$this->unitializedTimeZoneId = true;
463468
}
464469

src/Symfony/Component/Locale/Tests/Stub/StubIntlDateFormatterTest.php

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,62 @@ public function testFormatWithDefaultTimezoneIntl()
461461
{
462462
$this->skipIfIntlExtensionIsNotLoaded();
463463
$this->skipIfICUVersionIsTooOld();
464+
465+
$formatter = new \IntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT);
466+
$formatter->setPattern('yyyy-MM-dd HH:mm:ss');
467+
468+
$this->assertEquals(
469+
$this->createDateTime(0)->format('Y-m-d H:i:s'),
470+
$formatter->format(0)
471+
);
472+
}
473+
474+
public function testFormatWithDefaultTimezoneStubShouldUseTheTzEnvironmentVariableWhenAvailable()
475+
{
476+
$tz = getenv('TZ');
477+
putenv('TZ=Europe/London');
478+
479+
$formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT);
480+
$formatter->setPattern('yyyy-MM-dd HH:mm:ss');
481+
482+
$this->assertEquals(
483+
$this->createDateTime(0)->format('Y-m-d H:i:s'),
484+
$formatter->format(0)
485+
);
486+
487+
$this->assertEquals('Europe/London', getenv('TZ'));
488+
489+
// Restores TZ.
490+
putenv('TZ='.$tz);
491+
}
492+
493+
/**
494+
* It seems IntlDateFormatter caches the timezone id when not explicitely set via constructor or by the
495+
* setTimeZoneId() method. Since testFormatWithDefaultTimezoneIntl() runs using the default environment
496+
* time zone, this test would use it too if not running in a separated process.
497+
*
498+
* @runInSeparateProcess
499+
*/
500+
public function testFormatWithDefaultTimezoneIntlShouldUseTheTzEnvironmentVariableWhenAvailable()
501+
{
502+
$this->skipIfIntlExtensionIsNotLoaded();
503+
$this->skipIfICUVersionIsTooOld();
504+
505+
$tz = getenv('TZ');
506+
putenv('TZ=Europe/Paris');
507+
464508
$formatter = new \IntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT);
465509
$formatter->setPattern('yyyy-MM-dd HH:mm:ss');
466510

511+
$this->assertEquals('Europe/Paris', getenv('TZ'));
512+
467513
$this->assertEquals(
468514
$this->createDateTime(0)->format('Y-m-d H:i:s'),
469515
$formatter->format(0)
470516
);
517+
518+
// Restores TZ.
519+
putenv('TZ='.$tz);
471520
}
472521

473522
/**
@@ -992,11 +1041,13 @@ protected function createIntlFormatter($pattern = null)
9921041
return new \IntlDateFormatter('en', \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern);
9931042
}
9941043

995-
protected function createDateTime($timestamp = null, $timeZone = null)
1044+
protected function createDateTime($timestamp = null)
9961045
{
1046+
$timeZone = getenv('TZ') ?: 'UTC';
1047+
9971048
$dateTime = new \DateTime();
9981049
$dateTime->setTimestamp(null === $timestamp ? time() : $timestamp);
999-
$dateTime->setTimeZone(new \DateTimeZone(null === $timeZone ? date_default_timezone_get() : $timeZone));
1050+
$dateTime->setTimeZone(new \DateTimeZone($timeZone));
10001051

10011052
return $dateTime;
10021053
}

0 commit comments

Comments
 (0)
0