1 //========================================================================
5 // Copyright (C) 2008 Albert Astals Cid <aacid@kde.org>
6 // Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
8 // To see a description of the changes please see the Changelog file that
9 // came with your tarball or type make ChangeLog if you are building from git
11 //========================================================================
13 //========================================================================
15 // Based on code from pdfinfo.cc
17 // Copyright 1998-2003 Glyph & Cog, LLC
19 //========================================================================
28 /* See PDF Reference 1.3, Section 3.8.2 for PDF Date representation */
29 GBool
parseDateString(const char *dateString
, int *year
, int *month
, int *day
, int *hour
, int *minute
, int *second
, char *tz
, int *tzHour
, int *tzMinute
)
31 if ( dateString
== NULL
) return gFalse
;
32 if ( strlen(dateString
) < 2 ) return gFalse
;
34 if ( dateString
[0] == 'D' && dateString
[1] == ':' )
46 if ( sscanf( dateString
,
47 "%4d%2d%2d%2d%2d%2d%c%2d%*c%2d",
48 year
, month
, day
, hour
, minute
, second
,
49 tz
, tzHour
, tzMinute
) > 0 ) {
50 /* Workaround for y2k bug in Distiller 3 stolen from gpdf, hoping that it won't
51 * be used after y2.2k */
52 if ( *year
< 1930 && strlen (dateString
) > 14)
54 int century
, years_since_1900
;
55 if ( sscanf( dateString
,
56 "%2d%3d%2d%2d%2d%2d%2d",
57 ¢ury
, &years_since_1900
, month
, day
, hour
, minute
, second
) == 7 )
59 *year
= century
* 100 + years_since_1900
;
67 if (*year
<= 0) return gFalse
;
76 GooString
*timeToDateString(time_t *timet
) {
77 GooString
*dateString
;
81 time_t timep
= timet
? *timet
: time(NULL
);
85 gt
= gmtime_r (&timep
, &t
);
90 dateString
= new GooString ("D:");
93 len
= strftime (s
, sizeof(s
), "%Y", gt
);
94 dateString
->append (s
, len
);
97 len
= strftime (s
, sizeof(s
), "%m", gt
);
98 dateString
->append (s
, len
);
101 len
= strftime (s
, sizeof(s
), "%d", gt
);
102 dateString
->append (s
, len
);
105 len
= strftime (s
, sizeof(s
), "%H", gt
);
106 dateString
->append (s
, len
);
109 len
= strftime (s
, sizeof(s
), "%M", gt
);
110 dateString
->append (s
, len
);
113 len
= strftime (s
, sizeof(s
), "%S", gt
);
114 dateString
->append (s
, len
);