ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/email Mailer.java
Date Wed, 19 Jun 2002 07:22:14 GMT
bodewig     2002/06/19 00:22:13

  Modified:    src/main/org/apache/tools/ant/taskdefs/email Tag:
                        ANT_15_BRANCH Mailer.java
  Log:
  Format the timezone part ourselves in the Date header (I was obviously
  asking too much from SimpleDateFormat).
  
  PR: 9838
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.4.2.2   +24 -3     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/email/Mailer.java
  
  Index: Mailer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/email/Mailer.java,v
  retrieving revision 1.4.2.1
  retrieving revision 1.4.2.2
  diff -u -r1.4.2.1 -r1.4.2.2
  --- Mailer.java	18 Jun 2002 07:03:50 -0000	1.4.2.1
  +++ Mailer.java	19 Jun 2002 07:22:13 -0000	1.4.2.2
  @@ -55,8 +55,9 @@
   
   import java.text.DateFormat;
   import java.text.SimpleDateFormat;
  -import java.util.Date;
  +import java.util.Calendar;
   import java.util.Locale;
  +import java.util.TimeZone;
   import java.util.Vector;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Task;
  @@ -81,7 +82,7 @@
       protected boolean includeFileNames = false;
   
       private static DateFormat df =
  -        new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
  +        new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ", Locale.US);
   
       /**
        * Sets the mail server
  @@ -208,7 +209,27 @@
        * @since Ant 1.5
        */
       protected final String getDate() {
  -        return df.format(new Date());
  +        Calendar cal = Calendar.getInstance();
  +        TimeZone tz = cal.getTimeZone();
  +        int offset = tz.getOffset(cal.get(Calendar.ERA), 
  +                                  cal.get(Calendar.YEAR),
  +                                  cal.get(Calendar.MONTH),
  +                                  cal.get(Calendar.DAY_OF_MONTH),
  +                                  cal.get(Calendar.DAY_OF_WEEK),
  +                                  cal.get(Calendar.MILLISECOND));
  +        StringBuffer tzMarker = new StringBuffer(offset < 0 ? "-" : "+");
  +        offset = Math.abs(offset);
  +        int hours = offset / (60 * 60 * 1000);
  +        int minutes = offset / (60 * 1000) - 60 * hours;
  +        if (hours < 10) {
  +            tzMarker.append("0");
  +        }
  +        tzMarker.append(hours);
  +        if (minutes < 10) {
  +            tzMarker.append("0");
  +        }
  +        tzMarker.append(minutes);
  +        return df.format(cal.getTime()) + tzMarker.toString();
       }
   }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message