Example usage for org.joda.time Interval Interval

List of usage examples for org.joda.time Interval Interval

Introduction

In this page you can find the example usage for org.joda.time Interval Interval.

Prototype

public Interval(Object interval, Chronology chronology) 

Source Link

Document

Constructs a time interval by converting or copying from another object, overriding the chronology.

Usage

From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonContractSituation.java

License:Open Source License

private Interval getInterval() {
    return getBeginDate() != null && getEndDate() != null
            ? new Interval(getBeginDate().toDateTimeAtStartOfDay(),
                    getEndDate().plusDays(1).toDateTimeAtStartOfDay())
            : null;//w w w.j a v a2s . co  m
}

From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonContractSituation.java

License:Open Source License

public boolean betweenDates(LocalDate begin, LocalDate end) {
    Interval dateInterval = new Interval(begin.toDateTimeAtStartOfDay(),
            end.toDateTimeAtStartOfDay().plusDays(1));
    return betweenDates(dateInterval);
}

From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonProfessionalCategory.java

License:Open Source License

public boolean betweenDates(LocalDate beginDate, LocalDate endDate) {
    if (isValid()) {
        if (getEndDate() == null) {
            return endDate == null || !getBeginDate().isAfter(endDate);
        }//from   w ww  .  j a  v a 2 s  . co  m
        if (endDate == null) {
            return !beginDate.isAfter(getEndDate());
        }
        Interval dateInterval = new Interval(beginDate.toDateTimeAtStartOfDay(),
                endDate.toDateTimeAtStartOfDay().plusDays(1));
        return getInterval().overlaps(dateInterval);
    }
    return false;
}

From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonProfessionalData.java

License:Open Source License

public ProfessionalCategory getLastProfessionalCategoryByCategoryType(CategoryType categoryType,
        LocalDate beginDate, LocalDate endDate) {
    Interval dateInterval = null;//w  w  w . jav a 2s . co  m
    if (beginDate != null && endDate != null) {
        dateInterval = new Interval(beginDate.toDateTimeAtStartOfDay(),
                endDate.plusDays(1).toDateTimeAtStartOfDay());
    }
    PersonContractSituation lastPersonContractSituation = null;
    GiafProfessionalData giafProfessionalData = getGiafProfessionalData();
    if (giafProfessionalData != null) {
        for (final PersonContractSituation situation : giafProfessionalData
                .getValidPersonContractSituations()) {
            if ((dateInterval == null || situation.overlaps(dateInterval))
                    && (categoryType == null || (situation.getProfessionalCategory() != null
                            && situation.getProfessionalCategory().getCategoryType().equals(categoryType)))
                    && (lastPersonContractSituation == null
                            || situation.isAfter(lastPersonContractSituation))) {
                lastPersonContractSituation = situation;
            }
        }
    }
    return lastPersonContractSituation == null ? null : lastPersonContractSituation.getProfessionalCategory();
}

From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonProfessionalData.java

License:Open Source License

public PersonContractSituation getCurrentOrLastPersonContractSituationByCategoryType(CategoryType categoryType,
        LocalDate beginDate, LocalDate endDate) {
    LocalDate today = new LocalDate();
    Interval dateInterval = null;/*  w  w w.j  a v a  2s .c  om*/
    if (beginDate != null && endDate != null) {
        dateInterval = new Interval(beginDate.toDateTimeAtStartOfDay(),
                endDate.plusDays(1).toDateTimeAtStartOfDay());
    }
    PersonContractSituation lastPersonContractSituation = null;
    PersonContractSituation currentPersonContractSituation = null;
    GiafProfessionalData giafProfessionalDataByCategoryType = getGiafProfessionalData();
    if (giafProfessionalDataByCategoryType != null) {
        for (final PersonContractSituation situation : giafProfessionalDataByCategoryType
                .getValidPersonContractSituations()) {
            if ((categoryType == null || (situation.getProfessionalCategory() != null
                    && situation.getProfessionalCategory().getCategoryType().equals(categoryType)))) {
                if ((dateInterval == null || situation.overlaps(dateInterval))) {
                    if (situation.isActive(today) && (currentPersonContractSituation == null
                            || situation.isAfter(currentPersonContractSituation))) {
                        currentPersonContractSituation = situation;
                    }
                    lastPersonContractSituation = situation;
                }
            }
        }
    }
    return currentPersonContractSituation != null ? currentPersonContractSituation
            : lastPersonContractSituation;
}

From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonProfessionalExemption.java

License:Open Source License

public boolean isLongDuration() {
    Integer daysBetween = new Interval(getBeginDate().toDateTimeAtStartOfDay(),
            getEndDate().toDateTimeAtStartOfDay().plusDays(1)).toPeriod(PeriodType.days()).getDays();
    return (daysBetween == null || daysBetween >= 90);
}

