|
1
|
|
|
<?php |
|
2
|
|
|
/************************************************************************ |
|
3
|
|
|
* OVIDENTIA http://www.ovidentia.org * |
|
4
|
|
|
************************************************************************ |
|
5
|
|
|
* Copyright (c) 2003 by CANTICO ( http://www.cantico.fr ) * |
|
6
|
|
|
* * |
|
7
|
|
|
* This file is part of Ovidentia. * |
|
8
|
|
|
* * |
|
9
|
|
|
* Ovidentia is free software; you can redistribute it and/or modify * |
|
10
|
|
|
* it under the terms of the GNU General Public License as published by * |
|
11
|
|
|
* the Free Software Foundation; either version 2, or (at your option) * |
|
12
|
|
|
* any later version. * |
|
13
|
|
|
* * |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, but * |
|
15
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of * |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
|
17
|
|
|
* See the GNU General Public License for more details. * |
|
18
|
|
|
* * |
|
19
|
|
|
* You should have received a copy of the GNU General Public License * |
|
20
|
|
|
* along with this program; if not, write to the Free Software * |
|
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,* |
|
22
|
|
|
* USA. * |
|
23
|
|
|
************************************************************************/ |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* |
|
28
|
|
|
*/ |
|
29
|
|
|
class absences_HalfDay |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* First working period start |
|
33
|
|
|
* @var BAB_DateTime |
|
34
|
|
|
*/ |
|
35
|
|
|
public $dtstart; |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Last working period end |
|
40
|
|
|
* @var BAB_DateTime |
|
41
|
|
|
*/ |
|
42
|
|
|
public $dtend; |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* working periods durations sum |
|
47
|
|
|
* @var int seconds |
|
48
|
|
|
*/ |
|
49
|
|
|
public $duration = 0; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* |
|
53
|
|
|
* @var string AM | PM |
|
54
|
|
|
*/ |
|
55
|
|
|
public $type; |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Extract a end date using start date and a number of days lower than 0,5 |
|
60
|
|
|
* @param float $days |
|
61
|
|
|
* @throws Exception |
|
62
|
|
|
* @return BAB_DateTime |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getEndDateFromQuantity($days) |
|
65
|
|
|
{ |
|
66
|
|
|
if ($days > 0.5) { |
|
67
|
|
|
throw new Exception('More than 0.5 days on a half day is not possible'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if ($days == 0.5) { |
|
71
|
|
|
return $this->dtend; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if ($days <= 0) { |
|
75
|
|
|
return $this->dtstart; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$consumed = $this->duration *$days *2; |
|
79
|
|
|
$endDate = clone $this->dtstart; |
|
80
|
|
|
|
|
81
|
|
|
//var_dump($endDate->getIsoDateTime().' + '.($consumed/3600).'H'); |
|
82
|
|
|
|
|
83
|
|
|
$endDate->add($consumed, BAB_DATETIME_SECOND); |
|
84
|
|
|
|
|
85
|
|
|
return $endDate; |
|
86
|
|
|
} |
|
87
|
|
|
} |