Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset date part for time type #380

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Common/Doctrine/Type/UTCTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class UTCTimeType extends TimeType
*/
public function convertToDatabaseValue($time, AbstractPlatform $platform): ?string
{
// Reset date part of the time object to 01/01/1970 to keep the timezone consistent
// between writing and reading the entity from the database
$time->setDate(1970, 1, 1);

if ($time instanceof DateTime) {
$time->setTimezone(self::getUtc());
}
Expand All @@ -47,6 +51,10 @@ public function convertToPHPValue($timeString, AbstractPlatform $platform): ?Dat

$time = DateTime::createFromFormat($platform->getTimeFormatString(), $timeString, self::getUtc());

// Reset date part of the time object to 01/01/1970 to keep the timezone consistent
// between writing and reading the entity from the database
$time->setDate(1970, 1, 1);

if (!$time) {
throw ConversionException::conversionFailedFormat(
$timeString,
Expand Down
Loading