Package edu.uiuc.ncsa.security.core.util
Class DateUtils
- java.lang.Object
-
- edu.uiuc.ncsa.security.core.util.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 Summary
Fields Modifier and Type Field Description static long
MAX_TIMEOUT
-
Constructor Summary
Constructors Constructor Description DateUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
checkTimestamp(String token)
Given a token, this will take the date and check that it lies within theMAX_TIMEOUT
range, throwing anInvalidTimestampException
if it does not.static void
checkTimestamp(String token, long maxTime)
Check the timestamp for the given token.static boolean
compareDates(Date date0, Date date1)
Date equality taking into account that one or both of these might be SQL timestamp objects.static boolean
equals(Date date1, Date date2)
This compares the two dates down to the nearest millisecond.static Date
getDate(String token)
Get the date from a token.static Date
getDate(URI token)
Parse and retrieve the date from a token.static Date
sqlTSToDate(Timestamp timestamp)
SQL timestamps store their milliseconds slightly differently than dates, so equality will always fail.
-
-
-
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 theMAX_TIMEOUT
range, throwing anInvalidTimestampException
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:
-
-