Problems with std.time and local conversion?

fawcett at uwindsor.ca fawcett at uwindsor.ca
Thu Apr 15 09:46:50 PDT 2010


Hi folks,

The std.date library for D2 seems to be buggy with respect to local
timezone conversions:

     // demo.d
     import std.stdio;
     import std.date;

     void main() {
       // UTC first, then local
       writefln(toString(getUTCtime()));
       writefln(toString(UTCtoLocalTime(getUTCtime())));
     }

Compiling and running:

     $ uname -srm
     Linux 2.6.31-20-generic x86_64
     $ dmd | head -1
     Digital Mars D Compiler v2.043

     $ dmd demo.d

     $ TZ=UTC date ; TZ=EST5EDT date       # try GNU date first
     Thu Apr 15 16:31:40 UTC 2010
     Thu Apr 15 12:31:40 EDT 2010

     $ TZ=EST5EDT ./demo
     Thu Apr 15 17:32:02 GMT+0100 2010     # UTC wrong!
     Thu Apr 15 18:32:02 GMT+0100 2010     # Local wrong!

The library it gets it right on TZ=UTC, so the TZ environment variable
is clearly being considered:

     $ TZ=UTC ./demo
     Thu Apr 15 16:32:20 GMT+0000 2010
     Thu Apr 15 16:32:20 GMT+0000 2010

But of course TZ=UTC sidesteps local conversion altogether. I also
tried with TZ=EST but that gives identical results to TZ=UTC.

Can anyone help explain what's happening here? (If it matters, I
installed the i386 .deb package on my x86_64 machine; otherwise I
think this is a typical installation.)

Thanks,
Graham



More information about the Digitalmars-d mailing list