sllh / doctrine-dbal-utc-datetime
Doctrine DBAL 的 UTC DateTime 类型
v1.0.0
2017-09-25 19:52 UTC
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-09-13 02:54:35 UTC
README
Doctrine DBAL 的 UTC DateTime 类型。
为什么需要这个 DBAL 类型?
这个特殊类型让你可以确保始终将任何 DateTime 保存为 UTC 格式。
目标是摆脱许多数据库供应商的相当危险的时区管理。
有关更多信息,请阅读官方 Doctrine wiki 页面,其中介绍了这个类。
安装
首先,您需要通过 composer 需求此库
composer require sllh/doctrine-dbal-utc-datetime
然后,替换默认的 datetime
和 datetimetz
DBAL 类型
use Doctrine\DBAL\Types\Type; use SLLH\Doctrine\DBAL\Types\UTCDateTimeType; Type::overrideType('datetime', UTCDateTimeType::class); Type::overrideType('datetimetz', UTCDateTimeType::class);
如果您使用 Symfony,您可以通过 config.yml
文件覆盖类型
doctrine: dbal: types: datetime: SLLH\Doctrine\DBAL\Types\UTCDateTimeType datetimetz: SLLH\Doctrine\DBAL\Types\UTCDateTimeType
那么,您就可以开始了!祝您编码愉快!
许可证
此包采用 MIT 许可证。请参阅LICENSE 文件中的完整许可证。