mirror of
https://github.com/beste/clock.git
synced 2026-08-17 17:47:13 +00:00
The stella-maris/clock package provides an interface based on the currently proposed status of PSR20. Due to the inactivity of the PSR20 working group this is a way to already provide interoperability while still maintaining forward compatibility. When the current status of PSR20 will be released at one point in time the stella-maris/clock package will extend the PSR20 interface so that this package becomes immeadiately PSR20 compatible without any further work necessary. In the long run the stella-maris/clock package will then be marked deprecated so that people can then use the PSR20 provided implementation. Should the implementation of PSR20 change between now and a possible release then this interface will still exist and a possible implementation will need more code-changes anyhow so this interface will still provide some way of interoperability. The implementation of the PSR20 polyfill has been moved to the stella-maris/clock interface which can be implemented independentyl from PSR20 and might allow some interoperability before the working group of the FIG manages to decide upon something.
38 lines
732 B
PHP
38 lines
732 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Beste\Clock;
|
|
|
|
use Beste\Clock;
|
|
use DateTimeImmutable;
|
|
use StellaMaris\Clock\ClockInterface;
|
|
|
|
final class MinuteClock implements Clock
|
|
{
|
|
private ClockInterface $clock;
|
|
|
|
private function __construct(ClockInterface $clock)
|
|
{
|
|
$this->clock = $clock;
|
|
}
|
|
|
|
public static function wrapping(ClockInterface $clock): self
|
|
{
|
|
return new self($clock);
|
|
}
|
|
|
|
public function now(): DateTimeImmutable
|
|
{
|
|
return $this->floor($this->clock->now());
|
|
}
|
|
|
|
private function floor(DateTimeImmutable $now): DateTimeImmutable
|
|
{
|
|
return $now->setTime(
|
|
(int) $now->format('H'),
|
|
(int) $now->format('i')
|
|
);
|
|
}
|
|
}
|