re GNATS java.util/47 (Date.toString() returns embedded newline)

Fix for PR java.util/47:
	* configure, include/config.h: Rebuilt.
	* configure.in: Don't look for ctime or ctime_r.
	* Makefile.in: Rebuilt.
	* Makefile.am (nat_source_files): Don't mention natDate.cc.
	* java/util/natDate.cc: Removed.
	* java/util/TimeZone.java (tzIDs, rawOffsets, timeZones): New
	static fields.
	(getAvailableIDs): Rewrote.
	(getTimeZone): Rewrote.
	* java/util/Date.java (toGMTString): New method.
	(toLocaleString): New method.
	(toString): Rewrote.

From-SVN: r29656
This commit is contained in:
Tom Tromey 1999-09-24 19:12:23 +00:00 committed by Tom Tromey
parent aaaec1142d
commit 98e7ae2962
10 changed files with 343 additions and 372 deletions

View File

@ -1,3 +1,19 @@
1999-09-24 Tom Tromey <tromey@cygnus.com>
Fix for PR java.util/47:
* configure, include/config.h: Rebuilt.
* configure.in: Don't look for ctime or ctime_r.
* Makefile.in: Rebuilt.
* Makefile.am (nat_source_files): Don't mention natDate.cc.
* java/util/natDate.cc: Removed.
* java/util/TimeZone.java (tzIDs, rawOffsets, timeZones): New
static fields.
(getAvailableIDs): Rewrote.
(getTimeZone): Rewrote.
* java/util/Date.java (toGMTString): New method.
(toLocaleString): New method.
(toString): Rewrote.
1999-09-23 Tom Tromey <tromey@cygnus.com>
* configure: Rebuilt.

View File

@ -802,7 +802,6 @@ java/net/natInetAddress.cc \
java/net/natPlainDatagramSocketImpl.cc \
java/net/natPlainSocketImpl.cc \
java/text/natCollator.cc \
java/util/natDate.cc \
java/util/natGregorianCalendar.cc \
java/util/zip/natDeflater.cc \
java/util/zip/natInflater.cc

View File

@ -616,7 +616,6 @@ java/net/natInetAddress.cc \
java/net/natPlainDatagramSocketImpl.cc \
java/net/natPlainSocketImpl.cc \
java/text/natCollator.cc \
java/util/natDate.cc \
java/util/natGregorianCalendar.cc \
java/util/zip/natDeflater.cc \
java/util/zip/natInflater.cc

View File

@ -46,9 +46,6 @@
/* Define if using POSIX threads on Linux. */
#undef LINUX_THREADS
/* Define if you have the `ctime_r' function. */
#undef HAVE_CTIME_R
/* Define if you have the `gmtime_r' function. */
#undef HAVE_GMTIME_R

510
libjava/configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -282,7 +282,6 @@ if test -n "${with_cross_host}"; then
AC_DEFINE(HAVE_MEMMOVE)
AC_DEFINE(HAVE_MEMCPY)
AC_DEFINE(HAVE_STRERROR)
AC_DEFINE(HAVE_CTIME_R)
AC_DEFINE(HAVE_GMTIME_R)
AC_DEFINE(HAVE_LOCALTIME_R)
dnl This is only for POSIX threads.
@ -303,7 +302,6 @@ if test -n "${with_cross_host}"; then
fi
else
AC_CHECK_FUNCS(strerror ioctl select fstat open fsync sleep)
AC_CHECK_FUNCS(ctime_r ctime, break)
AC_CHECK_FUNCS(gmtime_r localtime_r readdir_r getpwuid_r)
AC_CHECK_FUNCS(access stat mkdir rename rmdir unlink realpath)
AC_CHECK_FUNCS(inet_aton inet_addr, break)

View File

@ -61,9 +61,6 @@
/* Define if using POSIX threads on Linux. */
#undef LINUX_THREADS
/* Define if you have the `ctime_r' function. */
#undef HAVE_CTIME_R
/* Define if you have the `gmtime_r' function. */
#undef HAVE_GMTIME_R
@ -131,12 +128,6 @@
/* Define if you have the access function. */
#undef HAVE_ACCESS
/* Define if you have the ctime function. */
#undef HAVE_CTIME
/* Define if you have the ctime_r function. */
#undef HAVE_CTIME_R
/* Define if you have the fstat function. */
#undef HAVE_FSTAT

View File

@ -445,10 +445,33 @@ public class Date implements java.io.Serializable, Cloneable
+ cal.get(Calendar.DST_OFFSET)/(60*1000));
}
public native String toString ();
public String toString ()
{
// This is slow, but does it matter? There is no particularly
// fast way to do it, because we need the timezone offset, which
// we don't store. Unix ctime() doesn't provide this information.
SimpleDateFormat fmt = new SimpleDateFormat ("E MMM dd HH:mm:ss z yyyy",
Locale.US);
fmt.setTimeZone(TimeZone.getDefault());
return fmt.format(this);
}
// TODO: toLocaleString
// TODO: toGMTString
public String toGMTString ()
{
// 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);
return fmt.format(this);
}
public String toLocaleString ()
{
// This method is deprecated. We don't care if it is very slow.
DateFormat fmt = DateFormat.getDateTimeInstance();
fmt.setTimeZone(TimeZone.getDefault());
return fmt.format(this);
}
public static long UTC (int year, int month, int date,
int hours, int minutes, int seconds)

