本文整理汇总了PHP中Nette\Utils\DateTime::diff方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTime::diff方法的具体用法?PHP DateTime::diff怎么用?PHP DateTime::diff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\DateTime
的用法示例。
在下文中一共展示了DateTime::diff方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSpecificDays
/**
*
* @param integer $nextDays
* @return array
*/
public function getSpecificDays($nextDays = 30, $previousDays = 0)
{
$now = new \DateTime();
return array_filter($this->specificDays, function ($val, $key) use($now, $nextDays, $previousDays) {
$time = new \DateTime($key);
$diff = (int) $now->diff($time)->format('%r%a');
return $diff >= $previousDays * -1 && $diff <= $nextDays;
}, ARRAY_FILTER_USE_BOTH);
}
示例2: renderEmail
public function renderEmail()
{
$person = $this->userManager->get($this->user->getId());
$this->template->person = $person;
$now = new DateTime();
$diff = $now->diff($person->change_email_requested);
if ($diff->h < 1 && $diff->days == 0) {
$this->template->openStepTwo = TRUE;
}
}
示例3: validityCheck
public function validityCheck($form)
{
$values = $form->getValues();
if ($values->password != $values->password2) {
$form->addError('Obě varianty hesla musí být stejné.');
}
$bdate = new \Nette\Utils\DateTime($values->birthdate);
$diff = $bdate->diff(new \Nette\Utils\DateTime());
$diff = $diff->format('%d');
if ($diff < 7) {
$form->addError('Uživatelé by měli být starší než jeden týden. ' . $diff . ' dní je příliš málo.');
}
$data = $this->model->getSelection()->where(array("email" => $values->email))->fetch();
if ($data) {
$form->addError('Email ' . $values->email . ' je již používán.');
}
}
示例4: processDownloadRequestCreation
/**
* process wigle request and determine what to do
* returns status code
*
* @param Coords $coords
* @param int $idSource
* @return bool|string
*/
public function processDownloadRequestCreation($coords, $idSource)
{
$coords = new Coords(round($coords->getLatStart() - 0.005, 2), round($coords->getLatEnd() + 0.005, 2), round($coords->getLonStart() - 0.005, 2), round($coords->getLonEnd() + 0.005, 2));
$existingRequest = $this->getRequestAlreadyExistingInLatLngRange($coords, $idSource);
if ($existingRequest) {
// nalezeno
$er = $existingRequest->toArray();
// pokud processed = N pak je ve fronte a neni stazeno
if ($er["processed"] == "N") {
return self::STATE_ERR_ALREADY_IN_QUEUE;
} else {
$today = new DateTime();
$diff = $today->diff($er["processed_date"]);
if ($diff->days < self::MIN_DAYS_BEFORE_UPDATE_AREA) {
return self::STATE_ERR_RECENTLY_DOWNLOADED;
} else {
return $this->addAllNotDownloadedRequests($coords, $idSource);
}
}
} else {
return $this->addAllNotDownloadedRequests($coords, $idSource);
}
}
示例5: isTokenValid
/**
* @param string $token
* @param int $expirationTime
* @return bool
*/
public function isTokenValid($token, $expirationTime = 10)
{
try {
$user = $this->read()->where("recoveryToken", $token)->limit(1)->fetch();
if ($user) {
$current = new DateTime();
$diff = $current->diff(new DateTime($user->getRecoveryTokenInserted()));
if ($diff->format("%h") == 0 && $diff->format("%i") <= $expirationTime) {
return true;
} else {
return false;
}
} else {
return false;
}
} catch (\PDOException $e) {
return false;
}
}
示例6: changeEmailStepTwo
/**
* @param $id int
* @param $tokenOne string
* @param $tokenTwo string
*/
public function changeEmailStepTwo($id, $tokenOne, $tokenTwo)
{
$person = $this->get($id);
$now = new DateTime();
$diff = $now->diff($person->change_email_requested);
if ($diff->h >= 1) {
// todo throw exception
return FALSE;
}
$verified = FALSE;
if (Passwords::verify($tokenOne, $person->change_email_tokenOne)) {
if (Passwords::verify($tokenTwo, $person->change_email_tokenTwo)) {
$verified = TRUE;
}
} else {
// swithed codes?
if (Passwords::verify($tokenOne, $person->change_email_tokenTwo)) {
if (Passwords::verify($tokenTwo, $person->change_email_tokenOne)) {
$verified = TRUE;
}
}
}
if (!$verified) {
// todo throw excaption
return FALSE;
}
$newEmail = $person->change_email;
$data = array('email' => $newEmail, 'change_email' => '', 'change_email_tokenOne' => '', 'change_email_tokenTwo' => '', 'change_email_requested' => '');
$this->get($id)->update($data);
return $newEmail;
}