List of usage examples for org.joda.time Days getDays
public int getDays()
From source file:com.github.cassandra.jdbc.provider.datastax.codecs.JavaSqlDateCodec.java
License:Apache License
@Override public ByteBuffer serialize(Date value, ProtocolVersion protocolVersion) { if (value == null) return null; Days days = daysBetween(EPOCH, LocalDate.fromDateFields(value)); int unsigned = fromSignedToUnsignedInt(days.getDays()); return cint().serializeNoBoxing(unsigned, protocolVersion); }
From source file:com.github.cassandra.jdbc.provider.datastax.codecs.StringDateCodec.java
License:Apache License
@Override public ByteBuffer serialize(String value, ProtocolVersion protocolVersion) { if (value == null) return null; Days days = daysBetween(EPOCH, LocalDate.parse(value)); int unsigned = fromSignedToUnsignedInt(days.getDays()); return cint().serializeNoBoxing(unsigned, protocolVersion); }
From source file:com.github.flawedbliss.dicebotr3.DicebotR3.java
License:Open Source License
private void checkPremiumExpired(String uid, int clId) { Connection connect = null;//ww w.j a v a2 s .c om PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { connect = cp.getConnection(); preparedStatement = connect.prepareStatement("SELECT * FROM premium WHERE used_by=?"); preparedStatement.setString(1, uid); resultSet = preparedStatement.executeQuery(); DateTime today = new DateTime(new Date()); DateTime latest = new DateTime(new Date()); latest = latest.minusYears(1); if (resultSet.isBeforeFirst()) { while (resultSet.next()) { DateTime resultSetDate = new DateTime(resultSet.getDate("date_used")); if (resultSetDate.isAfter(latest)) { latest = resultSetDate; } } Days d = Days.daysBetween(latest, today); if (d.getDays() > cfg.getPremiumDays()) { myApi.removeClientFromServerGroup(cfg.getPremiumGID(), myApi.getClientByUId(uid).getDatabaseId()); myApi.sendPrivateMessage(clId, "Your premium has expired."); } } } catch (SQLException ex) { log.warning("SQLException when trying to check premium of" + uid); ex.printStackTrace(); } }
From source file:com.github.flawedbliss.dicebotr3.DicebotR3.java
License:Open Source License
private boolean checkInactivity(String uid, int days) { if (cfg.getInactiveGID() == -1) { return false; }// w w w.j a va 2 s . c om Connection connect = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { connect = cp.getConnection(); preparedStatement = connect.prepareStatement("SELECT * FROM lastlogin WHERE uid=?"); preparedStatement.setString(1, uid); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { DateTime today = new DateTime(new Date()); DateTime lastlogin = new DateTime(resultSet.getDate("lastlogin")); Days d = Days.daysBetween(today, lastlogin); if (d.getDays() > days) { myApi.addClientToServerGroup(cfg.getInactiveGID(), myApi.getClientByUId(uid).getDatabaseId()); return true; } } resultSet.close(); preparedStatement.close(); connect.close(); } catch (SQLException ex) { log.warning("SQLException while checking inactivity of " + uid); } return false; }
From source file:com.inkubator.common.util.DateTimeUtil.java
/** * get total days difference, between two date type * * @return Integer//from w w w. j ava 2 s. c om * @param date1 Date reference * @param date2 Date reference */ public static Integer getTotalDayDifference(Date date1, Date date2) { Days days = Days.daysBetween(new DateMidnight(date1), new DateMidnight(date2)); return days.getDays(); }
From source file:com.iucosoft.eavertizare.gui.MainJFrame.java
public void autoRun() { System.out.println("Spring 4 + Quartz 2.2.1 ~"); // SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy"); // Runnable myRunnable = new Runnable() { ///* www .j a v a 2 s . com*/ // @Override // public void run() { DateTime start = new DateTime(); List<Firma> listFirma = firmaDao.findAll(); List<Client> listClients; //*******************Sincronizare************ sincronizare(); //***************** for (Firma firmalocal : listFirma) { listClients = clientsDao.findAllClientsForFirmaLocal(firmalocal); for (Client client : listClients) { // System.out.println("" + sdf.format(client.getDateExpirare())); DateTime end = new DateTime(client.getDateExpirare()); Days days = Days.daysBetween(start, end); if (days.getDays() == -2) { // System.out.println("" + sdf.format(client.getDateExpirare())); System.out.println(" " + client.getDateExpirare()); SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy"); String mesajClient = client.getFirma().getMesajPentruClienti() .replaceFirst("nume", client.getNume()).replaceFirst("prenume", client.getPrenume()) .replaceFirst("data", sdf.format(client.getDateExpirare()).toString()) .replaceFirst("compania", client.getFirma().getNumeFirma()); try { // client.setTrimis(true); smsSender.sendSms(client.getNrTelefon(), mesajClient); mailSender.sendMail(client.getEmail(), "E-avetizare", mesajClient); } catch (Exception ex) { Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(this, "Verificai conexiunea la internet!\n" + ex, "Error", JOptionPane.ERROR_MESSAGE); } // try { // // this.wait(); // Thread.sleep(5000); // } catch (InterruptedException ex) { // Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex); // } } // clientsDao.update(client.getFirma(), client); } } this.refreshFrame(); // } // }; // // Thread thread = new Thread(myRunnable); // thread.start(); }
From source file:com.liteoc.logic.expressionTree.ArithmeticOpNode.java
License:LGPL
private String calculateDaysBetween(String value1, String value2) { DateMidnight dm1 = new DateMidnight(ExpressionTreeHelper.getDate(value1).getTime()); DateMidnight dm2 = new DateMidnight(ExpressionTreeHelper.getDate(value2).getTime()); switch (op) { case MINUS: { Days d = Days.daysBetween(dm1, dm2); int days = d.getDays(); return String.valueOf(Math.abs(days)); }// w w w. j a va 2 s. c om default: return null; // Bad operator! } }
From source file:com.nitdlibrary.EditBook.java
public void calculateBookPerformance() throws SQLException { issueResultSet.beforeFirst();/*from w w w . ja v a2 s . com*/ java.util.Date returnDate = null, dueDate = null; LocalDate returnDateJoda = null, dueDateJoda = null; int totalIssued = 0, returned = 0, fine = 0, currentIssue = 0; int flag = 0; //incremented when today is > due date and return_date is null. it means that some books are not returned and fine calc is shown wrt today while (issueResultSet.next()) { totalIssued++; if (issueResultSet.getString("return_date") != null) returned++; DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); try { dueDate = format.parse(issueResultSet.getString("due_date")); /** * IF BOOK HAS NOT BEEN RETURNED AND TODAY>DUEDATE .. FINE TO BE PAID IS SHOWN */ if (issueResultSet.getString("return_date") != null && (issueResultSet.getString("return_date").compareTo("") != 0)) { returnDate = format.parse(issueResultSet.getString("return_date")); } else { String tempDate = format.format(new java.util.Date()); returnDate = format.parse(tempDate); if (dueDate.before(returnDate)) // i.e due date before today and book is not returned. flag++; } returnDateJoda = new LocalDate(returnDate); dueDateJoda = new LocalDate(dueDate); } catch (ParseException ex) { Logger.getLogger(EditViewStudent.class.getName()).log(Level.SEVERE, null, ex); } if (dueDate.before(returnDate)) { Days d = Days.daysBetween(returnDateJoda, dueDateJoda); fine += d.getDays(); } if (issueResultSet.getString("return_date") == null || (issueResultSet.getString("return_date").compareTo("") == 0)) { currentIssue++; } } /** * setting values in Labels */ issued.setText("No of times Issued : " + totalIssued); returnedLabel.setText("No of times Returned : " + returned); if (fine < 0) fine = 0; fineLabel.setText("Total Fine Obtained: " + fine); if (currentIssue != 0) currentLabel.setText("Currently issued : Yes"); else currentLabel.setText("Currently issued : No"); if (flag != 0) exceedLabel.setText("*OverDue : " + flag + " student has exceeded due date and has not returned. Assuming he/she retuns today, total fine is being shown."); else exceedLabel.setText("*"); }
From source file:com.nitdlibrary.EditBook.java
/** * THIS FUNCTION CALCULATES DATA FOR FILTERED RESULTSET AND UPDATES THE LABELS * @param from//from ww w .j av a 2 s . co m * @param to */ private void calculateFilteredPerformance(LocalDate from, LocalDate to) throws SQLException { issueFilteredResultSet.beforeFirst(); java.util.Date returnDate = null, dueDate = null; LocalDate returnDateJoda = null, dueDateJoda = null; int totalIssued = 0, returned = 0, fine = 0, currentIssue = 0; int flag = 0; //incremented when today is > due date and return_date is null. it means that some books are not returned and fine calc is shown wrt today while (issueFilteredResultSet.next()) { totalIssued++; if (issueFilteredResultSet.getString("return_date") != null) returned++; DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); try { dueDate = format.parse(issueFilteredResultSet.getString("due_date")); /** * IF BOOK HAS NOT BEEN RETURNED AND TODAY>DUEDATE .. FINE TO BE PAID IS SHOWN */ if (issueFilteredResultSet.getString("return_date") != null && (issueFilteredResultSet.getString("return_date").compareTo("") != 0)) { returnDate = format.parse(issueFilteredResultSet.getString("return_date")); } else { String tempDate = format.format(new java.util.Date()); returnDate = format.parse(tempDate); if (dueDate.before(returnDate)) // i.e due date before today and book is not returned. flag++; } returnDateJoda = new LocalDate(returnDate); dueDateJoda = new LocalDate(dueDate); } catch (ParseException ex) { Logger.getLogger(EditViewStudent.class.getName()).log(Level.SEVERE, null, ex); } if (dueDate.before(returnDate)) { Days d = Days.daysBetween(returnDateJoda, dueDateJoda); fine += d.getDays(); } if (issueFilteredResultSet.getString("return_date") == null || (issueFilteredResultSet.getString("return_date").compareTo("") == 0)) { currentIssue++; } } /** * setting values in Labels */ issuedFiltered.setText("No of times Issued : " + totalIssued); returnedFiltered.setText("No of times Returned : " + returned); if (fine < 0) fine = 0; fineFiltered.setText("Total Fine Obtained : " + fine); if (currentIssue != 0) currentFiltered.setText("Remained issued : Yes"); else currentFiltered.setText("Remained issued : No"); // if(flag!=0){ //exceedLabel.setText("* "+ flag +" books have exceeded due date and are not returned. Assuming they are retuned today, total fine is being shown."); // } }
From source file:com.nitdlibrary.EditViewStudent.java
/** * THIS FUNCTION CALCULATES STUDENT PERFORMCE AND UPDATES FIELDS *//*from ww w . j a v a2 s .c o m*/ private void calculateStudentPerformance() throws SQLException { issueResultSet.beforeFirst(); Date returnDate = null, dueDate = null; LocalDate returnDateJoda = null, dueDateJoda = null; int totalIssued = 0, returned = 0, fine = 0, currentIssue = 0; int flag = 0; //incremented when today is > due date and return_date is null. it means that some books are not returned and fine calc is shown wrt today while (issueResultSet.next()) { totalIssued++; if (issueResultSet.getString("return_date") != null) returned++; DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); try { dueDate = format.parse(issueResultSet.getString("due_date")); /** * IF BOOK HAS NOT BEEN RETURNED AND TODAY>DUEDATE .. FINE TO BE PAID IS SHOWN */ if (issueResultSet.getString("return_date") != null && (issueResultSet.getString("return_date").compareTo("") != 0)) { returnDate = format.parse(issueResultSet.getString("return_date")); } else { String tempDate = format.format(new Date()); returnDate = format.parse(tempDate); if (dueDate.before(returnDate)) // i.e due date before today and book is not returned. flag++; } returnDateJoda = new LocalDate(returnDate); dueDateJoda = new LocalDate(dueDate); } catch (ParseException ex) { Logger.getLogger(EditViewStudent.class.getName()).log(Level.SEVERE, null, ex); } System.out.println( "DUE DATE : " + dueDateJoda.toString() + " RETURN DATE : " + returnDateJoda.toString()); if (dueDate.before(returnDate)) { Days d = Days.daysBetween(dueDateJoda, returnDateJoda); fine += d.getDays(); System.out.println("Calculting fine"); } if (issueResultSet.getString("return_date") == null || (issueResultSet.getString("return_date").compareTo("") == 0)) { currentIssue++; } } /** * setting values in Labels */ issued.setText("Total Books Issued : " + totalIssued); returnedLabel.setText("Total Books Returned : " + returned); if (fine < 0) fine = 0; fineLabel.setText("Total Fine : " + fine); currentLabel.setText("Currently issued book count : " + currentIssue); if (flag != 0) exceedLabel.setText("* " + flag + " books have exceeded due date and are not returned. Assuming they are retuned today, total fine is being shown."); }