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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to