How do I compute the date of the 1st Sunday of April and the last Sunday in October given the year? I'm working on a project in which a real-time clock has to correct itself for DST automatically. Any ideas? Thanks alot Dana Rodakis
I found this doing a google search on "date algorithms" Not sure if it will do what you want but it might be worth a look. http://alcor.concordia.ca/~gpkatch/gdate-algorithm.html -Walt
How do you store your RTC in the system? Supposedly you use 32-bit time in seconds, you can have a 10-years or 20-years table which contains DST in/out time for each year. This is the easy way, however, this means your product won't go international. Another way I like is to create a virtual monthly calendar table for each "type of month" in your code (i.e., 1st DayOfMonth can start from SUN, MON, ..., SAT, so you'll have 7 types of month). Once you compute the 1st DayOfMonth, you know which table to use and where your first SUN is and where your last SUN is in this month's table. Computing RTC is always a tedious job.
"this means your product won't go international." Not sure what you mean by this - how you calculate it doesn't affect whether you also have the means to specify different dates to suit different countries and/or timezones? I'm not even sure that there is a deterministic formula for when BST applies?
Unless this 10-years DST table I was talking about can be programmed to XDATA, then you can certainly make your product none country dependent.