Index: java/net/URLConnection.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/net/URLConnection.java,v retrieving revision 1.22 diff -u -b -B -r1.22 URLConnection.java --- java/net/URLConnection.java 25 Jan 2004 13:39:34 -0000 1.22 +++ java/net/URLConnection.java 12 Feb 2004 16:40:50 -0000 @@ -43,6 +43,8 @@ import java.io.OutputStream; import java.security.AllPermission; import java.security.Permission; +import java.text.ParsePosition; +import java.text.SimpleDateFormat; import java.util.Collections; import java.util.Date; import java.util.Hashtable; @@ -161,6 +163,8 @@ */ protected URL url; + private static SimpleDateFormat dateFormat1, dateFormat2, dateFormat3; + private static boolean dateformats_initialized = false; /** * Creates a URL connection to a given URL. A real connection is not made. @@ -352,23 +356,24 @@ */ public long getHeaderFieldDate (String name, long defaultValue) { - String str = getHeaderField (name); - - if (str == null) - return defaultValue; + if (! dateformats_initialized) + initializeDateFormats (); - // This needs to change since Date(String) is deprecated, but DateFormat - // doesn't seem to be working for some reason - //DateFormat df = DateFormat.getDateInstance (DateFormat.FULL, Locale.US); - //df.setLenient (true); - - //Date date = df.parse (value, new ParsePosition (0)); - Date date = new Date (str); + long result = defaultValue; + String str = getHeaderField (name); - if (date == null) - return defaultValue; + if (str != null) + { + Date date; + if ((date = dateFormat1.parse (str, new ParsePosition (0))) != null) + result = date.getTime (); + else if ((date = dateFormat2.parse (str, new ParsePosition (0))) != null) + result = date.getTime (); + else if ((date = dateFormat3.parse (str, new ParsePosition (0))) != null) + result = date.getTime (); + } - return (date.getTime() / 1000); + return result; } /** @@ -953,4 +958,22 @@ fileNameMap = map; } -} + + // We don't put these in a static initializer, because it creates problems + // with initializer co-dependency: SimpleDateFormat's constructors eventually + // depend on URLConnection (via the java.text.*Symbols classes). + private synchronized void initializeDateFormats() + { + if (dateformats_initialized) + return; + + Locale locale = new Locale("En", "Us", "Unix"); + dateFormat1 = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'", + locale); + dateFormat2 = new SimpleDateFormat("EEEE, dd-MMM-yy hh:mm:ss 'GMT'", + locale); + dateFormat3 = new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy", locale); + dateformats_initialized = true; + } +} // class URLConnection +