| 1 | <?php |
||
| 9 | class Pause |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var \DateTime |
||
| 13 | */ |
||
| 14 | private $start; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var \DateTime |
||
| 18 | */ |
||
| 19 | private $end; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Pause constructor. |
||
| 23 | * @param \DateTime $start |
||
| 24 | * @param \DateTime $end |
||
| 25 | */ |
||
| 26 | 24 | public function __construct(\DateTime $start, \DateTime $end) |
|
| 27 | { |
||
| 28 | 24 | if ($start > $end) { |
|
| 29 | 3 | throw new \InvalidArgumentException("Pause can't start after ending"); |
|
| 30 | } |
||
| 31 | |||
| 32 | 21 | if ($start->format('Y-m-d') !== $end->format('Y-m-d')) { |
|
| 33 | 3 | throw new \InvalidArgumentException("Pause must end in the same day"); |
|
| 34 | } |
||
| 35 | |||
| 36 | 18 | $this->start = $start; |
|
| 37 | 18 | $this->end = $end; |
|
| 38 | 18 | } |
|
| 39 | |||
| 40 | /** |
||
| 41 | * @return \DateTime |
||
| 42 | */ |
||
| 43 | 63 | public function getStart() |
|
| 47 | |||
| 48 | /** |
||
| 49 | * @return \DateTime |
||
| 50 | */ |
||
| 51 | 60 | public function getEnd() |
|
| 55 | |||
| 56 | /** |
||
| 57 | * @return \DateInterval |
||
| 58 | */ |
||
| 59 | 12 | public function getDuration() |
|
| 63 | |||
| 64 | /** |
||
| 65 | * @param Pause $pause |
||
| 66 | * @return bool |
||
| 67 | */ |
||
| 68 | 27 | public function isOverlapping(Pause $pause) |
|
| 69 | { |
||
| 70 | 27 | if ($this->getEnd() <= $pause->getStart()) { |
|
| 71 | 6 | return false; |
|
| 72 | } |
||
| 73 | |||
| 74 | 27 | if ($this->getStart() >= $pause->getEnd()) { |
|
| 75 | 18 | return false; |
|
| 76 | } |
||
| 77 | |||
| 78 | 9 | return true; |
|
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | 12 | public function exportBlock() |
|
| 88 | } |
||
| 89 |