Index: src/main/org/apache/tools/ant/taskdefs/Touch.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Touch.java,v
retrieving revision 1.24
diff -u -r1.24 Touch.java
--- src/main/org/apache/tools/ant/taskdefs/Touch.java	23 Apr 2002 08:35:05 -0000	1.24
+++ src/main/org/apache/tools/ant/taskdefs/Touch.java	13 May 2002 14:40:38 -0000
@@ -61,6 +61,7 @@
 import org.apache.tools.ant.types.FileSet;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.JavaEnvUtils;
+import org.apache.tools.ant.util.DateUtils;
 
 import java.io.File;
 import java.io.IOException;
@@ -68,6 +69,7 @@
 import java.text.ParseException;
 import java.util.Locale;
 import java.util.Vector;
+import java.util.Date;
 
 /**
  * Touch a file and/or fileset(s) -- corresponds to the Unix touch command.
@@ -78,7 +80,7 @@
  * <p>Note: Setting the modification time of files is not supported in
  * JDK 1.1.</p>
  *
- * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> 
+ * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  * @author <a href="mailto:mj@servidium.com">Michael J. Sikorsky</a>
  * @author <a href="mailto:shaw@servidium.com">Robert Shaw</a>
  *
@@ -93,6 +95,8 @@
     private String dateTime;
     private Vector filesets = new Vector();
     private FileUtils fileUtils;
+    private String datePattern = null;
+    private String localeString = null;
 
     public Touch() {
         fileUtils = FileUtils.newFileUtils();
@@ -114,13 +118,27 @@
     }
 
     /**
-     * Date in the format MM/DD/YYYY HH:MM AM_PM.
+     * Date in the format MM/DD/YYYY HH:MM AM_PM or as specified by setDatePattern
      */
     public void setDatetime(String dateTime) {
         this.dateTime = dateTime;
     }
 
     /**
+     * DatePattern in SimpleDateFormat style
+     */
+    public void setPattern(String pattern){
+        this.datePattern = pattern;
+    }
+
+    /**
+     * The locale to use for parsing
+     */
+    public void setLocale(String localeString){
+        this.localeString = localeString;
+    }
+
+    /**
      * Adds a set of files (nested fileset attribute).
      */
     public void addFileset(FileSet set) {
@@ -134,7 +152,7 @@
         long savedMillis = millis;
 
         if (file == null && filesets.size() == 0) {
-            throw 
+            throw
                 new BuildException("Specify at least one source - a file or "
                                    + "a fileset.");
         }
@@ -143,19 +161,21 @@
             throw new BuildException("Use a fileset to touch directories.");
         }
 
