Index: src/main/org/apache/tools/ant/util/DateUtils.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/util/DateUtils.java,v
retrieving revision 1.5
diff -u -r1.5 DateUtils.java
--- src/main/org/apache/tools/ant/util/DateUtils.java	15 Apr 2002 14:56:34 -0000	1.5
+++ src/main/org/apache/tools/ant/util/DateUtils.java	13 May 2002 14:38:15 -0000
@@ -57,9 +57,14 @@
 import java.text.DateFormat;
 import java.text.MessageFormat;
 import java.text.SimpleDateFormat;
+import java.text.ParsePosition;
+import java.text.ParseException;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.TimeZone;
+import java.util.NoSuchElementException;
+import java.util.Locale;
+import java.util.StringTokenizer;
 
 /**
  * Helper methods to deal with date/time formatting with a specific
@@ -68,9 +73,10 @@
  *
  * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
  * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
+ * @author <a href="mailto:roxspring@imapmail.org">Rob Oxspring</a>
  *
  * @since Ant 1.5
- * 
+ *
  * @version $Revision: 1.5 $
  */
 public final class DateUtils {
@@ -219,4 +225,104 @@
         }
         return (((((dayOfTheYear + epact) * 6) + 11) % 177) / 22) & 7;
     }
-}
+
+    /**
+     * Parses a locale string into a usable java Locale object.
+     * The format expected is as specified in the Locale documentation.
+     * @param locale the string representation of the locale
+     * @returns the parsed locale
+     * @throws ParseException if an expected token is found or
+     *  an unexpected token is not.  Note the parsePosition in the exception
+     *  should not be relied upon as the method does not set it accurately
+     */
+    // NOTE THIS IS NOT STRICTLY DATE RELATED SHOULD IT BE MOVED?
+    public static Locale parseLocale(final String locale)
+        throws ParseException
+    {
+        // Code rippped and modified from Tstamp.java
+
+        // tokenise the string
+        final StringTokenizer st = new StringTokenizer(locale, " \t\n\r\f,");
+
+        // what we're looking for at any given stage
+        String expected = null;
+        try{
+            // grab the language part
+            expected = "language (lowercase two-letter ISO-639 code)";
+            final String language = st.nextToken();
+
+            // grab the country
+            expected = "country (uppercase two-letter ISO-3166 code)";
+            final String country = st.nextToken();
+
+            // if there is more to come..
+            if(st.hasMoreElements()){
+                // grab the variant
+                expected = "variant (browser / vendor specific e.g. WIN, MAC, POSIX)";
+                final String variant = st.nextToken();
+
+                // if there is still more then abort.
+                if(st.hasMoreElements()){
+                    throw new ParseException("Unexpected elements ending string",0);
+                }
+                else{
+                    // otherwise use everything to build the locale
+                    return new Locale(language,country,variant);
+                }
+            }
+            else{
+                // otherwise ignore varient and build the locale
+                return new Locale(language,country);
+            }
+        }
+        catch(NoSuchElementException nsee){
+            // one of the st.nextToken() calls has failed.
+            // report the exception noting what we were looking for.
+            throw new ParseException("Failed to parse locale, expected: " + expected,0);
+        }
+    }
+
+    /**
+     * Parses a specified date using the supplied pattern and locale.
+     * @param dateString the correctly formatted date in String form.
+     * @param pattern the format of the date, locale dependant short
+     *  styles are used if a null pattern is passed.
+     * @param localeString the locale as a String, default is US.
+     * @return the fully parsed date object
+     * @throws ParseException if the locale was not parsed, the date
+     *  was not parsed.
+     * @see #parseLocale(locale)
+     */
+    public static Date parseDate(final String dateString, final String pattern, final String localeString)
+        throws ParseException
+    {
+        // set up teh locale
+        Locale locale;
+        if(localeString==null){
+            // default to the US
+            locale = Locale.US;
+        }
+        else{
+            // otherwise try and parse the locale
+            locale = parseLocale(localeString);
+        }
+
+
+
+        // set up the format
+        DateFormat format;
+        if(pattern==null){
+            // default to short formats for selected locale
+            format = DateFormat.getDateTimeInstance(DateFormat.SHORT,
+                                                    DateFormat.SHORT,
+                                                    locale);
+        }
+        else{
+            // otherwise use the specified pattern
+            format = new SimpleDateFormat(pattern,locale);
+        }
+
+        // parse the date to pass back
+        return format.parse(dateString);
+    }
+}
\ No newline at end of file
Index: src/testcases/org/apache/tools/ant/util/DateUtilsTest.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/testcases/org/apache/tools/ant/util/DateUtilsTest.java,v
retrieving revision 1.4
diff -u -r1.4 DateUtilsTest.java
--- src/testcases/org/apache/tools/ant/util/DateUtilsTest.java	19 Feb 2002 07:51:12 -0000	1.4
+++ src/testcases/org/apache/tools/ant/util/DateUtilsTest.java	13 May 2002 14:38:15 -0000
@@ -53,8 +53,10 @@
  */
 package org.apache.tools.ant.util;
 
