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

Last change on this file since 257 was 257, checked in by Eugene Romanenko, 13 years ago

PDF plugin: Poppler library updated to version 0.10.0

File size: 2.0 KB
Line 
1//========================================================================
2//
3// DateInfo.cc
4//
5// Copyright (C) 2008 Albert Astals Cid <aacid@kde.org>
6//
7// To see a description of the changes please see the Changelog file that
8// came with your tarball or type make ChangeLog if you are building from git
9//
10//========================================================================
11
12//========================================================================
13//
14// Based on code from pdfinfo.cc
15//
16// Copyright 1998-2003 Glyph & Cog, LLC
17//
18//========================================================================
19
20#include "DateInfo.h"
21
22#include <stdio.h>
23#include <string.h>
24
25/* See PDF Reference 1.3, Section 3.8.2 for PDF Date representation */
26GBool parseDateString(const char *dateString, int *year, int *month, int *day, int *hour, int *minute, int *second, char *tz, int *tzHour, int *tzMinute)
27{
28    if ( dateString == NULL ) return gFalse;
29    if ( strlen(dateString) < 2 ) return gFalse;
30
31    if ( dateString[0] == 'D' && dateString[1] == ':' )
32        dateString += 2;
33
34    *month = 1;
35    *day = 1;
36    *hour = 0;
37    *minute = 0;
38    *second = 0;
39    *tz = 0x00;
40    *tzHour = 0;
41    *tzMinute = 0;
42
43    if ( sscanf( dateString,
44                 "%4d%2d%2d%2d%2d%2d%c%2d%*c%2d",
45                 year, month, day, hour, minute, second,
46                 tz, tzHour, tzMinute ) > 0 ) {
47        /* Workaround for y2k bug in Distiller 3 stolen from gpdf, hoping that it won't
48        * be used after y2.2k */
49        if ( *year < 1930 && strlen (dateString) > 14)
50        {
51           int century, years_since_1900;
52           if ( sscanf( dateString,
53                        "%2d%3d%2d%2d%2d%2d%2d",
54                        &century, &years_since_1900, month, day, hour, minute, second) == 7 )
55           {
56               *year = century * 100 + years_since_1900;
57           }
58           else
59           {
60               return gFalse;
61           }
62       }
63
64       if (*year <= 0) return gFalse;
65
66       return gTrue;
67   }
68
69   return gFalse;
70}
Note: See TracBrowser for help on using the repository browser.