Re: riddle in the spirit of Feb. 29 Message #17 Posted by Dale Reed on 29 Feb 2012, 7:53 p.m., in response to message #6 by Marcus von Cube, Germany
We had an intern at work who was asked to write a function to switch into and out of DST. I was asked to review the code. (There were issues with documentation, variables declared that had long been deleted from the code, and so on. But this isn't about that.)
The intern followed the current U.S. rules. I reminded the intern that we (who will remain nameless) are a global company. We went to Wikipedia and checked out the article on daylight saving time (summer time). Not that it would need to be spot-on accurate -- it would give us a flavo(u)r for the variety of rules used around the world so we could give the code the right configurability. The rules, of course, are set by governments (not tech people) -- then they must be dealt with by programmers.
The code was reworked to deal with all the variations we found in the wiki, including:
* No change (tropical countries).
* Move forward in the early part of the year (northern hemisphere) or in the latter part of the year (southern hemisphere).
* Move at local time (U.S.) or at a fixed UTC (EU).
* Move on the first, second, third, fourth or last (whatever day of the week) of (whatever month).
* Move on the (whatever day of the week) BEFORE the 1st, ..., last (whatever...) (Russia, I think).
* Move on a fixed date (Israel, I think....).
* Move any number of minutes (Newfoundland moved 120 minutes one year instead of 60. At least I think it was the Newfies....).
* A couple other variants I can't remember without digging up my list.
And finally, the function must set a flag during the overlap (two 1:30 a.m.'s), and set a flag when the skip forward occurs (no 2:30 a.m.).
The second rev of the code was VASTLY improved. GOOD intern! :-)
Key takeaway: DST rules are established by (and changed at the whim of) governments. YMMV. Greatly.
I believe WinXP has a database file of DST rules for the Windows Time Service to use. (The timezone database feeds the pulldown in the clock config window.) When governments change DST, MS has to push a new database (via Windows Update). At least I think that's how it works. There was a KBxxxxxx item we had to make sure to apply before the end of October the year the U.S. changed from last Sunday in October to first Sunday in November. Not everybody did the update....
Dale
|