Class ISO8601DateFormat


  • @AlfrescoPublicApi
    public class ISO8601DateFormat
    extends Object
    Formatting support for ISO 8601 dates
        sYYYY-MM-DDThh:mm:ss.sssTZD
     
    where:
    • sYYYY Four-digit year with optional leading positive (+) or negative (-) sign. A negative sign indicates a year BCE. The absence of a sign or the presence of a positive sign indicates a year CE (for example, -0055 would indicate the year 55 BCE, while +1969 and 1969 indicate the year 1969 CE).
    • MM Two-digit month (01 = January, etc.)
    • DD Two-digit day of month (01 through 31)
    • hh Two digits of hour (00 through 23)
    • mm Two digits of minute (00 through 59)
    • ss.sss Seconds, to three decimal places (00.000 through 59.999)
    • TZD Time zone designator (either Z for Zulu, i.e. UTC, or +hh:mm or -hh:mm, i.e. an offset from UTC)
    • Field Detail

      • UTC_TIMEZONE

        public static final TimeZone UTC_TIMEZONE
    • Constructor Detail

      • ISO8601DateFormat

        public ISO8601DateFormat()
    • Method Detail

      • getCalendar

        public static Calendar getCalendar​(TimeZone timezone)
        Get a calendar object from cache.
        Parameters:
        timezone - timezone object to indicate the timezone to be used by the returned calendar object
        Returns:
        calendar object from cache or newly created (if cache is empty)
      • getCalendar

        public static Calendar getCalendar()
        Get a calendar object from cache for the system default timezone.
        Returns:
        calendar object from cache or newly created (if cache is empty)
      • format

        public static String format​(Date isoDate)
        Format date into ISO format (UCT0 / Zulu)
        Parameters:
        isoDate - the date to format
        Returns:
        the ISO Zulu timezone formatted string
      • formatToZulu

        public static String formatToZulu​(String isoDate)
        Normalise isoDate time to Zulu(UTC0) time-zone, removing any UTC offset.
        Parameters:
        isoDate -
        Returns:
        the ISO Zulu timezone formatted string e.g 2011-02-04T17:13:14.000+01:00 -> 2011-02-04T16:13:14.000Z
      • parse

        public static Date parse​(String isoDate)
        Parse date from ISO formatted string. The ISO8601 date must include TimeZone offset information
        Parameters:
        isoDate - ISO string to parse
        Returns:
        the date
        Throws:
        AlfrescoRuntimeException - if the parse failed
      • parse

        public static Date parse​(String isoDate,
                                 TimeZone timezone)
        Parse date from ISO formatted string, with an explicit timezone specified
        Parameters:
        isoDate - ISO string to parse
        timezone - The TimeZone the date is in
        Returns:
        the date
        Throws:
        AlfrescoRuntimeException - if the parse failed
      • parseInternal

        public static Date parseInternal​(String isoDate,
                                         TimeZone timezone)
        Parse date from ISO formatted string, either in the specified TimeZone, or with TimeZone information taken from the date
        Parameters:
        isoDate - ISO string to parse
        timezone - The time zone, null means default time zone
        Returns:
        the date
        Throws:
        AlfrescoRuntimeException - if the parse failed
      • isTimeComponentDefined

        public static boolean isTimeComponentDefined​(String isoDate)
        Checks whether or not the given ISO8601-formatted date-string contains a time-component instead of only the actual date.
        Parameters:
        isoDate -
        Returns:
        true, if time is present.
      • parseDayOnly

        public static Date parseDayOnly​(String isoDate,
                                        TimeZone timezone)
        Parses the given ISO8601-formatted date-string, not taking into account the time-component. The time-information for the will be reset to zero.
        Parameters:
        isoDate - the day (formatted sYYYY-MM-DD) or a full date (sYYYY-MM-DDThh:mm:ss.sssTZD)
        timezone - the timezone to use
        Returns:
        the parsed date
        Throws:
        AlfrescoRuntimeException - if the parsing failed.