Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs

public Class Tstamp

extends Task
Class Inheritance
Imports
java.text.SimpleDateFormat, java.time.Instant, java.util.Calendar, .Date, .HashMap, .List, .Locale, .Map, .NoSuchElementException, .Optional, .StringTokenizer, .TimeZone, .Vector, java.util.function.BiFunction, .Function, org.apache.tools.ant.BuildException, .Location, .MagicNames, .Project, .Task, org.apache.tools.ant.types.EnumeratedAttribute

Sets properties to the current time, or offsets from the current time. The default properties are TSTAMP, DSTAMP and TODAY;
Since
Ant 1.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
Tstamp.CustomFormat

This nested element that allows a property to be set to the current date and time in a given format.

public static class
Tstamp.Unit

set of valid units to use for time offsets.

Field Summary

Modifier and TypeField and Description
private List<Tstamp.CustomFormat>
private static final String
private String
Inherited from org.apache.tools.ant.Task:
targettaskNametaskTypewrapper

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Tstamp.CustomFormat

Returns:

a ready to fill-in format
createFormat
()

create a custom format with the current prefix.

public void
execute()

Overrides org.apache.tools.ant.Task.execute.

create the timestamps.
protected Date

Returns:

Date
getNow
()

Return the Date instance to use as base for DSTAMP, TSTAMP and TODAY.

protected Optional<Date>

Returns:

Optional containing the Date or null
getNow
(String
name of the property to check
propertyName
,
Function<String, Date>
conversion of the property value as string to Date
map
,
BiFunction<String, String, String>
supplier of the log message containing the property name and value if the conversion fails
log
)

Checks and returns a Date if the specified property is set.

public void
setPrefix(String
the prefix to use.
prefix
)

Set a prefix for the properties.

private void
setProperty(String name, String value)

helper that encapsulates prefix logic and property setting policy (i.e. we use setNewProperty instead of setProperty).

Inherited from org.apache.tools.ant.Task:
bindToOwnergetOwningTargetgetRuntimeConfigurableWrappergetTaskNamegetTaskTypegetWrapperhandleErrorFlushhandleErrorOutputhandleFlushhandleInputhandleOutputinitisInvalidloglogloglogmaybeConfigureperformreconfiguresetOwningTargetsetRuntimeConfigurableWrappersetTaskNamesetTaskType

Field Detail

customFormatsback to summary
private List<Tstamp.CustomFormat> customFormats
ENV_SOURCE_DATE_EPOCHback to summary
private static final String ENV_SOURCE_DATE_EPOCH
prefixback to summary
private String prefix

Constructor Detail

Tstampback to summary
public Tstamp()

Method Detail

createFormatback to summary
public Tstamp.CustomFormat createFormat()

create a custom format with the current prefix.

Returns:Tstamp.CustomFormat

a ready to fill-in format

executeback to summary
public void execute() throws BuildException

Overrides org.apache.tools.ant.Task.execute.

create the timestamps. Custom ones are done before the standard ones, to get their retaliation in early.

Annotations
@Override
Exceptions
BuildException:
on error.
getNowback to summary
protected Date getNow()

Return the Date instance to use as base for DSTAMP, TSTAMP and TODAY.

Returns:Date

Date

getNowback to summary
protected Optional<Date> getNow(String propertyName, Function<String, Date> map, BiFunction<String, String, String> log)

Checks and returns a Date if the specified property is set.

Parameters
propertyName:String

name of the property to check

map:Function<String, Date>

conversion of the property value as string to Date

log:BiFunction<String, String, String>

supplier of the log message containing the property name and value if the conversion fails

Returns:Optional<Date>

Optional containing the Date or null

setPrefixback to summary
public void setPrefix(String prefix)

Set a prefix for the properties. If the prefix does not end with a "." one is automatically added.

Parameters
prefix:String

the prefix to use.

Since
Ant 1.5
setPropertyback to summary
private void setProperty(String name, String value)

helper that encapsulates prefix logic and property setting policy (i.e. we use setNewProperty instead of setProperty).

org.apache.tools.ant.taskdefs back to summary

public Class Tstamp.CustomFormat

extends Object
Class Inheritance

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.

Field Summary

Modifier and TypeField and Description
private String
private int
private String
private int
private String
private String
private TimeZone
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
execute(Project
project to set property in.
project
,
Date
date to use as a starting point.
date
,
Location
line in file (for errors)
location
)

