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 21:11:21 UTC
svn commit: r1700645 - in /poi/trunk/src/java/org/apache/poi/ss:
formula/functions/DateFunc.java formula/functions/Today.java
usermodel/DateUtil.java
Author: nick
Date: Tue Sep 1 19:11:20 2015
New Revision: 1700645
URL: http://svn.apache.org/r1700645
Log:
Fix some Forbidden APIs errors
Modified:
poi/trunk/src/java/org/apache/poi/ss/formula/functions/DateFunc.java
poi/trunk/src/java/org/apache/poi/ss/formula/functions/Today.java
poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/DateFunc.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/DateFunc.java?rev=1700645&r1=1700644&r2=1700645&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/DateFunc.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/DateFunc.java Tue Sep 1 19:11:20 2015
@@ -20,6 +20,7 @@ package org.apache.poi.ss.formula.functi
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
+import java.util.TimeZone;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
@@ -30,10 +31,13 @@ import org.apache.poi.ss.usermodel.DateU
/**
* Implementation for the Excel function DATE
- *
- * @author Pavel Krupets (pkrupets at palmtreebusiness dot com)
*/
public final class DateFunc extends Fixed3ArgFunction {
+ /**
+ * 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 Function instance = new DateFunc();
@@ -87,7 +91,7 @@ public final class DateFunc extends Fixe
}
// Turn this into a Java date
- Calendar c = new GregorianCalendar(Locale.ROOT);
+ Calendar c = new GregorianCalendar(DEFAULT_TIMEZONE, Locale.ROOT);
c.set(year, month, day, 0, 0, 0);
c.set(Calendar.MILLISECOND, 0);
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/Today.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/Today.java?rev=1700645&r1=1700644&r2=1700645&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/Today.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/Today.java Tue Sep 1 19:11:20 2015
@@ -20,6 +20,7 @@ package org.apache.poi.ss.formula.functi
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
+import java.util.TimeZone;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
@@ -27,14 +28,16 @@ import org.apache.poi.ss.usermodel.DateU
/**
* Implementation of Excel TODAY() Function<br/>
- *
- * @author Frank Taffelt
*/
public final class Today extends Fixed0ArgFunction {
+ /**
+ * 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) {
-
- Calendar now = new GregorianCalendar(Locale.ROOT);
+ Calendar now = new GregorianCalendar(DEFAULT_TIMEZONE, 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()));
Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java?rev=1700645&r1=1700644&r2=1700645&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java Tue Sep 1 19:11:20 2015
@@ -61,7 +61,10 @@ public class DateUtil {
// elapsed time patterns: [h],[m] and [s]
private static final Pattern date_ptrn4 = Pattern.compile("^\\[([hH]+|[mM]+|[sS]+)\\]");
- // only get this static info once (because operations are not really cheap)
+ /**
+ * Excel doesn't store TimeZone information in the file, so if in doubt,
+ * use UTC to perform calculations
+ */
private static final TimeZone TIMEZONE_UTC = TimeZone.getTimeZone("UTC");
@@ -84,7 +87,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(Locale.ROOT);
+ Calendar calStart = new GregorianCalendar(TIMEZONE_UTC, Locale.ROOT);
calStart.setTime(date); // If date includes hours, minutes, and seconds, set them to 0
return internalGetExcelDate(calStart, use1904windowing);
}
@@ -322,7 +325,7 @@ public class DateUtil {
if (timeZone != null) {
calendar = new GregorianCalendar(timeZone, Locale.ROOT);
} else {
- calendar = new GregorianCalendar(Locale.ROOT); // using default time-zone
+ calendar = new GregorianCalendar(TIMEZONE_UTC, Locale.ROOT); // using default time-zone
}
setCalendar(calendar, wholeDays, millisecondsInDay, use1904windowing, roundSeconds);
return calendar;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org