Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc50bf01

Browse files
author
Barry Lind
committed
fixed bug reported by Wolfgang Winter w.winter@logitags.com where historic timestamps which do not have timezone info were being interpreted in local timezone instead of GMT. Also added a check to support timestamp vs. timestamptz in this code
1 parent68913b0 commitc50bf01

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

‎src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,17 +566,25 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException
566566
}
567567
else
568568
{
569-
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
569+
//if type is timestamptz then data is in GMT, else it is in local timezone
570+
if (fields[columnIndex -1].getPGType().equals("timestamptz")) {
571+
sbuf.append(" GMT");
572+
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
573+
}else {
574+
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
575+
}
570576
}
571577
}
572578
elseif (slen ==19)
573579
{
574580
// No tz or fractional second info.
575-
// I'm not sure if it is
576-
// possible to have a string in this format, as pg
577-
// should give us tz qualified timestamps back, but it was
578-
// in the old code, so I'm handling it for now.
581+
// if type is timestamptz then data is in GMT, else it is in local timezone
582+
if (fields[columnIndex -1].getPGType().equals("timestamptz")) {
583+
sbuf.append(" GMT");
584+
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
585+
}else {
579586
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");
587+
}
580588
}
581589
else
582590
{

‎src/interfaces/jdbc/org/postgresql/jdbc2/Array.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public Object getArray(long index, int count, Map map) throws SQLException
172172
retVal =newTimestamp[count ];
173173
StringBuffersbuf =null;
174174
for ( ;count >0;count-- )
175-
((java.sql.Timestamp[])retVal)[i++] =ResultSet.toTimestamp(arrayContents[(int)index++],rs );
175+
((java.sql.Timestamp[])retVal)[i++] =ResultSet.toTimestamp(arrayContents[(int)index++],rs,getBaseTypeName() );
176176
break;
177177

178178
// Other datatypes not currently supported. If you are really using other types ask

‎src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public Time getTime(int columnIndex) throws SQLException
401401
*/
402402
publicTimestampgetTimestamp(intcolumnIndex)throwsSQLException
403403
{
404-
returntoTimestamp(getString(columnIndex),this );
404+
returntoTimestamp(getString(columnIndex),this,fields[columnIndex-1].getPGType() );
405405
}
406406

407407
/*
@@ -1660,7 +1660,7 @@ public static Time toTime(String s) throws SQLException
16601660
*
16611661
* @throws SQLException if there is a problem parsing s.
16621662
**/
1663-
publicstaticTimestamptoTimestamp(Strings,ResultSetresultSet)
1663+
publicstaticTimestamptoTimestamp(Strings,ResultSetresultSet,StringpgDataType)
16641664
throwsSQLException
16651665
{
16661666
if (s ==null)
@@ -1735,18 +1735,26 @@ public static Timestamp toTimestamp(String s, ResultSet resultSet)
17351735
}
17361736
else
17371737
{
1738-
// Just found fractional seconds but no timezone.
1738+
// Just found fractional seconds but no timezone.
1739+
//If timestamptz then we use GMT, else local timezone
1740+
if (pgDataType.equals("timestamptz")) {
1741+
resultSet.sbuf.append(" GMT");
1742+
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
1743+
}else {
17391744
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
1745+
}
17401746
}
17411747
}
17421748
elseif (slen ==19)
17431749
{
1744-
// No tz or fractional second info.
1745-
// I'm not sure if it is
1746-
// possible to have a string in this format, as pg
1747-
// should give us tz qualified timestamps back, but it was
1748-
// in the old code, so I'm handling it for now.
1750+
// No tz or fractional second info.
1751+
//If timestamptz then we use GMT, else local timezone
1752+
if (pgDataType.equals("timestamptz")) {
1753+
resultSet.sbuf.append(" GMT");
1754+
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
1755+
}else {
17491756
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1757+
}
17501758
}
17511759
else
17521760
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp