static public boolean inRange(Timestamp start,Timestamp end,boolean OnMonday,boolean OnTuesday,boolean OnWednesday,boolean OnThursday,boolean OnFriday,boolean OnSaturday,boolean OnSunday){
  if (OnSaturday && OnSunday && OnMonday&& OnTuesday&& OnWednesday&& OnThursday&& OnFriday)   return false;
  GregorianCalendar calStart=new GregorianCalendar();
  calStart.setTimeInMillis(start.getTime());
  int dayStart=calStart.get(Calendar.DAY_OF_WEEK);
  GregorianCalendar calEnd=new GregorianCalendar();
  calEnd.setTimeInMillis(end.getTime());
  calEnd.add(Calendar.DAY_OF_YEAR,-1);
  int dayEnd=calEnd.get(Calendar.DAY_OF_WEEK);
  if (calStart.get(Calendar.YEAR) == calEnd.get(Calendar.YEAR) && calStart.get(Calendar.MONTH) == calEnd.get(Calendar.MONTH) && calStart.get(Calendar.DAY_OF_MONTH) == calEnd.get(Calendar.DAY_OF_YEAR)) {
    if ((!OnSaturday && dayStart == Calendar.SATURDAY) || (!OnSunday && dayStart == Calendar.SUNDAY) || (!OnMonday && dayStart == Calendar.MONDAY)|| (!OnTuesday && dayStart == Calendar.TUESDAY)|| (!OnWednesday && dayStart == Calendar.WEDNESDAY)|| (!OnThursday && dayStart == Calendar.THURSDAY)|| (!OnFriday && dayStart == Calendar.FRIDAY)) {
      return true;
    }
    return false;
  }
  BitSet days=new BitSet(8);
  if (dayEnd <= dayStart)   dayEnd+=7;
  for (int i=dayStart; i < dayEnd; i++) {
    int index=i;
    if (index > 7)     index-=7;
    days.set(index);
  }
  if ((!OnSaturday && days.get(Calendar.SATURDAY)) || (!OnSunday && days.get(Calendar.SUNDAY)) || (!OnMonday && days.get(Calendar.MONDAY))|| (!OnTuesday && days.get(Calendar.TUESDAY))|| (!OnWednesday && days.get(Calendar.WEDNESDAY))|| (!OnThursday && days.get(Calendar.THURSDAY))|| (!OnFriday && days.get(Calendar.FRIDAY))) {
    return true;
  }
  return false;
}

static public boolean inRange ( Timestamp start , Timestamp end , boolean OnMonday , boolean OnTuesday , boolean OnWednesday , boolean OnThursday , boolean OnFriday , boolean OnSaturday , boolean OnSunday ) { if ( OnSaturday && OnSunday && OnMonday && OnTuesday && OnWednesday && OnThursday && OnFriday ) return false ; GregorianCalendar calStart = new GregorianCalendar ( ) ; calStart . setTimeInMillis ( start . getTime ( ) ) ; int dayStart = calStart . get ( Calendar . DAY_OF_WEEK ) ; GregorianCalendar calEnd = new GregorianCalendar ( ) ; calEnd . setTimeInMillis ( end . getTime ( ) ) ; calEnd . add ( Calendar . DAY_OF_YEAR , - 1 ) ; int dayEnd = calEnd . get ( Calendar . DAY_OF_WEEK ) ; if ( calStart . get ( Calendar . YEAR ) == calEnd . get ( Calendar . YEAR ) && calStart . get ( Calendar . MONTH ) == calEnd . get ( Calendar . MONTH ) && calStart . get ( Calendar . DAY_OF_MONTH ) == calEnd . get ( Calendar . DAY_OF_YEAR ) ) { if ( ( ! OnSaturday && dayStart == Calendar . SATURDAY ) || ( ! OnSunday && dayStart == Calendar . SUNDAY ) || ( ! OnMonday && dayStart == Calendar . MONDAY ) || ( ! OnTuesday && dayStart == Calendar . TUESDAY ) || ( ! OnWednesday && dayStart == Calendar . WEDNESDAY ) || ( ! OnThursday && dayStart == Calendar . THURSDAY ) || ( ! OnFriday && dayStart == Calendar . FRIDAY ) ) { return true ; } return false ; } BitSet days = new BitSet ( 8 ) ; if ( dayEnd <= dayStart ) dayEnd += 7 ; for ( int i = dayStart ; i < dayEnd ; i ++ ) { int index = i ; if ( index > 7 ) index -= 7 ; days . set ( index ) ; } if ( ( ! OnSaturday && days . get ( Calendar . SATURDAY ) ) || ( ! OnSunday && days . get ( Calendar . SUNDAY ) ) || ( ! OnMonday && days . get ( Calendar . MONDAY ) ) || ( ! OnTuesday && days . get ( Calendar . TUESDAY ) ) || ( ! OnWednesday && days . get ( Calendar . WEDNESDAY ) ) || ( ! OnThursday && days . get ( Calendar . THURSDAY ) ) || ( ! OnFriday && days . get ( Calendar . FRIDAY ) ) ) { return true ; } return false ; }
is start . . end on one of the days ?