From source file:net.sourceforge.fenixedu.domain.phd.PhdIndividualProgramProcess.java

License:Open Source License

public boolean isActive(Interval interval) {
    List<Interval> activeStatesIntervals = new ArrayList<Interval>();
    Set<PhdProgramProcessState> states = new TreeSet<PhdProgramProcessState>(new Comparator<PhdProcessState>() {
        @Override//from  w  w  w  .  jav a  2  s .  co  m
        public int compare(PhdProcessState o1, PhdProcessState o2) {
            DateTime o1StateDate = o1.getStateDate() == null ? o1.getWhenCreated() : o1.getStateDate();
            DateTime o2StateDate = o2.getStateDate() == null ? o2.getWhenCreated() : o2.getStateDate();
            int result = o1StateDate.compareTo(o2StateDate);
            return result != 0 ? result : o1.getExternalId().compareTo(o2.getExternalId());
        }
    });
    states.addAll(getStates());
    DateTime beginActiveDate = null;
    for (PhdProgramProcessState state : states) {
        if (state.getType().isActive() && beginActiveDate == null) {
            beginActiveDate = state.getStateDate() == null ? state.getWhenCreated() : state.getStateDate();
        }
        if ((!state.getType().isActive()) && beginActiveDate != null) {
            activeStatesIntervals.add(new Interval(beginActiveDate,
                    state.getStateDate() == null ? state.getWhenCreated() : state.getStateDate()));
            beginActiveDate = null;
        }
    }
    for (Interval activeInterval : activeStatesIntervals) {
        if (interval.overlaps(activeInterval)) {
            return true;
        }
    }
    return (activeStatesIntervals.size() == 0 && beginActiveDate != null);
}

From source file:net.sourceforge.fenixedu.domain.phd.PhdProgramContextPeriod.java

License:Open Source License

private boolean overlaps(DateTime beginPeriod, DateTime endPeriod) {
    return getInterval().overlaps(new Interval(beginPeriod, endPeriod));
}

From source file:net.sourceforge.fenixedu.domain.phd.PhdProgramContextPeriod.java

License:Open Source License

public Interval getInterval() {
    return new Interval(getBeginDate(), getEndDate());
}

From source file:net.sourceforge.fenixedu.domain.reports.TeacherCreditsReportFile.java

License:Open Source License

