aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2023-09-14 14:13:22 +0000
committerPJ Fanning <fanningpj@apache.org>2023-09-14 14:13:22 +0000
commit3a6b91dd1fb7d0255711cca771a38b3c31c850e7 (patch)
tree3258787bf8b214320571a0d9617ba3e953e04cb0 /poi
parent16a1e360187b967c703d8621ef69703a5cb73b94 (diff)
downloadpoi-3a6b91dd1fb7d0255711cca771a38b3c31c850e7.tar.gz
poi-3a6b91dd1fb7d0255711cca771a38b3c31c850e7.zip
[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
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/ss/formula/functions/DateValue.java2
-rw-r--r--poi/src/test/java/org/apache/poi/ss/formula/functions/TestDateValue.java85
2 files changed, 41 insertions, 46 deletions
diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/DateValue.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/DateValue.java
index 18caf0da0e..235beedd3a 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/functions/DateValue.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/DateValue.java
@@ -54,7 +54,7 @@ public class DateValue extends Fixed1ArgFunction {
OperandResolver.getSingleValue(dateTextArg, srcRowIndex, srcColumnIndex));
if (dateText == null || dateText.isEmpty()) {
- return BlankEval.instance;
+ return ErrorEval.VALUE_INVALID;
}
return new NumberEval(DateUtil.getExcelDate(DateParser.parseLocalDate(dateText)));
diff --git a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestDateValue.java b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestDateValue.java
index a36a714d14..c20162ea0d 100644
--- a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestDateValue.java
+++ b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestDateValue.java
@@ -48,46 +48,46 @@ final class TestDateValue {
@Test
void testDateValue() {
- LocaleUtil.setUserLocale(Locale.ENGLISH);
- try {
- int days1900 = (int)ChronoUnit.DAYS.between(
- LocalDate.of(1899, Month.DECEMBER, 31),
- LocalDate.of(Year.now(LocaleUtil.getUserTimeZone().toZoneId()).getValue(), Month.FEBRUARY, 1)
- )+1;
- confirmDateValue(new StringEval("2020-02-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("FEB-01"), days1900);
- confirmDateValue(new StringEval("2/1/2020"), 43862);
- confirmDateValue(new StringEval("2/1"), days1900);
- confirmDateValue(new StringEval("2020/2/1"), 43862);
- confirmDateValue(new StringEval("2020/FEB/1"), 43862);
- confirmDateValue(new StringEval("FEB/1/2020"), 43862);
- confirmDateValue(new StringEval("2020/02/01"), 43862);
-
- confirmDateValue(new StringEval(""));
- confirmDateValue(BlankEval.instance);
-
- confirmDateValueError(new StringEval("non-date text"));
-
- // // EXCEL
- 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
- confirmDateValue(new StringEval("8/22/2011 12:00"), 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-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);
- } finally {
- LocaleUtil.setUserLocale(null);
- }
+ int days1900 = (int)ChronoUnit.DAYS.between(
+ LocalDate.of(1899, Month.DECEMBER, 31),
+ LocalDate.of(Year.now(LocaleUtil.getUserTimeZone().toZoneId()).getValue(), Month.FEBRUARY, 1)
+ )+1;
+ confirmDateValue(new StringEval("2020-02-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("FEB-01"), days1900);
+ confirmDateValue(new StringEval("2/1/2020"), 43862);
+ confirmDateValue(new StringEval("2/1"), days1900);
+ confirmDateValue(new StringEval("2020/2/1"), 43862);
+ confirmDateValue(new StringEval("2020/FEB/1"), 43862);
+ confirmDateValue(new StringEval("FEB/1/2020"), 43862);
+ confirmDateValue(new StringEval("2020/02/01"), 43862);
+
+ confirmDateValueError(new StringEval(""));
+ 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"));
+
+ // // EXCEL
+ 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
+ confirmDateValue(new StringEval("8/22/2011 12:00"), 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-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
@@ -110,11 +110,6 @@ final class TestDateValue {
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) {
ValueEval result = invokeDateValue(text);
assertEquals(ErrorEval.class, result.getClass());