www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.date time problem

reply Regan Heath <regan netmail.co.nz> writes:
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?

Regan
Aug 21 2007
next sibling parent reply Deewiant <deewiant.doesnotlike.spam gmail.com> writes:
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. -- Remove ".doesnotlike.spam" from the mail address.
Aug 21 2007
parent Regan Heath <regan netmail.co.nz> writes:
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
Aug 21 2007
prev sibling parent Deewiant <deewiant.doesnotlike.spam gmail.com> writes:
Regan Heath wrote:
 I think this is a bug, but I can't be sure.

I filed Issue 1436 in the 'Zilla. (I thought I already had, as I ran into this myself a few weeks ago. Good thing that you reminded me. <g>) -- Remove ".doesnotlike.spam" from the mail address.
Aug 21 2007