1752767 Members
5247 Online
108789 Solutions
New Discussion юеВ

Easter Date?

 
SOLVED
Go to solution
Ryan Clerk
Frequent Advisor

Easter Date?

Hi experts,

We always schedule maintenance over the Easter Sunday weekend. Is there a method to automatically calculate this date? I just can't seem to find any relationship between the date from year to year.

TIA,
Ryan
18 REPLIES 18
A. Clay Stephenson
Acclaimed Contributor

Re: Easter Date?

Go to www.perl.org/CPAN and search on easter. You will find plenty of methods. Easter date calculations are far from trivial. C. F. Gauss (the dude for whom the
magnetic field strength unit is named) devised an algoritm. I wrote a shell script based on his algorithm many years ago. I may be able to find it but I know there are Perl modules for this.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Easter Date?

This should get you started.

http://search.cpan.org/search?query=Easter&mode=all
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor
Solution

Re: Easter Date?

Hi Ryan:

This will compute the date for you:

# cat ./easter
#!/usr/bin/perl
use strict;
use Date::Calc qw(Easter_Sunday);
my ($year,$month,$day) = Easter_Sunday($ARGV[0]);
print "Easter is $month/$day/$year\n";

Run as:

# ./easter 2006
Easter is 4/16/2006

...or pass any year to it.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Easter Date?

Hi Ryan:

By the way, the computation of Easter's date can be done according to the algorithm presented here, if you really want to do so:

http://aa.usno.navy.mil/faq/docs/easter.html

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: Easter Date?

Okay Ryan, I found my old shell script, easter.sh. Invoke as easter.sh -u for full usage but basically it outputs MM DD of Easter for a given year. If no year argument is supplied, the current year is used.
If it ain't broke, I can fix that.
Ryan Clerk
Frequent Advisor

Re: Easter Date?

Hi A. Clay and JRF,

Thanks very much for the quick answers. I will probably use A. Clay's script only because my Perl skills are so limited.

Thanks,
Ryan
Hein van den Heuvel
Honored Contributor

Re: Easter Date?

Hmmm, maybe you should consider simply picking up a table like the one posted in the website pointed to by JRF.

Then you would just check the year against the end of the table, giving an error when it needs to be updated, or giving the date when it is there.
It would be as much code, much less error prone and readily tweakable for future special cases

Just a thought...

Hein.


http://aa.usno.navy.mil/faq/docs/easter.html

Ryan Clerk
Frequent Advisor

Re: Easter Date?

Hi experts,

As a follow up to this question, I would like to send out a notification on the two Mondays before the Easter weekend. How could I make a cron entry which would do this?

TIA,
Ryan
James R. Ferguson
Acclaimed Contributor

Re: Easter Date?

Hi Ryan:

You could cron something like this:

0 8 3,10 4 1 mailx -s "Easter is April 16" root < /dev/null

Look at the manpages for 'crontab(1)'. The line above generates a mail to "root" with the message "Easter is April 16" on April 3 and April 10 (Mondays) at 0800.

Add that line to your root crontab or create a root crontab with 'vi'.

I like to do:

# crontab -l > /tmp/mycrontab
[ edit ]
# crontab /tmp/mycrontab

Regards!

...JRF...