List of usage examples for org.joda.time Interval isAfter
public boolean isAfter(long millisInstant)
From source file:graph.inference.module.LaterThanWorker.java
License:Open Source License
@Override public void queryInternal(QueryObject queryObj) throws IllegalArgumentException { if (!(queryObj.getNode(1) instanceof DAGNode && queryObj.getNode(2) instanceof DAGNode)) return;// www . j a v a 2 s .c o m DAGNode dateA = (DAGNode) queryObj.getNode(1); DAGNode dateB = (DAGNode) queryObj.getNode(2); DateTime now = DateTime.now(); Interval dtA = parseDate(dateA, now); Interval dtB = parseDate(dateB, now); // If date A is later than date B, return true. if (dtA != null && dtB != null && dtA.isAfter(dtB)) queryObj.addResult(new Substitution(), queryObj.getNodes()); }
From source file:net.sourceforge.fenixedu.dataTransferObject.resourceAllocationManager.OccupationPeriodBean.java
License:Open Source License
private Iterable<Interval> extractIntervals(String parameter) { Iterable<Interval> intervals = Iterables.transform(SPLITTER.split(parameter), new Function<String, Interval>() { @Override/*www . jav a 2 s . c om*/ public Interval apply(String string) { String[] dates = string.split(","); if (dates.length != 2) { throw new RuntimeException( "Error while recreating intervals, '" + string + "' cannot be parsed!"); } LocalDate start = FORMATTER.parseDateTime(dates[0]).toLocalDate(); LocalDate end = FORMATTER.parseDateTime(dates[1]).toLocalDate(); return IntervalTools.getInterval(start, end); } }); Iterator<Interval> iter = intervals.iterator(); Interval last = iter.next(); while (iter.hasNext()) { Interval current = iter.next(); if (!current.isAfter(last)) { throw new DomainException("label.occupation.period.invalid.dates"); } last = current; } return intervals; }
From source file:op.allowance.PnlAllowance.java
License:Open Source License
private void updateCarrySums(Resident resident, LocalDate pit, BigDecimal amount) { String prevKey = getKey(resident, SYSCalendar.eom(pit.minusMonths(1))); if (!carrySums.containsKey(prevKey)) { carrySums.put(prevKey, AllowanceTools.getSUM(resident, SYSCalendar.eom(pit).minusMonths(1))); }// ww w . ja va2 s . c om // update carrysums for (LocalDate month = SYSCalendar.eom(pit); month .compareTo(SYSCalendar.eoy(new LocalDate())) <= 0; month = SYSCalendar.eom(month.plusMonths(1))) { OPDE.debug(month.toString("yyyy-MM-dd")); final String key = getKey(resident, month); if (!carrySums.containsKey(key)) { prevKey = getKey(resident, SYSCalendar.eom(month.minusMonths(1))); carrySums.put(key, carrySums.get(prevKey).add(amount)); } else { carrySums.put(key, carrySums.get(key).add(amount)); } contentmap.remove(key); } // fix minmax interval Interval myMinMax = new Interval(minmax.get(resident).getFirst().toDateTimeAtStartOfDay(), SYSCalendar.eod(minmax.get(resident).getSecond())); if (myMinMax.isBefore(pit.toDateTimeAtCurrentTime())) { minmax.put(resident, new Pair(minmax.get(resident).getFirst(), SYSCalendar.eom(pit))); } else if (myMinMax.isAfter(pit.toDateTimeAtCurrentTime())) { minmax.put(resident, new Pair(SYSCalendar.bom(pit), minmax.get(resident).getSecond())); } }
From source file:org.fenixedu.academic.dto.resourceAllocationManager.OccupationPeriodBean.java
License:Open Source License
private Iterable<Interval> extractIntervals(String parameter) { Iterable<Interval> intervals = StreamSupport.stream(SPLITTER.split(parameter).spliterator(), false) .map(string -> {/* w ww .j a va2 s.co m*/ String[] dates = string.split(","); if (dates.length != 2) { throw new RuntimeException( "Error while recreating intervals, '" + string + "' cannot be parsed!"); } LocalDate start = FORMATTER.parseDateTime(dates[0]).toLocalDate(); LocalDate end = FORMATTER.parseDateTime(dates[1]).toLocalDate(); return IntervalTools.getInterval(start, end); }).collect(Collectors.toList()); Iterator<Interval> iter = intervals.iterator(); Interval last = iter.next(); while (iter.hasNext()) { Interval current = iter.next(); if (!current.isAfter(last)) { throw new DomainException("label.occupation.period.invalid.dates"); } last = current; } return intervals; }
From source file:org.fenixedu.spaces.domain.Space.java
License:Open Source License
protected void add(Information information) { if (information == null) { return;// www . java2 s. co m } if (getCurrent() == null) { setCurrent(information); return; } final DateTime newStart = information.getValidFrom(); final DateTime newEnd = information.getValidUntil(); final Interval newValidity = information.getValidity(); Information newCurrent = null; Information last = null; Information newHead = null; Information current = getCurrent(); Information head = current; Interval currentValidity = current.getValidity(); boolean foundEnd = false; boolean foundStart = false; // insert at head if (newValidity.isAfter(currentValidity)) { newHead = information; newHead.setPrevious(head); } if (newHead == null) { //last is the previous element of the new list //newCurrent is the current element of the new list while (current != null) { if (!foundEnd && !foundStart && current.contains(newValidity)) { //if start and end is in the current element if (current.getValidity().equals(newValidity)) { // if it is the same period just replace current newCurrent = information; } else { Information right = dateEquals(current.getValidUntil(), newEnd) ? information : current.keepRight(newEnd); if (last != null) { last.setPrevious(right); } else { newHead = right; // no previous in new list, make right head } if (right != information) { right.setPrevious(information); } last = information; newCurrent = dateEquals(current.getValidFrom(), newStart) ? last : current.keepLeft(newStart); } foundEnd = true; foundStart = true; } else { if (!foundEnd) { final boolean isAfter = current.isAfter(newEnd); //if newEnd is after current end date, then it is a gap if (current.contains(newEnd) || isAfter) { if (!isAfter) { Information right = current.keepRight(newEnd); if (last != null) { last.setPrevious(right); } else { newHead = right; // no previous in new list, make right head } last = right; } newCurrent = information; // no need to cut current because it will be replaced by information foundEnd = true; } } final boolean isAfter = current.isAfter(newStart); //if newEnd is after current end date, then it is a gap if (foundEnd && (current.contains(newStart) || isAfter)) { // looking for the start newCurrent = current.keepLeft(newStart); foundStart = true; } else { if (!foundEnd || foundStart) { // if not in the process of searching for information just keep copying current newCurrent = current.copy(); } } } //bookkeeping code if (last != null && !last.equals(newCurrent)) { last.setPrevious(newCurrent); } last = newCurrent; if (newHead == null) { newHead = newCurrent; } current = current.getPrevious(); } //insert at end if (!foundEnd) { last.setPrevious(information); } } addHistory(head); setCurrent(newHead); }
From source file:org.kalypso.ui.rrm.internal.timeseries.view.actions.MergeTimeseriesOperation.java
License:Open Source License
private void validateTimeseries(final DateRange baseRange, final Period baseTimestep, final DateRange importRange, final Period importTimestep) throws CoreException { /* The timesteps must be equal. */ final Minutes baseMinutes = baseTimestep.toStandardMinutes(); final Minutes importMinutes = importTimestep.toStandardMinutes(); if (baseMinutes.getMinutes() != importMinutes.getMinutes()) throw new CoreException(new Status(IStatus.ERROR, KalypsoUIRRMPlugin.getID(), String.format(Messages.getString("MergeTimeseriesOperation.0"), baseTimestep.toString(), //$NON-NLS-1$ importTimestep.toString()))); /* Create the intervals. */ final Interval baseInterval = new Interval(new DateTime(baseRange.getFrom()), new DateTime(baseRange.getTo())); final Interval importInterval = new Interval(new DateTime(importRange.getFrom()), new DateTime(importRange.getTo())); /* Is the base range before the import range? */ /* Only a gap with one timestep is allowed. */ if (baseInterval.isBefore(importInterval)) { final DateTime baseEnd = baseInterval.getEnd(); final DateTime importStart = importInterval.getStart(); final Period gap = new Period(baseEnd, importStart); final Minutes gapMinutes = gap.toStandardMinutes(); if (gapMinutes.getMinutes() > 0 && baseMinutes.getMinutes() != gapMinutes.getMinutes()) throw new CoreException(new Status(IStatus.ERROR, KalypsoUIRRMPlugin.getID(), String.format(Messages.getString("MergeTimeseriesOperation.1"), baseMinutes.toString(), //$NON-NLS-1$ gapMinutes.toString()))); }//from www . java 2s . c om /* Is the base range after the import range? */ /* Only a gap with one timestep is allowed. */ if (baseInterval.isAfter(importInterval)) { final DateTime importEnd = importInterval.getEnd(); final DateTime baseStart = baseInterval.getStart(); final Period gap = new Period(importEnd, baseStart); final Minutes gapMinutes = gap.toStandardMinutes(); if (gapMinutes.getMinutes() > 0 && baseMinutes.getMinutes() != gapMinutes.getMinutes()) throw new CoreException(new Status(IStatus.ERROR, KalypsoUIRRMPlugin.getID(), String.format(Messages.getString("MergeTimeseriesOperation.1"), baseMinutes.toString(), //$NON-NLS-1$ gapMinutes.toString()))); } /* Here the intervals touch or overlap. */ }
From source file:syncthing.android.service.ServiceSettings.java
License:Open Source License
static long getNextNextStartTimeFor(long start, long end) { DateTime now = DateTime.now();//from w ww . jav a 2 s . c o m Interval interval = SyncthingUtils.getIntervalForRange(now, start, end); if (interval.isAfter(now)) { //Interval hasnt started yet return interval.getStartMillis(); } else { //were either inside the interval or past it, get the next days start //XXX we count inside interval as next day so if user // explicitly shuts us down we dont just start again return interval.getStart().plusDays(1).getMillis(); } }