Example usage for org.joda.time LocalDate toString

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

Introduction

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

Prototype

public String toString(String pattern) 

Source Link

Document

Output the date using the specified format pattern.

Usage

From source file:org.supercsv.cellprocessor.joda.FmtLocalDate.java

License:Apache License

/**
 * {@inheritDoc}//from   ww  w .j  av  a 2 s .  c o  m
 */
@Override
protected String format(final LocalDate jodaType, final DateTimeFormatter formatter) {
    return jodaType.toString(formatter);
}

From source file:org.vaadin.addons.javaee.fields.converter.StringToLocalDateConverter.java

License:Apache License

@Override
public String convertToPresentation(LocalDate value, Class<? extends String> targetType, Locale locale)
        throws Converter.ConversionException {
    if (value == null) {
        return null;
    }/*from w w w .  java 2s.c o  m*/
    return value.toString(DateTimeFormat.shortDate().withLocale(locale));
}

From source file:org.vaadin.testbenchsauce.BaseTestBenchTestCase.java

protected WebElement setLocalDateInDateField(String caption, LocalDate localDate) {
    String localDateAsString = localDate == null ? "" : localDate.toString("MM/dd/yyyy");
    return setLocalDateInDateFieldAsString(caption, localDateAsString);
}

From source file:pt.ist.expenditureTrackingSystem.presentationTier.actions.acquisitions.SearchPaymentProcessesAction.java

License:Open Source License

private void fillXlsInfo(Set<PaymentProcess> processes, StyledExcelSpreadsheet spreadsheet,
        OutputStream outputStream) throws IOException {
    spreadsheet.newRow();//w  ww .ja  va2  s.  c o m
    spreadsheet.addCell(processes.size() + " " + getAcquisitionResourceMessage("label.processes"));
    spreadsheet.newRow();

    setHeaders(spreadsheet);
    TreeSet<PaymentProcess> sortedProcesses = new TreeSet<PaymentProcess>(
            PaymentProcess.COMPARATOR_BY_YEAR_AND_ACQUISITION_PROCESS_NUMBER);
    sortedProcesses.addAll(processes);

    for (PaymentProcess process : sortedProcesses) {
        spreadsheet.newRow();

        spreadsheet.addCell(process.getAcquisitionProcessId());
        spreadsheet.addCell(process.getTypeShortDescription());
        AcquisitionItemClassification classification = process.getGoodsOrServiceClassification();
        spreadsheet.addCell(classification == null ? " " : classification.getLocalizedName());
        spreadsheet.addCell(process.getSuppliersDescription());
        spreadsheet.addCell(process.getRequest().getRequestItemsSet().size());
        spreadsheet.addCell(process.getProcessStateDescription());
        DateTime time = new DateTime();
        if (process.getPaymentProcessYear().getYear() != time.getYear()) {
            time = new DateTime(process.getPaymentProcessYear().getYear().intValue(), 12, 31, 23, 59, 59, 0);
        }
        spreadsheet.addCell(describeState(process, time));
        DateTime date = process.getDateFromLastActivity();
        spreadsheet.addCell((date == null) ? ""
                : date.getDayOfMonth() + "-" + date.getMonthOfYear() + "-" + date.getYear() + " "
                        + date.getHourOfDay() + ":" + date.getMinuteOfHour());
        spreadsheet.addCell(process.getRequest().getRequester().getFirstAndLastName());
        spreadsheet.addCell(process.getRequest().getRequestingUnit().getName());

        final MissionProcess missionProcess = process.getMissionProcess();
        spreadsheet.addCell(missionProcess == null ? "" : missionProcess.getProcessNumber());
        final Boolean skipSupplierFundAllocation = process.getSkipSupplierFundAllocation();
        spreadsheet.addCell(Boolean
                .toString(skipSupplierFundAllocation != null && skipSupplierFundAllocation.booleanValue()));
        spreadsheet.addCell(toString(process.getCPVReferences()));

        final StringBuilder builderAccountingUnit = new StringBuilder();
        final StringBuilder builderUnits = new StringBuilder();
        for (final Financer financer : process.getFinancersWithFundsAllocated()) {
            final AccountingUnit accountingUnit = financer.getAccountingUnit();
            if (accountingUnit != null) {
                if (builderAccountingUnit.length() > 0) {
                    builderAccountingUnit.append(", ");
                }
                builderAccountingUnit.append(accountingUnit.getName());
            }
            final Unit unit = financer.getUnit();
            if (unit != null) {
                if (builderUnits.length() > 0) {
                    builderUnits.append(", ");
                }
                builderUnits.append(unit.getUnit().getAcronym());
            }
        }
        spreadsheet.addCell(builderAccountingUnit.length() == 0 ? " " : builderAccountingUnit.toString());
        spreadsheet.addCell(builderUnits.length() == 0 ? " " : builderUnits.toString());

        final Money totalValue = process.getTotalValue();
        spreadsheet.addCell((totalValue == null ? Money.ZERO : totalValue).toFormatString());

        final StringBuilder fundAllocationNumbers = new StringBuilder();
        final StringBuilder commitmentNumbers = new StringBuilder();
        final StringBuilder efectiveFundAllocationNumbers = new StringBuilder();
        final StringBuilder requestOrderNumber = new StringBuilder();
        LocalDate invoiceDate = null;
        Money invoiceValue = Money.ZERO;

        if (process instanceof SimplifiedProcedureProcess) {
            SimplifiedProcedureProcess simplifiedProcedureProcess = (SimplifiedProcedureProcess) process;
            final AcquisitionRequest acquisitionRequest = simplifiedProcedureProcess.getAcquisitionRequest();
            for (PayingUnitTotalBean payingUnitTotal : acquisitionRequest.getTotalAmountsForEachPayingUnit()) {
                if ((simplifiedProcedureProcess.getFundAllocationPresent())
                        && (payingUnitTotal.getFinancer().isFundAllocationPresent())) {
                    if (fundAllocationNumbers.length() > 0) {
                        fundAllocationNumbers.append(", ");
                    }
                    fundAllocationNumbers.append(payingUnitTotal.getFinancer().getFundAllocationIds().trim());
                }

                if (commitmentNumbers.length() > 0) {
                    fundAllocationNumbers.append(", ");
                }
                String commitmentNumber = payingUnitTotal.getFinancer().getCommitmentNumber();
                if (commitmentNumber != null) {
                    commitmentNumber = commitmentNumber.trim();
                    if (commitmentNumber.length() > 0) {
                        commitmentNumbers.append(commitmentNumber);
                    }
                }

                if ((simplifiedProcedureProcess.getEffectiveFundAllocationPresent())
                        && (payingUnitTotal.getFinancer().isEffectiveFundAllocationPresent())) {
                    if (efectiveFundAllocationNumbers.length() > 0) {
                        efectiveFundAllocationNumbers.append(", ");
                    }
                    efectiveFundAllocationNumbers
                            .append(payingUnitTotal.getFinancer().getEffectiveFundAllocationIds().trim());
                }
            }

            boolean hasFullInvoice = false;
            for (final Invoice invoice : acquisitionRequest.getInvoices()) {
                //          final AcquisitionInvoice acquisitionInvoice = (AcquisitionInvoice) invoice;
                final LocalDate localDate = invoice.getInvoiceDate();
                if (invoiceDate == null || invoiceDate.isBefore(localDate)) {
                    invoiceDate = localDate;
                }

                hasFullInvoice = true;
                //          if (!hasFullInvoice) {
                //         final String confirmationReport = acquisitionInvoice.getConfirmationReport();
                //         if (confirmationReport == null) {
                //             hasFullInvoice = true;
                //         } else {
                //             for (int i = 0; i < confirmationReport.length(); ) {
                //            final int ulli = confirmationReport.indexOf("<ul><li>", i);
                //            final int q = confirmationReport.indexOf(" - Quantidade:", ulli);
                //            final int ulliClose = confirmationReport.indexOf("</li></ul>", q);
                //            final String itemDescription = confirmationReport.substring(i + "<ul><li>".length(), q);
                //            final int quantity = Integer.parseInt(confirmationReport.substring(q + " - Quantidade:".length(), ulliClose));
                //
                //            invoiceValue = invoiceValue.add(calculate(acquisitionRequest, itemDescription, quantity));
                //             }
                //         }
                //          }
            }

            if (hasFullInvoice) {
                invoiceValue = totalValue;
            }

            final PurchaseOrderDocument purchaseOrderDocument = simplifiedProcedureProcess
                    .getPurchaseOrderDocument();
            if (purchaseOrderDocument != null) {
                requestOrderNumber.append(purchaseOrderDocument.getRequestId());
            }
        }

        spreadsheet.addCell(fundAllocationNumbers.length() == 0 ? " " : fundAllocationNumbers.toString());
        spreadsheet.addCell(commitmentNumbers.length() == 0 ? " " : commitmentNumbers.toString());
        spreadsheet.addCell(requestOrderNumber.length() == 0 ? " " : requestOrderNumber.toString());
        spreadsheet.addCell(
                efectiveFundAllocationNumbers.length() == 0 ? " " : efectiveFundAllocationNumbers.toString());

        spreadsheet.addCell(invoiceDate == null ? " " : invoiceDate.toString("yyyy-MM-dd"));
        spreadsheet.addCell(invoiceValue.toFormatString());

        DateTime creationDate = process.getCreationDate();
        spreadsheet.addCell(creationDate == null ? " " : creationDate.toString("yyyy-MM-dd"));
        SortedSet<WorkflowLog> executionLogsSet = new TreeSet<WorkflowLog>(
                WorkflowLog.COMPARATOR_BY_WHEN_REVERSED);
        executionLogsSet.addAll(process.getExecutionLogsSet());
        DateTime approvalDate = getApprovalDate(process, executionLogsSet);
        spreadsheet.addCell(approvalDate == null ? " " : approvalDate.toString("yyyy-MM-dd"));
        DateTime authorizationDate = getAuthorizationDate(process, executionLogsSet);
        spreadsheet.addCell(authorizationDate == null ? " " : authorizationDate.toString("yyyy-MM-dd"));
    }
}

