Add null check before attempting to do math on the date.

This commit is contained in:
Andrew Chen 2012-09-06 16:35:13 -07:00
parent 513126fe08
commit 3f4bc28363
1 changed files with 8 additions and 5 deletions

View File

@ -211,12 +211,15 @@ public class Utility {
private static final long MILISECONDS_IN_18_HOURS = 18 * 60 * 60 * 1000;
/**
* Returns true if the specified date is within 18 hours of "now". Returns false otherwise.
* @param date
* @return
* Check a date to see if it was from "today."
* @param date Date of item to check.
* @return true if the specified date is within 18 hours of now.
*/
public static boolean isDateToday(Date date) {
Date now = new Date();
public static boolean isDateToday(final Date date) {
if (date == null) {
return false;
}
final Date now = new Date();
if (now.getTime() - MILISECONDS_IN_18_HOURS > date.getTime() || now.getTime() + MILISECONDS_IN_18_HOURS < date.getTime()) {
return false;
} else {