static Predicate < DateValue > weekIntervalFilter ( final int interval , final DayOfWeek weekStart , final DateValue dtStart ) { return new Predicate < DateValue > ( ) { private static final long serialVersionUID = 7059994888520369846L ; //the latest day with day of week weekStart on or before dtStart DateValue wkStart ; { DTBuilder wkStartB = new DTBuilder ( dtStart ) ; wkStartB . day -= ( 7 + TimeUtils . dayOfWeek ( dtStart ) . getCalendarConstant ( ) - weekStart . getCalendarConstant ( ) ) % 7 ; wkStart = wkStartB . toDate ( ) ; } public boolean apply ( DateValue date ) { int daysBetween = TimeUtils . daysBetween ( date , wkStart ) ; if ( daysBetween < 0 ) { //date must be before dtStart. Shouldn't occur in practice. daysBetween += ( interval * 7 * ( 1 + daysBetween / ( - 7 * interval ) ) ) ; } int off = ( daysBetween / 7 ) % interval ; return off == 0 ; } } ; }
Constructs a filter that accepts only every X week starting from the week containing the given date .