kalibora / datetime-immutable-factory
Create DateTimeImmutable from DateTimeInterface
Installs: 64 441
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 2
Open Issues: 0
pkg:composer/kalibora/datetime-immutable-factory
Requires
- php: ^8.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^v3.16
- phpstan/phpstan: ^1.10
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2026-01-17 05:08:45 UTC
README
Enforce DateTimeInterface to DateTimeImmutable.
Status
⚠️ This library is no longer necessary on PHP 8.0 or later.
PHP 8.0 introduced DateTimeImmutable::createFromInterface(), which provides the same functionality as this library.
If you are using PHP 8.0 or newer, please use the built-in method instead:
https://www.php.net/manual/en/datetimeimmutable.createfrominterface.php
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'); }