Beispiel #1
0
  /**
   * Changes input calendar by resetting time fields to 0.
   *
   * @param calendar the calendar to change; can't be null.
   * @return the changed calendar.
   */
  public static Calendar dateOnly(Calendar calendar) {
    ArgumentAssert.isNotNull(calendar, "Calendar can't be null.");

    calendar.set(Calendar.HOUR, calendar.getMinimum(Calendar.HOUR));
    calendar.set(Calendar.MINUTE, calendar.getMinimum(Calendar.MINUTE));
    calendar.set(Calendar.SECOND, calendar.getMinimum(Calendar.SECOND));
    calendar.set(Calendar.MILLISECOND, calendar.getMinimum(Calendar.MILLISECOND));

    return calendar;
  }
Beispiel #2
0
  /**
   * Checks whether date is within range. Range can't be opened, ie from or to can be null, but not
   * both.
   *
   * @param date the date to check whether within range; can't be null.
   * @param from the range from date.
   * @param to the range to value.
   * @return <code>true</code> if date is within range, otherwise <code>false</code>.
   */
  public static boolean isWithinRange(Date date, Date from, Date to) {
    ArgumentAssert.isNotNull(date, "Date is required.");
    ArgumentAssert.isTrue(from != null || to != null, "Either From or To date is required.");

    return (from == null || date.after(from)) && (to == null || date.before(to));
  }