This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from lucas0headshot/dev
fix: issue #5
- Loading branch information
Showing
3 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Rules; | ||
|
||
use Closure; | ||
use Illuminate\Contracts\Validation\ValidationRule; | ||
|
||
class ValidInterval implements ValidationRule | ||
{ | ||
private $hora_inicio; | ||
private $hora_fim; | ||
|
||
|
||
public function __construct(string $hora_inicio, string $hora_fim) | ||
{ | ||
$this->hora_inicio = $hora_inicio; | ||
$this->hora_fim = $hora_fim; | ||
} | ||
|
||
|
||
/** | ||
* Run the validation rule. | ||
* | ||
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail | ||
*/ | ||
public function validate(string $attribute, mixed $value, Closure $fail): void | ||
{ | ||
$hora_inicio = strtotime($this->hora_inicio); | ||
$hora_fim = strtotime($this->hora_fim); | ||
$intervalo = strtotime($value) - strtotime('TODAY'); | ||
|
||
if (($hora_fim - $hora_inicio) <= $intervalo) { | ||
$fail('O intervalo não pode ser maior ou igual ao período entre a hora de início e hora de fim.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters