Commit 3824a486 by Warren Levy Committed by Warren Levy

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
parent 61db4608
2001-01-08 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/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.
2001-01-08 Bryce McKinlay <bryce@albatross.co.nz>
* java/lang/Class.h (_Jv_InitClass): Use __builtin_expect.
......
......@@ -1260,7 +1260,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
......
......@@ -1020,7 +1020,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
......@@ -1172,8 +1171,8 @@ java/lang/reflect/natArray.lo java/lang/reflect/natConstructor.lo \
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 \
......
......@@ -21,6 +21,8 @@ public final class LocaleData_en_US extends ListResourceBundle
{
// 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 extends ListResourceBundle
/**/ "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 =
......
// 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);
......
// natSystem.cc - Native code implementing System class.
/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj.
......@@ -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,50 @@ getpwuid_adaptor(T_passwd * (*getpwuid_r)(T_uid user_id, T_passwd *pwd_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.
*/
jstring
java::lang::System::getSystemTimeZone (void)
{
time_t current_time;
char **tzinfo, *tzid;
long tzoffset;
current_time = time(0);
mktime(localtime(&current_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]);
}
jstring retval = JvNewStringUTF (tzid);
_Jv_Free (tzid);
return retval;
}
void
java::lang::System::init_properties (void)
{
......@@ -364,6 +421,11 @@ java::lang::System::init_properties (void)
SET ("user.language", "en");
}
// Set the "user.timezone" property.
jstring timezone = getDefaultTimeZoneId ();
if (timezone != NULL)
newprops->put (JvNewStringLatin1 ("user.timezone"), timezone);
// Set some properties according to whatever was compiled in with
// `-D'.
for (int i = 0; _Jv_Compiler_Properties[i]; ++i)
......
......@@ -81,24 +81,18 @@ public class DateFormatSymbols extends Object
/**/ "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,
......
/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj.
......@@ -461,7 +461,7 @@ public class Date implements java.io.Serializable, Cloneable
// This method is deprecated. We don't care if it is very slow.
SimpleDateFormat fmt = new SimpleDateFormat ("d MMM yyyy HH:mm:ss 'GMT'",
Locale.US);
fmt.setTimeZone(TimeZone.zoneGMT);
fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
return fmt.format(this);
}
......@@ -476,7 +476,7 @@ public class Date implements java.io.Serializable, Cloneable
public static long UTC (int year, int month, int date,
int hours, int minutes, int seconds)
{
GregorianCalendar cal = new GregorianCalendar (TimeZone.zoneGMT);
GregorianCalendar cal = new GregorianCalendar (TimeZone.getTimeZone("GMT"));
cal.set(year+1900, month, date, hours, minutes, seconds);
return cal.getTimeInMillis();
}
......
/* Copyright (C) 2000 Free Software Foundation
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
#include <config.h>
#include <gcj/cni.h>
#include <java/util/TimeZone.h>
#include <stdio.h>
#include <string.h>
#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
/*
* This method returns a time zone string that is used by the static
* initializer in java.util.TimeZone to create the default timezone
* instance. This is a key into the timezone table used by
* that class.
*/
jstring
java::util::TimeZone::getDefaultTimeZoneId (void)
{
time_t current_time;
char **tzinfo, *tzid;
long tzoffset;
jstring retval;
current_time = time(0);
mktime(localtime(&current_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]);
}
retval = JvNewStringUTF (tzid);
_Jv_Free (tzid);
return retval;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment