List of usage examples for org.joda.time YearMonthDay minusDays
public YearMonthDay minusDays(int days)
From source file:net.sourceforge.fenixedu.domain.ExecutionCourse.java
License:Open Source License
public boolean isInExamPeriod() { final YearMonthDay yearMonthDay = new YearMonthDay(); final ExecutionSemester executionSemester = getExecutionPeriod(); final ExecutionYear executionYear = getExecutionPeriod().getExecutionYear(); for (final CurricularCourse curricularCourse : getAssociatedCurricularCoursesSet()) { final DegreeCurricularPlan degreeCurricularPlan = curricularCourse.getDegreeCurricularPlan(); final ExecutionDegree executionDegree = degreeCurricularPlan.getExecutionDegreeByYear(executionYear); final YearMonthDay startExamsPeriod; if (executionSemester.getSemester().intValue() == 1) { startExamsPeriod = executionDegree.getPeriodExamsFirstSemester().getStartYearMonthDay(); } else if (executionSemester.getSemester().intValue() == 2) { startExamsPeriod = executionDegree.getPeriodExamsSecondSemester().getStartYearMonthDay(); } else {/* ww w . j ava 2 s .co m*/ throw new DomainException("unsupported.execution.period.semester"); } if (!startExamsPeriod.minusDays(2).isAfter(yearMonthDay)) { return true; } } return false; }
From source file:net.sourceforge.fenixedu.domain.Lesson.java
License:Open Source License
public void refreshPeriodAndInstancesInSummaryCreation(YearMonthDay newBeginDate) { if (!wasFinished() && newBeginDate != null && newBeginDate.isAfter(getPeriod().getStartYearMonthDay())) { SortedSet<YearMonthDay> instanceDates = getAllLessonInstancesDatesToCreate(getLessonStartDay(), newBeginDate.minusDays(1), true); YearMonthDay newEndDate = getPeriod().getLastOccupationPeriodOfNestedPeriods().getEndYearMonthDay(); if (!newBeginDate.isAfter(newEndDate)) { refreshPeriod(newBeginDate,/*ww w. j av a 2s. c om*/ getPeriod().getLastOccupationPeriodOfNestedPeriods().getEndYearMonthDay()); } else { OccupationPeriod period = getPeriod(); removeLessonSpaceOccupationAndPeriod(); period.delete(); } createAllLessonInstances(instanceDates); } }
From source file:net.sourceforge.fenixedu.domain.Lesson.java
License:Open Source License
private void refreshPeriodAndInstancesInEditOperation(YearMonthDay newBeginDate, YearMonthDay newEndDate, Boolean createLessonInstances, GenericPair<YearMonthDay, YearMonthDay> maxLessonsPeriod) { removeExistentInstancesWithoutSummaryAfterOrEqual(newBeginDate); SortedSet<YearMonthDay> instanceDates = getAllLessonInstancesDatesToCreate(getLessonStartDay(), newBeginDate.minusDays(1), createLessonInstances); refreshPeriod(newBeginDate, newEndDate); createAllLessonInstances(instanceDates); }
From source file:net.sourceforge.fenixedu.domain.Lesson.java
License:Open Source License
private YearMonthDay getValidEndDate(YearMonthDay endDate) { YearMonthDay lessonEnd = endDate.toDateTimeAtMidnight() .withDayOfWeek(getDiaSemana().getDiaSemanaInDayOfWeekJodaFormat()).toYearMonthDay(); if (lessonEnd.isAfter(endDate)) { lessonEnd = lessonEnd.minusDays(NUMBER_OF_DAYS_IN_WEEK); }/*w w w . ja v a 2 s . co m*/ return lessonEnd; }
From source file:net.sourceforge.fenixedu.domain.organizationalStructure.DegreeUnit.java
License:Open Source License
public PersonFunction addYearDelegatePersonFunction(Student student, CurricularYear curricularYear) { Registration lastActiveRegistration = student.getActiveRegistrationFor(getDegree()); if (lastActiveRegistration == null || !lastActiveRegistration.getDegree().equals(getDegree())) { throw new DomainException("error.delegates.studentNotBelongsToDegree"); }//w w w.j av a 2 s . com YearMonthDay currentDate = new YearMonthDay(); // The following restriction tries to guarantee that a new delegate is // elected before this person function ends ExecutionYear currentExecutionYear = ExecutionYear.readCurrentExecutionYear(); YearMonthDay endDate = currentExecutionYear.getEndDateYearMonthDay().plusYears(1); Function function = getActiveDelegateFunctionByType(FunctionType.DELEGATE_OF_YEAR); /* Check if there is another active person function with this type */ if (function != null) { List<PersonFunction> delegateFunctions = function.getActivePersonFunctions(); for (PersonFunction personFunction : delegateFunctions) { if (personFunction.getCurricularYear().equals(curricularYear) || personFunction.getDelegate().getRegistration().getStudent().equals(student)) { Student oldStudent = personFunction.getPerson().getStudent(); if (personFunction.getBeginDate().equals(currentDate)) { personFunction.getDelegate().delete(); } else { personFunction.setOccupationInterval(personFunction.getBeginDate(), currentDate.minusDays(1)); } final DelegateElection election = getDegree().getYearDelegateElectionWithLastCandidacyPeriod( ExecutionYear.readCurrentExecutionYear(), curricularYear); if (election != null && election.getElectedStudent() == oldStudent) { election.setElectedStudent(null); } } } } return PersonFunction.createYearDelegatePersonFunction(this, student.getPerson(), currentDate, endDate, function, curricularYear); }
From source file:net.sourceforge.fenixedu.domain.organizationalStructure.DegreeUnit.java
License:Open Source License
public void addDelegatePersonFunction(Student student, FunctionType functionType) { Registration lastActiveRegistration = student.getLastActiveRegistration(); if (lastActiveRegistration == null || !lastActiveRegistration.getDegree().equals(getDegree())) { throw new DomainException("error.delegates.studentNotBelongsToDegree"); }/*from w w w . j av a 2 s . co m*/ YearMonthDay currentDate = new YearMonthDay(); // The following restriction tries to guarantee that a new delegate is // elected before this person function ends ExecutionYear currentExecutionYear = ExecutionYear.readCurrentExecutionYear(); YearMonthDay endDate = currentExecutionYear.getEndDateYearMonthDay().plusYears(1); Function function = getActiveDelegateFunctionByType(functionType); /* Check if there is another active person function with this type */ if (function != null) { List<PersonFunction> delegateFunctions = function.getActivePersonFunctions(); for (PersonFunction personFunction : delegateFunctions) { if (personFunction.getBeginDate().equals(currentDate)) { if (personFunction.getFunction().getFunctionType().equals(FunctionType.DELEGATE_OF_YEAR)) { personFunction.getDelegate().delete(); } else { personFunction.delete(); } } else { personFunction.setOccupationInterval(personFunction.getBeginDate(), currentDate.minusDays(1)); } } } PersonFunction.createDelegatePersonFunction(this, student.getPerson(), currentDate, endDate, function); }
From source file:net.sourceforge.fenixedu.domain.organizationalStructure.DegreeUnit.java
License:Open Source License
public void removeActiveDelegatePersonFunctionFromStudentByFunctionType(Student student, FunctionType functionType) {//from w w w . j av a 2s . c o m YearMonthDay today = new YearMonthDay(); List<PersonFunction> delegatesFunctions = getAllActiveDelegatePersonFunctionsByFunctionType(functionType, null); if (!delegatesFunctions.isEmpty()) { for (PersonFunction function : delegatesFunctions) { Student delegateStudent = function.getPerson().getStudent(); if (delegateStudent.equals(student)) { function.setOccupationInterval(function.getBeginDate(), today.minusDays(1)); } } } }
From source file:net.sourceforge.fenixedu.domain.organizationalStructure.PedagogicalCouncilUnit.java
License:Open Source License
public void addDelegatePersonFunction(Person person, Function delegateFunction) { YearMonthDay currentDate = new YearMonthDay(); // The following restriction tries to guarantee that a new delegate is // elected before this person function ends ExecutionYear currentExecutionYear = ExecutionYear.readCurrentExecutionYear(); YearMonthDay endDate = currentExecutionYear.getEndDateYearMonthDay().plusYears(1); /* Check if there is another active person function with this type */ if (delegateFunction != null) { List<PersonFunction> delegateFunctions = delegateFunction.getActivePersonFunctions(); if (!delegateFunctions.isEmpty()) { for (PersonFunction personFunction : delegateFunctions) { if (personFunction.getBeginDate().equals(currentDate)) { if (personFunction.getFunction().getFunctionType().equals(FunctionType.DELEGATE_OF_YEAR)) { personFunction.getDelegate().delete(); } else { personFunction.delete(); }// w w w.j av a 2 s . c om } else { personFunction.setOccupationInterval(personFunction.getBeginDate(), currentDate.minusDays(1)); } } } } PersonFunction.createDelegatePersonFunction(this, person, currentDate, endDate, delegateFunction); }
From source file:net.sourceforge.fenixedu.domain.organizationalStructure.PedagogicalCouncilUnit.java
License:Open Source License
public void removeActiveDelegatePersonFunctionFromPersonByFunction(Person person, Function function) { YearMonthDay today = new YearMonthDay(); List<PersonFunction> delegatesFunctions = function.getActivePersonFunctions(); if (!delegatesFunctions.isEmpty()) { for (PersonFunction personfunction : delegatesFunctions) { Person delegate = personfunction.getPerson(); if (delegate.equals(person)) { if (personfunction.getBeginDate().equals(today)) { if (personfunction.getFunction().getFunctionType().equals(FunctionType.DELEGATE_OF_YEAR)) { personfunction.getDelegate().delete(); } else { personfunction.delete(); }/*from w ww .ja va 2s . c om*/ } else { personfunction.setOccupationInterval(personfunction.getBeginDate(), today.minusDays(1)); } } } } }
From source file:net.sourceforge.fenixedu.presentationTier.TagLib.GanttDiagramTagLib.java
License:Open Source License
private void insertNextAndBeforeLinks(StringBuilder builder) throws JspException { YearMonthDay firstDay = getGanttDiagramObject().getFirstInstant().toYearMonthDay(); if (firstDay != null) { String nextUrl = ""; String beforeUrl = ""; switch (getViewTypeEnum()) { case WEEKLY: if (!StringUtils.isEmpty(getWeeklyViewUrl())) { nextUrl = getRequest().getContextPath() + getWeeklyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.plusDays(Lesson.NUMBER_OF_DAYS_IN_WEEK).toString("ddMMyyyy"); beforeUrl = getRequest().getContextPath() + getWeeklyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.minusDays(Lesson.NUMBER_OF_DAYS_IN_WEEK).toString("ddMMyyyy"); builder.append(// w w w . j a v a 2 s.c o m "<tr><td class=\"tcalendarlinks\"></td><td colspan=\"7\" class=\"acenter tcalendarlinks\"> <span class=\"smalltxt\"><a href=\"") .append(beforeUrl).append("\">").append("<< ") .append(getMessage("label.previous.week")).append("</a>"); builder.append(" , ").append("<a href=\"").append(nextUrl).append("\">") .append(getMessage("label.next.week")).append(" >>").append("</a>") .append("</span></td><td class=\"tcalendarlinks\"></td><td class=\"tcalendarlinks\"></td></tr>"); } break; case DAILY: if (!StringUtils.isEmpty(getDailyViewUrl())) { nextUrl = getRequest().getContextPath() + getDailyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.plusDays(1).toString("ddMMyyyy"); beforeUrl = getRequest().getContextPath() + getDailyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.minusDays(1).toString("ddMMyyyy"); builder.append( "<tr><td class=\"tcalendarlinks\"></td><td class=\"acenter tcalendarlinks\"><span class=\"smalltxt\"><a href=\"") .append(beforeUrl).append("\">").append("<< ") .append(getMessage("label.previous.day")).append("</a>"); builder.append(" , ").append("<a href=\"").append(nextUrl).append("\">") .append(getMessage("label.next.day")).append(" >>").append("</a>") .append("</span></td><td class=\"tcalendarlinks\"></td><td class=\"tcalendarlinks\"></td></tr>"); } break; case MONTHLY: if (!StringUtils.isEmpty(getMonthlyViewUrl())) { DateTime month = firstDay.toDateTimeAtMidnight(); DateTime firstDayOfMonth = (month.getDayOfMonth() != 1) ? month.withDayOfMonth(1) : month; DateTime lastDayOfMonth = firstDayOfMonth.plusMonths(1).minusDays(1); int monthNumberOfDays = Days.daysBetween(firstDayOfMonth, lastDayOfMonth).getDays() + 1; nextUrl = getRequest().getContextPath() + getMonthlyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.plusMonths(1).toString("ddMMyyyy"); beforeUrl = getRequest().getContextPath() + getMonthlyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.minusMonths(1).toString("ddMMyyyy"); builder.append("<tr><td class=\"tcalendarlinks\"></td><td colspan=\"").append(monthNumberOfDays) .append("\" class=\"acenter tcalendarlinks\"><span class=\"smalltxt\"><a href=\"") .append(beforeUrl).append("\">").append("<< ") .append(getMessage("label.previous.month")).append("</a>"); builder.append(" , ").append("<a href=\"").append(nextUrl).append("\">") .append(getMessage("label.next.month")).append(" >>").append("</a>") .append("</span></td><td class=\"tcalendarlinks\"></td><td class=\"tcalendarlinks\"></td></tr>"); } break; case YEAR_DAILY: if (!StringUtils.isEmpty(getMonthlyViewUrl())) { DateTime month = firstDay.toDateTimeAtMidnight(); DateTime firstDayOfMonth = (month.getDayOfMonth() != 1) ? month.withDayOfMonth(1) : month; DateTime lastDayOfMonth = firstDayOfMonth.plusMonths(1).minusDays(1); int monthNumberOfDays = Days.daysBetween(firstDayOfMonth, lastDayOfMonth).getDays() + 1; nextUrl = getRequest().getContextPath() + getMonthlyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.plusMonths(1).toString("ddMMyyyy"); beforeUrl = getRequest().getContextPath() + getMonthlyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.minusMonths(1).toString("ddMMyyyy"); builder.append("<tr><td class=\"tcalendarlinks\"></td><td colspan=\"").append(monthNumberOfDays) .append("\" class=\"acenter tcalendarlinks\"><span class=\"smalltxt\"><a href=\"") .append(beforeUrl).append("\">").append("<< ") .append(getMessage("label.previous.month")).append("</a>"); builder.append(" , ").append("<a href=\"").append(nextUrl).append("\">") .append(getMessage("label.next.month")).append(" >>").append("</a>") .append("</span></td><td class=\"tcalendarlinks\"></td><td class=\"tcalendarlinks\"></td></tr>"); } break; default: break; } } }