shapecode / doctrine-dbal-datetimeutc
A custom Doctine DBAL type to use PHP DateTime objects set to the UTC timezone.
Fund package maintenance!
http://github.com/sponsors/nicklog
Paypal
Liberapay
Requires
- php: ^8.2
- doctrine/dbal: ^4.0
Requires (Dev)
- doctrine/coding-standard: ^12.0
- icanhazstring/composer-unused: ^0.8
- maglnet/composer-require-checker: ^4.10
- phpstan/phpstan: ^1.10
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^10.5
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^3.9
Replaces
README
A Doctrine DBAL Custom Mapping Type allowing the use of PHP DateTime objects automatically set to the UTC timezone.
Databases suck at timezones. The best way to deal with this is to store the date and time in UTC and separately store the timezone that should be used for display purposes. By default, PHP will create DateTime objects set the server's timezone. This custom type overrides this to set the timezone to UTC, allowing you to later convert to the proper timezone for display.
Install via composer:
composer req shapecode/doctrine-dbal-datetimeutc
Add the custom type before instantiating your entity manager:
use Doctrine\DBAL\Types\Type; use Shapecode\Doctrine\DBAL\Types\DateTimeUTCType; Type::addType(DateTimeUTCType::DATETIMEUTC, DateTimeUTCType::class);
Enjoy!