Class DateConverter


  • public final class DateConverter
    extends java.lang.Object
    Converts dates to strings and back using the PDF date standard in section 3.8.2 of PDF Reference 1.7.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private DateConverter()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static void adjustTimeZoneNicely​(java.util.GregorianCalendar cal, java.util.TimeZone tz)  
      (package private) static java.lang.String formatTZoffset​(long millis, java.lang.String sep)  
      (package private) static java.util.GregorianCalendar newGreg()  
      private static java.util.GregorianCalendar parseBigEndianDate​(java.lang.String text, java.text.ParsePosition initialWhere)  
      private static java.util.Calendar parseDate​(java.lang.String text, java.text.ParsePosition initialWhere)  
      private static java.util.GregorianCalendar parseSimpleDate​(java.lang.String text, java.lang.String[] fmts, java.text.ParsePosition initialWhere)  
      private static int parseTimeField​(java.lang.String text, java.text.ParsePosition where, int maxlen, int remedy)  
      (package private) static boolean parseTZoffset​(java.lang.String text, java.util.GregorianCalendar cal, java.text.ParsePosition initialWhere)  
      private static int restrainTZoffset​(long proposedOffset)  
      private static char skipOptionals​(java.lang.String text, java.text.ParsePosition where, java.lang.String optionals)  
      private static boolean skipString​(java.lang.String text, java.lang.String victim, java.text.ParsePosition where)  
      static java.util.Calendar toCalendar​(java.lang.String text)
      Returns the Calendar for a given string containing a date, or null if it cannot be parsed.
      static java.util.Calendar toCalendar​(COSString text)
      Returns the Calendar for a given COS string containing a date, or null if it cannot be parsed.
      static java.lang.String toISO8601​(java.util.Calendar cal)
      Converts the date to ISO 8601 string format: yyyy-mm-ddThh:MM:ss#hh:mm (where '#" is '+' or '-').
      static java.lang.String toString​(java.util.Calendar cal)
      Converts a Calendar to a string formatted as: D:yyyyMMddHHmmss#hh'mm' where # is Z, +, or -.
      private static void updateZoneId​(java.util.TimeZone tz)
      Update the zone ID based on the raw offset.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ALPHA_START_FORMATS

        private static final java.lang.String[] ALPHA_START_FORMATS
      • DIGIT_START_FORMATS

        private static final java.lang.String[] DIGIT_START_FORMATS
    • Constructor Detail

      • DateConverter

        private DateConverter()
    • Method Detail

      • toString

        public static java.lang.String toString​(java.util.Calendar cal)
        Converts a Calendar to a string formatted as: D:yyyyMMddHHmmss#hh'mm' where # is Z, +, or -.
        Parameters:
        cal - The date to convert to a string. May be null. The DST_OFFSET is included when computing the output time zone.
        Returns:
        The date as a String to be used in a PDF document, or null if the cal value is null
      • toISO8601

        public static java.lang.String toISO8601​(java.util.Calendar cal)
        Converts the date to ISO 8601 string format: yyyy-mm-ddThh:MM:ss#hh:mm (where '#" is '+' or '-').
        Parameters:
        cal - The date to convert. Must not be null. The DST_OFFSET is included in the output value.
        Returns:
        The date represented as an ISO 8601 string.
      • restrainTZoffset

        private static int restrainTZoffset​(long proposedOffset)
      • formatTZoffset

        static java.lang.String formatTZoffset​(long millis,
                                               java.lang.String sep)
      • parseTimeField

        private static int parseTimeField​(java.lang.String text,
                                          java.text.ParsePosition where,
                                          int maxlen,
                                          int remedy)
      • skipOptionals

        private static char skipOptionals​(java.lang.String text,
                                          java.text.ParsePosition where,
                                          java.lang.String optionals)
      • skipString

        private static boolean skipString​(java.lang.String text,
                                          java.lang.String victim,
                                          java.text.ParsePosition where)
      • newGreg

        static java.util.GregorianCalendar newGreg()
      • adjustTimeZoneNicely

        private static void adjustTimeZoneNicely​(java.util.GregorianCalendar cal,
                                                 java.util.TimeZone tz)
      • parseTZoffset

        static boolean parseTZoffset​(java.lang.String text,
                                     java.util.GregorianCalendar cal,
                                     java.text.ParsePosition initialWhere)
      • updateZoneId

        private static void updateZoneId​(java.util.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 - the time zone to update.
      • parseBigEndianDate

        private static java.util.GregorianCalendar parseBigEndianDate​(java.lang.String text,
                                                                      java.text.ParsePosition initialWhere)
      • parseSimpleDate

        private static java.util.GregorianCalendar parseSimpleDate​(java.lang.String text,
                                                                   java.lang.String[] fmts,
                                                                   java.text.ParsePosition initialWhere)
      • parseDate

        private static java.util.Calendar parseDate​(java.lang.String text,
                                                    java.text.ParsePosition initialWhere)
      • toCalendar

        public static java.util.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 - A COS string containing a date.
        Returns:
        The Calendar that the text string represents, or null if it cannot be parsed.
      • toCalendar

        public static java.util.Calendar toCalendar​(java.lang.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 - A COS string containing a date.
        Returns:
        The Calendar that the text string represents, or null if it cannot be parsed.