Class ClockFactory
PSR-20 Clock implementation.
Provides a PSR-20 compatible clock that returns Chronos instances. Useful for dependency injection and testing scenarios where you need to control the current time.
Example:
$clock = new ClockFactory('UTC');
$now = $clock->now(); // Returns Chronos instance
Namespace: Cake\Chronos
Method Summary
-
__construct() public
Constructor.
-
now() public
Returns the current time as a Chronos instance.
Method Detail
__construct() ¶ public
__construct(DateTimeZone|string|null $timezone = null)
Constructor.
Parameters
-
DateTimeZone|string|null$timezone optional The timezone
now() ¶ public
now(): Cake\Chronos\Chronos
Returns the current time as a Chronos instance.
The return type is DateTimeImmutable for PSR-20 compatibility, but the actual returned instance is always Chronos.
Returns
Cake\Chronos\Chronos