1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-26 09:38:52 -05:00

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

View File

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