4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Intl\Tests\DateFormatter
;
14 use Symfony\Component\Intl\DateFormatter\IntlDateFormatter
;
15 use Symfony\Component\Intl\Globals\IntlGlobals
;
17 class IntlDateFormatterTest
extends AbstractIntlDateFormatterTest
19 public function testConstructor()
21 $formatter = new IntlDateFormatter('en', IntlDateFormatter
::MEDIUM
, IntlDateFormatter
::SHORT
, 'UTC', IntlDateFormatter
::GREGORIAN
, 'y-M-d');
22 $this->assertEquals('y-M-d', $formatter->getPattern());
26 * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
28 public function testConstructorWithUnsupportedLocale()
30 new IntlDateFormatter('pt_BR', IntlDateFormatter
::MEDIUM
, IntlDateFormatter
::SHORT
);
33 public function testStaticCreate()
35 $formatter = IntlDateFormatter
::create('en', IntlDateFormatter
::MEDIUM
, IntlDateFormatter
::SHORT
);
36 $this->assertInstanceOf('\Symfony\Component\Intl\DateFormatter\IntlDateFormatter', $formatter);
39 public function testFormatWithUnsupportedTimestampArgument()
41 $formatter = $this->getDefaultDateFormatter();
56 $formatter->format($localtime);
57 } catch (\Exception
$e) {
58 $this->assertInstanceOf('Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException', $e);
60 if (version_compare(PHP_VERSION
, '5.3.4', '>=')) {
61 $this->assertStringEndsWith('Only integer unix timestamps and DateTime objects are supported. Please install the "intl" extension for full localization capabilities.', $e->getMessage());
63 $this->assertStringEndsWith('Only integer unix timestamps are supported. Please install the "intl" extension for full localization capabilities.', $e->getMessage());
69 * @expectedException \Symfony\Component\Intl\Exception\NotImplementedException
71 public function testFormatWithUnimplementedChars()
74 $formatter = new IntlDateFormatter('en', IntlDateFormatter
::MEDIUM
, IntlDateFormatter
::SHORT
, 'UTC', IntlDateFormatter
::GREGORIAN
, $pattern);
75 $formatter->format(0);
79 * @expectedException \Symfony\Component\Intl\Exception\NotImplementedException
81 public function testFormatWithNonIntegerTimestamp()
83 $formatter = $this->getDefaultDateFormatter();
84 $formatter->format(array());
87 public function testGetErrorCode()
89 $formatter = $this->getDefaultDateFormatter();
90 $this->assertEquals(IntlGlobals
::getErrorCode(), $formatter->getErrorCode());
93 public function testGetErrorMessage()
95 $formatter = $this->getDefaultDateFormatter();
96 $this->assertEquals(IntlGlobals
::getErrorMessage(), $formatter->getErrorMessage());
99 public function testIsLenient()
101 $formatter = $this->getDefaultDateFormatter();
102 $this->assertFalse($formatter->isLenient());
106 * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
108 public function testLocaltime()
110 $formatter = $this->getDefaultDateFormatter();
111 $formatter->localtime('Wednesday, December 31, 1969 4:00:00 PM PT');
115 * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentNotImplementedException
117 public function testParseWithNotNullPositionValue()
120 $formatter = $this->getDefaultDateFormatter('y');
121 $this->assertSame(0, $formatter->parse('1970', $position));
125 * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
127 public function testSetCalendar()
129 $formatter = $this->getDefaultDateFormatter();
130 $formatter->setCalendar(IntlDateFormatter
::GREGORIAN
);
134 * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
136 public function testSetLenient()
138 $formatter = $this->getDefaultDateFormatter();
139 $formatter->setLenient(true);
143 * @expectedException \Symfony\Component\Intl\Exception\NotImplementedException
145 public function testFormatWithGmtTimeZoneAndMinutesOffset()
147 parent
::testFormatWithGmtTimeZoneAndMinutesOffset();
151 * @expectedException \Symfony\Component\Intl\Exception\NotImplementedException
153 public function testFormatWithNonStandardTimezone()
155 parent
::testFormatWithNonStandardTimezone();
158 public function parseStandaloneAmPmProvider()
160 return $this->notImplemented(parent
::parseStandaloneAmPmProvider());
163 public function parseDayOfWeekProvider()
165 return $this->notImplemented(parent
::parseDayOfWeekProvider());
168 public function parseDayOfYearProvider()
170 return $this->notImplemented(parent
::parseDayOfYearProvider());
173 public function parseQuarterProvider()
175 return $this->notImplemented(parent
::parseQuarterProvider());
178 protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter
::GREGORIAN
, $pattern = null)
180 return new IntlDateFormatter($locale, $datetype, $timetype, $timezone, $calendar, $pattern);
183 protected function getIntlErrorMessage()
185 return IntlGlobals
::getErrorMessage();
188 protected function getIntlErrorCode()
190 return IntlGlobals
::getErrorCode();
193 protected function isIntlFailure($errorCode)
195 return IntlGlobals
::isFailure($errorCode);
199 * Just to document the differences between the stub and the intl
200 * implementations. The intl can parse any of the tested formats alone. The
201 * stub does not implement them as it would be needed to add more
202 * abstraction, passing more context to the transformers objects. Any of the
203 * formats are ignored alone or with date/time data (years, months, days,
204 * hours, minutes and seconds).
206 * Also in intl, format like 'ss E' for '10 2' (2nd day of year
207 * + 10 seconds) are added, then we have 86,400 seconds (24h * 60min * 60s)
210 * @param array $dataSets
214 private function notImplemented(array $dataSets)
216 return array_map(function ($row) {
217 return array($row[0], $row[1], 0);