public TypeValuePair evaluate(final FormulaContext context,
final ParameterCallback parameters) throws EvaluationException
{
if (parameters.getParameterCount() > 2)
{
throw new EvaluationException(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
}
final TypeRegistry typeRegistry = context.getTypeRegistry();
final Date d = typeRegistry.convertToDate(parameters.getType(0), parameters
.getValue(0));
int type = 1; // default is Type 1
if (parameters.getParameterCount() == 2)
{
final Number n = typeRegistry.convertToNumber(parameters.getType(1),
parameters.getValue(1));
if (n == null)
{
throw new EvaluationException(
LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
}
type = n.intValue();
if (type < 1 || type > 3)
{
throw new EvaluationException(
LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
}
}
if (d == null)
{
throw new EvaluationException(
LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
}
final Calendar gc = DateUtil.createCalendar(d, context
.getLocalizationContext());