summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-09-23 13:57:46 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-09-23 13:57:46 +0100
commit36c44ba6a88eeebecd019cc2766ad822d62c2739 (patch)
tree1cfc1139f9c12134199af62621a283b0ddc591c3
parentdebuginstallc shouldn't be built by default (diff)
downloadp2pvr-0.2.0.tar.bz2
p2pvr-0.2.0.tar.xz
p2pvr-0.2.0.zip
Fixes to workaround release date sometimes being an empty string :(p2pvr-0.2.0
-rw-r--r--libtmdb/Jamfile.jam1
-rw-r--r--libtmdb/conversions.cpp20
-rw-r--r--libtmdb/conversions.h13
-rw-r--r--libtmdb/tmdb-common.ice3
-rw-r--r--libtmdb/tmdb-models.ice4
5 files changed, 31 insertions, 10 deletions
diff --git a/libtmdb/Jamfile.jam b/libtmdb/Jamfile.jam
index 3144459..faf02b9 100644
--- a/libtmdb/Jamfile.jam
+++ b/libtmdb/Jamfile.jam
@@ -25,6 +25,7 @@ lib tmdb :
<library>curl
<library>adhocutil
<slicer>yes
+ <include>.
: :
<include>.
<library>Ice
diff --git a/libtmdb/conversions.cpp b/libtmdb/conversions.cpp
index 6df323d..7f291da 100644
--- a/libtmdb/conversions.cpp
+++ b/libtmdb/conversions.cpp
@@ -1,4 +1,4 @@
-#include <tmdb-common.h>
+#include "conversions.h"
#include <boost/numeric/conversion/cast.hpp>
#include <stdexcept>
@@ -6,22 +6,28 @@
namespace Slicer {
std::string
- dateToString(const ::TMDb::Date & in)
+ dateToString(const IceUtil::Optional<::TMDb::Date> & in)
{
+ if (!in) {
+ return std::string();
+ }
struct tm tm;
memset(&tm, 0, sizeof(struct tm));
- tm.tm_mday = in.Day;
- tm.tm_mon = in.Month;
- tm.tm_year = in.Year;
+ tm.tm_mday = in->Day;
+ tm.tm_mon = in->Month;
+ tm.tm_year = in->Year;
mktime(&tm);
char buf[BUFSIZ];
auto len = strftime(buf, BUFSIZ, "%Y-%m-%d", &tm);
return std::string(buf, len);
}
- ::TMDb::Date
+ IceUtil::Optional<::TMDb::Date>
stringToDate(const std::string & in)
{
+ if (in.empty()) {
+ return IceUtil::None;
+ }
struct tm tm;
memset(&tm, 0, sizeof(struct tm));
auto end = strptime(in.c_str(), "%Y-%m-%d", &tm);
@@ -29,7 +35,7 @@ namespace Slicer {
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) };
+ return ::TMDb::Date { SHORT(1900 + tm.tm_year), SHORT(1 + tm.tm_mon), SHORT(tm.tm_mday) };
}
}
diff --git a/libtmdb/conversions.h b/libtmdb/conversions.h
new file mode 100644
index 0000000..c64cf92
--- /dev/null
+++ b/libtmdb/conversions.h
@@ -0,0 +1,13 @@
+#ifndef LIBTMDB_OPTIONS_H
+#define LIBTMDB_OPTIONS_H
+
+#include <visibility.h>
+#include <tmdb-common.h>
+
+namespace Slicer {
+ DLL_PUBLIC std::string dateToString(const IceUtil::Optional<::TMDb::Date> &);
+ DLL_PUBLIC IceUtil::Optional<::TMDb::Date> stringToDate(const std::string &);
+}
+
+#endif
+
diff --git a/libtmdb/tmdb-common.ice b/libtmdb/tmdb-common.ice
index 1dec40f..3619af6 100644
--- a/libtmdb/tmdb-common.ice
+++ b/libtmdb/tmdb-common.ice
@@ -1,8 +1,9 @@
#ifndef TMDB_COMMON_ICE
#define TMDB_COMMON_ICE
+["slicer:include:conversions.h"]
module TMDb {
- ["slicer:conversion:std.string:stringToDate:dateToString"]
+ ["slicer:conversion:std.string:stringToDate:dateToString:nodeclare"]
struct Date {
short Year;
short Month;
diff --git a/libtmdb/tmdb-models.ice b/libtmdb/tmdb-models.ice
index 28d9b58..ae6bf90 100644
--- a/libtmdb/tmdb-models.ice
+++ b/libtmdb/tmdb-models.ice
@@ -47,7 +47,7 @@ module TMDb {
string OriginalTitle;
["slicer:name:release_date"]
- Date ReleaseDate;
+ optional(1) Date ReleaseDate;
["slicer:name:poster_path"]
string PosterPath;
@@ -161,7 +161,7 @@ module TMDb {
CountryRefList ProductionCountries;
["slicer:name:release_date"]
- Date ReleaseDate;
+ optional(1) Date ReleaseDate;
["slicer:name:revenue"]
long Revenue;