From dc226d8dec948a104f9c6ecb9f08f1efacc4b214 Mon Sep 17 00:00:00 2001 From: randomdan Date: Tue, 4 Mar 2014 23:16:09 +0000 Subject: Incorperate proper datetimes and durations now the core does --- p2pvr/ice/commonHelpers.cpp | 55 +++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 32 deletions(-) (limited to 'p2pvr/ice/commonHelpers.cpp') 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 -#include +#include 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(dt.time_of_day().hours()), + boost::numeric_cast(dt.time_of_day().minutes()) }; + } + + Common::Duration operator*(const boost::posix_time::time_duration & d) + { + return { + boost::numeric_cast(d.hours()), + boost::numeric_cast(d.minutes()) }; } - return mktime(&dt) + (seconds + (60 * (minutes + (60 * hours)))); } } -- cgit v1.2.3