[bug-67402] DATEVALUE function should return #VALUE! for a null or empty string argument. Thanks to Jakub Vojtisek.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1912313 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2023-09-14 14:13:22 +00:00
parent 16a1e36018
commit 3a6b91dd1f
2 changed files with 36 additions and 41 deletions

View File

@ -54,7 +54,7 @@ public class DateValue extends Fixed1ArgFunction {
OperandResolver.getSingleValue(dateTextArg, srcRowIndex, srcColumnIndex)); OperandResolver.getSingleValue(dateTextArg, srcRowIndex, srcColumnIndex));
if (dateText == null || dateText.isEmpty()) { if (dateText == null || dateText.isEmpty()) {
return BlankEval.instance; return ErrorEval.VALUE_INVALID;
} }
return new NumberEval(DateUtil.getExcelDate(DateParser.parseLocalDate(dateText))); return new NumberEval(DateUtil.getExcelDate(DateParser.parseLocalDate(dateText)));

View File

@ -48,8 +48,6 @@ final class TestDateValue {
@Test @Test
void testDateValue() { void testDateValue() {
LocaleUtil.setUserLocale(Locale.ENGLISH);
try {
int days1900 = (int)ChronoUnit.DAYS.between( int days1900 = (int)ChronoUnit.DAYS.between(
LocalDate.of(1899, Month.DECEMBER, 31), LocalDate.of(1899, Month.DECEMBER, 31),
LocalDate.of(Year.now(LocaleUtil.getUserTimeZone().toZoneId()).getValue(), Month.FEBRUARY, 1) LocalDate.of(Year.now(LocaleUtil.getUserTimeZone().toZoneId()).getValue(), Month.FEBRUARY, 1)
@ -67,8 +65,13 @@ final class TestDateValue {
confirmDateValue(new StringEval("FEB/1/2020"), 43862); confirmDateValue(new StringEval("FEB/1/2020"), 43862);
confirmDateValue(new StringEval("2020/02/01"), 43862); confirmDateValue(new StringEval("2020/02/01"), 43862);
confirmDateValue(new StringEval("")); confirmDateValueError(new StringEval(""));
confirmDateValue(BlankEval.instance); confirmDateValueError(BlankEval.instance);
confirmDateValueError(new StringEval("non-date text"));
confirmDateValueError(new StringEval("2/32/2020"));
confirmDateValueError(new StringEval("32/2/2020"));
confirmDateValueError(new StringEval("32/32/2020"));
confirmDateValueError(new StringEval("non-date text")); confirmDateValueError(new StringEval("non-date text"));
@ -85,9 +88,6 @@ final class TestDateValue {
// LibreOffice compatibility // LibreOffice compatibility
confirmDateValue(new StringEval("1954-07-20"), 19925); confirmDateValue(new StringEval("1954-07-20"), 19925);
} finally {
LocaleUtil.setUserLocale(null);
}
} }
@Test @Test
@ -110,11 +110,6 @@ final class TestDateValue {
assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.0001); assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.0001);
} }
private void confirmDateValue(ValueEval text) {
ValueEval result = invokeDateValue(text);
assertEquals(BlankEval.class, result.getClass());
}
private void confirmDateValueError(ValueEval text) { private void confirmDateValueError(ValueEval text) {
ValueEval result = invokeDateValue(text); ValueEval result = invokeDateValue(text);
assertEquals(ErrorEval.class, result.getClass()); assertEquals(ErrorEval.class, result.getClass());