aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/lang/System.java
diff options
context:
space:
mode:
authorWarren Levy <warrenl@redhat.com>2001-01-09 07:07:51 +0000
committerWarren Levy <warrenl@gcc.gnu.org>2001-01-09 07:07:51 +0000
commit3824a4860080dbc3b140e1eb7fa2b4efed115b81 (patch)
tree59c853c9c93930e645e808160cee16a1368a3fc2 /libjava/java/lang/System.java
parent61db460830bf37e7803f95472cead5cc3ba87da3 (diff)
downloadgcc-3824a4860080dbc3b140e1eb7fa2b4efed115b81.zip
gcc-3824a4860080dbc3b140e1eb7fa2b4efed115b81.tar.gz
gcc-3824a4860080dbc3b140e1eb7fa2b4efed115b81.tar.bz2
re PR libgcj/1411 (natTimeZone.cc should be removed)
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/System.java (getDefaultTimeZoneId): New private method. * java/lang/natSystem.cc (getSystemTimeZone): New private method. (init_properties): Set user.timezone property. * java/text/DateFormatSymbols.java (zoneStringsDefault): Added default timezone names; removed non-standard ones. Use standard ID names per JCL. * java/util/Date.java (toGMTString): Removed zoneGMT variable. (UTC): Ditto. * java/util/TimeZone.java: Add standard ID names per JCL; removed non-standard ones. (getDefaultTimeZoneId): Removed. (zoneGMT): Removed. (getDefaultTimeZoneId): Removed. * java/util/natTimeZone.cc: Removed. From-SVN: r38816
Diffstat (limited to 'libjava/java/lang/System.java')
-rw-r--r--libjava/java/lang/System.java80
1 files changed, 79 insertions, 1 deletions
diff --git a/libjava/java/lang/System.java b/libjava/java/lang/System.java
index ab1ca99..162bc1f 100644
--- a/libjava/java/lang/System.java
+++ b/libjava/java/lang/System.java
@@ -1,6 +1,6 @@
// System.java - System-specific info.
-/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj.
@@ -20,6 +20,7 @@ import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.util.Properties;
import java.util.PropertyPermission;
+import java.util.TimeZone;
/**
* @author Tom Tromey <tromey@cygnus.com>
@@ -41,6 +42,83 @@ public final class System
public static native long currentTimeMillis ();
+ // FIXME: When merging with Classpath, remember to remove the call to
+ // getDefaultTimeZoneId from java.util.Timezone.
+ private static native String getSystemTimeZone ();
+
+ // Get the System Timezone as reported by the OS. It should be in
+ // the form PST8PDT so we'll need to parse it and check that it's valid.
+ // The result is used to set the user.timezone property in init_properties.
+ // FIXME: Using the code from Classpath for generating the System
+ // Timezone IMO is suboptimal because it ignores whether the rules for
+ // DST match up.
+ private static String getDefaultTimeZoneId ()
+ {
+ String sysTimeZoneId = getSystemTimeZone ();
+
+ // Check if this is a valid timezone. Make sure the IDs match
+ // since getTimeZone returns GMT if no match is found.
+ TimeZone tz = TimeZone.getTimeZone (sysTimeZoneId);
+ if (tz.getID ().equals (sysTimeZoneId))
+ return sysTimeZoneId;
+
+ // Check if the base part of sysTimeZoneId is a valid timezone that
+ // matches with daylight usage and rawOffset. Make sure the IDs match
+ // since getTimeZone returns GMT if no match is found.
+ // First find start of GMT offset info and any Daylight zone name.
+ int startGMToffset = 0;
+ int sysTimeZoneIdLength = sysTimeZoneId.length();
+ for (int i = 0; i < sysTimeZoneIdLength && startGMToffset == 0; i++)
+ {
+ if (Character.isDigit (sysTimeZoneId.charAt (i)))
+ startGMToffset = i;
+ }
+
+ int startDaylightZoneName = 0;
+ boolean usesDaylight = false;
+ for (int i = sysTimeZoneIdLength - 1;
+ i >= 0 && !Character.isDigit (sysTimeZoneId.charAt (i)); --i)
+ {
+ startDaylightZoneName = i;
+ }
+ if (startDaylightZoneName > 0)
+ usesDaylight = true;
+
+ int GMToffset = Integer.parseInt (startDaylightZoneName == 0 ?
+ sysTimeZoneId.substring (startGMToffset) :
+ sysTimeZoneId.substring (startGMToffset, startDaylightZoneName));
+
+ // Offset could be in hours or seconds. Convert to millis.
+ if (GMToffset < 24)
+ GMToffset *= 60 * 60;
+ GMToffset *= -1000;
+
+ String tzBasename = sysTimeZoneId.substring (0, startGMToffset);
+ tz = TimeZone.getTimeZone (tzBasename);
+ if (tz.getID ().equals (tzBasename) && tz.getRawOffset () == GMToffset)
+ {
+ boolean tzUsesDaylight = tz.useDaylightTime ();
+ if (usesDaylight && tzUsesDaylight || !usesDaylight && !tzUsesDaylight)
+ return tzBasename;
+ }
+
+ // If no match, see if a valid timezone has the same attributes as this
+ // and then use it instead.
+ String[] IDs = TimeZone.getAvailableIDs (GMToffset);
+ for (int i = 0; i < IDs.length; ++i)
+ {
+ // FIXME: The daylight savings rules may not match the rules
+ // for the desired zone.
+ boolean IDusesDaylight =
+ TimeZone.getTimeZone (IDs[i]).useDaylightTime ();
+ if (usesDaylight && IDusesDaylight || !usesDaylight && !IDusesDaylight)
+ return IDs[i];
+ }
+
+ // If all else fails, return null.
+ return null;
+ }
+
public static void exit (int status)
{
Runtime.getRuntime().exit(status);