United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 4677493 REGRESSION: java.sql.Timestamp.getTime() returns wrong value with GMT
4677493 : REGRESSION: java.sql.Timestamp.getTime() returns wrong value with GMT

Details
Type:
Bug
Submit Date:
2002-04-30
Status:
Closed
Updated Date:
2013-04-09
Project Name:
JDK
Resolved Date:
2013-04-09
Component:
core-libs
OS:
windows_2000
Sub-Component:
java.sql
CPU:
x86
Priority:
P4
Resolution:
Not an Issue
Affected Versions:
1.4.0
Fixed Versions:

Related Reports

Sub Tasks

Description
Name: rmT116609			Date: 04/30/2002


FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
On Windows the behaviour of java.sql.Timestamp is impacted by the "Automatically adjust clock for daylight savings time" setting when the TimeZone is set to GMT and it shouldn't be.  For example, creating a Timestamp instance by passing it milliseconds or a string will result in different times based on whether or not "Automatically adjust clock for daylight savings time" is selected or
not.  The specific Timestamp string I was seeing problems with was "1968-12-18 10:15:30.4".  I'll give details in the steps to reproduce.

REGRESSION.  Last worked in version 1.3.1_03

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.  Create a small java app with the following code:

		String javaVersion = System.getProperty( "java.version" );
		System.out.println( javaVersion );
		
		Timestamp ts1 = Timestamp.valueOf("1968-12-18 10:15:30.4");
		long ms;
		if ( javaVersion.startsWith( "1.3" ) )
			ms = (ts1.getTime() + (ts1.getNanos()/1000000));
		else
			ms = ts1.getTime();
		System.out.println( "ms1 : " + ms );
		System.out.println( "ts1 : " + ts1 );
		Timestamp ts2 = new Timestamp( ms );
		if ( javaVersion.startsWith( "1.3" ) )
			ms = (ts2.getTime() + (ts2.getNanos()/1000000));
		else
			ms = ts2.getTime();
		System.out.println( "ms2 : " + ms );
		System.out.println( "ts2 : " + ts2 );
		System.out.println( "date: " + new java.util.Date( ms ) );

2.  Set the TimeZone to GMT and select "Automatically adjust clock for daylight savings time".

3.  Invoke the java app with JDK 1.3.1_03 and you'll receive a correct value of -32708669600 for milliseconds.

4.  Invoke the java app with JDK 1.4.0 and you'll receive an incorrect value of -32712269600 for milliseconds.

5.  Unselect "Automatically adjust clock for daylight savings time".

6.  Invoke the java app with JDK 1.4.0 and you'll receive a correct value of -32708669600 for milliseconds.

Results:

With JDK1.3.1_03(checking the "Automatically adjust clock for daylight savings time"):

C:\>java TimestampBug
1.3.1_03
ms1 : -32708669600
ts1 : 1968-12-18 10:15:30.4
ms2 : -32708669600
ts2 : 1968-12-18 10:15:30.4
date: Wed Dec 18 10:15:30 GMT 1968

With JDK1.3.1_03(unchecking the "Automatically adjust clock for daylight savings time"):

C:\>java TimestampBug
1.3.1_03
ms1 : -32708669600
ts1 : 1968-12-18 10:15:30.4
ms2 : -32708669600
ts2 : 1968-12-18 10:15:30.4
date: Wed Dec 18 10:15:30 GMT 1968

With JDK1.4.0(checking the "Automatically adjust clock for daylight savings time"):

C:\>java TimestampBug
1.4.0
ms1 : -32712269600
ts1 : 1968-12-18 10:15:30.4
ms2 : -32712269600
ts2 : 1968-12-18 10:15:30.4
date: Wed Dec 18 10:15:30 GMT 1968


With JDK1.4.0(unchecking the "Automatically adjust clock for daylight savings time"):

C:\>java TimestampBug
1.4.0
ms1 : -32708669600
ts1 : 1968-12-18 10:15:30.4
ms2 : -32708669600
ts2 : 1968-12-18 10:15:30.4
date: Wed Dec 18 10:15:30 GMT 1968

EXPECTED VERSUS ACTUAL BEHAVIOR :
In all cases I expected to receive a value of -32708669600 for milliseconds.

This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.sql.*;
import java.io.*;


class TimestampBug
{	
	public static void main(String[] args)
	{
		String javaVersion = System.getProperty( "java.version" );
		System.out.println( javaVersion );
		
		Timestamp ts1 = Timestamp.valueOf("1968-12-18 10:15:30.4");
		long ms;
		if ( javaVersion.startsWith( "1.3" ) )
			ms = (ts1.getTime() + (ts1.getNanos()/1000000));
		else
			ms = ts1.getTime();
		System.out.println( "ms1 : " + ms );
		System.out.println( "ts1 : " + ts1 );
		Timestamp ts2 = new Timestamp( ms );
		if ( javaVersion.startsWith( "1.3" ) )
			ms = (ts2.getTime() + (ts2.getNanos()/1000000));
		else
			ms = ts2.getTime();
		System.out.println( "ms2 : " + ms );
		System.out.println( "ts2 : " + ts2 );
		System.out.println( "date: " + new java.util.Date( ms ) );
	}
}
---------- END SOURCE ----------

Release Regression From : 1.3.1_03
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Review ID: 146049) 
======================================================================

                                    

Comments
See the comment from Maayoshi but this is not an issue
                                     
2013-04-09
EVALUATION

It's not clear from this bug report, but it's very likely that the selected time zone was London. According to the Olson tzdata, London was in GMT+1:00 from 1968 Oct 27 00:00 (until 1971 Oct 31 2:00), which transition means that it didn't go back to standard time. The following is the Olson tzdata. (Refer to the zic man page on Solaris or Linux for the zic file format.)

# Zone	NAME		GMTOFF	RULES	FORMAT	[UNTIL]
Zone	Europe/London	-0:01:15 -	LMT	1847 Dec  1 0:00s
			 0:00	GB-Eire	%s	1968 Oct 27
			 1:00	-	BST	1971 Oct 31 2:00u
			 0:00	GB-Eire	%s	1996
			 0:00	EU	GMT/BST

Until 1.3.x, Java didn't support any historical (future) time zone changes, but it does since 1.4.0. The 1.4.0 output correctly represents the historical time zone (GMT offset) changes. However, the Java time zone system doesn't support time zone name (abbreviation) changes. "GMT" should be "BST" for the time stamp of Date.toString().

Around Windows NT/98/2000, there were some confusions with the GMT time zone (GMT vs. London). The recent Windows has more decent time zone support.

I'd suggest this CR be closed as Not a Defect.
                                     
2010-07-07
EVALUATION

Deferring this bug to next release of jdk.
                                     
2006-07-20
EVALUATION

This should be fixed if possible for mustang and then backported to tiger
                                     
2006-05-10
EVALUATION

Requires investigation, will target for Mantis if fix required.


###@###.### 2002-05-28

Under investigation...

###@###.### 2003-11-12

Under consideration for JDBC 4.0

###@###.### 2004-02-06
                                     
2002-05-28



Hardware and Software, Engineered to Work Together