List of usage examples for org.joda.time Interval overlaps
public boolean overlaps(ReadableInterval interval)
From source file:org.libreplan.web.resources.search.ResourcePredicate.java
License:Open Source License
private boolean isOverlap(CalendarAvailability calendar) { if (calendar.getEndDate() == null) { if (finishDate != null) { return (finishDate.compareTo(calendar.getStartDate()) >= 0); } else {/*from www . ja v a 2s . c o m*/ return true; } } else { if (finishDate == null) { return (startDate.compareTo(calendar.getEndDate()) <= 0); } if (startDate == null) { return (finishDate.compareTo(calendar.getStartDate()) >= 0); } } Interval filter = getIntervalFilter(); Interval activePeriod = getIntervalActivePeriod(calendar); return filter.overlaps(activePeriod); }
From source file:org.opentestsystem.delivery.testadmin.domain.Proctor.java
License:Open Source License
public boolean isAvailableForTimeSlot(final TimeSlot timeSlot) { // if the user has not setup any availability windows just return true so the proctor can be scheduled if (this.availabilityWindow == null || this.availabilityWindow.isEmpty()) { return true; }//from w w w . j av a 2 s .c om final Interval timeSlotInterval = new Interval(timeSlot.getStartTime(), timeSlot.getEndTime()); boolean passesAvailable = false; boolean passesUnavailable = true; for (final AvailabilityWindow window : this.availabilityWindow) { if (!passesAvailable || passesUnavailable) { final Interval windowInterval = new Interval(window.getStartDateTime(), window.getEndDateTime()); if (Availability.AVAILABLE == window.getAvailability()) { if (windowInterval.contains(timeSlotInterval)) { passesAvailable = true; } } else if (Availability.NOTAVAILABLE == window.getAvailability()) { if (windowInterval.contains(timeSlotInterval) || windowInterval.overlaps(timeSlotInterval)) { passesUnavailable = false; } } } } return passesAvailable && passesUnavailable; }
From source file:org.opentestsystem.delivery.testadmin.scheduling.SchedulerHelper.java
License:Open Source License
/** * Interrogates a List of EligibleStudents to find a unique set of Assessments for all of the Students eligible. * //from w w w.ja v a 2 s . c o m * @param eligibleStudents * @param startDate * @param endDate * @return */ public List<Assessment> findAssessments(final List<EligibleStudent> eligibleStudents, final DateTime startDate, final DateTime endDate, final List<String> tenantIdsForAssessment) { // the assessments to schedule are the assessments with a test window at least partially within the schedule // dates // taken from the EligibleStudents // use a set to avoid duplicate Assessments // IMPORTANT!!!!!!!!! // This code will add one day to the end date of the schedule and each of the test window end dates // because the Joda Interval makes the end instant EXCLUSIVE // We need to ensure that the interval takes into account that the end dates are part of the interval. // Since all of our schedule dates and test windows use midnight as the time, an end date of 06-02-2014 00:00:00 // will turn into 06-03-2014 00:00:00 and thus the entire day of 06-02 is now part of the interval // !!!!!!!!!!!!!!!!!! final Interval scheduleInterval = new Interval(startDate, endDate.plusDays(1)); Interval testWindowInterval = null; final Set<Assessment> schedulableAssessments = new HashSet<Assessment>(); for (final EligibleStudent eligStudent : eligibleStudents) { for (final Assessment assess : eligStudent.getAssessments()) { for (final TestWindow testWindow : assess.getTestWindow()) { testWindowInterval = new Interval(testWindow.getBeginWindow(), testWindow.getEndWindow().plusDays(1)); if (scheduleInterval.overlaps(testWindowInterval) && tenantIdsForAssessment.contains(assess.getTenantId())) { schedulableAssessments.add(assess); break; } } } } return new ArrayList<Assessment>(schedulableAssessments); }
From source file:se.vgregion.services.calendar.CalendarServiceImpl.java
License:Open Source License
@Override public CalendarEvents getCalendarEventsFromIcalUrl(String url, CalendarEventsPeriod period, String type) throws CalendarServiceException { CalendarEvents calendarEvents = new CalendarEvents(); calendarEvents.setCalendarItems(new ArrayList<CalendarItem>()); Interval queryInterval = new Interval(period.getStartDate(), period.getEndDate()); try {/*from w w w . j ava2s. c o m*/ Calendar calendar = parseIcalUrl(url); Iterator<VEvent> itr = calendar.getComponents(Component.VEVENT).iterator(); while (itr.hasNext()) { VEvent vEvent = itr.next(); Date startDate = vEvent.getStartDate().getDate(); Date endDate = vEvent.getEndDate().getDate(); boolean wholeDays = !(startDate instanceof net.fortuna.ical4j.model.DateTime); if (wholeDays) { // Whole day event. Have had timezone problems with whole day events. Workaround it. String datePartStart = startDate.toString(); String datePartEnd = endDate.toString(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); sdf.setTimeZone(TimeZone.getDefault()); try { java.util.Date startParsed = sdf.parse(datePartStart); java.util.Date endParsed = sdf.parse(datePartEnd); startDate = new net.fortuna.ical4j.model.DateTime(startParsed); // Subtract a millisecond so we don't regard the event as taking place on the next day. Now we // end the event one millisecond before the day turns. endDate = new net.fortuna.ical4j.model.DateTime(endParsed.getTime() - 1); } catch (ParseException e) { LOGGER.error(e.getMessage(), e); } } Interval interval = new Interval(startDate.getTime(), endDate.getTime()); if (interval.overlaps(queryInterval)) { CalendarItem item = new CalendarItem(); item.setInterval(interval); item.setTitle(vEvent.getSummary().getValue()); item.setCalendarType(type); item.setWholeDays(wholeDays); calendarEvents.getCalendarItems().add(item); } } } catch (IOException ioe) { throw new CalendarServiceException(ioe); } catch (ParserException pe) { throw new CalendarServiceException(pe); } return calendarEvents; }
From source file:sg.atom.utils._commons.time.JodaUtils.java
License:Open Source License
public static boolean overlaps(final Interval i, Iterable<Interval> intervals) { return Iterables.any(intervals, new Predicate<Interval>() { @Override//from w ww . j a v a 2s.co m public boolean apply(@Nullable Interval input) { return input.overlaps(i); } }); }
From source file:wad.domain.resource.Resource.java
public boolean isAvailable(Interval interval) { Interval floorReserveableInterval = this.reservableIntervals.floor(interval); if (floorReserveableInterval == null || !floorReserveableInterval.contains(interval)) { return false; }//from w ww . ja va 2 s .c o m Interval floorReservedInterval = this.reservableIntervals.floor(interval); if (floorReservedInterval != null && floorReservedInterval.overlaps(interval)) { return false; } Interval ceilingReservedInterval = this.reservableIntervals.ceiling(interval); if (ceilingReservedInterval != null && ceilingReservedInterval.overlaps(interval)) { return false; } return true; }