stevel 2002/06/17 00:11:43
Modified: src/main/org/apache/tools/ant/taskdefs Tag: ANT_15_BRANCH
Tstamp.java
Log:
bug 9890; regression on <tstamp>. fixed by swapping order of eval
Revision Changes Path
No revision
No revision
1.27.2.1 +87 -8
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.27
retrieving revision 1.27.2.1
diff -u -r1.27 -r1.27.2.1
--- Tstamp.java 15 Apr 2002 15:33:09 -0000 1.27
+++ Tstamp.java 17 Jun 2002 07:11:42 -0000 1.27.2.1
@@ -72,7 +72,8 @@
import java.text.SimpleDateFormat;
/**
- * Sets TSTAMP, DSTAMP and TODAY
+ * Sets properties to the current time.
+ * The default properties are TSTAMP, DSTAMP and TODAY;
*
* @author [EMAIL PROTECTED]
* @author [EMAIL PROTECTED]
@@ -88,6 +89,8 @@
private String prefix = "";
/**
+ * Set a prefix for the properties. If the prefix does not end with a "."
+ * one is automatically added
* @since Ant 1.5
*/
public void setPrefix(String prefix) {
@@ -97,37 +100,55 @@
}
}
+ /**
+ * create the timestamps. Custom ones are done before
+ * the standard ones, to get their retalation in early.
+ * @throws BuildException
+ */
public void execute() throws BuildException {
try {
Date d = new Date();
+ Enumeration i = customFormats.elements();
+ while (i.hasMoreElements()) {
+ CustomFormat cts = (CustomFormat) i.nextElement();
+ cts.execute(project, d, location);
+ }
+
SimpleDateFormat dstamp = new SimpleDateFormat ("yyyyMMdd");
project.setNewProperty(prefix + "DSTAMP", dstamp.format(d));
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));
- Enumeration i = customFormats.elements();
- while (i.hasMoreElements()) {
- CustomFormat cts = (CustomFormat) i.nextElement();
- cts.execute(project, d, location);
- }
-
} catch (Exception e) {
throw new BuildException(e);
}
}
+ /**
+ * create a custom format with the the current prefix.
+ * @return a ready to fill-in format
+ */
public CustomFormat createFormat() {
CustomFormat cts = new CustomFormat(prefix);
customFormats.addElement(cts);
return cts;
}
+ /**
+ * This nested element that allows a property to be set
+ * to the current date and time in a given format.
+ * The date/time patterns are as defined in the
+ * Java SimpleDateFormat class.
+ * The format element also allows offsets to be applied to
+ * the time to generate different time values.
+ * @todo consider refactoring out into a re-usable element.
+ */
public class CustomFormat {
private TimeZone timeZone;
private String propertyName;
@@ -139,18 +160,41 @@
private int field = Calendar.DATE;
private String prefix = "";
+ /**
+ * Create a format with the current prefix
+ * @param prefix
+ */
public CustomFormat(String prefix) {
this.prefix = prefix;
}
+ /**
+ * The property to receive the date/time string in the given pattern
+ * @param propertyName
+ */
public void setProperty(String propertyName) {
this.propertyName = prefix + propertyName;
}
+ /**
+ * The date/time pattern to be used. The values are as
+ * defined by the Java SimpleDateFormat class.
+ * @param pattern
+ * @see java.text.SimpleDateFormat
+ */
public void setPattern(String pattern) {
this.pattern = pattern;
}
+ /**
+ * The locale used to create date/time string.
+ * The general form is "language, country, variant" but
+ * either variant or variant and country may be omitted.
+ * For more information please refer to documentation
+ * for the java.util.Locale class.
+ * @param locale
+ * @see java.util.Locale
+ */
public void setLocale(String locale) {
StringTokenizer st = new StringTokenizer(locale, " \t\n\r\f,");
try {
@@ -173,10 +217,20 @@
}
}
+ /**
+ * The timezone to use for displaying time.
+ * The values are as defined by the Java TimeZone class.
+ * @param id
+ * @see java.util.TimeZone
+ */
public void setTimezone(String id){
timeZone = TimeZone.getTimeZone(id);
}
+ /**
+ * The numeric offset to the current time.
+ * @param offset
+ */
public void setOffset(int offset) {
this.offset = offset;
}
@@ -196,10 +250,32 @@
field = u.getCalendarField();
}
+ /**
+ * The unit of the offset to be applied to the current time.
+ * Valid Values are
+ * <ul>
+ * <li>millisecond</li>
+ * <li>second</li>
+ * <li>minute</li>
+ * <li>hour</li>
+ * <li>day</li>
+ * <li>week</li>
+ * <li>month</li>
+ * <li>year</li>
+ * </ul>
+ * The default unit is day.
+ * @param unit
+ */
public void setUnit(Unit unit) {
field = unit.getCalendarField();
}
+ /**
+ * validate parameter and execute the format
+ * @param project project to set property in
+ * @param date date to use as a starting point
+ * @param location line in file (for errors)
+ */
public void execute(Project project, Date date, Location location) {
if (propertyName == null) {
throw new BuildException("property attribute must be
provided",
@@ -235,6 +311,9 @@
}
}
+ /**
+ * set of valid units to use for time offsets.
+ */
public static class Unit extends EnumeratedAttribute {
private static final String MILLISECOND = "millisecond";
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>