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:net.sourceforge.fenixedu.presentationTier.TagLib.GanttDiagramTagLib.java
License:Open Source License
private void insertNextAndBeforeLinks(StringBuilder builder) throws JspException { YearMonthDay firstDay = getGanttDiagramObject().getFirstInstant().toYearMonthDay(); if (firstDay != null) { String nextUrl = ""; String beforeUrl = ""; switch (getViewTypeEnum()) { case WEEKLY: if (!StringUtils.isEmpty(getWeeklyViewUrl())) { nextUrl = getRequest().getContextPath() + getWeeklyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.plusDays(Lesson.NUMBER_OF_DAYS_IN_WEEK).toString("ddMMyyyy"); beforeUrl = getRequest().getContextPath() + getWeeklyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.minusDays(Lesson.NUMBER_OF_DAYS_IN_WEEK).toString("ddMMyyyy"); builder.append(//from www . jav a 2s .c om "<tr><td class=\"tcalendarlinks\"></td><td colspan=\"7\" class=\"acenter tcalendarlinks\"> <span class=\"smalltxt\"><a href=\"") .append(beforeUrl).append("\">").append("<< ") .append(getMessage("label.previous.week")).append("</a>"); builder.append(" , ").append("<a href=\"").append(nextUrl).append("\">") .append(getMessage("label.next.week")).append(" >>").append("</a>") .append("</span></td><td class=\"tcalendarlinks\"></td><td class=\"tcalendarlinks\"></td></tr>"); } break; case DAILY: if (!StringUtils.isEmpty(getDailyViewUrl())) { nextUrl = getRequest().getContextPath() + getDailyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.plusDays(1).toString("ddMMyyyy"); beforeUrl = getRequest().getContextPath() + getDailyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.minusDays(1).toString("ddMMyyyy"); builder.append( "<tr><td class=\"tcalendarlinks\"></td><td class=\"acenter tcalendarlinks\"><span class=\"smalltxt\"><a href=\"") .append(beforeUrl).append("\">").append("<< ") .append(getMessage("label.previous.day")).append("</a>"); builder.append(" , ").append("<a href=\"").append(nextUrl).append("\">") .append(getMessage("label.next.day")).append(" >>").append("</a>") .append("</span></td><td class=\"tcalendarlinks\"></td><td class=\"tcalendarlinks\"></td></tr>"); } break; case MONTHLY: if (!StringUtils.isEmpty(getMonthlyViewUrl())) { DateTime month = firstDay.toDateTimeAtMidnight(); DateTime firstDayOfMonth = (month.getDayOfMonth() != 1) ? month.withDayOfMonth(1) : month; DateTime lastDayOfMonth = firstDayOfMonth.plusMonths(1).minusDays(1); int monthNumberOfDays = Days.daysBetween(firstDayOfMonth, lastDayOfMonth).getDays() + 1; nextUrl = getRequest().getContextPath() + getMonthlyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.plusMonths(1).toString("ddMMyyyy"); beforeUrl = getRequest().getContextPath() + getMonthlyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.minusMonths(1).toString("ddMMyyyy"); builder.append("<tr><td class=\"tcalendarlinks\"></td><td colspan=\"").append(monthNumberOfDays) .append("\" class=\"acenter tcalendarlinks\"><span class=\"smalltxt\"><a href=\"") .append(beforeUrl).append("\">").append("<< ") .append(getMessage("label.previous.month")).append("</a>"); builder.append(" , ").append("<a href=\"").append(nextUrl).append("\">") .append(getMessage("label.next.month")).append(" >>").append("</a>") .append("</span></td><td class=\"tcalendarlinks\"></td><td class=\"tcalendarlinks\"></td></tr>"); } break; case YEAR_DAILY: if (!StringUtils.isEmpty(getMonthlyViewUrl())) { DateTime month = firstDay.toDateTimeAtMidnight(); DateTime firstDayOfMonth = (month.getDayOfMonth() != 1) ? month.withDayOfMonth(1) : month; DateTime lastDayOfMonth = firstDayOfMonth.plusMonths(1).minusDays(1); int monthNumberOfDays = Days.daysBetween(firstDayOfMonth, lastDayOfMonth).getDays() + 1; nextUrl = getRequest().getContextPath() + getMonthlyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.plusMonths(1).toString("ddMMyyyy"); beforeUrl = getRequest().getContextPath() + getMonthlyViewUrl() + "&" + getFirstDayParameter() + "=" + firstDay.minusMonths(1).toString("ddMMyyyy"); builder.append("<tr><td class=\"tcalendarlinks\"></td><td colspan=\"").append(monthNumberOfDays) .append("\" class=\"acenter tcalendarlinks\"><span class=\"smalltxt\"><a href=\"") .append(beforeUrl).append("\">").append("<< ") .append(getMessage("label.previous.month")).append("</a>"); builder.append(" , ").append("<a href=\"").append(nextUrl).append("\">") .append(getMessage("label.next.month")).append(" >>").append("</a>") .append("</span></td><td class=\"tcalendarlinks\"></td><td class=\"tcalendarlinks\"></td></tr>"); } break; default: break; } } }
From source file:net.sourceforge.fenixedu.util.renderer.GanttDiagram.java
License:Open Source License
public int getMonthsDaysSize() { int result = 0; for (DateTime month : getMonths()) { DateTime firstDayOfMonth = (month.getDayOfMonth() != 1) ? month.withDayOfMonth(1) : month; DateTime lastDayOfMonth = firstDayOfMonth.plusMonths(1).minusDays(1); int monthNumberOfDays = Days.daysBetween(firstDayOfMonth, lastDayOfMonth).getDays() + 1; result += monthNumberOfDays;//www . j a va2 s . com } return result; }
From source file:net.technicpack.launcher.ui.components.news.AuthorshipWidget.java
License:Open Source License
private String getDateText(Date date) { LocalDate posted = new LocalDate(date.getTime()); LocalDate now = new LocalDate(); Years yearsSince = Years.yearsBetween(posted, now); Months monthsSince = Months.monthsBetween(posted, now); Days daysSince = Days.daysBetween(posted, now); Hours hoursSince = Hours.hoursBetween(posted, now); Minutes minutesSince = Minutes.minutesBetween(posted, now); if (yearsSince.getYears() > 1) return resources.getString("time.years", Integer.toString(yearsSince.getYears())); else if (yearsSince.getYears() == 1) return resources.getString("time.year"); else if (monthsSince.getMonths() > 1) return resources.getString("time.months", Integer.toString(monthsSince.getMonths())); else if (monthsSince.getMonths() == 1) return resources.getString("time.month"); else if (daysSince.getDays() > 1) return resources.getString("time.days", Integer.toString(daysSince.getDays())); else if (daysSince.getDays() == 1) return resources.getString("time.day"); else if (hoursSince.getHours() > 1) return resources.getString("time.hours", Integer.toString(hoursSince.getHours())); else if (hoursSince.getHours() == 1) return resources.getString("time.hour"); else if (minutesSince.getMinutes() > 1) return resources.getString("time.minutes", Integer.toString(minutesSince.getMinutes())); else// w ww. j a v a 2 s. c o m return resources.getString("time.minute"); }
From source file:net.tourbook.ui.views.calendar.CalendarGraph.java
License:Open Source License
public void gotoToday() { _dt = new DateTime(); final Days d = Days.daysBetween(new DateTime(0), _dt); _selectedItem = new Selection((long) d.getDays(), SelectionType.DAY); gotoDate(_dt);//from w w w. j av a 2 s .c om }
From source file:odin.domain.Sprint.java
License:Apache License
public static int getRemainingAvailability(String sprintString, String username) { EntityManager em = DBUtil.getEntityManager(); TypedQuery<Sprint> q = em/*from ww w. jav a2 s.c om*/ .createQuery("select s from Sprint s WHERE s.sprintName = :sprintString", Sprint.class) .setParameter("sprintString", sprintString); Sprint sprint = q.getSingleResult(); // em.detach(sprint); LocalDate today = new LocalDate(); int availability = 0; SimpleDateFormat sdf = new SimpleDateFormat("M/d/yy"); for (Week week : sprint.getWeeks()) { LocalDate weekEndDate = LocalDate.fromDateFields(week.getEndDate()); int days = Days.daysBetween(today, weekEndDate).getDays(); System.out.println(days); if (days >= 0) { if (days < 6) { // Calculate hours left on a part week. int remainingHours = Availability.getAvailability(sdf.format(weekEndDate.toDate()), username) / 5 * days; availability = availability + remainingHours; System.out.println("Part week. Calculated availability for week ending " + sdf.format(week.getEndDate()) + " is " + remainingHours); } else availability = availability + Availability.getAvailability(sdf.format(weekEndDate.toDate()), username); } } em.close(); return availability; }
From source file:office.CheckIn.java
public void ExecuteCommand() { double price = 0.00; int selectedRowIndex = table.getSelectedRow(); int selectedColumnIndex = table.getSelectedColumn(); String item = (String) table.getModel().getValueAt(selectedRowIndex, 5); String returned = (String) table.getModel().getValueAt(selectedRowIndex, 8); Date dueDate = (Date) table.getModel().getValueAt(selectedRowIndex, 7); int custID = (int) table.getModel().getValueAt(selectedRowIndex, 0); int days = Days.daysBetween(new DateTime(dueDate), new DateTime(DATE.getDate())).getDays(); if (days < 0) { days = 0;/* w w w .j ava 2 s.c om*/ } try { Connection con = dbCon.getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT price_day FROM items WHERE item = '" + item + "'"); rs.next(); price = rs.getDouble(1); // Closes the Connection rs.close(); con.close(); } catch (Exception e) { System.out.print(e); e.printStackTrace(); JOptionPane optionPane = new JOptionPane(e.toString()); JDialog dialog = optionPane.createDialog("Error!"); dialog.setAlwaysOnTop(this.isAlwaysOnTopSupported()); dialog.setVisible(true); } amountOwe = days * price; if (returned != null) { String query = "UPDATE CHECKOUTS SET RETURNED='" + returned + "', CHECKINDATE='" + DATE.getDate() + "', STAFF2='" + staffName + "', AMOUNTOWE=" + amountOwe + " WHERE CUST_ID = " + custID; try { Connection con = dbCon.getConnection(); Statement stmt = con.createStatement(); stmt.executeUpdate(query); con.close(); } catch (Exception e) { System.out.print(e); e.printStackTrace(); JOptionPane optionPane = new JOptionPane(e.toString()); JDialog dialog = optionPane.createDialog("Error!"); dialog.setAlwaysOnTop(this.isAlwaysOnTopSupported()); dialog.setVisible(true); } } else { JOptionPane.showMessageDialog(null, "Please select the cell you want to update!", "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:op.care.nursingprocess.PnlNursingProcess.java
License:Open Source License
private Icon getIcon(NursingProcess np) { DateTime nexteval = new DateTime(np.getNextEval()); if (!np.isClosed()) { return getIcon(Days.daysBetween(new DateTime(), nexteval).getDays()); } else {//from w ww . j a va 2 s . c om return SYSConst.icon22stopSign; } }
From source file:op.care.nursingprocess.PnlNursingProcess.java
License:Open Source License
private int getMinimumNextEvalDays(final ResInfoCategory cat) { int days = Integer.MAX_VALUE; for (NursingProcess np : valuecache.get(cat)) { if (!np.isClosed()) days = Math.min(Days.daysBetween(new DateTime(), new DateTime(np.getNextEval())).getDays(), days); }/* ww w .jav a 2 s.co m*/ return days; }
From source file:opticalworkshopmonitoringsystem.CenteringAndEdgingDivision.java
License:Open Source License
private void jTextField6FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField6FocusLost // TODO add your handling code here: Date d1 = null;/* w w w . jav a2 s . c o m*/ Date d2 = null; startdate = jTextField1.getText() + "/" + jTextField4.getText() + "/" + jTextField5.getText(); enddate = jTextField2.getText() + "/" + jTextField3.getText() + "/" + jTextField6.getText(); //d1=; SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); try { d1 = format.parse(startdate); d2 = format.parse(enddate); DateTime dt1 = new DateTime(d1); DateTime dt2 = new DateTime(d2); jLabel26.setText(Days.daysBetween(dt1, dt2).getDays() + " days"); d3 = Days.daysBetween(dt1, dt2).getDays() + " days"; } catch (Exception e) { JOptionPane.showMessageDialog(this.getParent(), "Please enter a valid date"); } }
From source file:opticalworkshopmonitoringsystem.CenteringAndEdgingDivision.java
License:Open Source License
private void jTextField18FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField18FocusLost // TODO add your handling code here: Date d4 = null;//from ww w . java 2 s .c o m Date d5 = null; startdate1 = jTextField13.getText() + "/" + jTextField14.getText() + "/" + jTextField15.getText(); enddate1 = jTextField16.getText() + "/" + jTextField17.getText() + "/" + jTextField18.getText(); SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); try { d4 = format.parse(startdate1); d5 = format.parse(enddate1); DateTime dt4 = new DateTime(d4); DateTime dt5 = new DateTime(d5); jLabel28.setText(Days.daysBetween(dt4, dt5).getDays() + " days"); d6 = Days.daysBetween(dt4, dt5).getDays() + " days"; } catch (Exception e) { JOptionPane.showMessageDialog(this.getParent(), "Please enter a valid date"); } }