com.googlecode.mjorm.mql.functions.DateVariableFunction Maven / Gradle / Ivy
package com.googlecode.mjorm.mql.functions;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.googlecode.mjorm.mql.AbstractMqlVariableFunction;
import com.googlecode.mjorm.mql.MqlException;
public abstract class DateVariableFunction
extends AbstractMqlVariableFunction {
public static final String[] DATE_TIME_FORMATS = {
"yyyy-MM-dd HH:mm:ss,S z",
"yyyy-MM-dd HH:mm:ss,S",
"yyyy-MM-dd HH:mm:ss z",
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd z",
"yyyy-MM-dd",
};
public static final DateVariableFunction INSTANCE = DateVariableFunction.createFunction("date", DATE_TIME_FORMATS);
public static DateVariableFunction createFunction(final String name, final String... formats) {
return new DateVariableFunction() {
@Override
protected void init() {
setFunctionName(name);
setExactArgs(1);
setFormats(formats);
}
};
}
private SimpleDateFormat[] formats;
protected void setFormats(String[] formats) {
assertNotInitialized();
this.formats = new SimpleDateFormat[formats.length];
for (int i=0; i