Java SQL Time isTimeInRange(java.sql.Time start, java.sql.Time end, java.util.Date d)

Here you can find the source of isTimeInRange(java.sql.Time start, java.sql.Time end, java.util.Date d)

Description

Tells you if the date part of a datetime is in a certain time range.

License

Open Source License

Declaration

public static boolean isTimeInRange(java.sql.Time start,
        java.sql.Time end, java.util.Date d) 

Method Source Code

//package com.java2s;
import java.util.*;

public class Main {
    public static Calendar calendar = new GregorianCalendar();

    /**//  w  ww.j  a v a2s. c  o  m
     * Tells you if the date part of a datetime is in a certain time range.
     */
    public static boolean isTimeInRange(java.sql.Time start,
            java.sql.Time end, java.util.Date d) {
        d = new java.sql.Time(d.getHours(), d.getMinutes(), d.getSeconds());

        if (start == null || end == null) {
            return false;
        }

        if (start.before(end) && (!(d.after(start) && d.before(end)))) {
            return false;
        }

        if (end.before(start) && (!(d.after(end) || d.before(start)))) {
            return false;
        }
        return true;
    }

    public static int getSeconds(Date date) {
        calendar.setTime(date);
        return calendar.get(Calendar.SECOND);
    }
}

Related

  1. isDateTime(int type)
  2. isDateTime(String val)
  3. isTime(final Class type)
  4. isTime(final PropertyDescriptor pd)
  5. isTime(String val)
  6. merge(java.util.Date date, java.util.Date time)
  7. mergeDateTime(Date date, Time time)
  8. minTime()
  9. minutesToTime(int minutes)