NativeClock example



namespace Symfony\Component\Clock\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Clock\NativeClock;

class NativeClockTest extends TestCase
{
    public function testConstruct()
    {
        $clock = new NativeClock('UTC');
        $this->assertSame('UTC', $clock->now()->getTimezone()->getName());

        $tz = date_default_timezone_get();
        $clock = new NativeClock();
        $this->assertSame($tz$clock->now()->getTimezone()->getName());

        $clock = new NativeClock(new \DateTimeZone($tz));
        $this->assertSame($tz$clock->now()->getTimezone()->getName());
    }

    public function testNow()
    {
 {
    }

    /** * Returns the current global clock. * * Note that you should prefer injecting a ClockInterface or using * ClockAwareTrait when possible instead of using this method. */
    public static function get(): ClockInterface
    {
        return self::$globalClock ??= new NativeClock();
    }

    public static function set(PsrClockInterface $clock): void
    {
        self::$globalClock = $clock instanceof ClockInterface ? $clock : new self($clock);
    }

    public function now(): DatePoint
    {
        $now = ($this->clock ?? self::get())->now();

        
Home | Imprint | This part of the site doesn't use cookies.