This is the mail archive of the
java-patches@sources.redhat.com
mailing list for the Java project.
PATCH: PR 1411 Remove natTimeZone.cc (proposal)
- To: Java Patch List <java-patches at sourceware dot cygnus dot com>
- Subject: PATCH: PR 1411 Remove natTimeZone.cc (proposal)
- From: Warren Levy <warrenl at redhat dot com>
- Date: Wed, 27 Dec 2000 23:44:06 -0800 (PST)
- cc: bryce at albatross dot co dot nz
Folks,
Here is a patch I've come up with for removing natTimeZone.cc. I'm not
completely happy with it as it is isn't as clean as I usually like things
to be. Specifically, take a look at the patch to java/lang/natSystem.cc
and let me know if you have any ideas for improvement.
The issue is that we have to both recognize standard timezone names (per
the JCL) in case a user sets the user.timezone property, as well as
figuring out a valid timezone from the attributes of the timezone as
reported by the OS (e.g. GMT offset and whether daylight savings time
is used). I suppose I could just set the property here without doing
any verification and then do all these checks for the name and zone
attributes in a private method in java.util.TimeZone. This alternative
didn't seem as clean since some context is lost upon leaving the new
java.lang.System.getDefaultTimeZoneId (i.e. the zone name and GMT offset
are no longer available as separate entities and would have to be parsed
from the user.timezone property and distinguished from valid timezone
names in user.timezone that don't follow the PST8PDT format). The nit
that really bugs me the most is that I've had to free up memory in a
separate block from where I allocated it (I usually like to keep them
together); otherwise, I feel pretty good about the patch. It does take
care of the PR and supports timezones better than we've done to date.
For the record also note that I've reworked the algorithm that came from
Classpath for setting the timezone from the form e.g. "PST8PDT" to "PST"
per the standard usage in the JCL. I've added the standard timezone names
to accommodate this. This is a straightforward change and I don't see any
problems with it.
If I don't hear back from anyone with improvements or alternatives in a
day or two, I'll just go ahead and commit the patch (it can always be
adjusted later if someone comes up with something better down the road).
I don't have a new JNI version of getDefaultTimeZoneId to use for the
parallel Classpath patches. If anyone has an itch to do that, let me
know.
--warrenl
2000-12-27 Warren Levy <warrenl@redhat.com>
Fix for PR libgcj/1411:
* Makefile.am: Removed java/util/natTimeZone.cc.
* Makefile.in: Rebuilt.
* gnu/gcj/text/LocaleData_en_US.java (zoneStringsDefault): Added
missing localized timezone names.
* java/lang/natSystem.cc (getDefaultTimeZoneId): New private method.
(init_properties): Set user.timezone property.
* java/text/DateFormatSymbols.java (zoneStringsDefault): Added
default timezone names. Use standard ID names per JCL.
* java/util/TimeZone.java: Add standard ID names per JCL.
(getDefaultTimeZoneId): Removed.
* java/util/natTimeZone.cc: Removed.
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/egcs/libjava/Makefile.am,v
retrieving revision 1.119
diff -u -p -r1.119 Makefile.am
--- Makefile.am 2000/12/13 15:45:29 1.119
+++ Makefile.am 2000/12/28 06:20:05
@@ -1255,7 +1255,6 @@ java/net/natPlainDatagramSocketImpl.cc \
java/net/natPlainSocketImpl.cc \
java/text/natCollator.cc \
java/util/natGregorianCalendar.cc \
-java/util/natTimeZone.cc \
java/util/zip/natDeflater.cc \
java/util/zip/natInflater.cc
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/egcs/libjava/Makefile.in,v
retrieving revision 1.128
diff -u -p -r1.128 Makefile.in
--- Makefile.in 2000/12/13 15:45:29 1.128
+++ Makefile.in 2000/12/28 06:20:05
@@ -1015,7 +1015,6 @@ java/net/natPlainDatagramSocketImpl.cc \
java/net/natPlainSocketImpl.cc \
java/text/natCollator.cc \
java/util/natGregorianCalendar.cc \
-java/util/natTimeZone.cc \
java/util/zip/natDeflater.cc \
java/util/zip/natInflater.cc
@@ -1167,8 +1166,8 @@ java/lang/reflect/natArray.lo java/lang/
java/lang/reflect/natField.lo java/lang/reflect/natMethod.lo \
java/net/natInetAddress.lo java/net/natPlainDatagramSocketImpl.lo \
java/net/natPlainSocketImpl.lo java/text/natCollator.lo \
-java/util/natGregorianCalendar.lo java/util/natTimeZone.lo \
-java/util/zip/natDeflater.lo java/util/zip/natInflater.lo
+java/util/natGregorianCalendar.lo java/util/zip/natDeflater.lo \
+java/util/zip/natInflater.lo
libgcjx_la_OBJECTS = gnu/gcj/xlib/natClip.lo \
gnu/gcj/xlib/natColormap.lo gnu/gcj/xlib/natDisplay.lo \
gnu/gcj/xlib/natDrawable.lo gnu/gcj/xlib/natFont.lo \
@@ -1718,9 +1717,8 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_D
.deps/java/util/jar/JarException.P .deps/java/util/jar/JarFile.P \
.deps/java/util/jar/JarInputStream.P \
.deps/java/util/jar/JarOutputStream.P .deps/java/util/jar/Manifest.P \
-.deps/java/util/natGregorianCalendar.P .deps/java/util/natTimeZone.P \
-.deps/java/util/zip/Adler32.P .deps/java/util/zip/CRC32.P \
-.deps/java/util/zip/CheckedInputStream.P \
+.deps/java/util/natGregorianCalendar.P .deps/java/util/zip/Adler32.P \
+.deps/java/util/zip/CRC32.P .deps/java/util/zip/CheckedInputStream.P \
.deps/java/util/zip/CheckedOutputStream.P \
.deps/java/util/zip/Checksum.P \
.deps/java/util/zip/DataFormatException.P \
Index: gnu/gcj/text/LocaleData_en_US.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/gnu/gcj/text/LocaleData_en_US.java,v
retrieving revision 1.3
diff -u -p -r1.3 LocaleData_en_US.java
--- LocaleData_en_US.java 2000/03/07 19:55:25 1.3
+++ LocaleData_en_US.java 2000/12/28 06:20:05
@@ -21,6 +21,8 @@ public final class LocaleData_en_US exte
{
// These are for DateFormatSymbols.
static String[][] zoneStringsDefault = {
+ { "GMT", "Greenwich Mean Time", "GMT",
+ /**/ "Greenwich Mean Time", "GMT", "GMT" },
{ "PST", "Pacific Standard Time", "PST",
/**/ "Pacific Daylight Time", "PDT", "San Francisco" },
{ "MST", "Mountain Standard Time", "MST",
@@ -35,10 +37,18 @@ public final class LocaleData_en_US exte
/**/ "Eastern Standard Time", "EST", "Indianapolis" },
{ "PRT", "Atlantic Standard Time", "AST",
/**/ "Atlantic Daylight Time", "ADT", "Halifax" },
+ { "CNT", "Newfoundland Standard Time", "NST",
+ /**/ "Newfoundland Daylight Time", "NDT", "St. Johns" },
+ { "ECT", "Central European Standard Time", "CET",
+ /**/ "Central European Daylight Time", "CEST", "Paris" },
+ { "CTT", "China Standard Time", "CST",
+ /**/ "China Standard Time", "CST", "Shanghai" },
+ { "JST", "Japan Standard Time", "JST",
+ /**/ "Japan Standard Time", "JST", "Tokyo" },
{ "HST", "Hawaii Standard Time", "HST",
- /**/ "Hawaii Daylight Time", "HDT", "Honolulu" },
- { "AST", "Alaska Standard Time", "AST",
- /**/ "Alaska Daylight Time", "ADT", "Anchorage" }
+ /**/ "Hawaii Standard Time", "HST", "Honolulu" },
+ { "AST", "Alaska Standard Time", "AKST",
+ /**/ "Alaska Daylight Time", "AKDT", "Anchorage" }
};
private static final Object[][] contents =
Index: java/lang/natSystem.cc
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/natSystem.cc,v
retrieving revision 1.31
diff -u -p -r1.31 natSystem.cc
--- natSystem.cc 2000/11/29 04:53:37 1.31
+++ natSystem.cc 2000/12/28 06:20:05
@@ -10,6 +10,7 @@ details. */
#include <config.h>
+#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -28,6 +29,17 @@ details. */
#include <langinfo.h>
#endif
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
#include <gcj/cni.h>
#include <jvm.h>
#include <java-props.h>
@@ -38,6 +50,7 @@ details. */
#include <java/lang/NullPointerException.h>
#include <java/lang/StringBuffer.h>
#include <java/util/Properties.h>
+#include <java/util/TimeZone.h>
#include <java/io/PrintStream.h>
#include <java/io/InputStream.h>
@@ -214,6 +227,84 @@ getpwuid_adaptor(T_passwd * (*getpwuid_r
}
#endif
+/*
+ * This method returns a time zone string that is used by init_properties
+ * to set the default timezone property 'user.timezone'. That value is
+ * used by default as a key into the timezone table used by the
+ * java::util::TimeZone class.
+ */
+static char *
+getDefaultTimeZoneId (void)
+{
+ time_t current_time;
+ char **tzinfo, *tzid;
+ long tzoffset;
+ jboolean usesDaylight = false;
+
+ current_time = time(0);
+
+ mktime(localtime(¤t_time));
+ tzinfo = tzname;
+ tzoffset = timezone;
+
+ if ((tzoffset % 3600) == 0)
+ tzoffset = tzoffset / 3600;
+
+ if (!strcmp(tzinfo[0], tzinfo[1]))
+ {
+ tzid = (char*) _Jv_Malloc (strlen(tzinfo[0]) + 6);
+ if (!tzid)
+ return NULL;
+
+ sprintf(tzid, "%s%ld", tzinfo[0], tzoffset);
+ }
+ else
+ {
+ tzid = (char*) _Jv_Malloc (strlen(tzinfo[0]) + strlen(tzinfo[1]) + 6);
+ if (!tzid)
+ return NULL;
+
+ sprintf(tzid, "%s%ld%s", tzinfo[0], tzoffset, tzinfo[1]);
+ usesDaylight = true;
+ }
+
+ // Check if tzid is a valid timezone. Make sure the ID's match since
+ // getTimeZone returns GMT if no match is found.
+ jstring tzidString = JvNewStringUTF (tzid);
+ java::util::TimeZone *tz = java::util::TimeZone::getTimeZone (tzidString);
+ if (tz->getID ()->equals (tzidString))
+ return tzid;
+
+ // Check if the base part of tzid is a valid timezone that matches
+ // with daylight usage. Make sure the ID's match since getTimeZone
+ // returns GMT if no match is found.
+ tzidString = JvNewStringUTF (tzinfo[0]);
+ tz = java::util::TimeZone::getTimeZone (tzidString);
+ if (tz->getID ()->equals (tzidString))
+ {
+ jboolean tzUsesDaylight = tz->useDaylightTime ();
+ if (usesDaylight && tzUsesDaylight || !usesDaylight && !tzUsesDaylight)
+ return tzinfo[0];
+ }
+
+ // If no match, see if a valid timezone has the same attributes as this
+ // and then use it instead.
+ jstringArray IDs =
+ java::util::TimeZone::getAvailableIDs ((jint) (timezone * -1000L));
+ for (int i = 0; i < IDs->length; ++i)
+ {
+ jstring *elts = elements (IDs);
+ jboolean IDusesDaylight =
+ java::util::TimeZone::getTimeZone (elts[i])->useDaylightTime ();
+ if (usesDaylight && IDusesDaylight || !usesDaylight && !IDusesDaylight)
+ {
+ return (char *) JvGetStringChars (elts[i]);
+ }
+ }
+
+ return NULL;
+}
+
void
java::lang::System::init_properties (void)
{
@@ -363,6 +454,14 @@ java::lang::System::init_properties (voi
{
SET ("user.language", "en");
}
+
+ // Set the "user.timezone" property.
+ char *tzid = getDefaultTimeZoneId ();
+ if (tzid != NULL)
+ {
+ SET ("user.timezone", tzid);
+ _Jv_Free (tzid);
+ }
// Set some properties according to whatever was compiled in with
// `-D'.
Index: java/text/DateFormatSymbols.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/text/DateFormatSymbols.java,v
retrieving revision 1.8
diff -u -p -r1.8 DateFormatSymbols.java
--- DateFormatSymbols.java 2000/12/06 21:14:14 1.8
+++ DateFormatSymbols.java 2000/12/28 06:20:05
@@ -81,24 +81,18 @@ public class DateFormatSymbols extends O
/**/ "Eastern Standard Time", "EST", "Indianapolis" },
{ "PRT", "Atlantic Standard Time", "AST",
/**/ "Atlantic Daylight Time", "ADT", "Halifax" },
+ { "CNT", "Newfoundland Standard Time", "NST",
+ /**/ "Newfoundland Daylight Time", "NDT", "St. Johns" },
+ { "ECT", "Central European Standard Time", "CET",
+ /**/ "Central European Daylight Time", "CEST", "Paris" },
+ { "CTT", "China Standard Time", "CST",
+ /**/ "China Standard Time", "CST", "Shanghai" },
+ { "JST", "Japan Standard Time", "JST",
+ /**/ "Japan Standard Time", "JST", "Tokyo" },
{ "HST", "Hawaii Standard Time", "HST",
- /**/ "Hawaii Daylight Time", "HDT", "Honolulu" },
- { "AST", "Alaska Standard Time", "AST",
- /**/ "Alaska Daylight Time", "ADT", "Anchorage" },
- { "PST8PDT", "Pacific Standard Time", "PST",
- /******/ "Pacific Daylight Time", "PDT", "San Francisco" },
- { "MST7MDT", "Mountain Standard Time", "MST",
- /******/ "Mountain Daylight Time", "MDT", "Denver" },
- { "CST6CDT", "Central Standard Time", "CST",
- /******/ "Central Daylight Time", "CDT", "Chicago" },
- { "EST5EDT", "Eastern Standard Time", "EST",
- /******/ "Eastern Daylight Time", "EDT", "Boston" },
- { "AST4ADT", "Atlantic Standard Time", "AST",
- /******/ "Atlantic Daylight Time", "ADT", "Halifax" },
- { "HST10HDT", "Hawaii Standard Time", "HST",
- /*******/ "Hawaii Daylight Time", "HDT", "Honolulu" },
- { "AST9ADT", "Alaska Standard Time", "AKST",
- /******/ "Alaska Daylight Time", "AKDT", "Anchorage" }
+ /**/ "Hawaii Standard Time", "HST", "Honolulu" },
+ { "AST", "Alaska Standard Time", "AKST",
+ /**/ "Alaska Daylight Time", "AKDT", "Anchorage" }
};
// These are each arrays with a value for SHORT, MEDIUM, LONG, FULL,
Index: java/util/TimeZone.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/util/TimeZone.java,v
retrieving revision 1.9
diff -u -p -r1.9 TimeZone.java
--- TimeZone.java 2000/12/28 05:55:56 1.9
+++ TimeZone.java 2000/12/28 06:20:05
@@ -100,9 +100,10 @@ public abstract class TimeZone implement
timezones.put("Pacific/Rarotonga", tz);
timezones.put("Pacific/Tahiti", tz);
tz = new SimpleTimeZone
- (-9000 * 3600, "America/Juneau",
+ (-9000 * 3600, "AST",
Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
+ timezones.put("AST", tz);
timezones.put("America/Juneau", tz);
timezones.put("America/Anchorage", tz);
timezones.put("America/Nome", tz);
@@ -112,10 +113,10 @@ public abstract class TimeZone implement
tz = new SimpleTimeZone(-8500 * 3600, "Pacific/Marquesas");
timezones.put("Pacific/Marquesas", tz);
tz = new SimpleTimeZone
- (-8000 * 3600, "PST8PDT",
+ (-8000 * 3600, "PST",
Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
- timezones.put("PST8PDT", tz);
+ timezones.put("PST", tz);
timezones.put("America/Dawson", tz);
timezones.put("America/Los_Angeles", tz);
timezones.put("America/Tijuana", tz);
@@ -124,15 +125,15 @@ public abstract class TimeZone implement
timezones.put("US/Pacific-New", tz);
tz = new SimpleTimeZone(-8000 * 3600, "Pacific/Pitcairn");
timezones.put("Pacific/Pitcairn", tz);
- tz = new SimpleTimeZone(-7000 * 3600, "MST");
- timezones.put("MST", tz);
+ tz = new SimpleTimeZone(-7000 * 3600, "PNT");
+ timezones.put("PNT", tz);
timezones.put("America/Dawson_Creek", tz);
timezones.put("America/Phoenix", tz);
tz = new SimpleTimeZone
- (-7000 * 3600, "MST7MDT",
+ (-7000 * 3600, "MST",
Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
- timezones.put("MST7MDT", tz);
+ timezones.put("MST", tz);
timezones.put("America/Boise", tz);
timezones.put("America/Chihuahua", tz);
timezones.put("America/Denver", tz);
@@ -152,10 +153,10 @@ public abstract class TimeZone implement
timezones.put("America/Tegucigalpa", tz);
timezones.put("Pacific/Galapagos", tz);
tz = new SimpleTimeZone
- (-6000 * 3600, "CST6CDT",
+ (-6000 * 3600, "CST",
Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
- timezones.put("CST6CDT", tz);
+ timezones.put("CST", tz);
timezones.put("America/Cambridge_Bay", tz);
timezones.put("America/Cancun", tz);
timezones.put("America/Chicago", tz);
@@ -181,8 +182,8 @@ public abstract class TimeZone implement
Calendar.APRIL, 1, 0, 0 * 3600,
Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600);
timezones.put("America/Havana", tz);
- tz = new SimpleTimeZone(-5000 * 3600, "EST");
- timezones.put("EST", tz);
+ tz = new SimpleTimeZone(-5000 * 3600, "IET");
+ timezones.put("IET", tz);
timezones.put("America/Bogota", tz);
timezones.put("America/Cayman", tz);
timezones.put("America/Guayaquil", tz);
@@ -197,10 +198,10 @@ public abstract class TimeZone implement
timezones.put("America/Port-au-Prince", tz);
timezones.put("America/Porto_Acre", tz);
tz = new SimpleTimeZone
- (-5000 * 3600, "EST5EDT",
+ (-5000 * 3600, "EST",
Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
- timezones.put("EST5EDT", tz);
+ timezones.put("EST", tz);
timezones.put("America/Detroit", tz);
timezones.put("America/Louisville", tz);
timezones.put("America/Montreal", tz);
@@ -240,9 +241,10 @@ public abstract class TimeZone implement
timezones.put("America/Asuncion", tz);
timezones.put("America/Boa_Vista", tz);
tz = new SimpleTimeZone
- (-4000 * 3600, "America/Thule",
+ (-4000 * 3600, "PRT",
Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
+ timezones.put("PRT", tz);
timezones.put("America/Thule", tz);
timezones.put("America/Glace_Bay", tz);
timezones.put("America/Goose_Bay", tz);
@@ -574,7 +576,8 @@ public abstract class TimeZone implement
Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
timezones.put("Asia/Krasnoyarsk", tz);
- tz = new SimpleTimeZone(8000 * 3600, "Antarctica/Casey");
+ tz = new SimpleTimeZone(8000 * 3600, "CTT");
+ timezones.put("CTT", tz);
timezones.put("Antarctica/Casey", tz);
timezones.put("Asia/Brunei", tz);
timezones.put("Asia/Chungking", tz);
@@ -715,24 +718,10 @@ public abstract class TimeZone implement
String tzid = System.getProperty("user.timezone");
if (tzid == null)
- tzid = getDefaultTimeZoneId();
-
- if (tzid == null)
tzid = "GMT";
defaultZone = getTimeZone(tzid);
}
-
- /* This method returns us a time zone id string which is in the
- form <standard zone name><GMT offset><daylight time zone name>.
- The GMT offset is in seconds, except where it is evenly divisible
- by 3600, then it is in hours. If the zone does not observe
- daylight time, then the daylight zone name is omitted. Examples:
- in Chicago, the timezone would be CST6CDT. In Indianapolis
- (which does not have Daylight Savings Time) the string would
- be EST5
- */
- private static native String getDefaultTimeZoneId();
/**
* Gets the time zone offset, for current date, modified in case of