diff --git a/src/java/org/apache/poi/ss/formula/functions/DateFunc.java b/src/java/org/apache/poi/ss/formula/functions/DateFunc.java index 03152e0c13..cd64505d56 100644 --- a/src/java/org/apache/poi/ss/formula/functions/DateFunc.java +++ b/src/java/org/apache/poi/ss/formula/functions/DateFunc.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 org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.EvaluationException; @@ -86,7 +87,7 @@ public final class DateFunc extends Fixed3ArgFunction { } // Turn this into a Java date - Calendar c = new GregorianCalendar(); + Calendar c = new GregorianCalendar(Locale.ROOT); c.set(year, month, day, 0, 0, 0); c.set(Calendar.MILLISECOND, 0); 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 f2bd1a5ddb..fc03734ef4 100644 --- a/src/java/org/apache/poi/ss/formula/functions/Days360.java +++ b/src/java/org/apache/poi/ss/formula/functions/Days360.java @@ -18,6 +18,7 @@ package org.apache.poi.ss.formula.functions; import java.util.Calendar; import java.util.GregorianCalendar; +import java.util.Locale; import org.apache.poi.ss.formula.eval.EvaluationException; import org.apache.poi.ss.formula.eval.NumberEval; @@ -72,7 +73,7 @@ public class Days360 extends Var2or3ArgFunction { } private static Calendar getDate(double date) { - Calendar processedDate = new GregorianCalendar(); + Calendar processedDate = new GregorianCalendar(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 8832e20e79..411257a09f 100644 --- a/src/java/org/apache/poi/ss/formula/functions/EOMonth.java +++ b/src/java/org/apache/poi/ss/formula/functions/EOMonth.java @@ -20,6 +20,7 @@ package org.apache.poi.ss.formula.functions; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.Locale; import org.apache.poi.ss.formula.OperationEvaluationContext; import org.apache.poi.ss.formula.eval.ErrorEval; @@ -63,7 +64,7 @@ public class EOMonth implements FreeRefFunction { Date startDate = DateUtil.getJavaDate(startDateAsNumber, false); - Calendar cal = new GregorianCalendar(); + Calendar cal = new GregorianCalendar(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); diff --git a/src/java/org/apache/poi/ss/formula/functions/Today.java b/src/java/org/apache/poi/ss/formula/functions/Today.java index 8abc2f0d92..906cbda1ff 100644 --- a/src/java/org/apache/poi/ss/formula/functions/Today.java +++ b/src/java/org/apache/poi/ss/formula/functions/Today.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 org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.ValueEval; @@ -33,7 +34,7 @@ public final class Today extends Fixed0ArgFunction { public ValueEval evaluate(int srcRowIndex, int srcColumnIndex) { - Calendar now = new GregorianCalendar(); + Calendar now = new GregorianCalendar(Locale.ROOT); now.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DATE),0,0,0); now.set(Calendar.MILLISECOND, 0); return new NumberEval(DateUtil.getExcelDate(now.getTime())); diff --git a/src/java/org/apache/poi/ss/formula/functions/WeekNum.java b/src/java/org/apache/poi/ss/formula/functions/WeekNum.java index e678104a23..9cfd26fe5c 100644 --- a/src/java/org/apache/poi/ss/formula/functions/WeekNum.java +++ b/src/java/org/apache/poi/ss/formula/functions/WeekNum.java @@ -23,6 +23,7 @@ import org.apache.poi.ss.usermodel.DateUtil; import java.util.Calendar; import java.util.GregorianCalendar; +import java.util.Locale; /** * Implementation for Excel WeekNum() function.

