Hello,
I would like to propose standardizing a clock interface for reading the current time, date, timestamp, and timezone.
The problems I hope to solve is when testing time sensitive code, there is a unified way to represend the current time. I have run into several issues doing this some of which are:
- Some library use different Clock interfaces / implementations.
- Its impossible to mock some calls to date and time without using a PHP extension to override the current time & date.
- There are about 10 competing library implentations to this problem just from a quck search on packagist
The proposed interface would look like this:
interface ClockInterface
{
public function timestamp():int;
public function immutable():\DateTimeImmutable;
public function datetime():\DateTime
public function microtime():float
public function timezone():\DateTimeZone
}
I have created a pull request for this here:
I am looking to find out if anyone is interesting in sponsoring this Standard.
I have enjoyed using the PSR-16 interopable caches, and also migrated a large legacy application to use PSR-7/PSR-15 and also benefits from using standard middlewares and request extensions, and hope this could provide a similar experience in the future.
Regards,
Chris Seufert