mirror of https://github.com/apache/poi.git
[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:
parent
16a1e36018
commit
3a6b91dd1f
|
@ -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)));
|
||||||
|
|
|
@ -48,46 +48,46 @@ final class TestDateValue {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDateValue() {
|
void testDateValue() {
|
||||||
LocaleUtil.setUserLocale(Locale.ENGLISH);
|
int days1900 = (int)ChronoUnit.DAYS.between(
|
||||||
try {
|
LocalDate.of(1899, Month.DECEMBER, 31),
|
||||||
int days1900 = (int)ChronoUnit.DAYS.between(
|
LocalDate.of(Year.now(LocaleUtil.getUserTimeZone().toZoneId()).getValue(), Month.FEBRUARY, 1)
|
||||||
LocalDate.of(1899, Month.DECEMBER, 31),
|
)+1;
|
||||||
LocalDate.of(Year.now(LocaleUtil.getUserTimeZone().toZoneId()).getValue(), Month.FEBRUARY, 1)
|
confirmDateValue(new StringEval("2020-02-01"), 43862);
|
||||||
)+1;
|
confirmDateValue(new StringEval("01-02-2020"), 43862);
|
||||||
confirmDateValue(new StringEval("2020-02-01"), 43862);
|
confirmDateValue(new StringEval("2020-FEB-01"), 43862);
|
||||||
confirmDateValue(new StringEval("01-02-2020"), 43862);
|
confirmDateValue(new StringEval("2020-Feb-01"), 43862);
|
||||||
confirmDateValue(new StringEval("2020-FEB-01"), 43862);
|
confirmDateValue(new StringEval("2020-FEBRUARY-01"), 43862);
|
||||||
confirmDateValue(new StringEval("2020-Feb-01"), 43862);
|
confirmDateValue(new StringEval("FEB-01"), days1900);
|
||||||
confirmDateValue(new StringEval("2020-FEBRUARY-01"), 43862);
|
confirmDateValue(new StringEval("2/1/2020"), 43862);
|
||||||
confirmDateValue(new StringEval("FEB-01"), days1900);
|
confirmDateValue(new StringEval("2/1"), days1900);
|
||||||
confirmDateValue(new StringEval("2/1/2020"), 43862);
|
confirmDateValue(new StringEval("2020/2/1"), 43862);
|
||||||
confirmDateValue(new StringEval("2/1"), days1900);
|
confirmDateValue(new StringEval("2020/FEB/1"), 43862);
|
||||||
confirmDateValue(new StringEval("2020/2/1"), 43862);
|
confirmDateValue(new StringEval("FEB/1/2020"), 43862);
|
||||||
confirmDateValue(new StringEval("2020/FEB/1"), 43862);
|
confirmDateValue(new StringEval("2020/02/01"), 43862);
|
||||||
confirmDateValue(new StringEval("FEB/1/2020"), 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("non-date text"));
|
||||||
|
confirmDateValueError(new StringEval("2/32/2020"));
|
||||||
|
confirmDateValueError(new StringEval("32/2/2020"));
|
||||||
|
confirmDateValueError(new StringEval("32/32/2020"));
|
||||||
|
|
||||||
// // EXCEL
|
confirmDateValueError(new StringEval("non-date text"));
|
||||||
confirmDateValue(new StringEval("8/22/2011"), 40777); // Serial number of a date entered as text.
|
|
||||||
confirmDateValue(new StringEval("22-MAY-2011"), 40685); // Serial number of a date entered as text.
|
|
||||||
confirmDateValue(new StringEval("2011/02/23"), 40597); // Serial number of a date entered as text.
|
|
||||||
|
|
||||||
//ignore time parts
|
// // EXCEL
|
||||||
confirmDateValue(new StringEval("8/22/2011 12:00"), 40777); // Serial number of a date entered as text.
|
confirmDateValue(new StringEval("8/22/2011"), 40777); // Serial number of a date entered as text.
|
||||||
confirmDateValue(new StringEval("8/22/2011 6:02:23 PM"), 40777); // Serial number of a date entered as text.
|
confirmDateValue(new StringEval("22-MAY-2011"), 40685); // Serial number of a date entered as text.
|
||||||
confirmDateValue(new StringEval("22-AUG-2011 6:02:23PM"), 40777); // Serial number of a date entered as text.
|
confirmDateValue(new StringEval("2011/02/23"), 40597); // Serial number of a date entered as text.
|
||||||
confirmDateValue(new StringEval("22-AUG-2011 6:02:23AM"), 40777); // Serial number of a date entered as text.
|
|
||||||
|
|
||||||
// LibreOffice compatibility
|
//ignore time parts
|
||||||
confirmDateValue(new StringEval("1954-07-20"), 19925);
|
confirmDateValue(new StringEval("8/22/2011 12:00"), 40777); // Serial number of a date entered as text.
|
||||||
} finally {
|
confirmDateValue(new StringEval("8/22/2011 6:02:23 PM"), 40777); // Serial number of a date entered as text.
|
||||||
LocaleUtil.setUserLocale(null);
|
confirmDateValue(new StringEval("22-AUG-2011 6:02:23PM"), 40777); // Serial number of a date entered as text.
|
||||||
}
|
confirmDateValue(new StringEval("22-AUG-2011 6:02:23AM"), 40777); // Serial number of a date entered as text.
|
||||||
|
|
||||||
|
// LibreOffice compatibility
|
||||||
|
confirmDateValue(new StringEval("1954-07-20"), 19925);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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());
|
||||||
|
|
Loading…
Reference in New Issue