diff --git a/eZ/Publish/API/Repository/Tests/FieldType/DateIntegrationTest.php b/eZ/Publish/API/Repository/Tests/FieldType/DateIntegrationTest.php index 2f128e4fed1..782cc49a98a 100644 --- a/eZ/Publish/API/Repository/Tests/FieldType/DateIntegrationTest.php +++ b/eZ/Publish/API/Repository/Tests/FieldType/DateIntegrationTest.php @@ -342,13 +342,35 @@ public function providerForTestIsNotEmptyValue() protected function getValidSearchValueOne() { - $date = new DateTime(); - return $date->setTimestamp( 123456 )->setTime( 0, 0, 0 )->getTimestamp(); + $date = new DateTime( "1970-01-02" ); + return $date->getTimestamp(); } protected function getValidSearchValueTwo() { - $date = new DateTime(); - return $date->setTimestamp( 234567 )->setTime( 0, 0, 0 )->getTimestamp(); + $date = new DateTime( "1970-01-03" ); + return $date->getTimestamp(); + } + + protected function getSearchTargetValueOne() + { + // Handling Legacy Search Engine, which stores Checkbox value as integer + if ( ltrim( get_class( $this->getSetupFactory() ), '\\' ) === 'eZ\Publish\API\Repository\Tests\SetupFactory\Legacy' ) + { + return $this->getValidSearchValueOne(); + } + + return "1970-01-02"; + } + + protected function getSearchTargetValueTwo() + { + // Handling Legacy Search Engine, which stores Checkbox value as integer + if ( ltrim( get_class( $this->getSetupFactory() ), '\\' ) === 'eZ\Publish\API\Repository\Tests\SetupFactory\Legacy' ) + { + return $this->getValidSearchValueTwo(); + } + + return "1970-01-03"; } } diff --git a/eZ/Publish/Core/FieldType/Date/SearchField.php b/eZ/Publish/Core/FieldType/Date/SearchField.php index f6abf97cf11..a4f61bae274 100644 --- a/eZ/Publish/Core/FieldType/Date/SearchField.php +++ b/eZ/Publish/Core/FieldType/Date/SearchField.php @@ -12,6 +12,7 @@ use eZ\Publish\SPI\Persistence\Content\Field; use eZ\Publish\SPI\FieldType\Indexable; use eZ\Publish\SPI\Search; +use DateTime; /** * Indexable definition for Date field type @@ -27,11 +28,17 @@ class SearchField implements Indexable */ public function getIndexData( Field $field ) { + // The field type stores date value as a timestamp of the start of the day in the + // environment's timezone. + // We format this as Y-m-d and add Z to signify UTC (zero offset). + $dateTime = new DateTime(); + $dateTime->setTimestamp( $field->value->data["timestamp"] ); + return array( new Search\Field( 'value', - $field->value->data["timestamp"], - new Search\FieldType\IntegerField() + $dateTime->format( "Y-m-d\\Z" ), + new Search\FieldType\DateField() ), ); } @@ -44,7 +51,7 @@ public function getIndexData( Field $field ) public function getIndexDefinition() { return array( - 'value' => new Search\FieldType\IntegerField(), + 'value' => new Search\FieldType\DateField(), ); }