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;
"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();
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);
import java.util.Calendar;\r
import java.util.GregorianCalendar;\r
import java.util.Locale;\r
+import java.util.TimeZone;\r
\r
/**\r
* Implementation for Excel WeekNum() function.<p/>\r
* Return_type is a number that determines on which day the week begins. The default is 1.\r
* 1 Week begins on Sunday. Weekdays are numbered 1 through 7.\r
* 2 Week begins on Monday. Weekdays are numbered 1 through 7.\r
- *\r
- * @author cedric dot walter @ gmail dot com\r
*/\r
public class WeekNum extends Fixed2ArgFunction implements FreeRefFunction {\r
+ /**\r
+ * Excel doesn't store TimeZone information in the file, so if in doubt,\r
+ * use UTC to perform calculations\r
+ */\r
+ private static final TimeZone DEFAULT_TIMEZONE = TimeZone.getTimeZone("UTC");\r
\r
public static final FreeRefFunction instance = new WeekNum();\r
\r
} catch (EvaluationException e) {\r
return ErrorEval.VALUE_INVALID;\r
}\r
- Calendar serialNumCalendar = new GregorianCalendar(Locale.ROOT);\r
+ Calendar serialNumCalendar = new GregorianCalendar(DEFAULT_TIMEZONE, Locale.ROOT);\r
serialNumCalendar.setTime(DateUtil.getJavaDate(serialNum, false));\r
\r
int returnType = 0;\r
/**
* Utilities to read hex from files.
* TODO - move to test packages
- *
- * @author Marc Johnson
- * @author Glen Stampoultzis (glens at apache.org)
*/
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);
}