/** * Validator. * * @access public * @param string $input Input value * @param int $age Minimal age value * @param string $format (optional) Date format * @return boolean */ public function validate($input, $age, $format = 'Y-m-d') { if (($input = Time::createFromFormat($format, $input)) === false) { return false; } return $input->getTimestamp() == Time::now()->modify("-{$age} years")->getTimestamp(); }
/** * */ public function testNow() { $time = Time::now(); $this->assertSame($time->format('Y-m-d H:i'), (new DateTime())->format('Y-m-d H:i')); // $time = Time::now('Asia/Tokyo'); $this->assertSame('Asia/Tokyo', $time->getTimeZone()->getName()); // $time = Time::now(new DateTimeZone('Asia/Tokyo')); $this->assertSame('Asia/Tokyo', $time->getTimeZone()->getName()); }
/** * {@inheritdoc} */ public function throttle(UserInterface $user, $maxLoginAttempts, $lockTime) { $now = Time::now(); // Reset the failed attempt count if the last failed attempt was more than $lockTime seconds ago if (($lastFailAt = $user->getLastFailAt()) !== null) { if ($now->getTimestamp() - $lastFailAt->getTimestamp() > $lockTime) { $user->resetFailedAttempts(); } } // Increment the failed attempt count and update the last fail time $user->incrementFailedAttempts(); $user->setLastFailAt($now); // Lock the account for $lockTime seconds if we have exeeded the maximum number of login attempts if ($user->getFailedAttempts() >= $maxLoginAttempts) { $user->lockUntil(Time::now()->forward($lockTime)); } // Save the changes to the user return $user->save(); }
/** * {@inheritdoc} */ public function isLocked() { return $this->locked_until !== null && $this->locked_until->getTimestamp() >= Time::now()->getTimestamp(); }