com.partnersoft.data
Class Duration

java.lang.Object
  extended by com.partnersoft.data.Duration
All Implemented Interfaces:
Immutable, java.lang.Comparable<Duration>

public class Duration
extends java.lang.Object
implements java.lang.Comparable<Duration>, Immutable

A representation of a length of time.

This class allows you to specify durations in a variety of units and get them out in a similar variety without worrying about whether your time is in milliseconds or seconds or fortnights or whatnot. Base storage is in milliseconds. I suppose smaller durations might be interesting to some people.

Copyright 2008 Partner Software, Inc.

Author:
Paul Reavis
See Also:
DateAndTime, Date, Time

Field Summary
static long DAYS_TO_MILLIS
           
static long HOURS_TO_MILLIS
           
static double MILLIS_TO_DAYS
           
static double MILLIS_TO_HOURS
           
static double MILLIS_TO_MINUTES
           
static double MILLIS_TO_SECONDS
           
static long MINUTES_TO_MILLIS
           
static long SECONDS_TO_MILLIS
           
 
Constructor Summary
Duration(java.lang.String value)
           
 
Method Summary
 int compareTo(Duration nother)
           
 boolean equals(java.lang.Object nother)
           
static Duration forDays(double days)
           
static Duration forHours(double hours)
           
static Duration forMilliseconds(long millis)
           
static Duration forMinutes(double minutes)
           
static Duration forSeconds(double seconds)
           
static Duration forString(java.lang.String value)
           
 double getDays()
           
 int getDaysPart()
          Returns the truncated days amount - useful when breaking the duration up into hours minutes seconds etc.
 double getHours()
           
 int getHoursPart()
          Returns the truncated hours amount - useful when breaking the duration up into hours minutes seconds etc.
 long getMilliseconds()
           
 int getMillisecondsPart()
          Returns the truncated millisecond amount - useful when breaking the duration up into hours minutes seconds etc.
 double getMinutes()
           
 int getMinutesPart()
          Returns the truncated minutes amount - useful when breaking the duration up into hours minutes seconds etc.
 double getSeconds()
           
 int getSecondsPart()
          Returns the truncated seconds amount - useful when breaking the duration up into hours minutes seconds etc.
 java.util.Date toJavaUtilDate()
          Returns this time represented as a Date object.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SECONDS_TO_MILLIS

public static final long SECONDS_TO_MILLIS
See Also:
Constant Field Values

MINUTES_TO_MILLIS

public static final long MINUTES_TO_MILLIS
See Also:
Constant Field Values

HOURS_TO_MILLIS

public static final long HOURS_TO_MILLIS
See Also:
Constant Field Values

DAYS_TO_MILLIS

public static final long DAYS_TO_MILLIS
See Also:
Constant Field Values

MILLIS_TO_SECONDS

public static final double MILLIS_TO_SECONDS
See Also:
Constant Field Values

MILLIS_TO_MINUTES

public static final double MILLIS_TO_MINUTES
See Also:
Constant Field Values

MILLIS_TO_HOURS

public static final double MILLIS_TO_HOURS
See Also:
Constant Field Values

MILLIS_TO_DAYS

public static final double MILLIS_TO_DAYS
See Also:
Constant Field Values
Constructor Detail

Duration

public Duration(java.lang.String value)
Method Detail

forMilliseconds

public static Duration forMilliseconds(long millis)

forSeconds

public static Duration forSeconds(double seconds)

forMinutes

public static Duration forMinutes(double minutes)

forHours

public static Duration forHours(double hours)

forDays

public static Duration forDays(double days)

forString

public static Duration forString(java.lang.String value)

getMilliseconds

public long getMilliseconds()

getSeconds

public double getSeconds()

getMinutes

public double getMinutes()

getHours

public double getHours()

getDays

public double getDays()

getMillisecondsPart

public int getMillisecondsPart()
Returns the truncated millisecond amount - useful when breaking the duration up into hours minutes seconds etc.

Returns:

getSecondsPart

public int getSecondsPart()
Returns the truncated seconds amount - useful when breaking the duration up into hours minutes seconds etc.

Returns:

getMinutesPart

public int getMinutesPart()
Returns the truncated minutes amount - useful when breaking the duration up into hours minutes seconds etc.

Returns:

getHoursPart

public int getHoursPart()
Returns the truncated hours amount - useful when breaking the duration up into hours minutes seconds etc.

Returns:

getDaysPart

public int getDaysPart()
Returns the truncated days amount - useful when breaking the duration up into hours minutes seconds etc.

Returns:

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toJavaUtilDate

public java.util.Date toJavaUtilDate()
Returns this time represented as a Date object.


equals

public boolean equals(java.lang.Object nother)
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(Duration nother)
Specified by:
compareTo in interface java.lang.Comparable<Duration>