I see from the documentation that timeZoneName defaults to UTC.
So, if reading a timestamp that has no timezone specified, does it get read in assuming UTC? And upon writing it out, should it not also be written assuming the same UTC? Keeping the same time zone assumption for both reading and writing would preserve the value.
But currently, it appears to be read in as UTC, but written out as local time zone, thus causing the value to change.
Example file is "time_types.csv":
colTimestamp
2017-08-04 14:12:37.0
Sample code:
Propertiesprops=newProperties();props.put("columnTypes","Timestamp");Connectionconn=DriverManager.getConnection("jdbc:relique:csv:.",props);Statementstmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);ResultSetresults=stmt.executeQuery("select colTimestamp from time_types");booleanwriteHeaderLine=true;CsvDriver.writeToCsv(results,System.out,writeHeaderLine);conn.close();
Expected Result (should match input file exactly):
colTimestamp
2017-08-04 14:12:37.0
Actual Result (off by 7 hours, since I am in Pacific Daylight Time):
Changing the timeZoneName to the above gets the behavior I am looking for. But I was still interested in your thoughts on this. Is this a bug (timezones for reading and writing do not match), or by design (timezone for reading is configurable, but writing is always local)?
Thanks!
Last edit: Richard See 2017-08-04
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I see from the documentation that timeZoneName defaults to UTC.
So, if reading a timestamp that has no timezone specified, does it get read in assuming UTC? And upon writing it out, should it not also be written assuming the same UTC? Keeping the same time zone assumption for both reading and writing would preserve the value.
But currently, it appears to be read in as UTC, but written out as local time zone, thus causing the value to change.
Example file is "time_types.csv":
Sample code:
Expected Result (should match input file exactly):
Actual Result (off by 7 hours, since I am in Pacific Daylight Time):
Workaround:
Changing the timeZoneName to the above gets the behavior I am looking for. But I was still interested in your thoughts on this. Is this a bug (timezones for reading and writing do not match), or by design (timezone for reading is configurable, but writing is always local)?
Thanks!
Last edit: Richard See 2017-08-04
This is a bug in CsvJdbc. The timeZoneName of the database connection should be used when writing timestamps in CsvDriver.writeToCsv().
I have logged this as bug 128, "CsvDriver.writeToCsv does not use connection timeZoneName".