Example usage for org.joda.time LocalDate toDateTimeAtStartOfDay

List of usage examples for org.joda.time LocalDate toDateTimeAtStartOfDay

Introduction

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

Prototype

public DateTime toDateTimeAtStartOfDay() 

Source Link

Document

Converts this LocalDate to a full datetime at the earliest valid time for the date using the default time zone.

Usage

From source file:net.sourceforge.fenixedu.domain.Teacher.java

License:Open Source License

public double getServiceExemptionCredits(ExecutionSemester executionSemester) {
    Set<PersonContractSituation> personProfessionalExemptions = getValidTeacherServiceExemptions(
            executionSemester);//from w w w  .  j a  v  a2 s .  c om
    Interval semesterInterval = new Interval(
            executionSemester.getBeginDateYearMonthDay().toLocalDate().toDateTimeAtStartOfDay(),
            executionSemester.getEndDateYearMonthDay().toLocalDate().toDateTimeAtStartOfDay());
    int lessonsDays = semesterInterval.toPeriod(PeriodType.days()).getDays();

    List<Interval> notYetOverlapedIntervals = new ArrayList<Interval>();
    List<Interval> newIntervals = new ArrayList<Interval>();
    notYetOverlapedIntervals.add(semesterInterval);

    Double mandatoryLessonHours = getMandatoryLessonHours(executionSemester);
    Double maxSneHours = mandatoryLessonHours;
    TeacherService teacherService = getTeacherServiceByExecutionPeriod(executionSemester);
    if (teacherService != null && teacherService.getReductionService() != null) {
        maxSneHours = Math.max(0,
                (mandatoryLessonHours - teacherService.getReductionServiceCredits().doubleValue()));
    }

    for (PersonContractSituation personContractSituation : personProfessionalExemptions) {
        LocalDate exemptionEnd = personContractSituation.getServiceExemptionEndDate() == null
                ? semesterInterval.getEnd().toLocalDate()
                : personContractSituation.getServiceExemptionEndDate();

        Interval exemptionInterval = new Interval(
                personContractSituation.getBeginDate().toDateTimeAtStartOfDay(),
                exemptionEnd.toDateTimeAtStartOfDay());

        PersonProfessionalExemption personProfessionalExemption = personContractSituation
                .getPersonProfessionalExemption();
        if (personContractSituation.countForCredits(semesterInterval)) {
            if (personProfessionalExemption != null) {
                exemptionEnd = personProfessionalExemption.getEndDate() == null
                        ? semesterInterval.getEnd().toLocalDate()
                        : personProfessionalExemption.getEndDate();
                exemptionInterval = new Interval(
                        personProfessionalExemption.getBeginDate().toDateTimeAtStartOfDay(),
                        exemptionEnd.toDateTimeAtStartOfDay());
                if (personProfessionalExemption.getIsSabaticalOrEquivalent()) {
                    if (isSabbaticalForSemester(exemptionInterval, semesterInterval)) {
                        return maxSneHours;
                    } else {
                        continue;
                    }
                }
            }
            for (Interval notYetOverlapedInterval : notYetOverlapedIntervals) {
                Interval overlapInterval = exemptionInterval.overlap(notYetOverlapedInterval);
                if (overlapInterval != null) {
                    newIntervals.addAll(getNotOverlapedIntervals(overlapInterval, notYetOverlapedInterval));
                } else {
                    newIntervals.add(notYetOverlapedInterval);
                }
            }
            notYetOverlapedIntervals.clear();
            notYetOverlapedIntervals.addAll(newIntervals);
            newIntervals.clear();
        }
    }

    int notOverlapedDays = 0;
    for (Interval interval : notYetOverlapedIntervals) {
        notOverlapedDays += interval.toPeriod(PeriodType.days()).getDays();
    }
    int overlapedDays = lessonsDays - notOverlapedDays;
    Double overlapedPercentage = round(Double.valueOf(overlapedDays) / Double.valueOf(lessonsDays));
    return round(overlapedPercentage * maxSneHours);

}

