Example usage for org.joda.time LocalDate plusDays

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

Introduction

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

Prototype

public LocalDate plusDays(int days) 

Source Link

Document

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

Usage

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

License:Apache License

private void initializeForEmployeeIfNeeded(String emplId) {
    // All employees have a leave balance and sick balance setup
    if (emplLeaveBalances.get(emplId) == null) {
        List<JobCodeTime> leaveBalances = new ArrayList<JobCodeTime>();
        leaveBalances.add(new JobCodeTime(SICK, 215 * 60 + 4)); // 215 hours, 4 min
        leaveBalances.add(new JobCodeTime(VACATION, 64 * 60 + 10)); //64:10
        emplLeaveBalances.put(emplId, leaveBalances);
    }//from   w w  w  .j av a 2s  .  c  o  m

    // Add work entries for the employee.
    if (emplWorkEntries.get(emplId) == null) {
        LocalDate startDate = calculatePayperiodStartDate(new LocalDate());
        LocalDate tomorrow = new LocalDate().plusDays(1);
        List<TimePeriodEntry> items = new ArrayList<TimePeriodEntry>();
        // Create entries for 1 pay period back through current
        for (int i = -DAYS_IN_PAY_PERIOD; i < DAYS_IN_PAY_PERIOD; i++) {
            LocalDate date = startDate.plusDays(i);
            // For previous pay period, worked 7 hours a day. For current pay period, hours is based on
            // day of week + 15 minutes, up through today.  // Skip Sat and Sun since they by default don't display.
            int timeWorked = i < 0 ? 7 * 60 : date.getDayOfWeek() * 60 + 15;
            if (date.getDayOfWeek() < 6 && date.isBefore(tomorrow)) {
                items.add(new TimePeriodEntry(date, WORKED, timeWorked));
            }
        }
        emplWorkEntries.put(emplId, items);
    }

    if (emplLeaveEntries.get(emplId) == null) {
        emplLeaveEntries.put(emplId, new ArrayList<TimePeriodEntry>());
    }
}

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

License:Apache License

@Override
public PayPeriodDailyLeaveTimeSummary getLeaveHoursReported(String emplId, LocalDate dateInPayPeriod) {
    initializeForEmployeeIfNeeded(emplId);

    LocalDate startDate = calculatePayperiodStartDate(dateInPayPeriod);

    PayPeriodDailyLeaveTimeSummary summary = new PayPeriodDailyLeaveTimeSummary();
    summary.setPayPeriodStart(startDate);
    summary.setPayPeriodEnd(startDate.plusDays(DAYS_IN_PAY_PERIOD - 1));
    summary.setJobDescriptions(jobDescriptions);

    // If more than 1 pay period back or forward, leave cannot be entered.
    int dayDelta = Days.daysBetween(new LocalDate(), startDate).getDays();
    summary.setDisplayOnlyJobCodes(//ww w  . j av a 2  s . c  o m
            dayDelta <= DAYS_IN_PAY_PERIOD * -2 || dayDelta > DAYS_IN_PAY_PERIOD ? allUneditableJobs
                    : uneditableJobs);
    summary.setTimePeriodEntries(getTimeEntries(emplId, startDate, summary.getPayPeriodEnd()));

    return summary;
}

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);/*www . ja v a 2s  . co m*/
        }
    }
    return validEntries;
}

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

License:Apache License

public boolean hasOccurrencesAt(final LocalDate date) throws ParseException {
    if (this.rrule != null) {
        LocalDate end = date.plusDays(1);
        LocalDateIterator it = LocalDateIteratorFactory.createLocalDateIterator(rrule,
                new LocalDate(this.startDate), false);
        it.advanceTo(date);/*w w  w.jav a  2  s  . c o m*/
        return it.hasNext() && it.next().isBefore(end);
    } else if (this.endDate != null) {
        LocalDate start = new LocalDate(this.startDate);
        LocalDate end = new LocalDate(this.endDate);
        return !date.isBefore(start) && !date.isAfter(end);
    } else {
        return new LocalDate(this.startDate).isEqual(date);
    }
}

