summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarren Levy <warrenl@redhat.com>2000-11-28 01:38:48 +0000
committerWarren Levy <warrenl@redhat.com>2000-11-28 01:38:48 +0000
commitc20f927025ba6c1296b653488d27e9211fe5c0dd (patch)
treecd7950505d2ddf20463e70bde885a00556e9a6cb
parent466c6d811d514503622d2dd79b662d3d80b7026d (diff)
downloadclasspath-c20f927025ba6c1296b653488d27e9211fe5c0dd.tar.gz
* gnu/java/locale/LocaleInformation_en.java (localPatternChars):
Letters 'k' and 'h' were reversed from the spec. * java/text/DateFormat.java: Minor formatting fixes. (DEFAULT): Added comment to note discrepancy against JCL. (equals): Check that numberFormat is equals (per JCL). * java/text/SimpleDateFormat.java (tokens): Made transient. (serialVersionUID): Added new field. (readObject): Added serialization method. (standardChars): Added new private field. (SimpleDateFormat): Rewrote constructors to match JCL. Merged from libgcj. (toLocalizedPattern): Merged from libgcj. (applyLocalizedPattern): Merged from libgcj. (format): Merged from libgcj; now handles pos. (parseLenient): Made private. (parseStrict): Made private. * java/util/TimeZone.java: Use user.timezone property if set. (setRawOffset): Added abstract method per spec. (getTimeZone): Changed comment to reflect that GMT is the default.
-rw-r--r--ChangeLog22
-rw-r--r--gnu/java/locale/LocaleInformation_en.java2
-rw-r--r--java/text/DateFormat.java23
-rw-r--r--java/text/SimpleDateFormat.java105
-rw-r--r--java/util/TimeZone.java15
5 files changed, 129 insertions, 38 deletions
diff --git a/ChangeLog b/ChangeLog
index 22d6e2742..fa180c88d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2000-11-27 Warren Levy <warrenl@cygnus.com>
+
+ * gnu/java/locale/LocaleInformation_en.java (localPatternChars):
+ Letters 'k' and 'h' were reversed from the spec.
+ * java/text/DateFormat.java: Minor formatting fixes.
+ (DEFAULT): Added comment to note discrepancy against JCL.
+ (equals): Check that numberFormat is equals (per JCL).
+ * java/text/SimpleDateFormat.java (tokens): Made transient.
+ (serialVersionUID): Added new field.
+ (readObject): Added serialization method.
+ (standardChars): Added new private field.
+ (SimpleDateFormat): Rewrote constructors to match JCL. Merged
+ from libgcj.
+ (toLocalizedPattern): Merged from libgcj.
+ (applyLocalizedPattern): Merged from libgcj.
+ (format): Merged from libgcj; now handles pos.
+ (parseLenient): Made private.
+ (parseStrict): Made private.
+ * java/util/TimeZone.java: Use user.timezone property if set.
+ (setRawOffset): Added abstract method per spec.
+ (getTimeZone): Changed comment to reflect that GMT is the default.
+
2000-11-27 Bryce McKinlay <bryce@albatross.co.nz>
* java/util/Vector.java (ensureCapacity): Don't increment modCount.
diff --git a/gnu/java/locale/LocaleInformation_en.java b/gnu/java/locale/LocaleInformation_en.java
index ff8795d6f..22e7371e5 100644
--- a/gnu/java/locale/LocaleInformation_en.java
+++ b/gnu/java/locale/LocaleInformation_en.java
@@ -141,7 +141,7 @@ private static final String[][] zoneStrings =
/**
* This is the list of pattern characters for formatting dates
*/
-private static final String localPatternChars = "GyMdhHmsSEDFwWakKz"; // Not a mistake!
+private static final String localPatternChars = "GyMdkHmsSEDFwWahKz"; // Not a mistake!
/**
* This is the DateFormat.SHORT date format
diff --git a/java/text/DateFormat.java b/java/text/DateFormat.java
index cd468df3a..e675467d9 100644
--- a/java/text/DateFormat.java
+++ b/java/text/DateFormat.java
@@ -1,5 +1,5 @@
/* DateFormat.java -- Class for formatting/parsing date/times
- Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -67,6 +67,8 @@ public abstract class DateFormat extends Format implements java.io.Serializable
public static final int LONG = 1;
public static final int MEDIUM = 2;
public static final int SHORT = 3;
+ // FIXME: XXX: The JCL says this should be set to MEDIUM. Changing this
+ // to match the spec will affect other modules.
public static final int DEFAULT = 4;
/**
@@ -99,7 +101,7 @@ public abstract class DateFormat extends Format implements java.io.Serializable
if (!(obj instanceof Date))
throw new IllegalArgumentException("Invalid object type: " + obj);
- return(format((Date)obj, toAppendTo, fieldPosition));
+ return format((Date)obj, toAppendTo, fieldPosition);
}
/**
@@ -363,7 +365,7 @@ public abstract class DateFormat extends Format implements java.io.Serializable
Locale[] l = new Locale[1];
l[0] = Locale.getDefault();
- return(l);
+ return l;
}
/**
@@ -466,7 +468,7 @@ public abstract class DateFormat extends Format implements java.io.Serializable
*/
public int hashCode()
{
- return(System.identityHashCode(this));
+ return System.identityHashCode(this);
}
/**
@@ -477,7 +479,7 @@ public abstract class DateFormat extends Format implements java.io.Serializable
* <ul>
* <li>Is not <code>null</code>.
* <li>Is an instance of <code>DateFormat</code>.
- * <li>Has the same calendar field value as this object.
+ * <li>Has the same calendar and numberFormat field values as this object.
* </ul>
*
* @param obj The object to test for equality against.
@@ -487,16 +489,13 @@ public abstract class DateFormat extends Format implements java.io.Serializable
public boolean equals(Object obj)
{
if (obj == null)
- return(false);
+ return false;
if (!(obj instanceof DateFormat))
- return(false);
+ return false;
DateFormat df = (DateFormat)obj;
- if (!df.calendar.equals(calendar))
- return(false);
-
- return(true);
+ return calendar.equals(df.calendar) && numberFormat.equals(df.numberFormat);
}
/**
@@ -506,7 +505,7 @@ public abstract class DateFormat extends Format implements java.io.Serializable
*/
public Object clone()
{
- return(super.clone());
+ return super.clone();
}
} // class DateFormat
diff --git a/java/text/SimpleDateFormat.java b/java/text/SimpleDateFormat.java
index 95ac80c2c..be6ee8976 100644
--- a/java/text/SimpleDateFormat.java
+++ b/java/text/SimpleDateFormat.java
@@ -1,6 +1,6 @@
/* SimpleDateFormat.java -- A class for parsing/formating simple
date constructs
- Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -36,8 +36,8 @@ import java.util.Locale;
import java.util.TimeZone;
import java.util.SimpleTimeZone;
import java.util.Vector;
-
-// Note that readObject still needs to be written for this class.
+import java.io.ObjectInputStream;
+import java.io.IOException;
/**
* SimpleDateFormat provides convenient methods for parsing and formatting
@@ -60,12 +60,34 @@ public class SimpleDateFormat extends DateFormat
}
}
- private Vector tokens;
+ private transient Vector tokens;
private DateFormatSymbols formatData; // formatData
private Date defaultCenturyStart =
- new Date(System.currentTimeMillis() - (80*365*24*60*60*1000));
+ new Date(System.currentTimeMillis() - (80*365*24*60*60*1000));
private String pattern;
private int serialVersionOnStream = 1; // 0 indicates JDK1.1.3 or earlier
+ private static final long serialVersionUID = 4774881970558875024L;
+
+ // This string is specified in the JCL. We set it here rather than
+ // do a DateFormatSymbols(Locale.US).getLocalPatternChars() since
+ // someone could theoretically change those values (though unlikely).
+ private static final String standardChars = "GyMdkHmsSEDFwWahKz";
+
+ private void readObject(ObjectInputStream stream)
+ throws IOException, ClassNotFoundException
+ {
+ stream.defaultReadObject();
+ if (serialVersionOnStream < 1)
+ {
+ defaultCenturyStart =
+ new Date(System.currentTimeMillis() - (80*365*24*60*60*1000));
+ serialVersionOnStream = 1;
+ }
+
+ // Set up items normally taken care of by the constructor.
+ tokens = new Vector();
+ compileFormat(pattern);
+ }
private void compileFormat(String pattern)
{
@@ -137,12 +159,13 @@ public class SimpleDateFormat extends DateFormat
* variables in DateFormatSymbols to encapsulate this.
*/
super();
- calendar = new GregorianCalendar();
- calendar.setTimeZone(TimeZone.getDefault());
+ Locale locale = Locale.getDefault();
+ calendar = new GregorianCalendar(locale);
tokens = new Vector();
- formatData = new DateFormatSymbols();
- compileFormat(formatData.dateFormats[DEFAULT]+' '+formatData.timeFormats[DEFAULT]);
- this.pattern = pattern;
+ formatData = new DateFormatSymbols(locale);
+ pattern = formatData.dateFormats[DEFAULT]+' '+formatData.timeFormats[DEFAULT];
+ compileFormat(pattern);
+ numberFormat = NumberFormat.getInstance(locale);
}
/**
@@ -151,7 +174,7 @@ public class SimpleDateFormat extends DateFormat
*/
public SimpleDateFormat(String pattern)
{
- this(pattern,new DateFormatSymbols());
+ this(pattern, Locale.getDefault());
}
/**
@@ -160,7 +183,13 @@ public class SimpleDateFormat extends DateFormat
*/
public SimpleDateFormat(String pattern, Locale locale)
{
- this(pattern,new DateFormatSymbols(locale));
+ super();
+ calendar = new GregorianCalendar(locale);
+ tokens = new Vector();
+ formatData = new DateFormatSymbols(locale);
+ compileFormat(pattern);
+ this.pattern = pattern;
+ numberFormat = NumberFormat.getInstance(locale);
}
/**
@@ -170,11 +199,14 @@ public class SimpleDateFormat extends DateFormat
public SimpleDateFormat(String pattern, DateFormatSymbols formatData) {
super();
calendar = new GregorianCalendar();
+ // FIXME: XXX: Is it really necessary to set the timezone?
+ // The Calendar constructor is supposed to take care of this.
calendar.setTimeZone(TimeZone.getDefault());
tokens = new Vector();
this.formatData = formatData;
compileFormat(pattern);
this.pattern = pattern;
+ numberFormat = NumberFormat.getInstance();
}
// What is the difference between localized and unlocalized? The
@@ -198,10 +230,10 @@ public class SimpleDateFormat extends DateFormat
*
* @return The format string.
*/
- public String
- toLocalizedPattern()
+ public String toLocalizedPattern()
{
- return(pattern);
+ String localChars = formatData.getLocalPatternChars();
+ return applyLocalizedPattern (pattern, standardChars, localChars);
}
/**
@@ -224,12 +256,33 @@ public class SimpleDateFormat extends DateFormat
*
* @param pattern The new format pattern.
*/
- public void
- applyLocalizedPattern(String pattern)
+ public void applyLocalizedPattern(String pattern)
{
- tokens = new Vector();
- compileFormat(pattern);
- this.pattern = pattern;
+ String localChars = formatData.getLocalPatternChars();
+ pattern = applyLocalizedPattern (pattern, localChars, standardChars);
+ applyPattern(pattern);
+ }
+
+ private String applyLocalizedPattern(String pattern,
+ String oldChars, String newChars)
+ {
+ int len = pattern.length();
+ StringBuffer buf = new StringBuffer(len);
+ boolean quoted = false;
+ for (int i = 0; i < len; i++)
+ {
+ char ch = pattern.charAt(i);
+ if (ch == '\'')
+ quoted = ! quoted;
+ if (! quoted)
+ {
+ int j = oldChars.indexOf(ch);
+ if (j >= 0)
+ ch = newChars.charAt(j);
+ }
+ buf.append(ch);
+ }
+ return buf.toString();
}
/**
@@ -331,7 +384,7 @@ public class SimpleDateFormat extends DateFormat
* appending to the specified StringBuffer. The input StringBuffer
* is returned as output for convenience.
*/
- public StringBuffer format(Date date, StringBuffer buffer, FieldPosition z) {
+ public StringBuffer format(Date date, StringBuffer buffer, FieldPosition pos) {
String temp;
Calendar theCalendar = (Calendar) calendar.clone();
theCalendar.setTime(date);
@@ -342,6 +395,7 @@ public class SimpleDateFormat extends DateFormat
Object o = e.nextElement();
if (o instanceof FieldSizePair) {
FieldSizePair p = (FieldSizePair) o;
+ int beginIndex = buffer.length();
switch (p.field) {
case ERA_FIELD:
buffer.append(formatData.eras[theCalendar.get(Calendar.ERA)]);
@@ -412,6 +466,11 @@ public class SimpleDateFormat extends DateFormat
default:
throw new IllegalArgumentException("Illegal pattern character");
}
+ if (pos != null && p.field == pos.getField())
+ {
+ pos.setBeginIndex(beginIndex);
+ pos.setEndIndex(buffer.length());
+ }
} else {
buffer.append(o.toString());
}
@@ -465,7 +524,7 @@ public class SimpleDateFormat extends DateFormat
* US style MM/DD/YY or the European style DD/MM/YY. Or is it YYYY/MM/DD?
* I'm an American, so I guess you know which one I'm choosing....
*/
- public Date parseLenient(String dateStr, ParsePosition pos)
+ private Date parseLenient(String dateStr, ParsePosition pos)
{
int month = -1;
int day = -1;
@@ -829,7 +888,7 @@ public class SimpleDateFormat extends DateFormat
* Note that this method doesn't properly protect against
* StringIndexOutOfBoundsException. FIXME
*/
- public Date parseStrict(String dateStr, ParsePosition pos)
+ private Date parseStrict(String dateStr, ParsePosition pos)
{
// start looking at position pos.index
Enumeration e = tokens.elements();
diff --git a/java/util/TimeZone.java b/java/util/TimeZone.java
index b14e04b23..50c6407e1 100644
--- a/java/util/TimeZone.java
+++ b/java/util/TimeZone.java
@@ -712,7 +712,11 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable
{
System.loadLibrary("javautil");
- String tzid = getDefaultTimeZoneId();
+ String tzid = System.getProperty("user.timezone");
+
+ if (tzid == null)
+ tzid = getDefaultTimeZoneId();
+
if (tzid == null)
tzid = "GMT";
@@ -753,6 +757,13 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable
public abstract int getRawOffset();
/**
+ * Sets the time zone offset, ignoring daylight savings. This is
+ * the offset to add to UTC to get the local time.
+ * @param offsetMillis the time zone offset to GMT.
+ */
+ public abstract void setRawOffset(int offsetMillis);
+
+ /**
* Gets the identifier of this time zone. For instance, PST for
* Pacific Standard Time.
* @returns the ID of this time zone.
@@ -905,7 +916,7 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable
/**
* Gets the TimeZone for the given ID.
* @param ID the time zone identifier.
- * @return The time zone for the identifier or null, if no such time
+ * @return The time zone for the identifier or GMT, if no such time
* zone exists.
*/
public static TimeZone getTimeZone(String ID)