PDA

View Full Version here: : I thought picking the date for Easter was easy


astroron
08-04-2012, 11:58 AM
Picking the date was I thought just so easy, Sunday closest to Full Moon Ect,
Not So.
http://www.rmg.co.uk/explore/astronomy-and-time/time-facts/the-date-of-easter
Quite complicated really:rolleyes:
Happy Easter:D
cheers :thumbsup:

mithrandir
08-04-2012, 02:45 PM
Ron, since just about everyone has Perl on their computers these days:

#!/usr/bin/perl -w
use POSIX;

$y=($#ARGV>-1)?$ARGV[0]:strftime('%Y',localtime())
or die("$0: year required\n");

$c = int($y/100);
$n = $y-19*int($y/19);
$k = int(($c-17)/25);
$i = $c-int($c/4)-int(($c-$k)/3)+19*$n+15;
$i = $i-30*int($i/30);
$i = $i-int($i/28)*(1-int($i/28)*int(29/($i+1))*int((21-$n)/11));
$j = $y+int($y/4)+$i+2-$c+int($c/4);
$j = $j-7*int($j/7);
$l = $i-$j;
$m = 3+int(($l+40)/44);
$d = $l+28-31*($m/4);
@when=(0,0,0,$d,$m-1,$y-1900);
print strftime("%Y/%b/%d\n",@when);
or if you install the Date::Easter module:

#!/usr/bin/perl -w
use POSIX;
use Date::Easter;

$y=($#ARGV>-1)?$ARGV[0]:strftime('%Y',localtime())
or die("$0: year required\n");

($M,$D)=gregorian_easter($y);
@when=(0,0,0,$D,$M-1,$y-1900);
print strftime("%Y/%b/%d gregorian\n",@when);

($M,$D)=julian_easter($y);
@when=(0,0,0,$D,$M-1,$y-1900);
print strftime("%Y/%b/%d julian\n",@when);

($M,$D)=orthodox_easter($y);
@when=(0,0,0,$D,$M-1,$y-1900);
print strftime("%Y/%b/%d orthodox\n",@when);The first version is probably simpler in C.

leon
08-04-2012, 03:48 PM
Ya learn something every day. :rolleyes:

Leon :thumbsup:

Barrykgerdes
08-04-2012, 04:31 PM
I have a calendar. I get a new one every year. It has the dates of Easter, School holidays, other public holidays etc. no need for a computer program.;):lol::thumbsup::D
Besides every day is a holiday for me!

Barry

PS I also have a program in qbasic that can do the same.

astroron
08-04-2012, 05:12 PM
I wouldn't know where to start, I don't understand any of that stuff:rolleyes:
Cheers

xstream
08-04-2012, 06:27 PM
It's easy Ron!

Perl 1, Knit 2. :P

astroron
08-04-2012, 06:43 PM
:lol::lol::lol:
Cheers Alex:thumbsup:

skysurfer
08-04-2012, 06:56 PM
And here the Javascript implementation:



/**
* @param year the year of which easter has to be calculated
* @param option calculate other date than easter (offset in days)
* @returns JD of Easter date
*/

function easter(year, option)
{
var golden, solar, lunar, pfm, dom, tmp, easterday,d;

/* the Golden number */
golden = (year % 19) + 1;

if ( year <= 1752 )
{
/* JULIAN CALENDAR */
/* the "Dominical number" - finding a Sunday */
dom = (year + Math.floor(year/4) + 5) % 7;
if (dom < 0) dom += 7;

/* uncorrected date of the Paschal full moon */
pfm = (3 - (11*golden) - 7) % 30;
if (pfm < 0) pfm += 30;
}
else
{
/* GREGORIAN CALENDAR */
/* the "Dominical number" - finding a Sunday */
dom = (year + Math.floor(year/4) - Math.floor(year/100) + Math.floor(year/400)) % 7;
if (dom < 0) dom += 7;

/* the solar and lunar corrections */
solar = Math.floor((year-1600)/100) - Math.floor((year-1600)/400);
lunar = Math.floor((Math.floor((year-1400) / 100) * 8) / 25);

/* uncorrected date of the Paschal full moon */
pfm = (3 - (11*golden) + solar - lunar) % 30;
if (pfm < 0) pfm += 30;
}

/* corrected date of the Paschal full moon - days after 21st March */
if ((pfm == 29) || (pfm == 28 && golden > 11))
pfm--;

tmp = (4-pfm-dom) % 7;
if (tmp < 0) tmp += 7;

/* easterday as the number of days after 21st March */
easterday = pfm + tmp + 1;

//alert(year + ' ' + tmp + ' ' + easterday);

if (easterday < 11)
d = datetojd(new Array(year,3, easterday+21,12,0,0));
else
d = datetojd(new Array(year,4, easterday-10,12,0,0));
if (arguments.count > 1)
d += option;
d = Math.floor(d);
return d;
}


function datetojd(datestr)
{
n = datestr; // array assumed y-m-d-h-i-s
var date = new Date(n[0],n[1]-1, n[2], n[3], n[4], n[5]);
var jd = date.getTime()/86400000 + 2440588 - (date.getTimezoneOffset()/1440);
//alert(jd + ' ' + (date.getTime()/86400000 + 2440588));
return jd;
}

mithrandir
08-04-2012, 07:41 PM
One C++ source for easter is part of lunar.zip (http://www.projectpluto.com/lunar.zip) from Project Pluto

It compiles, with its driver test program, by:
*nix/cygwin: g++ -DTEST_CODE -o easter easter.cpp
MSVC: cl -DTEST_CODE -o easter.exe easter.cpp

Now, who has it in Java, Pascal, REXX, Python, ...

ballaratdragons
08-04-2012, 08:08 PM
This thread make absolutely no sense to me. :screwy:

Must be a foreign language. :P

Don't worry Ron, you aren't alone in the confusion :lol:

:bashcomp: :driving: :scared3:

Ric
09-04-2012, 01:06 AM
It is interesting how it is worked out.

I understand a bit of that code but it's all a bit above me.

von Tom
09-04-2012, 04:43 AM
A Perl of wisdom from Andrew there...
Anyone got it in BASIC?