From source file:org.efaps.esjp.ui.dashboard.StatusPanel_Base.java

License:Apache License

@Override
public CharSequence getHtmlSnipplet() throws EFapsException {
    CharSequence ret;/*from  www .  j  a  va  2s .  c o m*/
    if (isCached()) {
        ret = getFromCache();
    } else {
        final Map<LocalDate, Set<Long>> values = new TreeMap<>();

        final DateTime startDate = new DateTime().minusDays(getDays());

        final QueryBuilder queryBldr = new QueryBuilder(CICommon.HistoryLogin);
        queryBldr.addWhereAttrGreaterValue(CICommon.HistoryLogin.Created, startDate);
        queryBldr.addOrderByAttributeAsc(CICommon.HistoryLogin.Created);
        final MultiPrintQuery multi = queryBldr.getPrint();
        multi.addAttribute(CICommon.HistoryLogin.Created, CICommon.HistoryLogin.GeneralInstanceLink);
        multi.executeWithoutAccessCheck();
        while (multi.next()) {
            final DateTime created = multi.getAttribute(CICommon.HistoryLogin.Created);
            final LocalDate date = created.toLocalDate();
            final Long gId = multi.getAttribute(CICommon.HistoryLogin.GeneralInstanceLink);
            Set<Long> set;
            if (values.containsKey(date)) {
                set = values.get(date);
            } else {
                set = new HashSet<>();
                values.put(date, set);
            }
            set.add(gId);
        }

        final LineChart chart = new LineChart().setLineLayout(LineLayout.LINES).setWidth(getWidth())
                .setHeight(getHeight());
        final String title = getTitle();
        if (title != null && !title.isEmpty()) {
            chart.setTitle(getTitle());
        }
        final Axis xAxis = new Axis().setName("x").addConfig("rotation", "-45");
        chart.addAxis(xAxis);

        final Serie<Data> serie = new Serie<Data>();
        serie.setName("Usuarios").setMouseIndicator(new MouseIndicator());
        ;
        chart.addSerie(serie);

        final List<Map<String, Object>> labels = new ArrayList<>();
        int idx = 1;
        LocalDate current = startDate.toLocalDate();
        while (current.isBefore(new DateTime().plusDays(1).toLocalDate())) {
            int yVal;
            if (values.containsKey(current)) {
                yVal = values.get(current).size();
            } else {
                yVal = 0;
            }
            final Data data = new Data();
            serie.addData(data);
            data.setYValue(yVal).setXValue(idx);
            final Map<String, Object> labelMap = new HashMap<>();
            labelMap.put("value", idx);
            labelMap.put("text", Util
                    .wrap4String(current.toString(getDateFormat(), Context.getThreadContext().getLocale())));
            labels.add(labelMap);
            idx++;
            current = current.plusDays(1);
        }
        xAxis.setLabels(Util.mapCollectionToObjectArray(labels));
        chart.setOrientation(Orientation.HORIZONTAL_LEGEND_CHART);
        ret = chart.getHtmlSnipplet();
        cache(ret);
    }
    return ret;
}

From source file:org.egov.tl.service.DemandNoticeService.java

License:Open Source License

