List of usage examples for org.joda.time DateTime plus
public DateTime plus(ReadablePeriod period)
From source file:de.azapps.mirakel.model.recurring.Recurring.java
License:Open Source License
@NonNull private Optional<DateTime> addRecurring(@NonNull final Optional<DateTime> cal, final boolean onlyOnce) { if (!cal.isPresent()) { return absent(); }//from w w w .j av a2 s . co m DateTime c = cal.get(); final DateTime now = new DateTime(); if (isExact()) { c = now; } now.withSecondOfMinute(0); now.withMinuteOfHour(0); final List<Integer> weekdays = getWeekdays(); if (weekdays.isEmpty()) { if ((!getStartDate().isPresent() || now.isAfter(getStartDate().get())) && (!getEndDate().isPresent() || now.isBefore(getEndDate().get()))) { do { c = c.plus(recurringInterval); } while (c.isBefore(now) && !onlyOnce); } } else { int diff = 8; if (c.isBefore(now)) { c = now; } c = c.plusDays(1); for (final Integer day : weekdays) { int local_diff = day - c.getDayOfWeek(); if (local_diff < 0) { local_diff += 7; } if (diff > local_diff) { diff = local_diff; } } c = c.plusDays(diff); } return of(c); }
From source file:de.hpi.bpmn2_0.replay.ReplayTrace.java
License:Open Source License
private void calcTimingAll() { TraceNode node;/*from w ww.j ava 2 s . c o m*/ DateTime timeBefore = null; DateTime timeAfter = null; int timeBeforePos = 0; int timeAfterPos = 0; long duration; for (int i = 0; i < timeOrderedReplayedNodes.size(); i++) { node = timeOrderedReplayedNodes.get(i); timeBefore = null; timeAfter = null; if (!node.isTimed()) { //---------------------------------------- // The incoming nodes to this node have been already assigned timestamps // according to the traversal order starting from the Start event node (always timed) // Therefore, a node selects timestamp based on those of its incoming nodes. // This is to ensure a node's timestamp must be after all timestamp of its incoming nodes //---------------------------------------- TraceNode mostRecentIncomingNode = null; for (TraceNode incomingNode : node.getSources()) { if (timeBefore == null || timeBefore.isBefore(incomingNode.getStart())) { timeBefore = incomingNode.getStart(); mostRecentIncomingNode = incomingNode; } } timeBeforePos = timeOrderedReplayedNodes.indexOf(mostRecentIncomingNode); //---------------------------------------- //Go backward and look for a timed node, //known that it can either encounter a timed activity/gateway or //the Start event node (always timed) //---------------------------------------- /* for (int j=i-1;j>=0;j--) { if (timeOrderedReplayedNodes.get(j).isTimed()) { timeBefore = timeOrderedReplayedNodes.get(j).getStart(); timeBeforePos = j; break; } } */ //---------------------------------------- // Go forward and look for a timed node, known that it can encounter // either a timed node or the End event node eventually (always timed). // In the timeOrderedReplayedNodes array order, all nodes after // this node are either subsequent and connected to it on the model or // in parallel with it. It is possible to set a node's timestamp // after that of a parallel node because its next sequential node may have timestamp // after the node in parallel. So, this ensures its timestamp is after // any next node in chronological order, either sequential or parallel //---------------------------------------- for (int j = i + 1; j < timeOrderedReplayedNodes.size(); j++) { if (timeOrderedReplayedNodes.get(j).isTimed() && timeOrderedReplayedNodes.get(j).getStart().isAfter(timeBefore)) { timeAfter = timeOrderedReplayedNodes.get(j).getStart(); timeAfterPos = j; break; } } //---------------------------------------- //It may happen that timeBefore >= timeAfter because the two activities //at timeBeforePos and timeAfterPos are on parallel branches and have //the same timestamp. //---------------------------------------- /* if (timeBefore != null && timeAfter != null && timeBefore.isEqual(timeAfter) && !node.getSources().contains(timeOrderedReplayedNodes.get(timeBeforePos))) { //For activity or split gateway: continue searching backward for another timed node if (node.getSources().size() <= 1) { for (int j=timeBeforePos-1;j>=0;j--) { if (timeOrderedReplayedNodes.get(j).isTimed() && timeOrderedReplayedNodes.get(j).getStart().isBefore(timeAfter)) { timeBefore = timeOrderedReplayedNodes.get(j).getStart(); timeBeforePos = j; break; } } } //For joining gateway: continue searching forward for another timed node else { for (int j=timeAfterPos+1;j<timeOrderedReplayedNodes.size();j++) { if (timeOrderedReplayedNodes.get(j).isTimed() && timeOrderedReplayedNodes.get(j).getStart().isAfter(timeBefore)) { timeAfter = timeOrderedReplayedNodes.get(j).getStart(); timeAfterPos = j; break; } } } } */ //---------------------------------------------- //Always take two ends of the trace plus a buffer as time limit //in case the replay trace has no timestamped activity at two ends //NOTE: This is in case some process models cannot reach the End Event (unsound model) //---------------------------------------------- if (timeBefore == null) { timeBefore = (new DateTime(LogUtility.getTimestamp(logTrace.getTrace().get(0)))) .minusSeconds(replayer.getReplayParams().getStartEventToFirstEventDuration()); } if (timeAfter == null) { timeAfter = (new DateTime( LogUtility.getTimestamp(logTrace.getTrace().get(logTrace.getTrace().size() - 1)))) .plusSeconds(replayer.getReplayParams().getLastEventToEndEventDuration()); } //---------------------------------------------- // Take average timestamp between TimeBefore and TimeAfter //---------------------------------------------- duration = (new Duration(timeBefore, timeAfter)).getMillis(); if (timeAfterPos > timeBeforePos) { duration = Math.round(1.0 * duration * (i - timeBeforePos) / (timeAfterPos - timeBeforePos)); } node.setStart(timeBefore.plus(Double.valueOf(duration).longValue())); } } }
From source file:de.ifgi.airbase.feeder.io.filter.TimeRangeFilter.java
License:Open Source License
public void addRange(DateTime start, Period length) { this.ranges.add(new Range(start, start.plus(length))); }
From source file:de.rwth.idsg.xsharing.router.persistence.domain.routes.representation.factory.UraRepresentationFactory.java
License:Open Source License
private static <T extends AbstractLegRepresentation> List<IndividualTrip> getListOfTrips(List<T> reps, DateTime startTime) {// ww w. j av a 2s.com List<IndividualTrip> resultList = new ArrayList<>(reps.size()); DateTime arrival; DateTime departure = startTime; // convert legs one by one for (T leg : reps) { arrival = departure; Location startLocation; Location endLocation; Integer startDelay = 0; Integer endDelay = 0; switch (leg.getType()) { // Station -> Station // case BikeLeg: { // incorporate delays by check-out etc. startDelay += leg.getTransferTime(); endDelay += leg.getTransferTime(); StationRepresentation startStation = null; StationRepresentation endStation = null; if (leg instanceof LegDetailsRepresentation) { startStation = ((LegDetailsRepresentation) leg).getStartStation(); endStation = ((LegDetailsRepresentation) leg).getEndStation(); } startLocation = getUraStation(leg.getFrom(), startStation); endLocation = getUraStation(leg.getTo(), endStation); } break; // Station -> Position // case CarLeg: { // incorporate delays by check-out etc. startDelay += leg.getTransferTime(); StationRepresentation startStation = null; if (leg instanceof LegDetailsRepresentation) { startStation = ((LegDetailsRepresentation) leg).getStartStation(); } startLocation = getUraStation(leg.getFrom(), startStation); endLocation = getUraPosition(leg.getTo()); } break; // Position -> Position // case WalkingLeg: { startLocation = getUraPosition(leg.getFrom()); endLocation = getUraPosition(leg.getTo()); } break; default: throw new RuntimeException("Unexpected leg type"); } departure = arrival.plus(Duration.standardSeconds(startDelay)); // predictions need to include delay by transfers Prediction start = new Prediction.Builder().withScheduledArrivalTime(arrival) .withScheduledDepartureTime(departure).withLocation(startLocation).build(); arrival = departure.plus(Duration.standardSeconds(leg.getDuration())); departure = arrival.plus(Duration.standardSeconds(endDelay)); Prediction end = new Prediction.Builder().withScheduledArrivalTime(arrival) .withScheduledDepartureTime(departure).withLocation(endLocation).build(); PathData path = null; if (leg instanceof LegDetailsRepresentation) { path = new PathData.Builder() .withRouteGeometry(convertRouteGeometry((LegDetailsRepresentation) leg)).build(); } IndividualTrip trip = new IndividualTrip.Builder() .withDuration(Duration.standardSeconds((long) leg.getDuration())).withStart(start).withEnd(end) .withLengthInM(leg.getDistance()).withUuid(String.valueOf(leg.getId())) .withModalType(toModalType(leg.getType())).withPathDataSource("xsharing-iv").withPathData(path) .build(); resultList.add(trip); } return resultList; }
From source file:debop4k.timeperiod.samples.LargeBreak.java
License:Apache License
public LargeBreak(DateTime start) { super(start, start.plus(SchoolDay.LargeBreakDuration)); }
From source file:debop4k.timeperiod.samples.Lesson.java
License:Apache License
public Lesson(DateTime start) { super(start, start.plus(SchoolDay.LessonDuration)); }
From source file:debop4k.timeperiod.samples.SchoolDay.java
License:Apache License
public SchoolDay(DateTime moment) { this.moment = moment; lesson1 = new Lesson(moment); moment = moment.plus(lesson1.getDuration()); break1 = new ShortBreak(moment); moment = moment.plus(break1.getDuration()); lesson2 = new Lesson(moment); moment = moment.plus(lesson2.getDuration()); break2 = new LargeBreak(moment); moment = moment.plus(break2.getDuration()); lesson3 = new Lesson(moment); moment = moment.plus(lesson3.getDuration()); break3 = new ShortBreak(moment); moment = moment.plus(break3.getDuration()); lesson4 = new Lesson(moment); moment = moment.plus(lesson4.getDuration()); super.addAll(Arrays.asList(lesson1, break1, lesson2, break2, lesson3, break3, lesson4)); }
From source file:debop4k.timeperiod.samples.ShortBreak.java
License:Apache License
public ShortBreak(DateTime start) { super(start, start.plus(SchoolDay.ShortBreakDuration)); }
From source file:debop4k.timeperiod.samples.TimeBlockPeriodRelationTestData.java
License:Apache License
public TimeBlockPeriodRelationTestData(DateTime start, DateTime end, Duration duration) { assert duration.compareTo(Duration.ZERO) >= 0 : "duration ? 0 ??? ? ."; reference = new TimeBlock(start, end, true); val beforeEnd = start.minus(duration); val beforeStart = beforeEnd.minus(reference.getDuration()); val insideStart = start.plus(duration); val insideEnd = end.minus(duration); val afterStart = end.plus(duration); val afterEnd = afterStart.plus(reference.getDuration()); after = new TimeBlock(beforeStart, beforeEnd, true); startTouching = new TimeBlock(beforeStart, start, true); startInside = new TimeBlock(beforeStart, insideStart, true); insideStartTouching = new TimeBlock(start, afterStart, true); enclosingStartTouching = new TimeBlock(start, insideEnd, true); enclosing = new TimeBlock(insideStart, insideEnd, true); enclosingEndTouching = new TimeBlock(insideStart, end, true); exactMatch = new TimeBlock(start, end, true); inside = new TimeBlock(beforeStart, afterEnd, true); insideEndTouching = new TimeBlock(beforeStart, end, true); endInside = new TimeBlock(insideEnd, afterEnd, true); endTouching = new TimeBlock(end, afterEnd, true); before = new TimeBlock(afterStart, afterEnd, true); allPeriods.addAll(Arrays.asList(reference, after, startTouching, startInside, insideStartTouching, enclosingStartTouching, enclosing, enclosingEndTouching, exactMatch, inside, insideEndTouching, endInside, endTouching, before)); }
From source file:debop4k.timeperiod.samples.TimeRangePeriodRelationTestData.java
License:Apache License
public TimeRangePeriodRelationTestData(DateTime start, DateTime end, Duration duration) { assert duration.compareTo(Duration.ZERO) >= 0 : "duration ? 0 ??? ? ."; reference = new TimeRange(start, end, true); val beforeEnd = start.minus(duration); val beforeStart = beforeEnd.minus(reference.getDuration()); val insideStart = start.plus(duration); val insideEnd = end.minus(duration); val afterStart = end.plus(duration); val afterEnd = afterStart.plus(reference.getDuration()); after = new TimeRange(beforeStart, beforeEnd, true); startTouching = new TimeRange(beforeStart, start, true); startInside = new TimeRange(beforeStart, insideStart, true); insideStartTouching = new TimeRange(start, afterStart, true); enclosingStartTouching = new TimeRange(start, insideEnd, true); enclosing = new TimeRange(insideStart, insideEnd, true); enclosingEndTouching = new TimeRange(insideStart, end, true); exactMatch = new TimeRange(start, end, true); inside = new TimeRange(beforeStart, afterEnd, true); insideEndTouching = new TimeRange(beforeStart, end, true); endInside = new TimeRange(insideEnd, afterEnd, true); endTouching = new TimeRange(end, afterEnd, true); before = new TimeRange(afterStart, afterEnd, true); allPeriods.addAll(Arrays.asList(reference, after, startTouching, startInside, insideStartTouching, enclosingStartTouching, enclosing, enclosingEndTouching, exactMatch, inside, insideEndTouching, endInside, endTouching, before)); }