From source file:pt.ist.expenditureTrackingSystem.presentationTier.actions.statistics.StatisticsAction.java

License:Open Source License

private Spreadsheet createInformationForExpenseReports(final Integer year) {
    final Spreadsheet spreadsheet = new Spreadsheet("ExpenseReport " + year);
    spreadsheet.setHeader("Ano");
    spreadsheet.setHeader("Processo");
    spreadsheet.setHeader("Classificao");
    spreadsheet.setHeader("Caso de excepo");
    spreadsheet.setHeader("Estado");
    spreadsheet.setHeader("CPV");
    spreadsheet.setHeader("Valor sem IVA");
    spreadsheet.setHeader("Valor com IVA");
    spreadsheet.setHeader("Data envio nota de encomenda");
    spreadsheet.setHeader("Data salto envio nota de encomenda");
    spreadsheet.setHeader("Data factura");

    final PaymentProcessYear paymentProcessYear = PaymentProcessYear.getPaymentProcessYearByYear(year);
    for (final PaymentProcess paymentProcess : paymentProcessYear.getPaymentProcessSet()) {
        if (paymentProcess instanceof SimplifiedProcedureProcess) {
            final SimplifiedProcedureProcess simplifiedProcedureProcess = (SimplifiedProcedureProcess) paymentProcess;
            final AcquisitionRequest acquisitionRequest = simplifiedProcedureProcess.getRequest();

            final Row row = spreadsheet.addRow();
            row.setCell(simplifiedProcedureProcess.getYear());
            row.setCell(simplifiedProcedureProcess.getProcessNumber());
            row.setCell(simplifiedProcedureProcess.getProcessClassification().getLocalizedName());

            final boolean isException = simplifiedProcedureProcess.getSkipSupplierFundAllocation()
                    .booleanValue();//from   ww w .  j a v  a  2  s. c  om
            row.setCell(isException ? "Sim" : "No");

            final AcquisitionProcessStateType acquisitionProcessStateType = simplifiedProcedureProcess
                    .getAcquisitionProcessStateType();
            row.setCell(acquisitionProcessStateType.getLocalizedName());

            final Set<CPVReference> cpvReferences = new TreeSet<CPVReference>(
                    CPVReference.COMPARATOR_BY_DESCRIPTION);
            for (final RequestItem requestItem : acquisitionRequest.getRequestItemsSet()) {
                cpvReferences.add(requestItem.getCPVReference());
            }
            final StringBuilder cpvs = new StringBuilder();
            for (final CPVReference cpvReference : cpvReferences) {
                if (cpvs.length() > 1) {
                    cpvs.append(", ");
                }
                cpvs.append(cpvReference.getCode());
            }
            row.setCell(cpvs.length() == 0 ? " " : cpvs.toString());

            final Money currentValue = acquisitionRequest.getCurrentValue();
            row.setCell(currentValue == null ? " " : currentValue.toFormatStringWithoutCurrency());

            final Money currentTotalValue = acquisitionRequest
                    .getCurrentTotalItemValueWithAdditionalCostsAndVat();
            row.setCell(currentTotalValue == null ? " " : currentTotalValue.toFormatStringWithoutCurrency());

            final DateTime sendDate = findSendDate(simplifiedProcedureProcess,
                    SendPurchaseOrderToSupplier.class);
            row.setCell(sendDate == null ? " " : sendDate.toString("yyyy-MM-dd"));

            final DateTime skipDate = findSendDate(simplifiedProcedureProcess, SkipPurchaseOrderDocument.class);
            row.setCell(skipDate == null ? " " : skipDate.toString("yyyy-MM-dd"));

            final StringBuilder invoiceDateStringBuilder = new StringBuilder();
            for (final LocalDate localDate : getInvoiceDates(simplifiedProcedureProcess)) {
                if (invoiceDateStringBuilder.length() > 0) {
                    invoiceDateStringBuilder.append(", ");
                }
                invoiceDateStringBuilder.append(localDate.toString("yyyy-MM-dd"));
            }
            row.setCell(invoiceDateStringBuilder.toString());
        }
    }

    return spreadsheet;
}

