Menu

#149 Add timezone support for timestamp data type

closed-fixed
None
5
2009-12-27
2009-12-25
Volker Lamp
No

Request:
Timezone support for the timestamp data type (and probably for the date data type and the time data type as well) would be very useful for some DbUnit users.

Analysis:
Currently, timezones are not supported since the parsing effort is being delegated to java.sql.Timestamp.valueOf() which cannot handle timezones. Actually, Timestamp.valueOf() silently uses the default timezone. This can lead to surprising results. Consider the following code and the two different outputs, depending on the default timezone:

System.out.println( "jvm's timezone: " + TimeZone.getDefault().getID() );
String input = "2007-12-05 10:00:00.000000000";
Timestamp ts = Timestamp.valueOf( input );
System.out.println( input + "'s is " + ts.getTime() + " milliseconds since January 1, 1970, 00:00:00 GMT" );

- with the default timezone of my system:

jvm's timezone: Europe/Zurich
2007-12-05 10:00:00.000000000 is parsed to be 1196845200000 milliseconds since January 1, 1970, 00:00:00 GMT

- in UTC:

jvm's timezone: UTC
2007-12-05 10:00:00.000000000 is parsed to be 1196848800000 milliseconds since January 1, 1970, 00:00:00 GMT

(credit to Guillaume Cottenceau, see http://archives.postgresql.org/pgsql-jdbc/2007-12/msg00014.php\)

Solution:
Use java.text.DateFormat.parse() instead. See attached patch.

Discussion

  • Volker Lamp

    Volker Lamp - 2009-12-25

    Timezone support for timestamp data type patch

     
  • John Hurst

    John Hurst - 2009-12-27
    • assigned_to: nobody --> jbhurst
     
  • John Hurst

    John Hurst - 2009-12-27
    • status: open --> closed-fixed
     
  • John Hurst

    John Hurst - 2009-12-27

    Done in svn:1131.

     

Log in to post a comment.