List of usage examples for org.joda.time LocalDate isBefore
public boolean isBefore(ReadablePartial partial)
From source file:net.sourceforge.fenixedu.domain.TutorshipSummary.java
License:Open Source License
public boolean isActive() { if (getSemester().getTutorshipSummaryPeriod() == null) { return false; }/*w w w. j ava 2s .c om*/ LocalDate curDate = new LocalDate(); LocalDate beginDate = getSemester().getTutorshipSummaryPeriod().getBeginDate(); LocalDate endDate = getSemester().getTutorshipSummaryPeriod().getEndDate(); return !(curDate.isBefore(beginDate) || curDate.isAfter(endDate)); }
From source file:nl.welteninstituut.tel.la.importers.rescuetime.RescueTimeTask.java
License:Open Source License
@Override public void run() { OauthServiceAccount account = getAccount(AccountJDO.RESCUETIMECLIENT, accountId); if (account != null) { if (start == null) { if (account.getLastSynced() == null) { String startDate = Configuration.get(Configuration.STARTDATE); if (startDate != null) { start = new DateTime(startDate + "T00:00"); } else { log.severe(Configuration.STARTDATE + " is missing from configuration"); }//from w ww . java2s .c o m } else { start = new DateTime(account.getLastSynced()); } } if (start != null) { LocalDate localDate = start.toLocalDate(); try { JSONObject data = getData(account.getAccessToken(), localDate); System.out.println(data); JSONArray rows = data.getJSONArray("rows"); String mbox = null; if (rows.length() > 0) { AccountJDO pa = AccountManager.getAccount(account.getPrimaryAccount()); mbox = pa != null ? pa.getEmail() : null; } Row row = null; for (int i = 0; i < rows.length(); i++) { row = new Row(rows.getJSONArray(i)); if (row.getDate().isEqual(start) || row.getDate().isAfter(start)) { if (isTimeAllowed(row.getDate())) { String xapi = String.format(XAPI_RESCUETIME_FORMAT, row.getDate(), mbox, row.getActivity(), row.getTimeSpent()); StatementManager.addStatement(xapi, "rescuetime"); } } } boolean isNotToday = localDate.isBefore(new LocalDate()); if (isNotToday) { start = localDate.plusDays(1).toDateTimeAtStartOfDay(); } else { if (row != null) { start = row.getDate().plusSeconds(1); } } account.setLastSynced(start.toDate()); OauthServiceAccountManager.updateOauthServiceAccount(account); if (isNotToday) { ImportTask.scheduleTask(new RescueTimeTask(accountId, start)); } } catch (JSONException | IOException e) { e.printStackTrace(); } } } else { log.severe("no RescueTime service account found for " + accountId); } }
From source file:op.tools.SYSCalendar.java
License:Open Source License
public static void handleDateFocusLost(FocusEvent evt, LocalDate min, LocalDate max) { LocalDate dt; if (max == null) { max = new LocalDate(); }/*from w w w. j a v a2 s . co m*/ try { dt = new LocalDate(parseDate(((JTextField) evt.getSource()).getText())); } catch (NumberFormatException ex) { OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.wrongdate"))); dt = new LocalDate(); } if (dt.isAfter(max)) { dt = new LocalDate(); DisplayMessage dm = new DisplayMessage( dt.isAfter(max) ? SYSTools.xx("misc.msg.futuredate") : SYSTools.xx("misc.msg.wrongdate")); OPDE.getDisplayManager().addSubMessage(dm); } if (dt.isBefore(min)) { dt = new LocalDate(); OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.DateTooOld"))); } ((JTextField) evt.getSource()).setText(DateFormat.getDateInstance().format(dt.toDate())); }
From source file:org.alexlg.bankit.controllers.AccountController.java
License:Open Source License
/** * Build categories summary for each month from startDate * to previous nbPrevMonth//www . ja va 2 s. com * @param startDate Start the summary for this month * @param endDate Stop the summary for this month * @return Map with the date of the month and a Map with Category * and amount for this category for this month */ protected Map<Date, Map<Category, BigDecimal>> buildCategories(LocalDate startDate, LocalDate endDate) { Map<Date, Map<Category, BigDecimal>> categories = new LinkedHashMap<Date, Map<Category, BigDecimal>>(); YearMonth curMonth = null; //month we start to retrieve YearMonth endMonth = null; //last month we have to retrieve if (startDate.isBefore(endDate)) { curMonth = new YearMonth(startDate.getYear(), startDate.getMonthOfYear()); endMonth = new YearMonth(endDate.getYear(), endDate.getMonthOfYear()); } else { curMonth = new YearMonth(endDate.getYear(), endDate.getMonthOfYear()); endMonth = new YearMonth(startDate.getYear(), startDate.getMonthOfYear()); } do { Map<Category, BigDecimal> monthSummary = categoryDao.getMonthSummary(curMonth); if (monthSummary.size() > 0) { categories.put(curMonth.toLocalDate(1).toDate(), monthSummary); } curMonth = curMonth.plusMonths(1); } while (curMonth.isBefore(endMonth) || curMonth.isEqual(endMonth)); return categories; }
From source file:org.angnysa.yaba.service.impl.DefaultTransactionService.java
License:Open Source License
@Override public List<Transaction> computeTransactions(TransactionDefinition td, LocalDate start, LocalDate end) { if (start.isAfter(end)) { throw new IllegalArgumentException("start is after end"); }/*from w ww. j a v a2 s .c o m*/ List<Transaction> result = new ArrayList<Transaction>(); if (td.getPeriod() == null) { // non repeating if ((td.getDate().isAfter(start) || td.getDate().isEqual(start)) && (td.getDate().isBefore(end) || td.getDate().isEqual(end))) { Transaction at = new Transaction(); at.setTransactionId(td.getId()); at.setDate(td.getDate()); at.setAmount(td.getAmount()); result.add(at); } } else { // repeating // get first valid date LocalDate current = td.getDate(); while (current.isBefore(start)) { current = current.plus(td.getPeriod()); } // get true last limit if (td.getEnd() != null && td.getEnd().isBefore(end)) { end = td.getEnd(); } // list occurrences while (current.isBefore(end) || current.isEqual(end)) { Transaction at = new Transaction(); at.setTransactionId(td.getId()); at.setDate(current); if (td.getReconciliation(current) == null) { at.setAmount(td.getAmount()); } else { at.setAmount(td.getReconciliation(current)); } result.add(at); current = current.plus(td.getPeriod()); } } Collections.sort(result, new Comparator<Transaction>() { @Override public int compare(Transaction t1, Transaction t2) { return t1.getDate().compareTo(t2.getDate()); } }); return result; }
From source file:org.apache.bigtop.datagenerators.weatherman.internal.Driver.java
License:Apache License
public void run(String[] args) throws Exception { locations = new LocationReader().readData(); parseArgs(args);//from www. j a v a 2 s .c o m WeatherGenerator generator = new WeatherGenerator(startDate, location, seedFactory); LocalDate date = startDate; LocalDate endDate = startDate.plusDays(simulationLength); List<WeatherRecord> trajectory = Lists.newArrayList(); while (date.isBefore(endDate)) { WeatherRecord weather = generator.sample(); trajectory.add(weather); date = weather.getDate(); } writeWeather(location, trajectory); }
From source file:org.apache.fineract.accounting.closure.storeglaccountbalance.data.GLClosureJournalEntryBalanceValidator.java
License:Apache License
/** * Validates the request to generate a closure journal entry account balance report * /*from ww w .j a v a2s . c o m*/ * @param officeId * @param startClosure * @param endClosure */ public void validateGenerateReportRequest(final Long officeId, final GLClosureData startClosure, final GLClosureData endClosure) { final Long endClosureId = (endClosure != null) ? endClosure.getId() : null; final String resourceNameToLowerCase = StringUtils .lowerCase(StoreGLAccountBalanceResource.CLOSURE_ACCOUNT_BALANCE_REPORT_ENTITY_NAME); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder dataValidatorBuilder = new DataValidatorBuilder(dataValidationErrors) .resource(resourceNameToLowerCase); dataValidatorBuilder.reset().parameter(UriQueryParameterHelper.OFFICE_ID_PARAMETER_NAME).value(officeId) .notBlank(); dataValidatorBuilder.reset().parameter(UriQueryParameterHelper.END_CLOSURE_ID_PARAMETER_NAME) .value(endClosureId).notBlank(); if (startClosure != null && startClosure.isDeleted()) { throw new GLClosureNotFoundException(startClosure.getId()); } if (endClosure != null && endClosure.isDeleted()) { throw new GLClosureNotFoundException(endClosureId); } if (startClosure != null && endClosure != null) { final LocalDate startClosureClosingDate = startClosure.getClosingDate(); final LocalDate endClosureClosingDate = endClosure.getClosingDate(); if (endClosureClosingDate.isBefore(startClosureClosingDate)) { dataValidatorBuilder.failWithCodeNoParameterAddedToErrorCode( "error.msg." + resourceNameToLowerCase + ".end.closure.closing.date.cannot.be.before.start.closure.closing.date", "Closing " + "date of end closure must be after closing date of start closure."); } if (startClosure.getId().equals(endClosure.getId())) { dataValidatorBuilder.failWithCodeNoParameterAddedToErrorCode( "error.msg." + resourceNameToLowerCase + ".end.closure.cannot.be.equal.to.start.closure", "End closure cannot be equal " + "to start closure."); } } if (officeId != null && startClosure != null && !startClosure.getOfficeId().equals(officeId)) { dataValidatorBuilder.failWithCodeNoParameterAddedToErrorCode( "error.msg." + resourceNameToLowerCase + ".start.closure.office.id.must.be.equal.to.provided.office.id", "The start closure " + "office id is different from provided office id"); } if (officeId != null && endClosure != null && !endClosure.getOfficeId().equals(officeId)) { dataValidatorBuilder.failWithCodeNoParameterAddedToErrorCode( "error.msg." + resourceNameToLowerCase + ".end.closure.office.id.must.be.equal.to.provided.office.id", "The end closure " + "office id is different from provided office id"); } // throw data validation exception if there are any validation errors this.throwExceptionIfValidationWarningsExist(dataValidationErrors); }
From source file:org.apache.fineract.infrastructure.scheduledemail.service.EmailCampaignWritePlatformCommandHandlerImpl.java
License:Apache License
private void updateTriggerDates(Long campaignId) { final EmailCampaign emailCampaign = this.emailCampaignRepository.findOne(campaignId); if (emailCampaign == null) { throw new EmailCampaignNotFound(campaignId); }/* w w w .j a v a2 s .com*/ LocalDateTime nextTriggerDate = emailCampaign.getNextTriggerDate(); emailCampaign.setLastTriggerDate(nextTriggerDate.toDate()); //calculate new trigger date and insert into next trigger date /** * next run time has to be in the future if not calculate a new future date */ LocalDate nextRuntime = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(), emailCampaign.getNextTriggerDate().toLocalDate(), nextTriggerDate.toLocalDate()); if (nextRuntime.isBefore(DateUtils.getLocalDateOfTenant())) { // means next run time is in the past calculate a new future date nextRuntime = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(), emailCampaign.getNextTriggerDate().toLocalDate(), DateUtils.getLocalDateOfTenant()); } final LocalDateTime getTime = emailCampaign.getRecurrenceStartDateTime(); final String dateString = nextRuntime.toString() + " " + getTime.getHourOfDay() + ":" + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute(); final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); final LocalDateTime newTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat); emailCampaign.setNextTriggerDate(newTriggerDateWithTime.toDate()); this.emailCampaignRepository.saveAndFlush(emailCampaign); }
From source file:org.apache.fineract.infrastructure.sms.service.SmsCampaignWritePlatformCommandHandlerImpl.java
License:Apache License
private void updateTriggerDates(Long campaignId) { final SmsCampaign smsCampaign = this.smsCampaignRepository.findOne(campaignId); if (smsCampaign == null) { throw new SmsCampaignNotFound(campaignId); }//from ww w .j a v a 2 s . c o m LocalDateTime nextTriggerDate = smsCampaign.getNextTriggerDate(); smsCampaign.setLastTriggerDate(nextTriggerDate.toDate()); //calculate new trigger date and insert into next trigger date /** * next run time has to be in the future if not calculate a new future date */ LocalDate nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(), smsCampaign.getNextTriggerDate().toLocalDate(), nextTriggerDate.toLocalDate()); if (nextRuntime.isBefore(DateUtils.getLocalDateOfTenant())) { // means next run time is in the past calculate a new future date nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(), smsCampaign.getNextTriggerDate().toLocalDate(), DateUtils.getLocalDateOfTenant()); } final LocalDateTime getTime = smsCampaign.getRecurrenceStartDateTime(); final String dateString = nextRuntime.toString() + " " + getTime.getHourOfDay() + ":" + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute(); final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); final LocalDateTime newTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat); smsCampaign.setNextTriggerDate(newTriggerDateWithTime.toDate()); this.smsCampaignRepository.saveAndFlush(smsCampaign); }
From source file:org.apache.fineract.organisation.teller.data.CashierTransactionDataValidator.java
License:Apache License
public void validateCashierAllowedDateAndTime(final Cashier cashier, final Teller teller) { Long staffId = cashier.getStaff().getId(); final LocalDate fromDate = new LocalDate(cashier.getStartDate()); final LocalDate endDate = new LocalDate(cashier.getEndDate()); final LocalDate tellerFromDate = teller.getStartLocalDate(); final LocalDate tellerEndDate = teller.getEndLocalDate(); /**//from ww w . ja v a 2s. co m * to validate cashier date range in range of teller date range */ if (fromDate.isBefore(tellerFromDate) || endDate.isBefore(tellerFromDate) || (tellerEndDate != null && fromDate.isAfter(tellerEndDate) || endDate.isAfter(tellerEndDate))) { throw new CashierDateRangeOutOfTellerDateRangeException(); } /** * to validate cashier has not been assigned for same duration */ String sql = "select count(*) from m_cashiers c where c.staff_id = " + staffId + " AND " + "(('" + fromDate + "' BETWEEN c.start_date AND c.end_date OR '" + endDate + "' BETWEEN c.start_date AND c.end_date )" + " OR ( c.start_date BETWEEN '" + fromDate + "' AND '" + endDate + "' OR c.end_date BETWEEN '" + fromDate + "' AND '" + endDate + "'))"; if (!cashier.isFullDay()) { String startTime = cashier.getStartTime(); String endTime = cashier.getEndTime(); sql = sql + " AND ( Time(c.start_time) BETWEEN TIME('" + startTime + "') and TIME('" + endTime + "') or Time(c.end_time) BETWEEN TIME('" + startTime + "') and TIME('" + endTime + "')) "; } int count = this.jdbcTemplate.queryForObject(sql, Integer.class); if (count > 0) { throw new CashierAlreadyAlloacated(); } }