I saw a previous patch for Tstamp.java that hasn't been committed yet.  I
wasn't sure if I should continue waiting, I decided to go ahead and make
my change.   My initial change was to allow a different format for the
time stamp, as the current format didn't quite meet my
requirements.  (Automated creation of a build timestamp to display on the
web application.) 

Since I was there.  I decided to "goldplate" a bit, and add the same for
date stamp, and today stamp.  As well as allowing those non-US users a
chance, by allowing the user to change locales.

Any comments?

Scott



Index: Tstamp.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tstamp.java,v
retrieving revision 1.5
diff -b -u -r1.5 Tstamp.java
--- Tstamp.java 2000/09/14 07:19:52     1.5
+++ Tstamp.java 2000/11/29 03:34:58
@@ -66,18 +66,46 @@
  * @author [EMAIL PROTECTED]
  */
 public class Tstamp extends Task {
+    private SimpleDateFormat tstamp = new SimpleDateFormat ("HHmm");
+    private SimpleDateFormat dstamp = new SimpleDateFormat ("yyyyMMdd");
+    private SimpleDateFormat today = new SimpleDateFormat ("MMMM d yyyy");
+    private String dateFormat = "yyyyMMdd";
+    private String todayFormat = "MMMM d yyyy";
+    private Locale locale = Locale.US;
+    private String language = "en";
+    private String country = "US";
 
+    public void setTimeFormat(String format) throws BuildException{ 
+        try {
+            tstamp = new SimpleDateFormat(format);
+        } catch (Exception e) {
+            throw new BuildException(e.getMessage());
+        }
+    }
+    public void setDateFormat(String format) throws BuildException{ 
+        try {
+            dstamp = new SimpleDateFormat(format);
+        } catch (Exception e) {
+            throw new BuildException(e.getMessage());
+        }
+    }
+    public void setTodayFormat(String format) throws BuildException{ 
+        try {
+            today = new SimpleDateFormat(format);
+        } catch (Exception e) {
+            throw new BuildException(e.getMessage());
+        }
+    }
+    public void setLanguage(String language) { this.language = language; }
+    public void setCountry(String country) { this.country= country; }
+
     public void execute() throws BuildException {
         try {
             Date d = new Date();
 
-            SimpleDateFormat dstamp = new SimpleDateFormat ("yyyyMMdd");
             project.setProperty("DSTAMP", dstamp.format(d));
-
-            SimpleDateFormat tstamp = new SimpleDateFormat ("HHmm");
             project.setProperty("TSTAMP", tstamp.format(d));
-
-            SimpleDateFormat today  = new SimpleDateFormat ("MMMM d yyyy", 
Locale.US);
+            SimpleDateFormat today  = new SimpleDateFormat (todayFormat, new 
Locale(language, country, ""));
             project.setProperty("TODAY", today.format(d));
         } catch (Exception e) {
             throw new BuildException(e);

Reply via email to