diff options
author | Glenn Adams <gadams@apache.org> | 2012-05-09 12:20:34 +0000 |
---|---|---|
committer | Glenn Adams <gadams@apache.org> | 2012-05-09 12:20:34 +0000 |
commit | 1c9c25bd5bef114bdc176ee8554fe0cd34183be2 (patch) | |
tree | 9d96c1a60dc2c733322d2c04cd42aade274b2ece /src | |
parent | 953e762e1b5dcb2cb31b6ca8a87110018c9151de (diff) | |
download | xmlgraphics-fop-1c9c25bd5bef114bdc176ee8554fe0cd34183be2.tar.gz xmlgraphics-fop-1c9c25bd5bef114bdc176ee8554fe0cd34183be2.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFInfo.java | 55 |
1 files changed, 5 insertions, 50 deletions
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 */ @@ -236,57 +235,13 @@ public class PDFInfo extends PDFObject { } /** - * 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()); } } |