aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2020-12-24 18:42:29 +0000
committerAndreas Beeker <kiwiwings@apache.org>2020-12-24 18:42:29 +0000
commita0fa9e19b1196bc10034f15474d27ce23bf5865a (patch)
tree499c1eb427ebff72f7e447d13dd1de1552df8146 /src/java/org
parentfb012041e8dd788637e68737199bc313b3e90098 (diff)
downloadpoi-a0fa9e19b1196bc10034f15474d27ce23bf5865a.tar.gz
poi-a0fa9e19b1196bc10034f15474d27ce23bf5865a.zip
#65026 - Migrate tests to Junit 5
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1884783 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
-rw-r--r--src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java3
-rw-r--r--src/java/org/apache/poi/ss/formula/atp/DateParser.java77
-rw-r--r--src/java/org/apache/poi/ss/util/DateParser.java2
3 files changed, 8 insertions, 74 deletions
diff --git a/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java b/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java
index ce73077910..a4ec0a35c4 100644
--- a/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java
+++ b/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java
@@ -17,6 +17,7 @@
package org.apache.poi.poifs.nio;
+import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -35,7 +36,7 @@ import org.apache.poi.util.POILogger;
/**
* A POIFS {@link DataSource} backed by a File
*/
-public class FileBackedDataSource extends DataSource {
+public class FileBackedDataSource extends DataSource implements Closeable {
private final static POILogger logger = POILogFactory.getLogger(FileBackedDataSource.class);
private final FileChannel channel;
diff --git a/src/java/org/apache/poi/ss/formula/atp/DateParser.java b/src/java/org/apache/poi/ss/formula/atp/DateParser.java
index 1cb25527b6..a8419bc51f 100644
--- a/src/java/org/apache/poi/ss/formula/atp/DateParser.java
+++ b/src/java/org/apache/poi/ss/formula/atp/DateParser.java
@@ -17,80 +17,13 @@
package org.apache.poi.ss.formula.atp;
-import java.util.Calendar;
-import java.util.regex.Pattern;
-
-import org.apache.poi.ss.formula.eval.ErrorEval;
-import org.apache.poi.ss.formula.eval.EvaluationException;
-import org.apache.poi.util.LocaleUtil;
+import org.apache.poi.util.Removal;
/**
* Parser for java dates.
+ * @deprecated in 5.0.0 - use {@link org.apache.poi.ss.util.DateParser}
*/
-public class DateParser {
- private DateParser() {
- // enforcing singleton
- }
-
- /**
- * 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.
- */
- public static Calendar parseDate(String strVal) throws EvaluationException {
- String[] parts = Pattern.compile("/").split(strVal);
- if (parts.length != 3) {
- throw new EvaluationException(ErrorEval.VALUE_INVALID);
- }
- String part2 = parts[2];
- int spacePos = part2.indexOf(' ');
- if (spacePos > 0) {
- // drop time portion if present
- part2 = part2.substring(0, spacePos);
- }
- int f0;
- int f1;
- int f2;
- try {
- f0 = Integer.parseInt(parts[0]);
- f1 = Integer.parseInt(parts[1]);
- f2 = Integer.parseInt(part2);
- } catch (NumberFormatException e) {
- throw new EvaluationException(ErrorEval.VALUE_INVALID);
- }
- if (f0 < 0 || f1 < 0 || f2 < 0 || (f0 > 12 && f1 > 12 && f2 > 12)) {
- // easy to see this cannot be a valid date
- throw new EvaluationException(ErrorEval.VALUE_INVALID);
- }
-
- if (f0 >= 1900 && f0 < 9999) {
- // when 4 digit value appears first, the format is YYYY/MM/DD, regardless of OS settings
- return makeDate(f0, f1, f2);
- }
- // otherwise the format seems to depend on OS settings (default date format)
-// if (false) {
-// // MM/DD/YYYY is probably a good guess, if the in the US
-// return makeDate(f2, f0, f1);
-// }
- // TODO - find a way to choose the correct date format
- throw new RuntimeException("Unable to determine date format for text '" + strVal + "'");
- }
-
- /**
- * @param month 1-based
- */
- private static Calendar makeDate(int year, int month, int day) throws EvaluationException {
- if (month < 1 || month > 12) {
- throw new EvaluationException(ErrorEval.VALUE_INVALID);
- }
- Calendar cal = LocaleUtil.getLocaleCalendar(year, month - 1, 1, 0, 0, 0);
- if (day < 1 || day > cal.getActualMaximum(Calendar.DAY_OF_MONTH)) {
- throw new EvaluationException(ErrorEval.VALUE_INVALID);
- }
- cal.set(Calendar.DAY_OF_MONTH, day);
- return cal;
- }
-
+@Removal(version = "6.0.0")
+@Deprecated
+public class DateParser extends org.apache.poi.ss.util.DateParser {
}
diff --git a/src/java/org/apache/poi/ss/util/DateParser.java b/src/java/org/apache/poi/ss/util/DateParser.java
index 996a1384f1..a69dae6383 100644
--- a/src/java/org/apache/poi/ss/util/DateParser.java
+++ b/src/java/org/apache/poi/ss/util/DateParser.java
@@ -35,7 +35,7 @@ import org.apache.poi.util.LocaleUtil;
* Parser for java dates.
*/
public class DateParser {
- private DateParser() {
+ protected DateParser() {
// enforcing singleton
}