List of usage examples for org.joda.time LocalDate plusDays
public LocalDate plusDays(int days)
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 ww w . j ava 2 s. 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:nz.co.jsrsolutions.tideservice.scraper.provider.EasyTideTideDataProvider.java
License:Open Source License
@Override public List<TidePredictionDay> getTidePredictionDay(Port port) throws TideDataProviderException { HttpGet getRequest;//from www . jav a2 s. c om try { getRequest = new EasyTideHttpGet( mUriBuilder.buildGetPredictionUri(mGetTidePredictionUrlSuffix, port.getExternalId(), 3)); HttpResponse response = mHttpClient.execute(getRequest); Parser parser = getHtmlParser(response); // Parse the timezone information NodeList nodeList = new NodeList(); NodeFilter filter = new AndFilter(new TagNameFilter("SPAN"), new HasAttributeFilter("ID", "PredictionSummary1_lblZoneTimeOffset")); parser.reset(); for (NodeIterator e = parser.elements(); e.hasMoreNodes();) { e.nextNode().collectInto(nodeList, filter); } if (nodeList.size() != 1) { throw new TideDataProviderException("Couldn't retrieve the time zone information"); } String timeZoneString = ((TagNode) nodeList.elementAt(0)).getChildren().elementAt(0).getText(); Matcher timeZoneMatcher = mTimeZoneRegexPattern.matcher(timeZoneString); // attempt the common case first int hoursOffset; int minutesOffset; if (timeZoneMatcher.matches()) { hoursOffset = Integer.parseInt(timeZoneMatcher.group(1)); final String minutesString = timeZoneMatcher.group(3); minutesOffset = (minutesString == null) ? 0 : Integer.parseInt(minutesString); } else if (timeZoneString.compareTo("Port predictions (Standard Local Time) are equal to UTC") == 0) { // is already UTC hoursOffset = 0; minutesOffset = 0; } else { throw new TideDataProviderException( "Couldn't parse the time zone information from: ".concat(timeZoneString)); } final DateTimeZone timeZone = DateTimeZone.forOffsetHoursMinutes(hoursOffset, minutesOffset); // Parse the current day (today) information nodeList = new NodeList(); filter = new AndFilter(new TagNameFilter("SPAN"), new HasAttributeFilter("ID", "PredictionSummary1_lblPredictionStart")); parser.reset(); for (NodeIterator e = parser.elements(); e.hasMoreNodes();) { e.nextNode().collectInto(nodeList, filter); } if (nodeList.size() != 1) { throw new TideDataProviderException("Couldn't retrieve today's date"); } String todayString = ((TagNode) nodeList.elementAt(0)).getChildren().elementAt(0).getText(); Matcher todayMatcher = mTodayRegexPattern.matcher(todayString); LocalDate localDate; if (todayMatcher.matches()) { localDate = LocalDate.parse(todayMatcher.group(1).concat(todayMatcher.group(2)), mLocalDateFormatter); } else { throw new TideDataProviderException( "Couldn't parse the time zone information from: ".concat(timeZoneString)); } // Get each of the HW,LW tables nodeList = new NodeList(); filter = new AndFilter(new TagNameFilter("TABLE"), new OrFilter(new HasAttributeFilter("CLASS", "HWLWTable"), new OrFilter(new HasAttributeFilter("CLASS", "HWLWTable first"), new OrFilter(new HasAttributeFilter("CLASS", "HWLWTable last"), new HasAttributeFilter("CLASS", "HWLWTable first last"))))); parser.reset(); for (NodeIterator e = parser.elements(); e.hasMoreNodes();) { e.nextNode().collectInto(nodeList, filter); } int numDays = nodeList.size(); final List<TidePredictionDay> tidePredictionDays = new ArrayList<TidePredictionDay>(numDays); for (int nDay = 0; nDay < numDays; ++nDay) { final TagNode tagNode = (TagNode) nodeList.elementAt(nDay); final TidePredictionDay tidePredictionDay = new TidePredictionDay(); tidePredictionDay.setLocalDate(localDate); // LWHW NodeList lwHwNodeList = new NodeList(); filter = new AndFilter(new TagNameFilter("TH"), new HasAttributeFilter("CLASS", "HWLWTableHWLWCellPrintFriendly")); tagNode.collectInto(lwHwNodeList, filter); // Times and Heights NodeList timeHeightNodeList = new NodeList(); filter = new AndFilter(new TagNameFilter("TD"), new HasAttributeFilter("CLASS", "HWLWTableCellPrintFriendly")); tagNode.collectInto(timeHeightNodeList, filter); int numTides = lwHwNodeList.size(); for (int nTide = 0; nTide < numTides; ++nTide) { final TidePrediction tidePrediction = new TidePrediction(); tidePrediction.setTidePredictionType(TidePredictionType .fromString(lwHwNodeList.elementAt(nTide).getChildren().elementAt(0).getText())); // Set the time LocalTime localTime; String localTimeString = timeHeightNodeList.elementAt(nTide).getChildren().elementAt(0) .getText(); if (localTimeString != null && !localTimeString.isEmpty() && localTimeString.compareTo(" ") != 0) { if (localTimeString.contains("*")) { localTimeString = localTimeString.replace("*", ""); tidePrediction.setIsEstimate(true); } localTime = mLocalTimeFormatter.parseLocalTime(localTimeString); } else { // we can't really make out that this is a sensible prediction // so don't include this continue; } final DateTime dateTime = localDate.toDateTime(localTime, timeZone); tidePrediction.setUtcTime(dateTime); // Set the height where possible final String heightString = timeHeightNodeList.elementAt(nTide + numTides).getChildren() .elementAt(0).getText(); if (heightString != null && !heightString.isEmpty()) { Matcher tideHeightMatcher = mTideHeightRegexPattern.matcher(heightString); if (tideHeightMatcher.matches()) { tidePrediction.setHeight(Float.parseFloat(tideHeightMatcher.group(1))); } } // Tie both together tidePrediction.setTidePredictionDay(tidePredictionDay); tidePredictionDay.getTidePredictions().add(tidePrediction); } tidePredictionDays.add(tidePredictionDay); localDate = localDate.plusDays(1); } return tidePredictionDays; } catch (URISyntaxException e) { throw new TideDataProviderException(e); } catch (IOException e) { throw new TideDataProviderException(e); } catch (ParseException e) { throw new TideDataProviderException(e); } catch (ParserException e) { throw new TideDataProviderException(e); } }
From source file:orc.lib.orchard.forms.DateTimeRangesField.java
License:Open Source License
private void renderHour(final PrintWriter out, final int hour) throws IOException { out.write("<tr>"); out.write("<th>"); out.write(formatHour(hour));// w w w . jav a 2s .com out.write("</th>"); LocalDate current = span.getStart(); final LocalDate end = span.getEnd(); final LocalTime time = new LocalTime(hour, 0); while (current.compareTo(end) < 0) { out.write("<td>"); renderTime(out, current.toDateTime(time)); out.write("</td>"); current = current.plusDays(1); } out.write("</tr>"); }
From source file:orc.lib.orchard.forms.DateTimeRangesField.java
License:Open Source License
private void renderTableHeader(final PrintWriter out) throws IOException { out.write("<tr><th> </th>"); LocalDate current = span.getStart(); final LocalDate end = span.getEnd(); while (current.compareTo(end) < 0) { out.write("<th>"); out.write(formatDateHeader(current)); out.write("</th>"); current = current.plusDays(1); }/* ww w. ja va 2 s .c o m*/ out.write("</tr>"); }
From source file:org.activiti.dmn.engine.impl.mvel.extension.DateUtil.java
License:Apache License
public static Date addDate(Date startDate, Integer years, Integer months, Integer days) { LocalDate currentDate = new LocalDate(startDate); currentDate = currentDate.plusYears(years); currentDate = currentDate.plusMonths(months); currentDate = currentDate.plusDays(days); return currentDate.toDate(); }
From source file:org.alexlg.bankit.controllers.AccountController.java
License:Open Source License
/** * Build a set of MonthOps for all future ops : "manual" or costs (beyond 2 days of current) * @param day Current day/*from ww w . j a v a 2 s. c om*/ * @param futurePlannedOps List of manual future operations * @param costs List of costs * @param balance Start balance * @param nbMonth Number of month to build in addition to the current month. * @return A set of MonthOps for each month planned */ protected Set<MonthOps> buildFutureOps(LocalDate day, List<Operation> futurePlannedOps, List<Cost> costs, BigDecimal balance, int nbMonth) { Set<MonthOps> futureOps = new TreeSet<MonthOps>(); //going through all months for (int i = 0; i < nbMonth + 1; i++) { LocalDate monthDate = day.monthOfYear().addToCopy(i); int lastDayOfMonth = monthDate.dayOfMonth().getMaximumValue(); MonthOps monthOps = new MonthOps(monthDate, balance); futureOps.add(monthOps); //adding "manual" operation of the current month if (futurePlannedOps.size() > 0) { //loop an add all operation of the month for (Operation op : futurePlannedOps) { if (new LocalDate(op.getOperationDate()).getMonthOfYear() == monthDate.getMonthOfYear()) { op.setAuto(false); monthOps.addOp(op); } } } //adding costs of the current month LocalDate costStartDay = day.plusDays(2); for (Cost cost : costs) { int costDay = cost.getDay(); //if the operation is planned after the last day of month //set it to the last day if (costDay > lastDayOfMonth) costDay = lastDayOfMonth; LocalDate opDate = new LocalDate(monthDate.getYear(), monthDate.getMonthOfYear(), costDay); //checking if we add the cost (the date is after current+2) if (opDate.isAfter(costStartDay)) { Operation op = new Operation(); //setting a fake id for comparison (as we put the operation in the set) op.setOperationId(cost.getCostId() + i); op.setOperationDate(opDate.toDate()); op.setPlanned(cost.getAmount()); op.setLabel(cost.getLabel()); op.setCategory(cost.getCategory()); op.setAuto(true); monthOps.addOp(op); } } //saving current balance for next monthOp balance = monthOps.getBalance(); } return futureOps; }
From source file:org.apache.fineract.portfolio.calendar.service.CalendarUtils.java
License:Apache License
public static boolean isValidRecurringDate(final Recur recur, final LocalDate seedDate, final LocalDate date) { final Collection<LocalDate> recurDate = getRecurringDates(recur, seedDate, date, date.plusDays(1), 1); return (recurDate == null || recurDate.isEmpty()) ? false : true; }
From source file:org.apache.fineract.portfolio.calendar.service.CalendarUtils.java
License:Apache License
public static LocalDate getFirstRepaymentMeetingDate(final Calendar calendar, final LocalDate disbursementDate, final Integer loanRepaymentInterval, final String frequency) { final Recur recur = CalendarUtils.getICalRecur(calendar.getRecurrence()); if (recur == null) { return null; }/*w w w. j ava 2 s .c om*/ LocalDate startDate = disbursementDate; final LocalDate seedDate = calendar.getStartDateLocalDate(); if (isValidRedurringDate(calendar.getRecurrence(), seedDate, startDate)) { startDate = startDate.plusDays(1); } // Recurring dates should follow loanRepaymentInterval. // e.g. // for weekly meeting interval is 1 // where as for loan product with fortnightly frequency interval is 2 // to generate currect set of meeting dates reset interval same as loan // repayment interval. recur.setInterval(loanRepaymentInterval); // Recurring dates should follow loanRepayment frequency. // e.g. // daily meeting frequency should support all loan products with any // frequency type. // to generate currect set of meeting dates reset frequency same as loan // repayment frequency. if (recur.getFrequency().equals(Recur.DAILY)) { recur.setFrequency(frequency); } final LocalDate firstRepaymentDate = getNextRecurringDate(recur, seedDate, startDate); return firstRepaymentDate; }
From source file:org.apache.fineract.portfolio.calendar.service.CalendarUtils.java
License:Apache License
public static LocalDate getNextRepaymentMeetingDate(final String recurringRule, final LocalDate seedDate, final LocalDate repaymentDate, final Integer loanRepaymentInterval, final String frequency, final WorkingDays workingDays) { final Recur recur = CalendarUtils.getICalRecur(recurringRule); if (recur == null) { return null; }/* w w w .j a v a2s . c o m*/ LocalDate tmpDate = repaymentDate; if (isValidRecurringDate(recur, seedDate, repaymentDate)) { tmpDate = repaymentDate.plusDays(1); } /* * Recurring dates should follow loanRepaymentInterval. * * e.g. The weekly meeting will have interval of 1, if the loan product * with fortnightly frequency will have interval of 2, to generate right * set of meeting dates reset interval same as loan repayment interval. */ recur.setInterval(loanRepaymentInterval); /* * Recurring dates should follow loanRepayment frequency. //e.g. daily * meeting frequency should support all loan products with any type of * frequency. to generate right set of meeting dates reset frequency * same as loan repayment frequency. */ if (recur.getFrequency().equals(Recur.DAILY)) { recur.setFrequency(frequency); } LocalDate newRepaymentDate = getNextRecurringDate(recur, seedDate, tmpDate); final LocalDate nextRepaymentDate = getNextRecurringDate(recur, seedDate, newRepaymentDate); newRepaymentDate = WorkingDaysUtil.getOffSetDateIfNonWorkingDay(newRepaymentDate, nextRepaymentDate, workingDays); return newRepaymentDate; }
From source file:org.apache.fineract.portfolio.calendar.service.CalendarUtils.java
License:Apache License
public static LocalDate getRecentEligibleMeetingDate(final String recurringRule, final LocalDate seedDate) { LocalDate currentDate = DateUtils.getLocalDateOfTenant(); final Recur recur = CalendarUtils.getICalRecur(recurringRule); if (recur == null) { return null; }//from www . jav a2 s . c o m if (isValidRecurringDate(recur, seedDate, currentDate)) { return currentDate; } if (recur.getFrequency().equals(Recur.DAILY)) { currentDate = currentDate.plusDays(recur.getInterval()); } else if (recur.getFrequency().equals(Recur.WEEKLY)) { currentDate = currentDate.plusWeeks(recur.getInterval()); } else if (recur.getFrequency().equals(Recur.MONTHLY)) { currentDate = currentDate.plusMonths(recur.getInterval()); } else if (recur.getFrequency().equals(Recur.YEARLY)) { currentDate = currentDate.plusYears(recur.getInterval()); } return getNextRecurringDate(recur, seedDate, currentDate); }