Bug 28550 - TimeZone.getDefault() probably incorrect and not equals(`/etc/localtime`)
Summary: TimeZone.getDefault() probably incorrect and not equals(`/etc/localtime`)
Status: UNCONFIRMED
Alias: None
Product: classpath
Classification: Unclassified
Component: classpath (show other bugs)
Version: unspecified
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: 16990
  Show dependency treegraph
 
Reported: 2006-07-31 08:44 UTC by Andrew Cowie
Modified: 2006-07-31 08:48 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Cowie 2006-07-31 08:44:40 UTC
The default ("local") timezone returned by TimeZone.getDefault() should match the  name of the zone pointed at by the /etc/localtime symlink [or named in the first line of the an /etc/timezone file, which is a long since deprecated usage]

On our office systems, /etc/localtime -> /usr/share/zoneinfo/Australia/Sydney (and just for kicks, /etc/timezone = "Australia/Sydney")

$ java TimeZoneBugs
Local zone:                                             Australia/Sydney
(correct)

For zone named:                                         America/Montreal
TimeZone.getID() should be the same:                    America/Montreal

For zone named:                                         Australia/Sydney
TimeZone.getID() should be the same:                    Australia/Sydney

For zone named:                                         Europe/Paris
TimeZone.getID() should be the same:                    Europe/Paris

You can observe that the TimeZone returned with .getTimeZone("Australia/Sydney") matches .getDefault() ... and even more importantly, they match with .equals()

But with classpath, things are confused. JamVM 1.4.3 + classpath 0.91:

$ jamvm TimeZoneBugs
Local zone:                                             AET
(wrong!)

For zone named:                                         America/Montreal
TimeZone.getID() should be the same:                    America/Montreal

For zone named:                                         Australia/Sydney
TimeZone.getID() should be the same:                    Australia/Sydney

For zone named:                                         Europe/Paris
TimeZone.getID() should be the same:                    Europe/Paris

With GCJ 4.1.1 the same problem arises:

$ ./TimeZoneBugs
Local zone:                                             AET
(wrong!)
etc

AfC
Comment 1 Andrew Cowie 2006-07-31 08:46:58 UTC
See attachment 11977 [details] to bug 28549 for the testcase to demonstrate this bug.

AfC
Comment 2 Jakub Jelinek 2007-02-22 16:05:16 UTC
Subject: Bug 28550

Author: jakub
Date: Thu Feb 22 16:04:55 2007
New Revision: 122229

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122229
Log:
libjava/
	PR libgcj/17002
	PR classpath/28550
	* java/util/VMTimeZone.java (getDefaultTimeZoneId): To read
	/etc/localtime, use ZoneInfo.readTZFile instead of
	VMTimeZone.readtzFile.  Get better timezone name for /etc/localtime,
	either if it is a symlink or through /etc/sysconfig/clock.
	(readSysconfigClockFile): New static method.
	(readtzFile): Removed.
	* java/lang/System.java: Add gnu.java.util.zoneinfo.dir to comments.
	* posix.cc (_Jv_platform_initProperties): Set
	gnu.java.util.zoneinfo.dir.
	* sources.am (gnu_java_util_source_files): Add
	classpath/gnu/java/util/ZoneInfo.java.
	* Makefile.in: Regenerated.
	* java/util/VMTimeZone.h: Regenerated.
	* java/util/TimeZone.h: Regenerated.
	* gnu/java/util/ZoneInfo.h: Generated.
libjava/classpath/
	* java/util/Date.java (parse): Properly parse 09:01:02 as
	hours/minutes/seconds, not as hours/minutes/year.
	* java/util/SimpleTimeZone.java (SimpleTimeZone): Simplify
	{start,end}TimeMode constructor by calling shorter constructor,
	set {start,end}TimeMode fields after it returns.
	(setStartRule): Don't adjust startTime into WALL_TIME.  Set
	startTimeMode to WALL_TIME.
	(endStartRule): Similarly.
	(getOffset): Handle properly millis + dstOffset overflowing into the
	next day.  Adjust startTime resp. endTime based on startTimeMode
	resp. endTimeMode.
	* java/util/TimeZone.java (zoneinfo_dir, availableIDs, aliases0): New
	static fields.
	(timezones): Remove synchronized keyword.  Set zoneinfo_dir.
	If non-null, set up aliases0 and don't put anything into
	timezones0.
	(defaultZone): Call getTimeZone instead of timezones().get.
	(getDefaultTimeZone): Fix parsing of EST5 or EST5EDT6.  Use
	getTimeZoneInternal instead of timezones().get.
	(parseTime): Parse correctly hour:minute.
	(getTimeZoneInternal): New private method.
	(getTimeZone): Do the custom ID checking first, canonicalize
	ID for custom IDs as required by documentation.  Call
	getTimeZoneInternal to handle the rest.
	(getAvailableIDs(int)): Add locking.  Handle zoneinfo_dir != null.
	(getAvailableIDs(File,String,ArrayList)): New private method.
	(getAvailableIDs()): Add locking.  Handle zoneinfo_dir != null.
	* gnu/java/util/ZoneInfo.java: New file.

