CoreFiles by mySites.guru
lcobucci-clock-polyfill.php70 lines, 1,523 bytes, from Joomla_4.2.8-Stable-Full_Package.zip
Raw History Compare with 4.2.7
md5
563064962e67eb700480d265422933db
sha1
7ab8fbb79ce3d1ddc65e0df3e567287782442c64
sha256
a48348e85c2659f17466e0241f08d934388456a5634ecb34a41d5c82de412ae7
<?php

namespace Lcobucci\Clock;

use DateTimeImmutable;
use DateTimeZone;
use function interface_exists;

if (! interface_exists(Clock::class)) {
    interface Clock
    {
        /** @return DateTimeImmutable */
        public function now();
    }

    final class FrozenClock implements Clock
    {
        /** @var DateTimeImmutable */
        private $now;

        public function __construct(DateTimeImmutable $now)
        {
            $this->now = $now;
        }

        /** @return self */
        public static function fromUTC()
        {
            return new self(new DateTimeImmutable('now', new DateTimeZone('UTC')));
        }

        public function setTo(DateTimeImmutable $now)
        {
            $this->now = $now;
        }

        public function now()
        {
            return $this->now;
        }
    }

    final class SystemClock implements Clock
    {
        /** @var DateTimeZone */
        private $timezone;

        public function __construct(DateTimeZone $timezone)
        {
            $this->timezone = $timezone;
        }

        /** @return self */
        public static function fromUTC()
        {
            return new self(new DateTimeZone('UTC'));
        }

        /** @return self */
        public static function fromSystemTimezone()
        {
            return new self(new DateTimeZone(date_default_timezone_get()));
        }

        public function now()
        {
            return new DateTimeImmutable('now', $this->timezone);
        }
    }
}

The same content is in 75 releases, Joomla 4.2.0-beta3 to 4.4.14. See them all, or every version of this file.