Class DateUtils


  • public class DateUtils
    extends Object
    General Date utilities. This allows for checking if a token has an expired timestamp and conversions to or from SQL timestamps.

    Created by Jeff Gaynor
    on May 18, 2011 at 2:40:19 PM

    • Field Detail

      • MAX_TIMEOUT

        public static long MAX_TIMEOUT
    • Constructor Detail

      • DateUtils

        public DateUtils()
    • Method Detail

      • getDate

        public static Date getDate​(URI token)
        Parse and retrieve the date from a token.
        Parameters:
        token -
        Returns:
      • getDate

        public static Date getDate​(String token)
        Get the date from a token. Semantics of tokens are that the last path component (i.e. everything after the last "/") is the date in milliseconds.
        Parameters:
        token -
        Returns:
      • checkTimestamp

        public static void checkTimestamp​(String token,
                                          long maxTime)
        Check the timestamp for the given token. The maxTime is the maximum life in ms that the token is valid for.
        Parameters:
        token -
        maxTime -
      • checkTimestamp

        public static void checkTimestamp​(String token)
        Given a token, this will take the date and check that it lies within the MAX_TIMEOUT range, throwing an InvalidTimestampException if it does not.
        Parameters:
        token -
      • sqlTSToDate

        public static Date sqlTSToDate​(Timestamp timestamp)
        SQL timestamps store their milliseconds slightly differently than dates, so equality will always fail. This is really irritating since SQL timestamps extend Java dates, so the assumption would be that there is no change in functionality. The times as milliseconds, however, are the same. This utility converts between them. Use this whenever you pull an SQL timestamp from a database and need to get a java Date.
        Parameters:
        timestamp -
        Returns:
      • compareDates

        public static boolean compareDates​(Date date0,
                                           Date date1)
        Date equality taking into account that one or both of these might be SQL timestamp objects.
        Parameters:
        date0 -
        date1 -
        Returns:
      • equals

        public static boolean equals​(Date date1,
                                     Date date2)
        This compares the two dates down to the nearest millisecond. This is useful if you get back an SQL timestamp that has been converted to a date since there will be random rounding errors in the nanoseconds.
        Parameters:
        date1 -
        date2 -
        Returns: