|
|
@@ -35,9 +35,9 @@ class TimeTest extends TestCase
|
|
|
parent::setUp();
|
|
|
$this->now = Time::getTestNow();
|
|
|
$this->frozenNow = FrozenTime::getTestNow();
|
|
|
- $this->locale = Time::$defaultLocale;
|
|
|
- Time::$defaultLocale = 'en_US';
|
|
|
- FrozenTime::$defaultLocale = 'en_US';
|
|
|
+ $this->locale = Time::getDefaultLocale();
|
|
|
+ Time::setDefaultLocale('en_US');
|
|
|
+ FrozenTime::setDefaultLocale('en_US');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -49,11 +49,11 @@ class TimeTest extends TestCase
|
|
|
{
|
|
|
parent::tearDown();
|
|
|
Time::setTestNow($this->now);
|
|
|
- Time::$defaultLocale = $this->locale;
|
|
|
+ Time::setDefaultLocale($this->locale);
|
|
|
Time::resetToStringFormat();
|
|
|
|
|
|
FrozenTime::setTestNow($this->frozenNow);
|
|
|
- FrozenTime::$defaultLocale = $this->locale;
|
|
|
+ FrozenTime::setDefaultLocale($this->locale);
|
|
|
FrozenTime::resetToStringFormat();
|
|
|
date_default_timezone_set('UTC');
|
|
|
I18n::locale(I18n::DEFAULT_LOCALE);
|
|
|
@@ -447,7 +447,7 @@ class TimeTest extends TestCase
|
|
|
$expected = '00:59:28';
|
|
|
$this->assertTimeFormat($expected, $result);
|
|
|
|
|
|
- $class::$defaultLocale = 'fr-FR';
|
|
|
+ $class::setDefaultLocale('fr-FR');
|
|
|
$result = $time->i18nFormat(\IntlDateFormatter::FULL);
|
|
|
$expected = 'jeudi 14 janvier 2010 13:59:28 UTC';
|
|
|
$this->assertTimeFormat($expected, $result);
|
|
|
@@ -562,7 +562,7 @@ class TimeTest extends TestCase
|
|
|
public function testToString($class)
|
|
|
{
|
|
|
$time = new $class('2014-04-20 22:10');
|
|
|
- $class::$defaultLocale = 'fr-FR';
|
|
|
+ $class::setDefaultLocale('fr-FR');
|
|
|
$class::setToStringFormat(\IntlDateFormatter::FULL);
|
|
|
$this->assertTimeFormat('dimanche 20 avril 2014 22:10:00 UTC', (string)$time);
|
|
|
}
|
|
|
@@ -754,7 +754,7 @@ class TimeTest extends TestCase
|
|
|
$this->assertNotNull($time);
|
|
|
$this->assertEquals('2013-10-13 00:54', $time->format('Y-m-d H:i'));
|
|
|
|
|
|
- $class::$defaultLocale = 'fr-FR';
|
|
|
+ $class::setDefaultLocale('fr-FR');
|
|
|
$time = $class::parseDateTime('13 10, 2013 12:54');
|
|
|
$this->assertNotNull($time);
|
|
|
$this->assertEquals('2013-10-13 12:54', $time->format('Y-m-d H:i'));
|
|
|
@@ -779,7 +779,7 @@ class TimeTest extends TestCase
|
|
|
$this->assertNotNull($time);
|
|
|
$this->assertEquals('2013-10-13 00:00', $time->format('Y-m-d H:i'));
|
|
|
|
|
|
- $class::$defaultLocale = 'fr-FR';
|
|
|
+ $class::setDefaultLocale('fr-FR');
|
|
|
$time = $class::parseDate('13 10, 2013 12:54');
|
|
|
$this->assertNotNull($time);
|
|
|
$this->assertEquals('2013-10-13 00:00', $time->format('Y-m-d H:i'));
|
|
|
@@ -804,7 +804,7 @@ class TimeTest extends TestCase
|
|
|
$this->assertNotNull($time);
|
|
|
$this->assertEquals('00:54:00', $time->format('H:i:s'));
|
|
|
|
|
|
- $class::$defaultLocale = 'fr-FR';
|
|
|
+ $class::setDefaultLocale('fr-FR');
|
|
|
$time = $class::parseTime('23:54');
|
|
|
$this->assertNotNull($time);
|
|
|
$this->assertEquals('23:54:00', $time->format('H:i:s'));
|
|
|
@@ -836,13 +836,46 @@ class TimeTest extends TestCase
|
|
|
public function testParseDateDifferentTimezone($class)
|
|
|
{
|
|
|
date_default_timezone_set('Europe/Paris');
|
|
|
- $class::$defaultLocale = 'fr-FR';
|
|
|
+ $class::setDefaultLocale('fr-FR');
|
|
|
$result = $class::parseDate('12/03/2015');
|
|
|
$this->assertEquals('2015-03-12', $result->format('Y-m-d'));
|
|
|
$this->assertEquals(new \DateTimeZone('Europe/Paris'), $result->tz);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Tests the default locale setter.
|
|
|
+ *
|
|
|
+ * @dataProvider classNameProvider
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testGetSetDefaultLocale($class)
|
|
|
+ {
|
|
|
+ $class::setDefaultLocale('fr-FR');
|
|
|
+ $this->assertSame('fr-FR', $class::getDefaultLocale());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Tests the default locale setter.
|
|
|
+ *
|
|
|
+ * @dataProvider classNameProvider
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testDefaultLocaleEffectsFormatting($class)
|
|
|
+ {
|
|
|
+ $result = $class::parseDate('12/03/2015');
|
|
|
+ $this->assertRegExp('/Dec 3, 2015[ ,]+12:00 AM/', $result->nice());
|
|
|
+
|
|
|
+ $class::setDefaultLocale('fr-FR');
|
|
|
+
|
|
|
+ $result = $class::parseDate('12/03/2015');
|
|
|
+ $this->assertRegexp('/12 mars 2015 (?:à )?00:00/', $result->nice());
|
|
|
+
|
|
|
+ $expected = 'Y-m-d';
|
|
|
+ $result = $class::parseDate('12/03/2015');
|
|
|
+ $this->assertEquals('2015-03-12', $result->format($expected));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Custom assert to allow for variation in the version of the intl library, where
|
|
|
* some translations contain a few extra commas.
|
|
|
*
|