kalibora / datetime-immutable-factory
从 DateTimeInterface 创建 DateTimeImmutable
v0.2.0
2023-06-24 02:06 UTC
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: 2024-09-24 05:24:55 UTC
README
强制 DateTimeInterface 转换为 DateTimeImmutable。
用法
$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'); }