diff --git a/src/java/org/apache/poi/hpsf/Property.java b/src/java/org/apache/poi/hpsf/Property.java index d141349bd..14dbee027 100644 --- a/src/java/org/apache/poi/hpsf/Property.java +++ b/src/java/org/apache/poi/hpsf/Property.java @@ -18,6 +18,7 @@ package org.apache.poi.hpsf; import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; import java.util.LinkedHashMap; import java.util.Map; @@ -52,9 +53,6 @@ import org.apache.poi.util.POILogger; * href="http://msdn.microsoft.com/library/en-us/stg/stg/property_set_display_name_dictionary.asp?frame=true"> * Property Set Display Name Dictionary. * - * @author Rainer Klute <klute@rainer-klute.de> - * @author Drew Varner (Drew.Varner InAndAround sc.edu) * @see Section * @see Variant */ @@ -238,7 +236,7 @@ public class Property { /* Without a codepage the length is equal to the number of * bytes. */ - b.append(new String(src, o, (int) sLength)); + b.append(new String(src, o, (int) sLength, Charset.forName("ASCII"))); break; } case CodePageUtil.CP_UNICODE: diff --git a/src/java/org/apache/poi/hssf/usermodel/DVConstraint.java b/src/java/org/apache/poi/hssf/usermodel/DVConstraint.java index 8e322ce80..4548486a4 100644 --- a/src/java/org/apache/poi/hssf/usermodel/DVConstraint.java +++ b/src/java/org/apache/poi/hssf/usermodel/DVConstraint.java @@ -21,6 +21,7 @@ import java.text.MessageFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Locale; import java.util.regex.Pattern; import org.apache.poi.hssf.model.HSSFFormulaParser; @@ -55,10 +56,6 @@ public class DVConstraint implements DataValidationConstraint { } - // convenient access to ValidationType namespace - private static final ValidationType VT = null; - - private final int _validationType; private int _operator; private String[] _explicitListValues; @@ -184,7 +181,7 @@ public class DVConstraint implements DataValidationConstraint { throw new IllegalArgumentException("expr1 must be supplied"); } OperatorType.validateSecondArg(comparisonOperator, expr2); - SimpleDateFormat df = dateFormat == null ? null : new SimpleDateFormat(dateFormat); + SimpleDateFormat df = dateFormat == null ? null : new SimpleDateFormat(dateFormat, Locale.ROOT); // formula1 and value1 are mutually exclusive String formula1 = getFormulaFromTextExpression(expr1); 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 325fbbb23..73b51a5fb 100644 --- a/src/java/org/apache/poi/ss/formula/atp/DateParser.java +++ b/src/java/org/apache/poi/ss/formula/atp/DateParser.java @@ -19,6 +19,8 @@ package org.apache.poi.ss.formula.atp; import java.util.Calendar; import java.util.GregorianCalendar; +import java.util.Locale; +import java.util.TimeZone; import java.util.regex.Pattern; import org.apache.poi.ss.formula.eval.ErrorEval; @@ -26,10 +28,13 @@ import org.apache.poi.ss.formula.eval.EvaluationException; /** * Parser for java dates. - * - * @author jfaenomoto@gmail.com */ public class DateParser { + /** + * Excel doesn't store TimeZone information in the file, so if in doubt, + * use UTC to perform calculations + */ + private static final TimeZone DEFAULT_TIMEZONE = TimeZone.getTimeZone("UTC"); public DateParser instance = new DateParser(); @@ -90,7 +95,8 @@ public class DateParser { if (month < 1 || month > 12) { throw new EvaluationException(ErrorEval.VALUE_INVALID); } - Calendar cal = new GregorianCalendar(year, month - 1, 1, 0, 0, 0); + Calendar cal = new GregorianCalendar(DEFAULT_TIMEZONE, Locale.ROOT); + cal.set(year, month - 1, 1, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); if (day < 1 || day > cal.getActualMaximum(Calendar.DAY_OF_MONTH)) { throw new EvaluationException(ErrorEval.VALUE_INVALID);