pauci / datetime
Enhanced DateTime, DateTimeImmutable and DateInterval objects
v0.7.0
2023-01-18 12:28 UTC
Requires (Dev)
- php-parallel-lint/php-parallel-lint: ^1.3
- phpstan/extension-installer: ^1.2
- phpstan/phpstan: ^1.9
- phpstan/phpstan-phpunit: ^1.3
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
Suggests
- pauci/datetime-doctrine: Allows the use of pauci/datetime value objects as Doctrine field types.
This package is auto-updated.
Last update: 2026-05-18 19:36:48 UTC
README
Provides enhanced DateTime and DateInterval objects with clock abstraction
- based on
DateTimeImmutableobject (to discourage the use of mutable version) - provides
SystemClockfor production andFrozenClockfor testing - provides extra static factory methods:
now()(uses clock),fromString(),fromTimestamp(),fromFloatTimestamp() - implements
StringableandJsonSerializablewith implicit conversion to string (ISO 8601)
Examples
use Pauci\DateTime\DateTime; $now = $clock->now(); // or DateTime::setClock($clock); $now = DateTime::now(); echo $now; // 2016-05-20T14:30:54.345678+02:00 echo json_encode($now); // "2016-05-20T14:30:54.345678+02:00" echo DateTime::fromTimestamp(1512148033); // 2017-12-01T18:07:13+01:00 echo DateTime::fromFloatTimestamp(1512148033.000005); // 2017-12-01T18:07:13.000005+01:00 DateTime::setFormat('Y-m-d H:i:s'); echo $now; // 2016-05-20 14:30:54 echo json_encode($now); // "2016-05-20 14:30:54"