[poppler] poppler/qt4/src: poppler-document.cc, 1.10, 1.11 poppler-qt4.h, 1.18, 1.19

Brad Hards bradh at freedesktop.org
Mon Dec 26 22:10:03 PST 2005


Update of /cvs/poppler/poppler/qt4/src
In directory gabe:/tmp/cvs-serv12644/qt4/src

Modified Files:
	poppler-document.cc poppler-qt4.h 
Log Message:
qt4/src/poppler-qt4.h and qt4/src/poppler-document.cc: add convertDate() function that
turns char* PDF date strings into QDateTime. This version handles
the timezone conversions. Refactored the existing date() method
to use it.

qt4/tests/check_dateConversion.cpp: unit tests for convertDate()
qt4/tests/check_metadata.cpp: update to reflect UTC.
qt4/tests/.cvsignore: suppress check_dateConversion



Index: poppler-document.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-document.cc,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- poppler-document.cc	7 Dec 2005 08:31:09 -0000	1.10
+++ poppler-document.cc	27 Dec 2005 06:10:01 -0000	1.11
@@ -280,43 +280,15 @@
 	char *s;
 	int year, mon, day, hour, min, sec;
 	Dict *infoDict = info.getDict();
-	QString result;
+	QDateTime result;
 
 	if ( infoDict->lookup( type.toLatin1().data(), &obj )->isString() )
 	{
-	    s = obj.getString()->getCString();
-	    if ( s[0] == 'D' && s[1] == ':' )
-		s += 2;
-	    /* FIXME process time zone on systems that support it */  
-	    if ( sscanf( s, "%4d%2d%2d%2d%2d%2d", &year, &mon, &day, &hour, &min, &sec ) == 6 )
-	    {
-		/* Workaround for y2k bug in Distiller 3 stolen from gpdf, hoping that it won't
-		 *   * be used after y2.2k */
-		if ( year < 1930 && strlen (s) > 14) {
-		    int century, years_since_1900;
-		    if ( sscanf( s, "%2d%3d%2d%2d%2d%2d%2d",
-				 &century, &years_since_1900,
-				 &mon, &day, &hour, &min, &sec) == 7 )
-			year = century * 100 + years_since_1900;
-		    else {
-			obj.free();
-			info.free();
-			return QDateTime();
-		    }
-		}
-
-		QDate d( year, mon, day );  //CHECK: it was mon-1, Jan->0 (??)
-		QTime t( hour, min, sec );
-		if ( d.isValid() && t.isValid() ) {
-		    obj.free();
-		    info.free();
-		    return QDateTime( d, t );
-		}
-	    }
+	    result = Poppler::convertDate(obj.getString()->getCString());
 	}
 	obj.free();
 	info.free();
-	return QDateTime();
+	return result;
     }
 
     bool Document::isEncrypted() const
@@ -390,4 +362,59 @@
 	return page(index);
     }
 
+    QDateTime convertDate( char *dateString )
+    {
+        int year;
+        int mon = 1;
+        int day = 1;
+        int hour = 0;
+        int min = 0;
+        int sec = 0;
+        char tz = 0x00;
+        int tzHours = 0;
+        int tzMins = 0;
+
+        if ( dateString[0] == 'D' && dateString[1] == ':' )
+            dateString += 2;
+        if ( sscanf( dateString,
+		     "%4d%2d%2d%2d%2d%2d%c%2d%*c%2d",
+		     &year, &mon, &day, &hour, &min, &sec,
+		     &tz, &tzHours, &tzMins ) > 0 ) {
+            /* Workaround for y2k bug in Distiller 3 stolen from gpdf, hoping that it won't
+             * be used after y2.2k */
+            if ( year < 1930 && strlen (dateString) > 14) {
+                int century, years_since_1900;
+                if ( sscanf( dateString, "%2d%3d%2d%2d%2d%2d%2d",
+                             &century, &years_since_1900,
+                             &mon, &day, &hour, &min, &sec) == 7 )
+                    year = century * 100 + years_since_1900;
+                else {
+                    return QDateTime();
+                }
+            }
+
+            QDate d( year, mon, day );
+            QTime t( hour, min, sec );
+            if ( d.isValid() && t.isValid() ) {
+                QDateTime dt( d, t, Qt::UTC );
+                if ( tz ) {
+                    // then we have some form of timezone
+                    if ( 'Z' == tz  ) {
+                        // We are already at UTC
+                    } else if ( '+' == tz ) {
+                        // local time is ahead of UTC
+                        dt = dt.addSecs(-1*((tzHours*60)+tzMins)*60);
+                    } else if ( '-' == tz ) {
+                        // local time is behind UTC
+                        dt = dt.addSecs(((tzHours*60)+tzMins)*60);
+                    } else {
+                        qWarning("unexpected tz val");
+                    }
+                }
+                return dt;
+            }
+        }
+        return QDateTime();
+    }
+
 }

Index: poppler-qt4.h
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-qt4.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- poppler-qt4.h	27 Dec 2005 05:08:34 -0000	1.18
+++ poppler-qt4.h	27 Dec 2005 06:10:01 -0000	1.19
@@ -531,6 +531,11 @@
 	Document::Document(DocumentData *dataA);
     };
 
+    /**
+       Conversion from PDF date string format to QDateTime
+    */
+    QDateTime convertDate( char *dateString );
+
 }
 #endif
 



More information about the poppler mailing list