FileDocCategorySizeDatePackage
Date.javaAPI DocApache Ant 1.705366Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.types.resources.selectors

Date

public class Date extends Object implements ResourceSelector
Date ResourceSelector. Based on the date FileSelector, with the most notable difference being the lack of support for the includedirs attribute. It is recommended that the effect of includeDirs = "false" be achieved for resources by enclosing a "dir" Type ResourceSelector and a Date ResourceSelector in an Or ResourceSelector.
since
Ant 1.7

Fields Summary
private static final String
MILLIS_OR_DATETIME
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
private Long
millis
private String
dateTime
private String
pattern
private org.apache.tools.ant.types.TimeComparison
when
private long
granularity
Constructors Summary
Methods Summary
public synchronized java.lang.StringgetDatetime()
Get the date & time in String format.

return
a String representing a date & time.

        return dateTime;
    
public synchronized longgetGranularity()
Get the timestamp granularity used by this ResourceSelector.

return
the long granularity.

        return granularity;
    
public synchronized longgetMillis()
Get the date/time in ms.

return
long number of millis since 1970.

        return millis == null ? -1L : millis.longValue();
    
public synchronized java.lang.StringgetPattern()
Get the pattern for use with the datetime attribute.

return
a SimpleDateFormat-compatible pattern string.

        return pattern;
    
public synchronized org.apache.tools.ant.types.TimeComparisongetWhen()
Get the comparison mode.

return
a TimeComparison object.

        return when;
    
public synchronized booleanisSelected(org.apache.tools.ant.types.Resource r)
Return true if this Resource is selected.

param
r the Resource to check.
return
whether the Resource was selected.

        if (dateTime == null && millis == null) {
            throw new BuildException(MILLIS_OR_DATETIME);
        }
        if (millis == null) {
            DateFormat df = ((pattern == null)
                ? DateFormat.getDateTimeInstance(
                    DateFormat.SHORT, DateFormat.SHORT, Locale.US)
                : new SimpleDateFormat(pattern));
            try {
                long m = df.parse(dateTime).getTime();
                if (m < 0) {
                    throw new BuildException("Date of " + dateTime
                        + " results in negative milliseconds value"
                        + " relative to epoch (January 1, 1970, 00:00:00 GMT).");
                }
                setMillis(m);
            } catch (ParseException pe) {
                throw new BuildException("Date of " + dateTime
                        + " Cannot be parsed correctly. It should be in"
                        + (pattern == null
                        ? " MM/DD/YYYY HH:MM AM_PM" : pattern) + " format.");
            }
        }
        return when.evaluate(r.getLastModified(), millis.longValue(), granularity);
    
public synchronized voidsetDateTime(java.lang.String s)
Set the date and time as a String.

param
s the date & time to use.

        dateTime = s;
        millis = null;
    
public synchronized voidsetGranularity(long g)
Set the granularity to use for this ResourceSelector.

param
g the timestamp granularity.

        granularity = g;
    
public synchronized voidsetMillis(long m)
Set the date/time in milliseconds since 1970.

param
m the number of millis.


                      
         
        millis = new Long(m);
    
public synchronized voidsetPattern(java.lang.String p)
Set the optional pattern to use with the datetime attribute.

param
p the SimpleDateFormat-compatible pattern string.

        pattern = p;
    
public synchronized voidsetWhen(org.apache.tools.ant.types.TimeComparison c)
Set the comparison mode.

param
c a TimeComparison object.

        when = c;