private String getPenaltyRateDetails(List<PenaltyRates> penaltyRates, Installment currentInstallment,
        LicenseAppType licenseAppType) {
    StringBuilder penaltylist = new StringBuilder();

    Long fromRange = penaltyRatesService.getMinFromRange(licenseAppType);
    Long toRange = penaltyRatesService.getMaxToRange(licenseAppType);

    for (PenaltyRates penaltyRate : penaltyRates) {
        LocalDate currentInstallmentStartDate = LocalDate.fromDateFields(currentInstallment.getFromDate())
                .plusDays(1);/*ww w .  j  av  a 2s  . c om*/
        LocalDate currentStartDate = LocalDate.fromDateFields(currentInstallment.getFromDate());
        if (penaltyRate.getRate() <= ZERO.doubleValue()) {
            penaltylist.append("Before ")
                    .append(getDefaultFormattedDate(
                            currentInstallmentStartDate.plusDays(penaltyRate.getToRange().intValue()).toDate()))
                    .append(" without penalty\n");
        }
        if (penaltyRate.getRate() > ZERO.doubleValue()) {
            if (penaltyRate.getToRange() >= toRange) {
                penaltylist.append("    After ")
                        .append(getDefaultFormattedDate(
                                currentStartDate.plusDays(penaltyRate.getFromRange().intValue()).toDate()))
                        .append(WITH).append(penaltyRate.getRate().intValue()).append("% penalty");
            } else if (penaltyRate.getFromRange() <= fromRange) {
                penaltylist.append("Before ")
                        .append(getDefaultFormattedDate(currentInstallmentStartDate
                                .plusDays(penaltyRate.getToRange().intValue()).toDate()))
                        .append(WITH).append(penaltyRate.getRate().intValue()).append("% penalty\n");
            } else {
                penaltylist.append("    From ")
                        .append(getDefaultFormattedDate(currentInstallmentStartDate
                                .plusDays(penaltyRate.getFromRange().intValue()).toDate()))
                        .append(" to ")
                        .append(getDefaultFormattedDate(
                                currentStartDate.plusDays(penaltyRate.getToRange().intValue()).toDate()))
                        .append(WITH).append(penaltyRate.getRate().intValue()).append("% penalty\n");
            }
        }
    }
    return penaltylist.toString();
}

From source file:org.egov.tl.service.ValidityService.java

License:Open Source License

private void applyLicenseExpiryBasedOnCustomValidity(TradeLicense license, Validity validity) {
    LocalDate nextExpiryDate = new LocalDate(license.isNewApplication() ? license.getCommencementDate()
            : license.getCurrentDemand().getEgInstallmentMaster().getFromDate());
    if (validity.getYear() != null && validity.getYear() > 0)
        nextExpiryDate = nextExpiryDate.plusYears(validity.getYear());
    if (validity.getMonth() != null && validity.getMonth() > 0)
        nextExpiryDate = nextExpiryDate.plusMonths(validity.getMonth());
    if (validity.getWeek() != null && validity.getWeek() > 0)
        nextExpiryDate = nextExpiryDate.plusWeeks(validity.getWeek());
    if (validity.getDay() != null && validity.getDay() > 0)
        nextExpiryDate = nextExpiryDate.plusDays(validity.getDay());
    license.setDateOfExpiry(nextExpiryDate.toDate());
}

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

License:Apache License

private LocalDate adjustDateIn(final LocalDate date, final IntervalEnding ending) {
    if (date == null) {
        return null;
    }/*from   ww  w. j  a  v  a 2  s  .co  m*/
    return ending == IntervalEnding.INCLUDING_END_DATE ? date.plusDays(1) : date;
}

From source file:org.estatio.dscm.dom.playlist.Playlist.java

License:Apache License

@MultiLine(numberOfLines = 10)
@MemberOrder(sequence = "9")
public String getNextOccurences() {
    StringBuilder builder = new StringBuilder();
    LocalDate fromDate = clockService.now().compareTo(this.getStartDate()) >= 0 ? clockService.now()
            : this.getStartDate();
    for (LocalDateTime occurence : nextOccurences(fromDate.plusDays(7))) {
        builder.append(occurence.toString("yyyy-MM-dd HH:mm"));
        builder.append("\n");
    }//  www  . j  a v a  2 s  .co m
    return builder.toString();
}

From source file:org.estatio.fixturescripts.CreateRetroInvoices.java

License:Apache License

@Programmatic
public ExecutionContext createLease(final Lease lease, final LocalDate startDueDate,
        final LocalDate nextDueDate, final ExecutionContext fixtureResults) {
    for (LocalDate dueDate : findDueDatesForLease(startDueDate, nextDueDate, lease)) {
        InvoiceCalculationParameters parameters = new InvoiceCalculationParameters(lease,
                InvoiceCalculationSelection.ALL.selectedTypes(), InvoiceRunType.NORMAL_RUN, dueDate,
                startDueDate, dueDate.plusDays(1));
        createAndApprove(parameters, fixtureResults);
    }/*from  w w  w. j ava2s  . c o  m*/
    return fixtureResults;
}