summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2008-08-29 23:06:19 +0200
committerAlbert Astals Cid <aacid@kde.org>2008-08-29 23:06:19 +0200
commit8f1deb3f8000bdeb845a6c786a654bc7eb684f0a (patch)
treee0d00d4c1aec2b6fe53ef1836887d384a8d5862d /utils
parentc39f23dca98d3efe8d094c9a3e1bd460ba57d1ce (diff)
Are we a lib or aren't we? Unify String to Date parsing so we all behave the same way
Diffstat (limited to 'utils')
-rw-r--r--utils/pdfinfo.cc16
-rw-r--r--utils/pdftohtml.cc9
2 files changed, 6 insertions, 19 deletions
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index a7f81d38..df54862b 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -43,6 +43,7 @@
#include "UnicodeMap.h"
#include "PDFDocEncoding.h"
#include "Error.h"
+#include "DateInfo.h"
static void printInfoString(Dict *infoDict, char *key, char *text,
UnicodeMap *uMap);
@@ -366,25 +367,14 @@ static void printInfoString(Dict *infoDict, char *key, char *text,
static void printInfoDate(Dict *infoDict, char *key, char *text) {
Object obj;
char *s;
- int year, mon, day, hour, min, sec, n;
+ int year, mon, day, hour, min, sec;
struct tm tmStruct;
char buf[256];
if (infoDict->lookup(key, &obj)->isString()) {
fputs(text, stdout);
s = obj.getString()->getCString();
- if (s[0] == 'D' && s[1] == ':') {
- s += 2;
- }
- if ((n = sscanf(s, "%4d%2d%2d%2d%2d%2d",
- &year, &mon, &day, &hour, &min, &sec)) >= 1) {
- switch (n) {
- case 1: mon = 1;
- case 2: day = 1;
- case 3: hour = 0;
- case 4: min = 0;
- case 5: sec = 0;
- }
+ if ( parseDateString( s, &year, &mon, &day, &hour, &min, &sec ) ) {
tmStruct.tm_year = year - 1900;
tmStruct.tm_mon = mon - 1;
tmStruct.tm_mday = day;
diff --git a/utils/pdftohtml.cc b/utils/pdftohtml.cc
index ede4c813..86284411 100644
--- a/utils/pdftohtml.cc
+++ b/utils/pdftohtml.cc
@@ -42,6 +42,7 @@
#include "PSOutputDev.h"
#include "GlobalParams.h"
#include "Error.h"
+#include "DateInfo.h"
#include "goo/gfile.h"
#ifndef GHOSTSCRIPT
@@ -410,11 +411,7 @@ static GooString* getInfoDate(Dict *infoDict, char *key) {
if (infoDict->lookup(key, &obj)->isString()) {
s = obj.getString()->getCString();
- if (s[0] == 'D' && s[1] == ':') {
- s += 2;
- }
- if (sscanf(s, "%4d%2d%2d%2d%2d%2d",
- &year, &mon, &day, &hour, &min, &sec) == 6) {
+ if ( parseDateString( s, &year, &mon, &day, &hour, &min, &sec ) ) {
tmStruct.tm_year = year - 1900;
tmStruct.tm_mon = mon - 1;
tmStruct.tm_mday = day;
@@ -426,7 +423,7 @@ static GooString* getInfoDate(Dict *infoDict, char *key) {
tmStruct.tm_isdst = -1;
mktime(&tmStruct); // compute the tm_wday and tm_yday fields
if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S+00:00", &tmStruct)) {
- result = new GooString(buf);
+ result = new GooString(buf);
} else {
result = new GooString(s);
}