Counting only weekend days between two timestamps
I found the logic of the set operations a bit hard confusing.  It appears that the goal is to take some set of days, named days, and remove entries from it.  So, start with days and remove entries from it.  You don't need the other sets named outsideDays and dates.

It's weird that it.numberOfDaysOutsideCVB returns a set rather than a number, as suggested by the method name.

The looping mechanism is cumbersome:


def xx = new GregorianCalendar()
xx.setTimeInMillis(f.time.next().time)
f = xx



The l day is always removed, regardless of the day of the week.  That deserves an explanatory comment.  Furthermore, f and l are somewhat cryptic variable names.

Set days = DateUtils.businessDaysBetweenDates(it.entryTimestamp, it.exitTimestamp)
days.removeAll(it.numberOfDaysOutsideCVB)

def children = QueueEntry.findAllByParent(QueueEntry.findById(it.id))
for (QueueEntry qe : children) {
    def entry = new GregorianCalendar()
    entry.setTimeInMillis(DateUtils.getClearedTime(qe.entryTimestamp))
    def exit = new GregorianCalendar()
    exit.setTimeInMillis(DateUtils.getClearedTime(qe.exitTimestamp))

    entry.upto(exit.previous()) { day -&gt;
        switch (day.get(Calendar.DAY_OF_WEEK)) {
          case Calendar.SATURDAY:
          case Calendar.SUNDAY:
            break
          default:
            days.remove(day.time.time)
        }
    }
    // Remove the last day regardless of day of week. (Why?)
    days.remove(exit.time.time)
}
turnTimes &lt;&lt; days.size()