本文整理汇总了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;
}