| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- 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 <code>null</code>
- * @param date2
- * the second date, not <code>null</code>
- * @param field
- * the field from <code>Calendar</code>
- * @return diff millis
- * @throws IllegalArgumentException
- * if any argument is <code>null</code>
- * @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 <code>null</code>
- * @param date2
- * the second date, not <code>null</code>
- * @param field
- * the field from <code>Calendar</code>
- * @return diff millis
- * @throws IllegalArgumentException
- * if any argument is <code>null</code>
- * @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;
- }
-
- }
|