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/testcases/org/apache/tools/ant/util DateUtilsTest.java
Date Tue, 19 Feb 2002 07:51:12 GMT
bodewig     02/02/18 23:51:12

  Modified:    src/main/org/apache/tools/ant/taskdefs Zip.java
               src/main/org/apache/tools/ant/util DateUtils.java
               src/testcases/org/apache/tools/ant/util DateUtilsTest.java
  Log:
  please don't use <zip>'s file attribute
  
  Revision  Changes    Path
  1.62      +17 -3     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Zip.java
  
  Index: Zip.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Zip.java,v
  retrieving revision 1.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- Zip.java	8 Feb 2002 14:17:24 -0000	1.61
  +++ Zip.java	19 Feb 2002 07:51:12 -0000	1.62
  @@ -62,12 +62,13 @@
   import java.io.ByteArrayOutputStream;
   import java.io.ByteArrayInputStream;
   
  +import java.util.Calendar;
   import java.util.Hashtable;
   import java.util.Stack;
  -
   import java.util.Vector;
   import java.util.zip.CRC32;
   import java.util.zip.ZipInputStream;
  +
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.FileScanner;
   import org.apache.tools.ant.Project;
  @@ -76,6 +77,7 @@
   import org.apache.tools.ant.types.EnumeratedAttribute;
   import org.apache.tools.ant.types.ZipFileSet;
   import org.apache.tools.ant.types.ZipScanner;
  +import org.apache.tools.ant.util.DateUtils;
   import org.apache.tools.ant.util.FileUtils;
   import org.apache.tools.ant.util.SourceFileScanner;
   import org.apache.tools.ant.util.MergingMapper;
  @@ -135,9 +137,21 @@
        * @deprecated Use setDestFile(File) instead
        */
       public void setFile(File file) {
  -        log("DEPRECATED - The file attribute has been renamed destfile."
  -            +" This attribute will be unsupported before Ant1.5 is released",
  +        log("DEPRECATED - The file attribute has been renamed destfile.",
  +            Project.MSG_ERR);
  +        log("This attribute will be unsupported before Ant1.5 is released.",
  +            Project.MSG_ERR);
  +
  +        log("Be aware that the effect of using the file attribute depends on",
               Project.MSG_ERR);
  +        log("the phase of the moon.", Project.MSG_WARN);
  +        int phase = DateUtils.getPhaseOfMoon(Calendar.getInstance());
  +        if (phase == 4) {
  +            log("You are lucky!  Full moon tonight.");
  +        } else if (phase == 0) {
  +            log("Be careful!  New moon tonight.", Project.MSG_WARN);
  +        }
  +        
           setDestFile(file);
       }
   
  
  
  
  1.2       +47 -0     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DateUtils.java	5 Feb 2002 21:14:28 -0000	1.1
  +++ DateUtils.java	19 Feb 2002 07:51:12 -0000	1.2
  @@ -57,6 +57,7 @@
   import java.text.DateFormat;
   import java.text.MessageFormat;
   import java.text.SimpleDateFormat;
  +import java.util.Calendar;
   import java.util.Date;
   import java.util.TimeZone;
   
  @@ -66,6 +67,11 @@
    * or a plurialization correct elapsed time in minutes and seconds.
    *
    * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
  + * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  + *
  + * @since Ant 1.5
  + * 
  + * @version $Revision: 1.2 $
    */
   public final class DateUtils {
   
  @@ -172,4 +178,45 @@
           return sdf;
       }
   
  +    /**
  +     * Calculate the phase of the moon for a given date.
  +     *
  +     * <p>Code heavily influenced by hacklib.c in <a
  +     * href="http://www.nethack.org/">Nethack</a></p>
  +     *
  +     * <p>The Algorithm:
  +     *
  +     * <pre>
  +     * moon period = 29.53058 days ~= 30, year = 365.2422 days
  +     *
  +     * days moon phase advances on first day of year compared to preceding year
  +     *	= 365.2422 - 12*29.53058 ~= 11
  +     *
  +     * years in Metonic cycle (time until same phases fall on the same days of
  +     *	the month) = 18.6 ~= 19
  +     *
  +     * moon phase on first day of year (epact) ~= (11*(year%19) + 18) % 30
  +     *	(18 as initial condition for 1900)
  +     *
  +     * current phase in days = first day phase + days elapsed in year
  +     *
  +     * 6 moons ~= 177 days
  +     * 177 ~= 8 reported phases * 22
  +     * + 11/22 for rounding
  +     * </pre>
  +     *
  +     * @return The phase of the moon as a number between 0 and 7 with
  +     *         0 meaning new moon and 4 meaning full moon.
  +     *
  +     * @since 1.2, Ant 1.5
  +     */
  +    public static int getPhaseOfMoon(Calendar cal) {
  +        int dayOfTheYear = cal.get(Calendar.DAY_OF_YEAR);
  +        int yearInMetonicCycle = ((cal.get(Calendar.YEAR)-1900) % 19) + 1;
  +	int epact = (11 * yearInMetonicCycle + 18) % 30;
  +	if ((epact == 25 && yearInMetonicCycle > 11) || epact == 24) {
  +            epact++;
  +        }
  +	return (((((dayOfTheYear + epact) * 6) + 11) % 177) / 22) & 7;
  +    }
   }
  
  
  
  1.4       +12 -0     jakarta-ant/src/testcases/org/apache/tools/ant/util/DateUtilsTest.java
  
  Index: DateUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/util/DateUtilsTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DateUtilsTest.java	6 Feb 2002 11:31:59 -0000	1.3
  +++ DateUtilsTest.java	19 Feb 2002 07:51:12 -0000	1.4
  @@ -63,6 +63,7 @@
    * TestCase for DateUtils.
    *
    * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
  + * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
    */
   public class DateUtilsTest extends TestCase {
       public DateUtilsTest(String s) {
  @@ -114,5 +115,16 @@
           String text = DateUtils.format(ms,
                   DateUtils.ISO8601_TIME_PATTERN);
           assertEquals("20:11:12", text);
  +    }
  +
  +    public void testPhaseOfMoon() {
  +        TimeZone timeZone = TimeZone.getTimeZone("GMT");
  +        Calendar cal = Calendar.getInstance(timeZone);
  +        // should be full moon
  +        cal.set(2002, 2, 27);
  +        assertEquals(4, DateUtils.getPhaseOfMoon(cal));
  +        // should be new moon
  +        cal.set(2002, 2, 12);
  +        assertEquals(0, DateUtils.getPhaseOfMoon(cal));
       }
   }
  
  
  

--
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