mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-23 01:29:43 +01:00
Reworked withinDateRange to avoid type conversion between doubles and longs; expressed in long integer math.
This commit is contained in:
@@ -36,11 +36,12 @@ public final class DateUtil {
|
|||||||
*
|
*
|
||||||
* @param date the date to be checked.
|
* @param date the date to be checked.
|
||||||
* @param compareTo the date to compare to.
|
* @param compareTo the date to compare to.
|
||||||
* @param range the range in days to be considered valid.
|
* @param dayRange the range in days to be considered valid.
|
||||||
* @return whether or not the date is within the range.
|
* @return whether or not the date is within the range.
|
||||||
*/
|
*/
|
||||||
public static boolean withinDateRange(long date, long compareTo, int range) {
|
public static boolean withinDateRange(long date, long compareTo, int dayRange) {
|
||||||
final double differenceInDays = (compareTo - date) / 1000.0 / 60.0 / 60.0 / 24.0;
|
// ms = dayRange x 24 hours/day x 60 min/hour x 60 sec/min x 1000 ms/sec
|
||||||
return differenceInDays < range;
|
final long msRange = dayRange * 24L * 60L * 60L * 1000L;
|
||||||
|
return (compareTo - date) < msRange;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user