1436 – std.date.getLocalTZA() returns wrong values when in DST under Windows

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1436 - std.date.getLocalTZA() returns wrong values when in DST under Windows
Summary: std.date.getLocalTZA() returns wrong values when in DST under Windows
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D1 (retired)
Hardware: All Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
Reported: 2007年08月21日 06:27 UTC by Matti Niemenmaa
Modified: 2014年02月16日 15:22 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Matti Niemenmaa 2007年08月21日 06:27:05 UTC
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);
Comment 1 Walter Bright 2007年09月28日 22:13:07 UTC
Fixed dmd 1.021 and 2.004


AltStyle によって変換されたページ (->オリジナル) /