本文整理匯總了PHP中Nette\Utils\DateTime::add方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateTime::add方法的具體用法?PHP DateTime::add怎麽用?PHP DateTime::add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nette\Utils\DateTime
的用法示例。
在下文中一共展示了DateTime::add方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setLastAndNextRun
/**
* Calculate and set last and next run
*/
public function setLastAndNextRun()
{
// set lastRun, lastSuccess
$this->lastRun = new DateTime();
$this->nextRun = null;
// find nextTime to run
foreach ($this->conditions as $condition) {
$nextRun = $condition->getNextRunTime($this->lastRun);
// if nextRun less than lastRun set lastRun + 1min
if ($nextRun < $this->lastRun) {
$nextRun = $this->lastRun->add(new \DateInterval("PT1M"));
}
if ($this->nextRun) {
$this->nextRun = $this->nextRun > $nextRun ? $nextRun : $this->nextRun;
} else {
$this->nextRun = $nextRun;
}
}
}
示例2: resetPasswordToken
/**
* Generate token for change password.
*
* @param string $email
*
* @return string|false
*/
public function resetPasswordToken($email)
{
$user = $this->userRepository->findOneBy(["email" => $email]);
// userExist?
if ($user) {
$tokenExpires = new DateTime();
$tokenExpires->add(new \DateInterval('PT60M'));
// 60 min for expire
$token = $this->userRepository->resetPasswordToken($user, $tokenExpires);
return $token ? $token : false;
} else {
return false;
}
}
示例3: setStateRunning
/**
* Lock table for read only and set task state to running (State = 1)
*
* @param Task $task
*
* @return bool
*/
public function setStateRunning(Task $task)
{
$table = $this->getTable();
if ($task->maxExecutionTimeInSecond) {
$exceedDateTime = new Nette\Utils\DateTime();
$task->exceedDateTime = $exceedDateTime->add(new \DateInterval("PT" . $task->maxExecutionTimeInSecond . "S"));
}
$cnt = $table->where("TaskID", $task->id)->where("State", $task->state)->update(["State" => 1, "ExceedDateTime" => $task->exceedDateTime]);
if ($cnt > 0) {
$task->state = 1;
}
return $cnt > 0;
}