diff options
author | Dominik Stadler <centic@apache.org> | 2020-10-25 07:21:34 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2020-10-25 07:21:34 +0000 |
commit | b6960fbe549cf8078fa8c166ab475c07dc32fce3 (patch) | |
tree | 4bcfa2849b5de5abbc47f9842c8a8becfa4911a8 /src/java | |
parent | 90bfac52d607c6a8499bfefe17d12d74253e5b7a (diff) | |
download | poi-b6960fbe549cf8078fa8c166ab475c07dc32fce3.tar.gz poi-b6960fbe549cf8078fa8c166ab475c07dc32fce3.zip |
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
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/org/apache/poi/ss/util/DateParser.java | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/java/org/apache/poi/ss/util/DateParser.java b/src/java/org/apache/poi/ss/util/DateParser.java index 292630006d..996a1384f1 100644 --- a/src/java/org/apache/poi/ss/util/DateParser.java +++ b/src/java/org/apache/poi/ss/util/DateParser.java @@ -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); + } } } |