https://bz.apache.org/bugzilla/show_bug.cgi?id=63819
Bug ID: 63819
Summary: Spreadsheet DATEVALUE function missing
Product: POI
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P2
Component: SS Common
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
Please implement function DATEVALUE
https://support.office.com/en-us/article/DATEVALUE-function-DF8B07D4-7761-4A93-BC33-B7471BBFF252
https://help.libreoffice.org/Calc/DATEVALUE
It could by done like this: (adding sublass class in
org.apache.poi.ss.formula.functions.DateFunc)
public final class DateFunc extends Fixed3ArgFunction {
....
public static final Function DATEVALUE = new Fixed1ArgFunction() {
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex,
ValueEval arg0) {
try {
ValueEval ve = OperandResolver.getSingleValue(arg0,
srcRowIndex, srcColumnIndex);
String arg = OperandResolver.coerceValueToString(ve);
StringTokenizer t = new StringTokenizer(arg, "-/");
String A = t.nextToken();
String B = t.nextToken();
String C = t.hasMoreTokens() ? t.nextToken() : null;
if (B.length() > 3) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
int year;
int month;
int day;
int a = Integer.valueOf(A);
if (StringUtils.isNumeric(B)) {
int b = Integer.valueOf(B);
int c = Integer.valueOf(C);
month = b;
if (a >= 1900) { // =DATEVALUE("2011/02/23")
year = a;
day = c;
} else { // =DATEVALUE("8/22/2011")
year = c;
day = a;
}
} else {
String monthName = B.toLowerCase();
String months[] = new DateFormatSymbols().getMonths();
for (month = 0; month < 12; month++) {
if (months[month].startsWith(monthName)) {
break;
}
}
if (month >= 12) {
throw new
EvaluationException(ErrorEval.VALUE_INVALID);
}
month++;
if (C == null) {
// =DATEVALUE("22-MAY")
GregorianCalendar gc = new GregorianCalendar();
year = gc.get(Calendar.YEAR);
day = a;
} else {
// =DATEVALUE("22-MAY-2011")
year = Integer.valueOf(C);
day = a;
}
}
return new NumberEval(evaluate(year, month, day));
} catch (EvaluationException e) {
return e.getErrorEval();
}
}
};
...
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]