|
@@ -463,13 +463,62 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|
{
|
|
{
|
|
$this->skipIfIntlExtensionIsNotLoaded();
|
|
$this->skipIfIntlExtensionIsNotLoaded();
|
|
$this->skipIfICUVersionIsTooOld();
|
|
$this->skipIfICUVersionIsTooOld();
|
|
|
|
+
|
|
|
|
+ $formatter = new \IntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT);
|
|
|
|
+ $formatter->setPattern('yyyy-MM-dd HH:mm:ss');
|
|
|
|
+
|
|
|
|
+ $this->assertEquals(
|
|
|
|
+ $this->createDateTime(0)->format('Y-m-d H:i:s'),
|
|
|
|
+ $formatter->format(0)
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function testFormatWithDefaultTimezoneStubShouldUseTheTzEnvironmentVariableWhenAvailable()
|
|
|
|
+ {
|
|
|
|
+ $tz = getenv('TZ');
|
|
|
|
+ putenv('TZ=Europe/London');
|
|
|
|
+
|
|
|
|
+ $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT);
|
|
|
|
+ $formatter->setPattern('yyyy-MM-dd HH:mm:ss');
|
|
|
|
+
|
|
|
|
+ $this->assertEquals(
|
|
|
|
+ $this->createDateTime(0)->format('Y-m-d H:i:s'),
|
|
|
|
+ $formatter->format(0)
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ $this->assertEquals('Europe/London', getenv('TZ'));
|
|
|
|
+
|
|
|
|
+ // Restores TZ.
|
|
|
|
+ putenv('TZ='.$tz);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * It seems IntlDateFormatter caches the timezone id when not explicitely set via constructor or by the
|
|
|
|
+ * setTimeZoneId() method. Since testFormatWithDefaultTimezoneIntl() runs using the default environment
|
|
|
|
+ * time zone, this test would use it too if not running in a separated process.
|
|
|
|
+ *
|
|
|
|
+ * @runInSeparateProcess
|
|
|
|
+ */
|
|
|
|
+ public function testFormatWithDefaultTimezoneIntlShouldUseTheTzEnvironmentVariableWhenAvailable()
|
|
|
|
+ {
|
|
|
|
+ $this->skipIfIntlExtensionIsNotLoaded();
|
|
|
|
+ $this->skipIfICUVersionIsTooOld();
|
|
|
|
+
|
|
|
|
+ $tz = getenv('TZ');
|
|
|
|
+ putenv('TZ=Europe/Paris');
|
|
|
|
+
|
|
$formatter = new \IntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT);
|
|
$formatter = new \IntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT);
|
|
$formatter->setPattern('yyyy-MM-dd HH:mm:ss');
|
|
$formatter->setPattern('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
+ $this->assertEquals('Europe/Paris', getenv('TZ'));
|
|
|
|
+
|
|
$this->assertEquals(
|
|
$this->assertEquals(
|
|
$this->createDateTime(0)->format('Y-m-d H:i:s'),
|
|
$this->createDateTime(0)->format('Y-m-d H:i:s'),
|
|
$formatter->format(0)
|
|
$formatter->format(0)
|
|
);
|
|
);
|
|
|
|
+
|
|
|
|
+ // Restores TZ.
|
|
|
|
+ putenv('TZ='.$tz);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -994,11 +1043,13 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|
return new \IntlDateFormatter('en', \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern);
|
|
return new \IntlDateFormatter('en', \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern);
|
|
}
|
|
}
|
|
|
|
|
|
- protected function createDateTime($timestamp = null, $timeZone = null)
|
|
|
|
|
|
+ protected function createDateTime($timestamp = null)
|
|
{
|
|
{
|
|
|
|
+ $timeZone = getenv('TZ') ?: 'UTC';
|
|
|
|
+
|
|
$dateTime = new \DateTime();
|
|
$dateTime = new \DateTime();
|
|
$dateTime->setTimestamp(null === $timestamp ? time() : $timestamp);
|
|
$dateTime->setTimestamp(null === $timestamp ? time() : $timestamp);
|
|
- $dateTime->setTimeZone(new \DateTimeZone(null === $timeZone ? date_default_timezone_get() : $timeZone));
|
|
|
|
|
|
+ $dateTime->setTimeZone(new \DateTimeZone($timeZone));
|
|
|
|
|
|
return $dateTime;
|
|
return $dateTime;
|
|
}
|
|
}
|