summary refs log tree commit diff stats
path: root/includes/specialdates.php
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2008-11-19 17:27:03 -0500
committerStarla Insigna <hatkirby@fourisland.com>2008-11-19 17:27:03 -0500
commit24503e3abe705acde2df159aeae61be0d009f92e (patch)
tree8debbd53dcd0db2f5934c5e2af4e697e3787781d /includes/specialdates.php
downloadfourisland-24503e3abe705acde2df159aeae61be0d009f92e.tar.gz
fourisland-24503e3abe705acde2df159aeae61be0d009f92e.tar.bz2
fourisland-24503e3abe705acde2df159aeae61be0d009f92e.zip
Imported sources
Diffstat (limited to 'includes/specialdates.php')
-rwxr-xr-xincludes/specialdates.php314
1 files changed, 314 insertions, 0 deletions
diff --git a/includes/specialdates.php b/includes/specialdates.php new file mode 100755 index 0000000..91a356e --- /dev/null +++ b/includes/specialdates.php
@@ -0,0 +1,314 @@
1<?php
2/*
3 444444444
4 4::::::::4
5 4:::::::::4
6 4::::44::::4
7 4::::4 4::::4 Four Island
8 4::::4 4::::4
9 4::::4 4::::4 Written and maintained by Starla Insigna
104::::444444::::444
114::::::::::::::::4 includes/specialdates.php
124444444444:::::444
13 4::::4 Please do not use, reproduce or steal the
14 4::::4 contents of this file without explicit
15 4::::4 permission from Hatkirby.
16 44::::::44
17 4::::::::4
18 4444444444
19*/
20
21if (!defined('S_INCLUDE_FILE')) {define('S_INCLUDE_FILE',1);}
22
23require('headerproc.php');
24
25/* REMEMBER!
26Months: Jan=1-Dec=12
27Dates: 1=1-...=...
28Days: Mon=1-Sun=7 */
29
30$specialdates = array();
31
32$j=0;
33for ($j=0;$j<(365+sd_isLeapYear());$j++)
34{
35 $specialdates[$j] = '';
36}
37
38sd_solar_annual('New Years Day',1,1); //BG Pic; DateFinder
39sd_lunar_annual('Martin Luther King Day',1,1,3); //BG Pic; DateFinder
40sd_solar_annual('Groundhog Day',2,2); //BG Pic; DateFinder
41sd_lunar_annual('Presidents Day',2,1,3); //DateFinder
42sd_solar_annual('Valentines Day',2,14); //BG Pic; DateFinder
43sd_solar_multiannual('Leap Day',2,29,4,2004); //DateFinder
44sd_solar_annual('St Patricks Day',3,17); //DateFinder
45sd_solar_annual('Tris CIEday',4,22); //DateFinder
46sd_solar_annual('Silence Day',4,25); //DateFinder
47sd_solar_annual('WCA Day',5,5); //DateFinder
48sd_lunar_annual('Mothers Day',5,7,2); //BG Pic; DateFinder; Header Pic
49sd_lunar_annual('Memorial Day',5,1,4); //BG Pic; DateFinder; Header Pic
50sd_easter(); //BG Pic; DateFinder
51sd_solar_annual('Hatkirbys B-Day',6,7); //BG Pic; DateFinder; Header Pic
52sd_solar_annual('Flag Day',6,14); //BG Pic; DateFinder
53sd_lunar_annual('Fathers Day',6,7,3); //BG Pic; DateFinder
54sd_solar_annual('CTNH',6,17); //Header Pic
55sd_solar_annual('Independance Day',7,4); //BG Pic; DateFinder
56sd_lunar_annual('SysAdminDay',7,5,4); //DateFinder
57sd_lunar_annual('Labor Day',9,1,1); //Yet to be implemented
58sd_solar_annual('Four Island A',9,22); //BG Pic; DateFinder; Header Pic
59sd_lunar_annual('Columbus Day',10,1,2); //BG Pic; DateFinder
60sd_solar_annual('Halloween',10,31); //BG Pic; DateFinder
61sd_solar_annual('Veterans Day',11,11); //BG Pic; DateFinder
62sd_lunar_annual('Thanksgiving',11,4,4); //DateFinder
63sd_kirbyWeek(); //BG Pic; DateFinder
64sd_solar_annual('Christmas Eve',12,24); //BG Pic; DateFinder
65sd_solar_annual('Christmas Day',12,25); //BG Pic; DateFinder
66sd_solar_annual('New Years Eve',12,31); //BG Pic; DateFinder
67
68function sd_solar_annual($id,$month,$date)
69{
70 $did = sd_getMonthStart($month-1);
71 $did += ($date-1);
72 sd_addDateIn($id,$did);
73}
74
75function sd_solar_monthly($id,$date)
76{
77 $i=0;
78 for ($i=0;$i<12;$i++)
79 {
80 sd_solar_annual($id,$i+1,$date);
81 }
82}
83
84function sd_lunar_annual($id,$month,$dotw,$wn)
85{
86 $did = sd_getMonthStart($month-1);
87 $ys = sd_clearDate();
88 $ys+=(60*60*24*$did);
89 if (sd_date('N',$ys)>$dotw)
90 {
91 $ys+=(((7-sd_date('N',$ys))+$dotw)*60*60*24);
92 } else {
93 $ys+=(($dotw-sd_date('N',$ys))*60*60*24);
94 }
95 $ys+=(($wn-1)*60*60*24*7);
96 $did = sd_getMonthStart(sd_date('m',$ys)-1);
97 $did += (sd_date('j',$ys)-1);
98 sd_addDateIn($id,$did);
99}
100
101function sd_getMonthStart($month)
102{
103 if ($month==0)
104 {
105 return 0;
106 } else {
107 $c = sd_daysInMonth($month-1)+sd_getMonthStart($month-1);
108 if (date('F jS Y',sd_clearDate()+($c*60*60*24)) == 'March 31st 2008' || $month == 2)
109 {
110// echo($month . ':' . sd_daysInMonth($month-1) . ':' . sd_getMonthStart($month-1) . "\n");
111 }
112 return ($c);
113 }
114}
115
116function sd_daysInMonth($month)
117{
118 switch ($month)
119 {
120 case 0: return 31;
121 case 1: return (28+sd_isLeapYear());
122 case 2: return 31;
123 case 3: return 30;
124 case 4: return 31;
125 case 5: return 30;
126 case 6: return 31;
127 case 7: return 31;
128 case 8: return 30;
129 case 9: return 31;
130 case 10: return 30;
131 case 11: return 31;
132 default: throw new Exception('Invalid month ID');
133 }
134}
135
136function sd_isLeapYear()
137{
138 return sd_date('L');
139}
140
141function sd_isSpecialDay($id)
142{
143 global $specialdates;
144 $did = sd_getMonthStart(sd_date('n')-1);
145 $did += (sd_date('j')-1);
146 if ($specialdates[$did] == $id)
147 {
148 return 1;
149 } else {
150 return 0;
151 }
152}
153
154function sd_ifNoSpecialDay()
155{
156 global $specialdates;
157 $did = sd_getMonthStart(sd_date('n')-1);
158 $did += (sd_date('j')-1);
159 if ($specialdates[$did] == '')
160 {
161 return 1;
162 } else {
163 return 0;
164 }
165}
166
167function sd_kirbyWeek()
168{
169 $did = sd_getMonthStart(11);
170 $ys = sd_clearDate();
171 $ys+=(60*60*24*24);
172 $ys+=(60*60*24*$did);
173 $tWD=sd_date('N',$ys);
174 if ($tWD==7) {$tWD=0;}
175 $ys-=($tWD*60*60*24);
176 $ys-=(60*60*24*7);
177 sd_solar_annual('Kirby Week',12,sd_date('j',$ys));
178 sd_solar_annual('Kirby Week',12,sd_date('j',$ys)+1);
179 sd_solar_annual('Kirby Week',12,sd_date('j',$ys)+2);
180 sd_solar_annual('Kirby Week',12,sd_date('j',$ys)+3);
181 sd_solar_annual('Kirby Week',12,sd_date('j',$ys)+4);
182 sd_solar_annual('Kirby Week',12,sd_date('j',$ys)+5);
183 sd_solar_annual('Kirby Week',12,sd_date('j',$ys)+6);
184}
185
186function sd_easter()
187{
188 $nYear = sd_date('Y');
189 $nCent = $nYear/100;
190 $nRemain19 = $nYear%19;
191 $n1 = ($nCent-15)/2+202-11*$nRemain19;
192 if ($nCent>20)
193 {
194 if ($nCent>26) {$n1--;}
195 if ($nCent>38) {$n1--;}
196 if ($nCent==21 || $nCent==24 || $nCent==25 || $nCent==33 || $nCent==36 || $nCent==37) {$n1--;}
197 }
198 $n1%=30;
199 if ($n1==29 || ($n1 && $nRemain19>10)) {$n1--;}
200 $ys = sd_clearDate();
201 if ($n1>10)
202 {
203 $ys+=(60*60*24*sd_getMonthStart(3));
204 $ys+=(60*60*24*($n1-10-1));
205 } else {
206 $ys+=(60*60*24*sd_getMonthStart(2));
207 $ys+=(60*60*24*($n1+21-1));
208 }
209 $nWD = sd_date('N',$ys);
210 if ($nWD==7) {$nWD=0;}
211 $ys+=(60*60*24*(7-$nWD));
212 sd_solar_annual('Easter',sd_date('m',$ys),sd_date('j',$ys));
213 $ys-=(60*60*24*46);
214 sd_solar_annual('Mardi Gras',sd_date('m',$ys),sd_date('j',$ys));
215 $ys+=(60*60*24);
216 sd_solar_annual('Ash Wednesday',sd_date('m',$ys),sd_date('j',$ys));
217 $ys+=(60*60*24*38);
218 sd_solar_annual('Palm Sunday',sd_date('m',$ys),sd_date('j',$ys));
219 $ys+=(60*60*24*5);
220 sd_solar_annual('Good Friday',sd_date('m',$ys),sd_date('j',$ys));
221}
222
223function sd_findDay($id)
224{
225 global $specialdates;
226 $i=0;
227 for ($i=0;$i<(365+sd_isLeapYear());$i++)
228 {
229 if ($specialdates[$i] == $id)
230 {
231 return $i;
232 }
233 }
234 throw new Exception('Specified holiday does not exist');
235}
236
237function sd_findNextDay()
238{
239 global $specialdates;
240 $did = sd_getMonthStart(sd_date('n')-1);
241 $did += (sd_date('j')-1);
242 $i=0;
243 for ($i=$did;$i<(365+sd_isLeapYear());$i++)
244 {
245 if ($specialdates[$i] != '')
246 {
247 return $i;
248 }
249 }
250 throw new Exception('No more holidays this year');
251}
252
253function sd_getCurrentDay()
254{
255 global $specialdates;
256 $did = sd_getMonthStart(sd_date('n')-1);
257 $did += (sd_date('j')-1);
258 return $specialdates[$did];
259}
260
261function sd_solar_multiannual($id,$month,$date,$years,$sy)
262{
263 global $specialdates;
264 $cy = sd_date('Y');
265 $cy -= $sy;
266 if ($cy==0 || $cy%$years==0)
267 {
268 $did = sd_getMonthStart($month-1);
269 $did += ($date-1);
270 $specialdates[$did] = $id;
271 }
272}
273
274function sd_solar_once($id,$month,$date,$year)
275{
276 if ($year == sd_date('Y'))
277 {
278 sd_solar_annual($id,$month,$date);
279 }
280}
281
282function sd_getDay($id)
283{
284 global $specialdates;
285 return $specialdates[$id];
286}
287
288function sd_lunar_monthly($id,$dotw,$wn)
289{
290 $i=1;
291 for ($i=1;$i<13;$i++) {
292 sd_lunar_annual($id,$i,$dotw,$wn);
293 }
294}
295
296function sd_date($format,$timestamp = 0)
297{
298 if ($timestamp == 0) {$timestamp = time();}
299 return date($format,$timestamp);
300}
301
302function sd_clearDate()
303{
304 $ys = strtotime('January 1 ' . date('Y'));
305 return $ys;
306}
307
308function sd_addDateIn($id,$dateid)
309{
310 global $specialdates;
311 $specialdates[$dateid] = $id;
312}
313
314?>