Thread overview
Can't get local time on Windows 2000
Aug 24, 2005
k2
Aug 26, 2005
Walter
Aug 26, 2005
Carlos Santander
Aug 27, 2005
Walter
Aug 29, 2005
Carlos Santander
Aug 31, 2005
Carlos Santander
Aug 29, 2005
Carlos Santander
Aug 29, 2005
Carlos Santander
Aug 27, 2005
Manfred Nowak
Aug 29, 2005
Carlos Santander
August 24, 2005
import std.date;
import std.stdio;

void main()
{
writefln("UTC  :%s", toTimeString(getUTCtime()));
writefln("Local:%s", toTimeString(UTCtoLocalTime(getUTCtime())));
}

---
UTC  :17:07:24 GMT+0000
Local:17:07:24 GMT+0000

Date of my PC is GMT+09:00.
When you test this code, you have to use Windows 2000 or XP, not 9x.
And change to time zone that is no daylight-saving.


August 26, 2005
"k2" <k2_member@pathlink.com> wrote in message news:dei96c$94k$1@digitaldaemon.com...
> import std.date;
> import std.stdio;
>
> void main()
> {
> writefln("UTC  :%s", toTimeString(getUTCtime()));
> writefln("Local:%s", toTimeString(UTCtoLocalTime(getUTCtime())));
> }
>
> ---
> UTC  :17:07:24 GMT+0000
> Local:17:07:24 GMT+0000
>
> Date of my PC is GMT+09:00.
> When you test this code, you have to use Windows 2000 or XP, not 9x.
> And change to time zone that is no daylight-saving.

Running on my PC, with XP, it gives:

UTC  :10:56:04 GMT-0700
Local:03:56:04 GMT-0700


August 26, 2005
Walter escribió:
> "k2" <k2_member@pathlink.com> wrote in message
> news:dei96c$94k$1@digitaldaemon.com...
> 
>>import std.date;
>>import std.stdio;
>>
>>void main()
>>{
>>writefln("UTC  :%s", toTimeString(getUTCtime()));
>>writefln("Local:%s", toTimeString(UTCtoLocalTime(getUTCtime())));
>>}
>>
>>---
>>UTC  :17:07:24 GMT+0000
>>Local:17:07:24 GMT+0000
>>
>>Date of my PC is GMT+09:00.
>>When you test this code, you have to use Windows 2000 or XP, not 9x.
>>And change to time zone that is no daylight-saving.
> 
> 
> Running on my PC, with XP, it gives:
> 
> UTC  :10:56:04 GMT-0700
> Local:03:56:04 GMT-0700
> 
> 

Walter, this issue has been mentioned before. Check for instance:

http://www.digitalmars.com/d/archives/digitalmars/D/bugs/189.html
http://www.digitalmars.com/d/archives/25669.html

I tried k2's code on W2K and it was wrong too. My TZ is GMT-0500, Bogotá, Lima, Quito.

-- 
Carlos Santander Bernal
August 27, 2005
Walter wrote in news:denlng$1mrb$1@digitaldaemon.com

> Running on my PC, with XP
[...]

Running XP also:

GMT is true localtime
localtime is true localtime +0200

Switching the timezones confirms the behaviour described.

-manfred
August 27, 2005
"Carlos Santander" <csantander619@gmail.com> wrote in message news:deo9l4$25i2$1@digitaldaemon.com...
> Walter, this issue has been mentioned before. Check for instance:
>
> http://www.digitalmars.com/d/archives/digitalmars/D/bugs/189.html http://www.digitalmars.com/d/archives/25669.html
>
> I tried k2's code on W2K and it was wrong too. My TZ is GMT-0500, Bogotá,
Lima,
> Quito.

It doesn't happen on my system. Can you perhaps take a look at std.date.d and debug it on your system? It's only a few lines of code.


August 29, 2005
Walter escribió:
> "k2" <k2_member@pathlink.com> wrote in message
> news:dei96c$94k$1@digitaldaemon.com...
> 
>>import std.date;
>>import std.stdio;
>>
>>void main()
>>{
>>writefln("UTC  :%s", toTimeString(getUTCtime()));
>>writefln("Local:%s", toTimeString(UTCtoLocalTime(getUTCtime())));
>>}
>>
>>---
>>UTC  :17:07:24 GMT+0000
>>Local:17:07:24 GMT+0000
>>
>>Date of my PC is GMT+09:00.
>>When you test this code, you have to use Windows 2000 or XP, not 9x.
>>And change to time zone that is no daylight-saving.
> 
> 
> Running on my PC, with XP, it gives:
> 
> UTC  :10:56:04 GMT-0700
> Local:03:56:04 GMT-0700
> 
> 

Here're some results:

---gdc 0.15 on Mac---
$ date
Sun Aug 28 15:27:26 ECT 2005

$ ./test
UTC  :01:27:28 GMT+0500
Local:06:27:28 GMT+0500

---gdc 0.15 on Linux---
$ date
dom ago 28 15:27:10 ECT 2005

$ ./test
UTC  :01:27:15 GMT+0500
Local:06:27:15 GMT+0500

---dmd 0.128 on Linux---
$ ./test
UTC  :15:27:13 GMT-0500
Local:10:27:13 GMT-0500

---dmd 0.128 on WinXP---
>time
La hora actual es: 15:36:32,94
Escriba una nueva hora:

>test
UTC  :20:36:34 GMT+0000
Local:20:36:34 GMT+0000

So, gdc is as lost as it can be. DMD on linux, getUTCtime() returns the local time. DMD on Windows, getUTCtime() is correct. UTCtoLocalTime() on linux seems to be ok, but not on Windows.

Remember, my TZ is GMT-0500, no CT, no ET, but South America.

-- 
Carlos Santander Bernal
August 29, 2005
Walter escribió:
> "Carlos Santander" <csantander619@gmail.com> wrote in message
> news:deo9l4$25i2$1@digitaldaemon.com...
> 
>>Walter, this issue has been mentioned before. Check for instance:
>>
>>http://www.digitalmars.com/d/archives/digitalmars/D/bugs/189.html
>>http://www.digitalmars.com/d/archives/25669.html
>>
>>I tried k2's code on W2K and it was wrong too. My TZ is GMT-0500, Bogotá,
> 
> Lima,
> 
>>Quito.
> 
> 
> It doesn't happen on my system. Can you perhaps take a look at std.date.d
> and debug it on your system? It's only a few lines of code.
> 
> 

On Windows, the problem is in getLocalTZA(). It's returning 0 here, so UTCtoLocalTime() fails because it does nothing to the date returned by getUTCtime(). I don't know how GetTimeZoneInformation() should work, but I'd guess the problem is in that switch in getLocalTZA().

I still have to check on linux.

-- 
Carlos Santander Bernal
August 29, 2005
Walter escribió:
> "Carlos Santander" <csantander619@gmail.com> wrote in message
> news:deo9l4$25i2$1@digitaldaemon.com...
> 
>>Walter, this issue has been mentioned before. Check for instance:
>>
>>http://www.digitalmars.com/d/archives/digitalmars/D/bugs/189.html
>>http://www.digitalmars.com/d/archives/25669.html
>>
>>I tried k2's code on W2K and it was wrong too. My TZ is GMT-0500, Bogotá,
> 
> Lima,
> 
>>Quito.
> 
> 
> It doesn't happen on my system. Can you perhaps take a look at std.date.d
> and debug it on your system? It's only a few lines of code.
> 
> 

Ok, as I hinted in another post, the problem on linux is easy: getUTCtime() is returning the local time, which means gettimeofday() or time() return the local time. Maybe there should be getUTCtime() and getLocalTime() in phobos: on linux, getUTCtime() calls getLocalTime() and on Windows it's the opposite. Just an idea...

-- 
Carlos Santander Bernal
August 29, 2005
Walter escribió:
> "Carlos Santander" <csantander619@gmail.com> wrote in message
> news:deo9l4$25i2$1@digitaldaemon.com...
> 
>>Walter, this issue has been mentioned before. Check for instance:
>>
>>http://www.digitalmars.com/d/archives/digitalmars/D/bugs/189.html
>>http://www.digitalmars.com/d/archives/25669.html
>>
>>I tried k2's code on W2K and it was wrong too. My TZ is GMT-0500, Bogotá,
> 
> Lima,
> 
>>Quito.
> 
> 
> It doesn't happen on my system. Can you perhaps take a look at std.date.d
> and debug it on your system? It's only a few lines of code.
> 
> 

Regarding gdc, the problem seems to be in _d_gnu_cbridge_tza(), but I'm not sure.

-- 
Carlos Santander Bernal
August 31, 2005
Carlos Santander escribió:
> Walter escribió:
> 
>> "Carlos Santander" <csantander619@gmail.com> wrote in message
>> news:deo9l4$25i2$1@digitaldaemon.com...
>>
>>> Walter, this issue has been mentioned before. Check for instance:
>>>
>>> http://www.digitalmars.com/d/archives/digitalmars/D/bugs/189.html
>>> http://www.digitalmars.com/d/archives/25669.html
>>>
>>> I tried k2's code on W2K and it was wrong too. My TZ is GMT-0500, Bogotá,
>>
>>
>> Lima,
>>
>>> Quito.
>>
>>
>>
>> It doesn't happen on my system. Can you perhaps take a look at std.date.d
>> and debug it on your system? It's only a few lines of code.
>>
>>
> 
> On Windows, the problem is in getLocalTZA(). It's returning 0 here, so UTCtoLocalTime() fails because it does nothing to the date returned by getUTCtime(). I don't know how GetTimeZoneInformation() should work, but I'd guess the problem is in that switch in getLocalTZA().
> 
> I still have to check on linux.
> 

Another thought (even if I haven't tested): if the problem is GetTimeZoneInformation(), why not replace the code when it returns 0 with a call to GetSystemTime() and GetLocalTime(), and then get the timezone from that difference?

-- 
Carlos Santander Bernal