1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright Enalean (c) 2011 - 2015. All rights reserved. |
4
|
|
|
* |
5
|
|
|
* Tuleap and Enalean names and logos are registrated trademarks owned by |
6
|
|
|
* Enalean SAS. All other trademarks or names are properties of their respective |
7
|
|
|
* owners. |
8
|
|
|
* |
9
|
|
|
* This file is a part of Tuleap. |
10
|
|
|
* |
11
|
|
|
* Tuleap is free software; you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU General Public License as published by |
13
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
14
|
|
|
* (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* Tuleap is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU General Public License |
22
|
|
|
* along with Tuleap. If not, see <http://www.gnu.org/licenses/>. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* A time period that has a start date and a duration |
27
|
|
|
*/ |
28
|
|
|
abstract class TimePeriod { |
29
|
|
|
/** |
30
|
|
|
* @var int The time period start date, as a Unix timestamp. |
31
|
|
|
*/ |
32
|
|
|
private $start_date; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var int The time period duration, in days. |
36
|
|
|
*/ |
37
|
|
|
private $duration; |
38
|
|
|
|
39
|
|
|
public function __construct($start_date, $duration) { |
40
|
|
|
$this->start_date = $start_date; |
41
|
|
|
$this->duration = $duration; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return int |
46
|
|
|
*/ |
47
|
|
|
public function getStartDate() { |
48
|
|
|
return $this->start_date; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return int |
53
|
|
|
*/ |
54
|
|
|
public function getDuration() { |
55
|
|
|
return $this->duration; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return int |
60
|
|
|
*/ |
61
|
|
|
public function getEndDate() { |
62
|
|
|
$last_offset = end($this->getDayOffsets()); |
|
|
|
|
63
|
|
|
return strtotime("+$last_offset days", $this->getStartDate()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return array of string |
68
|
|
|
*/ |
69
|
|
|
public function getHumanReadableDates() { |
70
|
|
|
$dates = array(); |
71
|
|
|
|
72
|
|
|
foreach($this->getDayOffsets() as $day_offset) { |
73
|
|
|
$day = strtotime("+$day_offset days", $this->getStartDate()); |
74
|
|
|
$dates[] = date('D d', $day); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $dates; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* To be used to iterate consistently over the time period |
82
|
|
|
* |
83
|
|
|
* @return array of int |
84
|
|
|
*/ |
85
|
|
|
public abstract function getDayOffsets(); |
86
|
|
|
} |
87
|
|
|
|