}
});
+ public static final Function DATEADD = registerFunc(new Func3("DateAdd") {
+ @Override
+ protected Value eval3(EvalContext ctx,
+ Value param1, Value param2, Value param3) {
+ if(param3.isNull()) {
+ return ValueSupport.NULL_VAL;
+ }
+
+ String intv = param1.getAsString(ctx).trim();
+ int val = param2.getAsLongInt(ctx);
+
+ int result = -1;
+ Calendar cal = nonNullToCalendar(ctx, param3);
+
+ // FIXME
+ if(intv.equalsIgnoreCase(INTV_YEAR)) {
+ cal.add(Calendar.YEAR, val);
+ } else if(intv.equalsIgnoreCase(INTV_QUARTER)) {
+ cal.add(Calendar.MONTH, val * 3);
+ } else if(intv.equalsIgnoreCase(INTV_MONTH)) {
+ cal.add(Calendar.MONTH, val);
+ } else if(intv.equalsIgnoreCase(INTV_DAY_OF_YEAR)) {
+ cal.add(Calendar.DAY_OF_YEAR, val);
+ } else if(intv.equalsIgnoreCase(INTV_DAY)) {
+ cal.add(Calendar.DAY_OF_YEAR, val);
+ } else if(intv.equalsIgnoreCase(INTV_WEEKDAY)) {
+ cal.add(Calendar.DAY_OF_WEEK, val);
+ } else if(intv.equalsIgnoreCase(INTV_WEEK)) {
+ cal.add(Calendar.WEEK_OF_YEAR, val);
+ } else if(intv.equalsIgnoreCase(INTV_HOUR)) {
+ cal.add(Calendar.HOUR, val);
+ } else if(intv.equalsIgnoreCase(INTV_MINUTE)) {
+ cal.add(Calendar.MINUTE, val);
+ } else if(intv.equalsIgnoreCase(INTV_SECOND)) {
+ cal.add(Calendar.SECOND, val);
+ } else {
+ throw new EvalException("Invalid interval " + intv);
+ }
+
+ return ValueSupport.toValue(cal);
+ }
+ });
+
public static final Function NOW = registerFunc(new Func0("Now") {
@Override
protected Value eval0(EvalContext ctx) {
import java.math.BigDecimal;
import java.text.DateFormat;
+import java.util.Calendar;
import java.util.Date;
-import com.healthmarketscience.jackcess.expr.LocaleContext;
import com.healthmarketscience.jackcess.expr.EvalException;
+import com.healthmarketscience.jackcess.expr.LocaleContext;
import com.healthmarketscience.jackcess.expr.Value;
import com.healthmarketscience.jackcess.impl.ColumnImpl;
ColumnImpl.fromDateDouble(dd, ctx.getCalendar())));
}
+ public static Value toValue(Calendar cal) {
+ boolean hasTime = ((cal.get(Calendar.HOUR) != 0) ||
+ (cal.get(Calendar.MINUTE) != 0) ||
+ (cal.get(Calendar.SECOND) == 0));
+
+ boolean hasDate =
+ ((cal.get(Calendar.YEAR) != ExpressionTokenizer.BASE_DATE_YEAR) ||
+ ((cal.get(Calendar.MONTH) + 1) != ExpressionTokenizer.BASE_DATE_MONTH) ||
+ (cal.get(Calendar.DAY_OF_MONTH) == ExpressionTokenizer.BASE_DATE_DAY));
+
+ Value.Type type = (hasDate ?
+ (hasTime ? Value.Type.DATE_TIME : Value.Type.DATE) :
+ Value.Type.TIME);
+
+ return new DateTimeValue(type, cal.getTime());
+ }
+
public static Value toValue(Value.Type type, Date d) {
return new DateTimeValue(type, d);
}