Example usage for org.joda.time LocalDate minusDays

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

Introduction

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

Prototype

public LocalDate minusDays(int days) 

Source Link

Document

Returns a copy of this date minus the specified number of days.

Usage

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.jodatime.DateConverterForJodaLocalDate.java

License:Apache License

@Override
protected LocalDate doConvertToObject(String value, Locale locale) throws ConversionException {
    LocalDate date = convert(value);
    LocalDate adjustedDate = date.minusDays(adjustBy);
    return adjustedDate;
}

From source file:org.apereo.portlet.hr.demo.timereporting.dao.DemoStaffTimeReportingImpl.java

License:Apache License

private LocalDate calculatePayperiodStartDate(LocalDate date) {
    return date.minusDays(5).withDayOfWeek(SATURDAY);
}

From source file:org.apereo.portlet.hr.demo.timereporting.dao.DemoStaffTimeReportingImpl.java

License:Apache License

private List<TimePeriodEntry> entriesInDateRange(LocalDate startDate, LocalDate endDate,
        List<TimePeriodEntry> entries) {
    LocalDate dayPriorToStart = startDate.minusDays(1);
    LocalDate dayAfterEnd = endDate.plusDays(1);
    List<TimePeriodEntry> validEntries = new ArrayList<TimePeriodEntry>();
    for (TimePeriodEntry entry : entries) {
        if (entry.getDate().isAfter(dayPriorToStart) && entry.getDate().isBefore(dayAfterEnd)) {
            validEntries.add(entry);/*ww w .  j a va 2 s .  c  om*/
        }
    }
    return validEntries;
}

From source file:org.codeqinvest.codechanges.FakeCodeChurnCalculator.java

License:Open Source License

@Override
public Collection<DailyCodeChurn> calculateCodeChurn(ScmConnectionSettings connectionSettings, String file,
        LocalDate day, int numberOfDays) throws CodeChurnCalculationException, ScmConnectionEncodingException {
    if (!codeChurnByFileAndDay.containsKey(file) || !codeChurnByFileAndDay.get(file).containsKey(day)) {
        throw new CodeChurnCalculationException();
    }/*from   w  w w .ja v  a 2 s. co  m*/

    Set<DailyCodeChurn> codeChurns = Sets.newHashSet();
    for (int i = 0; i <= numberOfDays; i++) {
        DailyCodeChurn currentCodeChurn = codeChurnByFileAndDay.get(file).get(day.minusDays(i));
        if (currentCodeChurn != null) {
            codeChurns.add(currentCodeChurn);
        }
    }
    return codeChurns;
}

From source file:org.codeqinvest.codechanges.scm.svn.SvnCodeChurnCalculatorService.java

License:Open Source License

/**
 * {@inheritDoc}//from   w  w w  . j  a v  a 2  s  .c  o  m
 */
@Override
public Collection<DailyCodeChurn> calculateCodeChurn(ScmConnectionSettings connectionSettings, String file,
        LocalDate startDay, int numberOfDays)
        throws CodeChurnCalculationException, ScmConnectionEncodingException {

    String currentFilePath = file;
    int currentNumberOfDay;
    long lastRevision = -1;
    Map<LocalDate, DailyCodeChurn> codeChurns = Maps.newHashMap();
    for (int i = 0; i <= numberOfDays; i++) {
        currentNumberOfDay = i;
        final LocalDate day = startDay.minusDays(i);
        try {
            final Collection<SvnFileRevision> revisions = revisionsRetrieverService
                    .retrieveRevisions(connectionSettings, day).getRevisions(currentFilePath);
            List<Double> codeChurnProportions = new ArrayList<Double>(revisions.size());
            for (SvnFileRevision revision : revisions) {

                if (lastRevision != -1 && revision.getRevision() == lastRevision) {
                    lastRevision = -1;
                    continue;
                }

                codeChurnProportions.add(calculateCodeChurnProportion(connectionSettings, revision));

                if (!revision.getOldPath().equalsIgnoreCase(revision.getNewPath())) {
                    // file was moved or renamed => change the currentFilePath for next revision retrieving requests
                    currentFilePath = revision.getFilePartOfOldPath(connectionSettings);

                    // spawn get revisions request afterwards for new file name due it's possible that there are revision for it on the current day
                    if (existRevisionsForFileOnDay(connectionSettings, currentFilePath, day)
                            && i - 1 == currentNumberOfDay - 1) {
                        // to prevent that the day index is incremented more than once when there are more renamed revision on the current day
                        i = currentNumberOfDay - 1;
                        lastRevision = revision.getRevision();
                    }
                }
            }

            if (codeChurns.containsKey(day)) {
                codeChurns.get(day).addCodeChurnProportions(codeChurnProportions);
            } else {
                codeChurns.put(day, new DailyCodeChurn(day, codeChurnProportions));
            }
        } catch (SVNException e) {
            log.error("Error with svn server communication occurred!", e);
            throw new CodeChurnCalculationException(e);
        } catch (UnsupportedEncodingException e) {
            log.error("An error with encoding settings of scm connection occurred! (settings: "
                    + connectionSettings.toString() + ")", e);
            throw new ScmConnectionEncodingException(e);
        }
    }
    return codeChurns.values();
}

