Issue Details (XML | Word | Printable)

Key: JDBC-154
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Roman Rokytskyy
Reporter: Stanislav Kroo
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Jaybird JCA/JDBC Driver

Incorrect result of ResultSet.getTimestamp() at the moment of transition to summertime

Created: 24/Mar/10 01:00 PM   Updated: 18/Aug/12 07:31 AM
Component/s: JDBC driver
Affects Version/s: Jaybird 2.1.6
Fix Version/s: Jaybird 2.2

Environment:
Firebird 2.1.2
JRE 1.6


 Description  « Hide
There is no possibility to get correctly Timestamp values from the moment of transition to summertime during one hour.
For example, if JRE runned at GMT+3 TimeZone with active Daylight Saving Time option (Moscow), both values "2010-03-28 02:15" and "2010-03-28 03:15" selected as "2010-03-28 03:15:00.0".
-------- SQL script --------->
create table Test(dt1 Timestamp, dt2 Timestamp)
insert into Test values('2010-03-28 02:15:00.0', '2010-03-28 03:15:00.0')
-------- Java code --------->
java.sql.ResultSet rs = connection.createStatement().executeQuery("select * from Test");
rs.next();
System.out.println("\t\t\t\t\t\tdt1 \t\t\tdt2");
System.out.println("getString(\"dt\"): \t\t\t\t" + rs.getString("dt1") + "\t" + rs.getString("dt2"));
System.out.println("getTimestamp(\"dt\"): \t\t\t\t" + rs.getTimestamp("dt1") + "\t" + rs.getTimestamp("dt2"));
System.out.println("getTimestamp(\"dt\").getTime(): \t\t\t" + rs.getTimestamp("dt1").getTime() + "\t\t" + rs.getTimestamp("dt2").getTime());
Calendar gmtCalendar = Calendar.getInstance( java.util.TimeZone.getTimeZone("GMT-0:00") );
System.out.println("getTimestamp(\"dt\",gmtCalendar): \t\t" + rs.getTimestamp("dt1",gmtCalendar) + "\t" + rs.getTimestamp("dt2",gmtCalendar));
System.out.println("getTimestamp(\"dt\",gmtCalendar).getTime(): \t" + rs.getTimestamp("dt1",gmtCalendar).getTime() + "\t\t" + rs.getTimestamp("dt2",gmtCalendar).getTime());
-------- Result --------->
dt1 dt2
getString("dt"): 2010-03-28 03:15:00.0 2010-03-28 03:15:00.0
getTimestamp("dt"): 2010-03-28 03:15:00.0 2010-03-28 03:15:00.0
getTimestamp("dt").getTime(): 1269731700000 1269731700000
getTimestamp("dt",gmtCalendar): 2010-03-28 06:15:00.0 2010-03-28 06:15:00.0
getTimestamp("dt",gmtCalendar).getTime(): 1269742500000 1269742500000



 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Mark Rotteveel added a comment - 04/Apr/10 01:15 PM - edited
This is not a bug. I assume the 28th 2:00 is the cutover time for DST in Russia (it is the 28th 2:00 in the Netherlands). In that case 2:15 does not exist and is essentially an invalid time. In that situation Java will by default treat it leniently and convert the time to the assumed correct time of 3:15.

The following code will print out: Sun Mar 28 03:15:00 CEST 2010 (as it should):
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, new Locale("nl"));
df.setTimeZone(TimeZone.getTimeZone("Europe/Amsterdam"));
Date date = df.parse("28-03-10 2:15");
System.out.println(date);

Stanislav Kroo added a comment - 04/Apr/10 07:26 PM - edited
To Mr. Mark Rotteveel

You are quite right that '2010-03-28 02:15 is an invalid time in Moscow.
But what if we must treat database time as Greenwich Time?

I checked JDBC drivers for Oracle and MS SQL Server.
Both drivers give the same result:
                                                                                dt1 dt2
...
getTimestamp("dt",gmtCalendar): 2010-03-28 06:15:00.0 2010-03-28 07:15:00.0
getTimestamp("dt",gmtCalendar).getTime(): 1269742500000 1269746100000

Mark Rotteveel added a comment - 06/May/12 07:16 AM
It looks like this bug was fixed in Jaybird 2.2:
dt1 dt2
getTimestamp("dt",gmtCalendar): 2010-03-28 04:15:00.0 2010-03-28 05:15:00.0
getTimestamp("dt",gmtCalendar).getTime(): 1269742500000 1269746100000

This is in CEST.

Result when using Jaybird 2.1.6:
dt1 dt2
getTimestamp("dt",gmtCalendar): 2010-03-28 04:15:00.0 2010-03-28 04:15:00.0
getTimestamp("dt",gmtCalendar).getTime(): 1269742500000 1269742500000