Added:
    trunk/libjava/classpath/gnu/java/util/ZoneInfo.java
    trunk/libjava/classpath/lib/gnu/java/util/ZoneInfo.class   (with props)
    trunk/libjava/gnu/java/util/ZoneInfo.h
Modified:
    trunk/libjava/ChangeLog
    trunk/libjava/Makefile.in
    trunk/libjava/classpath/ChangeLog
    trunk/libjava/classpath/java/util/Date.java
    trunk/libjava/classpath/java/util/SimpleTimeZone.java
    trunk/libjava/classpath/java/util/TimeZone.java
    trunk/libjava/classpath/lib/java/util/Date.class
    trunk/libjava/classpath/lib/java/util/SimpleTimeZone.class
    trunk/libjava/classpath/lib/java/util/TimeZone$1.class
    trunk/libjava/classpath/lib/java/util/TimeZone.class
    trunk/libjava/classpath/lib/java/util/VMTimeZone.class
    trunk/libjava/java/lang/System.java
    trunk/libjava/java/util/TimeZone.h
    trunk/libjava/java/util/VMTimeZone.h
    trunk/libjava/java/util/VMTimeZone.java
    trunk/libjava/posix.cc
    trunk/libjava/sources.am

Propchange: trunk/libjava/classpath/lib/gnu/java/util/ZoneInfo.class
            ('svn:mime-type' added)


Comment 3 gary@gcc.gnu.org 2007-02-23 15:13:36 UTC
Subject: Bug 28550

Author: gary
Date: Fri Feb 23 15:13:18 2007
New Revision: 122258

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122258
Log:
2007-02-22  Jakub Jelinek  <jakub@redhat.com>

	PR libgcj/17002
	PR classpath/28550
	* java/util/VMTimeZone.java (getDefaultTimeZoneId): To read
	/etc/localtime, use ZoneInfo.readTZFile instead of
	VMTimeZone.readtzFile.  Get better timezone name for /etc/localtime,
	either if it is a symlink or through /etc/sysconfig/clock.
	(readSysconfigClockFile): New static method.
	(readtzFile): Removed.
	* java/lang/System.java: Add gnu.java.util.zoneinfo.dir to comments.
	* posix.cc (_Jv_platform_initProperties): Set
	gnu.java.util.zoneinfo.dir.
	* sources.am (gnu_java_util_source_files): Add
	classpath/gnu/java/util/ZoneInfo.java.
	* Makefile.in: Regenerated.
	* java/util/VMTimeZone.h: Regenerated.
	* java/util/TimeZone.h: Regenerated.
	* gnu/java/util/ZoneInfo.h: Generated.


Modified:
    trunk/libjava/classpath/lib/gnu/java/util/ZoneInfo.class
    trunk/libjava/classpath/lib/java/lang/System$EnvironmentCollection.class
    trunk/libjava/classpath/lib/java/lang/System$EnvironmentMap.class
    trunk/libjava/classpath/lib/java/lang/System$EnvironmentSet.class
    trunk/libjava/classpath/lib/java/lang/System.class
    trunk/libjava/classpath/lib/java/util/Date.class
    trunk/libjava/classpath/lib/java/util/GregorianCalendar.class
    trunk/libjava/classpath/lib/java/util/SimpleTimeZone.class
    trunk/libjava/classpath/lib/java/util/TimeZone$1.class
    trunk/libjava/classpath/lib/java/util/TimeZone.class
    trunk/libjava/classpath/lib/java/util/VMTimeZone.class