From source file:org.devmaster.elasticsearch.index.mapper.Recurring.java

License:Apache License

public LocalDate getNextOccurrence(LocalDate date) throws ParseException {

    final LocalDate start = new LocalDate(this.startDate);

    if (this.rrule != null) {
        LocalDateIterator it = LocalDateIteratorFactory.createLocalDateIterator(rrule, start.minusDays(1),
                false);/*  w  ww.jav a  2 s.c  om*/
        it.advanceTo(date);
        return it.hasNext() ? it.next() : null;
    } else if (this.endDate == null) {
        return !date.isAfter(start) ? start : null;
    } else {
        LocalDate end = new LocalDate(this.endDate);
        return !date.isAfter(end) ? start : null;
    }
}

From source file:org.estatio.dom.asset.registration.FixedAssetRegistration.java

License:Apache License

public FixedAssetRegistration changeDates(
        final @ParameterLayout(named = "Start date") @Parameter(optionality = Optionality.OPTIONAL) LocalDate startDate,
        final @ParameterLayout(named = "End date") @Parameter(optionality = Optionality.OPTIONAL) LocalDate endDate) {
    if (getPrevious() != null) {
        getPrevious().getChangeDates().changeDates(getPrevious().getStartDate(), startDate.minusDays(1));
    }//from w w w  .j  av a 2s. c  o  m

    return getChangeDates().changeDates(startDate, endDate);
}

From source file:org.estatio.dom.valuetypes.AbstractInterval.java

License:Apache License

private LocalDate adjustDateOut(final LocalDate date, final IntervalEnding ending) {
    if (date == null) {
        return null;
    }/*from www . j  a v  a  2  s  . com*/
    return ending == IntervalEnding.INCLUDING_END_DATE ? date.minusDays(1) : date;
}

From source file:org.estatio.services.clock.ClockService.java

License:Apache License

static LocalDate beginningOfMonth(final LocalDate date) {
    final int dayOfMonth = date.getDayOfMonth();
    return date.minusDays(dayOfMonth - 1);
}

From source file:org.fenixedu.academic.ui.struts.action.departmentAdmOffice.SummariesControlAction.java

License:Open Source License

private List<DetailSummaryElement> getExecutionCourseResume(final ExecutionSemester executionSemester,
        Collection<Professorship> professorships) {
    List<DetailSummaryElement> allListElements = new ArrayList<DetailSummaryElement>();
    LocalDate today = new LocalDate();
    LocalDate oneWeekBeforeToday = today.minusDays(8);
    for (Professorship professorship : professorships) {
        BigDecimal lessonsGiven = EMPTY;
        BigDecimal summariesGiven = EMPTY;
        BigDecimal summariesGivenPercentage = EMPTY;
        BigDecimal notTaughtSummaries = EMPTY;
        BigDecimal notTaughtSummariesPercentage = EMPTY;
        if (professorship.belongsToExecutionPeriod(executionSemester)) {
            for (Shift shift : professorship.getExecutionCourse().getAssociatedShifts()) {
                lessonsGiven = lessonsGiven.add(BigDecimal.valueOf(shift.getNumberOfLessonInstances()));

                // Get the number of summaries given
                summariesGiven = getSummariesGiven(professorship, shift, summariesGiven, oneWeekBeforeToday);
                // Get the number of not taught summaries
                notTaughtSummaries = getNotTaughtSummaries(professorship, shift, notTaughtSummaries,
                        oneWeekBeforeToday);
            }/*  ww  w .  j  av  a  2  s  .  c  o  m*/
            summariesGiven = summariesGiven.setScale(1, RoundingMode.HALF_UP);
            notTaughtSummaries = notTaughtSummaries.setScale(1, RoundingMode.HALF_UP);

            if (lessonsGiven.signum() == 1) {
                summariesGivenPercentage = summariesGiven.divide(lessonsGiven, 3, BigDecimal.ROUND_CEILING)
                        .multiply(BigDecimal.valueOf(100));
                notTaughtSummariesPercentage = notTaughtSummaries
                        .divide(lessonsGiven, 3, BigDecimal.ROUND_CEILING).multiply(BigDecimal.valueOf(100));
            }

            Teacher teacher = professorship.getTeacher();
            String categoryName = null;
            if (teacher != null) {
                final Optional<TeacherAuthorization> authorization = teacher
                        .getTeacherAuthorization(executionSemester.getAcademicInterval());

                categoryName = authorization.isPresent()
                        ? authorization.get().getTeacherCategory().getName().getContent()
                        : null;

            }

            String siglas = getSiglas(professorship);

            String teacherEmail = professorship.getPerson().getDefaultEmailAddress() != null
                    ? professorship.getPerson().getDefaultEmailAddress().getPresentationValue()
                    : null;

            DetailSummaryElement listElementDTO = new DetailSummaryElement(professorship.getPerson().getName(),
                    professorship.getExecutionCourse().getNome(),
                    teacher != null ? teacher.getTeacherId() : null, teacherEmail, categoryName, summariesGiven,
                    notTaughtSummaries, siglas, lessonsGiven, summariesGivenPercentage,
                    notTaughtSummariesPercentage);

            allListElements.add(listElementDTO);
        }
    }
    return allListElements;
}