Completed
Push — master ( 392b53...baab95 )
by Artem
01:29
created

DateRange::assertSameTimezones()   A

Complexity

Conditions 2
Paths 2

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 2
nc 2
nop 0
1
<?php
2
/*
3
 * This file is part of the DateTime library.
4
 *
5
 * (c) Artem Henvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Fresh\DateTime;
14
15
use Fresh\DateTime\Exception\LogicException;
16
17
/**
18
 * DateRange.
19
 *
20
 * @author Artem Henvald <[email protected]>
21
 */
22
class DateRange
23
{
24
    /** @var \DateTimeInterface */
25
    private $since;
26
27
    /** @var \DateTimeInterface */
28
    private $till;
29
30
    /**
31
     * @param \DateTimeInterface $since
32
     * @param \DateTimeInterface $till
33
     */
34
    public function __construct(\DateTimeInterface $since, \DateTimeInterface $till)
35
    {
36
        $this->since = $since;
37
        $this->till = $till;
38
    }
39
40
    /**
41
     * @return \DateTimeInterface
42
     */
43
    public function getSince(): \DateTimeInterface
44
    {
45
        return $this->since;
46
    }
47
48
    /**
49
     * @param \DateTimeInterface $since
50
     *
51
     * @return $this
52
     */
53
    public function setSince(\DateTimeInterface $since): self
54
    {
55
        $this->since = $since;
56
57
        return $this;
58
    }
59
60
    /**
61
     * @return \DateTimeInterface
62
     */
63
    public function getTill(): \DateTimeInterface
64
    {
65
        return $this->till;
66
    }
67
68
    /**
69
     * @param \DateTimeInterface $till
70
     *
71
     * @return $this
72
     */
73
    public function setTill(\DateTimeInterface $till): self
74
    {
75
        $this->till = $till;
76
77
        return $this;
78
    }
79
80
    /**
81
     * @throws LogicException
82
     */
83
    public function assertSameTimezones(): void
84
    {
85
        if ($this->since->getTimezone()->getName() !== $this->till->getTimezone()->getName()) {
86
            throw new LogicException('Date range has different timezones');
87
        }
88
    }
89
}
90