View File

@ -68,21 +68,57 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable
public abstract boolean inDaylightTime (Date date);
public static TimeZone getTimeZone (String ID)
public static synchronized TimeZone getTimeZone (String ID)
{
return zoneGMT; // FIXME
int i;
for (i = 0; i < tzIDs.length; ++i)
{
if (ID.equals(tzIDs[i]))
break;
}
if (i == tzIDs.length)
return null;
if (timeZones[i] == null)
{
if (ID.equals("GMT"))
timeZones[i] = zoneGMT;
else
timeZones[i] = new SimpleTimeZone (rawOffsets[i], tzIDs[i]);
}
return timeZones[i];
}
public static String[] getAvailableIDs()
{ // FIXME - only knows about GMT
String[] zones = new String[1];
zones[0] = "GMT";
return zones;
{
return (String[]) tzIDs.clone();
}
public static String[] getAvailableIDs(int rawOffset)
{
return rawOffset == 0 ? getAvailableIDs() : new String[0]; // FIXME
int first, last;
for (first = 0; first < rawOffsets.length; ++first)
{
if (rawOffset == rawOffsets[first])
break;
}
if (first == rawOffsets.length)
return new String[0];
for (last = first + 1; last < rawOffsets.length; ++last)
{
if (rawOffset != rawOffsets[last])
break;
}
String[] r = new String[last - first];
for (int i = first; i < last; ++i)
{
r[i - first] = tzIDs[i];
}
return r;
}
private static synchronized TimeZone setDefault()
@ -117,4 +153,31 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable
}
// public Object clone ();
// Names of timezones. This array is kept in parallel with
// rawOffsets. This list comes from the JCL 1.1 book.
private static final String[] tzIDs =
{
"MIT", "HST", "AST", "PST", "PNT",
"MST", "CST", "EST", "IET", "PRT",
"CNT", "AGT", "BET", "CAT", "GMT",
"ECT", "EET", "ART", "EAT", "MET",
"NET", "PLT", "IST", "BST", "VST",
"CTT", "JST", "ACT", "AET", "SST",
"NST"
};
// This holds raw offsets in milliseconds.
// 3600000 == 60 * 60 * 1000
private static final int[] rawOffsets =
{
-11 * 3600000, -10 * 3600000, -9 * 3600000, -8 * 3600000, -7 * 3600000,
-7 * 3600000, -6 * 3600000, -5 * 3600000, -5 * 3600000, -4 * 3600000,
-35 * 360000, -3 * 3600000, -3 * 3600000, -1 * 3600000, 0,
1 * 3600000, 1 * 3600000, 2 * 3600000, 3 * 3600000, 35 * 360000,
4 * 3600000, 5 * 3600000, 55 * 360000, 6 * 3600000, 7 * 3600000,
8 * 3600000, 9 * 3600000, 95 * 360000, 10 * 3600000, 11 * 3600000,
12 * 3600000
};
// This caches all the corresponding zone objects.
private static TimeZone[] timeZones = new TimeZone[tzIDs.length];
}

View File

@ -1,67 +0,0 @@
/* Copyright (C) 1998, 1999 Cygnus Solutions
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>
// We want to make sure to pick up the POSIX ctime_r. Some systems,
// such as Solaris 2.6, have their own version as well.
#ifdef HAVE_CTIME_R
#define _POSIX_PTHREAD_SEMANTICS
#endif
#include <gcj/cni.h>
#include <java/util/Date.h>
#include <java/lang/String.h>
#include <time.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#if HAVE_CTIME_R
/* Use overload resolution to find out the signature of ctime_r. */
/* This is Posix ctime_r(). */
template <typename T_clock, typename T_buf, size_t buflen>
static inline char *
ctime_adaptor (char* (*ctime_r)(T_clock *clock, T_buf *buf),
time_t *clock, char (&buf)[buflen])
{
return ctime_r (clock, buf);
}
/* This is an old-style ctime_r, used on IRIX 5.2. */
template <typename T_clock, typename T_buf, typename T_buflen, size_t buflen>
static inline char *
ctime_adaptor (char* (*ctime_r)(T_clock *clock, T_buf *buf, T_buflen len),
time_t *clock, char (&buf)[buflen])
{
return ctime_r (clock, buf, buflen);
}
#endif
jstring
java::util::Date::toString()
{
#ifdef HAVE_CTIME_R
time_t t = millis / 1000;
char buf[30];
return JvNewStringLatin1 (ctime_adaptor (ctime_r, &t, buf));
#elif defined (HAVE_CTIME)
// FIXME: this isn't thread-safe.
time_t t = millis / 1000;
return JvNewStringLatin1 (ctime (&t));
#else
return NULL;
#endif
}