From 24503e3abe705acde2df159aeae61be0d009f92e Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Wed, 19 Nov 2008 17:27:03 -0500 Subject: Imported sources --- includes/specialdates.php | 314 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 314 insertions(+) create mode 100755 includes/specialdates.php (limited to 'includes/specialdates.php') 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 @@ +$dotw) + { + $ys+=(((7-sd_date('N',$ys))+$dotw)*60*60*24); + } else { + $ys+=(($dotw-sd_date('N',$ys))*60*60*24); + } + $ys+=(($wn-1)*60*60*24*7); + $did = sd_getMonthStart(sd_date('m',$ys)-1); + $did += (sd_date('j',$ys)-1); + sd_addDateIn($id,$did); +} + +function sd_getMonthStart($month) +{ + if ($month==0) + { + return 0; + } else { + $c = sd_daysInMonth($month-1)+sd_getMonthStart($month-1); + if (date('F jS Y',sd_clearDate()+($c*60*60*24)) == 'March 31st 2008' || $month == 2) + { +// echo($month . ':' . sd_daysInMonth($month-1) . ':' . sd_getMonthStart($month-1) . "\n"); + } + return ($c); + } +} + +function sd_daysInMonth($month) +{ + switch ($month) + { + case 0: return 31; + case 1: return (28+sd_isLeapYear()); + case 2: return 31; + case 3: return 30; + case 4: return 31; + case 5: return 30; + case 6: return 31; + case 7: return 31; + case 8: return 30; + case 9: return 31; + case 10: return 30; + case 11: return 31; + default: throw new Exception('Invalid month ID'); + } +} + +function sd_isLeapYear() +{ + return sd_date('L'); +} + +function sd_isSpecialDay($id) +{ + global $specialdates; + $did = sd_getMonthStart(sd_date('n')-1); + $did += (sd_date('j')-1); + if ($specialdates[$did] == $id) + { + return 1; + } else { + return 0; + } +} + +function sd_ifNoSpecialDay() +{ + global $specialdates; + $did = sd_getMonthStart(sd_date('n')-1); + $did += (sd_date('j')-1); + if ($specialdates[$did] == '') + { + return 1; + } else { + return 0; + } +} + +function sd_kirbyWeek() +{ + $did = sd_getMonthStart(11); + $ys = sd_clearDate(); + $ys+=(60*60*24*24); + $ys+=(60*60*24*$did); + $tWD=sd_date('N',$ys); + if ($tWD==7) {$tWD=0;} + $ys-=($tWD*60*60*24); + $ys-=(60*60*24*7); + sd_solar_annual('Kirby Week',12,sd_date('j',$ys)); + sd_solar_annual('Kirby Week',12,sd_date('j',$ys)+1); + sd_solar_annual('Kirby Week',12,sd_date('j',$ys)+2); + sd_solar_annual('Kirby Week',12,sd_date('j',$ys)+3); + sd_solar_annual('Kirby Week',12,sd_date('j',$ys)+4); + sd_solar_annual('Kirby Week',12,sd_date('j',$ys)+5); + sd_solar_annual('Kirby Week',12,sd_date('j',$ys)+6); +} + +function sd_easter() +{ + $nYear = sd_date('Y'); + $nCent = $nYear/100; + $nRemain19 = $nYear%19; + $n1 = ($nCent-15)/2+202-11*$nRemain19; + if ($nCent>20) + { + if ($nCent>26) {$n1--;} + if ($nCent>38) {$n1--;} + if ($nCent==21 || $nCent==24 || $nCent==25 || $nCent==33 || $nCent==36 || $nCent==37) {$n1--;} + } + $n1%=30; + if ($n1==29 || ($n1 && $nRemain19>10)) {$n1--;} + $ys = sd_clearDate(); + if ($n1>10) + { + $ys+=(60*60*24*sd_getMonthStart(3)); + $ys+=(60*60*24*($n1-10-1)); + } else { + $ys+=(60*60*24*sd_getMonthStart(2)); + $ys+=(60*60*24*($n1+21-1)); + } + $nWD = sd_date('N',$ys); + if ($nWD==7) {$nWD=0;} + $ys+=(60*60*24*(7-$nWD)); + sd_solar_annual('Easter',sd_date('m',$ys),sd_date('j',$ys)); + $ys-=(60*60*24*46); + sd_solar_annual('Mardi Gras',sd_date('m',$ys),sd_date('j',$ys)); + $ys+=(60*60*24); + sd_solar_annual('Ash Wednesday',sd_date('m',$ys),sd_date('j',$ys)); + $ys+=(60*60*24*38); + sd_solar_annual('Palm Sunday',sd_date('m',$ys),sd_date('j',$ys)); + $ys+=(60*60*24*5); + sd_solar_annual('Good Friday',sd_date('m',$ys),sd_date('j',$ys)); +} + +function sd_findDay($id) +{ + global $specialdates; + $i=0; + for ($i=0;$i<(365+sd_isLeapYear());$i++) + { + if ($specialdates[$i] == $id) + { + return $i; + } + } + throw new Exception('Specified holiday does not exist'); +} + +function sd_findNextDay() +{ + global $specialdates; + $did = sd_getMonthStart(sd_date('n')-1); + $did += (sd_date('j')-1); + $i=0; + for ($i=$did;$i<(365+sd_isLeapYear());$i++) + { + if ($specialdates[$i] != '') + { + return $i; + } + } + throw new Exception('No more holidays this year'); +} + +function sd_getCurrentDay() +{ + global $specialdates; + $did = sd_getMonthStart(sd_date('n')-1); + $did += (sd_date('j')-1); + return $specialdates[$did]; +} + +function sd_solar_multiannual($id,$month,$date,$years,$sy) +{ + global $specialdates; + $cy = sd_date('Y'); + $cy -= $sy; + if ($cy==0 || $cy%$years==0) + { + $did = sd_getMonthStart($month-1); + $did += ($date-1); + $specialdates[$did] = $id; + } +} + +function sd_solar_once($id,$month,$date,$year) +{ + if ($year == sd_date('Y')) + { + sd_solar_annual($id,$month,$date); + } +} + +function sd_getDay($id) +{ + global $specialdates; + return $specialdates[$id]; +} + +function sd_lunar_monthly($id,$dotw,$wn) +{ + $i=1; + for ($i=1;$i<13;$i++) { + sd_lunar_annual($id,$i,$dotw,$wn); + } +} + +function sd_date($format,$timestamp = 0) +{ + if ($timestamp == 0) {$timestamp = time();} + return date($format,$timestamp); +} + +function sd_clearDate() +{ + $ys = strtotime('January 1 ' . date('Y')); + return $ys; +} + +function sd_addDateIn($id,$dateid) +{ + global $specialdates; + $specialdates[$dateid] = $id; +} + +?> -- cgit 1.4.1