Comment 4 cvs-commit@developer.classpath.org 2007-02-23 15:50:46 UTC
Subject: Bug 28550

CVSROOT:	/cvsroot/classpath
Module name:	classpath
Changes by:	Gary Benson <gbenson>	07/02/23 15:50:04

Modified files:
	.              : ChangeLog NEWS 
	java/lang      : System.java 
	java/util      : Date.java SimpleTimeZone.java TimeZone.java 
	vm/reference/java/util: VMTimeZone.java 
Added files:
	gnu/java/util  : ZoneInfo.java 

Log message:
	2007-02-23  Gary Benson  <gbenson@redhat.com>
		    Jakub Jelinek  <jakub@redhat.com>
	
		PR libgcj/17002
		PR classpath/28550
		* java/util/Date.java (parse): Properly parse 09:01:02 as
		hours/minutes/seconds, not as hours/minutes/year.
		* java/util/SimpleTimeZone.java (SimpleTimeZone): Simplify
		{start,end}TimeMode constructor by calling shorter constructor,
		set {start,end}TimeMode fields after it returns.
		(setStartRule): Don't adjust startTime into WALL_TIME.  Set
		startTimeMode to WALL_TIME.
		(endStartRule): Similarly.
		(getOffset): Handle properly millis + dstOffset overflowing into the
		next day.  Adjust startTime resp. endTime based on startTimeMode
		resp. endTimeMode.
		* java/util/TimeZone.java (zoneinfo_dir, availableIDs, aliases0): New
		static fields.
		(timezones): Remove synchronized keyword.  Set zoneinfo_dir.
		If non-null, set up aliases0 and don't put anything into
		timezones0.
		(defaultZone): Call getTimeZone instead of timezones().get.
		(getDefaultTimeZone): Fix parsing of EST5 or EST5EDT6.  Use
		getTimeZoneInternal instead of timezones().get.
		(parseTime): Parse correctly hour:minute.
		(getTimeZoneInternal): New private method.
		(getTimeZone): Do the custom ID checking first, canonicalize
		ID for custom IDs as required by documentation.  Call
		getTimeZoneInternal to handle the rest.
		(getAvailableIDs(int)): Add locking.  Handle zoneinfo_dir != null.
		(getAvailableIDs(File,String,ArrayList)): New private method.
		(getAvailableIDs()): Add locking.  Handle zoneinfo_dir != null.
		* vm/reference/java/util/VMTimeZone.java (getDefaultTimeZoneId):
		To read /etc/localtime, use ZoneInfo.readTZFile instead of
		VMTimeZone.readtzFile.  Get better timezone name for
		/etc/localtime, either if it is a symlink or through
		/etc/sysconfig/clock.
		(readSysconfigClockFile): New static method.
		(readtzFile): Removed.
		* gnu/java/util/ZoneInfo.java: New file.	
		* java/lang/System.java: Add gnu.java.util.zoneinfo.dir to comments.
	        * NEWS: Documented TimeZone interface changes.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/classpath/ChangeLog?cvsroot=classpath&r1=1.9128&r2=1.9129
http://cvs.savannah.gnu.org/viewcvs/classpath/NEWS?cvsroot=classpath&r1=1.177&r2=1.178
http://cvs.savannah.gnu.org/viewcvs/classpath/gnu/java/util/ZoneInfo.java?cvsroot=classpath&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/classpath/java/lang/System.java?cvsroot=classpath&r1=1.59&r2=1.60
http://cvs.savannah.gnu.org/viewcvs/classpath/java/util/Date.java?cvsroot=classpath&r1=1.25&r2=1.26
http://cvs.savannah.gnu.org/viewcvs/classpath/java/util/SimpleTimeZone.java?cvsroot=classpath&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/classpath/java/util/TimeZone.java?cvsroot=classpath&r1=1.36&r2=1.37
http://cvs.savannah.gnu.org/viewcvs/classpath/vm/reference/java/util/VMTimeZone.java?cvsroot=classpath&r1=1.4&r2=1.5



Comment 5 Jakub Jelinek 2007-06-22 12:17:28 UTC
Subject: Bug 28550

Author: jakub
Date: Fri Jun 22 12:17:00 2007
New Revision: 125946

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=125946
Log:
2007-02-24  Jakub Jelinek  <jakub@redhat.com>

