val(new Date(0)).add(new YearToMonth(1, 6)).as("d3"),
dateAdd(new Date(0), new YearToMonth(1, 6)).as("d3a"),
val(new Date(0)).add(new YearToMonth(1, 6).neg()).as("d4a"),
val(new Date(0)).sub(new YearToMonth(1, 6)).as("d4b"),
val(new Date(0)).add(new DayToSecond(2)).as("d5"),
dateAdd(new Date(0), new DayToSecond(2)).as("d5a"),
val(new Date(0)).add(new DayToSecond(2).neg()).as("d6a"),
val(new Date(0)).sub(new DayToSecond(2)).as("d6b"),
val(new Timestamp(0)).add(1).as("ts1"),
timestampAdd(new Timestamp(0), 1).as("ts1a"),
val(new Timestamp(0)).add(-1).as("ts2a"),
val(new Timestamp(0)).sub(1).as("ts2b"),
val(new Timestamp(0)).add(new YearToMonth(1, 6)).as("ts3"),
timestampAdd(new Timestamp(0), new YearToMonth(1, 6)).as("ts3a"),
val(new Timestamp(0)).add(new YearToMonth(1, 6).neg()).as("ts4a"),
val(new Timestamp(0)).sub(new YearToMonth(1, 6)).as("ts4b"),
val(new Timestamp(0)).add(new DayToSecond(2)).as("ts5"),
timestampAdd(new Timestamp(0), new DayToSecond(2)).as("ts5a"),
val(new Timestamp(0)).add(new DayToSecond(2).neg()).as("ts6a"),
val(new Timestamp(0)).sub(new DayToSecond(2)).as("ts6b"),
val(new Timestamp(0)).add(new DayToSecond(2, 6)).as("ts7"),
val(new Timestamp(0)).add(new DayToSecond(2, 6).neg()).as("ts8a"),
val(new Timestamp(0)).sub(new DayToSecond(2, 6)).as("ts8b"),
// Dummy field for simpler testing
inline("dummy")
).fetchOne();
Calendar cal;
cal = cal();
cal.add(Calendar.DATE, 1);
assertEquals(new Date(cal.getTimeInMillis()), record.getValue("d1"));
assertEquals(new Date(cal.getTimeInMillis()), record.getValue("d1a"));
assertEquals(new Timestamp(cal.getTimeInMillis() - tsShift), record.getValue("ts1"));
assertEquals(new Timestamp(cal.getTimeInMillis() - tsShift), record.getValue("ts1a"));
cal = cal();
cal.add(Calendar.DATE, -1);
assertEquals(new Date(cal.getTimeInMillis()), record.getValue("d2a"));
assertEquals(new Date(cal.getTimeInMillis()), record.getValue("d2b"));
assertEquals(new Timestamp(cal.getTimeInMillis() - tsShift), record.getValue("ts2a"));
assertEquals(new Timestamp(cal.getTimeInMillis() - tsShift), record.getValue("ts2b"));
cal = cal();
cal.add(Calendar.MONTH, 18);
assertEquals(new Date(cal.getTimeInMillis()), record.getValue("d3"));
assertEquals(new Date(cal.getTimeInMillis()), record.getValue("d3a"));
assertEquals(new Timestamp(cal.getTimeInMillis() - tsShift), record.getValue("ts3"));
assertEquals(new Timestamp(cal.getTimeInMillis() - tsShift), record.getValue("ts3a"));
cal = cal();
cal.add(Calendar.MONTH, -18);
assertEquals(new Date(cal.getTimeInMillis()), record.getValue("d4a"));
assertEquals(new Date(cal.getTimeInMillis()), record.getValue("d4b"));
assertEquals(new Timestamp(cal.getTimeInMillis() - tsShift), record.getValue("ts4a"));
assertEquals(new Timestamp(cal.getTimeInMillis() - tsShift), record.getValue("ts4b"));
cal = cal();
cal.add(Calendar.DATE, 2);
assertEquals(new Date(cal.getTimeInMillis()), record.getValue("d5"));
assertEquals(new Date(cal.getTimeInMillis()), record.getValue("d5a"));
assertEquals(new Timestamp(cal.getTimeInMillis() - tsShift), record.getValue("ts5"));
assertEquals(new Timestamp(cal.getTimeInMillis() - tsShift), record.getValue("ts5a"));
cal = cal();
cal.add(Calendar.DATE, -2);
assertEquals(new Date(cal.getTimeInMillis()), record.getValue("d6a"));
assertEquals(new Date(cal.getTimeInMillis()), record.getValue("d6b"));
assertEquals(new Timestamp(cal.getTimeInMillis() - tsShift), record.getValue("ts6a"));
assertEquals(new Timestamp(cal.getTimeInMillis() - tsShift), record.getValue("ts6b"));
cal = cal();
cal.add(Calendar.DATE, 2);
cal.add(Calendar.HOUR, 6);
assertEquals(new Timestamp(cal.getTimeInMillis() - tsShift), record.getValue("ts7"));
cal = cal();
cal.add(Calendar.DATE, -2);
cal.add(Calendar.HOUR, -6);
assertEquals(new Timestamp(cal.getTimeInMillis() - tsShift), record.getValue("ts8a"));
assertEquals(new Timestamp(cal.getTimeInMillis() - tsShift), record.getValue("ts8b"));
// [#566] INTERVAL arithmetic: difference
// --------------------------------------
record =
create().select(
dateDiff(new Date(0), new Date(30 * 60 * 60 * 1000L)).as("d1"),
dateDiff(new Date(30 * 60 * 60 * 1000L), new Date(0)).as("d2"),
timestampDiff(new Timestamp(0), new Timestamp(30 * 60 * 60 * 1000L)).as("ts1"),
timestampDiff(new Timestamp(30 * 60 * 60 * 1000L), new Timestamp(0)).as("ts2"),
// Dummy field for simpler testing
inline("dummy")
).fetchOne();
assertEquals(-1, record.getValue("d1"));
assertEquals(1, record.getValue("d2"));
assertEquals(new DayToSecond(1, 6).neg(), record.getValue("ts1"));
assertEquals(new DayToSecond(1, 6), record.getValue("ts2"));
// [#470] TRUNC function
record =
create().select(
trunc(new Date(1000)).as("d1"),