UTC DateTime type for Doctrine DBAL.
This special type allow you to be sure to always save any DateTime to the UTC format.
The goal is to get rid of the quite hazardous timezone management of many database vendors.
For more information, please read the official Doctrine wiki page, where this class come from.
First of all, you need to require this library through composer:
composer require sllh/doctrine-dbal-utc-datetime
Then, replace the default datetime
and datetimetz
DBAL types:
use Doctrine\DBAL\Types\Type;
use SLLH\Doctrine\DBAL\Types\UTCDateTimeType;
Type::overrideType('datetime', UTCDateTimeType::class);
Type::overrideType('datetimetz', UTCDateTimeType::class);
If you are using Symfony, you can override the type trough the config.yml
file:
doctrine:
dbal:
types:
datetime: SLLH\Doctrine\DBAL\Types\UTCDateTimeType
datetimetz: SLLH\Doctrine\DBAL\Types\UTCDateTimeType
And voilĂ ! You are good to go. Happy coding!
This bundle is under the MIT license. See the complete license on the LICENSE file.