Browse Source

Add Locale support to TStamp task.

Submitted by:	Michal Pise <michal.pise@st.ms.mff.cuni.cz>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269408 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 24 years ago
parent
commit
3088910997
1 changed files with 37 additions and 3 deletions
  1. +37
    -3
      src/main/org/apache/tools/ant/taskdefs/Tstamp.java

+ 37
- 3
src/main/org/apache/tools/ant/taskdefs/Tstamp.java View File

@@ -85,8 +85,7 @@ public class Tstamp extends Task {
project.setProperty("TODAY", today.format(d));
Enumeration i = customFormats.elements();
while(i.hasMoreElements())
{
while(i.hasMoreElements()) {
CustomFormat cts = (CustomFormat)i.nextElement();
cts.execute(project,d, location);
}
@@ -107,6 +106,9 @@ public class Tstamp extends Task {
{
private String propertyName;
private String pattern;
private String language;
private String country;
private String variant;
private int offset = 0;
private int field = Calendar.DATE;
@@ -124,6 +126,29 @@ public class Tstamp extends Task {
this.pattern = pattern;
}
public void setLocale(String locale)
{
StringTokenizer st = new StringTokenizer( locale, " \t\n\r\f,");
try {
language = st.nextToken();
if (st.hasMoreElements()) {
country = st.nextToken();
if (st.hasMoreElements()) {
country = st.nextToken();
if (st.hasMoreElements()) {
throw new BuildException( "bad locale format", location);
}
}
}
else {
country = "";
}
}
catch (NoSuchElementException e) {
throw new BuildException( "bad locale format", e, location);
}
}
public void setOffset(int offset) {
this.offset = offset;
}
@@ -168,7 +193,16 @@ public class Tstamp extends Task {
throw new BuildException("pattern attribute must be provided", location);
}
SimpleDateFormat sdf = new SimpleDateFormat (pattern);
SimpleDateFormat sdf;
if (language == null) {
sdf = new SimpleDateFormat(pattern);
}
else if (variant == null) {
sdf = new SimpleDateFormat(pattern, new Locale(language, country));
}
else {
sdf = new SimpleDateFormat(pattern, new Locale(language, country, variant));
}
if (offset != 0) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);


Loading…
Cancel
Save