public void dateTimeEqualsIgnoreTimeTest() {
StringBuilder sb = new StringBuilder();
View threads = null;
Document firstDoc = null;
Document secondDoc = null;
DateTime firstDate = null;
DateTime secondDate = null;
try {
Session s = ExtLibUtil.getCurrentSession();
Database currDb = s.getCurrentDatabase();
threads = currDb.getView("AllThreads");
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(100);
firstDoc = threads.getNthDocument(randomInt);
randomInt = randomGenerator.nextInt(100);
secondDoc = threads.getNthDocument(randomInt);
String firstDt = firstDoc.getFirstItem("Date").getText();
String secondDt = secondDoc.getFirstItem("Date").getText();
firstDate = s.createDateTime(firstDt);
secondDate = s.createDateTime(secondDt);
Calendar c1 = GregorianCalendar.getInstance();
Calendar c2 = GregorianCalendar.getInstance();
c1.setTime(firstDate.toJavaDate());
c1.set(Calendar.HOUR_OF_DAY, 0);
c1.set(Calendar.MINUTE, 0);
c1.set(Calendar.SECOND, 0);
c1.set(Calendar.MILLISECOND, 0);
c2.setTime(secondDate.toJavaDate());
c2.set(Calendar.HOUR_OF_DAY, 0);
c2.set(Calendar.MINUTE, 0);
c2.set(Calendar.SECOND, 0);
c2.set(Calendar.MILLISECOND, 0);
sb.append("Comparing " + firstDt + " (" + firstDoc.getUniversalID() + ") with " + secondDt + " ("
+ secondDoc.getUniversalID() + ")...");
if (c1.equals(c2)) {
sb.append("first is the same date as second");
} else {
sb.append("first is NOT the same date as second");
}
} catch (NotesException e) {
// doSomething
} finally {
try {
threads.recycle();
firstDoc.recycle();
secondDoc.recycle();
firstDate.recycle();
secondDate.recycle();
} catch (NotesException e) {
// doSomething
}
}
ExtLibUtil.getViewScope().put("oldJavaTest", sb.toString());