Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0380765

Browse files
committed
Attached is a patch to fix the problem Thomas mentions below. The JDBC
driver now correctly handles timezones that are offset fractional hours from GMT (ie. -06:30). Barry Lind
1 parent 9a61532 commit 0380765

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,13 +472,35 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException
472472
//so this code strips off timezone info and adds on the GMT+/-...
473473
//as well as adds a third digit for partial seconds if necessary
474474
StringBuffer strBuf = new StringBuffer(s);
475+
476+
//we are looking to see if the backend has appended on a timezone.
477+
//currently postgresql will return +/-HH:MM or +/-HH for timezone offset
478+
//(i.e. -06, or +06:30, note the expectation of the leading zero for the
479+
//hours, and the use of the : for delimiter between hours and minutes)
480+
//if the backend ISO format changes in the future this code will
481+
//need to be changed as well
475482
char sub = strBuf.charAt(strBuf.length()-3);
476483
if (sub == '+' || sub == '-') {
477484
strBuf.setLength(strBuf.length()-3);
478485
if (subsecond) {
479-
strBuf = strBuf.append('0').append("GMT").append(s.substring(s.length()-3, s.length())).append(":00");
486+
strBuf.append('0').append("GMT").append(s.substring(s.length()-3, s.length())).append(":00");
487+
} else {
488+
strBuf.append("GMT").append(s.substring(s.length()-3, s.length())).append(":00");
489+
}
490+
} else if (sub == ':') {
491+
//we may have found timezone info of format +/-HH:MM, or there is no
492+
//timezone info at all and this is the : preceding the seconds
493+
char sub2 = strBuf.charAt(strBuf.length()-5);
494+
if (sub2 == '+' || sub2 == '-') {
495+
//we have found timezone info of format +/-HH:MM
496+
strBuf.setLength(strBuf.length()-5);
497+
if (subsecond) {
498+
strBuf.append('0').append("GMT").append(s.substring(s.length()-5));
480499
} else {
481-
strBuf = strBuf.append("GMT").append(s.substring(s.length()-3, s.length())).append(":00");
500+
strBuf.append("GMT").append(s.substring(s.length()-5));
501+
}
502+
} else if (subsecond) {
503+
strBuf.append('0');
482504
}
483505
} else if (subsecond) {
484506
strBuf = strBuf.append('0');

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,14 +484,36 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException
484484
sbuf.setLength(0);
485485
sbuf.append(s);
486486

487+
//we are looking to see if the backend has appended on a timezone.
488+
//currently postgresql will return +/-HH:MM or +/-HH for timezone offset
489+
//(i.e. -06, or +06:30, note the expectation of the leading zero for the
490+
//hours, and the use of the : for delimiter between hours and minutes)
491+
//if the backend ISO format changes in the future this code will
492+
//need to be changed as well
487493
char sub = sbuf.charAt(sbuf.length()-3);
488494
if (sub == '+' || sub == '-') {
495+
//we have found timezone info of format +/-HH
489496
sbuf.setLength(sbuf.length()-3);
490497
if (subsecond) {
491498
sbuf.append('0').append("GMT").append(s.substring(s.length()-3)).append(":00");
492499
} else {
493500
sbuf.append("GMT").append(s.substring(s.length()-3)).append(":00");
494501
}
502+
} else if (sub == ':') {
503+
//we may have found timezone info of format +/-HH:MM, or there is no
504+
//timezone info at all and this is the : preceding the seconds
505+
char sub2 = sbuf.charAt(sbuf.length()-5);
506+
if (sub2 == '+' || sub2 == '-') {
507+
//we have found timezone info of format +/-HH:MM
508+
sbuf.setLength(sbuf.length()-5);
509+
if (subsecond) {
510+
sbuf.append('0').append("GMT").append(s.substring(s.length()-5));
511+
} else {
512+
sbuf.append("GMT").append(s.substring(s.length()-5));
513+
}
514+
} else if (subsecond) {
515+
sbuf.append('0');
516+
}
495517
} else if (subsecond) {
496518
sbuf.append('0');
497519
}

0 commit comments

Comments
 (0)