07-10-2002, 06:21 PM
Has anyone found or written a script to calculate when holidays will appear during the year?
I'm writing a script to send an alert if the data is not current but one of my cohorts in crime said "What about holidays?" to which i replied "Turn off your pager."
Unfortunately thats not a "good" solution, So here I am asking for help once again. :)
If I need to put in a base line of the holidays like starting in 2000 that would be fine also.
Thanks in advance... :)
07-10-2002, 09:45 PM
Could you be more specific about which holidays you want? But, let's say you want to see if it is July 4, you could use this script:
var date=new Date().getDate();
var month=new Date().getMonth()+1;
if(date==4&&month==7) alert("Happy Independenced Day!");
Hope that helps!
Happy coding! :)
07-11-2002, 03:56 AM
Seems to me you need a more general solution than just holidays. I'd think you'd want to be able to "mark" any date - like vacations or sick days.
Off the top of my head I'd say implement an array of dates. Each date in the array is a day that you don't send that alert. Just scan the array and if today's date is there, well there you are. This will prevent you from having to test for (e.g. hard code) specific dates.
Additionally, you can store the year value such that you can tell if a particular date is recurring, or is just a one time thing. For example if you leave the year blank for July 4 then that means this is a recurring (annual) date. If the year is in there explicitly then when that day,month,year is past the date can be purged from the array.
If you want to get fancy, you might want to "encode" a date range; rather than enter each day of someone's 20 day vacation, you enter the beginning and ending date. In this case you'd need a sort of a more sophisticated data structure to know what dates are beginning and end dates, and what beginning/ending dates are paired. Off hand, I don't know what that might look like. You'd need a unique marker (key) for each pair and then an additional marker to know what is the beginning or end (or smart code to figure out that the earlier date of a given matched pair is the beginning).
You can have lots of fun with this. It has job security written all over it!
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.