DateUtils (Apache Ant API)

org.apache.tools.ant.util
Class DateUtils


java.lang.Object

  |

  +--org.apache.tools.ant.util.DateUtils


public final class DateUtils
extends java.lang.Object

Helper methods to deal with date/time formatting with a specific defined format (ISO8601) or a plurialization correct elapsed time in minutes and seconds.

Since:
Ant 1.5
Version:
$Revision: 1.5 $
Author:
Stephane Bailliez
, Stefan Bodewig

Field Summary
static java.lang.String ISO8601_DATE_PATTERN
          ISO8601-like pattern for date.
static java.lang.String ISO8601_DATETIME_PATTERN
          ISO8601-like pattern for date-time.
static java.lang.String ISO8601_TIME_PATTERN
          ISO8601-like pattern for time.
 
Method Summary
static java.lang.String format(java.util.Date date, java.lang.String pattern)
          Format a date/time into a specific pattern.
static java.lang.String format(long date, java.lang.String pattern)
          Format a date/time into a specific pattern.
static java.lang.String formatElapsedTime(long millis)
          Format an elapsed time into a plurialization correct string.
static int getPhaseOfMoon(java.util.Calendar cal)
          Calculate the phase of the moon for a given date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ISO8601_DATETIME_PATTERN


public static final java.lang.String ISO8601_DATETIME_PATTERN
ISO8601-like pattern for date-time. It does not support timezone. yyyy-MM-ddTHH:mm:ss

See Also:
Constant Field Values

ISO8601_DATE_PATTERN


public static final java.lang.String ISO8601_DATE_PATTERN
ISO8601-like pattern for date. yyyy-MM-dd

See Also:
Constant Field Values

ISO8601_TIME_PATTERN


public static final java.lang.String ISO8601_TIME_PATTERN
ISO8601-like pattern for time. HH:mm:ss

See Also:
Constant Field Values
Method Detail

format


public static java.lang.String format(long date,
                                      java.lang.String pattern)
Format a date/time into a specific pattern.

Parameters:
date - the date to format expressed in milliseconds.
pattern - the pattern to use to format the date.
Returns:
the formatted date.

format


public static java.lang.String format(java.util.Date date,
                                      java.lang.String pattern)
Format a date/time into a specific pattern.

Parameters:
date - the date to format expressed in milliseconds.
pattern - the pattern to use to format the date.
Returns:
the formatted date.

formatElapsedTime


public static java.lang.String formatElapsedTime(long millis)
Format an elapsed time into a plurialization correct string. It is limited only to report elapsed time in minutes and seconds and has the following behavior.

Returns:
the formatted text in minutes/seconds.

getPhaseOfMoon


public static int getPhaseOfMoon(java.util.Calendar cal)
Calculate the phase of the moon for a given date.

Code heavily influenced by hacklib.c in Nethack

The Algorithm:

 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
 

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


Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.