Bug 1436 – std.date.getLocalTZA() returns wrong values when in DST under Windows
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D1 (retired)
Platform
All
OS
Windows
Creation time
2007-08-21T06:27:00Z
Last change time
2014-02-16T15:22:05Z
Keywords
patch, wrong-code
Assigned to
bugzilla
Creator
matti.niemenmaa+dbugzilla
Comments
Comment #0 by matti.niemenmaa+dbugzilla — 2007-08-21T06:27:05Z
Currently, getLocalTZA() does the following:
--
r = GetTimeZoneInformation(&tzi);
switch (r) {
case TIME_ZONE_ID_STANDARD:
case TIME_ZONE_ID_DAYLIGHT:
case TIME_ZONE_ID_UNKNOWN:
t = -(tzi.Bias + tzi.StandardBias) * cast(d_time)(60 * TicksPerSecond);
break;
default:
t = 0;
break;
}
return t;
--
As can be seen, it always uses the StandardBias field, as long as GetTimeZoneInformation doesn't result in an error.
However, this is incorrect. When TIME_ZONE_ID_DAYLIGHT is returned, the DaylightBias field should be used, as this indicates that the system is currently using Daylight Savings Time. StandardBias is meant to be used only when the system is not in DST, as documented at http://msdn.microsoft.com/library/en-us/sysinfo/base/gettimezoneinformation.asp and http://msdn2.microsoft.com/en-us/library/ms725481.aspx
One possible working version follows:
--
r = GetTimeZoneInformation(&tzi);
switch (r) {
case TIME_ZONE_ID_STANDARD: t = tzi.Bias + tzi.StandardBias; break;
case TIME_ZONE_ID_DAYLIGHT: t = tzi.Bias + tzi.DaylightBias; break;
case TIME_ZONE_ID_UNKNOWN: t = tzi.Bias; break;
default:
t = 0;
break;
}
return -t * cast(d_time)(60 * TicksPerSecond);