1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* You may not change or alter any portion of this comment or credits |
4
|
|
|
* of supporting developers from this source code or any supporting source code |
5
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
* |
7
|
|
|
* This program is distributed in the hope that it will be useful, |
8
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @copyright {@link http://xoops.org/ XOOPS Project} |
14
|
|
|
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
15
|
|
|
* @package |
16
|
|
|
* @since |
17
|
|
|
* @author XOOPS Development Team, |
18
|
|
|
* @author Antiques Promotion (http://www.antiquespromotion.ca) |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
View Code Duplication |
if (!function_exists('easter')) { |
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param $y |
24
|
|
|
* @param $holidays |
25
|
|
|
*/ |
26
|
|
|
function easter($y, &$holidays) |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$e = 21 + easter_days($y); |
29
|
|
|
if ($e > 31) { |
30
|
|
|
$e -= 31; |
31
|
|
|
$em = 4; |
32
|
|
|
} else { |
33
|
|
|
$em = 3; |
34
|
|
|
} |
35
|
|
|
$f = $e - 2; |
36
|
|
|
$m = $e + 1; |
37
|
|
|
if ($f > 0) { |
38
|
|
|
$holidays["$y-$em-$f"] = 'Good Friday'; |
39
|
|
|
} else { |
40
|
|
|
$f = 31 - $f; |
41
|
|
|
$holidays["$y-3-$f"] = 'Good Friday'; |
42
|
|
|
} |
43
|
|
|
$holidays["$y-$em-$e"] = 'Easter'; |
44
|
|
|
if ($m > 31) { |
45
|
|
|
$m -= 31; |
46
|
|
|
$holidays["$y-4-$m"] = 'Easter Monday'; |
47
|
|
|
} else { |
48
|
|
|
$holidays["$y-$em-$m"] = 'Easter Monday'; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->holidays = array(); |
54
|
|
|
$start = (int)date('Y') - 10; |
55
|
|
|
$end = $start + 30; |
56
|
|
|
|
57
|
|
View Code Duplication |
for ($y = $start; $y < $end; ++$y) { |
|
|
|
|
58
|
|
|
easter($y, $this->holidays); |
59
|
|
|
$v = ((int)date('N', strtotime("$y-5-25")) == 1) ? '25' : date('j', strtotime('Last Monday', strtotime("$y-5-25"))); |
60
|
|
|
$m = date('j', strtotime('+2 Sunday', strtotime("$y-5-1"))); |
61
|
|
|
$f = date('j', strtotime('+3 Sunday', strtotime("$y-6-1"))); |
62
|
|
|
$c = date('j', strtotime('+1 Monday', strtotime("$y-8-1"))); |
63
|
|
|
$l = date('j', strtotime('+1 Monday', strtotime("$y-9-1"))); |
64
|
|
|
$t = date('j', strtotime('+2 Monday', strtotime("$y-10-1"))); |
65
|
|
|
|
66
|
|
|
$this->holidays["$y-1-1"] = 'New Years Day'; |
67
|
|
|
$this->holidays["$y-2-14"] = 'Valentine\'s Day'; |
68
|
|
|
$this->holidays["$y-3-17"] = 'St. Patrick\'s Day'; |
69
|
|
|
$this->holidays["$y-4-22"] = 'Earth Day'; |
70
|
|
|
$this->holidays["$y-5-$m"] = 'Mother\'s Day'; |
71
|
|
|
$this->holidays["$y-5-$v"] = 'Victoria Day'; |
72
|
|
|
$this->holidays["$y-6-$f"] = 'Father\'s Day'; |
73
|
|
|
$this->holidays["$y-7-1"] = 'Canada Day'; |
74
|
|
|
$this->holidays["$y-8-$c"] = 'Civic Holiday'; |
75
|
|
|
$this->holidays["$y-9-$l"] = 'Labour Day'; |
76
|
|
|
$this->holidays["$y-10-$t"] = 'Thanksgiving'; |
77
|
|
|
$this->holidays["$y-10-31"] = 'Halloween'; |
78
|
|
|
$this->holidays["$y-11-11"] = 'Rememberance Day'; |
79
|
|
|
$this->holidays["$y-12-25"] = 'Christmas Day'; |
80
|
|
|
$this->holidays["$y-12-26"] = 'Boxing Day'; |
81
|
|
|
} |
82
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.