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-10-24 05:30:54 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');
}