AbstractEvent::contains()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of CalendR, a Fréquence web project.
5
 *
6
 * (c) 2012 Fréquence web
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CalendR\Event;
13
14
use CalendR\Period\PeriodInterface;
15
16
/**
17
 * Abstract class that ease event manipulation.
18
 *
19
 * @author Yohan Giareli <[email protected]>
20
 */
21
abstract class AbstractEvent implements EventInterface
22
{
23
    /**
24
     * Check if the given date is during the event.
25
     *
26
     * @param \DateTime $datetime
27
     *
28
     * @return bool true if $datetime is during the event, false otherwise
29
     */
30
    public function contains(\DateTime $datetime)
31
    {
32
        return $this->getBegin() <= $datetime && $datetime < $this->getEnd();
33
    }
34
35
    /**
36
     * Check if the given period is during the event.
37
     *
38
     * @param PeriodInterface $period
39
     *
40
     * @return bool true if $period is during the event, false otherwise
41
     */
42
    public function containsPeriod(PeriodInterface $period)
43
    {
44
        return $this->contains($period->getBegin()) && $this->contains($period->getEnd());
45
    }
46
47
    /**
48
     * Check if the event is during the given period.
49
     *
50
     * @param PeriodInterface $period
51
     *
52
     * @return bool true if the event is during $period, false otherwise
53
     */
54
    public function isDuring(PeriodInterface $period)
55
    {
56
        return $this->getBegin() >= $period->getBegin() && $this->getEnd() < $period->getEnd();
57
    }
58
}
59