blob: ed3b18c4949882ef4a2ad1d0e8a4169f31f7c13f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package cgeo.geocaching.utils;
import cgeo.geocaching.Geocache;
import java.util.Calendar;
import java.util.Date;
public final class CalendarUtils {
private CalendarUtils() {
// utility class
}
public static int daysSince(final long date) {
final Calendar logDate = Calendar.getInstance();
logDate.setTimeInMillis(date);
logDate.set(Calendar.SECOND, 0);
logDate.set(Calendar.MINUTE, 0);
logDate.set(Calendar.HOUR_OF_DAY, 0);
final Calendar today = Calendar.getInstance();
today.set(Calendar.SECOND, 0);
today.set(Calendar.MINUTE, 0);
today.set(Calendar.HOUR_OF_DAY, 0);
return (int) Math.round((today.getTimeInMillis() - logDate.getTimeInMillis()) / 86400000d);
}
public static int daysSince(final Calendar date) {
return daysSince(date.getTimeInMillis());
}
public static boolean isPastEvent(final Geocache cache) {
if (!cache.isEventCache()) {
return false;
}
final Date hiddenDate = cache.getHiddenDate();
return hiddenDate != null && CalendarUtils.daysSince(hiddenDate.getTime()) > 0;
}
/**
* Return whether the given date is *more* than 1 day away. We allow 1 day to be "present time" to compensate for
* potential timezone issues.
*
* @param date
* the date
*/
public static boolean isFuture(final Calendar date) {
return daysSince(date) < -1;
}
}
|