Esempio n. 1
0
 /**
  * @test
  */
 public function getDateTimeRespectsConfiguredTimezone()
 {
     ClockProvider::setTimezone('UTC');
     $clock = new RealClock();
     $now = $clock->getDateTime();
     $this->assertInstanceof('DateTime', $now);
     $this->assertEquals($now->getTimezone()->getName(), date_default_timezone_get());
 }
Esempio n. 2
0
 /**
  * @return DateTime
  */
 public function getDateTime()
 {
     $now = DateTime::createFromFormat('U', $this->time);
     $now->setTimezone(ClockProvider::getTimezone());
     return $now;
 }
Esempio n. 3
0
<?php

namespace Pekkis\Clock\Example;

require_once __DIR__ . '/../vendor/autoload.php';
use Pekkis\Clock\ClockProvider;
use Pekkis\Clock\FixedClock;
use DateTime;
// Real system clock, returns actual time
$time = ClockProvider::getClock()->getTime();
var_dump($time);
// Fixed clock (for testing for example)
ClockProvider::setClock(new FixedClock(new DateTime('1978-03-21')));
$time = ClockProvider::getClock()->getTime();
var_dump($time);
// Get time as datetime object
$time = ClockProvider::getClock()->getDateTime();
var_dump($time->format('Y-m-d H:i:s'));
Esempio n. 4
0
 /**
  * @test
  */
 public function listensToSetter()
 {
     $clock = new FixedClock(time());
     ClockProvider::setClock($clock);
     $this->assertSame($clock, ClockProvider::getClock());
 }