diff options
Diffstat (limited to 'libtmdb/conversions.cpp')
-rw-r--r-- | libtmdb/conversions.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
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) }; } } |