summaryrefslogtreecommitdiff
path: root/libtmdb/conversions.cpp
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2014-09-19 23:52:30 +0000
committerrandomdan <randomdan@localhost>2014-09-19 23:52:30 +0000
commit28691c29e93fbc4fdb5ae4866287282840fba021 (patch)
tree8b83ca80afc3f3a5d11b04a56c440d2aa38f4e16 /libtmdb/conversions.cpp
parentSupport muxing directly in storage (diff)
downloadp2pvr-28691c29e93fbc4fdb5ae4866287282840fba021.tar.bz2
p2pvr-28691c29e93fbc4fdb5ae4866287282840fba021.tar.xz
p2pvr-28691c29e93fbc4fdb5ae4866287282840fba021.zip
First bash at a slicer ice proxy for TMDb and an untested instantiation in p2pvr's core adapter
Diffstat (limited to 'libtmdb/conversions.cpp')
-rw-r--r--libtmdb/conversions.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/libtmdb/conversions.cpp b/libtmdb/conversions.cpp
new file mode 100644
index 0000000..488419f
--- /dev/null
+++ b/libtmdb/conversions.cpp
@@ -0,0 +1,35 @@
+#include <tmdb-common.h>
+#include <boost/numeric/conversion/cast.hpp>
+#include <stdexcept>
+
+#define SHORT(x) boost::numeric_cast< ::Ice::Short >(x)
+
+namespace Slicer {
+ std::string
+ dateToString(const ::TMDb::Date & in)
+ {
+ char buf[BUFSIZ];
+ struct tm tm({ 0, 0, 0, in.Day, in.Month, in.Year, 0, 0, 0
+#ifdef _BSD_SOURCE
+ , 0, 0
+#endif
+ });
+ mktime(&tm);
+ auto len = strftime(buf, BUFSIZ, "%Y-%m-%d", &tm);
+ return std::string(buf, len);
+ }
+
+ ::TMDb::Date
+ stringToDate(const std::string & in)
+ {
+ struct tm tm;
+ memset(&tm, 0, sizeof(struct tm));
+ auto end = strptime(in.c_str(), "%Y-%m-%d", &tm);
+ mktime(&tm);
+ if (!end || *end) {
+ throw std::runtime_error("Invalid date string: " + in);
+ }
+ return { SHORT(1900 + tm.tm_year), SHORT(1 + tm.tm_mon), SHORT(tm.tm_mday) };
+ }
+
+}