package org.apache.poi.dev;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileReader;
+import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Locale;
import java.util.Properties;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+import org.apache.poi.util.StringUtil;
import org.apache.poi.util.XMLHelper;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
private static void transform(final File in, final File out, final File xslt)
throws FileNotFoundException, TransformerException
{
- final Reader r = new FileReader(xslt);
+ final Reader r = new InputStreamReader(new FileInputStream(xslt), StringUtil.UTF8);
final StreamSource ss = new StreamSource(r);
final TransformerFactory tf = TransformerFactory.newInstance();
final Transformer t;
import java.util.Calendar;
import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
import org.apache.poi.ss.usermodel.DateUtil;
/**
* A calculator for workdays, considering dates as excel representations.
- *
- * @author jfaenomoto@gmail.com
*/
public class WorkdayCalculator {
+ /**
+ * 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 WorkdayCalculator instance = new WorkdayCalculator();
public Date calculateWorkdays(double start, int workdays, double[] holidays) {
Date startDate = DateUtil.getJavaDate(start);
int direction = workdays < 0 ? -1 : 1;
- Calendar endDate = Calendar.getInstance();
+ Calendar endDate = Calendar.getInstance(DEFAULT_TIMEZONE, Locale.ROOT);
endDate.setTime(startDate);
double excelEndDate = DateUtil.getExcelDate(endDate.getTime());
while (workdays != 0) {
int startDay = (int) Math.floor(start < end ? start : end);
int endDay = (int) Math.floor(end > start ? end : start);
for (; startDay <= endDay; startDay++) {
- Calendar today = Calendar.getInstance();
+ Calendar today = Calendar.getInstance(DEFAULT_TIMEZONE, Locale.ROOT);
today.setTime(DateUtil.getJavaDate(startDay));
if (today.get(Calendar.DAY_OF_WEEK) == dayOfWeek) {
pastDaysOfWeek++;
* @return <code>true</code> if date is weekend, <code>false</code> otherwise.
*/
protected boolean isWeekend(double aDate) {
- Calendar date = Calendar.getInstance();
+ Calendar date = Calendar.getInstance(DEFAULT_TIMEZONE, Locale.ROOT);
date.setTime(DateUtil.getJavaDate(aDate));
return date.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || date.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;
}
result = localePrefixes.get( localeString.substring( 0, 2 ) );\r
if( result == null ) {\r
Locale parentLocale = new Locale(localeString.substring( 0, 2 ));\r
- logger.log( POILogger.ERROR, "Unable to find prefix for " + locale + "(" + locale.getDisplayName() + ") or " \r
- + localeString.substring( 0, 2 ) + "(" + parentLocale.getDisplayName() + ")" );\r
+ logger.log( POILogger.ERROR, "Unable to find prefix for " + locale + "(" + locale.getDisplayName(Locale.ROOT) + ") or " \r
+ + localeString.substring( 0, 2 ) + "(" + parentLocale.getDisplayName(Locale.ROOT) + ")" );\r
return "";\r
}\r
}\r