From ed7ae32a69bd623226011571dbf87bae270b7a50 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 1 May 2010 17:37:12 +0000 Subject: [PATCH] Made datetime parsing more reliable --- src/misc.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index 0833caabb..3d40370eb 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -483,9 +483,15 @@ QString misc::magnetUriToHash(QString magnet_uri) { } QString misc::boostTimeToQString(const boost::optional boostDate) { - if(!boostDate) return tr("Unknown"); + if(!boostDate || !boostDate.is_initialized() || boostDate->is_not_a_date_time()) return tr("Unknown"); struct std::tm tm = boost::posix_time::to_tm(*boostDate); - return QDateTime::fromTime_t(mktime(&tm)).toString(Qt::DefaultLocaleLongDate); + time_t t = mktime(&tm); + if(t < 0) + return tr("Unknown"); + QDateTime dt = QDateTime::fromTime_t(t); + if(dt.isNull() || !dt.isValid()) + return tr("Unknown"); + return dt.toString(Qt::DefaultLocaleLongDate); } // Replace ~ in path