[Issue 1436] New: std.date.getLocalTZA() returns wrong values when in DST under Windows
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Aug 21 04:27:06 PDT 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1436
Summary: std.date.getLocalTZA() returns wrong values when in DST
under Windows
Product: D
Version: 1.020
Platform: All
OS/Version: Windows
Status: NEW
Keywords: patch, wrong-code
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: bugzilla at digitalmars.com
ReportedBy: deewiant at gmail.com
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);
--
More information about the Digitalmars-d-bugs
mailing list