Menu

#280 Error on date parsing with XLSTable / XlsDataSet

v2.4.*
closed-fixed
Bug (232)
2.5.3
5
2016-05-21
2010-02-28
No

At
org.dbunit.dataset.excel.XlsTable.java,
the code below causes dates to be wrong parsed from XLS files.
The way it is, Jan 10, 2009 00:00, in GMT+3, is valued as Jan 09, 2009, 21:00.

To avoid the bug, one can pass
-Duser.timezone=GMT
to the TestRunner, so offset is hard forced to be zero, and date is not changed.

protected Object getDateValue(HSSFCell cell)
{
logger.debug("getDateValue(cell={}) - start", cell);

double numericValue = cell.getNumericCellValue();
Date date = HSSFDateUtil.getJavaDate(numericValue); // at this point, date is OK

// This code subtracts "default" offset from date parsed from XLS, causing the bug
// Add the timezone offset again because it was subtracted automatically by Apache-POI (we need UTC)
long tzOffset = TimeZone.getDefault().getOffset(date.getTime());

date = new Date(date.getTime() + tzOffset);
return new Long(date.getTime());
}

Thanks,
Fábio.

Discussion

  • Jeff Jensen

    Jeff Jensen - 2016-05-21
    • status: open --> closed-fixed
    • assigned_to: matthias g --> Jeff Jensen
    • Fixed Release: --> 2.5.3
     
  • Jeff Jensen

    Jeff Jensen - 2016-05-21

    Committed both of the above.

     

    Related

    Bugs: #371
    Commit: [2bc788]


Log in to post a comment.