Top Description Fields Constructors Methods
org.apache.pdfbox.util

public final Class DateConverter

extends Object
Class Inheritance
Imports
java.text.ParsePosition, .SimpleDateFormat, java.util.Calendar, .Date, .GregorianCalendar, .Locale, .SimpleTimeZone, .TimeZone, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.cos.COSString

Converts dates to strings and back using the PDF date standard in section 3.8.2 of PDF Reference 1.7.
Authors
Ben Litchfield, Fred Hansen TODO Move members of this class elsewhere for shared use in pdfbox and xmpbox.

Field Summary

Modifier and TypeField and Description
private static final String[]
private static final int
private static final String[]
private static final int
private static final Log
private static final int
private static final int
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
pack-priv static String
formatTZoffset(long millis, String sep)

pack-priv static GregorianCalendar
private static GregorianCalendar
private static Calendar
parseDate(String text, ParsePosition initialWhere)

private static GregorianCalendar
parseSimpleDate(String text, String[] fmts, ParsePosition initialWhere)

private static int
parseTimeField(String text, ParsePosition where, int maxlen, int remedy)

pack-priv static boolean
private static int
restrainTZoffset(long proposedOffset)

private static char
skipOptionals(String text, ParsePosition where, String optionals)

private static boolean
skipString(String text, String victim, ParsePosition where)

public static Calendar

Returns:

The Calendar that the text string represents, or null if it cannot be parsed.
toCalendar
(COSString
A COS string containing a date.
text
)

Returns the Calendar for a given COS string containing a date, or null if it cannot be parsed.

public static Calendar

Returns:

The Calendar that the text string represents, or null if it cannot be parsed.
toCalendar
(String
A COS string containing a date.
text
)

Returns the Calendar for a given string containing a date, or null if it cannot be parsed.

public static String

Returns:

The date represented as an ISO 8601 string.
toISO8601
(Calendar
The date to convert. Must not be null. The DST_OFFSET is included in the output value.
cal
)

Converts the date to ISO 8601 string format: yyyy-mm-ddThh:MM:ss#hh:mm (where '#" is '+' or '-').

public static String

Returns:

The date as a String to be used in a PDF document, or null if the cal value is null
toString
(Calendar
The date to convert to a string. May be null. The DST_OFFSET is included when computing the output time zone.
cal
)

Converts a Calendar to a string formatted as: D:yyyyMMddHHmmss#hh'mm' where # is Z, +, or -.

private static void
updateZoneId(TimeZone
the time zone to update.
tz
)

Update the zone ID based on the raw offset.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALPHA_START_FORMATSback to summary
private static final String[] ALPHA_START_FORMATS
DAYback to summary
private static final int DAY
DIGIT_START_FORMATSback to summary
private static final String[] DIGIT_START_FORMATS
HALF_DAYback to summary
private static final int HALF_DAY
LOGback to summary
private static final Log LOG
MILLIS_PER_HOURback to summary
private static final int MILLIS_PER_HOUR
MILLIS_PER_MINUTEback to summary
private static final int MILLIS_PER_MINUTE
MINUTES_PER_HOURback to summary
private static final int MINUTES_PER_HOUR
SECONDS_PER_MINUTEback to summary
private static final int SECONDS_PER_MINUTE

Constructor Detail

DateConverterback to summary
private DateConverter()

Method Detail

adjustTimeZoneNicelyback to summary
private static void adjustTimeZoneNicely(GregorianCalendar cal, TimeZone tz)
formatTZoffsetback to summary
pack-priv static String formatTZoffset(long millis, String sep)
newGregback to summary
pack-priv static GregorianCalendar newGreg()
parseBigEndianDateback to summary
private static GregorianCalendar parseBigEndianDate(String text, ParsePosition initialWhere)
parseDateback to summary
private static Calendar parseDate(String text, ParsePosition initialWhere)
parseSimpleDateback to summary
private static GregorianCalendar parseSimpleDate(String text, String[] fmts, ParsePosition initialWhere)
parseTimeFieldback to summary
private static int parseTimeField(String text, ParsePosition where, int maxlen, int remedy)
parseTZoffsetback to summary
pack-priv static boolean parseTZoffset(String text, GregorianCalendar cal, ParsePosition initialWhere)
restrainTZoffsetback to summary
private static int restrainTZoffset(long proposedOffset)
skipOptionalsback to summary
private static char skipOptionals(String text, ParsePosition where, String optionals)
skipStringback to summary
private static boolean skipString(String text, String victim, ParsePosition where)
toCalendarback to summary
public static Calendar toCalendar(COSString text)

Returns the Calendar for a given COS string containing a date, or null if it cannot be parsed. The returned value will have 0 for DST_OFFSET.

Parameters
text:COSString

A COS string containing a date.

Returns:Calendar

The Calendar that the text string represents, or null if it cannot be parsed.

toCalendarback to summary
public static Calendar toCalendar(String text)

Returns the Calendar for a given string containing a date, or null if it cannot be parsed. The returned value will have 0 for DST_OFFSET.

Parameters
text:String

A COS string containing a date.

Returns:Calendar

The Calendar that the text string represents, or null if it cannot be parsed.

toISO8601back to summary
public static String toISO8601(Calendar cal)

Converts the date to ISO 8601 string format: yyyy-mm-ddThh:MM:ss#hh:mm (where '#" is '+' or '-').

Parameters
cal:Calendar

The date to convert. Must not be null. The DST_OFFSET is included in the output value.

Returns:String

The date represented as an ISO 8601 string.

toStringback to summary
public static String toString(Calendar cal)

Converts a Calendar to a string formatted as: D:yyyyMMddHHmmss#hh'mm' where # is Z, +, or -.

Parameters
cal:Calendar

The date to convert to a string. May be null. The DST_OFFSET is included when computing the output time zone.

Returns:String

The date as a String to be used in a PDF document, or null if the cal value is null

updateZoneIdback to summary
private static void updateZoneId(TimeZone tz)

Update the zone ID based on the raw offset. This is either GMT, GMT+hh:mm or GMT-hh:mm, where n is between 1 and 14. The highest negative hour is -14, the highest positive hour is 12. Zones that don't fit in this schema are set to zone ID "unknown".

Parameters
tz:TimeZone

the time zone to update.