for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Spatie\Honeypot;
use DateTimeInterface;
use Illuminate\Support\Facades\Date;
class EncryptedTime
{
protected $carbon;
/** @var string */
protected $encryptedTime;
public static function create(DateTimeInterface $dateTime)
$encryptedTime = app('encrypter')->encrypt($dateTime->getTimestamp());
return new static($encryptedTime);
}
public function __construct(string $encryptedTime)
$this->encryptedTime = $encryptedTime;
$timestamp = app('encrypter')->decrypt($encryptedTime);
if (! $this->isValidTimeStamp($timestamp)) {
throw new \Exception(sprintf('Timestamp %s is invalid', $timestamp));
$this->carbon = Date::createFromTimestamp($timestamp);
public function isFuture(): bool
return $this->carbon->isFuture();
public function __toString()
return $this->encryptedTime;
private function isValidTimeStamp(string $timestamp)
return ((string) (int) $timestamp === $timestamp)
&& ($timestamp >= 0)
&& ($timestamp <= PHP_INT_MAX);