TradingWeekImpl extends JodaWorkingWeek implements TradingWeek { @Override public TradingSession getTradingSessionOnOrAfter(DateTime date) { if(sessions.size() == 0) { throw new IllegalStateException("Trading week has no sessions configured!"); } while(!isWorkingDay(date.toLocalDate())) { date = date.plusDays(1); } int otherDay = date.getDayOfWeek(); LocalTime lt = date.toLocalTime(); int len = sessions.size(); for(int i = 0;i < len;i++) { TradingSession ts = sessions.get(i); if(ts.contains(date)) { return ts; }else if(ts.day() == otherDay){ if(ts.start().isAfter(lt)) { return ts; }else if(ts.end().isBefore(lt)) { return sessions.get(i == len - 1 ? 0 : i + 1); } } } return null; } private  TradingWeekImpl(byte tradingDays); static Builder configBuilder(
        String propertiesFilePath, String calendarName, String tradingWeekName); static Builder configBuilder(
        Properties properties, String calendarName, String tradingWeekName); @Override int length(); @Override void addTradingSession(TradingSession session); @Override TradingSession getStartSession(); @Override TradingSession getEndSession(); @Override int getTradingDaysInMonth(DateTime dt); @Override boolean isTradingDay(DateTime dt); @Override DateTime getSessionTradingDate(DateTime dt); @Override long getWeekMillis(); @Override long getSessionMillisBetween(DateTime dt1, DateTime dt2); TradingSession getTradingSessionOnOrBefore(DateTime date); @Override DateTime getPreviousSessionDate(DateTime dt, Period period); @Override TradingSession getTradingSessionOnOrAfter(DateTime date); @Override DateTime getNextSessionDate(DateTime dt, Period period); static TradingWeek loadDefaultTradingWeek(); @Override boolean isWorkingDay(LocalDate date); static int naturalDaysBetween(int startDay, int endDay); static String dayToString(int day); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static final TradingWeek DEFAULT; }
@Test public void testGetTradingSessionOnOrAfter() { TradingWeek tradingWeek = getTestTradingWeek(TEST); assertEquals(7, tradingWeek.length()); DateTime testDate = new DateTime(2009, 5, 3, 8, 30, 0, 0); TradingSession session = tradingWeek.getTradingSessionOnOrAfter(testDate); assertEquals("Sunday(08:30:00.000-15:30:00.000)", session.toString()); testDate = new DateTime(2009, 5, 4, 8, 30, 0, 0); session = tradingWeek.getTradingSessionOnOrAfter(testDate); assertEquals("Monday(08:30:00.000-15:30:00.000)", session.toString()); testDate = new DateTime(2009, 5, 5, 8, 30, 0, 0); session = tradingWeek.getTradingSessionOnOrAfter(testDate); assertEquals("Tuesday(08:30:00.000-15:30:00.000)", session.toString()); testDate = new DateTime(2009, 5, 6, 8, 30, 0, 0); session = tradingWeek.getTradingSessionOnOrAfter(testDate); assertEquals("Wednesday(08:30:00.000-15:30:00.000)", session.toString()); testDate = new DateTime(2009, 5, 7, 8, 30, 0, 0); session = tradingWeek.getTradingSessionOnOrAfter(testDate); assertEquals("Thursday(08:30:00.000-15:30:00.000)", session.toString()); testDate = new DateTime(2009, 5, 8, 8, 30, 0, 0); session = tradingWeek.getTradingSessionOnOrAfter(testDate); assertEquals("Friday(08:30:00.000-15:30:00.000)", session.toString()); testDate = new DateTime(2009, 5, 9, 8, 30, 0, 0); session = tradingWeek.getTradingSessionOnOrAfter(testDate); assertEquals("Saturday(08:30:00.000-15:30:00.000)", session.toString()); testDate = new DateTime(2009, 5, 2, 16, 30, 0, 0); session = tradingWeek.getTradingSessionOnOrAfter(testDate); assertEquals("Sunday(08:30:00.000-15:30:00.000)", session.toString()); testDate = new DateTime(2009, 5, 2, 15, 31, 0, 0); session = tradingWeek.getTradingSessionOnOrAfter(testDate); assertEquals("Sunday(08:30:00.000-15:30:00.000)", session.toString()); testDate = new DateTime(2009, 5, 2, 15, 30, 1, 0); session = tradingWeek.getTradingSessionOnOrAfter(testDate); assertEquals("Sunday(08:30:00.000-15:30:00.000)", session.toString()); }