本文整理汇总了PHP中Nette\DateTime::diff方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTime::diff方法的具体用法?PHP DateTime::diff怎么用?PHP DateTime::diff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\DateTime
的用法示例。
在下文中一共展示了DateTime::diff方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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\DateTime($values->birthdate);
$diff = $bdate->diff(new \Nette\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.');
}
}
示例2: verifyToken
/**
* verify token in database and delete it
*
* @param $token
* @param int $userId
* @return bool
*/
public function verifyToken($token, $userId)
{
$request = $this->database->table('users_password_reset')->where('userId', $userId)->fetch();
$now = new Nette\DateTime();
if ($request) {
$dateDiff = $now->diff($request->created);
$totalHours = $dateDiff->d * 24 + $dateDiff->h;
// remove token older than 2h
if ($totalHours > 2) {
$this->database->table('users_password_reset')->where('userId', $userId)->delete();
return FALSE;
}
}
if ($request && $request->id > 0) {
if ($request->token == SELF::calculateHash($token, $request->salt)) {
$this->database->table('users_password_reset')->where('userId', $userId)->delete();
return TRUE;
}
}
return FALSE;
}