From source file:pt.ist.fenixedu.contracts.persistenceTierOracle.view.GiafEmployeeAssiduity.java

License:Open Source License

public static JsonObject readAssiduityOfEmployee(final User user, final LocalDate date,
        final User responsible) {
    final JsonObject result = new JsonObject();
    result.addProperty("username", user.getUsername());
    result.addProperty("name", user.getProfile().getDisplayName());
    result.addProperty("avatarUrl", user.getProfile().getAvatarUrl());

    final JsonArray records = new JsonArray();
    result.add("assiduityRecords", records);

    GiafDbConnector.getInstance().executeQuery(new ResultSetConsumer() {

        @Override//from   w  w  w . j av  a2 s .  com
        public String query() {
            return "SELECT "

                    + "a.ID_PICAGEM, "

                    + "a.ID_EMPREGADO, "

                    + "to_char(a.data,'YYYY-MM-DD'), "

                    + "to_char(a.HORA, 'HH24:MI'), "

                    + "a.OPERACAO, "

                    + "a.TIPO "

                    + "FROM MYGIAF_CASS_PICAGEM a"

                    + (responsible == user ? " " : ", MYGIAF_V_RESP_SUBORDINADO b ")

                    + "WHERE a.ID_EMPREGADO = ? AND (a.DATA = ? OR a.DATA = ?) "

                    + (responsible == user ? ""
                            : "AND a.ID_EMPREGADO = b.UTILIZADOR_NUM_EMP AND b.chefe_equipa_id = ? ")

                    + "ORDER BY a.id_picagem";
        }

        @Override
        public void prepare(final PreparedStatement statement) throws SQLException {
            final String giafNumber = convertIntoGiafNumber(getEmployeeNumber(user));
            final LocalDate ld = (date == null ? new LocalDate() : date);
            statement.setString(1, giafNumber);
            statement.setString(2, ld.toString("yyyy-MM-dd"));
            statement.setString(3, ld.minusDays(1).toString("yyyy-MM-dd"));
            if (responsible != user) {
                statement.setString(4, responsible.getUsername().toUpperCase());
            }
        }

        @Override
        public void accept(final ResultSet resultSet) throws SQLException {
            final JsonObject view = new JsonObject();
            view.addProperty("moment", resultSet.getString(3) + " " + resultSet.getString(4));
            view.addProperty("operation", resultSet.getString(5));
            records.add(view);
        }

    });

    return result;
}

