mirror of https://github.com/apache/poi.git
Prevent some unit-tests from failing when non-English local is used in Maven run
Also improve the error message when parsing the date fails. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1882825 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
90bfac52d6
commit
b6960fbe54
|
@ -18,6 +18,7 @@
|
|||
package org.apache.poi.ss.util;
|
||||
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.time.DateTimeException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
@ -83,7 +84,7 @@ public class DateParser {
|
|||
|
||||
/**
|
||||
* Parses a date from a string.
|
||||
*
|
||||
*
|
||||
* @param strVal a string with a date pattern.
|
||||
* @return a date parsed from argument.
|
||||
* @throws EvaluationException exception upon parsing.
|
||||
|
@ -102,7 +103,11 @@ public class DateParser {
|
|||
: LocalDate.now(LocaleUtil.getUserTimeZone().toZoneId()).getYear();
|
||||
int month = parseMonth(groups.get(format.monthIndex));
|
||||
int day = Integer.parseInt(groups.get(format.dayIndex));
|
||||
return LocalDate.of(year, month, day);
|
||||
try {
|
||||
return LocalDate.of(year, month, day);
|
||||
} catch (DateTimeException e) {
|
||||
throw new DateTimeException("Failed to parse date-string " + strVal);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2902,7 +2902,12 @@ public final class TestBugs extends BaseTestBugzillaIssues {
|
|||
}
|
||||
@Test
|
||||
public void test63819() throws IOException {
|
||||
simpleTest("63819.xls");
|
||||
LocaleUtil.setUserLocale(Locale.UK);
|
||||
try {
|
||||
simpleTest("63819.xls");
|
||||
} finally {
|
||||
LocaleUtil.resetUserLocale();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2961,8 +2966,12 @@ public final class TestBugs extends BaseTestBugzillaIssues {
|
|||
evals.add(wb.getCreationHelper().createFormulaEvaluator());
|
||||
evals.addAll(SIMPLE_REFS.values());
|
||||
|
||||
HSSFFormulaEvaluator.setupEnvironment( files.toArray(new String[0]), evals.toArray(new HSSFFormulaEvaluator[0]) );
|
||||
evals.get(0).evaluateAll();
|
||||
try {
|
||||
HSSFFormulaEvaluator.setupEnvironment(files.toArray(new String[0]), evals.toArray(new HSSFFormulaEvaluator[0]));
|
||||
evals.get(0).evaluateAll();
|
||||
} catch (RuntimeException e) {
|
||||
throw new RuntimeException("While handling files " + files + " and evals " + evals, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -50,31 +50,36 @@ public final class TestDateValue {
|
|||
|
||||
@Test
|
||||
public void testDateValue() {
|
||||
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"), 43862);
|
||||
confirmDateValue(new StringEval("2/1/2020"), 43862);
|
||||
confirmDateValue(new StringEval("2/1"), 43862);
|
||||
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);
|
||||
LocaleUtil.setUserLocale(Locale.ENGLISH);
|
||||
try {
|
||||
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"), 43862);
|
||||
confirmDateValue(new StringEval("2/1/2020"), 43862);
|
||||
confirmDateValue(new StringEval("2/1"), 43862);
|
||||
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);
|
||||
confirmDateValue(new StringEval(""));
|
||||
confirmDateValue(BlankEval.instance);
|
||||
|
||||
confirmDateValueError(new StringEval("non-date text"));
|
||||
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.
|
||||
// // 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.
|
||||
|
||||
// LibreOffice compatibility
|
||||
confirmDateValue(new StringEval("1954-07-20"), 19925);
|
||||
// LibreOffice compatibility
|
||||
confirmDateValue(new StringEval("1954-07-20"), 19925);
|
||||
} finally {
|
||||
LocaleUtil.setUserLocale(null);
|
||||
}
|
||||
}
|
||||
|
||||
private ValueEval invokeDateValue(ValueEval text) {
|
||||
|
@ -97,4 +102,4 @@ public final class TestDateValue {
|
|||
assertEquals(ErrorEval.class, result.getClass());
|
||||
assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), ((ErrorEval) result).getErrorCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue