Re: [ros-users] ros::time to boost::posix_time::ptime

トップ ページ
添付ファイル:
Eメールのメッセージ
+ (text/plain)
このメッセージを削除
このメッセージに返信
著者: User discussions
日付:  
To: ros-users
題目: Re: [ros-users] ros::time to boost::posix_time::ptime
Hi

Thanks to Lorenz and William for the quick answer
It would be nice to enhance the code for a back conversion back to
ros::Time who is in charge for that?
The downside would be that the resolution will be reduced if boost
time is compiled for six fraction digits (mirosec).

void fromBoost ( const boost::posix_time::ptime &src, ros::Time &des ) const {
    boost::posix_time::time_duration diff = src -
boost::posix_time::from_time_t(0);
    des.sec = diff.total_seconds();
#if defined(BOOST_DATE_TIME_HAS_NANOSECONDS)
    des.nsec = diff.fractional_seconds();
#else
    #warning boost time uses only microseconds nanoseconds are lost
    des.nsec = diff.fractional_seconds()*1000;
#endif
}