Skip to content

Doctrine2 DateTimeType that will always store your DateTime in the UTC timezone.

License

Notifications You must be signed in to change notification settings

SooMedia/doctrine-utcdatetime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Doctrine UTCDateTimeType

Doctrine2 DateTimeType that will always store your DateTime in the UTC timezone.

All the code in this library was found in DoctrineExtensions' documentation. I take no credits for this code, I just simply bundled it in a nice and easy to use package.

Using the UTCDateTimeType

Add the library

Add the library in your project with Composer:

$ composer require soomedia/doctrine-utcdatetime

Override the default datetime type

Simply copied from DoctrineExtensions' documentation:

We simply have to register and override the datetime type. WARNING: this will override the datetime type for all your entities and for all entities in external bundles or extensions, so if you have some entities that require the standard datetime type from Doctrine, you must modify the above type and use a different name (such as utcdatetime). Additionally, if you use DoctrineExtensions, you'll need to modify Timestampable so that it includes utcdatetime as a valid type.

In Symfony2 you can do this like so:

doctrine:
    dbal:
        types:
            datetime: SooMedia\Doctrine\DBAL\Types\UTCDateTimeType

In Zend Framework 2 you have to add the following to your module.config.php:

<?php
return array(
    // other module config here
    'doctrine' => array(
        'configuration' => array(
            'orm_default' => array( // use the name of your default configuration/connection
                'types' => array(
                    'datetime' => 'SooMedia\Doctrine\DBAL\Types\UTCDateTimeType',
                ),
            ),
        ),
        // other configuration here, like the driver config
    ),
);

Credits

As I said: all credits for this piece of brilliant code goes to DoctrineExtensions. DoctrineExtensions adds a whole bunch of extra goodies to Doctrine, so I can really recommend using it!

About

Doctrine2 DateTimeType that will always store your DateTime in the UTC timezone.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages