Re: Days until Easter and Christmas

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kevin Waterson wrote:
This one time, at band camp, tedd <tedd.sperling@xxxxxxxxx> wrote:

Easter lands on different dates depending upon several different factors. For example in Canada it's the day after it is in the USA -- I guess Canadians are slower, eh? :-)

Also, in some religions the date is the full-moon after the Equinox and not a specific date. Furthermore, the Equinox does not always land on March 21, but sometimes it's March 20 (leap year).

So, the key is to find the date of the Vernal Equinox, which as you say,
does not always land on March 21. However, every 400 years, it does happen
on March 21 7:30am GST. From there, we can derive a base for future dates.
Every 4th year is a leap year, and every 4th century, giving 97 leap days
each 400 years. so (365*400+97)/400 is 365.2425 gives the length of each year.
Then the dates can be calculated as follows:

http://phpro.org/examples/Get-Vernal-Equinox.html

Any improvements welcomed

Kind regards
Kevin

just for the sake of madness, many moons ago I wrote this bit of code which will create a "datestamp"

<?
/*
Valid Date Ranges:
1st January 1 (datestamp 1) to 31st December 32767 (datestamp 11967900)

datestamp(year,month,day)
Turns any date in the valid date range into an integer value

datestamp_parts(datestamp)
Takes input datestamp and returns an array containing the date info		
*/
function datestamp($y=0,$m=0,$d=0) {
	/*
	datestamp(year, month, day)
		year INT | not required | default: current year
		month INT | not required | default: current month
		day INT | not required | default: current day
	called with no values returns the current dates datestamp
	returns false on error
	*/
	$datestamp = false;
	$y = $y ? $y : date("Y");
	$m = $m ? $m : date("n");
	$d = $d ? $d : date("j");
	if(checkdate($m, $d, $y)) {
$datestamp = ((($y-1)*365)+date("z",mktime(1,1,1,$m,$d,2007))+(floor($y/4)-(floor($y/100)-floor($y/400))))+1; if(((((floor($y/100) == $y/100) && (floor($y/400) == $y/400))) || ((floor($y/4) == $y/4) && (floor($y/400) == $y/400)) || ((floor($y/4) == ($y/4)) && !(floor($y/100) == $y/100))) && (date("z",mktime(1,1,1,$m,$d,2000))<60)) {
			$datestamp--; //leapyear adjustment
		}
	}
	return $datestamp;
}

function datestamp_parts($datestamp=0) {
	if($datestamp && ($datestamp < 11967900)) {
$yd= ((365)+($datestamp-((ceil(($datestamp-((floor((($datestamp/365)/4)-floor(($datestamp/365)/100)+floor(($datestamp/365)/400)))))/365))*(365))))-(floor(((ceil(($datestamp-((floor((($datestamp/365)/4)-floor(($datestamp/365)/100)+floor(($datestamp/365)/400)))))/365))-1)/4)-(floor(((ceil(($datestamp-((floor((($datestamp/365)/4)-floor(($datestamp/365)/100)+floor(($datestamp/365)/400)))))/365))-1)/100)-floor(((ceil(($datestamp-((floor((($datestamp/365)/4)-floor(($datestamp/365)/100)+floor(($datestamp/365)/400)))))/365))-1)/400))); $y = (ceil(($datestamp-((floor((($datestamp/365)/4)-floor(($datestamp/365)/100)+floor(($datestamp/365)/400)))))/365)); $l = ((floor((ceil(($datestamp-((floor((($datestamp/365)/4)-floor(($datestamp/365)/100)+floor(($datestamp/365)/400)))))/365))/4)-(floor((ceil(($datestamp-((floor((($datestamp/365)/4)-floor(($datestamp/365)/100)+floor(($datestamp/365)/400)))))/365))/100)-floor((ceil(($datestamp-((floor((($datestamp/365)/4)-floor(($datestamp/365)/100)+floor(($datestamp/365)/400)))))/365))/400)))-(floor(((ceil(($datestamp-((floor((($datestamp/365)/4)-floor(($datestamp/365)/100)+floor(($datestamp/365)/400)))))/365))-1)/4)-(floor(((ceil(($datestamp-((floor((($datestamp/365)/4)-floor(($datestamp/365)/100)+floor(($datestamp/365)/400)))))/365))-1)/100)-floor(((ceil(($datestamp-((floor((($datestamp/365)/4)-floor(($datestamp/365)/100)+floor(($datestamp/365)/400)))))/365))-1)/400))));
		if((!$l && $yd>365)) {
			$yd=$yd-365;
			$y++;
			$l=1;
		} elseif($l && $yd>366) {
			$yd=$yd-366;
			$y++;
			$l=0;
		}
		$uy = $l ? 2000 : 2001;
		$m = date("n",mktime(1,1,1,1,$yd,$uy));
		$md = date("j",mktime(1,1,1,1,$yd,$uy));
		$out['year'] = $y;
		$out['month'] = $m;
		$out['month_day'] = $md;
		$out['leapyear'] = $l;
		$out['year_day'] = $yd;
		return $out;
	} else {
		return false;
	}
}
?>

not sure why I'm throwing it in but it sure was interesting trying to make it, possibly the single longest line of eye watering code ever in there lol!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux