package com.goafanti.common.utils;
import java.util.Calendar;
import java.util.Date;
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
/**
* Determines how two dates compare up to no more than the specified most
* significant field.
*
* @param date1
* the first date, not null
* @param date2
* the second date, not null
* @param field
* the field from Calendar
* @return diff millis
* @throws IllegalArgumentException
* if any argument is null
* @see #truncate(Calendar, int)
* @see #truncatedCompareTo(Date, Date, int)
* @since 3.0
*/
public static long truncatedDiffTo(final Date date1, final Date date2, final int field) {
final Date truncatedDate1 = truncate(date1, field);
final Date truncatedDate2 = truncate(date2, field);
long thisTime = truncatedDate1.getTime();
long anotherTime = truncatedDate2.getTime();
return Math.abs(thisTime - anotherTime);
}
/**
* Determines how two dates compare up to no more than the specified most
* significant field.
*
* @param date1
* the first date, not null
* @param date2
* the second date, not null
* @param field
* the field from Calendar
* @return diff millis
* @throws IllegalArgumentException
* if any argument is null
* @see #truncate(Calendar, int)
* @see #truncatedCompareTo(Date, Date, int)
* @since 3.0
*/
public static long truncatedHourDiffTo(final Date date1, final Date date2) {
return truncatedDiffTo(date1, date2, Calendar.HOUR) / 3600000;
}
}