Formats a time interval depending on the size according to:
- just now - interval < 1 min
- 2 min ago - interval < 30 mins
- 3:17 AM - today
- Yesterday, 3:17 AM - yesterday
- Jan. 10, 7:12 AM - current year
- Jan. 10,2015, 7:12 AM - less than the current year
public static getIncrescentTimeInterval ( $value, $currentTime = null ) : string | ||
Результат | string |
/** * @test * @dataProvider providerIncrescentTimeInterval */ public function testIncrescentTimeInterval($date, $curDate, $expected) { $this->assertEquals($expected, \Scalr_Util_DateTime::getIncrescentTimeInterval($date, $curDate)); $date = DateTime::createFromFormat('Y-m-d H:i:s', $date); $curDate = DateTime::createFromFormat('Y-m-d H:i:s', $curDate); $this->assertEquals($expected, \Scalr_Util_DateTime::getIncrescentTimeInterval($date, $curDate)); }
public function getContent($params = []) { if ($this->user->getType() != User::TYPE_SCALR_ADMIN) { throw new Scalr_Exception_InsufficientPermissions(); } $hosts = []; foreach (ScalrHost::find() as $host) { $hosts[] = ['host' => $host->host, 'version' => $host->version, 'edition' => $host->edition, 'revision' => empty($host->gitCommit) ? '' : $host->gitCommit, 'revDate' => empty($host->gitCommitAdded) ? '' : $host->gitCommitAdded->format('Y-m-d H:i:s O')]; } $stateNames = ScalrService::listStateNames(); $allServices = []; foreach (ScalrService::find([['name' => ['$nin' => ScalrService::EXCLUDED_SERVICES]]]) as $scalrService) { $lastTime = empty($scalrService->lastFinish) ? time() : $scalrService->lastFinish->getTimestamp(); $allServices[] = ['name' => ucfirst(str_replace("_", " ", $scalrService->name)), 'numWorkers' => $scalrService->numWorkers, 'numTasks' => $scalrService->numTasks, 'lastStart' => !empty($scalrService->lastStart) ? Scalr_Util_DateTime::getIncrescentTimeInterval($scalrService->lastStart) : '', 'timeSpent' => !empty($scalrService->lastStart) ? $lastTime - $scalrService->lastStart->getTimestamp() : '', 'state' => $stateNames[$scalrService->state]]; } return ['hosts' => $hosts, 'services' => $allServices]; }