std.date time problem

Regan Heath regan at netmail.co.nz
Tue Aug 21 04:28:38 PDT 2007


Deewiant wrote:
> Regan Heath wrote:
>> I think this is a bug, but I can't be sure.
>>
>> [time.d]
>> import std.stdio, std.date;
>>
>> void main()
>> {
>>     d_time now = UTCtoLocalTime(getUTCtime());
>>     writefln("%s", toTimeString(now));
>> }
>>
>> dmd -run time.d
>> 10:54:42 GMT+0100
>>
>> time /t
>> 09:55
>>
>> I am in London so at GMT, but it's summer so we're at +0100 currently
>> (aka BST).  It seems std.date adds an extra hour?
>>
> 
> Yep, it's buggy. std.date does essentially the following in getLocalTZA() on
> Windows (shortened to pseudocode):
> 
> TIME_ZONE_INFORMATION tzi;
> GetTimeZoneInformation(&tzi);
> 
> if (unknown time zone || in standard time || in daylight savings time)
> 	return -(tzi.Bias + tzi.StandardBias) * 60 * TicksPerSecond;
> else
> 	return 0; // error
> 
> Microsoft documents at http://msdn2.microsoft.com/en-us/library/ms725481.aspx that:
> 
> - "Bias" is "[t]he current bias for local time translation on this computer, in
> minutes" and "UTC = local time + bias".
> 
> - "StandardBias" is "[t]he bias value to be used during local time translations
> that occur during standard time."
> 
> - "DaylightBias" (not used in std.date) is "[t]he bias value to be used during
> local time translations that occur during daylight saving time."
> 
> That is, UTC = local time + Bias + StandardBias, or UTC = local time + Bias +
> DaylightBias, depending on whether DST is active or not.
> 
> However, Phobos uses StandardBias in all cases. It should use DaylightBias if
> GetTimeZoneInformation returns TIME_ZONE_ID_DAYLIGHT.
> 
> In London, I presume that Bias is 0, StandardBias is 0, and DaylightBias is -60,
> which is why std.date is wrong.

Thanks, I'm going to post this to bugzilla.

Regan



More information about the Digitalmars-d mailing list