Completed
Pull Request — master (#5)
by Brent
12:47
created

DateBetween::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Spatie\ValidationRules\Rules;
4
5
use Carbon\Carbon;
6
use Illuminate\Contracts\Validation\Rule;
7
8
class DateBetween implements Rule
9
{
10
    /** @var \Carbon\Carbon */
11
    protected $start;
12
13
    /** @var \Carbon\Carbon */
14
    protected $end;
15
16
    /** @var bool */
17
    protected $orEquals = false;
18
19
    public function __construct(Carbon $start, Carbon $end)
20
    {
21
        $this->start = $start->copy();
22
23
        $this->end = $end->copy();
24
    }
25
26
    public function orEquals(bool $orEquals = true): DateBetween
27
    {
28
        $this->orEquals = $orEquals;
29
30
        return $this;
31
    }
32
33
    public function withoutTime(): DateBetween
34
    {
35
        $this->start->startOfDay();
36
37
        $this->end->endOfDay();
38
39
        return $this;
40
    }
41
42
    public function passes($attribute, $value)
43
    {
44
        $date = Carbon::make($value);
45
46
        return $date->between($this->start, $this->end, $this->orEquals);
47
    }
48
49
    public function message()
50
    {
51
        return __('validationRules.date_between');
52
    }
53
}
54