doctrineum/datetime-immutable

This package is abandoned and no longer maintained. The author suggests using the doctrine/dbal package instead.

DateTimeImmutable as a type for Doctrine - abandoned as doctrine/dba already implement this

2.1.0 2018-07-18 07:59 UTC

This package is auto-updated.

Last update: 2022-02-01 12:57:16 UTC


README

Test Coverage License

Deprecated

Use Doctrine\DBAL\Types\DateTimeImmuable instead.

Do you need it?

  • first of all, think twice if you need a new type into your application
  • on the other side, immutable object of any time can save you a lot of problems and time...

Usage

  • register it
\Doctrineum\DateTimeImmutable\DateTimeImmutableType::registerSelf();
  • use it
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();

Common pitfalls

Be aware of timezone which is not persisted and therefore can not be restored on fetch. Doctrine uses server default timezone for it. For details and most of all, for solution, see Doctrine docs