Fix some Forbidden APIs errors
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1700635 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6703c9d3fb
commit
f098eca5a0
@ -19,6 +19,7 @@ package org.apache.poi.ss.formula.functions;
|
|||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.apache.poi.ss.formula.eval.ErrorEval;
|
import org.apache.poi.ss.formula.eval.ErrorEval;
|
||||||
import org.apache.poi.ss.formula.eval.EvaluationException;
|
import org.apache.poi.ss.formula.eval.EvaluationException;
|
||||||
@ -86,7 +87,7 @@ public final class DateFunc extends Fixed3ArgFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Turn this into a Java date
|
// 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(year, month, day, 0, 0, 0);
|
||||||
c.set(Calendar.MILLISECOND, 0);
|
c.set(Calendar.MILLISECOND, 0);
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ package org.apache.poi.ss.formula.functions;
|
|||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.apache.poi.ss.formula.eval.EvaluationException;
|
import org.apache.poi.ss.formula.eval.EvaluationException;
|
||||||
import org.apache.poi.ss.formula.eval.NumberEval;
|
import org.apache.poi.ss.formula.eval.NumberEval;
|
||||||
@ -72,7 +73,7 @@ public class Days360 extends Var2or3ArgFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Calendar getDate(double date) {
|
private static Calendar getDate(double date) {
|
||||||
Calendar processedDate = new GregorianCalendar();
|
Calendar processedDate = new GregorianCalendar(Locale.ROOT);
|
||||||
processedDate.setTime(DateUtil.getJavaDate(date, false));
|
processedDate.setTime(DateUtil.getJavaDate(date, false));
|
||||||
return processedDate;
|
return processedDate;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ package org.apache.poi.ss.formula.functions;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.apache.poi.ss.formula.OperationEvaluationContext;
|
import org.apache.poi.ss.formula.OperationEvaluationContext;
|
||||||
import org.apache.poi.ss.formula.eval.ErrorEval;
|
import org.apache.poi.ss.formula.eval.ErrorEval;
|
||||||
@ -63,7 +64,7 @@ public class EOMonth implements FreeRefFunction {
|
|||||||
|
|
||||||
Date startDate = DateUtil.getJavaDate(startDateAsNumber, false);
|
Date startDate = DateUtil.getJavaDate(startDateAsNumber, false);
|
||||||
|
|
||||||
Calendar cal = new GregorianCalendar();
|
Calendar cal = new GregorianCalendar(Locale.ROOT);
|
||||||
cal.setTime(startDate);
|
cal.setTime(startDate);
|
||||||
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
|
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
|
||||||
cal.set(Calendar.MILLISECOND, 0);
|
cal.set(Calendar.MILLISECOND, 0);
|
||||||
|
@ -19,6 +19,7 @@ package org.apache.poi.ss.formula.functions;
|
|||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.apache.poi.ss.formula.eval.NumberEval;
|
import org.apache.poi.ss.formula.eval.NumberEval;
|
||||||
import org.apache.poi.ss.formula.eval.ValueEval;
|
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) {
|
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(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DATE),0,0,0);
|
||||||
now.set(Calendar.MILLISECOND, 0);
|
now.set(Calendar.MILLISECOND, 0);
|
||||||
return new NumberEval(DateUtil.getExcelDate(now.getTime()));
|
return new NumberEval(DateUtil.getExcelDate(now.getTime()));
|
||||||
|
@ -23,6 +23,7 @@ import org.apache.poi.ss.usermodel.DateUtil;
|
|||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation for Excel WeekNum() function.<p/>
|
* Implementation for Excel WeekNum() function.<p/>
|
||||||
@ -52,7 +53,7 @@ public class WeekNum extends Fixed2ArgFunction implements FreeRefFunction {
|
|||||||
} catch (EvaluationException e) {
|
} catch (EvaluationException e) {
|
||||||
return ErrorEval.VALUE_INVALID;
|
return ErrorEval.VALUE_INVALID;
|
||||||
}
|
}
|
||||||
Calendar serialNumCalendar = new GregorianCalendar();
|
Calendar serialNumCalendar = new GregorianCalendar(Locale.ROOT);
|
||||||
serialNumCalendar.setTime(DateUtil.getJavaDate(serialNum, false));
|
serialNumCalendar.setTime(DateUtil.getJavaDate(serialNum, false));
|
||||||
|
|
||||||
int returnType = 0;
|
int returnType = 0;
|
||||||
|
@ -21,6 +21,7 @@ package org.apache.poi.ss.usermodel;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -83,7 +84,7 @@ public class DateUtil {
|
|||||||
* @param use1904windowing Should 1900 or 1904 date windowing be used?
|
* @param use1904windowing Should 1900 or 1904 date windowing be used?
|
||||||
*/
|
*/
|
||||||
public static double getExcelDate(Date date, boolean use1904windowing) {
|
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
|
calStart.setTime(date); // If date includes hours, minutes, and seconds, set them to 0
|
||||||
return internalGetExcelDate(calStart, use1904windowing);
|
return internalGetExcelDate(calStart, use1904windowing);
|
||||||
}
|
}
|
||||||
@ -319,9 +320,9 @@ public class DateUtil {
|
|||||||
int millisecondsInDay = (int)((date - wholeDays) * DAY_MILLISECONDS + 0.5);
|
int millisecondsInDay = (int)((date - wholeDays) * DAY_MILLISECONDS + 0.5);
|
||||||
Calendar calendar;
|
Calendar calendar;
|
||||||
if (timeZone != null) {
|
if (timeZone != null) {
|
||||||
calendar = new GregorianCalendar(timeZone);
|
calendar = new GregorianCalendar(timeZone, Locale.ROOT);
|
||||||
} else {
|
} else {
|
||||||
calendar = new GregorianCalendar(); // using default time-zone
|
calendar = new GregorianCalendar(Locale.ROOT); // using default time-zone
|
||||||
}
|
}
|
||||||
setCalendar(calendar, wholeDays, millisecondsInDay, use1904windowing, roundSeconds);
|
setCalendar(calendar, wholeDays, millisecondsInDay, use1904windowing, roundSeconds);
|
||||||
return calendar;
|
return calendar;
|
||||||
|
@ -26,6 +26,7 @@ import java.nio.charset.Charset;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
@ -142,14 +143,14 @@ public final class TestUnfixedBugs extends TestCase {
|
|||||||
// second to be different here!
|
// second to be different here!
|
||||||
int startYear = 1900;
|
int startYear = 1900;
|
||||||
int dayAdjust = -1; // Excel thinks 2/29/1900 is a valid date, which it isn't
|
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(startYear,0, wholeDays1 + dayAdjust, 0, 0, 0);
|
||||||
calendar1.set(Calendar.MILLISECOND, millisecondsInDay1);
|
calendar1.set(Calendar.MILLISECOND, millisecondsInDay1);
|
||||||
// this is the rounding part:
|
// this is the rounding part:
|
||||||
calendar1.add(Calendar.MILLISECOND, 500);
|
calendar1.add(Calendar.MILLISECOND, 500);
|
||||||
calendar1.clear(Calendar.MILLISECOND);
|
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(startYear,0, wholeDays2 + dayAdjust, 0, 0, 0);
|
||||||
calendar2.set(Calendar.MILLISECOND, millisecondsInDay2);
|
calendar2.set(Calendar.MILLISECOND, millisecondsInDay2);
|
||||||
// this is the rounding part:
|
// this is the rounding part:
|
||||||
|
@ -20,6 +20,7 @@ package org.apache.poi.hslf.util;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.apache.poi.util.LittleEndian;
|
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
|
* Get the date found in the byte array, as a java Data object
|
||||||
*/
|
*/
|
||||||
public static Date getDate(byte[] data, int offset) {
|
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.YEAR, LittleEndian.getShort(data,offset));
|
||||||
cal.set(Calendar.MONTH, LittleEndian.getShort(data,offset+2)-1);
|
cal.set(Calendar.MONTH, LittleEndian.getShort(data,offset+2)-1);
|
||||||
|
@ -28,6 +28,7 @@ import java.util.Calendar;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
@ -227,7 +228,7 @@ public class TestWriteWellKnown extends TestCase {
|
|||||||
* (e.g. author, edit date, application name) and to the document
|
* (e.g. author, edit date, application name) and to the document
|
||||||
* summary information (e.g. company, manager).
|
* summary information (e.g. company, manager).
|
||||||
*/
|
*/
|
||||||
Calendar cal = new GregorianCalendar();
|
Calendar cal = new GregorianCalendar(Locale.ROOT);
|
||||||
cal.set(2000, 6, 6, 6, 6, 6);
|
cal.set(2000, 6, 6, 6, 6, 6);
|
||||||
final long time1 = cal.getTimeInMillis();
|
final long time1 = cal.getTimeInMillis();
|
||||||
cal.set(2001, 7, 7, 7, 7, 7);
|
cal.set(2001, 7, 7, 7, 7, 7);
|
||||||
|
@ -25,6 +25,7 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
@ -461,7 +462,7 @@ public final class TestHSSFDateUtil {
|
|||||||
* @param day one based
|
* @param day one based
|
||||||
*/
|
*/
|
||||||
private static Date createDate(int year, int month, int day, int hour, int minute, int second) {
|
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(year, month, day, hour, minute, second);
|
||||||
c.set(Calendar.MILLISECOND, 0);
|
c.set(Calendar.MILLISECOND, 0);
|
||||||
return c.getTime();
|
return c.getTime();
|
||||||
|
@ -19,6 +19,7 @@ package org.apache.poi.ss.formula.atp;
|
|||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ public final class TestYearFracCalculator extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static double md(int year, int month, int day) {
|
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(year, month-1, day, 0, 0, 0);
|
||||||
c.set(Calendar.MILLISECOND, 0);
|
c.set(Calendar.MILLISECOND, 0);
|
||||||
|
@ -20,6 +20,7 @@ package org.apache.poi.ss.formula.functions;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
import junit.framework.AssertionFailedError;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
@ -44,13 +45,13 @@ public final class TestDays360 extends TestCase {
|
|||||||
return cal.getTime();
|
return cal.getTime();
|
||||||
}
|
}
|
||||||
private static Date decrementDay(Date d) {
|
private static Date decrementDay(Date d) {
|
||||||
Calendar c = new GregorianCalendar();
|
Calendar c = new GregorianCalendar(Locale.ROOT);
|
||||||
c.setTimeInMillis(d.getTime());
|
c.setTimeInMillis(d.getTime());
|
||||||
c.add(Calendar.DAY_OF_MONTH, -1);
|
c.add(Calendar.DAY_OF_MONTH, -1);
|
||||||
return c.getTime();
|
return c.getTime();
|
||||||
}
|
}
|
||||||
private static String fmt(Date d) {
|
private static String fmt(Date d) {
|
||||||
Calendar c = new GregorianCalendar();
|
Calendar c = new GregorianCalendar(Locale.ROOT);
|
||||||
c.setTimeInMillis(d.getTime());
|
c.setTimeInMillis(d.getTime());
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(c.get(Calendar.YEAR));
|
sb.append(c.get(Calendar.YEAR));
|
||||||
|
Loading…
Reference in New Issue
Block a user