sllh/doctrine-dbal-utc-datetime

UTC DateTime type for Doctrine DBAL

v1.0.0 2017-09-25 19:52 UTC

This package is auto-updated.

Last update: 2024-12-13 03:22:22 UTC


README

UTC DateTime type for Doctrine DBAL.

Latest Stable Version Latest Unstable Version License

Total Downloads Monthly Downloads Daily Downloads

Build Status Coverage Status

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.