Skip to content

Commit

Permalink
Fix for #618 DateTime is not set to UTC when using Extract (#619)
Browse files Browse the repository at this point in the history
* Test for issue 618 - DateTime not set to UTC

* Fix issue 618 - DateTime not set to UTC
  • Loading branch information
jeroenherczeg authored and Markus Kalkbrenner committed Aug 9, 2018
1 parent 5f51511 commit 4dfd71f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/QueryType/Extract/RequestBuilder.php
Expand Up @@ -48,6 +48,9 @@ public function build(QueryInterface $query)

// literal.*
foreach ($doc->getFields() as $name => $value) {
if ($value instanceof \DateTime) {
$value = $query->getHelper()->formatDate($value);
}
$value = (array) $value;
foreach ($value as $multival) {
$request->addParam('literal.'.$name, $multival);
Expand Down
25 changes: 25 additions & 0 deletions tests/QueryType/Extract/RequestBuilderTest.php
Expand Up @@ -113,4 +113,29 @@ public function testContentTypeHeader()

$this->assertSame($headers, $request->getHeaders());
}

public function testDocumentDateTimeField()
{
$timezone = new \DateTimeZone('Europe/London');
$date = new \DateTime('2013-01-15 14:41:58', $timezone);

$document = $this->query->createDocument(['date' => $date]);
$this->query->setDocument($document);

$request = $this->builder->build($this->query);

$this->assertEquals(
[
'fmap.from-field' => 'to-field',
'literal.date' => '2013-01-15T14:41:58Z',
'omitHeader' => 'true',
'extractOnly' => 'false',
'param1' => 'value1',
'resource.name' => 'RequestBuilderTest.php',
'wt' => 'json',
'json.nl' => 'flat',
],
$request->getParams()
);
}
}

0 comments on commit 4dfd71f

Please sign in to comment.