From source file:rabbit.data.internal.xml.DataStore.java

License:Apache License

@Override
public File getDataFile(LocalDate date, IPath location) {
    return location.append(id + "-" + date.toString("yyyy-MM")).addFileExtension("xml").toFile();
}

From source file:ru.codemine.ccms.router.api.ApiRouter.java

License:Open Source License

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/api/passability", method = RequestMethod.GET)
public @ResponseBody List<PassabilityJson> getPassabilityJson(@RequestParam(required = false) Integer shopid,
        @RequestParam(required = false) String shopname, @RequestParam("startDate") String startDateStr,
        @RequestParam("endDate") String endDateStr, @RequestParam(required = false) String detail) {
    if (shopid == null && shopname == null)
        throw new InvalidParametersException();
    if (shopid != null && shopname != null)
        throw new InvalidParametersException();

    try {/*from ww  w.  ja v  a  2s.  c  om*/
        Shop shop = shopid == null ? shopService.getByName(shopname) : shopService.getById(shopid);

        DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");
        List<PassabilityJson> resulList = new ArrayList<>();

        LocalDate startDate = formatter.parseLocalDate(startDateStr);
        LocalDate endDate = formatter.parseLocalDate(endDateStr);

        if (detail == null || "none".equals(detail)) {
            PassabilityJson record = new PassabilityJson();

            record.setStartDate(startDate.toString("dd.MM.YYYY"));
            record.setEndDate(endDate.toString("dd.MM.YYYY"));
            if (shop.isCountersEnabled()) {
                record.setIn(counterService.getInValueByPeriod(shop, startDate, endDate));
                record.setOut(counterService.getOutValueByPeriod(shop, startDate, endDate));
            } else {
                record.setIn(salesService.getPassabilityValueByPeriod(shop, startDate, endDate));
                record.setOut(record.getIn());
            }
            resulList.add(record);
        } else if ("day".equals(detail)) {
            // ? ,  ? 
            List<SalesMeta> smList = salesService.getByPeriod(shop, startDate.withDayOfMonth(1),
                    endDate.dayOfMonth().withMaximumValue());
            List<Sales> allSales = salesService.getAllSalesFromMetaList(smList, startDate, endDate);

            for (Sales s : allSales) {
                PassabilityJson record = new PassabilityJson();

                record.setStartDate(s.getDate().toString("dd.MM.YYYY"));
                record.setEndDate(s.getDate().toString("dd.MM.YYYY"));
                record.setIn(shop.isCountersEnabled()
                        ? counterService.getInValueByPeriod(shop, s.getDate(), s.getDate())
                        : s.getPassability());
                record.setOut(shop.isCountersEnabled()
                        ? counterService.getOutValueByPeriod(shop, s.getDate(), s.getDate())
                        : s.getPassability());

                resulList.add(record);
            }
        } else if ("month".equals(detail)) {
            startDate = startDate.withDayOfMonth(1);
            endDate = endDate.dayOfMonth().withMaximumValue();

            List<SalesMeta> smList = salesService.getByPeriod(shop, startDate, endDate);
            for (SalesMeta sm : smList) {
                PassabilityJson record = new PassabilityJson();

                record.setStartDate(sm.getStartDate().toString("dd.MM.YYYY"));
                record.setEndDate(sm.getEndDate().toString("dd.MM.YYYY"));
                record.setIn(shop.isCountersEnabled()
                        ? counterService.getInValueByPeriod(shop, sm.getStartDate(), sm.getEndDate())
                        : sm.getPassabilityTotal());
                record.setOut(shop.isCountersEnabled()
                        ? counterService.getOutValueByPeriod(shop, sm.getStartDate(), sm.getEndDate())
                        : sm.getPassabilityTotal());

                resulList.add(record);
            }
        }

        return resulList;
    } catch (Exception e) {
        log.warn(" ?  API (?) - "
                + e.getLocalizedMessage());
        return new ArrayList<>();
    }
}

From source file:ru.codemine.ccms.router.ExpencesRouter.java