libjava/classpath/
	* java/util/TimeZone.java (getDefaultDisplayName): Don't
	check if TimeZone is instanceof SimpleTimeZone.

2007-02-22  Jakub Jelinek  <jakub@redhat.com>

libjava/
	PR libgcj/17002
	PR classpath/28550
	* java/util/VMTimeZone.java (getDefaultTimeZoneId): To read
	/etc/localtime, use ZoneInfo.readTZFile instead of
	VMTimeZone.readtzFile.  Get better timezone name for /etc/localtime,
	either if it is a symlink or through /etc/sysconfig/clock.
	(readSysconfigClockFile): New static method.
	(readtzFile): Removed.
	* java/lang/System.java: Add gnu.java.util.zoneinfo.dir to comments.
	* posix.cc (_Jv_platform_initProperties): Set
	gnu.java.util.zoneinfo.dir.
	* sources.am (gnu_java_util_source_files): Add
	classpath/gnu/java/util/ZoneInfo.java.
	* Makefile.in: Regenerated.
libjava/classpath/
	* java/util/Date.java (parse): Properly parse 09:01:02 as
	hours/minutes/seconds, not as hours/minutes/year.
	* java/util/SimpleTimeZone.java (SimpleTimeZone): Simplify
	{start,end}TimeMode constructor by calling shorter constructor,
	set {start,end}TimeMode fields after it returns.
	(setStartRule): Don't adjust startTime into WALL_TIME.  Set
	startTimeMode to WALL_TIME.
	(endStartRule): Similarly.
	(getOffset): Handle properly millis + dstOffset overflowing into the
	next day.  Adjust startTime resp. endTime based on startTimeMode
	resp. endTimeMode.
	* java/util/TimeZone.java (zoneinfo_dir, availableIDs, aliases0): New
	static fields.
	(timezones): Remove synchronized keyword.  Set zoneinfo_dir.
	If non-null, set up aliases0 and don't put anything into
	timezones0.
	(defaultZone): Call getTimeZone instead of timezones().get.
	(getDefaultTimeZone): Fix parsing of EST5 or EST5EDT6.  Use
	getTimeZoneInternal instead of timezones().get.
	(parseTime): Parse correctly hour:minute.
	(getTimeZoneInternal): New private method.
	(getTimeZone): Do the custom ID checking first, canonicalize
	ID for custom IDs as required by documentation.  Call
	getTimeZoneInternal to handle the rest.
	(getAvailableIDs(int)): Add locking.  Handle zoneinfo_dir != null.
	(getAvailableIDs(File,String,ArrayList)): New private method.
	(getAvailableIDs()): Add locking.  Handle zoneinfo_dir != null.
	* gnu/java/util/ZoneInfo.java: New file.

2007-02-14  Jakub Jelinek  <jakub@redhat.com>
	Andrew Haley  <aph@redhat.com>

libjava/classpath/
	* java/util/TimeZone.java (getDateParams): Negate dayOfWeek.

2007-02-09  Jakub Jelinek  <jakub@redhat.com>

libjava/
	* java/util/VMTimeZone.java: Rewrite to handle both the old
	'TZif\0' format and the new one.
libjava/classpath/
	* java/util/TimeZone.java: Handle default (one hour) daylight
	savings.

	PR 23566
	* java/util/TimeZone.java (timezones): Regenerate from tzdata2007a.

Added:
    branches/redhat/fc6-4_1-branch/libjava/classpath/gnu/java/util/ZoneInfo.java
Modified:
    branches/redhat/fc6-4_1-branch/libjava/ChangeLog
    branches/redhat/fc6-4_1-branch/libjava/Makefile.in
    branches/redhat/fc6-4_1-branch/libjava/classpath/ChangeLog
    branches/redhat/fc6-4_1-branch/libjava/classpath/java/util/Date.java
    branches/redhat/fc6-4_1-branch/libjava/classpath/java/util/SimpleTimeZone.java
    branches/redhat/fc6-4_1-branch/libjava/classpath/java/util/TimeZone.java
    branches/redhat/fc6-4_1-branch/libjava/java/lang/System.java
    branches/redhat/fc6-4_1-branch/libjava/java/util/VMTimeZone.java
    branches/redhat/fc6-4_1-branch/libjava/posix.cc
    branches/redhat/fc6-4_1-branch/libjava/sources.am