*
* @param values A list with the values that the scalar function is performed on them.
* @return A date value with the appropriate date.
*/
public Value evaluate(List<Value> values) {
Value value = values.get(0);
Date date;
GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
// If the given value is null, return a null date value.
if(value.isNull()) {
return DateValue.getNullValue();
}
DateValue dateValue;
switch(value.getType()) {
case DATE:
dateValue = (DateValue) value;
break;
case DATETIME:
dateValue = new DateValue((GregorianCalendar)
(((DateTimeValue) value).getObjectToFormat()));
break;
case NUMBER:
date = new Date((long) ((NumberValue) value).getValue());
gc.setTime(date);
dateValue = new DateValue(gc);
break;
default:// Should never get here.
throw new RuntimeException("Value type was not found: " + value.getType());
}
return dateValue;
}