ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Tstamp.java
Date Mon, 30 Jul 2001 13:08:05 GMT
conor       01/07/30 06:08:05

  Modified:    src/main/org/apache/tools/ant/taskdefs Tstamp.java
  Log:
  Add Locale support to TStamp task.
  
  Submitted by:	Michal Pise <michal.pise@st.ms.mff.cuni.cz>
  
  Revision  Changes    Path
  1.11      +37 -3     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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Tstamp.java	2001/01/05 10:55:05	1.10
  +++ Tstamp.java	2001/07/30 13:08:05	1.11
  @@ -85,8 +85,7 @@
               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 @@
       {
           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 @@
               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 @@
                   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);
  
  
  

Mime
View raw message