January 16, 2001
By Karen Kenworthy
IN THIS ISSUE
It's a glorious day, here at the secluded Power Tools workshop. Yesterday's rain washed away the last of December's snow. And now the sun is shining clear and bright. Thanks to the sudden warmth, the birds, squirrels, and other year-round residents are busy, making plans for the coming year. The promise of Spring is easy to believe, on a day like this.
Two of the promises of Spring are longer days and more daylight. In the Northern Hemisphere at least, the Winter Solstice, late in December, marks the shortest day and longest night of the year. But for the next six months the sun spends more and more of its time above the horizon each day.
By the time of the Spring Equinox, around the third week of March, the days are finally longer than the nights. This sunny condition continues until the Autumnal Equinox, late in September. Between these two dates, sunshine is abundant, and starlight is in short supply.
Readers in the Southern Hemisphere should re-read the last two paragraphs while holding their monitors upside down. :)
Now you might think the extra daylight from March to September would make people devalue the stuff. But oddly, this is exactly the time of year that most of the United States, and many other countries in the northern half of the globe, go to great lengths to "save daylight."
This miracle is accomplished by changing time. At some mutually agreeable time during the Spring, in the wee hours of a morning, all clocks in a region are set forward, usually by an hour. This begins the portion of each year known as Daylight Savings Time, or just Daylight Time.
The immediate result of this change to our clocks is that the sun rises, and sets, an hour later than the day before. Early risers, who once awoke to the first rays of dawn, now drink their first cup of coffee in predawn darkness. They do, at least, until the lengthening of days undoes this change of time, bringing daylight back to the early morning hours.
Time is set "right" again in the Fall, when clocks are moved back to their original settings. Occurring in late Fall, this end of Daylight Time marks the beginning of Standard Time.
The sun takes no notice of our efforts to shift time and save daylight. It continues to bath the earth according to its own schedule. But computer programmers can't be so nonchalant. All sorts of software, from payroll programs, to e-mail clients, to personal schedulers, and more, must know what time it is. And that means they must take shifts from Standard Time, to Daylight Time, and back again, into account.
Unfortunately, keeping track of time isn't as easy as it might seem. Within the United States, Arizona, Hawaii and most of Indiana do not shift their clocks. Instead, they stay on Standard Time year-round. The rest of the U.S. moves their clocks forward at 2 a.m. on the first Sunday of April, and moves them back again on the last Sunday in October.
In Britain (where Daylight Time is known as British Summer Time), the clocks are adjusted on the last Sunday of March and October. New European Union rules will cause most, but not all, EU countries to make their adjustments at the same time. Mexico and Canada follows the same schedule as the U.S., with one exception. Beginning October 29, 2000, Canada's new territory of Nunavut uses Central Daylight Time all year. At the moment, Japanese don't adjust their clocks at all, staying on Standard Time year round.
Fortunately, Windows helps programmers manage these details. When Windows is first installed, it asks for the name of the time zone where the computer resides. Behind the scenes, it uses this information to consult a table of Daylight and Standard Time transition rules. Later, Windows will follow those rules and automatically adjust the computer's clock.
Windows will reveal the rules it is following, if a program asks. And that's just what Karen's Computer Profiler does. If you were with us last week, you'll remember this little program. When run, it displays over 100 bits of information about your computer, its CPU, memory, operating system, keyboard, monitor, mouse, and more.
To learn some of the information it displays, the Profiler calls the built-in Windows function GetTimeZoneInformation. In response, Windows fills a block of memory with several bits of time zone information. The information is stored in a structure Windows calls TIME_ZONE_INFORMATION (what else?).
Within that structure are two fields named StandardDate and DaylightDate. These fields are themselves structures, blocks of memory containing other fields. Their type of structure is known as SYSTEMTIME, and it contains fields such as Year, Month, Day, Hour, Minute, Second, and DayOfWeek.
Now you might think the StandardDate structure would contain the date and time that Standard Time goes into effect, while the DaylightDate structure holds the beginning of Daylight Time. I thought that. But if you agreed with me, we were both wrong.
By pure dumb luck, these structures do hold the Daylight and Standard Time transitions times, for the year 2001, within North America. With one gotcha. The Year field of each structure contains a zero, instead of 2001. As a result, when Karen's Computer Profiler displayed the information it thought it had discovered, it was almost right.
But reader Don Mattingly noticed the problem. "I have one question... Now that we are in year 2001, why do the "Standard Time Begins:" and "Daylight Time Begins:" show the year 2000?"
The answer to Don's question turned out to be simple. Since the Year field of each SYSTEMTIME structure was zero, the Profiler thought it referred to year '00, or 2000. But why did the Year fields of these structures contain a value of zero in the first place? Shouldn't the fields have held the value 2001?
Reader John Howells provided the explanation. As it turns out, Windows sets the Year field of a SYSTEMTIME structure for a reason. This special value signals programs that the information returned is not an actual date. Instead, it's a set of rules that must be followed to determine a date, rules such as "The last Sunday of April" or "The 2nd Tuesday of July."
Thanks to the help from John and Don, the new Profiler now properly displays the dates when Daylight and Standard Time begin. It also displays the rules that Windows follows, after translating them into English. While I was making changes, I also taught the Profiler how to discover more information about your computer's keyboard, and fixed a few bugs.
If you'd like to give it a try, you can download the new Profiler 1.3 from the program's home page at https://www.karenware.com/powertools/ptprofiler. The program's Visual Basic source code can be downloaded there too, if you'd like to see what goes on behind the scenes. As always, they're both free.
As for me, I'm going to see if I can't sneak of tomorrow, and enjoy some of the wonderful weather we're having. If you can too, why don't you join me? If not, I hope you look for me on the 'net this week. And if you see me anywhere, be sure to wave and say "Hi!"
More than 6000 downloads monthly
Received $937.39 this month* — Thanks!
December Revenue* $937.39
*Licenses + Donations - PayPal Fees
November $151 October $133 USD — Thanks again!