1 | <?php |
||
15 | class PeriodService implements PeriodServiceInterface |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * @var \JhFlexiTime\Options\ModuleOptions |
||
20 | */ |
||
21 | protected $options; |
||
22 | |||
23 | /** |
||
24 | * @param ModuleOptions $options |
||
25 | */ |
||
26 | public function __construct(ModuleOptions $options) |
||
30 | |||
31 | /** |
||
32 | * Get total hours in period, using config |
||
33 | * to determine how many hours to count in each day |
||
34 | * exclude weekends |
||
35 | * |
||
36 | * @param \DatePeriod $period |
||
37 | * @return int |
||
38 | */ |
||
39 | protected function getTotalHoursInPeriod(\DatePeriod $period) |
||
53 | |||
54 | /** |
||
55 | * @param DateTime $start |
||
56 | * @param DateTime $end |
||
57 | * |
||
58 | * @return int |
||
59 | */ |
||
60 | public function getTotalHoursBetweenDates(DateTime $start, DateTime $end) |
||
69 | |||
70 | /** |
||
71 | * Get total hours in a given month |
||
72 | * |
||
73 | * @param DateTime $month |
||
74 | * @return float |
||
75 | */ |
||
76 | public function getTotalHoursInMonth(DateTime $month) |
||
85 | |||
86 | /** |
||
87 | * Calculate the hours between to dates |
||
88 | * return something like 7.5, 8.25 |
||
89 | * |
||
90 | * Minus the lunch duration from the total, |
||
91 | * so only return total working hours |
||
92 | * |
||
93 | * @param DateTime $start |
||
94 | * @param DateTime $end |
||
95 | * @throws \InvalidArgumentException |
||
96 | * @return float hour diff |
||
97 | */ |
||
98 | public function calculateHourDiff(DateTime $start, DateTime $end) |
||
112 | |||
113 | /** |
||
114 | * Get the remaining hours in a month |
||
115 | * using the config as a base for how many hours |
||
116 | * should be worked per day |
||
117 | * |
||
118 | * @param DateTime $today |
||
119 | * @return int |
||
120 | */ |
||
121 | public function getRemainingHoursInMonth(DateTime $today) |
||
132 | |||
133 | /** |
||
134 | * Get an array of all the dates of the week the given date |
||
135 | * is in |
||
136 | * |
||
137 | * @param DateTime $date |
||
138 | * @return DateTime[] |
||
139 | * @throws \Exception |
||
140 | */ |
||
141 | public function getDaysInWeek(DateTime $date) |
||
156 | |||
157 | /** |
||
158 | * Get an array of the first and last day of |
||
159 | * the week the given day is in |
||
160 | * |
||
161 | * @param DateTime $date |
||
162 | * @return array |
||
163 | * @throws \Exception |
||
164 | */ |
||
165 | public function getFirstAndLastDayOfWeek(DateTime $date) |
||
174 | |||
175 | /** |
||
176 | * Get the week which this date is in, and count the number |
||
177 | * of non-working days |
||
178 | * |
||
179 | * @param DateTime $date |
||
180 | * @return int |
||
181 | */ |
||
182 | public function getNumWorkingDaysInWeek(DateTime $date) |
||
188 | |||
189 | /** |
||
190 | * Remove any non-working days |
||
191 | * |
||
192 | * @param DateTime[] $dates |
||
193 | * @return DateTime[] |
||
194 | */ |
||
195 | public function removeNonWorkingDays(array $dates) |
||
204 | |||
205 | /** |
||
206 | * Get an array of weeks, with each day of the week in it |
||
207 | * |
||
208 | * @param DateTime $date |
||
209 | * @return array |
||
210 | */ |
||
211 | public function getWeeksInMonth(DateTime $date) |
||
246 | |||
247 | /** |
||
248 | * @param DateTime $dateA |
||
249 | * @param DateTime $dateB |
||
250 | * @return bool |
||
251 | */ |
||
252 | public function isDateAfterDay(DateTime $dateA, DateTime $dateB) |
||
258 | } |
||
259 |