You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2015/09/01 23:31:03 UTC
svn commit: r1700675 - in /poi/trunk/src/java/org/apache/poi:
ss/format/CellDateFormatter.java ss/formula/functions/WeekNum.java
util/HexRead.java
Author: nick
Date: Tue Sep 1 21:31:02 2015
New Revision: 1700675
URL: http://svn.apache.org/r1700675
Log:
Fix some Forbidden APIs errors
Modified:
poi/trunk/src/java/org/apache/poi/ss/format/CellDateFormatter.java
poi/trunk/src/java/org/apache/poi/ss/formula/functions/WeekNum.java
poi/trunk/src/java/org/apache/poi/util/HexRead.java
Modified: poi/trunk/src/java/org/apache/poi/ss/format/CellDateFormatter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/format/CellDateFormatter.java?rev=1700675&r1=1700674&r2=1700675&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/format/CellDateFormatter.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/format/CellDateFormatter.java Tue Sep 1 21:31:02 2015
@@ -24,14 +24,19 @@ import java.util.Calendar;
import java.util.Date;
import java.util.Formatter;
import java.util.Locale;
+import java.util.TimeZone;
import java.util.regex.Matcher;
/**
* Formats a date value.
- *
- * @author Ken Arnold, Industrious Media LLC
*/
public class CellDateFormatter extends CellFormatter {
+ /**
+ * 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");
+
private boolean amPmUpper;
private boolean showM;
private boolean showAmPm;
@@ -45,7 +50,7 @@ public class CellDateFormatter extends C
"mm/d/y");
static {
- Calendar c = Calendar.getInstance();
+ Calendar c = Calendar.getInstance(DEFAULT_TIMEZONE, Locale.ROOT);
c.set(1904, 0, 1, 0, 0, 0);
EXCEL_EPOCH_DATE = c.getTime();
EXCEL_EPOCH_TIME = c.getTimeInMillis();
@@ -183,7 +188,7 @@ public class CellDateFormatter extends C
if (!doneMillis) {
Date dateObj = (Date) value;
int pos = toAppendTo.length();
- Formatter formatter = new Formatter(toAppendTo);
+ Formatter formatter = new Formatter(toAppendTo, Locale.ROOT);
try {
long msecs = dateObj.getTime() % 1000;
formatter.format(LOCALE, sFmt, msecs / 1000.0);
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/WeekNum.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/WeekNum.java?rev=1700675&r1=1700674&r2=1700675&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/WeekNum.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/WeekNum.java Tue Sep 1 21:31:02 2015
@@ -24,6 +24,7 @@ import org.apache.poi.ss.usermodel.DateU
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
+import java.util.TimeZone;
/**
* Implementation for Excel WeekNum() function.<p/>
@@ -39,10 +40,13 @@ import java.util.Locale;
* Return_type is a number that determines on which day the week begins. The default is 1.
* 1 Week begins on Sunday. Weekdays are numbered 1 through 7.
* 2 Week begins on Monday. Weekdays are numbered 1 through 7.
- *
- * @author cedric dot walter @ gmail dot com
*/
public class WeekNum extends Fixed2ArgFunction 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 WeekNum();
@@ -53,7 +57,7 @@ public class WeekNum extends Fixed2ArgFu
} catch (EvaluationException e) {
return ErrorEval.VALUE_INVALID;
}
- Calendar serialNumCalendar = new GregorianCalendar(Locale.ROOT);
+ Calendar serialNumCalendar = new GregorianCalendar(DEFAULT_TIMEZONE, Locale.ROOT);
serialNumCalendar.setTime(DateUtil.getJavaDate(serialNum, false));
int returnType = 0;
Modified: poi/trunk/src/java/org/apache/poi/util/HexRead.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/HexRead.java?rev=1700675&r1=1700674&r2=1700675&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/HexRead.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/HexRead.java Tue Sep 1 21:31:02 2015
@@ -24,9 +24,6 @@ import java.util.ArrayList;
/**
* Utilities to read hex from files.
* TODO - move to test packages
- *
- * @author Marc Johnson
- * @author Glen Stampoultzis (glens at apache.org)
*/
public class HexRead
{
@@ -174,7 +171,7 @@ public class HexRead
static public byte[] readFromString(String data) {
try {
- return readData(new ByteArrayInputStream( data.getBytes() ), -1);
+ return readData(new ByteArrayInputStream( data.getBytes(StringUtil.UTF8) ), -1);
} catch (IOException e) {
throw new RuntimeException(e);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org