@@ -52,7 +53,7 @@ public class WeekNum extends Fixed2ArgFunction implements FreeRefFunction { } catch (EvaluationException e) { return ErrorEval.VALUE_INVALID; } - Calendar serialNumCalendar = new GregorianCalendar(); + Calendar serialNumCalendar = new GregorianCalendar(Locale.ROOT); serialNumCalendar.setTime(DateUtil.getJavaDate(serialNum, false)); int returnType = 0; diff --git a/src/java/org/apache/poi/ss/usermodel/DateUtil.java b/src/java/org/apache/poi/ss/usermodel/DateUtil.java index ca1d7d4659..31b33eabc4 100644 --- a/src/java/org/apache/poi/ss/usermodel/DateUtil.java +++ b/src/java/org/apache/poi/ss/usermodel/DateUtil.java @@ -21,6 +21,7 @@ package org.apache.poi.ss.usermodel; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.Locale; import java.util.TimeZone; import java.util.regex.Pattern; @@ -83,7 +84,7 @@ public class DateUtil { * @param use1904windowing Should 1900 or 1904 date windowing be used? */ public static double getExcelDate(Date date, boolean use1904windowing) { - Calendar calStart = new GregorianCalendar(); + Calendar calStart = new GregorianCalendar(Locale.ROOT); calStart.setTime(date); // If date includes hours, minutes, and seconds, set them to 0 return internalGetExcelDate(calStart, use1904windowing); } @@ -319,9 +320,9 @@ public class DateUtil { int millisecondsInDay = (int)((date - wholeDays) * DAY_MILLISECONDS + 0.5); Calendar calendar; if (timeZone != null) { - calendar = new GregorianCalendar(timeZone); + calendar = new GregorianCalendar(timeZone, Locale.ROOT); } else { - calendar = new GregorianCalendar(); // using default time-zone + calendar = new GregorianCalendar(Locale.ROOT); // using default time-zone } setCalendar(calendar, wholeDays, millisecondsInDay, use1904windowing, roundSeconds); return calendar; diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java index 83004cb3b8..bea8e7129b 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java @@ -26,6 +26,7 @@ import java.nio.charset.Charset; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.Locale; import junit.framework.TestCase; @@ -142,14 +143,14 @@ public final class TestUnfixedBugs extends TestCase { // second to be different here! int startYear = 1900; int dayAdjust = -1; // Excel thinks 2/29/1900 is a valid date, which it isn't - Calendar calendar1 = new GregorianCalendar(); + Calendar calendar1 = new GregorianCalendar(Locale.ROOT); calendar1.set(startYear,0, wholeDays1 + dayAdjust, 0, 0, 0); calendar1.set(Calendar.MILLISECOND, millisecondsInDay1); // this is the rounding part: calendar1.add(Calendar.MILLISECOND, 500); calendar1.clear(Calendar.MILLISECOND); - Calendar calendar2 = new GregorianCalendar(); + Calendar calendar2 = new GregorianCalendar(Locale.ROOT); calendar2.set(startYear,0, wholeDays2 + dayAdjust, 0, 0, 0); calendar2.set(Calendar.MILLISECOND, millisecondsInDay2); // this is the rounding part: diff --git a/src/scratchpad/src/org/apache/poi/hslf/util/SystemTimeUtils.java b/src/scratchpad/src/org/apache/poi/hslf/util/SystemTimeUtils.java index 926a2f5645..a6ab1ba803 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/util/SystemTimeUtils.java +++ b/src/scratchpad/src/org/apache/poi/hslf/util/SystemTimeUtils.java @@ -20,6 +20,7 @@ package org.apache.poi.hslf.util; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.Locale; import org.apache.poi.util.LittleEndian; @@ -47,7 +48,7 @@ public final class SystemTimeUtils { * Get the date found in the byte array, as a java Data object */ public static Date getDate(byte[] data, int offset) { - Calendar cal = new GregorianCalendar(); + Calendar cal = new GregorianCalendar(Locale.ROOT); cal.set(Calendar.YEAR, LittleEndian.getShort(data,offset)); cal.set(Calendar.MONTH, LittleEndian.getShort(data,offset+2)-1); diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java b/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java index e74eedf8a7..b58b4cd8f0 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java @@ -28,6 +28,7 @@ import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import junit.framework.TestCase; @@ -227,7 +228,7 @@ public class TestWriteWellKnown extends TestCase { * (e.g. author, edit date, application name) and to the document * summary information (e.g. company, manager). */ - Calendar cal = new GregorianCalendar(); + Calendar cal = new GregorianCalendar(Locale.ROOT); cal.set(2000, 6, 6, 6, 6, 6); final long time1 = cal.getTimeInMillis(); cal.set(2001, 7, 7, 7, 7, 7); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java index 2e34d6f602..7abd515743 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java @@ -25,6 +25,7 @@ import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.Locale; import java.util.TimeZone; import org.apache.poi.hssf.HSSFTestDataSamples; @@ -461,7 +462,7 @@ public final class TestHSSFDateUtil { * @param day one based */ private static Date createDate(int year, int month, int day, int hour, int minute, int second) { - Calendar c = new GregorianCalendar(); + Calendar c = new GregorianCalendar(Locale.ROOT); c.set(year, month, day, hour, minute, second); c.set(Calendar.MILLISECOND, 0); return c.getTime(); diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java b/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java index 22d3ba3492..abd8ba2ccd 100644 --- a/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java +++ b/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.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 junit.framework.TestCase; @@ -58,7 +59,7 @@ public final class TestYearFracCalculator extends TestCase { } private static double md(int year, int month, int day) { - Calendar c = new GregorianCalendar(); + Calendar c = new GregorianCalendar(Locale.ROOT); c.set(year, month-1, day, 0, 0, 0); c.set(Calendar.MILLISECOND, 0); diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java index 15dd1246b1..db39c09c32 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java @@ -20,6 +20,7 @@ package org.apache.poi.ss.formula.functions; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.Locale; import junit.framework.AssertionFailedError; import junit.framework.TestCase; @@ -44,13 +45,13 @@ public final class TestDays360 extends TestCase { return cal.getTime(); } private static Date decrementDay(Date d) { - Calendar c = new GregorianCalendar(); + Calendar c = new GregorianCalendar(Locale.ROOT); c.setTimeInMillis(d.getTime()); c.add(Calendar.DAY_OF_MONTH, -1); return c.getTime(); } private static String fmt(Date d) { - Calendar c = new GregorianCalendar(); + Calendar c = new GregorianCalendar(Locale.ROOT); c.setTimeInMillis(d.getTime()); StringBuilder sb = new StringBuilder(); sb.append(c.get(Calendar.YEAR));