diff options
| author | randomdan <randomdan@localhost> | 2014-03-04 23:16:09 +0000 |
|---|---|---|
| committer | randomdan <randomdan@localhost> | 2014-03-04 23:16:09 +0000 |
| commit | dc226d8dec948a104f9c6ecb9f08f1efacc4b214 (patch) | |
| tree | 17d84c075a7bfdf03aa485dbb26504b76ff56e69 /p2pvr/ice/commonHelpers.cpp | |
| parent | Add an SI function to get a transport suitable for getting SI based on the de... (diff) | |
| download | p2pvr-dc226d8dec948a104f9c6ecb9f08f1efacc4b214.tar.bz2 p2pvr-dc226d8dec948a104f9c6ecb9f08f1efacc4b214.tar.xz p2pvr-dc226d8dec948a104f9c6ecb9f08f1efacc4b214.zip | |
Incorperate proper datetimes and durations now the core does
Diffstat (limited to 'p2pvr/ice/commonHelpers.cpp')
| -rw-r--r-- | p2pvr/ice/commonHelpers.cpp | 55 |
1 files changed, 23 insertions, 32 deletions
diff --git a/p2pvr/ice/commonHelpers.cpp b/p2pvr/ice/commonHelpers.cpp index 64a1c61..46c7fad 100644 --- a/p2pvr/ice/commonHelpers.cpp +++ b/p2pvr/ice/commonHelpers.cpp @@ -1,46 +1,37 @@ #include "commonHelpers.h" #include <misc.h> -#include <boost/format.hpp> +#include <boost/numeric/conversion/cast.hpp> namespace Common { - std::string operator-(const Common::DateTime & a, const Common::DateTime & b) + boost::posix_time::ptime operator*(const Common::DateTime & dt) { - struct tm tma { - 0, a.Minute, a.Hour, - a.Day, a.Month - 1, a.Year - 1900, - 0, 0, 0, 0, 0}; - struct tm tmb { - 0, b.Minute, b.Hour, - b.Day, b.Month - 1, b.Year - 1900, - 0, 0, 0, 0, 0}; - auto secs = mktime(&tma) - mktime(&tmb); - return stringbf("%02d:%02d:%02d", secs / 3600, (secs / 60) % 60, secs % 60); + return boost::posix_time::ptime( + boost::gregorian::date(dt.Year, dt.Month, dt.Day), + boost::posix_time::time_duration(dt.Hour, dt.Minute, 0)); } - time_t operator-(const Common::DateTime & cdt, const std::string & interval) + boost::posix_time::time_duration operator*(const Common::Duration & d) { - struct tm dt { - 0, cdt.Minute, cdt.Hour, - cdt.Day, cdt.Month - 1, cdt.Year - 1900, - 0, 0, 0, 0, 0}; - unsigned short hours, minutes, seconds; - if (sscanf(interval.c_str(), "%hu:%hu:%hu", &hours, &minutes, &seconds) < 3) { - throw std::runtime_error("Couldn't parse interval"); - } - return mktime(&dt) - (seconds + (60 * (minutes + (60 * hours)))); + return boost::posix_time::time_duration(d.Hour, d.Minute, 0); } +} - time_t operator+(const Common::DateTime & cdt, const std::string & interval) - { - struct tm dt { - 0, cdt.Minute, cdt.Hour, - cdt.Day, cdt.Month - 1, cdt.Year - 1900, - 0, 0, 0, 0, 0}; - unsigned short hours, minutes, seconds; - if (sscanf(interval.c_str(), "%hu:%hu:%hu", &hours, &minutes, &seconds) < 3) { - throw std::runtime_error("Couldn't parse interval"); +namespace boost { + namespace posix_time { + Common::DateTime operator*(const boost::posix_time::ptime & dt) + { + return { + dt.date().year(), dt.date().month(), dt.date().day(), + boost::numeric_cast<short>(dt.time_of_day().hours()), + boost::numeric_cast<short>(dt.time_of_day().minutes()) }; + } + + Common::Duration operator*(const boost::posix_time::time_duration & d) + { + return { + boost::numeric_cast<short>(d.hours()), + boost::numeric_cast<short>(d.minutes()) }; } - return mktime(&dt) + (seconds + (60 * (minutes + (60 * hours)))); } } |
