aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/util/TimeZone.java
diff options
context:
space:
mode:
authorTom Tromey <tromey@cygnus.com>1999-09-24 19:12:23 +0000
committerTom Tromey <tromey@gcc.gnu.org>1999-09-24 19:12:23 +0000
commit98e7ae2962ad70fed5e3d776bf6992a2a154d629 (patch)
tree1ae1fb27538f4637b0c7cebaa4d290138da435a5 /libjava/java/util/TimeZone.java
parentaaaec1142d3e7b9174ecd74fd21c6c39d696d56d (diff)
downloadgcc-98e7ae2962ad70fed5e3d776bf6992a2a154d629.zip
gcc-98e7ae2962ad70fed5e3d776bf6992a2a154d629.tar.gz
gcc-98e7ae2962ad70fed5e3d776bf6992a2a154d629.tar.bz2
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
Diffstat (limited to 'libjava/java/util/TimeZone.java')
-rw-r--r--libjava/java/util/TimeZone.java77
1 files changed, 70 insertions, 7 deletions
diff --git a/libjava/java/util/TimeZone.java b/libjava/java/util/TimeZone.java
index ad2dd62..9e8142f 100644
--- a/libjava/java/util/TimeZone.java
+++ b/libjava/java/util/TimeZone.java
@@ -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];
}