List of usage examples for java.sql Timestamp after
public boolean after(Timestamp ts)
From source file:Main.java
public static void main(String[] args) { java.sql.Timestamp ts1 = java.sql.Timestamp.valueOf("2012-04-06 09:01:10"); java.sql.Timestamp ts2 = java.sql.Timestamp.valueOf("2013-04-06 09:01:10"); System.out.println(ts1.after(ts2)); }
From source file:org.gaixie.jibu.security.service.impl.LoginServiceImpl.java
public void resetPassword(String tokenValue, String password) throws JibuException { Connection conn = null;/*from ww w . ja va2 s. c o m*/ try { conn = ConnectionUtils.getConnection(); Token token = tokenDAO.get(conn, tokenValue); if (token == null) throw new TokenException("Token is null"); Calendar calendar = Calendar.getInstance(); long time = calendar.getTimeInMillis(); Timestamp ts = new Timestamp(time); if (ts.after(token.getExpiration())) throw new TokenException("Token expired."); if (password == null || password.isEmpty()) { throw new JibuException("Password is invalid."); } User user = new User(); String cryptpassword = MD5.encodeString(password, null); user.setPassword(cryptpassword); user.setId(token.getUser_id()); userDAO.update(conn, user); DbUtils.commitAndClose(conn); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); throw new JibuException(e.getMessage()); } finally { DbUtils.closeQuietly(conn); } }
From source file:com.springmvc.controller.TimeLogController.java
@RequestMapping(value = "/search", method = RequestMethod.GET) public String search(@RequestParam(value = "fromDate") String fromDate, String toDate, Model model) throws IOException, ParseException { List<TimeLog> timeLogs = timeLogService.getTimeLogs(); List<TimeLog> foundTimeLogs = new ArrayList<TimeLog>(); model.addAttribute("fromDate", fromDate); model.addAttribute("toDate", toDate); String message = ""; if (fromDate.isEmpty() || toDate.isEmpty()) { model.addAttribute("pageTitle", "TimeLogs"); model.addAttribute("pageDescription", "List of all login sessions and durations <br>You can sort and delete time logs as well"); model.addAttribute("type", "danger"); message = "Please choose a starting date with an ending date."; model.addAttribute("message", message); model.addAttribute("timelogs", timeLogService.getTimeLogs()); return "timelog_list"; }//from w w w .jav a2 s . com Timestamp beginDate = new Timestamp(new SimpleDateFormat("MM/dd/yyyy").parse(fromDate).getTime()); Timestamp endDate = new Timestamp(new SimpleDateFormat("MM/dd/yyyy").parse(toDate).getTime()); if (beginDate.after(endDate)) { model.addAttribute("pageTitle", "TimeLogs"); model.addAttribute("pageDescription", "List of all login sessions and durations <br>You can sort and delete time logs as well"); model.addAttribute("type", "danger"); message = "Starting date cannot be after the ending date."; model.addAttribute("message", message); model.addAttribute("timelogs", timeLogService.getTimeLogs()); return "timelog_list"; } for (TimeLog t : timeLogs) { if ((t.getLogin().after(beginDate)) && (t.getLogin().before(endDate))) { foundTimeLogs.add(t); } } model.addAttribute("timelogs", foundTimeLogs); if (foundTimeLogs.isEmpty()) { message = "No logs between \"" + fromDate + " and " + toDate + "\" were found"; model.addAttribute("type", "danger"); } else { String extraS = ""; String plural = "was"; if (foundTimeLogs.size() != 1) { extraS = "s"; plural = "were"; } message = foundTimeLogs.size() + " log" + extraS + " between \"" + fromDate + " and " + toDate + "\" " + plural + " found."; model.addAttribute("type", "success"); } model.addAttribute("pageTitle", "TimeLogs"); model.addAttribute("pageDescription", "All the logs that matched your search criteria."); model.addAttribute("message", message); return "timelog_list"; }
From source file:org.apache.ofbiz.entity.transaction.TransactionUtil.java
public static Timestamp getTransactionUniqueNowStamp() { Timestamp lastNowStamp = transactionLastNowStamp.get(); Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); // check for an overlap with the lastNowStamp, or if the lastNowStamp is in the future because of incrementing to make each stamp unique if (lastNowStamp != null && (lastNowStamp.equals(nowTimestamp) || lastNowStamp.after(nowTimestamp))) { nowTimestamp = new Timestamp(lastNowStamp.getTime() + 1); }/*w w w . j av a 2 s . c o m*/ transactionLastNowStamp.set(nowTimestamp); return nowTimestamp; }
From source file:no.trank.openpipe.jdbc.store.StateDocumentProducerTest.java
public void testUpdateModifiedDocuments() throws Exception { createValidTable();//from www .j av a 2s . com final Timestamp ts = new Timestamp(System.currentTimeMillis()); Thread.sleep(15); // So test will not fail on Windows jdbcTemplate.update( "INSERT INTO " + TABLE_NAME + " (" + COL_ID_NAME + ", " + COL_UPD_NAME + ") VALUES (?, ?)", DOC_ID, ts); // Setting up mock final Document doc = new Document(); doc.setFieldValue(FIELD_ID, DOC_ID); final DocumentProducer mockProd = setUpMockProducer(Arrays.asList(doc).iterator(), false); final StateDocumentProducer producer = setupProducer(mockProd); producer.init(); final Iterator<Document> it = producer.iterator(); assertTrue(it.hasNext()); assertEquals(DocumentOperation.MODIFY_VALUE, it.next().getOperation()); assertFalse(it.hasNext()); producer.close(); verify(mockProd); final String id = jdbcTemplate.queryForObject(getSelectId(), new StringRowMapper(), (Object[]) null); assertEquals(DOC_ID, id); final Timestamp upd = jdbcTemplate.queryForObject(getSelectUpd(), new TimestampRowMapper(), (Object[]) null); assertTrue(upd.after(ts)); }
From source file:DateUtils.java
/** * Method to compare time periods//w ww. j a va2 s. c o m * * @param iPeriodType1 - first period type, one of the period type constant * TIMING_XXX * @param iPeriodDuration1 - first period duration * @param iPeriodType2 - second period type, one of the period type constant * TIMING_XXX * @param iPeriodDuration2 - second period duration * @return int - 1 - first period is longer * 0 - periods are same * -1 - first period is shorter */ public static int comparePeriods(int iPeriodType1, int iPeriodDuration1, int iPeriodType2, int iPeriodDuration2) { int iReturn = 0; if ((iPeriodType1 != TIMING_NEVER) && (iPeriodType1 != TIMING_NONE) && (iPeriodType2 != TIMING_NEVER) && (iPeriodType2 != TIMING_NONE)) { Timestamp tsTimestamp1 = getPeriodExpiration(new Timestamp(0), iPeriodType1, iPeriodDuration1); Timestamp tsTimestamp2 = getPeriodExpiration(new Timestamp(0), iPeriodType2, iPeriodDuration2); // TODO: Improve: When would any of these be null? if ((tsTimestamp1 != null) && (tsTimestamp2 != null)) { if (tsTimestamp1.after(tsTimestamp2)) { iReturn = 1; } else if (tsTimestamp2.after(tsTimestamp1)) { iReturn = -1; } } } else { if (iPeriodType1 != iPeriodType2) { if (iPeriodType1 == TIMING_NEVER) { iReturn = 1; } else if (iPeriodType1 == TIMING_NONE) { iReturn = -1; } else if (iPeriodType2 == TIMING_NEVER) { iReturn = -1; } else if (iPeriodType2 == TIMING_NONE) { iReturn = 1; } } } return iReturn; }
From source file:org.openmicroscopy.shoola.agents.dataBrowser.DataFilter.java
/** * Filters the image by date. Returns <code>true</code> if the image is * in the interval, <code>false</code> otherwise. * /* w ww . j a v a 2 s. c o m*/ * @param image The image to handle. * @return See above. */ private boolean filterByDate(ImageData image) { Timestamp start = context.getFromDate(); Timestamp end = context.getToDate(); if (start == null && end == null) return true; Timestamp date; if (context.getTimeType() == SearchParameters.DATE_ACQUISITION) { date = image.getAcquisitionDate(); } else { date = image.getCreated(); } if (date == null) return false; if (start != null && end != null) { return date.after(start) && date.before(end); } if (start == null) { return date.before(end); } return date.after(start); }
From source file:org.etk.entity.engine.plugins.transaction.TransactionUtil.java
public static Timestamp getTransactionUniqueNowStamp() { Timestamp lastNowStamp = transactionLastNowStamp.get(); Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); // check for an overlap with the lastNowStamp, or if the lastNowStamp is in // the future because of incrementing to make each stamp unique if (lastNowStamp != null && (lastNowStamp.equals(nowTimestamp) || lastNowStamp.after(nowTimestamp))) { nowTimestamp = new Timestamp(lastNowStamp.getTime() + 1); }/*from ww w.jav a2 s . c om*/ transactionLastNowStamp.set(nowTimestamp); return nowTimestamp; }
From source file:org.kuali.rice.kew.notes.web.NoteAction.java
private List<Note> sortNotes(List<Note> allNotes, String sortOrder) { final int returnCode = KewApiConstants.Sorting.SORT_SEQUENCE_DSC.equalsIgnoreCase(sortOrder) ? -1 : 1; try {//from ww w. ja v a 2 s. c o m Collections.sort(allNotes, new Comparator<Note>() { @Override public int compare(Note o1, Note o2) { Timestamp date1 = o1.getNoteCreateDate(); Timestamp date2 = o2.getNoteCreateDate(); if (date1.before(date2)) { return returnCode * -1; } else if (date1.after(date2)) { return returnCode; } else { return 0; } } }); } catch (Throwable e) { LOG.error(e.getMessage(), e); } return allNotes; }
From source file:org.apache.ofbiz.base.util.UtilValidate.java
public static boolean isDateAfterNow(Timestamp date) { Timestamp now = UtilDateTime.nowTimestamp(); if (date != null) { return date.after(now); } else {/*from www .j a v a2s. c om*/ return false; } }