You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by ev...@apache.org on 2006/03/16 18:20:13 UTC
svn commit: r386389 - in
/maven/continuum/branches/continuum-1.0.x/continuum-web/src/main:
java/org/apache/maven/continuum/web/tool/DateTool.java
resources/templates/screens/ProjectBuild.vm
resources/templates/screens/ProjectBuilds.vm
Author: evenisse
Date: Thu Mar 16 09:20:11 2006
New Revision: 386389
URL: http://svn.apache.org/viewcvs?rev=386389&view=rev
Log:
[CONTINUUM-611] Add a column for duration and elapsed time for a build
Modified:
maven/continuum/branches/continuum-1.0.x/continuum-web/src/main/java/org/apache/maven/continuum/web/tool/DateTool.java
maven/continuum/branches/continuum-1.0.x/continuum-web/src/main/resources/templates/screens/ProjectBuild.vm
maven/continuum/branches/continuum-1.0.x/continuum-web/src/main/resources/templates/screens/ProjectBuilds.vm
Modified: maven/continuum/branches/continuum-1.0.x/continuum-web/src/main/java/org/apache/maven/continuum/web/tool/DateTool.java
URL: http://svn.apache.org/viewcvs/maven/continuum/branches/continuum-1.0.x/continuum-web/src/main/java/org/apache/maven/continuum/web/tool/DateTool.java?rev=386389&r1=386388&r2=386389&view=diff
==============================================================================
--- maven/continuum/branches/continuum-1.0.x/continuum-web/src/main/java/org/apache/maven/continuum/web/tool/DateTool.java (original)
+++ maven/continuum/branches/continuum-1.0.x/continuum-web/src/main/java/org/apache/maven/continuum/web/tool/DateTool.java Thu Mar 16 09:20:11 2006
@@ -19,8 +19,8 @@
import java.lang.reflect.Field;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-import java.util.Date;
import java.util.Calendar;
+import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
@@ -39,10 +39,10 @@
* $date.full_date -> Sunday, October 19, 2003
* $date.get('default','short') -> Oct 19, 2003 9:54 PM
* $date.get('yyyy-M-d H:m:s') -> 2003-10-19 21:54:50
- *
+ * <p/>
* $myDate -> Tue Oct 07 03:14:50 PDT 2003
- * $date.format('medium',$myDate) -> Oct 7, 2003 3:14:50 AM
- *
+ * $date.format('medium',$myDate) -> Oct 7, 2003 3:14:50 AM
+ * <p/>
* Example toolbox.xml config (if you want to use this with VelocityView):
* <tool>
* <key>date</key>
@@ -50,21 +50,21 @@
* <class>org.apache.velocity.tools.generic.DateTool</class>
* </tool>
* </pre></p>
- *
+ * <p/>
* <p>This tool is entirely threadsafe, and has no instance members.
* It may be used in any scope (request, session, or application).
- * As such, the methods are highly interconnected, and overriding
- * key methods provides an easy way to create subclasses that use
+ * As such, the methods are highly interconnected, and overriding
+ * key methods provides an easy way to create subclasses that use
* a non-default format, calendar, locale, or timezone.</p>
*
* @author <a href="mailto:nathan@esha.com">Nathan Bubna</a>
- * @since VelocityTools 1.0
* @version $Revision$ $Date$
+ * @since VelocityTools 1.0
*/
public class DateTool
{
- /**
- * The default format to be used when none is specified.
+ /**
+ * The default format to be used when none is specified.
*
* @since VelocityTools 1.1
*/
@@ -78,7 +78,6 @@
// do nothing
}
-
// ------------------------- system date access ------------------
/**
@@ -98,7 +97,6 @@
return Calendar.getInstance();
}
-
// ------------------------- default parameter access ----------------
/**
@@ -141,31 +139,31 @@
* Returns a {@link Calendar} instance created using the timezone and
* locale returned by getTimeZone() and getLocale(). This allows subclasses
* to easily override the default locale and timezone used by this tool.
- *
+ * <p/>
* <p>Sub-classes may override this method to return a Calendar instance
* not based on the system date.
- * Doing so will also cause the getDate(), get(String), get(String,String),
- * and toString() methods to return dates equivalent to the Calendar
- * returned by this method, because those methods return values derived
+ * Doing so will also cause the getDate(), get(String), get(String,String),
+ * and toString() methods to return dates equivalent to the Calendar
+ * returned by this method, because those methods return values derived
* from the result of this method.</p>
*
- * @return a {@link Calendar} instance created using the results of
+ * @return a {@link Calendar} instance created using the results of
* {@link #getTimeZone()} and {@link #getLocale()}.
* @see Calendar#getInstance(TimeZone zone, Locale aLocale)
*/
public Calendar getCalendar()
{
- return Calendar.getInstance(getTimeZone(), getLocale());
+ return Calendar.getInstance( getTimeZone(), getLocale() );
}
/**
* Return the pattern or style to be used for formatting dates when none
- * is specified. This implementation gives a 'default' date-time format.
+ * is specified. This implementation gives a 'default' date-time format.
* Subclasses may override this to provide a different default format.
- *
+ * <p/>
* <p>NOTE: At some point in the future it may be feasible to configure
* this value via the toolbox definition, but at present, it is not possible
- * to specify custom tool configurations there. For now you should just
+ * to specify custom tool configurations there. For now you should just
* override this in a subclass to have a different default.</p>
*
* @since VelocityTools 1.1
@@ -175,7 +173,6 @@
return DEFAULT_FORMAT;
}
-
// ------------------------- date value access ---------------------------
/**
@@ -185,7 +182,7 @@
*/
public Integer getYear()
{
- return getYear(getCalendar());
+ return getYear( getCalendar() );
}
/**
@@ -193,9 +190,9 @@
*
* @since VelocityTools 1.2
*/
- public Integer getYear(Object date)
+ public Integer getYear( Object date )
{
- return getValue(Calendar.YEAR, date);
+ return getValue( Calendar.YEAR, date );
}
/**
@@ -205,7 +202,7 @@
*/
public Integer getMonth()
{
- return getMonth(getCalendar());
+ return getMonth( getCalendar() );
}
/**
@@ -213,17 +210,17 @@
*
* @since VelocityTools 1.2
*/
- public Integer getMonth(Object date)
+ public Integer getMonth( Object date )
{
- return getValue(Calendar.MONTH, date);
+ return getValue( Calendar.MONTH, date );
}
/**
- * Returns the day (of the month) value of the date
+ * Returns the day (of the month) value of the date
* returned by {@link #getCalendar()}.
* <br><br>
* NOTE: Unlike java.util.Date, this returns the day of the month.
- * It is equivalent to Date.getDate() and
+ * It is equivalent to Date.getDate() and
* Calendar.get(Calendar.DAY_OF_MONTH). We could not call this method
* getDate() because that already exists in this class with a different
* function.
@@ -232,34 +229,34 @@
*/
public Integer getDay()
{
- return getDay(getCalendar());
+ return getDay( getCalendar() );
}
/**
* Returns the day (of the month) value for the specified date.
* <br><br>
* NOTE: Unlike java.util.Date, this returns the day of the month.
- * It is equivalent to Date.getDate() and
+ * It is equivalent to Date.getDate() and
* Calendar.get(Calendar.DAY_OF_MONTH). We could not call this method
* getDate() because that already exists in this class with a different
* function.
*
* @since VelocityTools 1.2
*/
- public Integer getDay(Object date)
+ public Integer getDay( Object date )
{
- return getValue(Calendar.DAY_OF_MONTH, date);
+ return getValue( Calendar.DAY_OF_MONTH, date );
}
/**
- * Return the specified value of the date returned by
+ * Return the specified value of the date returned by
* {@link #getCalendar()} or null if the field is invalid.
*
* @since VelocityTools 1.2
*/
- public Integer getValue(Object field)
+ public Integer getValue( Object field )
{
- return getValue(field, getCalendar());
+ return getValue( field, getCalendar() );
}
/**
@@ -268,33 +265,33 @@
* an Integer or it may be the name of the field as a String.
*
* @param field the corresponding Integer value or String name of the desired value
- * @param date the date/calendar from which the field value will be taken
+ * @param date the date/calendar from which the field value will be taken
* @since VelocityTools 1.2
*/
- public Integer getValue(Object field, Object date)
+ public Integer getValue( Object field, Object date )
{
- if (field == null)
+ if ( field == null )
{
return null;
}
int fieldValue;
- if (field instanceof Integer)
+ if ( field instanceof Integer )
{
- fieldValue = ((Integer)field).intValue();
+ fieldValue = ( (Integer) field ).intValue();
}
// all the public static field names are upper case
String fstr = field.toString().toUpperCase();
try
{
- Field clsf = Calendar.class.getField(fstr);
- fieldValue = clsf.getInt(Calendar.getInstance());
+ Field clsf = Calendar.class.getField( fstr );
+ fieldValue = clsf.getInt( Calendar.getInstance() );
}
- catch (Exception e)
+ catch ( Exception e )
{
return null;
}
- return getValue(fieldValue, date);
+ return getValue( fieldValue, date );
}
/**
@@ -302,29 +299,28 @@
* or null if the field or date is invalid.
*
* @param field the int for the desired field (e.g. Calendar.MONTH)
- * @param date the date/calendar from which the field value will be taken
+ * @param date the date/calendar from which the field value will be taken
* @since VelocityTools 1.2
*/
- public Integer getValue(int field, Object date)
+ public Integer getValue( int field, Object date )
{
- Calendar cal = toCalendar(date);
- if (cal == null)
+ Calendar cal = toCalendar( date );
+ if ( cal == null )
{
return null;
}
- return new Integer(cal.get(field));
+ return new Integer( cal.get( field ) );
}
-
// ------------------------- formatting methods ---------------------------
/**
* Returns a formatted string representing the date returned by
- * {@link #getDate()}. In its default implementation, this method
+ * {@link #getDate()}. In its default implementation, this method
* allows you to retrieve the current date in standard formats by
- * simply doing things like <code>$date.medium</code> or
+ * simply doing things like <code>$date.medium</code> or
* <code>$date.full</code>. If you want only the date or time portion
- * you can specify that along with the standard formats. (e.g.
+ * you can specify that along with the standard formats. (e.g.
* <code>$date.medium_date</code> or <code>$date.short_time</code>)
* More complex or custom formats can be retrieved
* by using the full method syntax. (e.g. $date.get('E, MMMM d'))
@@ -335,9 +331,9 @@
* @see #format(String format, Object obj, Locale locale, TimeZone timezone)
* @since VelocityTools 1.1
*/
- public String get(String format)
+ public String get( String format )
{
- return format(format, getDate());
+ return format( format, getDate() );
}
/**
@@ -352,24 +348,24 @@
* @see #format(String dateStyle, String timeStyle, Object obj, Locale locale, TimeZone timezone)
* @since VelocityTools 1.1
*/
- public String get(String dateStyle, String timeStyle)
+ public String get( String dateStyle, String timeStyle )
{
- return format(dateStyle, timeStyle, getDate(), getLocale());
+ return format( dateStyle, timeStyle, getDate(), getLocale() );
}
/**
* Converts the specified object to a date and formats it according to
* the pattern or style returned by {@link #getFormat()}.
- *
+ *
* @param obj the date object to be formatted
* @return the specified date formatted as a string
* @see #format(String format, Object obj, Locale locale, TimeZone timezone)
* @since VelocityTools 1.1
*/
- public String format(Object obj)
+ public String format( Object obj )
{
- return format(getFormat(), obj);
+ return format( getFormat(), obj );
}
/**
@@ -378,14 +374,14 @@
* returned by {@link #getLocale()}.
*
* @param format the formatting instructions
- * @param obj the date object to be formatted
+ * @param obj the date object to be formatted
* @return a formatted string for this locale representing the specified
* date or <code>null</code> if the parameters are invalid
* @see #format(String format, Object obj, Locale locale, TimeZone timezone)
*/
- public String format(String format, Object obj)
+ public String format( String format, Object obj )
{
- return format(format, obj, getLocale());
+ return format( format, obj, getLocale() );
}
/**
@@ -394,32 +390,32 @@
* {@link Locale}.
*
* @param format the formatting instructions
- * @param obj the date object to be formatted
+ * @param obj the date object to be formatted
* @param locale the locale to be used when formatting
* @return the given date as a formatted string
* @see #format(String format, Object obj, Locale locale, TimeZone timezone)
*/
- public String format(String format, Object obj, Locale locale)
+ public String format( String format, Object obj, Locale locale )
{
- return format(format, obj, locale, getTimeZone());
+ return format( format, obj, locale, getTimeZone() );
}
/**
* Returns a formatted string representing the specified date,
* {@link Locale}, and {@link TimeZone}.
- *
- * <p>
+ * <p/>
+ * <p/>
* The specified format may be a standard style pattern ('full', 'long',
* 'medium', 'short', or 'default').
* </p>
- * <p>
+ * <p/>
* You may also specify that you want only the date or time portion be
* appending '_date' or '_time' respectively to the standard style pattern.
* (e.g. 'full_date' or 'long_time')
* </p>
- * <p>
- * If the format fits neither of these patterns, then the output
- * will be formatted according to the symbols defined by
+ * <p/>
+ * If the format fits neither of these patterns, then the output
+ * will be formatted according to the symbols defined by
* {@link SimpleDateFormat}:
* <pre>
* Symbol Meaning Presentation Example
@@ -444,34 +440,33 @@
* z time zone (Text) Pacific Standard Time
* ' escape for text (Delimiter)
* '' single quote (Literal) '
- *
+ * <p/>
* Examples: "E, MMMM d" will result in "Tue, July 24"
* "EEE, M-d (H:m)" will result in "Tuesday, 7-24 (14:12)"
* </pre>
* </p>
- *
- * @param format the custom or standard pattern to be used
- * @param obj the date to format
- * @param locale the {@link Locale} to format the date for
+ *
+ * @param format the custom or standard pattern to be used
+ * @param obj the date to format
+ * @param locale the {@link Locale} to format the date for
* @param timezone the {@link TimeZone} to be used when formatting
* @return a formatted string representing the specified date or
* <code>null</code> if the parameters are invalid
* @since VelocityTools 1.1
*/
- public String format(String format, Object obj,
- Locale locale, TimeZone timezone)
+ public String format( String format, Object obj, Locale locale, TimeZone timezone )
{
if ( obj == null )
{
return null;
}
- Date date = toDate(obj);
- DateFormat df = getDateFormat(format, locale, timezone);
- if (date == null || df == null)
+ Date date = toDate( obj );
+ DateFormat df = getDateFormat( format, locale, timezone );
+ if ( date == null || df == null )
{
return null;
}
- return df.format(date);
+ return df.format( date );
}
@@ -481,14 +476,14 @@
*
* @param dateStyle the style pattern for the date
* @param timeStyle the style pattern for the time
- * @param obj the date to be formatted
- * @return a formatted representation of the given date
+ * @param obj the date to be formatted
+ * @return a formatted representation of the given date
* @see #format(String dateStyle, String timeStyle, Object obj, Locale locale, TimeZone timezone)
* @since VelocityTools 1.1
*/
- public String format(String dateStyle, String timeStyle, Object obj)
+ public String format( String dateStyle, String timeStyle, Object obj )
{
- return format(dateStyle, timeStyle, obj, getLocale());
+ return format( dateStyle, timeStyle, obj, getLocale() );
}
/**
@@ -497,16 +492,15 @@
*
* @param dateStyle the style pattern for the date
* @param timeStyle the style pattern for the time
- * @param obj the date to be formatted
- * @param locale the {@link Locale} to be used for formatting the date
- * @return a formatted representation of the given date
+ * @param obj the date to be formatted
+ * @param locale the {@link Locale} to be used for formatting the date
+ * @return a formatted representation of the given date
* @see #format(String dateStyle, String timeStyle, Object obj, Locale locale, TimeZone timezone)
* @since VelocityTools 1.1
*/
- public String format(String dateStyle, String timeStyle,
- Object obj, Locale locale)
+ public String format( String dateStyle, String timeStyle, Object obj, Locale locale )
{
- return format(dateStyle, timeStyle, obj, locale, getTimeZone());
+ return format( dateStyle, timeStyle, obj, locale, getTimeZone() );
}
/**
@@ -515,82 +509,79 @@
*
* @param dateStyle the style pattern for the date
* @param timeStyle the style pattern for the time
- * @param obj the date to be formatted
- * @param locale the {@link Locale} to be used for formatting the date
- * @param timezone the {@link TimeZone} the date should be formatted for
- * @return a formatted representation of the given date
+ * @param obj the date to be formatted
+ * @param locale the {@link Locale} to be used for formatting the date
+ * @param timezone the {@link TimeZone} the date should be formatted for
+ * @return a formatted representation of the given date
* @see java.text.DateFormat
* @see #format(String dateStyle, String timeStyle, Object obj, Locale locale, TimeZone timezone)
* @since VelocityTools 1.1
*/
- public String format(String dateStyle, String timeStyle,
- Object obj, Locale locale, TimeZone timezone)
+ public String format( String dateStyle, String timeStyle, Object obj, Locale locale, TimeZone timezone )
{
- Date date = toDate(obj);
- DateFormat df = getDateFormat(dateStyle, timeStyle, locale, timezone);
- if (date == null || df == null)
+ Date date = toDate( obj );
+ DateFormat df = getDateFormat( dateStyle, timeStyle, locale, timezone );
+ if ( date == null || df == null )
{
return null;
}
- return df.format(date);
+ return df.format( date );
}
-
// -------------------------- DateFormat creation methods --------------
/**
* Returns a {@link DateFormat} instance for the specified
* format, {@link Locale}, and {@link TimeZone}. If the format
* specified is a standard style pattern, then a date-time instance
- * will be returned with both the date and time styles set to the
+ * will be returned with both the date and time styles set to the
* specified style. If it is a custom format, then a customized
* {@link SimpleDateFormat} will be returned.
- *
- * @param format the custom or standard formatting pattern to be used
- * @param locale the {@link Locale} to be used
+ *
+ * @param format the custom or standard formatting pattern to be used
+ * @param locale the {@link Locale} to be used
* @param timezone the {@link TimeZone} to be used
* @return an instance of {@link DateFormat}
* @see SimpleDateFormat
* @see DateFormat
* @since VelocityTools 1.1
*/
- public DateFormat getDateFormat(String format, Locale locale,
- TimeZone timezone)
+ public DateFormat getDateFormat( String format, Locale locale, TimeZone timezone )
{
- if (format == null)
+ if ( format == null )
{
return null;
}
DateFormat df = null;
// do they want a date instance
- if (format.endsWith("_date"))
+ if ( format.endsWith( "_date" ) )
{
- String fmt = format.substring(0, format.length() - 5);
- int style = getStyleAsInt(fmt);
- df = getDateFormat(style, -1, locale, timezone);
+ String fmt = format.substring( 0, format.length() - 5 );
+ int style = getStyleAsInt( fmt );
+ df = getDateFormat( style, -1, locale, timezone );
}
// do they want a time instance?
- else if (format.endsWith("_time"))
+ else if ( format.endsWith( "_time" ) )
{
- String fmt = format.substring(0, format.length() - 5);
- int style = getStyleAsInt(fmt);
- df = getDateFormat(-1, style, locale, timezone);
+ String fmt = format.substring( 0, format.length() - 5 );
+ int style = getStyleAsInt( fmt );
+ df = getDateFormat( -1, style, locale, timezone );
}
// ok, they either want a custom or date-time instance
else
{
- int style = getStyleAsInt(format);
- if (style < 0)
+ int style = getStyleAsInt( format );
+ if ( style < 0 )
{
// we have a custom format
- df = new SimpleDateFormat(format, locale);
- df.setTimeZone(timezone);
+ df = new SimpleDateFormat( format, locale );
+ df.setTimeZone( timezone );
}
else
{
// they want a date-time instance
- df = getDateFormat(style, style, locale, timezone);
+ df = getDateFormat( style, style, locale, timezone );
}
}
return df;
@@ -599,68 +590,65 @@
/**
* Returns a {@link DateFormat} instance for the specified
* date style, time style, {@link Locale}, and {@link TimeZone}.
- *
- * @param dateStyle the date style
- * @param timeStyle the time style
- * @param locale the {@link Locale} to be used
- * @param timezone the {@link TimeZone} to be used
+ *
+ * @param dateStyle the date style
+ * @param timeStyle the time style
+ * @param locale the {@link Locale} to be used
+ * @param timezone the {@link TimeZone} to be used
* @return an instance of {@link DateFormat}
* @see #getDateFormat(int timeStyle, int dateStyle, Locale locale, TimeZone timezone)
* @since VelocityTools 1.1
*/
- public DateFormat getDateFormat(String dateStyle, String timeStyle,
- Locale locale, TimeZone timezone)
+ public DateFormat getDateFormat( String dateStyle, String timeStyle, Locale locale, TimeZone timezone )
{
- int ds = getStyleAsInt(dateStyle);
- int ts = getStyleAsInt(timeStyle);
- return getDateFormat(ds, ts, locale, timezone);
+ int ds = getStyleAsInt( dateStyle );
+ int ts = getStyleAsInt( timeStyle );
+ return getDateFormat( ds, ts, locale, timezone );
}
/**
* Returns a {@link DateFormat} instance for the specified
* time style, date style, {@link Locale}, and {@link TimeZone}.
- *
+ *
* @param dateStyle the date style (date will be ignored if this is
- * less than zero and the date style is not)
+ * less than zero and the date style is not)
* @param timeStyle the time style (time will be ignored if this is
- * less than zero and the date style is not)
- * @param locale the {@link Locale} to be used
- * @param timezone the {@link TimeZone} to be used
+ * less than zero and the date style is not)
+ * @param locale the {@link Locale} to be used
+ * @param timezone the {@link TimeZone} to be used
* @return an instance of {@link DateFormat} or <code>null</code>
* if an instance cannot be constructed with the given
* parameters
* @since VelocityTools 1.1
*/
- protected DateFormat getDateFormat(int dateStyle, int timeStyle,
- Locale locale, TimeZone timezone)
+ protected DateFormat getDateFormat( int dateStyle, int timeStyle, Locale locale, TimeZone timezone )
{
try
{
DateFormat df;
- if (dateStyle < 0 && timeStyle < 0)
+ if ( dateStyle < 0 && timeStyle < 0 )
{
// no style was specified, use default instance
df = DateFormat.getInstance();
}
- else if (timeStyle < 0)
+ else if ( timeStyle < 0 )
{
// only a date style was specified
- df = DateFormat.getDateInstance(dateStyle, locale);
+ df = DateFormat.getDateInstance( dateStyle, locale );
}
- else if (dateStyle < 0)
+ else if ( dateStyle < 0 )
{
// only a time style was specified
- df = DateFormat.getTimeInstance(timeStyle, locale);
+ df = DateFormat.getTimeInstance( timeStyle, locale );
}
else
{
- df = DateFormat.getDateTimeInstance(dateStyle, timeStyle,
- locale);
+ df = DateFormat.getDateTimeInstance( dateStyle, timeStyle, locale );
}
- df.setTimeZone(timezone);
+ df.setTimeZone( timezone );
return df;
}
- catch (Exception suppressed)
+ catch ( Exception suppressed )
{
// let it go...
return null;
@@ -673,34 +661,35 @@
* it will return the integer constant for that pattern. If not, it
* will return -1.
*
- * @see DateFormat
* @param style the string to be checked
* @return the int identifying the style pattern
+ * @see DateFormat
* @since VelocityTools 1.1
*/
- protected int getStyleAsInt(String style)
+ protected int getStyleAsInt( String style )
{
// avoid needlessly running through all the string comparisons
- if (style == null || style.length() < 4 || style.length() > 7) {
+ if ( style == null || style.length() < 4 || style.length() > 7 )
+ {
return -1;
}
- if (style.equalsIgnoreCase("full"))
+ if ( style.equalsIgnoreCase( "full" ) )
{
return DateFormat.FULL;
}
- if (style.equalsIgnoreCase("long"))
+ if ( style.equalsIgnoreCase( "long" ) )
{
return DateFormat.LONG;
}
- if (style.equalsIgnoreCase("medium"))
+ if ( style.equalsIgnoreCase( "medium" ) )
{
return DateFormat.MEDIUM;
}
- if (style.equalsIgnoreCase("short"))
+ if ( style.equalsIgnoreCase( "short" ) )
{
return DateFormat.SHORT;
}
- if (style.equalsIgnoreCase("default"))
+ if ( style.equalsIgnoreCase( "default" ) )
{
return DateFormat.DEFAULT;
}
@@ -708,12 +697,11 @@
return -1;
}
-
// ------------------------- date conversion methods ---------------
/**
* Converts an object to an instance of {@link Date} using the
- * format returned by {@link #getFormat()},the {@link Locale} returned
+ * format returned by {@link #getFormat()},the {@link Locale} returned
* by {@link #getLocale()}, and the {@link TimeZone} returned by
* {@link #getTimeZone()} if the object is not already an instance
* of Date, Calendar, or Long.
@@ -722,27 +710,27 @@
* @return the object as a {@link Date} or <code>null</code> if no
* conversion is possible
*/
- public Date toDate(Object obj)
+ public Date toDate( Object obj )
{
- return toDate(getFormat(), obj, getLocale(), getTimeZone());
+ return toDate( getFormat(), obj, getLocale(), getTimeZone() );
}
/**
* Converts an object to an instance of {@link Date} using the
- * specified format,the {@link Locale} returned by
+ * specified format,the {@link Locale} returned by
* {@link #getLocale()}, and the {@link TimeZone} returned by
* {@link #getTimeZone()} if the object is not already an instance
* of Date, Calendar, or Long.
*
* @param format - the format the date is in
- * @param obj - the date to convert
+ * @param obj - the date to convert
* @return the object as a {@link Date} or <code>null</code> if no
* conversion is possible
* @see #toDate(String format, Object obj, Locale locale)
*/
- public Date toDate(String format, Object obj)
+ public Date toDate( String format, Object obj )
{
- return toDate(format, obj, getLocale(), getTimeZone());
+ return toDate( format, obj, getLocale(), getTimeZone() );
}
/**
@@ -751,49 +739,48 @@
* an instance of Date, Calendar, or Long.
*
* @param format - the format the date is in
- * @param obj - the date to convert
+ * @param obj - the date to convert
* @param locale - the {@link Locale}
* @return the object as a {@link Date} or <code>null</code> if no
* conversion is possible
* @see SimpleDateFormat#parse
*/
- public Date toDate(String format, Object obj, Locale locale)
+ public Date toDate( String format, Object obj, Locale locale )
{
- return toDate(format, obj, locale, getTimeZone());
+ return toDate( format, obj, locale, getTimeZone() );
}
/**
* Converts an object to an instance of {@link Date} using the
- * specified format, {@link Locale}, and {@link TimeZone} if the
+ * specified format, {@link Locale}, and {@link TimeZone} if the
* object is not already an instance of Date, Calendar, or Long.
*
- * @param format - the format the date is in
- * @param obj - the date to convert
- * @param locale - the {@link Locale}
+ * @param format - the format the date is in
+ * @param obj - the date to convert
+ * @param locale - the {@link Locale}
* @param timezone - the {@link TimeZone}
* @return the object as a {@link Date} or <code>null</code> if no
* conversion is possible
* @see #getDateFormat
* @see SimpleDateFormat#parse
*/
- public Date toDate(String format, Object obj,
- Locale locale, TimeZone timezone)
+ public Date toDate( String format, Object obj, Locale locale, TimeZone timezone )
{
- if (obj == null)
+ if ( obj == null )
{
return null;
}
- if (obj instanceof Date)
+ if ( obj instanceof Date )
{
- return (Date)obj;
+ return (Date) obj;
}
- if (obj instanceof Calendar)
+ if ( obj instanceof Calendar )
{
- return ((Calendar)obj).getTime();
+ return ( (Calendar) obj ).getTime();
}
- if (obj instanceof Number)
+ if ( obj instanceof Number )
{
- long value = ((Number)obj).longValue();
+ long value = ( (Number) obj ).longValue();
if ( value == 0 )
{
return null;
@@ -805,10 +792,10 @@
try
{
//try parsing w/a customized SimpleDateFormat
- DateFormat parser = getDateFormat(format, locale, timezone);
- return parser.parse(String.valueOf(obj));
+ DateFormat parser = getDateFormat( format, locale, timezone );
+ return parser.parse( String.valueOf( obj ) );
}
- catch (Exception e)
+ catch ( Exception e )
{
return null;
}
@@ -822,47 +809,109 @@
* @return the converted date
* @see #toCalendar(Object obj, Locale locale)
*/
- public Calendar toCalendar(Object obj)
+ public Calendar toCalendar( Object obj )
{
- return toCalendar(obj, getLocale());
+ return toCalendar( obj, getLocale() );
}
/**
* Converts an object to an instance of {@link Calendar} using the
* locale returned by {@link #getLocale()} if necessary.
*
- * @param obj the date to convert
+ * @param obj the date to convert
* @param locale the locale used
* @return the converted date
* @see #toDate(String format, Object obj, Locale locale)
* @see Calendar
*/
- public Calendar toCalendar(Object obj, Locale locale)
+ public Calendar toCalendar( Object obj, Locale locale )
{
- if (obj == null)
+ if ( obj == null )
{
return null;
}
- if (obj instanceof Calendar)
+ if ( obj instanceof Calendar )
{
- return (Calendar)obj;
+ return (Calendar) obj;
}
//try to get a date out of it
- Date date = toDate(obj);
- if (date == null)
+ Date date = toDate( obj );
+ if ( date == null )
{
return null;
}
//convert the date to a calendar
- Calendar cal = Calendar.getInstance(locale);
- cal.setTime(date);
+ Calendar cal = Calendar.getInstance( locale );
+ cal.setTime( date );
// HACK: Force all fields to update. see link for explanation of this.
//http://java.sun.com/j2se/1.4/docs/api/java/util/Calendar.html
cal.getTime();
return cal;
}
+ public String getElapsedTime( Object startDate )
+ {
+ return getTimeDifference( startDate, getSystemDate() );
+ }
+
+ public String getTimeDifference( Object startDate, Object endDate )
+ {
+ Date start = toDate( startDate );
+ if ( start == null )
+ {
+ return "";
+ }
+
+ Date end = toDate( endDate );
+
+ if ( end == null )
+ {
+ end = getSystemDate();
+ }
+
+ int timeInSeconds = (int) ( ( end.getTime() - start.getTime() ) / 1000 );
+ int days, hours, minutes, seconds;
+ days = timeInSeconds / 86400;
+ timeInSeconds = timeInSeconds - ( days * 86400 );
+ hours = timeInSeconds / 3600;
+ timeInSeconds = timeInSeconds - ( hours * 3600 );
+ minutes = timeInSeconds / 60;
+ timeInSeconds = timeInSeconds - ( minutes * 60 );
+ seconds = timeInSeconds;
+
+ String elapsedTime = "";
+ if ( days > 0 )
+ {
+ elapsedTime = days + " d ";
+ elapsedTime += hours + " h ";
+ elapsedTime += minutes + " min ";
+ elapsedTime += seconds + " sec";
+ }
+ else
+ {
+ if ( hours > 0 )
+ {
+ elapsedTime = hours + " h ";
+ elapsedTime += minutes + " min ";
+ elapsedTime += seconds + " sec";
+ }
+ else
+ {
+ if ( minutes > 0 )
+ {
+ elapsedTime = minutes + " min ";
+ elapsedTime += seconds + " sec";
+ }
+ else
+ {
+ elapsedTime = seconds + " sec";
+ }
+ }
+ }
+
+ return elapsedTime;
+ }
// ------------------------- default toString() implementation ------------
@@ -873,7 +922,7 @@
*/
public String toString()
{
- return format(getFormat(), getDate());
+ return format( getFormat(), getDate() );
}
Modified: maven/continuum/branches/continuum-1.0.x/continuum-web/src/main/resources/templates/screens/ProjectBuild.vm
URL: http://svn.apache.org/viewcvs/maven/continuum/branches/continuum-1.0.x/continuum-web/src/main/resources/templates/screens/ProjectBuild.vm?rev=386389&r1=386388&r2=386389&view=diff
==============================================================================
--- maven/continuum/branches/continuum-1.0.x/continuum-web/src/main/resources/templates/screens/ProjectBuild.vm (original)
+++ maven/continuum/branches/continuum-1.0.x/continuum-web/src/main/resources/templates/screens/ProjectBuild.vm Thu Mar 16 09:20:11 2006
@@ -38,6 +38,21 @@
<td>$!{date.format('medium',$build.endTime)}</td>
</tr>
<tr class="b">
+ <th>Duration</th>
+ <td>
+ #if ( $build.endTime )
+ #set ( $endTime = $build.endTime )
+ #else
+ #set ( $endTime = 0 );
+ #end
+ #if ( $endTime.toString() != "0" )
+ $!{date.getTimeDifference($build.startTime, $build.endTime)}
+ #else
+ Started since : $!{date.getElapsedTime($build.startTime)}
+ #end
+ </td>
+ </tr>
+ <tr class="b">
<th>Build Trigger</th>
<td>$trigger.generate($build)</td>
</tr>
Modified: maven/continuum/branches/continuum-1.0.x/continuum-web/src/main/resources/templates/screens/ProjectBuilds.vm
URL: http://svn.apache.org/viewcvs/maven/continuum/branches/continuum-1.0.x/continuum-web/src/main/resources/templates/screens/ProjectBuilds.vm?rev=386389&r1=386388&r2=386389&view=diff
==============================================================================
--- maven/continuum/branches/continuum-1.0.x/continuum-web/src/main/resources/templates/screens/ProjectBuilds.vm (original)
+++ maven/continuum/branches/continuum-1.0.x/continuum-web/src/main/resources/templates/screens/ProjectBuilds.vm Thu Mar 16 09:20:11 2006
@@ -1,4 +1,4 @@
-$page.setTitle( "Continuum - ${project.name} Builds" )
+$page.setTitle( "Continuum - Continuum Web Builds" )
#if ( $data.user )
#set ( $c1user = $continuum.getUser( $data.user.userId ) )
@@ -30,14 +30,27 @@
<th class="tablehead">Build #</th>
<th class="tablehead">Start Time</th>
<th class="tablehead">End Time</th>
+ <th class="tablehead"> </th>
<th class="tablehead">State</th>
- <th class="tablehead"></th>
+ <th class="tablehead"> </th>
</tr>
#foreach ( $build in $builds )
<tr class="$css.nextClass">
<td>#if ( $build.state == 2 ) $build.buildNumber #end</td>
<td>$!{date.format('medium',$build.startTime)}</td>
<td>$!{date.format('medium',$build.endTime)}</td>
+ <td>
+ #if ( $build.endTime )
+ #set ( $endTime = $build.endTime )
+ #else
+ #set ( $endTime = 0 );
+ #end
+ #if ( $endTime.toString() != "0" )
+ Duration : $!{date.getTimeDifference($build.startTime, $build.endTime)}
+ #else
+ Started since : $!{date.getElapsedTime($build.startTime)}
+ #end
+ </td>
<td>$state.generate($build)</td>
<td><a href="$link.setPage('ProjectBuild.vm').addQueryData('view','ProjectBuild').addQueryData('buildId',$build.id).addQueryData('id',$project.id)">Result</a></td>
</tr>