Boost logo

Boost Users :

From: Paolo Coletta (paolo_at_[hidden])
Date: 2005-06-02 04:34:01


I needed something to convert the difference between two xtime values to
microseconds, so I looked at the to_microduration function in
time_conv.inl and I guess that there is a bug there. The if should be:

if (boost::xtime_cmp(xt, cur) <= 0)
    microseconds = 0;
else
    ...

In facts, the intent of the if condition seems to be avoiding negative
return values, as for the to_duration function.

Current code is:

inline void to_microduration(const boost::xtime& xt, int& microseconds)
{
    boost::xtime cur;
    int res = 0;
    res = boost::xtime_get(&cur, boost::TIME_UTC);
    assert(res == boost::TIME_UTC);

    if (boost::xtime_get(&cur, boost::TIME_UTC) <= 0)
        microseconds = 0;
    else
    {
        microseconds = (int)((xt.sec - cur.sec) * MICROSECONDS_PER_SECOND) +
            (((xt.nsec - cur.nsec) + (NANOSECONDS_PER_MICROSECOND/2)) /
                NANOSECONDS_PER_MICROSECOND);
    }
}

Paolo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net