From 1c9c25bd5bef114bdc176ee8554fe0cd34183be2 Mon Sep 17 00:00:00 2001 From: Glenn Adams Date: Wed, 9 May 2012 12:20:34 +0000 Subject: Bugzilla #53185: Unify date formatting between FOP and XGC as well as tidying the date format code. Submitted by Robert Meyer. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1336129 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/pdf/PDFInfo.java | 55 +++----------------------------- 1 file changed, 5 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/java/org/apache/fop/pdf/PDFInfo.java b/src/java/org/apache/fop/pdf/PDFInfo.java index d457c2888..2cfcc7d3b 100644 --- a/src/java/org/apache/fop/pdf/PDFInfo.java +++ b/src/java/org/apache/fop/pdf/PDFInfo.java @@ -21,12 +21,11 @@ package org.apache.fop.pdf; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Calendar; import java.util.Date; -import java.util.Locale; import java.util.TimeZone; +import org.apache.xmlgraphics.util.DateFormatUtil; + /** * class representing an /Info object */ @@ -235,58 +234,14 @@ public class PDFInfo extends PDFObject { return bout.toByteArray(); } - /** - * Returns a SimpleDateFormat instance for formatting PDF date-times. - * @return a new SimpleDateFormat instance - */ - protected static SimpleDateFormat getPDFDateFormat() { - SimpleDateFormat df = new SimpleDateFormat("'D:'yyyyMMddHHmmss", Locale.ENGLISH); - df.setTimeZone(TimeZone.getTimeZone("GMT")); - return df; - } - /** * Formats a date/time according to the PDF specification (D:YYYYMMDDHHmmSSOHH'mm'). * @param time date/time value to format * @param tz the time zone * @return the requested String representation */ - protected static String formatDateTime(Date time, TimeZone tz) { - Calendar cal = Calendar.getInstance(tz, Locale.ENGLISH); - cal.setTime(time); - - int offset = cal.get(Calendar.ZONE_OFFSET); - offset += cal.get(Calendar.DST_OFFSET); - - // DateFormat is operating on GMT so adjust for time zone offset - Date dt1 = new Date(time.getTime() + offset); - StringBuffer sb = new StringBuffer(); - sb.append(getPDFDateFormat().format(dt1)); - - offset /= (1000 * 60); // Convert to minutes - - if (offset == 0) { - sb.append('Z'); - } else { - if (offset > 0) { - sb.append('+'); - } else { - sb.append('-'); - } - int offsetHour = Math.abs(offset / 60); - int offsetMinutes = Math.abs(offset % 60); - if (offsetHour < 10) { - sb.append('0'); - } - sb.append(Integer.toString(offsetHour)); - sb.append('\''); - if (offsetMinutes < 10) { - sb.append('0'); - } - sb.append(Integer.toString(offsetMinutes)); - sb.append('\''); - } - return sb.toString(); + protected static String formatDateTime(final Date time, TimeZone tz) { + return DateFormatUtil.formatPDFDate(time, tz); } /** @@ -294,7 +249,7 @@ public class PDFInfo extends PDFObject { * @param time date/time value to format * @return the requested String representation */ - protected static String formatDateTime(Date time) { + protected static String formatDateTime(final Date time) { return formatDateTime(time, TimeZone.getDefault()); } } -- cgit v1.2.3