Day::isValid()   A
last analyzed

Complexity

Conditions 1
Paths 1

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 1
nc 1
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\Period;
13
14
/**
15
 * Represents a Day.
16
 *
17
 * @author Yohan Giarelli <[email protected]>
18
 */
19
class Day extends PeriodAbstract implements \Iterator
20
{
21
    const MONDAY = 1;
22
    const TUESDAY = 2;
23
    const WEDNESDAY = 3;
24
    const THURSDAY = 4;
25
    const FRIDAY = 5;
26
    const SATURDAY = 6;
27
    const SUNDAY = 0;
28
29
    /**
30
     * @var PeriodInterface
31
     */
32
    private $current;
33
34
    /**
35
     * Returns the period as a DatePeriod.
36
     *
37
     * @return \DatePeriod
38
     */
39
    public function getDatePeriod()
40
    {
41
        return new \DatePeriod($this->begin, new \DateInterval('P1D'), $this->end);
42
    }
43
44
    /**
45
     * Returns the day name (probably in english).
46
     *
47
     * @return string
48
     */
49
    public function __toString()
50
    {
51
        return $this->format('l');
52
    }
53
54
    /**
55
     * @param \DateTime $start
56
     *
57
     * @return bool
58
     */
59
    public static function isValid(\DateTime $start)
60
    {
61
        return $start->format('H:i:s') == '00:00:00';
62
    }
63
64
    /**
65
     * Returns a \DateInterval equivalent to the period.
66
     *
67
     * @static
68
     *
69
     * @return \DateInterval
70
     */
71
    public static function getDateInterval()
72
    {
73
        return new \DateInterval('P1D');
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function current()
80
    {
81
        return $this->current;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function next()
88
    {
89
        if (null === $this->current) {
90
            $this->current = $this->getFactory()->createHour($this->begin);
91
        } else {
92
            $this->current = $this->current->getNext();
93
            if (!$this->contains($this->current->getBegin())) {
94
                $this->current = null;
95
            }
96
        }
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function key()
103
    {
104
        return (int) $this->current->getBegin()->format('G');
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    public function valid()
111
    {
112
        return null !== $this->current;
113
    }
114
115
    /**
116
     * {@inheritdoc}
117
     */
118
    public function rewind()
119
    {
120
        $this->current = null;
121
        $this->next();
122
    }
123
}
124