From source file:net.sourceforge.fenixedu.domain.Teacher.java

License:Open Source License

public boolean isActiveForSemester(ExecutionSemester executionSemester) {
    int minimumWorkingDays = 90;
    int activeDays = 0;
    Interval semesterInterval = new Interval(
            executionSemester.getBeginDateYearMonthDay().toLocalDate().toDateTimeAtStartOfDay(),
            executionSemester.getEndDateYearMonthDay().toLocalDate().toDateTimeAtStartOfDay());
    PersonProfessionalData personProfessionalData = getPerson().getPersonProfessionalData();
    if (personProfessionalData != null) {
        GiafProfessionalData giafProfessionalData = personProfessionalData.getGiafProfessionalData();
        if (giafProfessionalData != null) {
            for (final PersonContractSituation situation : giafProfessionalData
                    .getValidPersonContractSituations()) {
                if (situation.overlaps(semesterInterval) && situation.getProfessionalCategory() != null
                        && situation.getProfessionalCategory().getCategoryType().equals(CategoryType.TEACHER)) {
                    LocalDate beginDate = situation.getBeginDate()
                            .isBefore(semesterInterval.getStart().toLocalDate())
                                    ? semesterInterval.getStart().toLocalDate()
                                    : situation.getBeginDate();
                    LocalDate endDate = situation.getEndDate() == null
                            || situation.getEndDate().isAfter(semesterInterval.getEnd().toLocalDate())
                                    ? semesterInterval.getEnd().toLocalDate()
                                    : situation.getEndDate();
                    int days = new Interval(beginDate.toDateTimeAtStartOfDay(),
                            endDate.toDateTimeAtStartOfDay()).toPeriod(PeriodType.days()).getDays() + 1;
                    activeDays = activeDays + days;
                }//from   ww w  .  ja  v  a  2s.c o m
            }
        }
    }
    return activeDays >= minimumWorkingDays;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.writtenEvaluations.SearchWrittenEvaluationsByDate.java

License:Open Source License

private Collection<ExecutionCourse> getExecutionCoursesActiveIn(LocalDate day) {
    DateTime date = day.toDateTimeAtStartOfDay();
    Set<ExecutionCourse> courses = new HashSet<>();
    for (ExecutionInterval interval : Bennu.getInstance().getExecutionIntervalsSet()) {
        if (interval instanceof ExecutionSemester && interval.getAcademicInterval().contains(date)) {
            ExecutionSemester semester = (ExecutionSemester) interval;
            courses.addAll(semester.getAssociatedExecutionCoursesSet());
        }// w  ww  . j  a v a  2s  .c  o  m
    }
    return courses;
}

From source file:no.digipost.api.util.Converters.java

License:Apache License

public static final Converter<LocalDate, DateTime> toDateTimeAfterStartOfDay(final Duration duration) {
    return new Converter<LocalDate, DateTime>() {
        @Override//  www  . j  a v  a2  s  . com
        public DateTime apply(LocalDate date) {
            return date.toDateTimeAtStartOfDay().plus(duration);
        }
    };
}

From source file:op.care.reports.PnlReport.java

License:Open Source License

private void reloadDisplay(final boolean lockmessageAfterwards) {
    /***//from   w  w w .  ja va 2  s.  c  o  m
     *               _                 _ ____  _           _
     *      _ __ ___| | ___   __ _  __| |  _ \(_)___ _ __ | | __ _ _   _
     *     | '__/ _ \ |/ _ \ / _` |/ _` | | | | / __| '_ \| |/ _` | | | |
     *     | | |  __/ | (_) | (_| | (_| | |_| | \__ \ |_) | | (_| | |_| |
     *     |_|  \___|_|\___/ \__,_|\__,_|____/|_|___/ .__/|_|\__,_|\__, |
     *                                              |_|            |___/
     */

    synchronized (contentmap) {
        SYSTools.clear(contentmap);
    }
    synchronized (cpMap) {
        SYSTools.clear(cpMap);
    }

    synchronized (linemap) {
        SYSTools.clear(linemap);
    }
    synchronized (valuecache) {
        SYSTools.clear(valuecache);
    }

    initPhase = true;

    OPDE.getMainframe().setBlocked(true);
    OPDE.getDisplayManager().setProgressBarMessage(new DisplayMessage(SYSTools.xx("misc.msg.wait"), -1, 100));
    final long time = System.currentTimeMillis();

    SwingWorker worker = new SwingWorker() {
        Date max = null;

        @Override
        protected Object doInBackground() throws Exception {

            GUITools.setResidentDisplay(resident);

            if (minmax == null) {
                minmax = NReportTools.getMinMax(resident);
            }

            holidays = Collections.synchronizedMap(
                    SYSCalendar.getHolidays(minmax.getStart().getYear(), minmax.getEnd().getYear()));

            if (minmax != null) {
                max = minmax.getEnd().toDate();
                LocalDate start = SYSCalendar.bom(minmax.getStart()).toLocalDate();
                LocalDate end = resident.isActive() ? new LocalDate()
                        : SYSCalendar.bom(minmax.getEnd()).toLocalDate();

                int maxYears = Years.yearsBetween(start.toDateTimeAtStartOfDay(), end.toDateTimeAtStartOfDay())
                        .getYears();

                int i = 0;
                for (int year = end.getYear(); year >= start.getYear(); year--) {
                    OPDE.debug((System.currentTimeMillis() - time) + " ms");
                    i++;
                    OPDE.getDisplayManager().setProgressBarMessage(
                            new DisplayMessage(SYSTools.xx("misc.msg.wait"), i, maxYears));
                    createCP4Year(year, start, end);
                }

                OPDE.debug((System.currentTimeMillis() - time) + " ms1");
            }

            return null;
        }

        @Override
        protected void done() {
            OPDE.debug((System.currentTimeMillis() - time) + " ms2");
            expandTheLast2Weeks();

            OPDE.debug((System.currentTimeMillis() - time) + " ms3");
            buildPanel();
            OPDE.debug((System.currentTimeMillis() - time) + " ms4");
            initPhase = false;
            OPDE.getDisplayManager().setProgressBarMessage(null);
            OPDE.getMainframe().setBlocked(false);
            if (lockmessageAfterwards)
                OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
            if (max != null) {
                OPDE.getDisplayManager().addSubMessage(new DisplayMessage(
                        SYSTools.xx("misc.msg.lastEntry") + ": " + DateFormat.getDateInstance().format(max),
                        5));
            } else {
                OPDE.getDisplayManager()
                        .addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.noentryyet"), 5));
            }
        }
    };
    worker.execute();
}

From source file:op.tools.SYSCalendar.java

License:Open Source License

public static DateTime eod(LocalDate date) {
    return eod(date.toDateTimeAtStartOfDay());
}

From source file:op.tools.SYSCalendar.java

License:Open Source License

public static LocalDate min(LocalDate a, LocalDate b) {
    return new LocalDate(
            Math.min(a.toDateTimeAtStartOfDay().getMillis(), b.toDateTimeAtStartOfDay().getMillis()));
}

From source file:op.tools.SYSCalendar.java

License:Open Source License

public static LocalDate max(LocalDate a, LocalDate b) {
    return new LocalDate(
            Math.max(a.toDateTimeAtStartOfDay().getMillis(), b.toDateTimeAtStartOfDay().getMillis()));
}

From source file:org.apache.fineract.portfolio.calendar.domain.Calendar.java

License:Apache License

public Calendar(final String title, final String description, final String location, final LocalDate startDate,
        final LocalDate endDate, final Integer duration, final Integer typeId, final boolean repeating,
        final String recurrence, final Integer remindById, final Integer firstReminder,
        final Integer secondReminder) {

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(CALENDAR_RESOURCE_NAME);

    final CalendarType calendarType = CalendarType.fromInt(typeId);
    if (calendarType.isCollection() && !repeating) {
        baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.REPEATING.getValue())
                .failWithCodeNoParameterAddedToErrorCode("must.repeat.for.collection.calendar");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }//from www. j a va2s .  c om
    }

    this.title = StringUtils.defaultIfEmpty(title, null);
    this.description = StringUtils.defaultIfEmpty(description, null);
    this.location = StringUtils.defaultIfEmpty(location, null);

    if (null != startDate) {
        this.startDate = startDate.toDateTimeAtStartOfDay().toDate();
    } else {
        this.startDate = null;
    }

    if (null != endDate) {
        this.endDate = endDate.toDateTimeAtStartOfDay().toDate();
    } else {
        this.endDate = null;
    }

    this.duration = duration;
    this.typeId = typeId;
    this.repeating = repeating;
    this.recurrence = StringUtils.defaultIfEmpty(recurrence, null);
    this.remindById = remindById;
    this.firstReminder = firstReminder;
    this.secondReminder = secondReminder;
}

From source file:org.apache.fineract.portfolio.client.domain.Client.java

License:Apache License

private Client(final AppUser currentUser, final ClientStatus status, final Office office,
        final Group clientParentGroup, final String accountNo, final String firstname, final String middlename,
        final String lastname, final String fullname, final LocalDate activationDate,
        final LocalDate officeJoiningDate, final String externalId, final String mobileNo, final Staff staff,
        final LocalDate submittedOnDate, final SavingsProduct savingsProduct,
        final SavingsAccount savingsAccount, final LocalDate dateOfBirth, final CodeValue gender,
        final CodeValue clientType, final CodeValue clientClassification, final Integer legalForm) {

    if (StringUtils.isBlank(accountNo)) {
        this.accountNumber = new RandomPasswordGenerator(19).generate();
        this.accountNumberRequiresAutoGeneration = true;
    } else {/*from   w  w w  .  j  av a 2  s.  c  o  m*/
        this.accountNumber = accountNo;
    }

    this.submittedOnDate = submittedOnDate.toDate();
    this.submittedBy = currentUser;

    this.status = status.getValue();
    this.office = office;
    if (StringUtils.isNotBlank(externalId)) {
        this.externalId = externalId.trim();
    } else {
        this.externalId = null;
    }

    if (StringUtils.isNotBlank(mobileNo)) {
        this.mobileNo = mobileNo.trim();
    } else {
        this.mobileNo = null;
    }

    if (activationDate != null) {
        this.activationDate = activationDate.toDateTimeAtStartOfDay().toDate();
        this.activatedBy = currentUser;
    }
    if (officeJoiningDate != null) {
        this.officeJoiningDate = officeJoiningDate.toDateTimeAtStartOfDay().toDate();
    }
    if (StringUtils.isNotBlank(firstname)) {
        this.firstname = firstname.trim();
    } else {
        this.firstname = null;
    }

    if (StringUtils.isNotBlank(middlename)) {
        this.middlename = middlename.trim();
    } else {
        this.middlename = null;
    }

    if (StringUtils.isNotBlank(lastname)) {
        this.lastname = lastname.trim();
    } else {
        this.lastname = null;
    }

    if (StringUtils.isNotBlank(fullname)) {
        this.fullname = fullname.trim();
    } else {
        this.fullname = null;
    }

    if (clientParentGroup != null) {
        this.groups = new HashSet<>();
        this.groups.add(clientParentGroup);
    }

    this.staff = staff;
    this.savingsProduct = savingsProduct;
    this.savingsAccount = savingsAccount;

    if (gender != null) {
        this.gender = gender;
    }
    if (dateOfBirth != null) {
        this.dateOfBirth = dateOfBirth.toDateTimeAtStartOfDay().toDate();
    }
    this.clientType = clientType;
    this.clientClassification = clientClassification;
    this.setLegalForm(legalForm);

    deriveDisplayName();
    validate();
}