Skip to content

Commit

Permalink
Merge branch '6.7' into 6.8
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickroger committed Mar 29, 2017
2 parents c5503df + 1e956cb commit 5744cd9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 36 deletions.
41 changes: 20 additions & 21 deletions eZ/Publish/API/Repository/Tests/FieldType/DateIntegrationTest.php
Expand Up @@ -109,7 +109,9 @@ public function getInvalidValidatorConfiguration()
*/
public function getValidCreationFieldData()
{
return DateValue::fromString('Wed, 21 Jul 2013 16:59:50');
// We may only create times from timestamps here, since storing will
// loose information about the timezone.
return DateValue::fromTimestamp(86400);
}

/**
Expand All @@ -119,7 +121,7 @@ public function getValidCreationFieldData()
*/
public function getFieldName()
{
return 'Wednesday 24 July 2013';
return 'Friday 02 January 1970';
}

/**
Expand All @@ -137,11 +139,10 @@ public function assertFieldDataLoadedCorrect(Field $field)
$field->value
);

$dateTime = new DateTime('Wed, 21 Jul 2013 16:59:50');
$dateTime->setTime(0, 0, 0);
$expectedData = array(
'date' => $dateTime,
'date' => new DateTime('@86400'),
);

$this->assertPropertiesCorrect(
$expectedData,
$field->value
Expand Down Expand Up @@ -186,11 +187,11 @@ public function provideInvalidCreationFieldData()
*/
public function getValidUpdateFieldData()
{
return DateValue::fromString('Wed, 21 Jul 2013 17:59:50');
return DateValue::fromTimestamp(86400);
}

/**
* Asserts the the field data was loaded correctly.
* Asserts the field data was loaded correctly.
*
* Asserts that the data provided by {@link getValidUpdateFieldData()}
* was stored and loaded correctly.
Expand All @@ -204,10 +205,8 @@ public function assertUpdatedFieldDataLoadedCorrect(Field $field)
$field->value
);

$dateTime = new DateTime('Wed, 21 Jul 2013 17:59:50');
$dateTime->setTime(0, 0, 0);
$expectedData = array(
'date' => $dateTime,
'date' => new DateTime('@86400'),
);
$this->assertPropertiesCorrect(
$expectedData,
Expand Down Expand Up @@ -276,13 +275,14 @@ public function assertCopiedFieldDataLoadedCorrectly(Field $field)
*/
public function provideToHashData()
{
$dateTime = new DateTime();
$timestamp = 186401;
$dateTime = new DateTime("@{$timestamp}");

return array(
array(
DateValue::fromTimestamp($timestamp = 186401),
DateValue::fromTimestamp($timestamp),
array(
'timestamp' => $dateTime->setTimestamp($timestamp)->setTime(0, 0, 0)->getTimestamp(),
'timestamp' => $dateTime->setTime(0, 0, 0)->getTimestamp(),
'rfc850' => $dateTime->format(DateTime::RFC850),
),
),
Expand Down Expand Up @@ -311,19 +311,22 @@ public function provideToHashData()
*/
public function provideFromHashData()
{
$timestamp = 123456;

$dateTime = new DateTime();
$dateTime->setTimestamp($timestamp)->setTime(0, 0, 0);

return array(
array(
array(
'timestamp' => $dateTime->setTimestamp(123456)->setTime(0, 0, 0)->getTimestamp(),
'timestamp' => $timestamp,
'rfc850' => ($rfc850 = $dateTime->format(DateTime::RFC850)),
),
DateValue::fromString($rfc850),
),
array(
array(
'timestamp' => $dateTime->setTimestamp($timestamp = 123456)->setTime(0, 0, 0)->getTimestamp(),
'timestamp' => $timestamp,
'rfc850' => null,
),
DateValue::fromTimestamp($timestamp),
Expand All @@ -349,16 +352,12 @@ public function providerForTestIsNotEmptyValue()

protected function getValidSearchValueOne()
{
$date = new DateTime('1970-01-02');

return $date->getTimestamp();
return 86400;
}

protected function getValidSearchValueTwo()
{
$date = new DateTime('1970-01-03');

return $date->getTimestamp();
return 172800;
}

protected function getSearchTargetValueOne()
Expand Down
6 changes: 1 addition & 5 deletions eZ/Publish/Core/FieldType/Date/SearchField.php
Expand Up @@ -29,11 +29,7 @@ class SearchField implements Indexable
*/
public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
{
// 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']);
$dateTime = new DateTime("@{$field->value->data['timestamp']}");

return array(
new Search\Field(
Expand Down
5 changes: 1 addition & 4 deletions eZ/Publish/Core/FieldType/Date/Value.php
Expand Up @@ -76,10 +76,7 @@ public static function fromString($dateString)
public static function fromTimestamp($timestamp)
{
try {
$dateTime = new DateTime();
$dateTime->setTimestamp($timestamp);

return new static($dateTime);
return new static(new DateTime("@{$timestamp}"));
} catch (Exception $e) {
throw new InvalidArgumentValue('$timestamp', $timestamp, __CLASS__, $e);
}
Expand Down
10 changes: 4 additions & 6 deletions eZ/Publish/Core/FieldType/Tests/DateTest.php
Expand Up @@ -135,8 +135,6 @@ public function provideInvalidInputForAcceptValue()
*/
public function provideValidInputForAcceptValue()
{
$dateTime = new DateTime();

return array(
array(
null,
Expand All @@ -149,12 +147,12 @@ public function provideValidInputForAcceptValue()
array(
($timestamp = 1346149200),
new DateValue(
clone $dateTime->setTimestamp($timestamp)
new DateTime("@{$timestamp}")
),
),
array(
DateValue::fromTimestamp(1372895999),
new DateValue($dateTime->setTimestamp(1372895999)->setTime(0, 0, 0)),
DateValue::fromTimestamp($timestamp = 1372895999),
new DateValue(new DateTime("@{$timestamp}")),
),
array(
($dateTime = new DateTime()),
Expand Down Expand Up @@ -263,7 +261,7 @@ public function provideInputForFromHash()
array(
'timestamp' => ($timestamp = 1362614400),
),
new DateValue(clone $dateTime->setTimestamp($timestamp)),
new DateValue(new DateTime("@{$timestamp}")),
),
array(
array(
Expand Down

0 comments on commit 5744cd9

Please sign in to comment.