TradingSessionImpl implements TradingSession { @Override public boolean contains(DateTime date) { int otherDay = date.getDayOfWeek(); LocalTime lt = date.toLocalTime(); boolean startBounded = (lt.isEqual(start) || lt.isAfter(start)); boolean endBounded = (lt.isEqual(end) || lt.isBefore(end)); return dayIsWithinSessionDay(otherDay) && ((startBounded && endBounded) || (day != endDay && ((otherDay == day && startBounded) || (otherDay == endDay && endBounded) || dayIsBetweenStartEndDays(otherDay)) )); } TradingSessionImpl(int day, int endDay, LocalTime start, LocalTime end); @Override int hourCount(); @Override int day(); @Override int endDay(); @Override LocalTime start(); @Override LocalTime end(); @Override long sessionMillis(); static long sessionMillis(DateTime startDate, DateTime endDate); static long sessionMillis(int startDay, LocalTime startTime, int endDay, LocalTime endTime); @Override String dayToString(); @Override boolean contains(DateTime date); @Override int compareTo(TradingSession other); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testContains() { TradingSession session = new TradingSessionImpl(DateTimeConstants.FRIDAY, DateTimeConstants.FRIDAY, new LocalTime(8, 30), new LocalTime(15, 30)); DateTime test = new DateTime(2010, 9, 10, 8, 30, 0, 0); assertTrue(session.contains(test)); test = new DateTime(2010, 9, 10, 15, 30, 0, 0); assertTrue(session.contains(test)); test = new DateTime(2010, 9, 10, 8, 29, 0, 0); assertFalse(session.contains(test)); test = new DateTime(2010, 9, 10, 15, 31, 0, 0); assertFalse(session.contains(test)); test = new DateTime(2010, 9, 11, 8, 30, 0, 0); assertFalse(session.contains(test)); session = new TradingSessionImpl(DateTimeConstants.SUNDAY, DateTimeConstants.TUESDAY, new LocalTime(18, 30), new LocalTime(3, 30)); test = new DateTime(2010, 9, 13, 3, 29, 59, 999); assertTrue(session.contains(test)); session = new TradingSessionImpl(DateTimeConstants.SUNDAY, DateTimeConstants.TUESDAY, new LocalTime(18, 30), new LocalTime(3, 30)); test = new DateTime(2010, 9, 11, 3, 29, 59, 999); assertFalse(session.contains(test)); session = new TradingSessionImpl(DateTimeConstants.SUNDAY, DateTimeConstants.TUESDAY, new LocalTime(18, 30), new LocalTime(3, 30)); test = new DateTime(2010, 9, 13, 3, 30, 01, 999); assertTrue(session.contains(test)); }