OSDN Git Service

okular: handle negative dates in okularTime() function
authorIvailo Monev <xakepa10@gmail.com>
Tue, 1 Aug 2023 04:00:06 +0000 (04:00 +0000)
committerIvailo Monev <xakepa10@gmail.com>
Tue, 1 Aug 2023 04:00:06 +0000 (04:00 +0000)
poppler::get_creation_date() and the other date-related functions are not
documented to return such but it happens

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
okular/generators/poppler/generator_pdf.cpp

index 2479f17..99d1b03 100644 (file)
@@ -13,7 +13,6 @@
 #include <qpainter.h>
 #include <kaboutdata.h>
 #include <klocale.h>
-#include <kdatetime.h>
 #include <kdebug.h>
 #include <kglobal.h>
 
@@ -48,8 +47,12 @@ static QString okularString(const poppler::ustring &popplerstring)
 
 static QString okularTime(const popplertimetype &popplertime)
 {
-    const KDateTime kdatetime(QDateTime::fromTime_t(popplertime));
-    return KGlobal::locale()->formatDateTime(kdatetime, QLocale::NarrowFormat);
+    if (popplertime <= 0) {
+        // -1, i.e. not set
+        return QString();
+    }
+    const QDateTime qdatetime(QDateTime::fromTime_t(popplertime));
+    return KGlobal::locale()->formatDateTime(qdatetime, QLocale::NarrowFormat);
 }
 
 static QDateTime okularDateTime(const popplertimetype &popplertime)