Skip to content

Commit f7b89ac

Browse files
author
Peter Mount
committed
Some more getTimestamp() fixes
1 parent d3f6552 commit f7b89ac

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/interfaces/jdbc/CHANGELOG

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Tue Oct 17 15:35:00 BST 2000 petermount@maidstone.gov.uk
2+
- Changed getTimestamp() again. This time Michael Stephenson's
3+
<mstephenson@tirin.openworld.co.uk> solution looked far better
4+
than the original solution put in June.
5+
16
Tue Oct 10 13:12:00 BST 2000 peter@retep.org.uk
27
- DatabaseMetaData.supportsAlterTableWithDropColumn() as psql doesn't
38
support dropping of individual columns
@@ -13,7 +18,6 @@ Mon Sep 25 14:22:00 BST 2000 peter@retep.org.uk
1318
- Removed the DriverClass kludge. Now the org.postgresql.Driver class
1419
is compiled from a template file, and now has both the connection
1520
class (ie jdbc1/jdbc2) and the current version's from Makefile.global
16-
-
1721

1822
Thu Jul 20 16:30:00 BST 2000 petermount@it.maidstone.gov.uk
1923
- Fixed DatabaseMetaData.getTableTypes()

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,23 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException
462462
if(s==null)
463463
return null;
464464

465-
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
465+
// This works, but it's commented out because Michael Stephenson's
466+
// solution is better still:
467+
//SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
468+
469+
// Michael Stephenson's solution:
470+
SimpleDateFormat df = null;
471+
if (s.length()>21 && s.indexOf('.') != -1) {
472+
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSzzz");
473+
} else if (s.length()>19 && s.indexOf('.') == -1) {
474+
df = new SimpleDateFormat("yyyy-MM-dd HH:MM:sszzz");
475+
} else if (s.length()>19 && s.indexOf('.') != -1) {
476+
df = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss.SS");
477+
} else if (s.length()>10 && s.length()<=18) {
478+
df = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
479+
} else {
480+
df = new SimpleDateFormat("yyyy-MM-dd");
481+
}
466482

467483
try {
468484
return new Timestamp(df.parse(s).getTime());

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,23 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException
465465
if(s==null)
466466
return null;
467467

468-
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
468+
// This works, but it's commented out because Michael Stephenson's
469+
// solution is better still:
470+
//SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
471+
472+
// Michael Stephenson's solution:
473+
SimpleDateFormat df = null;
474+
if (s.length()>21 && s.indexOf('.') != -1) {
475+
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSzzz");
476+
} else if (s.length()>19 && s.indexOf('.') == -1) {
477+
df = new SimpleDateFormat("yyyy-MM-dd HH:MM:sszzz");
478+
} else if (s.length()>19 && s.indexOf('.') != -1) {
479+
df = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss.SS");
480+
} else if (s.length()>10 && s.length()<=18) {
481+
df = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
482+
} else {
483+
df = new SimpleDateFormat("yyyy-MM-dd");
484+
}
469485

470486
try {
471487
return new Timestamp(df.parse(s).getTime());

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy