Re: bug in time() related to DST?
From: Alexander Grigoriev (alegr_at_earthlink.net)
Date: 06/17/04
- Next message: Scott McPhillips [MVP]: "Re: What do you use with Visual Studio 6.0"
- Previous message: Alexander Grigoriev: "Re: bug in time() related to DST?"
- In reply to: Mike Johnston: "bug in time() related to DST?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 17 Jun 2004 15:30:23 -0700
In MSVC 7, time() function is implemented with GetSystemTimeAsFileTime,
which supposedly should be more reliable. But I'm not sure if it completely
closes that short window of DST transition. If you want ANSI C function for
measuring intervals, use clock(). It won't suffer from any effects of DST
switch, even from transition.
"Mike Johnston" <MikeJohnston@discussions.microsoft.com> wrote in message
news:B027C4BB-0256-4867-88D2-7333AAC6C70F@microsoft.com...
> Hi,
>
> On the morning of April 4, several of the services we have running had an
error
> in comparing values of the time() function. Whne comparing the current
value of
> time() with a previous value (some few seconds ago) the difference was
> a large number. The code is looking for timeouts in field devices.
>
> I think there is a bug in time() and I would like either a confirmation or
> an indication of what the bug in my code is. If there is a bug, is there a
recommended workaround?
>
> The servers are running Win2000 Server. They have dual Xenon processors.
>
> The services generate logs that are timestamped to the ms with
GetLocalTime().
>
> I observed that the actual transition to Daylight Saving time occured at
about 600ms after the hour. I think this is crucial to the problem.
>
> In the time() function, the following calls are made.
> GetLocalTime( &loct );
> GetSystemTime( &gmt );
> GetTimeZoneInformation( &tzinfo );
>
> If the OS decides to switch to DST in between the first and third function
> call, the time data will be inconsistent.
>
> I have a second theory that is not defensible because I don't know
> the actual values. This seems plausible because this happened to all
> the services running on the server.
>
>
> In the time() function the information from GetTimeZoneInformation() is
cached. It is only refreshed 1 time per minute at the fastest rate.
>
> If a call to time() is made at 2:00:00.100 the TZ info will be standard
time.
> The call to GetLocalTime() will have the correct time and the time()
function
> will return the correct time.
>
> If a subsequent call to time() is made at 3:00:01.000 is made, the cached
TZ information will be incorrect and the return value from time() will be
off by 1 hour.
>
>
>
> Is this the correct interpretation of the time() function?
>
> Thanks
>
> --
> Mike Johnston
- Next message: Scott McPhillips [MVP]: "Re: What do you use with Visual Studio 6.0"
- Previous message: Alexander Grigoriev: "Re: bug in time() related to DST?"
- In reply to: Mike Johnston: "bug in time() related to DST?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|