Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
SystemClock
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 now
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * This file is part of php-fast-forward/clock.
7 *
8 * This source file is subject to the license bundled
9 * with this source code in the file LICENSE.
10 *
11 * @copyright Copyright (c) 2025-2026 Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
12 * @license   https://opensource.org/licenses/MIT MIT License
13 *
14 * @see       https://github.com/php-fast-forward/clock
15 * @see       https://github.com/php-fast-forward
16 * @see       https://datatracker.ietf.org/doc/html/rfc2119
17 */
18
19namespace FastForward\Clock;
20
21use DateTimeImmutable;
22use DateTimeZone;
23use Psr\Clock\ClockInterface;
24
25/**
26 * Provides the current system time in a predictable timezone.
27 */
28  class SystemClock implements ClockInterface
29{
30    private ?DateTimeZone $timezone;
31
32    /**
33     * Creates a new system clock.
34     *
35     * @param DateTimeZone|string|null $timezone the timezone that SHOULD be used by this clock
36     */
37    public function __construct(DateTimeZone|string|null $timezone = null)
38    {
39        $this->timezone = \is_string($timezone) ? new DateTimeZone($timezone) : $timezone;
40    }
41
42    /**
43     * Returns the current date-time.
44     */
45    public function now(): DateTimeImmutable
46    {
47        return new DateTimeImmutable('now', $this->timezone);
48    }
49}