Perl and Daylight Saving Time on Windows

Perl and Daylight Saving Time on Windows

am 06.03.2007 00:15:42 von Jan Dubois

Prompted by a bug report regarding the new DST rules I had a closer look
how localtime() determines Daylight Saving Time on Windows. This
information is not really specific to Perl but applies to all Windows
applications that use either the MSVCRT runtime library, or the Win32
API to determine DST transition times.

Executive summary:

If you only care about current and future timestamps, and *don't* have
the TZ environment variable set, then you should be fine by just
installing all Windows patches.

Otherwise read below:

============================================================ =========
The daylight saving time (DST) for the localtime() function is
determined by the C runtime library function of the same name.

This function has 2 different operating modes:

1) The TZ environment variable has been set.

In this case MSVCRT calculates DST itself, based on the USA rules.
The latest released version (as of (March 5th 2007) of MSVCRT.dll has
not yet been updated for the 2007 DST rules. The localtime() function
will still apply the old rules to 2007. Microsoft claims to have a
hotfix for this, that is available from Microsoft Customer Support
Services only:

http://support.microsoft.com/kb/932590

2) The TZ environment variable has *not* been set.

In this case MSVCRT retrieves the DST transition times from the
GetTimeZoneInformation() API:

http://msdn2.microsoft.com/en-us/library/ms724421.aspx

This API only provides the transition times according to the *current*
DST rules. There is no database of historical transition times. That
means that localtime() applied to previous years will use the new
transition times even for old timestamps.

Windows Vista (and Longhorn Server) support a new API called
GetDynamicTimeZoneInformation() that implements a database of historic
DST rules. It is not known if the hotfix mentioned above will make
use of this API when running on Vista.
============================================================ =========

Cheers,
-Jan

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs