termyn /
timekeeper
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Termyn\Timekeeper; |
||
| 6 | |||
| 7 | use DateTimeImmutable; |
||
| 8 | use DateTimeZone; |
||
| 9 | |||
| 10 | final class SystemTimeService implements TimeService |
||
| 11 | { |
||
| 12 | private readonly string $systemTimeZoneName; |
||
| 13 | |||
| 14 | public function __construct() |
||
| 15 | { |
||
| 16 | $this->systemTimeZoneName = sprintf('%s', ini_get('date.timezone')); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 17 | } |
||
| 18 | |||
| 19 | public function measure(): DateTimeImmutable |
||
| 20 | { |
||
| 21 | $localeDateTime = new DateTimeImmutable( |
||
| 22 | sprintf('@%s', time()) |
||
| 23 | ); |
||
| 24 | |||
| 25 | return $localeDateTime->setTimezone( |
||
| 26 | new DateTimeZone($this->systemTimeZoneName) |
||
| 27 | ); |
||
| 28 | } |
||
| 29 | } |
||
| 30 |