At a Perfect Time
Before I delve into the C/C++ constructs for handling DST and other timezone related info
, a few questions must be answered.
Q: Microsoft's announcement was sent to Microsoft's users. Is the said announcement relevant only for Windows users?
A: No, it isn't. The reported change in the DST scheme affects users of other operating systems and programming languages as well. Furthermore, while the 2007 DST period extension is currently effective in the United States, it's reasonable that other countries will adopt this scheme to save energy, and to ensure that DST periods in various countries remain in sync. In other words, the new DST scheme doesn't affect only C/C++ programmers using the Windows operating systemit has more far reaching consequences and scope.
Q: What is the major difference between 2007 and previous years with respect to DST?
A: Beginning in 2007, DST will be extended in the United States. DST started on March 11, 2007, which is three weeks earlier than usual. It will end on November 4, 2007, which is one week later than usual. This results in a new DST period that is four weeks longer than in previous years.
Q: What should I do then?
A: Unless certain updates are applied to your computer, the time zone settings for your computer's system clock may be incorrect during this four-week period. In particular, you must make sure that both your Windows operating system and your calendar programs are updated. As far as C/C++ developers are concerned, you will have to test existing applications and in some cases, relink them against the new CRT. In addition, hard-coded DST periods must be revised and replaced with dynamic DST detection facilities which I'm about to discuss here.
Time Zones and Daylight Saving
C/C++ implementations store time as Coordinated Universal Time (UTC) by default (UTC replaces the obsolescent term GMT). To access the local timezone information, applications and library functions rely on the TZ environment variable. The information encoded in TZ is then used for triggering a chain of updates that ultimately fill certain data structures and objects with the correct data.
To access DST and other timezone related information, you must call the _tzset() function first:
void _tzset(void); //declared in <ctime>
initializes the f the following global variables:
extern time_t _timezone;
extern time_t _altzone;
extern int _daylight;
extern char* _tzname;
| Author's Note: These variables may have slightly different names on certain implementations. For instance, _timezone is called timezone on older implementations. In essence, the main difference is that older implementations don't have an underscore at the beginning of functions and global variables. Please consult your IDE's online documentation for further information.