Commit 2e60f969 authored by Markus Kalkbrenner's avatar Markus Kalkbrenner

Merge branch 'develop' of https://github.com/bpolaszek/solarium into bpolaszek-develop

parents d3b40c8b 18b69852
......@@ -139,7 +139,7 @@ class Helper
*
* @see http://lucene.apache.org/solr/api/org/apache/solr/schema/DateField.html
*
* @param int|string|\DateTime $input accepted formats: timestamp, date string or DateTime
* @param int|string|\DateTimeInterface $input accepted formats: timestamp, date string or DateTime / DateTimeImmutable
*
* @return string|boolean false is returned in case of invalid input
*/
......@@ -148,7 +148,7 @@ class Helper
switch (true) {
// input of datetime object
case $input instanceof \DateTime:
case $input instanceof \DateTimeInterface:
// no work needed
break;
......@@ -180,7 +180,7 @@ class Helper
// handle the filtered input
if ($input) {
// when we get here the input is always a datetime object
$input->setTimezone(new \DateTimeZone('UTC'));
$input = $input->setTimezone(new \DateTimeZone('UTC'));
$iso8601 = $input->format(\DateTime::ISO8601);
$iso8601 = strstr($iso8601, '+', true); //strip timezone
$iso8601 .= 'Z';
......
......@@ -321,6 +321,22 @@ class HelperTest extends \PHPUnit_Framework_TestCase
);
}
public function testFormatDateInputDateTimeImmutable()
{
date_default_timezone_set("UTC"); // prevent timezone differences
$this->assertFalse(
$this->helper->formatDate(new \stdClass()),
'Expect any other object not to be accepted'
);
$this->assertEquals(
$this->mockFormatDateOutput(strtotime('2011-10-01')),
$this->helper->formatDate(new \DateTimeImmutable('2011-10-01')),
'Expects formatDate with DateTimeImmutable input to output ISO8601 with stripped timezone'
);
}
public function testFormatDate()
{
//check if timezone is stripped
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment