List of usage examples for org.joda.time Days daysBetween
public static Days daysBetween(ReadablePartial start, ReadablePartial end)
Days
representing the number of whole days between the two specified partial datetimes. From source file:Tools.CrawlersConnector.java
public ArrayList<CustomStatus> readKeyword(String keyword) throws MalformedURLException, IOException, JSONException, ParseException { //databaseHandler dbh=new databaseHandler(); BaselineAnalysisTools bat = new BaselineAnalysisTools(); ArrayList<CustomStatus> res; TwitterCrawler tc = new TwitterCrawler(); trueRes = new ArrayList<CustomStatus>(); //String keychain=allkeys.get(0); Date now = new Date(); Calendar c = Calendar.getInstance(); c.setTime(now);/*w w w.j a va 2s .c o m*/ c.add(Calendar.DATE, dateDiff); Date before6months = c.getTime(); SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); res = GlobalVarsStore.publicDBh.readTweets(keyword, null); boolean cancel = false; if (res == null) { res = new ArrayList<CustomStatus>(); } else if (res.size() > 0) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); before6months = formatter.parse(res.get(0).getCreatedAt()); int days = Days.daysBetween(new DateTime(before6months), new DateTime(now)).getDays(); if (days > 2) { before6months = c.getTime(); } else if (days < 1) cancel = true; } if (!cancel) { List<CustomStatus> tweetsCrawled = null; System.out.println(keyword + " -filter:links since:" + sf.format(before6months)); try { tweetsCrawled = tc.safeSearch((keyword + " -filter:links").replace(" ", "%20"), sf.format(before6months)); for (int j = 0; j < tweetsCrawled.size(); j++) { if (!tweetsCrawled.get(j).getClearText().contains("URL")) res.add(tweetsCrawled.get(j)); } res = clearDuplicateStatuses(res); for (int i = 0; i < res.size(); i++) { CustomStatus cur = res.get(i); cur.setPolarity(bat.SentiWordNetMeanAnalysisSingle(cur)); GlobalVarsStore.publicDBh.insertTweet(cur.getKeyword(), cur.getText(), cur.getPolarity(), cur.getId(), cur.getCreatedAt()); trueRes.add(cur); } return trueRes; } catch (NullPointerException exe) { int tries = 0; System.out.println("Communication error with database or crawler. Retrying in 60 seconds."); while (tweetsCrawled == null) { tries++; System.out.println("Try: " + tries); tweetsCrawled = tc.safeSearch((keyword + " -filter:links").replace(" ", "%20"), sf.format(before6months)); } for (int j = 0; j < tweetsCrawled.size(); j++) { if (!tweetsCrawled.get(j).getClearText().contains("URL")) res.add(tweetsCrawled.get(j)); } res = clearDuplicateStatuses(res); for (int i = 0; i < res.size(); i++) { CustomStatus cur = res.get(i); cur.setPolarity(bat.SentiWordNetMeanAnalysisSingle(cur)); GlobalVarsStore.publicDBh.insertTweet(cur.getKeyword(), cur.getText(), cur.getPolarity(), cur.getId(), cur.getCreatedAt()); trueRes.add(cur); } return trueRes; } } else { return res; } }
From source file:travelTimesBack.ProbabilitiesBackward.java
License:GNU General Public License
/** * Process.//from w w w . ja v a 2s. c om * * @throws Exception the exception */ @Execute public void process() throws Exception { /** ArrayList with the values of the computed variables */ ArrayList<Double> P = new ArrayList<Double>(); ArrayList<Double> pQ = new ArrayList<Double>(); ArrayList<Double> pET = new ArrayList<Double>(); ArrayList<Double> Q_out = new ArrayList<Double>(); ArrayList<Double> ET_out = new ArrayList<Double>(); ArrayList<Double> QttV = new ArrayList<Double>(); ArrayList<Double> ETttV = new ArrayList<Double>(); /** computation of the dimension of the array, given startDate and endDate */ DateTime start = formatter.parseDateTime(tStartDate); DateTime end = formatter.parseDateTime(tEndDate); dim = (tTimestep == 60) ? Hours.hoursBetween(start, end).getHours() + 1 : Days.daysBetween(start, end).getDays() + 1; /** deltaT is the difference between the beginning of the time series and * the beginning of the computation, in the case the analysis starts from a different * time-step */ if (tStartDateWaterBudget == null) deltaT = 0; else { DateTime startWaterBudget = formatter.parseDateTime(tStartDateWaterBudget); deltaT = Hours.hoursBetween(startWaterBudget, start).getHours(); } /** input values of precipitation*/ precipitation = inPrecipvalues.get(ID)[0]; if (isNovalue(precipitation)) precipitation = 0; /** the WB values are read just once, a t_i=0 */ if (t_i == 0) { inWaterStoragevalues = readData(inPathToStorage, ID); inDischargevalues = readData(inPathToDischarge, ID); inETvalues = (inPathToET == null) ? inETvalues : readData(inPathToET, ID); } /** initial conditions */ p_i = (inWaterStoragevalues[t_i + deltaT] > 0) ? precipitation / inWaterStoragevalues[t_i + deltaT] : 0; P.add(p_i); pQ.add(distributionValue(0) * P.get(0)); pET.add(distributionValue(0) * P.get(0)); Q_out.add(pQ.get(0) * inDischargevalues[t_i + deltaT]); if (inETvalues == null) ET_out.add(0.0); else ET_out.add(pET.get(0) * inETvalues[t_i + deltaT]); QttV.add(0.0); ETttV.add(0.0); /** loop for the computation of the probabilities and of the output fluxes * the loop continues until the value of the residence time pdf * is above the fixed threshold. The computation starts from time * step t=1, because of the initial conditions * */ t = 1; while (p_i > threshold & t < dim - t_i) { Q = inDischargevalues[t + t_i + deltaT]; S_t = inWaterStoragevalues[t + t_i - 1 + deltaT]; S_t1 = inWaterStoragevalues[t + t_i + deltaT]; ET = (inETvalues == null) ? 0.0 : inETvalues[t + t_i + deltaT]; /** StorageSelection value at time t */ SASvalue_t = distributionValue(t); P.add(computeP(SASvalue_t, p_i)); pQ.add(computePQ(P.get(t), SASvalue_t)); pET.add(computePET(P.get(t), SASvalue_t)); Q_out.add(computeQ(pQ.get(t))); ET_out.add(computeET(pET.get(t))); QttV.add(computeQtt(t, pQ.get(t))); ETttV.add(computeETtt(t, pET.get(t))); t++; } /** for each injection time the arrayFin is filled with t_i */ arrayFin.add((double) t_i); //System.out.println(t_i); /** * storage of results in hashmaps in which: * on the first column there re the injection times (date column) * and on the first row (value_t) are all the time step */ if (t_i < dim - 1) storeResult(P, pQ, pET, Q_out, ET_out, QttV, ETttV); else { storeResult(arrayFin, arrayFin, arrayFin, arrayFin, arrayFin, arrayFin, arrayFin); } /** t_i increases for considering the next injection time*/ t_i++; }
From source file:travelTimesFor.ProbabilitiesForward.java
License:GNU General Public License
/** * Process./* w w w. java 2 s . co m*/ * * @throws Exception the exception */ @Execute public void process() throws Exception { /** ArrayList with the values of the computed variables */ ArrayList<Double> thetaV = new ArrayList<Double>(); ArrayList<Double> pQ = new ArrayList<Double>(); ArrayList<Double> pET = new ArrayList<Double>(); ArrayList<Double> Q_out = new ArrayList<Double>(); ArrayList<Double> ET_out = new ArrayList<Double>(); /** computation of the dimension of the array, given startDate and endDate */ DateTime start = formatter.parseDateTime(tStartDate); DateTime end = formatter.parseDateTime(tEndDate); dim = (tTimestep == 60) ? Hours.hoursBetween(start, end).getHours() + 1 : Days.daysBetween(start, end).getDays() + 1; if (tStartDateWaterBudget == null) deltaT = 0; else { DateTime startWaterBudget = formatter.parseDateTime(tStartDateWaterBudget); deltaT = Hours.hoursBetween(startWaterBudget, start).getHours(); } /** input values of precipitation*/ J = inPrecipvalues.get(ID)[0]; if (isNovalue(J)) J = 0; /** the WB values are read just once, a t_i=0 */ if (t_i == 0) { inDischargevalues = readData(inPathToDischarge, ID); inETvalues = readData(inPathToET, ID); } /** since the dimension of the input hashmap varies in time * dim_i computes it for the following loop */ double dim_i = inPQ_backValues.size(); /** loop for the computation of the probabilities and of the output fluxes * it considers all the values from the series, each time from * a different injection time * */ for (int t = 0; t < dim_i; t++) { Q = inDischargevalues[t_i + t + deltaT]; ET = inETvalues[t_i + t + deltaT]; pQ_back = inPQ_backValues.get(t)[0]; if (isNovalue(pQ_back)) pQ_back = 0; pET_back = inPET_backValues.get(t)[0]; if (isNovalue(pET_back)) pET_back = 0; Q_ti = inQ_tiValues.get(t)[0]; if (isNovalue(Q_ti)) Q_ti = 0; ET_ti = inET_tiValues.get(t)[0]; if (isNovalue(ET_ti)) ET_ti = 0; thetaV.add(computeTheta()); pQ.add(computePQ(thetaV.get(t))); pET.add(computePET(thetaV.get(t))); Q_out.add(computeQ(thetaV.get(t), pQ.get(t))); ET_out.add(computeET(thetaV.get(t), pET.get(t))); } /** for each injection time the arrayFin is filled with a numeber, * needed for the ID of the output hashmap */ arrayFin.add((double) t_i); /** * storage of results in hashmaps in which: * on the first column there re the injection times (date column) * and on the first row (value_t) are all the time step */ if (t_i < dim - 1) storeResult(thetaV, pQ, pET, Q_out, ET_out); else { storeResult(arrayFin, arrayFin, arrayFin, arrayFin, arrayFin); } /** t increases for considering the next injection time*/ t_i++; intQ = 0; intQET = 0; }
From source file:ua.com.mycompany.fishsale.entities.Sale.java
public double calcIncome() { return (priceSale - pricePurchase - Days.daysBetween(datePurchase, dateSale).getDays() * OVERHEADS) * saleWeight; }
From source file:ua.mycompany.agedaysmonths.AgeDaysMonths.java
public static void main(String[] args) { LocalDate birthdate = new LocalDate(2015, 11, 12); LocalDate now = new LocalDate(); System.out.printf("My age in month: %d\n", Months.monthsBetween(birthdate, now).getMonths()); System.out.printf("My age in days: %d\n", Days.daysBetween(birthdate, now).getDays()); System.out.printf("Day of week my birtday: %s, %s\n", birthdate.getDayOfWeek(), birthdate.toString(DateTimeFormat.forPattern("E").withLocale(Locale.forLanguageTag("en")))); }
From source file:updaters.FeedStatsCalculator.java
License:Open Source License
/** * Apply not just the feed stats, but also the *//* ww w .jav a 2 s .com*/ private void calculateStartAndEnd() throws Exception { // First, read feed_info.txt // TODO is 1 ever not the correct value? FeedInfo feedInfo = store.getFeedInfoForId(1); if (feedInfo != null) { ServiceDate d; d = feedInfo.getStartDate(); if (d != null) { Calendar c = d.getAsCalendar(timezone); // move to GTFS noon, which will always be during the day. This accounts for both // multitimezone feeds and for daylight savings time c.add(Calendar.HOUR_OF_DAY, 12); startDate = c.getTime(); } d = feedInfo.getEndDate(); if (d != null) { Calendar c = d.getAsCalendar(timezone); c.add(Calendar.HOUR_OF_DAY, 12); endDate = c.getTime(); } } // we have an authoritative answer if (startDate != null && endDate != null) return; // let OBA deal with the complexities of interactions between // calendar.txt and // calendar_dates.txt // This code is lifted and slightly modified from // https://github.com/demory/otp_gtfs/blob/master/java/gtfsmetrics/src/main/java/org/openplans/gtfsmetrics/CalendarStatus.java Map<AgencyAndId, Set<ServiceDate>> addExceptions = new HashMap<AgencyAndId, Set<ServiceDate>>(); Map<AgencyAndId, Set<String>> removeExceptions = new HashMap<AgencyAndId, Set<String>>(); for (ServiceCalendarDate date : store.getAllCalendarDates()) { if (date.getExceptionType() == ServiceCalendarDate.EXCEPTION_TYPE_ADD) { Set<ServiceDate> dateSet = addExceptions.get(date.getServiceId()); if (dateSet == null) { dateSet = new HashSet<ServiceDate>(); addExceptions.put(date.getServiceId(), dateSet); } dateSet.add(date.getDate()); } else if (date.getExceptionType() == ServiceCalendarDate.EXCEPTION_TYPE_REMOVE) { Set<String> dateSet = removeExceptions.get(date.getServiceId()); if (dateSet == null) { dateSet = new HashSet<String>(); removeExceptions.put(date.getServiceId(), dateSet); } dateSet.add(constructMDYString(date.getDate())); } } DateTime latestEnd = new DateTime(0); DateTime earliestStart = null; for (ServiceCalendar svcCal : store.getAllCalendars()) { Calendar c; c = svcCal.getStartDate().getAsCalendar(timezone); c.add(Calendar.HOUR_OF_DAY, 12); DateTime start = new DateTime(c.getTime()); c = svcCal.getEndDate().getAsCalendar(timezone); c.add(Calendar.HOUR_OF_DAY, 12); DateTime end = new DateTime(c.getTime()); int totalDays = Days.daysBetween(start, end).getDays(); for (int d = 0; d < totalDays; d++) { int gd = getDay(svcCal, end.dayOfWeek().get());// dateCal.get(Calendar.DAY_OF_WEEK)); boolean removeException = false; Set<String> dateSet = removeExceptions.get(svcCal.getServiceId()); if (dateSet != null) { removeException = dateSet.contains(constructMDYString(end)); } if (gd == 1 && !removeException) break; end = end.minusDays(1); } if (end.isAfter(latestEnd)) latestEnd = end; totalDays = Days.daysBetween(start, end).getDays(); for (int d = 0; d < totalDays; d++) { int gd = getDay(svcCal, start.dayOfWeek().get());// dateCal.get(Calendar.DAY_OF_WEEK)); boolean removeException = false; Set<String> dateSet = removeExceptions.get(svcCal.getServiceId()); if (dateSet != null) { removeException = dateSet.contains(constructMDYString(start)); } if (gd == 1 && !removeException) break; start = start.plusDays(1); } if (earliestStart == null || start.isBefore(earliestStart)) earliestStart = start; } // now, expand based on calendar_dates.txt for (Set<ServiceDate> dateSet : addExceptions.values()) { for (ServiceDate sd : dateSet) { DateTime dt = new DateTime(sd.getAsDate(timezone).getTime()); if (dt.isAfter(latestEnd)) latestEnd = dt; if (dt.isBefore(earliestStart)) earliestStart = dt; } } this.startDate = earliestStart.toDate(); this.endDate = latestEnd.toDate(); }
From source file:UserInterface.AssetAdminRole.ManageMaintenaceJPanel.java
private void refreshMaintTable() { DefaultTableModel dtm = (DefaultTableModel) maintenanceJTable.getModel(); dtm.setRowCount(0);//www . j av a 2 s .c o m SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); Date today = new Date(); for (MedicalDevice md : ((AssetMgtOrganization) organization).getMedicalDeviceInventory() .getMedicalDeviceList()) { Object[] row = new Object[5]; row[0] = md; row[1] = dateFormat.format(md.getMaintScheduleHistory().getLastMaintenace().getLastMaintDate()); row[2] = dateFormat.format(md.getMaintScheduleHistory().getLastMaintenace().getNextMaintDate()); if (today.after(md.getMaintScheduleHistory().getLastMaintenace().getNextMaintDate())) { row[3] = "Expired"; md.setStatus("Out Of Service"); row[4] = md.getStatus(); } else { DateTime firstTime = new DateTime( md.getMaintScheduleHistory().getLastMaintenace().getNextMaintDate()); DateTime secondTime = new DateTime(today); int days = Days.daysBetween(new LocalDate(secondTime), new LocalDate(firstTime)).getDays(); row[3] = days; row[4] = md.getStatus(); } dtm.addRow(row); } }
From source file:utils.DateUtils.java
License:Open Source License
public static boolean isGreateThan(Date lesser, Date bigger) { if (lesser == null || bigger == null) return false; Days days = Days.daysBetween(new DateTime(bigger), new DateTime(lesser)); return (days.getDays() > 0); }
From source file:utils.DateUtils.java
License:Open Source License
public static boolean isLessThan(Date lesser, Date bigger) { if (lesser == null || bigger == null) return false; Days days = Days.daysBetween(new DateTime(bigger), new DateTime(lesser)); return (days.getDays() <= 0); }
From source file:utils.JodaDateUtil.java
License:Apache License
public static int localDaysBetween(Date from, Date to) { return Days.daysBetween(new DateTime(from).toLocalDate(), new DateTime(to).toLocalDate()).getDays(); }