validate parameter and execute the format.

public void
setLocale(String
the locale to use.
locale
)

The locale used to create date/time string.

public void
setOffset(int
the offset to use.
offset
)

The numeric offset to the current time.

public void
setPattern(String
the pattern to use.
pattern
)

The date/time pattern to be used.

public void
setProperty(String
the name of the property.
propertyName
)

The property to receive the date/time string in the given pattern

public void
setTimezone(String
the timezone value.
id
)

The timezone to use for displaying time.

public void
setUnit(String
the unit to use.
unit
)

Deprecated since 1.5.x.
Set the unit type (using String).
public void
setUnit(Tstamp.Unit
the unit to use.
unit
)

The unit of the offset to be applied to the current time.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countryback to summary
private String country
fieldback to summary
private int field
languageback to summary
private String language
offsetback to summary
private int offset
patternback to summary
private String pattern
propertyNameback to summary
private String propertyName
timeZoneback to summary
private TimeZone timeZone
variantback to summary
private String variant

Constructor Detail

CustomFormatback to summary
public CustomFormat()

Method Detail

executeback to summary
public void execute(Project project, Date date, Location location)

validate parameter and execute the format.

Parameters
project:Project

project to set property in.

date:Date

date to use as a starting point.

location:Location

line in file (for errors)

setLocaleback to summary
public void setLocale(String locale)

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.

Parameters
locale:String

the locale to use.

See Also
java.util.Locale
setOffsetback to summary
public void setOffset(int offset)

The numeric offset to the current time.

Parameters
offset:int

the offset to use.

setPatternback to summary
public void setPattern(String pattern)

The date/time pattern to be used. The values are as defined by the Java SimpleDateFormat class.

Parameters
pattern:String

the pattern to use.

See Also
java.text.SimpleDateFormat
setPropertyback to summary
public void setProperty(String propertyName)

The property to receive the date/time string in the given pattern

Parameters
propertyName:String

the name of the property.

setTimezoneback to summary
public void setTimezone(String id)

The timezone to use for displaying time. The values are as defined by the Java TimeZone class.

Parameters
id:String

the timezone value.

See Also
java.util.TimeZone
setUnitback to summary
public void setUnit(String unit)

Deprecated

since 1.5.x. setUnit(String) is deprecated and is replaced with setUnit(Tstamp.Unit) to make Ant's Introspection mechanism do the work and also to encapsulate operations on the unit in its own class.

Set the unit type (using String).

Parameters
unit:String

the unit to use.

Annotations
@Deprecated
setUnitback to summary
public void setUnit(Tstamp.Unit unit)

The unit of the offset to be applied to the current time. Valid Values are

  • millisecond
  • second
  • minute
  • hour
  • day
  • week
  • month
  • year
The default unit is day.
Parameters
unit:Tstamp.Unit

the unit to use.

org.apache.tools.ant.taskdefs back to summary

public Class Tstamp.Unit

extends EnumeratedAttribute
Class Inheritance

set of valid units to use for time offsets.

Field Summary

Modifier and TypeField and Description
private Map<String, Integer>
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String[]
private static final String
private static final String
Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
value

Constructor Summary

AccessConstructor and Description
public
Unit()

Constructor for Unit enumerated type.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

an int value.
getCalendarField
()

Convert the value to int unit value.

public String[]

Returns:

the value values.
getValues
()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

Get the valid values.
Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
containsValuegetIndexgetInstancegetValueindexOfValuesetValuetoString

Field Detail

calendarFieldsback to summary
private Map<String, Integer> calendarFields
DAYback to summary
private static final String DAY
HOURback to summary
private static final String HOUR
MILLISECONDback to summary
private static final String MILLISECOND
MINUTEback to summary
private static final String MINUTE
MONTHback to summary
private static final String MONTH
SECONDback to summary
private static final String SECOND
UNITSback to summary
private static final String[] UNITS
WEEKback to summary
private static final String WEEK
YEARback to summary
private static final String YEAR

Constructor Detail

Unitback to summary
public Unit()

Constructor for Unit enumerated type.

Method Detail

getCalendarFieldback to summary
public int getCalendarField()

Convert the value to int unit value.

Returns:int

an int value.

getValuesback to summary
public String[] getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

Get the valid values.

Returns:String[]

the value values.

Annotations
@Override