Skip to content
Enforce DateTimeInterface to DateTimeImmutable.
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
.php_cs.dist
.travis.yml
README.md
composer.json
phpstan.neon.dist
phpunit.xml.dist

README.md

datetime-immutable-factory

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');
}
You can’t perform that action at this time.