So i have an Laravel Application in which we check if time has passed by comparing current time in user timezone against time expired datetime stored in database of course in same timezone. So this is my code.
Test code
$staff = Staff::find(1);
$carbon = Carbon::now($staff->user->timezone);
$carbon->subHour(1);
$staff->status_exp = $carbon->toDateTimeString();
$processor = new Processor($staff);
$status = $processor->isExpired();
$this->assertTrue($status);
Application Code. Class has property name staff which is used below.
public function isExpired()
{
$now = Carbon::now($this->staff->user->timezone);
if($now->greaterThan(Carbon::parse($this->staff->status_exp)))
{
return true;
}
return false;
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire