This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: Another SimpleDateFormat.parse fix


I'm checking this in on the trunk.

Jeff and Bryce have convinced me that the calendar fixes are important
enough for the branch.  If I find the time I will migrate them over.
If someone else wants to do it, fine...

This patch fixes another bug in SimpleDateFormat.parse().  This bug
occurs when parsing a time to which daylight savings applies but where
the time zone is not specified.  I added a Mauve test for this.

I already checked this in to Classpath.

2001-05-14  Tom Tromey  <tromey@redhat.com>

	* java/text/SimpleDateFormat.java (parse): Clear DST_OFFSET and
	ZONE_OFFSET just before computing the time.

Tom

Index: libjava/java/text/SimpleDateFormat.java
===================================================================
RCS file: /cvs/cvsfiles/devo/libjava/java/text/SimpleDateFormat.java,v
retrieving revision 1.11.4.8
diff -u -r1.11.4.8 SimpleDateFormat.java
--- libjava/java/text/SimpleDateFormat.java	2001/05/10 17:54:58	1.11.4.8
+++ libjava/java/text/SimpleDateFormat.java	2001/05/14 17:22:54
@@ -655,8 +655,6 @@
 		    found_zone = true;
 		    TimeZone tz = TimeZone.getTimeZone (strings[0]);
 		    theCalendar.setTimeZone (tz);
-		    theCalendar.clear (Calendar.DST_OFFSET);
-		    theCalendar.clear (Calendar.ZONE_OFFSET);
 		    pos.setIndex(index + strings[k].length());
 		    break;
 		  }
@@ -709,6 +707,10 @@
 
     try
       {
+	// Clear calendar fields here to force getTime() to correctly
+	// respect DST in the timezone.
+	theCalendar.clear (Calendar.DST_OFFSET);
+	theCalendar.clear (Calendar.ZONE_OFFSET);
         return theCalendar.getTime();
       }
     catch (IllegalArgumentException x)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]