mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-12 18:34:36 +08:00
Patch from Ryouichi Matsuda
An attached patch corrects problem of this bug and fractional second. The handling of time zone was as follows: (a) with time zone using SimpleDateFormat("yyyy-MM-dd HH:mm:ss z") (b) without time zone using SimpleDateFormat("yyyy-MM-dd HH:mm:ss") About problem of fractional second, Fractional second was changed from milli-second to nano-second
This commit is contained in:
parent
7aa6270fc7
commit
8f83590aa1
@ -514,7 +514,9 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
StringBuffer sbuf = new StringBuffer(s);
|
||||
SimpleDateFormat df = null;
|
||||
|
||||
if (s.length() > 19)
|
||||
int slen = s.length();
|
||||
|
||||
if (slen > 19)
|
||||
{
|
||||
// The len of the ISO string to the second value is 19 chars. If
|
||||
// greater then 19, there should be tz info and perhaps fractional
|
||||
@ -534,7 +536,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
if (i < 24)
|
||||
sbuf.append(c);
|
||||
c = s.charAt(i++);
|
||||
} while (Character.isDigit(c));
|
||||
} while (i < slen && Character.isDigit(c));
|
||||
|
||||
// If there wasn't at least 3 digits we should add some zeros
|
||||
// to make up the 3 digits we tell java to expect.
|
||||
@ -547,21 +549,28 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
sbuf.append(".000");
|
||||
}
|
||||
|
||||
if (i < slen)
|
||||
{
|
||||
// prepend the GMT part and then add the remaining bit of
|
||||
// the string.
|
||||
sbuf.append(" GMT");
|
||||
sbuf.append(c);
|
||||
sbuf.append(s.substring(i, s.length()));
|
||||
sbuf.append(s.substring(i, slen));
|
||||
|
||||
// Lastly, if the tz part doesn't specify the :MM part then
|
||||
// we add ":00" for java.
|
||||
if (s.length() - i < 5)
|
||||
if (slen - i < 5)
|
||||
sbuf.append(":00");
|
||||
|
||||
// we'll use this dateformat string to parse the result.
|
||||
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
|
||||
}
|
||||
else if (s.length() == 19)
|
||||
else
|
||||
{
|
||||
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
}
|
||||
}
|
||||
else if (slen == 19)
|
||||
{
|
||||
// No tz or fractional second info.
|
||||
// I'm not sure if it is
|
||||
|
@ -1630,11 +1630,12 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
|
||||
// Copy s into sbuf for parsing.
|
||||
resultSet.sbuf.append(s);
|
||||
int slen = s.length();
|
||||
|
||||
if (s.length() > 19)
|
||||
if (slen > 19)
|
||||
{
|
||||
// The len of the ISO string to the second value is 19 chars. If
|
||||
// greater then 19, there should be tz info and perhaps fractional
|
||||
// greater then 19, there may be tz info and perhaps fractional
|
||||
// second info which we need to change to java to read it.
|
||||
|
||||
// cut the copy to second value "2001-12-07 16:29:22"
|
||||
@ -1651,7 +1652,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
if (i < 24)
|
||||
resultSet.sbuf.append(c);
|
||||
c = s.charAt(i++);
|
||||
} while (Character.isDigit(c));
|
||||
} while (i < slen && Character.isDigit(c));
|
||||
|
||||
// If there wasn't at least 3 digits we should add some zeros
|
||||
// to make up the 3 digits we tell java to expect.
|
||||
@ -1664,21 +1665,29 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
resultSet.sbuf.append(".000");
|
||||
}
|
||||
|
||||
if (i < slen)
|
||||
{
|
||||
// prepend the GMT part and then add the remaining bit of
|
||||
// the string.
|
||||
resultSet.sbuf.append(" GMT");
|
||||
resultSet.sbuf.append(c);
|
||||
resultSet.sbuf.append(s.substring(i, s.length()));
|
||||
resultSet.sbuf.append(s.substring(i, slen));
|
||||
|
||||
// Lastly, if the tz part doesn't specify the :MM part then
|
||||
// we add ":00" for java.
|
||||
if (s.length() - i < 5)
|
||||
if (slen - i < 5)
|
||||
resultSet.sbuf.append(":00");
|
||||
|
||||
// we'll use this dateformat string to parse the result.
|
||||
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
|
||||
}
|
||||
else if (s.length() == 19)
|
||||
else
|
||||
{
|
||||
// Just found fractional seconds but no timezone.
|
||||
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
}
|
||||
}
|
||||
else if (slen == 19)
|
||||
{
|
||||
// No tz or fractional second info.
|
||||
// I'm not sure if it is
|
||||
|
Loading…
Reference in New Issue
Block a user