diff --git a/eZ/Publish/API/Repository/Tests/FieldType/DateIntegrationTest.php b/eZ/Publish/API/Repository/Tests/FieldType/DateIntegrationTest.php index 5d20aa05cf..4952f86d7b 100644 --- a/eZ/Publish/API/Repository/Tests/FieldType/DateIntegrationTest.php +++ b/eZ/Publish/API/Repository/Tests/FieldType/DateIntegrationTest.php @@ -117,9 +117,9 @@ public function getInvalidValidatorConfiguration() */ public function getValidCreationFieldData() { - // We may only create times from timestamps here, since storing will - // loose information about the timezone. - return DateValue::fromTimestamp(86400); + $dateTime = $this->getValueOneDate(); + + return DateValue::fromTimestamp($dateTime->getTimestamp()); } /** @@ -147,8 +147,10 @@ public function assertFieldDataLoadedCorrect(Field $field) $field->value ); + $dateTime = $this->getValueOneDate(); + $expectedData = [ - 'date' => new DateTime('@86400'), + 'date' => $dateTime, ]; $this->assertPropertiesCorrect( @@ -195,7 +197,9 @@ public function provideInvalidCreationFieldData() */ public function getValidUpdateFieldData() { - return DateValue::fromTimestamp(86400); + $dateTime = $this->getValueOneDate(); + + return DateValue::fromTimestamp($dateTime->getTimestamp()); } /** @@ -213,8 +217,10 @@ public function assertUpdatedFieldDataLoadedCorrect(Field $field) $field->value ); + $dateTime = $this->getValueOneDate(); + $expectedData = [ - 'date' => new DateTime('@86400'), + 'date' => $dateTime, ]; $this->assertPropertiesCorrect( $expectedData, @@ -283,8 +289,9 @@ public function assertCopiedFieldDataLoadedCorrectly(Field $field) */ public function provideToHashData() { - $timestamp = 186401; - $dateTime = new DateTime("@{$timestamp}"); + $timestamp = 186400; + $dateTime = new DateTime(); + $dateTime->setTimestamp($timestamp); return [ [ @@ -327,17 +334,17 @@ public function provideFromHashData() return [ [ [ - 'timestamp' => $timestamp, + 'timestamp' => $dateTime->getTimestamp(), 'rfc850' => ($rfc850 = $dateTime->format(DateTime::RFC850)), ], DateValue::fromString($rfc850), ], [ [ - 'timestamp' => $timestamp, + 'timestamp' => $dateTime->getTimestamp(), 'rfc850' => null, ], - DateValue::fromTimestamp($timestamp), + DateValue::fromTimestamp($dateTime->getTimestamp()), ], ]; } @@ -360,12 +367,16 @@ public function providerForTestIsNotEmptyValue() protected function getValidSearchValueOne() { - return 86400; + $dateTime = $this->getValueOneDate(); + + return $dateTime->getTimestamp(); } protected function getValidSearchValueTwo() { - return 172800; + $dateTime = new DateTime('1970-01-03'); + + return $dateTime->getTimestamp(); } protected function getSearchTargetValueOne() @@ -387,4 +398,9 @@ protected function getSearchTargetValueTwo() return '1970-01-03T00:00:00Z'; } + + protected function getValueOneDate(): DateTime + { + return new DateTime('1970-01-02'); + } } diff --git a/eZ/Publish/Core/FieldType/Date/Value.php b/eZ/Publish/Core/FieldType/Date/Value.php index 58d05e707b..5a11f1399c 100644 --- a/eZ/Publish/Core/FieldType/Date/Value.php +++ b/eZ/Publish/Core/FieldType/Date/Value.php @@ -74,7 +74,10 @@ public static function fromString($dateString) public static function fromTimestamp($timestamp) { try { - return new static(new DateTime("@{$timestamp}")); + $datetime = new DateTime(); + $datetime->setTimestamp($timestamp); + + return new static($datetime); } catch (Exception $e) { throw new InvalidArgumentValue('$timestamp', $timestamp, __CLASS__, $e); } diff --git a/eZ/Publish/Core/FieldType/Tests/DateTest.php b/eZ/Publish/Core/FieldType/Tests/DateTest.php index 5b96123f78..4229a1235c 100644 --- a/eZ/Publish/Core/FieldType/Tests/DateTest.php +++ b/eZ/Publish/Core/FieldType/Tests/DateTest.php @@ -145,13 +145,11 @@ public function provideValidInputForAcceptValue() ], [ ($timestamp = 1346149200), - new DateValue( - new DateTime("@{$timestamp}") - ), + new DateValue((new DateTime())->setTimestamp($timestamp)), ], [ DateValue::fromTimestamp($timestamp = 1372895999), - new DateValue(new DateTime("@{$timestamp}")), + new DateValue((new DateTime())->setTimestamp($timestamp)), ], [ ($dateTime = new DateTime()), @@ -260,7 +258,7 @@ public function provideInputForFromHash() [ 'timestamp' => ($timestamp = 1362614400), ], - new DateValue(new DateTime("@{$timestamp}")), + new DateValue($dateTime->setTimestamp($timestamp)), ], [ [