Lines 21-32
Link Here
|
21 |
|
21 |
|
22 |
import java.io.ByteArrayOutputStream; |
22 |
import java.io.ByteArrayOutputStream; |
23 |
import java.io.IOException; |
23 |
import java.io.IOException; |
24 |
import java.text.SimpleDateFormat; |
|
|
25 |
import java.util.Calendar; |
26 |
import java.util.Date; |
24 |
import java.util.Date; |
27 |
import java.util.Locale; |
|
|
28 |
import java.util.TimeZone; |
25 |
import java.util.TimeZone; |
29 |
|
26 |
|
|
|
27 |
import org.apache.xmlgraphics.util.DateFormatUtil; |
28 |
|
30 |
/** |
29 |
/** |
31 |
* class representing an /Info object |
30 |
* class representing an /Info object |
32 |
*/ |
31 |
*/ |
Lines 236-292
Link Here
|
236 |
} |
235 |
} |
237 |
|
236 |
|
238 |
/** |
237 |
/** |
239 |
* Returns a SimpleDateFormat instance for formatting PDF date-times. |
|
|
240 |
* @return a new SimpleDateFormat instance |
241 |
*/ |
242 |
protected static SimpleDateFormat getPDFDateFormat() { |
243 |
SimpleDateFormat df = new SimpleDateFormat("'D:'yyyyMMddHHmmss", Locale.ENGLISH); |
244 |
df.setTimeZone(TimeZone.getTimeZone("GMT")); |
245 |
return df; |
246 |
} |
247 |
|
248 |
/** |
249 |
* Formats a date/time according to the PDF specification (D:YYYYMMDDHHmmSSOHH'mm'). |
238 |
* Formats a date/time according to the PDF specification (D:YYYYMMDDHHmmSSOHH'mm'). |
250 |
* @param time date/time value to format |
239 |
* @param time date/time value to format |
251 |
* @param tz the time zone |
240 |
* @param tz the time zone |
252 |
* @return the requested String representation |
241 |
* @return the requested String representation |
253 |
*/ |
242 |
*/ |
254 |
protected static String formatDateTime(Date time, TimeZone tz) { |
243 |
protected String formatDateTime(final Date time, TimeZone tz) { |
255 |
Calendar cal = Calendar.getInstance(tz, Locale.ENGLISH); |
244 |
return DateFormatUtil.formatPDFDate(time, tz); |
256 |
cal.setTime(time); |
|
|
257 |
|
258 |
int offset = cal.get(Calendar.ZONE_OFFSET); |
259 |
offset += cal.get(Calendar.DST_OFFSET); |
260 |
|
261 |
// DateFormat is operating on GMT so adjust for time zone offset |
262 |
Date dt1 = new Date(time.getTime() + offset); |
263 |
StringBuffer sb = new StringBuffer(); |
264 |
sb.append(getPDFDateFormat().format(dt1)); |
265 |
|
266 |
offset /= (1000 * 60); // Convert to minutes |
267 |
|
268 |
if (offset == 0) { |
269 |
sb.append('Z'); |
270 |
} else { |
271 |
if (offset > 0) { |
272 |
sb.append('+'); |
273 |
} else { |
274 |
sb.append('-'); |
275 |
} |
276 |
int offsetHour = Math.abs(offset / 60); |
277 |
int offsetMinutes = Math.abs(offset % 60); |
278 |
if (offsetHour < 10) { |
279 |
sb.append('0'); |
280 |
} |
281 |
sb.append(Integer.toString(offsetHour)); |
282 |
sb.append('\''); |
283 |
if (offsetMinutes < 10) { |
284 |
sb.append('0'); |
285 |
} |
286 |
sb.append(Integer.toString(offsetMinutes)); |
287 |
sb.append('\''); |
288 |
} |
289 |
return sb.toString(); |
290 |
} |
245 |
} |
291 |
|
246 |
|
292 |
/** |
247 |
/** |
Lines 294-300
Link Here
|
294 |
* @param time date/time value to format |
249 |
* @param time date/time value to format |
295 |
* @return the requested String representation |
250 |
* @return the requested String representation |
296 |
*/ |
251 |
*/ |
297 |
protected static String formatDateTime(Date time) { |
252 |
protected static String formatDateTime(final Date time) { |
298 |
return formatDateTime(time, TimeZone.getDefault()); |
253 |
return formatDateTime(time, TimeZone.getDefault()); |
299 |
} |
254 |
} |
300 |
} |
255 |
} |