1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* TimeHelper Helpers pour les dates de l'application GLSR. |
4
|
|
|
* |
5
|
|
|
* PHP Version 5 |
6
|
|
|
* |
7
|
|
|
* @author Quétier Laurent <[email protected]> |
8
|
|
|
* @copyright 2014 Dev-Int GLSR |
9
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
10
|
|
|
* |
11
|
|
|
* @version since 1.0.0 |
12
|
|
|
* |
13
|
|
|
* @link https://github.com/Dev-Int/glsr |
14
|
|
|
*/ |
15
|
|
|
namespace AppBundle\Helper; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Time helper. |
19
|
|
|
* |
20
|
|
|
* @category Helper |
21
|
|
|
*/ |
22
|
|
|
class TimeHelper |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* get Easter date. |
26
|
|
|
* |
27
|
|
|
* @param integer $pYear |
28
|
|
|
* @return timestamp |
29
|
|
|
*/ |
30
|
|
|
private function getEaster ($pYear = null) |
31
|
|
|
{ |
32
|
|
|
if (is_null ($pYear)) { |
33
|
|
|
$pYear = (int)date ('Y'); |
34
|
|
|
} |
35
|
|
|
$nDate = $pYear - 1900; |
36
|
|
|
$pAa = $nDate%19; |
37
|
|
|
$pBb = floor (((7*$pAa)+1)/19); |
38
|
|
|
$pCc = ((11*$pAa)-$pBb+4)%29; |
39
|
|
|
$pDd = floor ($nDate/4); |
40
|
|
|
$pEe = ($nDate-$pCc+$pDd+31)%7; |
41
|
|
|
$pResult = 25-$pCc-$pEe; |
42
|
|
|
if ($pResult > 0) { |
43
|
|
|
$pEaster = strtotime ($pYear.'/04/'.$pResult); |
44
|
|
|
} else { |
45
|
|
|
$pEaster = strtotime ($pYear.'/03/'.(31+$pResult)); |
46
|
|
|
} |
47
|
|
|
return $pEaster; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* get the next open day. |
52
|
|
|
* |
53
|
|
|
* @link http://codes-sources.commentcamarche.net/source/38705-jours-ouvres Jours ouvrés |
54
|
|
|
* @author Malalam |
55
|
|
|
* |
56
|
|
|
* @param timestamp $pDate Order date |
57
|
|
|
* @param integer $pDays Delta for the day of delivery |
58
|
|
|
* @return integer Delta next business day |
59
|
|
|
*/ |
60
|
|
|
function getNextOpenDay ($pDate, $pDays) { |
|
|
|
|
61
|
|
|
$aBankHolidays = ['1_1', '1_5', '8_5', '14_7', '15_8', '1_11', '11_11', '25_12', ]; |
62
|
|
|
if (function_exists ('easter_date')) { |
63
|
|
|
$pEaster = easter_date ((int)date('Y'), $pDate); |
64
|
|
|
} else { |
65
|
|
|
$pEaster = $this->getEaster ((int)date('Y'), $pDate); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
$aBankHolidays[] = date ('j_n',$pEaster); |
68
|
|
|
$aBankHolidays[] = date ('j_n', $pEaster + (86400*39)); |
69
|
|
|
$aBankHolidays[] = date ('j_n', $pEaster + (86400*49)); |
70
|
|
|
|
71
|
|
|
$pEnd = $pDays * 86400; |
72
|
|
|
$idn = 0; |
73
|
|
|
while ($idn < $pEnd) { |
74
|
|
|
$idn = strtotime ('+1 day', $idn); |
75
|
|
|
if (in_array (date ('w', $pDate+$idn),array (0,6) ) || in_array (date ('j_n', $pDate+$idn), $aBankHolidays)) { |
76
|
|
|
$pEnd = strtotime ('+1 day', $pEnd); |
77
|
|
|
$pDays ++; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
return $pDays; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.