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/util DateUtils.java
Date Fri, 08 Nov 2002 15:41:46 GMT
bodewig     2002/11/08 07:41:45

  Modified:    .        Tag: ANT_15_BRANCH WHATSNEW
               src/main/org/apache/tools/ant/listener Tag: ANT_15_BRANCH
                        MailLogger.java
               src/main/org/apache/tools/ant/util Tag: ANT_15_BRANCH
                        DateUtils.java
  Log:
  Merge fix for PR14046 from HEAD
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.263.2.96 +5 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.263.2.95
  retrieving revision 1.263.2.96
  diff -u -r1.263.2.95 -r1.263.2.96
  --- WHATSNEW	8 Nov 2002 13:20:10 -0000	1.263.2.95
  +++ WHATSNEW	8 Nov 2002 15:41:45 -0000	1.263.2.96
  @@ -24,6 +24,11 @@
   * <concat> would cause an exception if a <filelist> pointed to files
     that do not exist.
   
  +Other changes:
  +--------------
  +
  +* MailLogger now sets the Date header correctly.
  +
   Changes from Ant 1.5.1Beta1 to 1.5.1
   ====================================
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.10.2.1  +2 -0      jakarta-ant/src/main/org/apache/tools/ant/listener/MailLogger.java
  
  Index: MailLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/listener/MailLogger.java,v
  retrieving revision 1.10
  retrieving revision 1.10.2.1
  diff -u -r1.10 -r1.10.2.1
  --- MailLogger.java	21 Apr 2002 18:15:13 -0000	1.10
  +++ MailLogger.java	8 Nov 2002 15:41:45 -0000	1.10.2.1
  @@ -56,6 +56,7 @@
   import org.apache.tools.ant.BuildEvent;
   import org.apache.tools.ant.DefaultLogger;
   import org.apache.tools.ant.Project;
  +import org.apache.tools.ant.util.DateUtils;
   import org.apache.tools.ant.util.StringUtils;
   import org.apache.tools.mail.MailMessage;
   
  @@ -217,6 +218,7 @@
       private void sendMail(String mailhost, String from, String toList,
                             String subject, String message) throws IOException {
           MailMessage mailMessage = new MailMessage(mailhost);
  +        mailMessage.setHeader("Date", DateUtils.getDateForHeader());
   
           mailMessage.from(from);
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.5.2.1   +38 -1     jakarta-ant/src/main/org/apache/tools/ant/util/DateUtils.java
  
  Index: DateUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/util/DateUtils.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- DateUtils.java	15 Apr 2002 14:56:34 -0000	1.5
  +++ DateUtils.java	8 Nov 2002 15:41:45 -0000	1.5.2.1
  @@ -59,6 +59,7 @@
   import java.text.SimpleDateFormat;
   import java.util.Calendar;
   import java.util.Date;
  +import java.util.Locale;
   import java.util.TimeZone;
   
   /**
  @@ -94,6 +95,12 @@
       public static final String ISO8601_TIME_PATTERN
               = "HH:mm:ss";
   
  +    /**
  +     * Format used for SMTP (and probably other) Date headers.
  +     */
  +    public static final DateFormat DATE_HEADER_FORMAT
  +        = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ", Locale.US);
  +
   
   // code from Magesh moved from DefaultLogger and slightly modified
       private static final MessageFormat MINUTE_SECONDS
  @@ -218,5 +225,35 @@
               epact++;
           }
           return (((((dayOfTheYear + epact) * 6) + 11) % 177) / 22) & 7;
  +    }
  +
  +    /**
  +     * Returns the current Date in a format suitable for a SMTP date
  +     * header.
  +     *
  +     * @since Ant 1.5.2
  +     */
  +    public static String getDateForHeader() {
  +        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 DATE_HEADER_FORMAT.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