[kaffe] CVS kaffe (robilad): resynced with gnu classpath: simpledateformat fix

Kaffe CVS cvs-commits at kaffe.org
Wed May 18 15:34:40 PDT 2005


PatchSet 6552 
Date: 2005/05/18 22:24:39
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
resynced with gnu classpath: simpledateformat fix

2005-05-18  Dalibor Topic  <robilad at kaffe.org>

        Resynced with GNU Classpath.

        2005-05-18  Sven de Marothy <sven at physto.se>

        * java/text/SimpleDateFormat.java
        (computeOffset): Allow timezone to be first in the parsed String.

Members: 
	ChangeLog:1.4078->1.4079 
	libraries/javalib/java/text/SimpleDateFormat.java:1.51->1.52 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4078 kaffe/ChangeLog:1.4079
--- kaffe/ChangeLog:1.4078	Wed May 18 22:15:11 2005
+++ kaffe/ChangeLog	Wed May 18 22:24:39 2005
@@ -2,6 +2,15 @@
 
 	Resynced with GNU Classpath.
 
+	2005-05-18  Sven de Marothy <sven at physto.se>
+
+        * java/text/SimpleDateFormat.java
+        (computeOffset): Allow timezone to be first in the parsed String.
+
+2005-05-18  Dalibor Topic  <robilad at kaffe.org>
+
+	Resynced with GNU Classpath.
+
 	2005-05-16  Tom Tromey  <tromey at redhat.com>
 
         * gnu/java/net/protocol/http/Headers.java (parse): Include final
Index: kaffe/libraries/javalib/java/text/SimpleDateFormat.java
diff -u kaffe/libraries/javalib/java/text/SimpleDateFormat.java:1.51 kaffe/libraries/javalib/java/text/SimpleDateFormat.java:1.52
--- kaffe/libraries/javalib/java/text/SimpleDateFormat.java:1.51	Tue Apr 19 10:25:06 2005
+++ kaffe/libraries/javalib/java/text/SimpleDateFormat.java	Wed May 18 22:24:44 2005
@@ -999,7 +999,7 @@
 		int zoneCount = zoneStrings.length;
 		int index = pos.getIndex();
 		boolean found_zone = false;
-		simpleOffset = computeOffset(dateStr.substring(index));
+		simpleOffset = computeOffset(dateStr.substring(index), pos);
 		if (simpleOffset != null)
 		  {
 		    found_zone = true;
@@ -1186,26 +1186,44 @@
    * @return the parsed offset, or null if parsing
    *         failed.
    */
-  private Integer computeOffset(String zoneString)
+  private Integer computeOffset(String zoneString, ParsePosition pos)
   {
-    Pattern pattern =
+    Pattern pattern = 
       Pattern.compile("(GMT)?([+-])([012])?([0-9]):?([0-9]{2})");
     Matcher matcher = pattern.matcher(zoneString);
-    if (matcher.matches())
+
+    // Match from start, but ignore trailing parts
+    boolean hasAll = matcher.lookingAt();
+    try
+      {
+	// Do we have at least the sign, hour and minute?
+	matcher.group(2);
+	matcher.group(4);
+	matcher.group(5);
+      }
+    catch (IllegalStateException ise)
+      {
+	hasAll = false;
+      }
+    if (hasAll)
       {
 	int sign = matcher.group(2).equals("+") ? 1 : -1;
-	int hour = (Integer.parseInt(matcher.group(3)) * 10)
-	  + Integer.parseInt(matcher.group(4));
+	int hour = Integer.parseInt(matcher.group(4));
+	if (!matcher.group(3).equals(""))
+	  hour += (Integer.parseInt(matcher.group(3)) * 10);
 	int minutes = Integer.parseInt(matcher.group(5));
 
 	if (hour > 23)
 	  return null;
-
 	int offset = sign * ((hour * 60) + minutes) * 60000;
+
+	// advance the index
+	pos.setIndex(pos.getIndex() + matcher.end());
 	return new Integer(offset);
       }
     else if (zoneString.startsWith("GMT"))
       {
+	pos.setIndex(pos.getIndex() + 3);
 	return new Integer(0);
       }
     return null;




More information about the kaffe mailing list