+        if(dateTime != null && millis >= 0){
+            throw new BuildException("You cannot supply both datetime and the number of milliseconds.");
+        }
+
         try {
             if (dateTime != null) {
-                DateFormat df = 
-                    DateFormat.getDateTimeInstance(DateFormat.SHORT,
-                                                   DateFormat.SHORT,
-                                                   Locale.US);
                 try {
-                    setMillis(df.parse(dateTime).getTime());
+                    Date parsedDate = DateUtils.parseDate(dateTime,datePattern,localeString);
+                    setMillis(parsedDate.getTime());
                     if (millis < 0) {
                         throw new BuildException("Date of " + dateTime
                                                  + " results in negative "
                                                  + "milliseconds value "
-                                                 + "relative to epoch "
+                                                 + "relative to the epoch "
+                                                 + "beginning "
                                                  + "(January 1, 1970, "
                                                  + "00:00:00 GMT).");
                     }
@@ -180,18 +200,18 @@
                 try {
                     fileUtils.createNewFile(file);
                 } catch (IOException ioe) {
-                    throw new BuildException("Could not create " + file, ioe, 
+                    throw new BuildException("Could not create " + file, ioe,
                                              location);
                 }
             }
         }
 
-        if (millis >= 0 && 
+        if (millis >= 0 &&
             JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) {
             log("modification time of files cannot be set in JDK 1.1",
                 Project.MSG_WARN);
             return;
-        } 
+        }
 
         boolean resetMillis = false;
         if (millis < 0) {
@@ -215,7 +235,7 @@
             for (int j = 0; j < srcFiles.length ; j++) {
                 touch(new File(fromDir, srcFiles[j]));
             }
-         
+
             for (int j = 0; j < srcDirs.length ; j++) {
                 touch(new File(fromDir, srcDirs[j]));
             }
Index: src/main/org/apache/tools/ant/taskdefs/Tstamp.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tstamp.java,v
retrieving revision 1.27
diff -u -r1.27 Tstamp.java
--- src/main/org/apache/tools/ant/taskdefs/Tstamp.java	15 Apr 2002 15:33:09 -0000	1.27
+++ src/main/org/apache/tools/ant/taskdefs/Tstamp.java	13 May 2002 14:40:38 -0000
@@ -59,6 +59,7 @@
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Location;
 import org.apache.tools.ant.types.EnumeratedAttribute;
+import org.apache.tools.ant.util.DateUtils;
 
 import java.util.Calendar;
 import java.util.Date;
@@ -70,6 +71,7 @@
 import java.util.TimeZone;
 import java.util.Vector;
 import java.text.SimpleDateFormat;
+import java.text.ParseException;
 
 /**
  * Sets TSTAMP, DSTAMP and TODAY
@@ -107,7 +109,7 @@
             SimpleDateFormat tstamp = new SimpleDateFormat ("HHmm");
             project.setNewProperty(prefix + "TSTAMP", tstamp.format(d));
 
-            SimpleDateFormat today 
+            SimpleDateFormat today
                 = new SimpleDateFormat ("MMMM d yyyy", Locale.US);
             project.setNewProperty(prefix + "TODAY", today.format(d));
 
@@ -132,12 +134,10 @@
         private TimeZone timeZone;
         private String propertyName;
         private String pattern;
-        private String language;
-        private String country;
-        private String variant;
         private int offset = 0;
         private int field = Calendar.DATE;
         private String prefix = "";
+        private Locale locale = null;
 
         public CustomFormat(String prefix) {
             this.prefix = prefix;
@@ -152,24 +152,11 @@
         }
 
         public void setLocale(String locale) {
-            StringTokenizer st = new StringTokenizer(locale, " \t\n\r\f,");
-            try {
-                language = st.nextToken();
-                if (st.hasMoreElements()) {
-                    country = st.nextToken();
-                    if (st.hasMoreElements()) {
-                        variant = st.nextToken();
-                        if (st.hasMoreElements()) {
-                            throw new BuildException("bad locale format", 
-                                                      getLocation());
-                        }
-                    }
-                } else {
-                    country = "";
-                }
-            } catch (NoSuchElementException e) {
-                throw new BuildException("bad locale format", e, 
-                                         getLocation());
+            try{
+                this.locale = DateUtils.parseLocale(locale);
+            }
+            catch(ParseException pe){
+                throw new BuildException(pe.getMessage(),pe,getLocation());
             }
         }
 
@@ -200,37 +187,41 @@
             field = unit.getCalendarField();
         }
 
-        public void execute(Project project, Date date, Location location) {
+        public void execute(final Project project, Date date, final Location location) {
+            // check for the propertyname
             if (propertyName == null) {
                 throw new BuildException("property attribute must be provided",
                                          location);
             }
 
+            // check for a pattern
             if (pattern == null) {
                 throw new BuildException("pattern attribute must be provided",
                                          location);
             }
 
+            // setup the format using locale if appropriate
             SimpleDateFormat sdf;
-            if (language == null) {
+            if (locale == null) {
                 sdf = new SimpleDateFormat(pattern);
-            } else if (variant == null) {
-                sdf = new SimpleDateFormat(pattern,
-                                           new Locale(language, country));
             } else {
-                sdf = new SimpleDateFormat(pattern,
-                                           new Locale(language, country,
-                                                      variant));
+                sdf = new SimpleDateFormat(pattern,locale);
             }
+
+            // apply any offsets necessary
             if (offset != 0) {
-                Calendar calendar = Calendar.getInstance();
+                final Calendar calendar = Calendar.getInstance();
                 calendar.setTime(date);
                 calendar.add(field, offset);
                 date = calendar.getTime();
             }
+
+            // apply the timezone if necessary
             if (timeZone != null){
                 sdf.setTimeZone(timeZone);
             }
+
+            // set the pattern
             project.setNewProperty(propertyName, sdf.format(date));
         }
     }
@@ -281,4 +272,4 @@
             return units;
         }
     }
-}
+}
\ No newline at end of file
Index: src/main/org/apache/tools/ant/types/selectors/DateSelector.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/types/selectors/DateSelector.java,v
retrieving revision 1.1
diff -u -r1.1 DateSelector.java
--- src/main/org/apache/tools/ant/types/selectors/DateSelector.java	30 Apr 2002 22:38:35 -0000	1.1
+++ src/main/org/apache/tools/ant/types/selectors/DateSelector.java	13 May 2002 14:40:38 -0000
@@ -58,10 +58,12 @@
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.util.Locale;
+import java.util.Date;
 
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.types.EnumeratedAttribute;
 import org.apache.tools.ant.types.Parameter;
+import org.apache.tools.ant.util.DateUtils;
 
 /**
  * Selector that chooses files based on their last modified date.
@@ -73,6 +75,8 @@
 
     private long millis = -1;
     private String dateTime = null;
+    private String datePattern = null;
+    private String localeString = null;
     private boolean includeDirs = false;
     private int cmp = 0;
     public final static String MILLIS_KEY = "millis";
@@ -111,30 +115,33 @@
 
     /**
      * Sets the date. The user must supply it in MM/DD/YYYY HH:MM AM_PM
-     * format
+     * format unless a custom pattern is also specified
      *
      * @param dateTime a string in MM/DD/YYYY HH:MM AM_PM format
      */
     public void setDatetime(String dateTime) {
+        // moved parsing code to verifySettings to avoid conflicting with millis attribute (Rob)
         this.dateTime = dateTime;
-        if (dateTime != null) {
-            DateFormat df = DateFormat.getDateTimeInstance(
-                                                    DateFormat.SHORT,
-                                                    DateFormat.SHORT,
-                                                    Locale.US);
-            try {
-                setMillis(df.parse(dateTime).getTime());
-                if (millis < 0) {
-                    setError("Date of " + dateTime
-                        + " results in negative milliseconds value relative"
-                        + " to epoch (January 1, 1970, 00:00:00 GMT).");
-                }
-            } catch (ParseException pe) {
-                    setError("Date of " + dateTime
-                        + " Cannot be parsed correctly. It should be in"
-                        + " MM/DD/YYYY HH:MM AM_PM format.");
-            }
-        }
+    }
+
+    /**
+     * Sets the date pattern. The format is dictated by the SimpleDateFormat class
+     * @see java.text.SimpleDateFormat
+     * @param dateTime the pattern to use when parsing the date
+     */
+    public void setPattern(String datePattern) {
+        this.datePattern = datePattern;
+    }
+
+    /**
+     * Sets the locale. The locale is used when parsing dates, the format is along the lines of
+     * the Locale class description.
+     * @see java.util.Locale
+     * @see org.apache.tools.ant.util.DateUtils
+     * @param locale the locale that should be used
+     */
+    public void setLocale(String localeString) {
+        this.localeString = localeString;
     }
 
     /**
@@ -199,14 +206,36 @@
      * values have been set.
      */
     public void verifySettings() {
-        if (dateTime == null && millis < 0) {
-            setError("You must provide a datetime or the number of "
-                + "milliseconds.");
+
+        // check we haven't got both time and millis specified
+        if(dateTime != null && millis >= 0){
+            setError("You cannot supply both datetime and the number of milliseconds.");
+            return;
         }
-        else if (millis < 0) {
-            setError("Date of " + dateTime
-                + " results in negative milliseconds"
-                + " value relative to epoch (January 1, 1970, 00:00:00 GMT).");
+
+        // parse the date if supplied
+        if(dateTime!=null){
+            try {
+                final Date parsedDate = DateUtils.parseDate(dateTime,datePattern,localeString);
+                setMillis(parsedDate.getTime());
+            } catch (ParseException pe) {
+                setError("Date of " + dateTime
+                    + " Cannot be parsed correctly.");
+                return;
+            }
+        }
+
+        // check that we have a posetive date
+        if (millis < 0) {
+            if(dateTime==null){
+                setError("The number of milliseconds must be posetive");
+            }
+            else{
+                setError("Date of " + dateTime
+                    + " results in negative milliseconds"
+                    + " value relative to the epoch beginning (January 1, 1970, 00:00:00 GMT).");
+            }
+            return;
         }
     }
 

