it.dtt.ca.util
Class Duration

java.lang.Object
  extended by it.dtt.ca.util.Duration

public class Duration
extends java.lang.Object

This class represent the duration of a period of time and it could be used to convert the length of the period in several units of time.


Constructor Summary
Duration(int hours, int minutes, int seconds, int millis)
          Creates an instance of Duration representing the length of a period of time.
Duration(long millis)
          Creates an instance of Duration representing the length of a period of time.
 
Method Summary
static Duration getDuration(java.util.Date startTime, java.util.Date endTime)
          Calculates the time duration between a start time and an end time.
 long toMillis()
          Convert the total value in milliseconds.
 long toMinutes()
          Convert the total value in minutes.
 long toSeconds()
          Convert the total value in seconds.
 java.lang.String toString()
          Retrieves the duration as a String object formatted as "hh:mm:ss:lll".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Duration

public Duration(long millis)
Creates an instance of Duration representing the length of a period of time.

Parameters:
millis - the initial value in milliseconds.

Duration

public Duration(int hours,
                int minutes,
                int seconds,
                int millis)
Creates an instance of Duration representing the length of a period of time.

Parameters:
hours - initial value for hours.
minutes - initial value for minutes.
seconds - initial value for seconds.
millis - initial value for milliseconds.
Method Detail

toMillis

public long toMillis()
Convert the total value in milliseconds.

Returns:
length in milliseconds.

toSeconds

public long toSeconds()
Convert the total value in seconds.

Returns:
length in seconds.

toMinutes

public long toMinutes()
Convert the total value in minutes.

Returns:
length in minutes.

toString

public java.lang.String toString()
Retrieves the duration as a String object formatted as "hh:mm:ss:lll".

Overrides:
toString in class java.lang.Object
Returns:
duration as a string.

getDuration

public static Duration getDuration(java.util.Date startTime,
                                   java.util.Date endTime)
Calculates the time duration between a start time and an end time.

Parameters:
startTime - the start time.
endTime - the end time.
Returns:
the calculated duration.