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:com.stratio.crossdata.sh.utils.ConsoleUtils.java
License:Apache License
/** * Get previous history of the Crossdata console from a file. * * @param console Crossdata console created from a JLine console * @param sdf Simple Date Format to read dates from history file * @return File inserted in the JLine console with the previous history * @throws IOException/*w w w. j av a 2 s . co m*/ */ public static File retrieveHistory(ConsoleReader console, SimpleDateFormat sdf) throws IOException { Date today = new Date(); String workingDir = System.getProperty("user.home"); File dir = new File(workingDir, ".com.stratio.crossdata"); if (!dir.exists() && !dir.mkdir()) { LOG.error("Cannot create history directory: " + dir.getAbsolutePath()); } File file = new File(dir.getPath() + "/history.txt"); if (!file.exists() && !file.createNewFile()) { LOG.error("Cannot create history file: " + file.getAbsolutePath()); } if (LOG.isDebugEnabled()) { LOG.debug("Retrieving history from " + file.getAbsolutePath()); } BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); History oldHistory = new MemoryHistory(); DateTime todayDate = new DateTime(today); String line; String[] lineArray; Date lineDate; String lineStatement; try { while ((line = br.readLine()) != null) { lineArray = line.split("\\|"); lineDate = sdf.parse(lineArray[0]); if (Days.daysBetween(new DateTime(lineDate), todayDate).getDays() < DAYS_HISTORY_ENTRY_VALID) { lineStatement = lineArray[1]; oldHistory.add(lineStatement); } } } catch (ParseException ex) { LOG.error("Cannot parse date", ex); } catch (Exception ex) { LOG.error("Cannot read all the history", ex); } finally { br.close(); } console.setHistory(oldHistory); LOG.info("History retrieved"); return file; }
From source file:com.teamj.distribuidas.web.ExcursionUserBean.java
public String duracion(Date salida, Date retorno) { int days = Days.daysBetween(new LocalDate(salida), new LocalDate(retorno)).getDays(); return String.valueOf(days); }
From source file:com.thingsee.tracker.libs.SmartDateTimeUtil.java
License:Apache License
public static String getDateString_shortAndSmart(Date date, Resources res, boolean hrs24_clock) { String s;// w ww . ja v a 2 s .c om DateTime nowDT = new DateTime(); DateTime dateDT = new DateTime(date); int days = Days.daysBetween(dateDT, nowDT).getDays(); if (isToday(new DateTime(date))) s = res.getString(R.string.timestamp_today) + "," + getHourMinuteString(date, hrs24_clock); else if (days < 7) s = getDayString(date, res, hrs24_clock); else s = getDateString(date, hrs24_clock); return s; }
From source file:com.toedter.jcalendar.core.DateChooser.java
License:Open Source License
private void computeDayCellValues() { DateTime firstDayThisMonth = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), 1, 0, 0, 0, 0); DateTime firstDayNextMonth = firstDayThisMonth.plusMonths(1).withDayOfMonth(1); int dayOfWeek = firstDayThisMonth.dayOfWeek().get(); Days d = Days.daysBetween(firstDayThisMonth, firstDayNextMonth); int daysInThisMonth = d.getDays(); System.out.println(daysInThisMonth); int index = 2; for (IDayCell dayCell : dayCells) { if (index <= dayOfWeek || index - dayOfWeek > daysInThisMonth) { ((DayCell) dayCell).dayText = ""; } else {//from w w w. j a v a2 s. c o m ((DayCell) dayCell).dayText = "" + (index - dayOfWeek); } index++; } }
From source file:com.tojsq.view.master.VpnViewBean.java
public void search() { final List<Vpn> vpnList = vpnService.selectByQQ(this.getQq()); if (vpnList.size() > 0) { final Vpn vpn = vpnList.get(0); int days = Days.daysBetween(LocalDate.now(), LocalDate.fromDateFields(vpn.getEndDate())).getDays(); if (days < 0) { this.setResult(String.format("????:%s", LocalDate.fromDateFields(vpn.getEndDate()).toString("yyyy-MM-dd"))); } else {//from w ww.j a v a2 s . co m this.setResult(String.format(":%s,%d", LocalDate.fromDateFields(vpn.getEndDate()).toString("yyyy-MM-dd"), days)); } } else { this.setResult("?????QQ???~"); } }
From source file:com.tortel.deploytrack.data.Deployment.java
License:Apache License
/** * Returns the length of the deployment, in days * @return the length/* www . j a v a 2 s. co m*/ */ @Exclude public int getLength() { return Days.daysBetween(getStart(), getEnd()).getDays(); }
From source file:com.tortel.deploytrack.data.Deployment.java
License:Apache License
/** * Get the number of days completed so far */// ww w.j a v a 2 s. c o m @Exclude public int getCompleted() { DateTime start = getStart(); //Check if it has even started if (start.isAfterNow()) { return 0; } return Math.min(Days.daysBetween(start, new DateTime()).getDays(), getLength()); }
From source file:com.tremolosecurity.provisioning.scheduler.jobs.RemindApprovers.java
License:Apache License
@Override public void execute(ConfigManager configManager, JobExecutionContext context) throws ProvisioningException { if (configManager == null || configManager.getProvisioningEngine() == null) { logger.warn("System not fully initialized"); return;//from www .ja va 2 s . com } String msg = context.getJobDetail().getJobDataMap().getString("message"); int days = Integer.parseInt(context.getJobDetail().getJobDataMap().getString("days")); String mailAttribute = context.getJobDetail().getJobDataMap().getString("mailAttributeName"); Session session = null; try { session = configManager.getProvisioningEngine().getHibernateSessionFactory().openSession(); DateTime approvalsAfterDate = new DateTime().minusDays(days + 1); Query query = session.createQuery("FROM Approvals WHERE approved IS NULL AND createTS > :check_date"); query.setParameter("check_date", new java.sql.Date(approvalsAfterDate.getMillis())); List<com.tremolosecurity.provisioning.objects.Approvals> approvals = query.list(); DateTime now = new DateTime(); for (Approvals apr : approvals) { int daysOpen = Days.daysBetween(new DateTime(apr.getCreateTs().getTime()), now).getDays(); String label = apr.getLabel(); String mail = null; for (AllowedApprovers allowed : apr.getAllowedApproverses()) { mail = null; for (ApproverAttributes attr : allowed.getApprovers().getApproverAttributeses()) { if (attr.getName().equalsIgnoreCase(mailAttribute)) { mail = attr.getValue(); } } if (mail == null) { logger.warn("No attribute called '" + mailAttribute + "' for user '" + allowed.getApprovers().getUserKey() + "'"); } else { if (logger.isDebugEnabled()) { logger.debug("Notifying " + mail + " for " + label + " after " + daysOpen + " days"); } String toSend = msg.replaceAll("[%]L", label).replaceAll("[%]D", Integer.toString(daysOpen)); configManager.getProvisioningEngine().sendNotification(mail, toSend, "Open Approval for " + daysOpen + " days", new User(mail)); } } } } catch (Exception e) { throw new ProvisioningException("Error reminding open approvers", e); } finally { if (session != null) { session.close(); } } }
From source file:com.verigreen.collector.jobs.CacheCleanerJob.java
License:Apache License
private boolean isExceedThreashold(Date date) { Days daysBetweenCreationTimeAndNow = Days.daysBetween(new DateTime(date), DateTime.now()); return daysBetweenCreationTimeAndNow.getDays() >= Integer .parseInt(VerigreenNeededLogic.VerigreenMap.get("daysThreashold")); }
From source file:com.yahoo.sql4d.query.nodes.Interval.java
License:Open Source License
public Interval(String startTime, String endTime) { this.startTime = startTime.replaceAll("'", ""); this.endTime = endTime.replaceAll("'", ""); days = Days.daysBetween(getStartTime().withTimeAtStartOfDay(), getEndTime().withTimeAtStartOfDay()) .getDays() + 1;/*from w w w .j a v a 2s .c om*/ }