I am working on a project involving many measurements and I would like to use boost units to ensure that units are converted correctly. I started by introducing some typedefs to simplify notation:
#include <boost/units/cmath.hpp>
#include <boost/units/io.hpp>
#include <boost/units/systems/si.hpp>
#include <boost/units/systems/si/io.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
namespace Time = boost::posix_time;
typedef Time::ptime DateTime;
typedef Time::time_duration Duration;
namespace Units
{
using namespace boost::units;
namespace SI
{
using namespace boost::units::si;
}
template <class U> using Quantity = quantity<U>;
typedef Quantity<SI::length> Length;
typedef Quantity<SI::velocity> Velocity;
typedef Quantity<SI::time> Time;
}
I have written some code to compute distances and travel times using these units:
// a computation of distances which yields a length
Units::Length distance = origin.distance(destination);
Units::Velocity flight_speed(100 * Units::SI::meter / Units::SI::second);
Units::Time flight_time = distance / flight_speed;
DateTime departure_time = ...
DateTime arrival_time = departure_time + flight_time; // does not work..
This leads to my question: Is there some built-in way to convert between a Duration
(aka boost::posix_time::time_duration
) and time_duration
Units::Quantity<SI::time>
(aka boost::units::quantity<boost::units::si::time>
)? It seems like this should be built-in, but I did not find anything in the documentation about it.