Boost logo

Boost :

From: Stefan Seefeld (seefeld_at_[hidden])
Date: 2003-06-23 08:21:36


Jeff Garland wrote:

>>I'd like to replace my code by boost::date_time, but conversion
>>from boost::date_time to timeval doesn't seem to be supported.
>
>
> You are right, but this would make a nice addition.

I'd suggest these two converters to be added:

timeval to_timeval(const ptime &t)
{
   ptime timet_start(date(1970,1,1));
   time_duration diff = t - timet_start;
   timeval tv;
   //drop off the fractional seconds...
   tv.tv_sec = diff.ticks()/time_duration::rep_type::res_adjust();
   //The following only works with microsecond resolution!
   tv.tv_usec = diff.fractional_seconds();
   return tv;
}

timeval to_timeval(const time_duration &d)
{
   timeval tv;
   //drop off the fractional seconds...
   tv.tv_sec = d.ticks()/pt::time_duration::rep_type::res_adjust();
   //The following only works with microsecond resolution!
   tv.tv_usec = d.fractional_seconds();
   return tv;
}

the latter is especially useful as select() operates with durations,
so there is no need to convert between 1970-01-01 relative dates and
ptime...

Regards,
                Stefan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk