List of usage examples for org.joda.time LocalDate getDayOfMonth
public int getDayOfMonth()
From source file:eu.europa.ec.grow.espd.xml.common.importing.UblRequestResponseImporter.java
License:EUPL
protected final Date readIssueDate(IssueDateType issueDateType, IssueTimeType issueTimeType) { if (issueDateType == null || issueDateType.getValue() == null) { return null; }/* w ww.j a v a 2s . com*/ LocalDate localDate = issueDateType.getValue(); if (issueTimeType != null && issueTimeType.getValue() != null) { LocalTime localTime = issueTimeType.getValue(); return new LocalDateTime(localDate.getYear(), localDate.getMonthOfYear(), localDate.getDayOfMonth(), localTime.getHourOfDay(), localTime.getMinuteOfHour(), localTime.getSecondOfMinute()).toDate(); } return new LocalDateTime(localDate.getYear(), localDate.getMonthOfYear(), localDate.getDayOfMonth(), 0, 0, 0).toDate(); }
From source file:eu.trentorise.game.sample.DemoGameFactory.java
License:Apache License
private String generateCronExp() { // sample 0 2 0 4 JUN ? * LocalDate now = LocalDate.now(); return String.format("0 0 0 %s %s ? %s", now.getDayOfMonth() - 1, now.getMonthOfYear(), now.getYear()); }
From source file:fr.esecure.banking.PDFTransactionRapport.java
public String generateReport(List<Transaction> listInput, String outputFilename) throws Exception { remplirListTransactionRow(listInput); if (outputFilename == null) { outputFilename = defaultPath;/*from www . j a v a2 s .com*/ } LocalDate localDate = new LocalDate(); String rapportDate = localDate.getDayOfMonth() + "_" + localDate.getMonthOfYear() + "_" + localDate.getYear(); outputFilename = outputFilename + "/rapport_" + rapportDate + ".pdf"; try { generateAndSaveReport(outputFilename); listInput = null; } catch (Exception ex) { LOG.log(Level.SEVERE, "Une exception s'est produite pendant la generation du rapport PDF : " + ex.getMessage()); throw ex; } return outputFilename; }
From source file:gg.db.datamodel.Period.java
License:Open Source License
/** * Is the specified period valid?/*from www .ja va2 s.c o m*/ * @param startDate Start date of the period * @param endDate End date of the period * @param periodType Type of the period * @return <B>true</B> if the period is valid (or if startDate=endDate=periodType=null), <B>false</B> otherwise<BR/> * To be valid, a period has to be a "full" period: * <UL> * <LI> For each type of period: Start date > End date</LI> * <LI> For DAY period: number of days between Start date and End date = 0<BR/> * Example: <I>From 12/30/2005 to 12/30/2005</I></LI> * <LI> For WEEK period: number of days between Start date and End date = 6<BR/> * The period has to start on MONDAY<BR/> * The period has to end on SUNDAY<BR/> * Example: <I>From 12/01/2005 to 12/18/2005</I></LI> * <LI> For MONTH period: number of month between Start date and End date = 0<BR/> * The period has to start on the first day of the month (05/01/2006)<BR/> * The period has to end on the last day of the month (05/31/2006)<BR/> * Number of months between Start date - 1 day and End date = 1<BR/> * Number of months between Start date and End date + 1 day = 1<BR/> * Example: <I>From 03/01/2005 to 03/31/2005</I></LI> * <LI> For YEAR period: number of years between Start date and End date = 0<BR/> * The period has to start on the first day of the first month (01/01/2006)<BR/> * The period has to end in December<BR/> * The period has to end on the last day of the last month (12/31/2006)<BR/> * Number of years between Start date - 1 day and End date = 1<BR/> * Number of years between Start date and End date + 1 day = 1<BR/> * Example: <I>From 01/01/2006 to 12/31/2006</I></LI> * </UL> */ private boolean isPeriodValid(LocalDate startDate, LocalDate endDate, PeriodType periodType) { boolean periodValid = true; // Is the period valid // Check if Start date < End date if (startDate != null && endDate != null && startDate.compareTo(endDate) > 0) { periodValid = false; } // Check if the period is a "full" period if (periodValid && startDate != null && endDate != null && periodType != null) { switch (periodType) { case DAY: // i.e. a DAY period: from 05/12/2006 to 05/12/2006 if ((getNumberOfDays(startDate.minusDays(1), endDate) != 1) || // 12-11 = 1 (Nb of days = 1) (getNumberOfDays(startDate, endDate) != 0) || // // 12-12 = 0 (Nb of days = 0) (getNumberOfDays(startDate, endDate.plusDays(1)) != 1)) { // 13-12 = 1 (Nb of days = 1) periodValid = false; } break; case WEEK: // i.e. a WEEK period: from 05/12/2006 to 05/18/2006 if ((startDate.toDateTimeAtStartOfDay().getDayOfWeek() != DateTimeConstants.MONDAY) || // the week has to begin on MONDAY (getNumberOfWeeks(startDate.minusDays(1), endDate) != 1) || // 18-11 = 7 (Nb of weeks = 1) (getNumberOfWeeks(startDate, endDate) != 0) || // 18-12 = 6 (Nb of weeks = 0) (getNumberOfWeeks(startDate, endDate.plusDays(1)) != 1)) { // 19-12 = 7 (Nb of weeks = 1) periodValid = false; } break; case MONTH: // i.e. a MONTH period: from 05/01/2006 to 05/30/2006 if ((startDate.getDayOfMonth() != 1) || // the first day of the period has to be the first day of the month (getNumberOfMonths(startDate.minusDays(1), endDate) != 1) || // 5-4 = 1 (Nb of months = 1) (getNumberOfMonths(startDate, endDate) != 0) || // 5-5 = 0 (Nb of months = 0) (getNumberOfMonths(startDate, endDate.plusDays(1)) != 1)) { // 6-5 = 1 (Nb of months = 1) periodValid = false; } break; case YEAR: // i.e. a YEAR period: from 01/01/2006 to 12/31/2006 if ((startDate.getMonthOfYear() != 1 || startDate.getDayOfMonth() != 1) || // the first day of the period has to be the first day of the first month (endDate.getMonthOfYear() != 12) || // the month of the end date of the period has to be December (getNumberOfYears(startDate.minusDays(1), endDate) != 1) || // 2006-2005 = 1 (Nb of years = 1) (getNumberOfYears(startDate, endDate) != 0) || // 2006-2006 = 0 (Nb of years = 0) (getNumberOfYears(startDate, endDate.plusDays(1)) != 1)) { // 2007-2006 = 1 (Nb of years = 1) periodValid = false; } break; case FREE: // There is no constraint on the number of units for FREE type of period break; default: // Should never happen throw new AssertionError("The PeriodType is unknown"); } } return periodValid; }
From source file:it.webappcommon.lib.DateUtils.java
License:Open Source License
public static DateTime mergeDateTime2(Date date, Date time) { // setup objects // LocalDate localDate = new LocalDate(date.getYear(), date.getMonth(), // date.getDate()); // LocalTime localTime = new LocalTime(time.getHours(), // time.getMinutes(), time.getSeconds()); // LocalDate localDate = new LocalDate(date.getTime()); // LocalTime localTime = new LocalTime(time.getHours(), // time.getMinutes(), time.getSeconds()); // DateTime dt = localDate.toDateTime(localTime); // DateTime dt = new DateTime(date.getYear(), date.getMonth(), // date.getDate(), time.getHours(), time.getMinutes(), // time.getSeconds()); // DateTime dt1 = new DateTime(date.getTime()); // DateTime dt2 = new DateTime(time.getTime()); // DateTime dt = new DateTime(dt1.getYear(), dt1.getMonthOfYear(), // dt1.getDayOfMonth(), dt2.getHourOfDay(), dt2.getMinuteOfHour(), // dt2.getSecondOfMinute()); LocalDate localDate = new LocalDate(date.getTime()); int year = localDate.getYear(); // date.getYear(); int month = localDate.getMonthOfYear(); // date.getMonth(); int day = localDate.getDayOfMonth(); // date.getDate(); int h = time.getHours(); int m = time.getMinutes(); int s = time.getSeconds(); logger.debug(String.format("%s-%s-%s %s:%s:%s", year, month, day, h, m, s)); DateTime dt = new DateTime(year, month, day, h, m, s, DateTimeZone.UTC); return dt;/*from w ww. j a va 2 s . c o m*/ }
From source file:julian.lylly.model.Util.java
public static String daysToDate(LocalDate date) {//TODO: weak int y = date.getYear(); int m = date.getMonthOfYear(); int d = date.getDayOfMonth(); return y + "-" + longTo2DigitString(m) + "-" + longTo2DigitString(d); }
From source file:module.siadap.domain.util.SiadapMiscUtilClass.java
License:Open Source License
/** * /*from w ww. j a v a 2 s . c om*/ * @param date * the {@link LocalDate} that will be converted to represent the * date at the beginning of the day * @return an {@link ReadableInstant} with the same day/month/year but the * last instant of it, that is the last hour, last minute, last * second etc... */ public static ReadableInstant convertDateToEndOfDay(LocalDate date) { ReadableInstant newLocalDate = null; if (date != null) { return new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), 23, 59, 59, 59); } return newLocalDate; }
From source file:module.workingCapital.presentationTier.action.WorkingCapitalAction.java
License:Open Source License
private ActionForward exportInfoToExcel(Set<WorkingCapitalProcess> processes, WorkingCapitalContext context, HttpServletResponse response) throws Exception { final Integer year = context.getWorkingCapitalYear().getYear(); SheetData<WorkingCapitalProcess> sheetData = new SheetData<WorkingCapitalProcess>(processes) { @Override//from w w w . ja v a2s . c o m protected void makeLine(WorkingCapitalProcess workingCapitalProcess) { if (workingCapitalProcess == null) { return; } final WorkingCapital workingCapital = workingCapitalProcess.getWorkingCapital(); final WorkingCapitalInitialization initialization = workingCapital .getWorkingCapitalInitialization(); final AccountingUnit accountingUnit = workingCapital.getAccountingUnit(); addCell(getLocalizedMessate("label.module.workingCapital.year"), year); addCell(getLocalizedMessate("label.module.workingCapital"), workingCapitalProcess.getWorkingCapital().getUnit().getPresentationName()); addCell(getLocalizedMessate("WorkingCapitalProcessState"), workingCapitalProcess.getPresentableAcquisitionProcessState().getLocalizedName()); addCell(getLocalizedMessate("label.module.workingCapital.unit.responsible"), getUnitResponsibles(workingCapital)); addCell(getLocalizedMessate("label.module.workingCapital.initialization.accountingUnit"), accountingUnit == null ? "" : accountingUnit.getName()); addCell(getLocalizedMessate("label.module.workingCapital.requestingDate"), initialization.getRequestCreation().toString("yyyy-MM-dd HH:mm:ss")); addCell(getLocalizedMessate("label.module.workingCapital.requester"), initialization.getRequestor().getName()); final Person movementResponsible = workingCapital.getMovementResponsible(); addCell(getLocalizedMessate("label.module.workingCapital.movementResponsible"), movementResponsible == null ? "" : movementResponsible.getName()); addCell(getLocalizedMessate("label.module.workingCapital.fiscalId"), initialization.getFiscalId()); addCell(getLocalizedMessate("label.module.workingCapital.internationalBankAccountNumber"), initialization.getInternationalBankAccountNumber()); addCell(getLocalizedMessate("label.module.workingCapital.fundAllocationId"), initialization.getFundAllocationId()); final Money requestedAnualValue = initialization.getRequestedAnualValue(); addCell(getLocalizedMessate("label.module.workingCapital.requestedAnualValue.requested"), requestedAnualValue); addCell(getLocalizedMessate("label.module.workingCapital.requestedMonthlyValue.requested"), requestedAnualValue.divideAndRound(new BigDecimal(6))); final Money authorizedAnualValue = initialization.getAuthorizedAnualValue(); addCell(getLocalizedMessate("label.module.workingCapital.authorizedAnualValue"), authorizedAnualValue == null ? "" : authorizedAnualValue); final Money maxAuthorizedAnualValue = initialization.getMaxAuthorizedAnualValue(); addCell(getLocalizedMessate("label.module.workingCapital.maxAuthorizedAnualValue"), maxAuthorizedAnualValue == null ? "" : maxAuthorizedAnualValue); final DateTime lastSubmission = initialization.getLastSubmission(); addCell(getLocalizedMessate("label.module.workingCapital.initialization.lastSubmission"), lastSubmission == null ? "" : lastSubmission.toString("yyyy-MM-dd")); final DateTime refundRequested = initialization.getRefundRequested(); addCell(getLocalizedMessate("label.module.workingCapital.initialization.refundRequested"), refundRequested == null ? "" : refundRequested.toString("yyyy-MM-dd")); final WorkingCapitalTransaction lastTransaction = workingCapital.getLastTransaction(); if (lastTransaction == null) { addCell(getLocalizedMessate("label.module.workingCapital.transaction.accumulatedValue"), Money.ZERO); addCell(getLocalizedMessate("label.module.workingCapital.transaction.balance"), Money.ZERO); addCell(getLocalizedMessate("label.module.workingCapital.transaction.debt"), Money.ZERO); } else { addCell(getLocalizedMessate("label.module.workingCapital.transaction.accumulatedValue"), lastTransaction.getAccumulatedValue()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.balance"), lastTransaction.getBalance()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.debt"), lastTransaction.getDebt()); } for (final AcquisitionClassification classification : WorkingCapitalSystem.getInstance() .getAcquisitionClassificationsSet()) { final String description = classification.getDescription(); final String pocCode = classification.getPocCode(); final String key = pocCode + " - " + description; final Money value = calculateValueForClassification(workingCapital, classification); addCell(key, value); } } private Money calculateValueForClassification(final WorkingCapital workingCapital, final AcquisitionClassification classification) { Money result = Money.ZERO; for (final WorkingCapitalTransaction transaction : workingCapital .getWorkingCapitalTransactionsSet()) { if (transaction.isAcquisition()) { final WorkingCapitalAcquisitionTransaction acquisitionTransaction = (WorkingCapitalAcquisitionTransaction) transaction; final WorkingCapitalAcquisition acquisition = acquisitionTransaction .getWorkingCapitalAcquisition(); final AcquisitionClassification acquisitionClassification = acquisition .getAcquisitionClassification(); if (acquisitionClassification == classification) { result = result.add(acquisition.getValueAllocatedToSupplier()); } } } return result; } private String getUnitResponsibles(final WorkingCapital workingCapital) { final StringBuilder builder = new StringBuilder(); final SortedMap<Person, Set<Authorization>> authorizations = workingCapital .getSortedAuthorizations(); if (!authorizations.isEmpty()) { for (final Entry<Person, Set<Authorization>> entry : authorizations.entrySet()) { if (builder.length() > 0) { builder.append("; "); } builder.append(entry.getKey().getName()); } } return builder.toString(); } }; final LocalDate currentLocalDate = new LocalDate(); final SpreadsheetBuilder builder = new SpreadsheetBuilder(); builder.addConverter(Money.class, new CellConverter() { @Override public Object convert(final Object source) { final Money money = (Money) source; return money == null ? null : money.getRoundedValue().doubleValue(); } }); builder.addSheet(getLocalizedMessate("label.module.workingCapital") + " " + year + " - " + currentLocalDate.toString(), sheetData); final List<WorkingCapitalTransaction> transactions = new ArrayList<WorkingCapitalTransaction>(); for (final WorkingCapitalProcess process : processes) { final WorkingCapital workingCapital = process.getWorkingCapital(); transactions.addAll(workingCapital.getSortedWorkingCapitalTransactions()); } final SheetData<WorkingCapitalTransaction> transactionsSheet = new SheetData<WorkingCapitalTransaction>( transactions) { @Override protected void makeLine(WorkingCapitalTransaction transaction) { final WorkingCapital workingCapital = transaction.getWorkingCapital(); final WorkingCapitalProcess workingCapitalProcess = workingCapital.getWorkingCapitalProcess(); addCell(getLocalizedMessate("label.module.workingCapital.year"), year); addCell(getLocalizedMessate("label.module.workingCapital"), workingCapitalProcess.getWorkingCapital().getUnit().getPresentationName()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.number"), transaction.getNumber()); addCell(getLocalizedMessate("WorkingCapitalProcessState.CANCELED"), transaction.isCanceledOrRejected() ? getLocalizedMessate("label.yes") : getLocalizedMessate("label.no")); addCell(getLocalizedMessate("label.module.workingCapital.transaction.description") + " " + getLocalizedMessate("label.module.workingCapital.transaction.number"), transaction.getDescription()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.approval"), approvalLabel(transaction)); addCell(getLocalizedMessate("label.module.workingCapital.transaction.verification"), verificationLabel(transaction)); addCell(getLocalizedMessate("label.module.workingCapital.transaction.value"), transaction.getValue()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.accumulatedValue"), transaction.getAccumulatedValue()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.balance"), transaction.getBalance()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.debt"), transaction.getDebt()); if (transaction.isAcquisition()) { final WorkingCapitalAcquisitionTransaction acquisitionTx = (WorkingCapitalAcquisitionTransaction) transaction; final WorkingCapitalAcquisition acquisition = acquisitionTx.getWorkingCapitalAcquisition(); final AcquisitionClassification acquisitionClassification = acquisition .getAcquisitionClassification(); final String economicClassification = acquisitionClassification.getEconomicClassification(); final String pocCode = acquisitionClassification.getPocCode(); addCell(getLocalizedMessate( "label.module.workingCapital.configuration.acquisition.classifications.economicClassification"), economicClassification); addCell(getLocalizedMessate( "label.module.workingCapital.configuration.acquisition.classifications.pocCode"), pocCode); addCell(getLocalizedMessate( "label.module.workingCapital.configuration.acquisition.classifications.description"), acquisition.getDescription()); } } private Object verificationLabel(final WorkingCapitalTransaction transaction) { if (transaction.isAcquisition()) { final WorkingCapitalAcquisitionTransaction acquisition = (WorkingCapitalAcquisitionTransaction) transaction; if (acquisition.getWorkingCapitalAcquisition().getVerified() != null) { return getLocalizedMessate("label.verified"); } if (acquisition.getWorkingCapitalAcquisition().getNotVerified() != null) { return getLocalizedMessate("label.notVerified"); } } return "-"; } private String approvalLabel(final WorkingCapitalTransaction transaction) { if (transaction.isAcquisition()) { final WorkingCapitalAcquisitionTransaction acquisition = (WorkingCapitalAcquisitionTransaction) transaction; if (acquisition.getWorkingCapitalAcquisition().getApproved() != null) { return getLocalizedMessate("label.approved"); } if (acquisition.getWorkingCapitalAcquisition().getRejectedApproval() != null) { return getLocalizedMessate("label.rejected"); } } return "-"; } }; builder.addSheet(getLocalizedMessate("label.module.workingCapital.transactions"), transactionsSheet); return streamSpreadsheet(response, "FundosManeio_" + year + "-" + currentLocalDate.getDayOfMonth() + "-" + currentLocalDate.getMonthOfYear() + "-" + currentLocalDate.getYear(), builder); }
From source file:name.martingeisse.wicket.panel.simple.DateTimeTextFieldPanel.java
License:Open Source License
@Override protected void convertInput() { // get all required objects. Note: This method is invoked *before* the sub-text-fields // have stored their model values in this object, so we must get them manually. final Class<?> modelType = getType(); final LocalDate date = getDateTextField().getConvertedInput(); final LocalTime time = getTimeTextField().getConvertedInput(); // convert the input if (modelType == DateTime.class) { final DateTime localizedDateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), localizedChronology); setConvertedInputUnsafe(localizedDateTime.withChronology(originalChronology)); } else if (modelType == LocalDateTime.class) { setConvertedInputUnsafe(new LocalDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), localizedChronology));//from w w w. jav a2s . c om } else { throw new IllegalStateException("unsupported model type for DateTimeTextFieldPanel: " + modelType); } }
From source file:net.karlmartens.ui.widget.CalendarCombo.java
License:Apache License
public void setText(String text) { checkWidget();//from w w w . j a v a 2 s . co m if (text == null) error(ERROR_NULL_ARGUMENT); if (text.equals(_text.getText())) return; _text.setText(text); int[] selection; try { final LocalDate ld = _dateFormat.parseLocalDate(text); selection = new int[] { ld.getYear(), ld.getMonthOfYear(), ld.getDayOfMonth() }; } catch (IllegalArgumentException e) { selection = NO_SELECTION; } setSelection(selection[0], selection[1], selection[2]); }