+import java.util.Locale;
 import java.util.Date;
 import java.util.Calendar;
+import java.text.ParseException;
 import java.util.TimeZone;
 
 import junit.framework.TestCase;
@@ -64,6 +66,7 @@
  *
  * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
  * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
+ * @author <a href="mailto:roxspring@imapmail.org">Rob Oxspring</a>
  */
 public class DateUtilsTest extends TestCase {
     public DateUtilsTest(String s) {
@@ -126,5 +129,81 @@
         // should be new moon
         cal.set(2002, 2, 12);
         assertEquals(0, DateUtils.getPhaseOfMoon(cal));
+    }
+
+    public void testParseLocale(){
+        try{
+            Locale loc = DateUtils.parseLocale(" \tfr ES,");
+            assertEquals("ES",loc.getCountry());
+            assertEquals("fr",loc.getLanguage());
+        }
+        catch(ParseException pe){
+            fail(pe.getMessage());
+        }
+
+        try{
+            Locale loc = DateUtils.parseLocale(" \tFr Es,my_variant");
+            assertEquals("ES",loc.getCountry());
+            assertEquals("fr",loc.getLanguage());
+            assertEquals("MY_VARIANT",loc.getVariant());
+        }
+        catch(ParseException pe){
+            fail(pe.getMessage());
+        }
+
+        try{
+            Locale loc = DateUtils.parseLocale(" \tFr Es,my_variant blah");
+            fail("blah should be unacceptable as part of the locale");
+        }
+        catch(ParseException pe){
+            assertEquals(pe.getMessage(),"Unexpected elements ending string");
+        }
+
+        try{
+            Locale loc = DateUtils.parseLocale(" \tEn");
+            fail("locale aparently needs more than just a language");
+        }
+        catch(ParseException pe){
+            assertEquals(pe.getMessage(),"Failed to parse locale, expected: country (uppercase two-letter ISO-3166 code)");
+        }
+    }
+
+    public void testParseDate(){
+        try{
+            // test the us format is default
+            Date date = DateUtils.parseDate("5/13/2002 2:58 PM",null,null);
+            assertEquals(date.getTime(),1021298280000l);
+        }
+        catch(ParseException pe){
+            fail(pe.getMessage());
+        }
+
+        try{
+            // test the custom format
+            Date date = DateUtils.parseDate("2002-05-13T15:01:11","yyyy-MM-dd'T'hh:mm:ss",null);
+            assertEquals(date.getTime(),1021298471000l);
+        }
+        catch(ParseException pe){
+            fail(pe.getMessage());
+        }
+
+        try{
+            // test the custom format
+            Date date = DateUtils.parseDate("13 Mai 2002","d MMMM yyyy","de de");
+            assertEquals(date.getTime(),1021244400000l);
+        }
+        catch(ParseException pe){
+            fail(pe.getMessage());
+        }
+
+        try{
+            // test the custom format
+            Date date = DateUtils.parseDate("13.05.02 15:09",null,"de de");
+            assertEquals(date.getTime(),1021298940000l);
+        }
+        catch(ParseException pe){
+            fail(pe.getMessage());
+        }
+
     }
 }
