本文整理汇总了PHP中PhabricatorTime类的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorTime类的具体用法?PHP PhabricatorTime怎么用?PHP PhabricatorTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PhabricatorTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderResultList
protected function renderResultList(array $countdowns, PhabricatorSavedQuery $query, array $handles)
{
assert_instances_of($countdowns, 'PhabricatorCountdown');
$viewer = $this->requireViewer();
$list = new PHUIObjectItemListView();
$list->setUser($viewer);
foreach ($countdowns as $countdown) {
$id = $countdown->getID();
$ended = false;
$epoch = $countdown->getEpoch();
if ($epoch <= PhabricatorTime::getNow()) {
$ended = true;
}
$item = id(new PHUIObjectItemView())->setUser($viewer)->setObject($countdown)->setObjectName("C{$id}")->setHeader($countdown->getTitle())->setHref($this->getApplicationURI("{$id}/"))->addByline(pht('Created by %s', $handles[$countdown->getAuthorPHID()]->renderLink()));
if ($ended) {
$item->addAttribute(pht('Launched on %s', phabricator_datetime($epoch, $viewer)));
$item->setDisabled(true);
} else {
$time_left = $epoch - PhabricatorTime::getNow();
$num = round($time_left / (60 * 60 * 24));
$noun = pht('Days');
if ($num < 1) {
$num = round($time_left / (60 * 60), 1);
$noun = pht('Hours');
}
$item->setCountdown($num, $noun);
$item->addAttribute(phabricator_datetime($epoch, $viewer));
}
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No countdowns found.'));
return $result;
}
示例2: buildAbstractDocument
protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
{
$project = $object;
$project->updateDatasourceTokens();
$document->setDocumentTitle($project->getName());
$document->addRelationship($project->isArchived() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $project->getPHID(), PhabricatorProjectProjectPHIDType::TYPECONST, PhabricatorTime::getNow());
}
示例3: parseDateTime
protected function parseDateTime($value)
{
if (!strlen($value)) {
return null;
}
return PhabricatorTime::parseLocalTime($value, $this->getViewer());
}
示例4: loadTasks
protected function loadTasks(PhutilArgumentParser $args)
{
$ids = $args->getArg('id');
$class = $args->getArg('class');
$min_failures = $args->getArg('min-failure-count');
if (!$ids && !$class && !$min_failures) {
throw new PhutilArgumentUsageException(pht('Use --id, --class, or --min-failure-count to select tasks.'));
}
$active_query = new PhabricatorWorkerActiveTaskQuery();
$archive_query = new PhabricatorWorkerArchiveTaskQuery();
if ($ids) {
$active_query = $active_query->withIDs($ids);
$archive_query = $archive_query->withIDs($ids);
}
if ($class) {
$class_array = array($class);
$active_query = $active_query->withClassNames($class_array);
$archive_query = $archive_query->withClassNames($class_array);
}
if ($min_failures) {
$active_query = $active_query->withFailureCountBetween($min_failures, null);
$archive_query = $archive_query->withFailureCountBetween($min_failures, null);
}
$active_tasks = $active_query->execute();
$archive_tasks = $archive_query->execute();
$tasks = mpull($active_tasks, null, 'getID') + mpull($archive_tasks, null, 'getID');
if ($ids) {
foreach ($ids as $id) {
if (empty($tasks[$id])) {
throw new PhutilArgumentUsageException(pht('No task exists with id "%s"!', $id));
}
}
}
if ($class && $min_failures) {
if (!$tasks) {
throw new PhutilArgumentUsageException(pht('No task exists with class "%s" and at least %d failures!', $class, $min_failures));
}
} else {
if ($class) {
if (!$tasks) {
throw new PhutilArgumentUsageException(pht('No task exists with class "%s"!', $class));
}
} else {
if ($min_failures) {
if (!$tasks) {
throw new PhutilArgumentUsageException(pht('No tasks exist with at least %d failures!', $min_failures));
}
}
}
}
// When we lock tasks properly, this gets populated as a side effect. Just
// fake it when doing manual CLI stuff. This makes sure CLI yields have
// their expires times set properly.
foreach ($tasks as $task) {
if ($task instanceof PhabricatorWorkerActiveTask) {
$task->setServerTime(PhabricatorTime::getNow());
}
}
return $tasks;
}
示例5: handleRequest
public function handleRequest(AphrontRequest $request)
{
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$countdown = id(new PhabricatorCountdownQuery())->setViewer($viewer)->withIDs(array($id))->executeOne();
if (!$countdown) {
return new Aphront404Response();
}
$countdown_view = id(new PhabricatorCountdownView())->setUser($viewer)->setCountdown($countdown)->setHeadless(true);
$id = $countdown->getID();
$title = $countdown->getTitle();
$crumbs = $this->buildApplicationCrumbs()->addTextCrumb("C{$id}");
$epoch = $countdown->getEpoch();
if ($epoch >= PhabricatorTime::getNow()) {
$icon = 'fa-clock-o';
$color = '';
$status = pht('Running');
} else {
$icon = 'fa-check-square-o';
$color = 'dark';
$status = pht('Launched');
}
$header = id(new PHUIHeaderView())->setHeader($title)->setUser($viewer)->setPolicyObject($countdown)->setStatus($icon, $color, $status);
$actions = $this->buildActionListView($countdown);
$properties = $this->buildPropertyListView($countdown, $actions);
$object_box = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties);
$timeline = $this->buildTransactionTimeline($countdown, new PhabricatorCountdownTransactionQuery());
$add_comment = $this->buildCommentForm($countdown);
$content = array($crumbs, $object_box, $countdown_view, $timeline, $add_comment);
return $this->buildApplicationPage($content, array('title' => $title, 'pageObjects' => array($countdown->getPHID())));
}
示例6: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$tasks = $this->loadTasks($args);
foreach ($tasks as $task) {
$can_execute = !$task->isArchived();
if (!$can_execute) {
$console->writeOut("**<bg:yellow> %s </bg>** %s\n", pht('ARCHIVED'), pht('%s is already archived, and can not be executed.', $this->describeTask($task)));
continue;
}
// NOTE: This ignores leases, maybe it should respect them without
// a parameter like --force?
$task->setLeaseOwner(null);
$task->setLeaseExpires(PhabricatorTime::getNow());
$task->save();
$task_data = id(new PhabricatorWorkerTaskData())->loadOneWhere('id = %d', $task->getDataID());
$task->setData($task_data->getData());
$console->writeOut(pht('Executing task %d (%s)...', $task->getID(), $task->getTaskClass()));
$task = $task->executeTask();
$ex = $task->getExecutionException();
if ($ex) {
throw $ex;
}
}
return 0;
}
示例7: handleRequest
public function handleRequest(AphrontRequest $request)
{
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$countdown = id(new PhabricatorCountdownQuery())->setViewer($viewer)->withIDs(array($id))->executeOne();
if (!$countdown) {
return new Aphront404Response();
}
$countdown_view = id(new PhabricatorCountdownView())->setUser($viewer)->setCountdown($countdown);
$id = $countdown->getID();
$title = $countdown->getTitle();
$crumbs = $this->buildApplicationCrumbs()->addTextCrumb("C{$id}")->setBorder(true);
$epoch = $countdown->getEpoch();
if ($epoch >= PhabricatorTime::getNow()) {
$icon = 'fa-clock-o';
$color = '';
$status = pht('Running');
} else {
$icon = 'fa-check-square-o';
$color = 'dark';
$status = pht('Launched');
}
$header = id(new PHUIHeaderView())->setHeader($title)->setUser($viewer)->setPolicyObject($countdown)->setStatus($icon, $color, $status)->setHeaderIcon('fa-rocket');
$curtain = $this->buildCurtain($countdown);
$subheader = $this->buildSubheaderView($countdown);
$timeline = $this->buildTransactionTimeline($countdown, new PhabricatorCountdownTransactionQuery());
$comment_view = id(new PhabricatorCountdownEditEngine())->setViewer($viewer)->buildEditEngineCommentView($countdown);
$content = array($countdown_view, $timeline, $comment_view);
$view = id(new PHUITwoColumnView())->setHeader($header)->setSubheader($subheader)->setCurtain($curtain)->setMainColumn($content);
return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->setPageObjectPHIDs(array($countdown->getPHID()))->appendChild($view);
}
示例8: revokeToken
public function revokeToken()
{
if ($this->isRevocable()) {
$this->setTokenExpires(PhabricatorTime::getNow() - 1)->save();
}
return $this;
}
示例9: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$viewer = $this->getViewer();
$since = PhabricatorTime::getNow() - phutil_units('30 days in seconds');
$until = PhabricatorTime::getNow();
$mails = id(new PhabricatorMetaMTAMailQuery())->setViewer($viewer)->withDateCreatedBetween($since, $until)->execute();
$unfiltered = array();
foreach ($mails as $mail) {
$unfiltered_actors = mpull($mail->loadAllActors(), 'getPHID');
foreach ($unfiltered_actors as $phid) {
if (empty($unfiltered[$phid])) {
$unfiltered[$phid] = 0;
}
$unfiltered[$phid]++;
}
}
arsort($unfiltered);
$table = id(new PhutilConsoleTable())->setBorders(true)->addColumn('user', array('title' => pht('User')))->addColumn('unfiltered', array('title' => pht('Unfiltered')));
$handles = $viewer->loadHandles(array_keys($unfiltered));
$names = mpull(iterator_to_array($handles), 'getName', 'getPHID');
foreach ($unfiltered as $phid => $count) {
$table->addRow(array('user' => idx($names, $phid), 'unfiltered' => $count));
}
$table->draw();
echo "\n";
echo pht('Mail sent in the last 30 days.') . "\n";
echo pht('"Unfiltered" is raw volume before preferences were applied.') . "\n";
echo "\n";
return 0;
}
示例10: updateLease
private function updateLease(DrydockLease $lease)
{
if ($lease->getStatus() != DrydockLeaseStatus::STATUS_ACTIVE) {
return;
}
$viewer = $this->getViewer();
$drydock_phid = id(new PhabricatorDrydockApplication())->getPHID();
// Check if the lease has expired. If it is, we're going to send it a
// release command. This command will be handled immediately below, it
// just generates a command log and improves consistency.
$now = PhabricatorTime::getNow();
$expires = $lease->getUntil();
if ($expires && $expires <= $now) {
$command = DrydockCommand::initializeNewCommand($viewer)->setTargetPHID($lease->getPHID())->setAuthorPHID($drydock_phid)->setCommand(DrydockCommand::COMMAND_RELEASE)->save();
}
$commands = $this->loadCommands($lease->getPHID());
foreach ($commands as $command) {
if ($lease->getStatus() != DrydockLeaseStatus::STATUS_ACTIVE) {
// Leases can't receive commands before they activate or after they
// release.
break;
}
$this->processCommand($lease, $command);
$command->setIsConsumed(true)->save();
}
// If this is the task which will eventually release the lease after it
// expires but it is still active, reschedule the task to run after the
// lease expires. This can happen if the lease's expiration was pushed
// forward.
if ($lease->getStatus() == DrydockLeaseStatus::STATUS_ACTIVE) {
if ($this->getTaskDataValue('isExpireTask') && $expires) {
throw new PhabricatorWorkerYieldException($expires - $now);
}
}
}
示例11: buildWhereClause
protected function buildWhereClause(AphrontDatabaseConnection $conn_r)
{
$where = array();
if ($this->ids !== null) {
$where[] = qsprintf($conn_r, 'id IN (%Ld)', $this->ids);
}
if ($this->objectPHIDs !== null) {
$where[] = qsprintf($conn_r, 'objectPHID IN (%Ls)', $this->objectPHIDs);
}
if ($this->tokens !== null) {
$where[] = qsprintf($conn_r, 'token IN (%Ls)', $this->tokens);
}
if ($this->tokenTypes !== null) {
$where[] = qsprintf($conn_r, 'tokenType IN (%Ls)', $this->tokenTypes);
}
if ($this->expired !== null) {
if ($this->expired) {
$where[] = qsprintf($conn_r, 'expires <= %d', PhabricatorTime::getNow());
} else {
$where[] = qsprintf($conn_r, 'expires IS NULL OR expires > %d', PhabricatorTime::getNow());
}
}
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
}
示例12: testParseLocalTime
public function testParseLocalTime()
{
$u = new PhabricatorUser();
$u->setTimezoneIdentifier('UTC');
$v = new PhabricatorUser();
$v->setTimezoneIdentifier('America/Los_Angeles');
$t = 1370202281;
// 2013-06-02 12:44:41 -0700
$time = PhabricatorTime::pushTime($t, 'America/Los_Angeles');
$this->assertEqual($t, PhabricatorTime::parseLocalTime('now', $u));
$this->assertEqual($t, PhabricatorTime::parseLocalTime('now', $v));
$this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 -0700', $u));
$this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 -0700', $v));
$this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 PDT', $u));
$this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 PDT', $v));
$this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 19:44:41', $u));
$this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 12:44:41', $v));
$this->assertEqual($t + 3600, PhabricatorTime::parseLocalTime('+1 hour', $u));
$this->assertEqual($t + 3600, PhabricatorTime::parseLocalTime('+1 hour', $v));
unset($time);
$t = 1370239200;
// 2013-06-02 23:00:00 -0700
$time = PhabricatorTime::pushTime($t, 'America/Los_Angeles');
// For the UTC user, midnight was 6 hours ago because it's early in the
// morning for htem. For the PDT user, midnight was 23 hours ago.
$this->assertEqual($t + -6 * 3600 + 60, PhabricatorTime::parseLocalTime('12:01:00 AM', $u));
$this->assertEqual($t + -23 * 3600 + 60, PhabricatorTime::parseLocalTime('12:01:00 AM', $v));
unset($time);
}
示例13: buildAbstractDocument
protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
{
$revision = id(new DifferentialRevisionQuery())->setViewer($this->getViewer())->withPHIDs(array($object->getPHID()))->needReviewerStatus(true)->executeOne();
// TODO: This isn't very clean, but custom fields currently rely on it.
$object->attachReviewerStatus($revision->getReviewerStatus());
$document->setDocumentTitle($revision->getTitle());
$document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $revision->getAuthorPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $revision->getDateCreated());
$document->addRelationship($revision->isClosed() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $revision->getPHID(), DifferentialRevisionPHIDType::TYPECONST, PhabricatorTime::getNow());
// If a revision needs review, the owners are the reviewers. Otherwise, the
// owner is the author (e.g., accepted, rejected, closed).
$status_review = ArcanistDifferentialRevisionStatus::NEEDS_REVIEW;
if ($revision->getStatus() == $status_review) {
$reviewers = $revision->getReviewerStatus();
$reviewers = mpull($reviewers, 'getReviewerPHID', 'getReviewerPHID');
if ($reviewers) {
foreach ($reviewers as $phid) {
$document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $phid, PhabricatorPeopleUserPHIDType::TYPECONST, $revision->getDateModified());
// Bogus timestamp.
}
} else {
$document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_UNOWNED, $revision->getPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $revision->getDateModified());
// Bogus timestamp.
}
} else {
$document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $revision->getAuthorPHID(), PhabricatorPHIDConstants::PHID_TYPE_VOID, $revision->getDateCreated());
}
}
示例14: buildAbstractDocument
protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
{
$credential = $object;
$document->setDocumentTitle($credential->getName());
$document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $credential->getDescription());
$document->addRelationship($credential->getIsDestroyed() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $credential->getPHID(), PassphraseCredentialPHIDType::TYPECONST, PhabricatorTime::getNow());
}
示例15: buildAbstractDocument
protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
{
$blog = $object;
$document->setDocumentTitle($blog->getName());
$document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $blog->getDescription());
$document->addRelationship($blog->isArchived() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $blog->getPHID(), PhabricatorPhameBlogPHIDType::TYPECONST, PhabricatorTime::getNow());
}