class TradingWeekImpl extends JodaWorkingWeek implements TradingWeek {

    public TradingSession getTradingSessionOnOrBefore(DateTime date) {
        if(sessions.size() == 0) {
            throw new IllegalStateException("Trading week has no sessions configured!");
        }
        boolean decremented = false;
        while(!isWorkingDay(date.toLocalDate())) {
            date = date.minusDays(1);
            decremented = true;
        }
        int otherDay = date.getDayOfWeek();
        LocalTime lt = date.toLocalTime();
        int len = sessions.size();
        for(int i = len - 1;i >= 0;i--) {
            TradingSession ts = sessions.get(i);
            if(ts.contains(date) || decremented) {
                return ts;
            } else if(ts.day() == otherDay) {
               if(ts.end().isBefore(lt)) {
                   return ts;
               }else if(ts.start().isAfter(lt)) {
                   return sessions.get(i == 0 ? len - 1 : i - 1);
               }
            }
        }
       
        return null;
    }

    private  TradingWeekImpl(byte tradingDays);

}