/** * @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; }
/** * @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); } }
private function _nowAsTimestamp() { return Clock::now()->getTimestamp(); }
/** * 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); }