note 63696 deleted from function.date by bjori
| From: | bjori@php.net | Date: | Tue, 28 Mar 2006 19:33:29 +0000 |
| Subject: | note 63696 deleted from function.date by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-106871@lists.php.net to get a copy of this message | ||
Note Submitter:
Reason: bad code
----
Here is a function to calculate easter sunday for any year from 1900 to 4099, pass the year into the
function and it will return the date in the format dd/mm/yyyy
function calcEasterSunday($year){
$frac = $year/19;// GET THE FRACTION OF THE DATE
$fraction = explode(".",$frac);
//============ Set the year parameter ==============================//
if($year <= 2199){
$useYear = 2199;
}else if($year <= 2299){
$useYear = 2299;
}else if($year <= 2399){
$useYear = 2399;
}else if($year <= 2499){
$useYear = 2499;
}else if($year <= 2599){
$useYear = 2599;
}else if($year <= 2899){
$useYear = 2899;
}else if($year <= 3099){
$useYear = 3099;
}else if($year <= 3399){
$useYear = 3399;
}else if($year <= 3499){
$useYear = 3499;
}else if($year <= 3599){
$useYear = 3599;
}else if($year <= 3699){
$useYear = 3699;
}else if($year <= 3799){
$useYear = 3799;
}else if($year <= 4099){
$useYear = 4099;
}
//========== calculate easter sunday ==============================//
$useFrac = substr($fraction[1],0,3);
$pfm = $pfmDate[$useFrac][$useYear];
$num1 = $tableB[$pfm];
$num2 = $tableC[substr($year,0,2)];
$num3 = $tableD[substr($year,2,2)];
$total = $num1+$num2+$num3;
$adddays = $tableE[$total];
//========== Create date for easter sunday ======================//
$days = substr($pfm,1,2)+$adddays;
$mon = (substr($pfm,0,1)=="A")? 4 : 3;
if($mon==3 && $days > date("t",mktime(12,0,0,3,1,$year))){
$days = $days-date("t",mktime(12,0,0,3,1,$year));
$mon = 4;
}
$easterSunday = date("d/m/Y",mktime(12,0,0,$mon,$days,$year));
return $easterSunday;
}
For the tables that i used to create the arrays $pfmDate, $tableB-E follow the link
http://www.assa.org.au/edm.html#Calculator
hope this helps someone