From 36c44ba6a88eeebecd019cc2766ad822d62c2739 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 23 Sep 2017 13:57:46 +0100 Subject: Fixes to workaround release date sometimes being an empty string :( --- libtmdb/Jamfile.jam | 1 + libtmdb/conversions.cpp | 20 +++++++++++++------- libtmdb/conversions.h | 13 +++++++++++++ libtmdb/tmdb-common.ice | 3 ++- libtmdb/tmdb-models.ice | 4 ++-- 5 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 libtmdb/conversions.h 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 : curl adhocutil yes + . : : . 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 +#include "conversions.h" #include #include @@ -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 +#include + +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; -- cgit v1.2.3