[gs-cvs] rev 8291 - trunk/gs/src
ken at ghostscript.com
ken at ghostscript.com
Mon Oct 15 06:11:17 PDT 2007
Author: ken
Date: 2007-10-15 06:11:16 -0700 (Mon, 15 Oct 2007)
New Revision: 8291
Modified:
trunk/gs/src/gdevpdf.c
Log:
pdfwrite: When writing the /CreationDate /ModDate keys in the Info dictionary,
properly write the system local time instead of UTC.
DETAILS:
Bug #688783 "commit 6892 mis-uses the TZ environmental"
A rather lengthy thread, but in essence quite simple. A change to calculate
the system local time as an offset from UTC, and store this information in
the form described in the PDF Reference (Section 3.8.3 "Dates" on p133 of
the 1.6 PDF Reference).
The patch uses code supplied by SaGS.
(gdevpdf.c) pdf_initialize_ids, use the C runtime 'time' and 'gmtime' to
determine the difference between local system time and GMT. Use this to
calculate the difference (positive, negative, or none) from GMT, and the
number of hours and minutes comprising the difference. Use 'localtime' to
find the local system date and time.
Take all of the information from above, and format the result according to
the specification in the PDF Reference:
(D:YYYYMMDDhhmmssZhh'mm')
Where YYYY=4 digit local time year
MM=2 digit local time month
DD=2 digit local time day
hh=2 digit local time hours (24 hour)
mm=2 digit local time minutes
ss=2 digit local time seconds
Z=offset of local time from UTC
Z=no difference
+=local time later than UTC
-=local time earlier than UTC
hh'=hours difference between local time and UTC
mm'=minutes difference between local time and UTC
EXPECTED DIFFERENCES:
None
Modified: trunk/gs/src/gdevpdf.c
===================================================================
--- trunk/gs/src/gdevpdf.c 2007-10-15 06:43:04 UTC (rev 8290)
+++ trunk/gs/src/gdevpdf.c 2007-10-15 13:11:16 UTC (rev 8291)
@@ -273,16 +273,25 @@
* PostScript file. We think this is wrong, but we do the same.
*/
{
- struct tm tms;
+ struct tm tms;
time_t t;
- char buf[1+2+4+2+2+2+2+2+2+1+1+7]; /* (D:yyyymmddhhmmssZhh'mm')\0 */
+ char buf[1+2+4+2+2+2+2+2+1+2+1+2+1+1+1]; /* (D:yyyymmddhhmmssZhh'mm')\0 */
+ int timeoffset;
+ char timesign;
time(&t);
tms = *gmtime(&t);
- sprintf(buf,
- "(D:%04d%02d%02d%02d%02d%02dZ)",
- tms.tm_year + 1900, tms.tm_mon + 1, tms.tm_mday,
- tms.tm_hour, tms.tm_min, tms.tm_sec);
+ tms.tm_isdst = -1;
+ timeoffset = (int)difftime(t, mktime(&tms)); /* tz+dst in seconds */
+ timesign = (timeoffset == 0 ? 'Z' : timeoffset < 0 ? '-' : '+');
+ timeoffset = any_abs(timeoffset) / 60;
+ tms = *localtime(&t);
+
+ sprintf(buf, "(D:%04d%02d%02d%02d%02d%02d%c%02d\'%02d\')",
+ tms.tm_year + 1900, tms.tm_mon + 1, tms.tm_mday,
+ tms.tm_hour, tms.tm_min, tms.tm_sec,
+ timesign, timeoffset / 60, timeoffset % 60);
+
cos_dict_put_c_key_string(pdev->Info, "/CreationDate", (byte *)buf,
strlen(buf));
cos_dict_put_c_key_string(pdev->Info, "/ModDate", (byte *)buf,
More information about the gs-cvs
mailing list