@Override
public void renderReport(Spreadsheet spreadsheet) throws Exception {
    ExecutionYear executionYear = getExecutionYear();
    spreadsheet.setName("Docentes do " + Unit.getInstitutionAcronym() + " "
            + executionYear.getQualifiedName().replace("/", ""));
    spreadsheet.setHeader("IstId");
    spreadsheet.setHeader("N Mec");
    spreadsheet.setHeader("Nome");
    spreadsheet.setHeader("Semestre");
    spreadsheet.setHeader("Categoria");
    spreadsheet.setHeader("Situao");
    spreadsheet.setHeader("Regime");
    spreadsheet.setHeader("Docente de carreira");
    spreadsheet.setHeader("Departamento - ltimo");
    spreadsheet.setHeader("Departamento - dominante");
    spreadsheet.setHeader("CLE");
    spreadsheet.setHeader("CLE - correces");
    spreadsheet.setHeader("CL");
    spreadsheet.setHeader("CG");
    spreadsheet.setHeader("O");
    spreadsheet.setHeader("AD65 requerido");
    spreadsheet.setHeader("AD65 atribudo");
    spreadsheet.setHeader("SNE");
    spreadsheet.setHeader("CLN");
    //1 sem/*from   w  ww.  j av  a2  s  .co  m*/
    spreadsheet.setHeader("COT");
    spreadsheet.setHeader("COD");
    spreadsheet.setHeader("COM");
    //2 sem
    spreadsheet.setHeader("CO");
    spreadsheet.setHeader("CF");
    spreadsheet.setHeader("CLA");
    spreadsheet.setHeader("SNE - Descrio");
    spreadsheet.setHeader("O - Descrio");

    Collection<Teacher> teachers = Bennu.getInstance().getTeachersSet();
    for (ExecutionSemester executionSemester : executionYear.getExecutionPeriodsSet()) {
        Interval semesterInterval = new Interval(
                executionSemester.getBeginDateYearMonthDay().toLocalDate().toDateTimeAtStartOfDay(),
                executionSemester.getEndDateYearMonthDay().toLocalDate().toDateTimeAtStartOfDay());
        for (Teacher teacher : teachers) {
            boolean isContractedTeacher = teacher.isActiveForSemester(executionSemester);
            TeacherAuthorization teacherAuthorization = teacher.getTeacherAuthorization(executionSemester);
            if (isContractedTeacher || teacherAuthorization != null) {
                final Row row = spreadsheet.addRow();
                row.setCell(teacher.getPerson().getUsername());
                row.setCell(teacher.getPerson().getEmployee() != null
                        ? teacher.getPerson().getEmployee().getEmployeeNumber()
                        : null);
                row.setCell(teacher.getPerson().getName());
                row.setCell(executionSemester.getName());
                ProfessionalCategory category = null;
                PersonContractSituation situation = null;
                ProfessionalRegime regime = null;
                if (isContractedTeacher) {
                    category = teacher.getCategoryByPeriod(executionSemester);
                    situation = teacher.getCurrentOrLastTeacherContractSituation(
                            executionSemester.getBeginDateYearMonthDay().toLocalDate(),
                            executionSemester.getEndDateYearMonthDay().toLocalDate());
                    regime = getProfessionalRegime(situation, semesterInterval);
                } else if (teacherAuthorization != null) {
                    category = teacherAuthorization.getProfessionalCategory();
                }
                row.setCell(category == null ? null : category.getName().getContent());
                row.setCell(situation == null ? null : situation.getContractSituation().getName().getContent());

                row.setCell(regime == null ? null : regime.getName().getContent());
                row.setCell(teacher.isTeacherProfessorCategory(executionSemester) ? "S" : "N");
                Department lastWorkingDepartment = teacher.getLastWorkingDepartment(
                        executionSemester.getBeginDateYearMonthDay(),
                        executionSemester.getEndDateYearMonthDay());
                row.setCell(lastWorkingDepartment == null ? null : lastWorkingDepartment.getName());
                Department creditsDepartment = getCreditsDepartment(teacher, executionSemester);
                row.setCell(creditsDepartment == null ? null : creditsDepartment.getName());

                TeacherService teacherService = teacher.getTeacherServiceByExecutionPeriod(executionSemester);
                row.setCell(teacherService == null ? 0 : teacherService.getTeachingDegreeHours());// CLE

                row.setCell(teacherService == null ? 0 : teacherService.getTeachingDegreeCorrections());// CLE corrections

                row.setCell(teacherService == null ? 0 : teacherService.getTeachingDegreeCredits());// CL

                row.setCell(teacher.getManagementFunctionsCredits(executionSemester)); // CG
                //CG (desc)
                row.setCell(teacherService == null ? 0 : teacherService.getOtherServiceCredits());// O
                Double creditsReductionRequired = teacherService == null ? null
                        : teacherService.getReductionService() == null ? null
                                : teacherService.getReductionService().getCreditsReduction() == null ? null
                                        : teacherService.getReductionService().getCreditsReduction()
                                                .doubleValue();

                Double creditsReductionAttributed = teacherService == null ? null
                        : teacherService.getReductionService() == null ? null
                                : teacherService.getReductionService().getCreditsReductionAttributed() == null
                                        ? null
                                        : teacherService.getReductionService().getCreditsReductionAttributed()
                                                .doubleValue();
                row.setCell(creditsReductionRequired);// AD65 requerido
                row.setCell(creditsReductionAttributed);// AD65 atribudo

                row.setCell(teacher.getServiceExemptionCredits(executionSemester)); //SNE

                row.setCell(teacher.getMandatoryLessonHours(executionSemester)); //CLN

                AnnualTeachingCreditsBean annualTeachingCreditsBean = new AnnualTeachingCreditsBean(
                        executionYear, teacher, RoleType.SCIENTIFIC_COUNCIL);
                annualTeachingCreditsBean.calculateCredits();
                if (executionSemester.getSemester() == 1) {
                    row.setCell(annualTeachingCreditsBean.getProjectsTutorialsCredits());//COT
                    row.setCell(annualTeachingCreditsBean.getPhdDegreeThesesCredits());//COD
                    row.setCell(annualTeachingCreditsBean.getMasterDegreeThesesCredits());//COM
                    row.setCell(EMPTY_CELL);//CO
                    row.setCell(EMPTY_CELL);//CF
                    row.setCell(EMPTY_CELL);//CLA
                } else {
                    row.setCell(EMPTY_CELL);//COT
                    row.setCell(EMPTY_CELL);//COD
                    row.setCell(EMPTY_CELL);//COM
                    row.setCell(annualTeachingCreditsBean.getYearCredits());//CO
                    row.setCell(annualTeachingCreditsBean.getFinalCredits());//CF
                    row.setCell(annualTeachingCreditsBean.getAccumulatedCredits());//CLA         
                }
                row.setCell(getServiceExemptionDescription(executionSemester, teacher)); //SNE Desc
                row.setCell(teacherService == null ? EMPTY_CELL : getOthersDesciption(teacherService));//O (desc)
            }
        }
    }
}