public Collection<Predicate> dateTime(DateTimeExpression<java.util.Date> expr, DateTimeExpression<java.util.Date> other) { HashSet<Predicate> rv = new HashSet<Predicate>(); rv.addAll(comparable(expr, other)); rv.add(expr.milliSecond().eq(other.milliSecond())); rv.add(expr.second().eq(other.second())); rv.add(expr.minute().eq(other.minute())); rv.add(expr.hour().eq(other.hour())); rv.add(expr.dayOfMonth().eq(other.dayOfMonth())); if (!target.equals(Target.DERBY) && !module.equals(Module.JDO) && !target.equals(Target.ORACLE) && (!target.equals(Target.POSTGRESQL) || !module.equals(Module.JPA))) { rv.add(expr.dayOfWeek().eq(other.dayOfWeek())); rv.add(expr.dayOfYear().eq(other.dayOfYear())); if (!target.equals(Target.SQLSERVER) && !target.equals(Target.MYSQL) && !target.equals(Target.CUBRID) && !target.equals(Target.POSTGRESQL) && !target.equals(Target.HSQLDB)) { rv.add(expr.week().eq(other.week())); } } rv.add(expr.month().eq(other.month())); rv.add(expr.year().eq(other.year())); rv.add(expr.yearMonth().eq(other.yearMonth())); return ImmutableList.copyOf(rv); }
@Test public void test() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.MONTH, 0); cal.set(Calendar.YEAR, 2000); cal.set(Calendar.HOUR_OF_DAY, 13); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 12); cal.set(Calendar.MILLISECOND, 3); DateTimeExpression<Date> date = DateTimeConstant.create(cal.getTime()); assertEquals("1", date.dayOfMonth().toString()); assertEquals("1", date.month().toString()); assertEquals("2000", date.year().toString()); assertEquals("7", date.dayOfWeek().toString()); assertEquals("1", date.dayOfYear().toString()); assertEquals("13", date.hour().toString()); assertEquals("30", date.minute().toString()); assertEquals("12", date.second().toString()); assertEquals("3", date.milliSecond().toString()); }