source: trunk/poppler/mypoppler/poppler/DateInfo.cc @ 461

Last change on this file since 461 was 277, checked in by rbri, 12 years ago

PDF plugin: Poppler library updated to version 0.12.3

File size: 3.0 KB
Line 
1//========================================================================
2//
3// DateInfo.cc
4//
5// Copyright (C) 2008 Albert Astals Cid <aacid@kde.org>
6// Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
7//
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
10//
11//========================================================================
12
13//========================================================================
14//
15// Based on code from pdfinfo.cc
16//
17// Copyright 1998-2003 Glyph & Cog, LLC
18//
19//========================================================================
20
21#include <config.h>
22
23#include "DateInfo.h"
24
25#include <stdio.h>
26#include <string.h>
27
28/* See PDF Reference 1.3, Section 3.8.2 for PDF Date representation */
29GBool parseDateString(const char *dateString, int *year, int *month, int *day, int *hour, int *minute, int *second, char *tz, int *tzHour, int *tzMinute)
30{
31    if ( dateString == NULL ) return gFalse;
32    if ( strlen(dateString) < 2 ) return gFalse;
33
34    if ( dateString[0] == 'D' && dateString[1] == ':' )
35        dateString += 2;
36
37    *month = 1;
38    *day = 1;
39    *hour = 0;
40    *minute = 0;
41    *second = 0;
42    *tz = 0x00;
43    *tzHour = 0;
44    *tzMinute = 0;
45
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)
53        {
54           int century, years_since_1900;
55           if ( sscanf( dateString,
56                        "%2d%3d%2d%2d%2d%2d%2d",
57                        &century, &years_since_1900, month, day, hour, minute, second) == 7 )
58           {
59               *year = century * 100 + years_since_1900;
60           }
61           else
62           {
63               return gFalse;
64           }
65       }
66
67       if (*year <= 0) return gFalse;
68
69       return gTrue;
70   }
71
72   return gFalse;
73}
74
75
76GooString *timeToDateString(time_t *timet) {
77  GooString *dateString;
78  char s[5];
79  struct tm *gt;
80  size_t len;
81  time_t timep = timet ? *timet : time(NULL);
82 
83#ifdef HAVE_GMTIME_R
84  struct tm t;
85  gt = gmtime_r (&timep, &t);
86#else
87  gt = gmtime (&timep);
88#endif
89
90  dateString = new GooString ("D:");
91
92  /* Year YYYY */
93  len = strftime (s, sizeof(s), "%Y", gt);
94  dateString->append (s, len);
95
96  /* Month MM */
97  len = strftime (s, sizeof(s), "%m", gt);
98  dateString->append (s, len);
99
100  /* Day DD */
101  len = strftime (s, sizeof(s), "%d", gt);
102  dateString->append (s, len);
103
104  /* Hour HH */
105  len = strftime (s, sizeof(s), "%H", gt);
106  dateString->append (s, len);
107
108  /* Minute mm */
109  len = strftime (s, sizeof(s), "%M", gt);
110  dateString->append (s, len);
111
112  /* Second SS */
113  len = strftime (s, sizeof(s), "%S", gt);
114  dateString->append (s, len);
115
116  return dateString;
117}
118
Note: See TracBrowser for help on using the repository browser.