License:Open Source License

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/reports/graph/expences")
public String getExpencesGraph(@RequestParam(required = false) Integer shopid,
        @RequestParam(required = false) String dateStartStr, @RequestParam(required = false) String dateEndStr,
        ModelMap model) {/* w  ww . j  a va 2  s. co m*/
    model.addAllAttributes(utils.prepareModel());

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");
    LocalDate dateStart = dateStartStr == null ? LocalDate.now().withMonthOfYear(1).withDayOfMonth(1)
            : formatter.parseLocalDate(dateStartStr).withDayOfMonth(1);
    LocalDate dateEnd = dateEndStr == null ? LocalDate.now().dayOfMonth().withMaximumValue()
            : formatter.parseLocalDate(dateEndStr).dayOfMonth().withMaximumValue();

    if (dateEnd.isBefore(dateStart))
        dateEnd = dateStart;

    model.addAttribute("dateStartStr", dateStart.toString("dd.MM.YYYY"));
    model.addAttribute("dateEndStr", dateEnd.toString("dd.MM.YYYY"));

    List<Shop> shopList = shopService.getAllOpen();
    List<String> graphDataSalesTotal = new ArrayList<>();
    List<String> graphDataExpencesTotal = new ArrayList<>();

    Shop shop = shopid == null ? shopList.get(0) : shopService.getById(shopid);

    model.addAttribute("shop", shop);
    model.addAttribute("shopList", shopList);

    List<SalesMeta> smList = salesService.getByPeriod(shop, dateStart, dateEnd);

    for (SalesMeta sm : smList) {

        graphDataSalesTotal.add(sm.getGraphDataSalesTotal());
        graphDataExpencesTotal.add(sm.getGraphDataExpencesTotal());
    }

    model.addAttribute("graphDataSalesTotal", graphDataSalesTotal);
    model.addAttribute("graphDataExpencesTotal", graphDataExpencesTotal);

    return "reports/expences-graph";
}

From source file:ru.codemine.ccms.router.SalesRouter.java

License:Open Source License

@Secured("ROLE_USER")
@RequestMapping(value = "/salesUpd", method = RequestMethod.POST)
public @ResponseBody String updateSales(@RequestParam(required = false) Integer smid,
        @RequestParam(required = false) Integer shopid, @RequestBody List<SalesForm> salesForms,
        ModelMap model) {//from w w w  . ja  v a 2s. co m

    if (smid == null && shopid == null)
        throw new ResourceNotFoundException();

    String resultStr;
    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");

    if (smid != null) //  ?? 
    {
        SalesMeta salesMeta = salesService.getById(smid);

        for (SalesForm sf : salesForms) {
            Sales sales = salesMeta.getByDate(formatter.parseLocalDate(sf.getDate()));

            sales.setPassability(sf.getPassability());
            sales.setChequeCount(sf.getChequeCount());
            sales.setValue(sf.getValue());
            sales.setCashback(sf.getCashback());
        }

        salesService.update(salesMeta);

        resultStr = "{\"result\": \"success\"}";
    } else // ? 
    {
        Shop shop = shopService.getById(shopid);
        Set<Sales> newSalesSet = new TreeSet<>();

        LocalDate startDate = formatter.parseLocalDate(salesForms.get(0).getDate());
        LocalDate endDate = formatter.parseLocalDate(salesForms.get(salesForms.size() - 1).getDate());

        for (SalesForm sf : salesForms) {
            Sales sales = new Sales(shop, formatter.parseLocalDate(sf.getDate()));

            sales.setPassability(sf.getPassability());
            sales.setChequeCount(sf.getChequeCount());
            sales.setValue(sf.getValue());
            sales.setCashback(sf.getCashback());

            newSalesSet.add(sales);
        }

        SalesMeta newSalesMeta = new SalesMeta(shop);
        newSalesMeta.setSales(newSalesSet);
        newSalesMeta.setStartDate(startDate);
        newSalesMeta.setEndDate(endDate);
        newSalesMeta.setDescription(" : " + shop.getName() + " ("
                + startDate.toString("MMMM YYYY") + ")");

        salesService.create(newSalesMeta);

        resultStr = "{\"result\": \"success\"}";
    }

    return resultStr;
}