TimeZone

Mark Wielaard mark@klomp.org
Tue Aug 24 00:33:00 GMT 2004


Hi,

Our TimeZone support is not optimal and a little fragile. See the
TimeZone meta-bug http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16990

This patch tries to solve issues PR17002
"java.util.TimeZone.getDefault() is broken".

TimeZone.getDefault() has two bugs mapping short timezone names (plus
GMT-offset) to long/display timezone information.

- The interface between getDefault() and the native getDefaultTimeZoneId() is
unclear. Which means that the result of getDefaultTimeZoneId() is not always
mapped to the correct TimeZone.

- getDefaultTimeZoneId() should always return the standard (std) short timezone
name, never the alternative (dst) Daylight Savings Time name. When it returns a
dst name the getDefault() mapping from short name to long/display timezone name
also breaks.

Since using "standard" methods to get at the time zone and gmt offset is
fragile the patch also introduces some other ways to get at the timezone
data/name. First (as also done in the past) it tries to use the System
property "user.timezone", then the environment variable "TZ", then it
tries to read the /etc/timezone, then it tries to parse the
/etc/localtime (tz)file and finally, if all else fails, it uses the
(rewritten) native platform specific getDefaultTimeZoneId() function.

In the end we might just want to adopt the Olson tz data timezone
package completely as glibc does. Unfortunately neither the tzcode nor
glibc has any public interface to access all the available data if it is
available on the system. But the new readtzFile() method might be a
start to get our own parser for this data.

2004-08-22  Mark Wielaard  <mark@klomp.org>

       * java/util/TimeZone.java (defaultZone): Try a couple of ways to get
       a TimeZoneId string and then try to convert that to a TimeZone with
       getDefaultSystemTimeZone(String).
       (timezones0): Changed type from Hashtable to HashMap.
       (timezones): Create HashMap, not Hashtable.
       (getDefaultTimeZone): New method, rewritten from CNI version.
       (readTimeZoneFile): New method.
       (readtzFile): Likewise.
       (skipFully): Likewise.
       * java/util/natTimeZone.cc (getSystemTimeZone): Renamed to
       getDefaultTimeZoneId and rewritten.
       (getDefaultTimeZoneId): Rewritten in java.

OK to commit?

If this works out on all platforms I like to restructure it to refactor
out the pieces that should go into a VMTimeZone class so it can be
adopted by GNU Classpath upstream.

Cheers,

Mark
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TimeZone.patch
Type: text/x-patch
Size: 24797 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20040824/79f0f7a5/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20040824/79f0f7a5/attachment.sig>


More information about the Java-patches mailing list