diff --git a/api/config/packages/doctrine.yaml b/api/config/packages/doctrine.yaml index dae8287b..2dc3f229 100644 --- a/api/config/packages/doctrine.yaml +++ b/api/config/packages/doctrine.yaml @@ -10,6 +10,7 @@ doctrine: url: '%env(resolve:DATABASE_URL)%' types: uuid: Ramsey\Uuid\Doctrine\UuidType + datetime: App\Types\UTCDateTimeType #We override the default doctrine datetime with a UTC based version incompleteDate: App\Types\IncompleteDateType underInvestigation: App\Types\UnderInvestigationType money: Tbbc\MoneyBundle\Type\MoneyType diff --git a/api/src/Types/UTCDateTimeType.php b/api/src/Types/UTCDateTimeType.php new file mode 100644 index 00000000..23f934c6 --- /dev/null +++ b/api/src/Types/UTCDateTimeType.php @@ -0,0 +1,46 @@ +setTimeZone(self::$utc); + + return $value->format($platform->getDateTimeFormatString()); + } + + public function convertToPHPValue($value, AbstractPlatform $platform) + { + if ($value === null) { + return null; + } + + if (is_null(self::$utc)) { + self::$utc = new \DateTimeZone('UTC'); + } + + $val = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value, self::$utc); + + if (!$val) { + throw ConversionException::conversionFailed($value, $this->getName()); + } + + return $val; + } +}