sllh / doctrine-dbal-utc-datetime
UTC DateTime type for Doctrine DBAL
Requires
- php: ^7.1
- doctrine/dbal: ^2.6
Suggests
- doctrine/doctrine-bundle: For Symfony integration of the DBAL type
This package is auto-updated.
Last update: 2024-10-13 02:59:03 UTC
README
UTC DateTime type for Doctrine DBAL.
Why this DBAL Type?
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.
Setup
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!
License
This bundle is under the MIT license. See the complete license on the LICENSE file.