diff --git a/src/java/org/apache/poi/hssf/record/RecordFactory.java b/src/java/org/apache/poi/hssf/record/RecordFactory.java index c1a0f5707..9bd3bdf66 100644 --- a/src/java/org/apache/poi/hssf/record/RecordFactory.java +++ b/src/java/org/apache/poi/hssf/record/RecordFactory.java @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -432,8 +433,10 @@ public final class RecordFactory { Integer key = Integer.valueOf(sid); if (result.containsKey(key)) { Class prevClass = result.get(key).getRecordClass(); - throw new RuntimeException("duplicate record sid 0x" + Integer.toHexString(sid).toUpperCase() - + " for classes (" + recClass.getName() + ") and (" + prevClass.getName() + ")"); + throw new RuntimeException("duplicate record sid 0x" + + Integer.toHexString(sid).toUpperCase(Locale.ROOT) + + " for classes (" + recClass.getName() + ") and (" + + prevClass.getName() + ")"); } result.put(key, getRecordCreator(recClass)); } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java index 6ac536840..0d754da67 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java @@ -17,6 +17,8 @@ package org.apache.poi.hssf.usermodel; +import java.util.Locale; + import org.apache.poi.hssf.record.PaletteRecord; import org.apache.poi.hssf.util.HSSFColor; @@ -234,7 +236,7 @@ public final class HSSFPalette { { int c = color & 0xff; //as unsigned c = (c << 8) | c; //pad to 16-bit - s = Integer.toHexString(c).toUpperCase(); + s = Integer.toHexString(c).toUpperCase(Locale.ROOT); while (s.length() < 4) { s = "0" + s; diff --git a/src/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java b/src/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java index 9fda8dcfb..d9dc068d4 100644 --- a/src/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java +++ b/src/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java @@ -19,6 +19,7 @@ package org.apache.poi.ss.formula.atp; import java.util.Calendar; import java.util.GregorianCalendar; +import java.util.Locale; import java.util.TimeZone; import org.apache.poi.ss.formula.eval.ErrorEval; @@ -316,7 +317,7 @@ final class YearFracCalculator { } private static SimpleDate createDate(int dayCount) { - GregorianCalendar calendar = new GregorianCalendar(UTC_TIME_ZONE); + GregorianCalendar calendar = new GregorianCalendar(UTC_TIME_ZONE, Locale.ROOT); DateUtil.setCalendar(calendar, dayCount, 0, false, false); return new SimpleDate(calendar); } diff --git a/src/java/org/apache/poi/ss/formula/functions/Days360.java b/src/java/org/apache/poi/ss/formula/functions/Days360.java index fc03734ef..65178a567 100644 --- a/src/java/org/apache/poi/ss/formula/functions/Days360.java +++ b/src/java/org/apache/poi/ss/formula/functions/Days360.java @@ -19,6 +19,7 @@ package org.apache.poi.ss.formula.functions; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Locale; +import java.util.TimeZone; import org.apache.poi.ss.formula.eval.EvaluationException; import org.apache.poi.ss.formula.eval.NumberEval; @@ -31,10 +32,13 @@ import org.apache.poi.ss.usermodel.DateUtil; * (twelve 30-day months), which is used in some accounting calculations. Use * this function to help compute payments if your accounting system is based on * twelve 30-day months. - * - * @author PUdalau */ public class Days360 extends Var2or3ArgFunction { + /** + * 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 ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) { double result; @@ -73,7 +77,7 @@ public class Days360 extends Var2or3ArgFunction { } private static Calendar getDate(double date) { - Calendar processedDate = new GregorianCalendar(Locale.ROOT); + Calendar processedDate = new GregorianCalendar(DEFAULT_TIMEZONE, Locale.ROOT); processedDate.setTime(DateUtil.getJavaDate(date, false)); return processedDate; } diff --git a/src/java/org/apache/poi/ss/formula/functions/EOMonth.java b/src/java/org/apache/poi/ss/formula/functions/EOMonth.java index 411257a09..968b67eba 100644 --- a/src/java/org/apache/poi/ss/formula/functions/EOMonth.java +++ b/src/java/org/apache/poi/ss/formula/functions/EOMonth.java @@ -21,6 +21,7 @@ import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; +import java.util.TimeZone; import org.apache.poi.ss.formula.OperationEvaluationContext; import org.apache.poi.ss.formula.eval.ErrorEval; @@ -44,7 +45,12 @@ import org.apache.poi.ss.usermodel.DateUtil; * zero or negative (in the past). */ public class EOMonth implements FreeRefFunction { - + /** + * 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 static final FreeRefFunction instance = new EOMonth(); @Override @@ -64,7 +70,7 @@ public class EOMonth implements FreeRefFunction { Date startDate = DateUtil.getJavaDate(startDateAsNumber, false); - Calendar cal = new GregorianCalendar(Locale.ROOT); + Calendar cal = new GregorianCalendar(DEFAULT_TIMEZONE, Locale.ROOT); cal.setTime(startDate); cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); @@ -78,5 +84,4 @@ public class EOMonth implements FreeRefFunction { return e.getErrorEval(); } } - } diff --git a/src/java/org/apache/poi/ss/util/CellReference.java b/src/java/org/apache/poi/ss/util/CellReference.java index b4fa2b3ce..cc695e92f 100644 --- a/src/java/org/apache/poi/ss/util/CellReference.java +++ b/src/java/org/apache/poi/ss/util/CellReference.java @@ -173,7 +173,7 @@ public class CellReference { */ public static int convertColStringToIndex(String ref) { int retval=0; - char[] refs = ref.toUpperCase().toCharArray(); + char[] refs = ref.toUpperCase(Locale.ROOT).toCharArray(); for (int k=0; k 0) { + if(colStr.toUpperCase(Locale.ROOT).compareTo(lastCol) > 0) { return false; } } else { @@ -379,7 +379,7 @@ public class CellReference { } } - col = reference.substring(start,loc).toUpperCase(); + col = reference.substring(start,loc).toUpperCase(Locale.ROOT); row = reference.substring(loc); CellRefParts cellRefParts = new CellRefParts(sheetName, row, col); return cellRefParts;