Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed date/time handling #110

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Fixed date/time handling #110

wants to merge 4 commits into from

Conversation

agalanin
Copy link

SQLite's internal date and time functions use UTC time zone. So we need to adjust date/time formatting and scanning in library to always use UTC.

@@ -311,46 +312,21 @@ public Date getDate(int col) throws SQLException {
* @see java.sql.ResultSet#getDate(int, java.util.Calendar)
*/
public Date getDate(int col, Calendar cal) throws SQLException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this moves the driver away from the JDBC spec by ignoring the user supplied Calendar/Timezone information.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately there are no sqlite datatype like 'timestamp with timezone' in postgresql, so timezone information is lost during saving in sqlite database.

@gitblit
Copy link
Collaborator

gitblit commented Jun 21, 2016

I like the idea of wrangling the date/time type. Looks like the driver is storing text formatted dates using the local timezone. That was probably a mistake. I'm concerned about backwards compatibility with this change. Need more eyeballs on this review.

@TuomasKiviaho
Copy link

TuomasKiviaho commented Jun 22, 2016

I'm getting +2 hours with Europe/Helsinki time zone when using date_class=text

@gitblit
Copy link
Collaborator

gitblit commented Jun 22, 2016

@TuomasKiviaho A quick search tells me Helsinki is GMT+3 right now with DST. Are you saying your dates are actually +5 compared to GMT (and therefore +2 compared to what you expected)? Or are you saying they are GMT+2 ? Or some other combination? Fun with timezones...

@TuomasKiviaho
Copy link

Hi, 14:01 saved as string became 16:01 when I applied the UTC timezone fix. I didn't investigate it any further than that. Works OK with machines set in UTC timezone. Below is the snipped that I'm using.

 case SQLITE_TEXT:
                try {
                    return new Timestamp(stmt.conn.timestampFormat.parse(db.column_text(stmt.pointer, markCol(col))).getTime());
                }
                catch (Exception e) {
                    SQLException error = new SQLException("Error parsing time stamp");
                    error.initCause(e);

                    throw error;
                }

Fun with timezones...

Using org.threeten could be slightly less fun, but that's another story.

@gitblit
Copy link
Collaborator

gitblit commented Jun 23, 2016

Hi, 14:01 saved as string became 16:01 when I applied the UTC timezone fix.

Yeah, problems along those lines are what I was expecting. Hmmm...

@gitblit gitblit mentioned this pull request Jun 29, 2016
@agalanin
Copy link
Author

Any news?

@xerial xerial self-assigned this Apr 15, 2017
# Conflicts:
#	src/test/java/org/sqlite/AllTests.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants