List of usage examples for org.joda.time LocalDate isBefore
public boolean isBefore(ReadablePartial partial)
From source file:com.axelor.apps.tool.date.Period.java
License:Open Source License
public Period prorata(LocalDate date1, LocalDate date2) { Period p = null;// www .j a va 2 s . c om if (DateTool.isProrata(this.from, this.to, date1, date2)) { p = new Period(this); if (date1.isAfter(this.from)) { p.setFrom(date1); } if (date2 != null && date2.isBefore(this.to)) { p.setTo(date2); } } return p; }
From source file:com.axelor.auth.AuthUtils.java
License:Open Source License
public static boolean isActive(final User user) { if (user.getArchived() == Boolean.TRUE || user.getBlocked() == Boolean.TRUE) { return false; }//from w ww . j a va 2s. c om final LocalDate from = user.getActivateOn(); final LocalDate till = user.getExpiresOn(); final LocalDate now = LocalDate.now(); if ((from != null && from.isAfter(now)) || (till != null && till.isBefore(now))) { return false; } return true; }
From source file:com.cedarsoft.history.core.ContinuousEntriesInformation.java
License:Open Source License
/** * Returns the entry for the given date/*w ww.ja va 2 s. c o m*/ * * @param date the date * @return the entry * * @throws NoValidElementFoundException * if any. */ @Nonnull public E findEntry(@Nonnull LocalDate date) throws NoValidElementFoundException { if (date.isBefore(begin)) { throw new IllegalArgumentException("Date " + date + " is before beginning of the history: " + begin); } if (!date.isBefore(end)) { throw new IllegalArgumentException("Date " + date + " is after end of the history: " + end); } lock.readLock().lock(); E lastEntry = null; try { for (E entry : entries) { if (entry.getBegin().isAfter(date)) { break; } lastEntry = entry; } } finally { lock.readLock().unlock(); } if (lastEntry == null) { throw new NoValidElementFoundException("Date too early: No entry found for " + date); } else { return lastEntry; } }
From source file:com.cedarsoft.history.core.ContinuousEntriesInformation.java
License:Open Source License
/** * <p>findEntries</p>/*from w ww .j ava 2 s. c om*/ * * @param begin a LocalDate object. * @param end a LocalDate object. * @return a List object. */ @Nonnull public List<? extends E> findEntries(@Nonnull LocalDate begin, @Nonnull LocalDate end) { if (end.isBefore(this.begin)) { throw new IllegalArgumentException("End " + end + " is before beginning of the history: " + this.begin); } if (begin.isAfter(this.end)) { throw new IllegalArgumentException("Begin " + begin + " is after ending of the history: " + this.end); } List<E> foundEntries = new ArrayList<E>(); lock.readLock().lock(); try { for (E entry : this.entries) { if (DateUtils.isBetween(entry.getBegin(), begin, end)) { foundEntries.add(entry); } } } finally { lock.readLock().unlock(); } return foundEntries; }
From source file:com.cedarsoft.history.core.DateUtils.java
License:Open Source License
/** * Returns true if the given date is after/same than the begin and before the end * * @param date the date// w w w . j a va 2 s .c o m * @param begin the begin (inclusive) * @param end the end (exclusive) * @return whether the given date is between the two given dates */ public static boolean isBetween(@Nonnull LocalDate date, @Nonnull LocalDate begin, @Nonnull LocalDate end) { if (begin.isAfter(date)) { return false; } return date.isBefore(end); }
From source file:com.esofthead.mycollab.core.utils.BusinessDayTimeUtils.java
License:Open Source License
public static int duration(LocalDate start, LocalDate end) { int candidateDuration = 1; if (start.isAfter(end)) { return -1; }//from w ww. ja v a 2s . c o m try { DateCalculator<LocalDate> calc1 = LocalDateKitCalculatorsFactory.forwardCalculator("MyCollab"); calc1.setStartDate(start); start = calc1.getCurrentBusinessDate(); calc1.setStartDate(end); if (calc1.isNonWorkingDay(end)) { candidateDuration -= 1; end = calc1.getCurrentBusinessDate(); } long possibleDurations = (end.toDate().getTime() - start.toDate().getTime()) / DateTimeUtils.MILLISECONDS_IN_A_DAY; int varDays = Math.round((possibleDurations + 1) / 2); calc1.setStartDate(start); LocalDate testDate; while (true) { LocalDate previousBizDate = calc1.getCurrentBusinessDate(); calc1.moveByBusinessDays(varDays); testDate = calc1.getCurrentBusinessDate(); if (testDate.isAfter(end)) { varDays = Math.round((varDays + 1) / 2); calc1.setCurrentBusinessDate(previousBizDate); } else if (testDate.isBefore(end)) { candidateDuration += varDays; varDays = Math.round(varDays / 2); calc1.setStartDate(testDate); } else { return candidateDuration + varDays; } if (varDays == 0) { calc1.setStartDate(testDate); calc1.moveByBusinessDays(1); testDate = calc1.getCurrentBusinessDate(); if (!testDate.isEqual(end)) { // LOG.error("Error while calculate duration of " + start + "--" + end); } return candidateDuration + 1; } } } catch (Exception e) { LOG.error("Error while calculate duration of " + start + "--" + end); return candidateDuration; } }
From source file:com.esofthead.mycollab.module.project.view.assignments.gantt.GanttItemWrapper.java
License:Open Source License
public boolean setStartAndEndDate(LocalDate newStartDate, LocalDate newEndDate, boolean askToCheckPredecessors, boolean requestToCheckDependents) { if (newStartDate.isBefore(fixedStartDateByChilds) || newEndDate.isAfter(fixedEndDatebyChilds)) { throw new UserInvalidInputException("Invalid constraints"); }/* w w w . j a v a 2 s . c o m*/ boolean hasChange = false; if (!this.startDate.isEqual(newStartDate)) { hasChange = true; this.startDate = newStartDate; task.setStartDate(startDate.toDate()); ownStep.setStartDate(startDate.toDate()); } if (!this.endDate.isEqual(newEndDate)) { hasChange = true; this.endDate = newEndDate; task.setEndDate(endDate.toDate()); ownStep.setEndDate(endDate.plusDays(1).toDate()); } if (hasChange) { int duration = BusinessDayTimeUtils.duration(newStartDate, newEndDate); setDuration(duration * DateTimeUtils.MILISECONDS_IN_A_DAY); onDateChanges(askToCheckPredecessors, requestToCheckDependents); } return hasChange; }
From source file:com.esofthead.mycollab.module.project.view.assignments.gantt.GanttItemWrapper.java
License:Open Source License
public void adjustTaskDatesByPredecessors(List<TaskPredecessor> predecessors) { if (CollectionUtils.isNotEmpty(predecessors)) { LocalDate currentStartDate = new LocalDate(getStartDate()); LocalDate currentEndDate = new LocalDate(getEndDate()); LocalDate boundStartDate = new LocalDate(1970, 1, 1); LocalDate boundEndDate = new LocalDate(2100, 1, 1); for (TaskPredecessor predecessor : predecessors) { int ganttIndex = predecessor.getGanttIndex(); GanttItemWrapper ganttPredecessor = gantt.getBeanContainer().getItemByGanttIndex(ganttIndex); int dur = getDuration().intValue() - 1; if (ganttPredecessor != null) { Integer lagDay = predecessor.getLagday() + 1; if (TaskPredecessor.FS.equals(predecessor.getPredestype())) { LocalDate endDate = new LocalDate(ganttPredecessor.getEndDate()); endDate = endDate.plusDays(1); LocalDate expectedStartDate = BusinessDayTimeUtils.plusDays(endDate, lagDay); if (boundStartDate.isBefore(expectedStartDate)) { boundStartDate = expectedStartDate; }// ww w.j av a2 s . c o m if (currentStartDate.isBefore(expectedStartDate)) { currentStartDate = expectedStartDate; LocalDate expectedEndDate = currentStartDate.plusDays(dur); currentEndDate = DateTimeUtils.min(boundEndDate, expectedEndDate); } } else if (TaskPredecessor.FF.equals(predecessor.getPredestype())) { LocalDate endDate = new LocalDate(ganttPredecessor.getEndDate()); LocalDate expectedEndDate = BusinessDayTimeUtils.plusDays(endDate, lagDay); if (boundEndDate.isAfter(expectedEndDate)) { boundEndDate = expectedEndDate; } if (currentEndDate.isAfter(expectedEndDate)) { currentEndDate = expectedEndDate; LocalDate expectedStartDate = currentEndDate.minusDays(dur); currentStartDate = DateTimeUtils.max(boundStartDate, expectedStartDate); } } else if (TaskPredecessor.SF.equals(predecessor.getPredestype())) { LocalDate startDate = new LocalDate(ganttPredecessor.getStartDate()); LocalDate expectedEndDate = BusinessDayTimeUtils.plusDays(startDate, lagDay); if (boundEndDate.isAfter(expectedEndDate)) { boundEndDate = expectedEndDate; } if (currentEndDate.isAfter(expectedEndDate)) { currentEndDate = expectedEndDate; LocalDate expectedStartDate = currentEndDate.minusDays(dur); currentStartDate = DateTimeUtils.max(boundStartDate, expectedStartDate); } } else if (TaskPredecessor.SS.equals(predecessor.getPredestype())) { LocalDate startDate = new LocalDate(ganttPredecessor.getStartDate()); LocalDate expectedStartDate = BusinessDayTimeUtils.plusDays(startDate, lagDay); if (boundStartDate.isBefore(expectedStartDate)) { boundStartDate = expectedStartDate; } if (currentStartDate.isBefore(expectedStartDate)) { currentStartDate = expectedStartDate; LocalDate expectedEndDate = BusinessDayTimeUtils.plusDays(startDate, dur); currentEndDate = DateTimeUtils.min(boundEndDate, expectedEndDate); } } else { throw new MyCollabException( "Do not support predecessor type " + predecessor.getPredestype()); } if (currentEndDate.isBefore(currentStartDate)) { throw new UserInvalidInputException("Invalid constraint"); } } } setStartAndEndDate(currentStartDate, currentEndDate, false, true); } }
From source file:com.github.fauu.natrank.model.entity.Period.java
License:Open Source License
public boolean includesDate(LocalDate date) { return (!date.isBefore(fromDate) && (toDate == null || !date.isAfter(toDate))); }
From source file:com.github.serddmitry.jodainterval.LocalDateIntervalImpl.java
License:Apache License
@Override public boolean contains(LocalDate date) { return !date.isAfter(last) && !date.isBefore(first); }