|
Boost : |
From: martin troxler (martin.troxler_at_[hidden])
Date: 2005-05-12 03:37:25
It is possible, that the following line
boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
which invokes
template<class time_type>
class microsec_clock
{
static time_type local_time() {
timeval tv;
gettimeofday(&tv, 0); //gettimeofday does not support TZ adjust on Linux.
return create_time(&tv);
}
static time_type create_time(timeval* tv) {
time_t t = tv->tv_sec;
boost::uint32_t fs = tv->tv_usec;
::std::time(&t);
tm* curr = localtime(&t);
....
returns a time with 1s off its correct value.
The reason for this bug is the line with
::std::time(&t);
that overwrites the second value just a few µs after the call to gettimofday.
This new second value is used together with the fs value from gettimeofday.
Example:
tv from gettimofday: 12345s/999998 µs
t from std::time: 12346s
resulting time: 12346s/999998 µs !!!!
Question: Why this call to std::time? I commented it out and it worked.
Regards
Martin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk