"" <> writes:
> I have some old data files with old timestamps, where
> timestmap=time(NULL), some of them date back to the
> year 1999.
>
> I want to my code to print the timestamps and each one to
> include hour:minute:second as of the corresponding old day.
> The only routine for this job seems to be
> localtime(timestmap) - this is Windows Vista,
> Visual Studio 2005 C++.
>
> localtime() seems to consider the presence of Daylight Saving
> Time for the current day when it is actually called, but it does
> not seem to consider the presence of Daylight Saving Time
> for the old day.
[...]
It sounds like your system's implementation of localtime() is buggy.
There may not be much you can do to correct it, but workarounds are
possible.
> For example, I run localtime on a timestamp from 3-22-1999
> (Daylight Saving Time was not effective yet) today when Daylight
> Saving Time is effective and localtime() returns hour:minute:second
> one hour later as it should.
>
> Does it mean that the only way around it is to keep transition
> dates for Daylight Saving Time for all years and have my code
> make the adjustments depending on the old day and the current
> day? Is there any utility to do that or any better way?
That would be one solution, but it could break if a future version of
your implementation corrects the bug in localtime().
An alternative might be to use gmtime() and do the conversion to local
time yourself. But that requires knowing about the time zone, which
varies from place to place, within a year (as DST comes and goes), and
over history (as DST rules change, either nationally or locally).
I think there are time zone libraries that already include much of
this information (<OT>Googling "tzdata" may be helpful</OT>).
It's also likely that there's a system-specific solution. Try a
newsgroup that deals with Windows and/or with Visual Studio 2005 C++.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"