![]() ![]() Update: I just noticed you have an hour and minute in your time as well. It doesn't handle all rules, though, so you will need to add some code for the remaining rules. ![]() I found a Local/DST/Tz calculator here: and as it's a JavaScript applet you should be able to simply crib the code. But there's no searching going on otherwise, so it's strictly O(1). Worst case for this calculation is, you have to repeat your two rule calculations for the previous year. Note that the rules may have changed during the interval, so be sure to apply the correct one for the year you're looking at. target) year regardless of whether the target date is before or after those dates if the on/off date is in the future of your target date, then simply do the rule calculation again for the previous year. You can calculate the DST on/off dates for the current (i.e. October is associated with an "off", so we must currently have NO DST. Which of these dates is more recent? October. It's currently December, so given a couple of rules like "Mar lastSun" and "Oct lastSun" for my time zone, those dates would be Maand October 25, 2009. What you need to do is gather up all of these tersely formatted "rules" and develop a bit of code for each to determine the last date indicated by that rule. The on/off rules will have a funny spec like "Oct lastSun": That means the switch occurs in the night of the last Sunday in October. For reasons explained below, it may be handy to also be aware of the rules for the preceding year. There could be several different rules depending on which year, you want to be sure to grab the right one for your "target" year. Then you look up your time zone and pull out the variation against UTC, the DST on/off rule and offset. To get your DST information, the first thing to do is to calculate the year/month/day for your future date (if it isn't in that form already). ![]() But I can accept the premise that we just pretend the currently known rules will apply forever. Everybody's already commented on the problems with always-changing DSTs. ![]()
0 Comments
Leave a Reply. |