stefano 00/01/26 19:51:56
Modified: src/main/org/apache/tools/ant/taskdefs Tstamp.java
Log:
cleaner use of the Java API and added the "TODAY" stamp, used mainly in
documentation
Revision Changes Path
1.2 +23 -27
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tstamp.java
Index: Tstamp.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tstamp.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Tstamp.java 2000/01/13 10:41:41 1.1
+++ Tstamp.java 2000/01/27 03:51:55 1.2
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -9,7 +9,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -17,15 +17,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
@@ -57,35 +57,31 @@
import org.apache.tools.ant.*;
import java.io.*;
import java.util.*;
+import java.text.*;
+
/**
- * Will set TSTAMP and DSTAMP
+ * Sets TSTAMP, DSTAMP and TODAY
*
* @author [EMAIL PROTECTED]
+ * @author [EMAIL PROTECTED]
*/
public class Tstamp extends Task {
public void execute() throws BuildException {
- try {
- Calendar d=Calendar.getInstance();
- StringBuffer tstamp=new StringBuffer();
- tstamp.append( d.get(Calendar.YEAR));
- if(d.get(Calendar.MONTH) < 9) tstamp.append("0");
- tstamp.append( 1+d.get(Calendar.MONTH));
-
- if( d.get(Calendar.DAY_OF_MONTH) < 10 ) tstamp.append("0");
- tstamp.append(d.get(Calendar.DAY_OF_MONTH));
- project.setProperty( "DSTAMP" , tstamp.toString());
-
- if( d.get(Calendar.HOUR_OF_DAY) < 10 ) tstamp.append("0");
- tstamp.append( d.get(Calendar.HOUR_OF_DAY));
-
- if( d.get(Calendar.MINUTE) < 10 ) tstamp.append("0");
- tstamp.append(d.get(Calendar.MINUTE));
- project.setProperty( "TSTAMP" , tstamp.toString());
- } catch (Exception ex) {
- ex.printStackTrace();
- }
+ 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);
+ project.setProperty("TODAY", today.format(d));
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
}
-
}