kalibora/datetime-immutable-factory

Create DateTimeImmutable from DateTimeInterface

v0.2.0 2023-06-24 02:06 UTC

This package is auto-updated.

Last update: 2024-03-24 04:24:08 UTC


README

Enforce DateTimeInterface to DateTimeImmutable.

Usage

$immutable1 = DateTimeImmutableFactory::create(new \DateTime());
$immutable2 = DateTimeImmutableFactory::create(new \DateTimeImmutable());

function addOneDay(\DateTimeInterface $date) : \DateTimeInterface
{
    // Call to an undefined method DateTimeInterface::modify()
    // $date->modify();

    return DateTimeImmutableFactory::create($date)->modify('+1 day');
}