Menu

dbunit Merge Request #10: XlsTable#getDateValue adds timezone offset unnecessary. (merged)

Merging...

Merged

Something went wrong. Please, merge manually

Checking if merge is possible...

Something went wrong. Please, merge manually

Ryota Sato wants to merge 1 commit from /u/mnt40/dbunit/ to master, 2016-05-21

Problem

When I store the datetime value with XlsDataSet into PostgreSQL's timestamp column, the timestamp value has extra time.

e.g.)
In my Asia/Tokyo (+09:00) timezone environment,
when .xls cell value (date format) is 01/01/1970 00:00:00,
timestamp value stored in postgresql will be 01/01/1970 09:00:00.

I think this problem is identical with issue 280 and issue 371.

I checked this using PostgreSQL 9.4.5 (Windows7 64bit or Windows10 64bit or CentOS7.1 64bit)

Cause

Because the XlsTable#getDateValue(Cell) method adds the timezone offset, the value stored in PostgreSQL has extra value (=timezone offset).

How to fix

Comment out the lines below in XlsTable#getDateValue(Cell) works fine for me.

// 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);

I think it is not necessary to add the timezone offset.

For example, when .xls cell value in date format is 01/01/1970 00:00:00,
POI returns java.util.Date of 01/01/1970 00:00:00+09:00.
Then java.util.Date#getTime() returns -32400000 because this method returns UTC value.
And then, this value converted to java.sql.Timestamp in TimestampDataType.typeCast(Object). This results in timezone specific value 01/01/1970 00:00:00+09:00. So value stored in PostgreSQL is 01/01/1970 00:00:00 (timestamp without timezone) or 01/01/1970 00:00:00+09:00 (timestamp with timezone).

Commit Date  
[1ed126] (work) by Ryota Sato Ryota Sato

issue 280/371: Not to add system default timezone offset to numeric cell
value.

2016-01-17 15:03:45 Tree

Discussion

  • Jeff Jensen

    Jeff Jensen - 2016-04-17

    Thanks for the merge request.
    I'm wondering if a recent data type change may resolve the issue, since it appears when saving to the DB.

    Issue 380 https://sourceforge.net/p/dbunit/bugs/380/ , which points to a fix in issue 304 https://sourceforge.net/p/dbunit/bugs/304/ , deals with non-local timezones.

    I committed this fix and published a 2.5.3-SNAPSHOT. Do you have a moment to test it and reply whether it fixes the problem or not please?

    Snapshot repo info here:
    http://dbunit.sourceforge.net/repos.html

     
  • Ryota Sato

    Ryota Sato - 2016-04-21

    Thank you for your reply.
    I will try out 2.5.3-SNAPSHOT and then provide feedback.

     
  • Ryota Sato

    Ryota Sato - 2016-05-01

    I tried out 2.5.3-SNAPSHOT.
    It works fine when I wrote timestamp like '2015-01-01 10:00:00 +0100' in string cells.

    And sorry, I took misquotations (#304 and #380).
    What the issue I think is when we write timestamp in the numeric cell, the timestamp automatically substracted/added timezone offset.
    This is not ideal when our application programs are available in one timezone only.

    I rethought about this issue.
    What I rethought is written in the following GIST.
    https://gist.github.com/Monota/d62ed3fc9ab7e210b129daa86bc7ed1f

    My repository for survey is the following:
    https://github.com/Monota/spring-dbunit-timezone-survey

    And how to tackle it? In the case of numeric cell, I think...
    If an application program is available in one timezone only, dbunit should not substract/add timezone offset auotmatically.If an application program is available in the worldwide, dbunit should substract/add timezone offset auotmatically.
    I think to add a boolean property to XmlDataSet which indicates substract/add timezone offset automatically or not will be the best (and default setting should not change the behavior of the current version).

    What do you think about that?

    Many thanks.

     
  • Jeff Jensen

    Jeff Jensen - 2016-05-21
    • Status: open --> merged
     
  • Jeff Jensen

    Jeff Jensen - 2016-05-21

    Thanks again for the merge request and extra research.
    Excel does not have concept of timezones; I'm not sure why the code was adjusting for it.
    Issue [bugs:#371] adds a test showing this problem so have merged this and committed the test.

    Please test the updated snapshot and reply with your results!

     

    Related

    Bugs: #371

  • Ryota Sato

    Ryota Sato - 2016-05-21

    All my tests passed.
    Thank you so much!

     
  • Jeff Jensen

    Jeff Jensen - 2016-05-21

    Excellent! Thank you for verifying so quickly and again for the help!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.