[libpostgresql-jdbc-java] 01/10: Statement.getTime, .getDate, and .getTimestamp methods which are passed a Calendar object were rotating the timezone in the wrong direction. Rewrite this code to use the existing TimestampUtils methods to match the working code in ResultSets.
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:20:00 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_1_409
in repository libpostgresql-jdbc-java.
commit 5e9b62c4efd40b9f9dfb952490b0a10ea070dd71
Author: Kris Jurka <books at ejurka.com>
Date: Thu Jan 4 21:59:26 2007 +0000
Statement.getTime, .getDate, and .getTimestamp methods which are
passed a Calendar object were rotating the timezone in the wrong
direction. Rewrite this code to use the existing TimestampUtils
methods to match the working code in ResultSets.
Reported by Ravi Periasamy.
---
org/postgresql/jdbc2/AbstractJdbc2Statement.java | 75 ++++++++++--------------
1 file changed, 31 insertions(+), 44 deletions(-)
diff --git a/org/postgresql/jdbc2/AbstractJdbc2Statement.java b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
index 74f9ee3..0452c65 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2Statement.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
@@ -3,7 +3,7 @@
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.84.2.6 2006/09/26 04:42:25 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.84.2.7 2006/11/05 05:44:44 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -3023,35 +3023,47 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
public java.sql.Date getDate(int i, java.util.Calendar cal) throws SQLException
{
- if (cal == null)
- return getDate(i);
- java.util.Date tmp = getDate(i);
- if (tmp == null)
+ checkClosed();
+ checkIndex(i, Types.DATE, "Date");
+
+ if (callResult[i-1] == null)
return null;
- cal = changeTime(tmp, cal, false);
- return new java.sql.Date(cal.getTime().getTime());
+
+ if (cal != null)
+ cal = (Calendar)cal.clone();
+
+ String value = callResult[i-1].toString();
+ return connection.getTimestampUtils().toDate(cal, value);
}
public Time getTime(int i, java.util.Calendar cal) throws SQLException
{
- if (cal == null)
- return getTime(i);
- java.util.Date tmp = getTime(i);
- if (tmp == null)
+ checkClosed();
+ checkIndex(i, Types.TIME, "Time");
+
+ if (callResult[i-1] == null)
return null;
- cal = changeTime(tmp, cal, false);
- return new java.sql.Time(cal.getTime().getTime());
+
+ if (cal != null)
+ cal = (Calendar)cal.clone();
+
+ String value = callResult[i-1].toString();
+ return connection.getTimestampUtils().toTime(cal, value);
}
public Timestamp getTimestamp(int i, java.util.Calendar cal) throws SQLException
{
- if (cal == null)
- return getTimestamp(i);
- java.util.Date tmp = getTimestamp(i);
- if (tmp == null)
+ checkClosed();
+ checkIndex(i, Types.TIMESTAMP, "Timestamp");
+
+ if (callResult[i-1] == null)
return null;
- cal = changeTime(tmp, cal, false);
- return new java.sql.Timestamp(cal.getTime().getTime());
+
+ if (cal != null)
+ cal = (Calendar)cal.clone();
+
+ String value = callResult[i-1].toString();
+ return connection.getTimestampUtils().toTimestamp(cal, value);
}
// no custom types allowed yet..
@@ -3060,29 +3072,4 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
throw Driver.notImplemented(this.getClass(), "registerOutParameter(int,int,String)");
}
-
- static java.util.Calendar changeTime(java.util.Date t, java.util.Calendar cal, boolean Add)
- {
- long millis = t.getTime();
-
- if (millis == PGStatement.DATE_POSITIVE_INFINITY ||
- millis == PGStatement.DATE_NEGATIVE_INFINITY)
- {
- cal.setTime(t);
- return cal;
- }
-
- int localoffset = t.getTimezoneOffset() * 60 * 1000 * -1;
- int caloffset = cal.getTimeZone().getRawOffset();
- if (cal.getTimeZone().inDaylightTime(t))
- millis += 60 * 60 * 1000;
- caloffset = (Add) ? (caloffset - localoffset) : -1 * (caloffset - localoffset);
- java.util.Date tmpDate = new java.util.Date();
- tmpDate.setTime(millis - caloffset);
- cal.setTime(tmpDate);
- // cal.setTimeInMillis(millis-caloffset);
- tmpDate = null;
- return cal;
- }
-
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git
More information about the pkg-java-commits
mailing list