1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been added to CalendR, a Fréquence web project. |
5
|
|
|
* |
6
|
|
|
* (c) 2012 Ingewikkeld/Stefan Koopmanschap |
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 Range. |
16
|
|
|
* |
17
|
|
|
* @author Stefan Koopmanschap <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class Range extends PeriodAbstract |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @param \DateTime $begin |
23
|
|
|
* @param \DateTime $end |
24
|
|
|
* @param FactoryInterface $factory |
|
|
|
|
25
|
|
|
*/ |
26
|
|
|
public function __construct(\DateTime $begin, \DateTime $end, $factory = null) |
27
|
|
|
{ |
28
|
|
|
$this->factory = $factory; |
29
|
|
|
$this->begin = clone $begin; |
30
|
|
|
$this->end = clone $end; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param \DateTime $start |
35
|
|
|
* |
36
|
|
|
* @return bool |
37
|
|
|
*/ |
38
|
|
|
public static function isValid(\DateTime $start) |
39
|
|
|
{ |
40
|
|
|
return true; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return Day |
|
|
|
|
45
|
|
|
*/ |
46
|
|
|
public function getNext() |
47
|
|
|
{ |
48
|
|
|
$diff = $this->begin->diff($this->end); |
49
|
|
|
$begin = clone $this->begin; |
50
|
|
|
$begin->add($diff); |
51
|
|
|
$end = clone $this->end; |
52
|
|
|
$end->add($diff); |
53
|
|
|
|
54
|
|
|
return new self($begin, $end, $this->factory); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return Day |
|
|
|
|
59
|
|
|
*/ |
60
|
|
|
public function getPrevious() |
61
|
|
|
{ |
62
|
|
|
$diff = $this->begin->diff($this->end); |
63
|
|
|
$begin = clone $this->begin; |
64
|
|
|
$begin->sub($diff); |
65
|
|
|
$end = clone $this->end; |
66
|
|
|
$end->sub($diff); |
67
|
|
|
|
68
|
|
|
return new self($begin, $end, $this->factory); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Returns the period as a DatePeriod. |
73
|
|
|
* |
74
|
|
|
* @return \DatePeriod |
75
|
|
|
*/ |
76
|
|
|
public function getDatePeriod() |
77
|
|
|
{ |
78
|
|
|
return new \DatePeriod($this->begin, $this->begin->diff($this->end), $this->end); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Returns a \DateInterval equivalent to the period. |
83
|
|
|
* |
84
|
|
|
* @throws Exception\NotImplemented |
85
|
|
|
*/ |
86
|
|
|
public static function getDateInterval() |
87
|
|
|
{ |
88
|
|
|
throw new Exception\NotImplemented('Range period doesn\'t support getDateInterval().'); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.