1 | <?php |
||
18 | class DateRange implements JsonSerializable |
||
19 | { |
||
20 | /** |
||
21 | * start date |
||
22 | * |
||
23 | * @ORM\Column(type="datetime", nullable=true) |
||
24 | * |
||
25 | * @var \DateTime |
||
26 | */ |
||
27 | private $dateFrom; |
||
28 | |||
29 | /** |
||
30 | * end date |
||
31 | * |
||
32 | * @ORM\Column(type="datetime", nullable=true) |
||
33 | * |
||
34 | * @var \DateTime |
||
35 | */ |
||
36 | private $dateTo; |
||
37 | |||
38 | /** |
||
39 | * Constructor |
||
40 | * |
||
41 | * @param \DateTime $start |
||
42 | * @param \DateTime $end |
||
43 | */ |
||
44 | 5 | public function __construct(\DateTime $start = null, \DateTime $end = null) |
|
55 | |||
56 | /** |
||
57 | * Gets the start date. |
||
58 | * |
||
59 | * @return \DateTime |
||
60 | */ |
||
61 | 1 | public function getDateFrom() |
|
65 | |||
66 | /** |
||
67 | * Gets the end date. |
||
68 | * |
||
69 | * @return \DateTime |
||
70 | */ |
||
71 | 1 | public function getDateTo() |
|
75 | |||
76 | /** |
||
77 | * Formats date range to string using given $format |
||
78 | * |
||
79 | * @param string $f Any format accepted by php date() |
||
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | 2 | public function format($f = 'c') |
|
91 | |||
92 | /** |
||
93 | * String representation of date range. |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | 2 | public function __toString() |
|
101 | |||
102 | /** |
||
103 | * Returns duration of the date range in seconds. |
||
104 | * |
||
105 | * @return int |
||
106 | */ |
||
107 | 3 | public function getDurationInSeconds() |
|
122 | |||
123 | /** |
||
124 | * Array representation of the range |
||
125 | * |
||
126 | * @return array |
||
127 | */ |
||
128 | 2 | public function toArray($format = 'c') |
|
139 | |||
140 | /** |
||
141 | * Implement json serializable interface. |
||
142 | * |
||
143 | * @return array |
||
144 | */ |
||
145 | 1 | public function jsonSerialize() |
|
149 | |||
150 | /** |
||
151 | * Returns a boolean TRUE if the range instance is |
||
152 | * literally empty, FALSE otherwise. |
||
153 | * |
||
154 | * @return boolean |
||
155 | */ |
||
156 | 2 | public function isEmpty() |
|
160 | } |
||
161 |