now() public static method

Obtains a Clock set to the current time.
public static now ( ) : Clock
return Clock
 /**
  * @inheritdoc
  */
 public function get()
 {
     $function = $this->function;
     $now = Clock::now()->getTimestamp();
     if ($this->cachedResult === null || $now - $this->lastCallTime > $this->expireTime) {
         $this->cachedResult = $function();
         $this->lastCallTime = $now;
     }
     return $this->cachedResult;
 }
Beispiel #2
0
 /**
  * @test
  */
 public function shouldReturnTimestamp()
 {
     //given
     Clock::freeze('2011-01-02 12:34');
     //when
     $timestamp = Clock::now()->getTimestamp();
     //then
     $dateTime = new DateTime('2011-01-02 12:34');
     $this->assertEquals($dateTime->getTimestamp(), $timestamp);
 }
 public function poll()
 {
     Stats::reset();
     session_write_close();
     $stop = Clock::now()->plusSeconds(self::TIMEOUT);
     while (true) {
         if (!$stop->isAfter(Clock::now()) || connection_aborted()) {
             $this->layout->renderAjax("[]");
             return;
         }
         session_start();
         $events = Event::loadNew();
         session_write_close();
         if ($events) {
             $this->layout->renderAjax(Json::encode(Arrays::map($events, function (Event $event) {
                 return $event->toJsonArray();
             })));
             return;
         }
         Stats::reset();
         usleep(100 * 1000);
     }
 }
Beispiel #4
0
 private function _nowAsTimestamp()
 {
     return Clock::now()->getTimestamp();
 }
Beispiel #5
0
 /**
  * Modifies the current time and returns a formatted date.
  *
  * @link http://php.net/manual/en/datetime.formats.php
  *
  * @param string $interval
  * @param string $format
  * @return string
  */
 public static function modifyNow($interval, $format = self::DEFAULT_TIME_FORMAT)
 {
     return Clock::now()->toDateTime()->modify($interval)->format($format);
 }