diff options
| author | randomdan <randomdan@localhost> | 2014-01-09 20:31:18 +0000 |
|---|---|---|
| committer | randomdan <randomdan@localhost> | 2014-01-09 20:31:18 +0000 |
| commit | 800ab74ea27ca22aa62e953cbc012989c23c34ca (patch) | |
| tree | 67161266c9deb51cf8bb57d91401652c26f6ebc2 /p2pvr/ice/commonHelpers.cpp | |
| parent | Makefile scripts for updating schema/database (diff) | |
| download | p2pvr-800ab74ea27ca22aa62e953cbc012989c23c34ca.tar.bz2 p2pvr-800ab74ea27ca22aa62e953cbc012989c23c34ca.tar.xz p2pvr-800ab74ea27ca22aa62e953cbc012989c23c34ca.zip | |
Basic implementation of a recorder
Diffstat (limited to 'p2pvr/ice/commonHelpers.cpp')
| -rw-r--r-- | p2pvr/ice/commonHelpers.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/p2pvr/ice/commonHelpers.cpp b/p2pvr/ice/commonHelpers.cpp new file mode 100644 index 0000000..64a1c61 --- /dev/null +++ b/p2pvr/ice/commonHelpers.cpp @@ -0,0 +1,46 @@ +#include "commonHelpers.h" +#include <misc.h> +#include <boost/format.hpp> + +namespace Common { + std::string operator-(const Common::DateTime & a, const Common::DateTime & b) + { + 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); + } + + 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"); + } + return mktime(&dt) - (seconds + (60 * (minutes + (60 * hours)))); + } + + 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"); + } + return mktime(&dt) + (seconds + (60 * (minutes + (60 * hours)))); + } +} + |
