doctrineum / datetime-immutable
2.1.0
2018-07-18 07:59 UTC
Requires
- php: >=7.1
- doctrine/dbal: ~2.4
- doctrineum/self-registering-type: ^2.1
- granam/strict-object: ^3.0
- granam/string: ^3.0
- granam/tools: ^3.0
Requires (Dev)
- mockery/mockery: ~1.0
- phpunit/phpunit: ~7.0
README
已废弃
请使用Doctrine\DBAL\Types\DateTimeImmuable代替。
你是否需要它?
- 首先,如果需要在应用程序中添加新类型,请三思。
- 难道Doctrine\DBAL\Types\DateTime不够用吗?
- 另一方面,任何时间的不变对象可以为您节省许多问题和时间...
使用方法
- 注册
\Doctrineum\DateTimeImmutable\DateTimeImmutableType::registerSelf();
- 使用
use Doctrine\ORM\Mapping as ORM; class Foo { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue */ private $id; /** * @ORM\Column(type="datetime-immutable") */ private $when; public function __construct(\DateTimeImmutable $when) { $this->when = $when; } }
\Doctrineum\DateTimeImmutable\DateTimeImmutableType::registerSelf(); $foo = new Foo(new \DateTimeImmutable()); // ... $entityManager->persist($foo); $entityManager->flush();
常见错误
注意时区不被持久化,因此在获取时无法恢复。Doctrine使用服务器默认时区。有关详细信息,尤其是解决方案,请参阅Doctrine文档