[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace Lcobucci\Clock; 4 5 use DateTimeImmutable; 6 use DateTimeZone; 7 use function interface_exists; 8 9 if (! interface_exists(Clock::class)) { 10 interface Clock 11 { 12 /** @return DateTimeImmutable */ 13 public function now(); 14 } 15 16 final class FrozenClock implements Clock 17 { 18 /** @var DateTimeImmutable */ 19 private $now; 20 21 public function __construct(DateTimeImmutable $now) 22 { 23 $this->now = $now; 24 } 25 26 /** @return self */ 27 public static function fromUTC() 28 { 29 return new self(new DateTimeImmutable('now', new DateTimeZone('UTC'))); 30 } 31 32 public function setTo(DateTimeImmutable $now) 33 { 34 $this->now = $now; 35 } 36 37 public function now() 38 { 39 return $this->now; 40 } 41 } 42 43 final class SystemClock implements Clock 44 { 45 /** @var DateTimeZone */ 46 private $timezone; 47 48 public function __construct(DateTimeZone $timezone) 49 { 50 $this->timezone = $timezone; 51 } 52 53 /** @return self */ 54 public static function fromUTC() 55 { 56 return new self(new DateTimeZone('UTC')); 57 } 58 59 /** @return self */ 60 public static function fromSystemTimezone() 61 { 62 return new self(new DateTimeZone(date_default_timezone_get())); 63 } 64 65 public function now() 66 { 67 return new DateTimeImmutable('now', $this->timezone); 68 } 69 } 70 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |