Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect result of ResultSet.getTimestamp() at the moment of transition to summertime [JDBC154] #197

Closed
firebird-automations opened this issue Mar 24, 2010 · 6 comments

Comments

@firebird-automations
Copy link

Submitted by: Stanislav Kroo (kroo)

Assigned to: Roman Rokytskyy (rrokytskyy)

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

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

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);

@firebird-automations
Copy link
Author

Commented by: Stanislav Kroo (kroo)

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

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

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

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

Fix Version: Jaybird 2.2 [ 10053 ]

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant