Re: calculating election day

2004-02-05 Thread fliptop
On Tue, 3 Feb 2004 at 17:42, Chad A Gard opined:

CAG:I'm attempting to dynamically place an image into the user interface
CAG:of an intranet site to celebrate various holidays.  It's really not

this doesn't really have anything to do with cgi, but if you read the 
recipes for Date::Calc, you should be able to figure it out.

http://search.cpan.org/~stbey/Date-Calc-5.3/Calc.pod


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




calculating election day

2004-02-03 Thread Chad A Gard
I'm attempting to dynamically place an image into the user interface of 
an intranet site to celebrate various holidays.  It's really not 
important functionally, but meant to impart just a little fun/whimsy - 
which, of course, means I can't spend too much time with it.

Right now I'm running it as a CGI, but I'll probably modify it to run 
nightly via a cron job, and just rename an appropriate image from, say, 
groundhogsDay.gif to currentHoliday.gif to save processor time.  But, 
anyway, on to the problem.

to make things easy, I'm using Date::Manip (which, of course, isn't 
horribly fast, hence the desire to probably run it as a stand alone, 
cron-activated script in the end, rather than a CGI each time a user 
does something).

So, I've got a little script like so (for testing finding the right 
holiday).

use Date::Manip;
Date_Init(EraseHolidays=0, PersonalCnf=dateManip.conf);
$eventsToday = Events_List(today);
@eventList = @{$eventsToday}; #list in format (date, (list of event 
names));
@eventName = @{$eventList[1]}; #second item of list is the list of 
event names, ('event 1', 'event 2');
$todayIs = $eventName[0];
print Today is $todayIs\n;



with my dateManip.conf file like so:

*Events

Jan 1   = newYears
3rd Mon in Jan ; 2nd Mon in Jan = MLKDay
Feb 14 ; Feb 7  = 
valentinesDay
2nd Sun in May ; May 1  = monthersDay
last Mon in May; 2nd Mon in May = memorialDay
Jul 4 ; last mon in June= 
independenceDay
1st mon in sep ; last mon in august = laborDay
2nd Mon in Oct ; 1st Mon in Oct = ColumbusDay
4th Thu in Nov ; 2nd Thu in Nov = Thanksgiving
Dec 25 ; Dec 11 = 
Christmas
The idea is, I don't want to necessarily celebrate each holiday for 
the same length of time.  Now, my two questions.

First, as you can see, I listed events in the format event date ; date 
I want the image to first appear.  It appears from the date::manip docs 
that I should be able to instead do something like event date ; -n 
days, for example:

3rd Mon in Feb; -2day	=	WashingtonB-day

to get a washington's birthday image from the saturday preceding the 
3rd monday to the 3rd monday in feb.  but, that seems to give strange 
results - I always get the next holiday defined that way following the 
current date, even if it's listed as -1 day and we're months before it.

Am I misunderstanding how Date::Manip treats its events configuration, 
or is this a bug?  Any better way to work around it than to make rough 
judgements of what should be OK like I did?



The second question: How would one calculate election day here in the 
us?

$election = ParseDate(1st Tue after 1st Mon in Nov);

just doesn't quite work.  It seems a little obscure.  It'd be pretty 
simple in a script to find the first tuesday and see if it's  the 1st. 
 But, I can't really do that in the config file, since it is just read 
in and the dates parsed when the script is run.

Any ideas there?

TIA





Chad A Gard
http://www.percussionadvocates.com/chad


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response