microsoft.exchange.webservices.data
Class TimeSpan

java.lang.Object
  extended by microsoft.exchange.webservices.data.TimeSpan
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable

public class TimeSpan
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable, java.lang.Cloneable

The Class TimeSpan.

See Also:
Serialized Form

Field Summary
static int DAYS
          Constant for days unit and conversion.
static int HOURS
          Constant for hours unit and conversion.
static TimeSpan MAX_VALUE
          Represents the Maximum TimeSpan value.
static int MILLISECONDS
          Constant for milliseconds unit and conversion.
static TimeSpan MIN_VALUE
          Represents the Minimum TimeSpan value.
static int MINUTES
          Constant for minutes unit and conversion.
static int SECONDS
          Constant for seconds unit and conversion.
static TimeSpan ZERO
          Represents the TimeSpan with a value of zero.
 
Constructor Summary
TimeSpan(int units, long value)
          Creates a new TimeSpan object based on the unit and value entered.
TimeSpan(long time)
          Creates a new instance of TimeSpan based on the number of milliseconds entered.
 
Method Summary
 void add(int units, long value)
          Adds a number of units to this TimeSpan.
 void add(TimeSpan timespan)
          Adds a TimeSpan to this TimeSpan.
 java.lang.Object clone()
          Returns a clone of this TimeSpan.
static int compare(TimeSpan first, TimeSpan second)
          Compares two TimeSpan objects.
 int compareTo(java.lang.Object o)
          Compares this object with the specified object for order.
 TimeSpan duration()
          Returns a TimeSpan whose value is the absolute value of this TimeSpan.
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this one.
 long getDays()
          Gets the number of days (truncated).
 long getHours()
          Gets the number of hours (truncated).
 long getMilliseconds()
          Gets the number of milliseconds.
 long getMinutes()
          Gets the number of minutes (truncated).
 long getSeconds()
          Gets the number of seconds (truncated).
 double getTotalDays()
          Gets the number of days including fractional days.
 double getTotalHours()
          Gets the number of hours including fractional hours.
 long getTotalMilliseconds()
          Gets the number of milliseconds.
 double getTotalMinutes()
          Gets the number of minutes including fractional minutes.
 double getTotalSeconds()
          Gets the number of seconds including fractional seconds.
 int hashCode()
          Returns a hash code value for the object.
 boolean isNegative()
          Indicates whether the value of the TimeSpan is negative.
 boolean isPositive()
          Indicates whether the value of the TimeSpan is positive.
 boolean isZero()
          Indicates whether the value of the TimeSpan is zero.
 TimeSpan negate()
          Returns a TimeSpan whose value is the negated value of this TimeSpan.
static TimeSpan parse(java.lang.String s)
           
static TimeSpan subtract(java.util.Date date1, java.util.Date date2)
          Subtracts two Date objects creating a new TimeSpan object.
 void subtract(int units, long value)
          Subtracts a number of units from this TimeSpan.
 void subtract(TimeSpan timespan)
          Subtracts a TimeSpan from this TimeSpan.
 java.lang.String toString()
          Returns a string representation of the object in the format.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MILLISECONDS

public static final int MILLISECONDS
Constant for milliseconds unit and conversion.

See Also:
Constant Field Values

SECONDS

public static final int SECONDS
Constant for seconds unit and conversion.

See Also:
Constant Field Values

MINUTES

public static final int MINUTES
Constant for minutes unit and conversion.

See Also:
Constant Field Values

HOURS

public static final int HOURS
Constant for hours unit and conversion.

See Also:
Constant Field Values

DAYS

public static final int DAYS
Constant for days unit and conversion.

See Also:
Constant Field Values

MAX_VALUE

public static final TimeSpan MAX_VALUE
Represents the Maximum TimeSpan value.


MIN_VALUE

public static final TimeSpan MIN_VALUE
Represents the Minimum TimeSpan value.


ZERO

public static final TimeSpan ZERO
Represents the TimeSpan with a value of zero.

Constructor Detail

TimeSpan

public TimeSpan(long time)
Creates a new instance of TimeSpan based on the number of milliseconds entered.

Parameters:
time - the number of milliseconds for this TimeSpan.

TimeSpan

public TimeSpan(int units,
                long value)
Creates a new TimeSpan object based on the unit and value entered.

Parameters:
units - the type of unit to use to create a TimeSpan instance.
value - the number of units to use to create a TimeSpan instance.
Method Detail

subtract

public static TimeSpan subtract(java.util.Date date1,
                                java.util.Date date2)
Subtracts two Date objects creating a new TimeSpan object.

Parameters:
date1 - Date to use as the base value.
date2 - Date to subtract from the base value.
Returns:
a TimeSpan object representing the difference bewteen the two Date objects.

compareTo

public int compareTo(java.lang.Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. Comparison is based on the number of milliseconds in this TimeSpan.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - the Object to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one. Comparison is based on the number of milliseconds in this TimeSpan.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the reference object with which to compare.
Returns:
if the obj argument is a TimeSpan object with the exact same number of milliseconds. otherwise.

hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable. The method uses the same algorithm as found in the Long class.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.
See Also:
Object.equals(java.lang.Object), Hashtable

toString

public java.lang.String toString()
Returns a string representation of the object in the format. "[-]d.hh:mm:ss.ff" where "-" is an optional sign for negative TimeSpan values, the "d" component is days, "hh" is hours, "mm" is minutes, "ss" is seconds, and "ff" is milliseconds

Overrides:
toString in class java.lang.Object
Returns:
a string containing the number of milliseconds.

clone

public java.lang.Object clone()
Returns a clone of this TimeSpan.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this TimeSpan.

isPositive

public boolean isPositive()
Indicates whether the value of the TimeSpan is positive.

Returns:
if the value of the TimeSpan is greater than zero. otherwise.

isNegative

public boolean isNegative()
Indicates whether the value of the TimeSpan is negative.

Returns:
if the value of the TimeSpan is less than zero. otherwise.

isZero

public boolean isZero()
Indicates whether the value of the TimeSpan is zero.

Returns:
if the value of the TimeSpan is equal to zero. otherwise.

getMilliseconds

public long getMilliseconds()
Gets the number of milliseconds.

Returns:
the number of milliseconds.

getTotalMilliseconds

public long getTotalMilliseconds()
Gets the number of milliseconds.

Returns:
the number of milliseconds.

getSeconds

public long getSeconds()
Gets the number of seconds (truncated).

Returns:
the number of seconds.

getTotalSeconds

public double getTotalSeconds()
Gets the number of seconds including fractional seconds.

Returns:
the number of seconds.

getMinutes

public long getMinutes()
Gets the number of minutes (truncated).

Returns:
the number of minutes.

getTotalMinutes

public double getTotalMinutes()
Gets the number of minutes including fractional minutes.

Returns:
the number of minutes.

getHours

public long getHours()
Gets the number of hours (truncated).

Returns:
the number of hours.

getTotalHours

public double getTotalHours()
Gets the number of hours including fractional hours.

Returns:
the number of hours.

getDays

public long getDays()
Gets the number of days (truncated).

Returns:
the number of days.

getTotalDays

public double getTotalDays()
Gets the number of days including fractional days.

Returns:
the number of days.

add

public void add(TimeSpan timespan)
Adds a TimeSpan to this TimeSpan.

Parameters:
timespan - the TimeSpan to add to this TimeSpan.

add

public void add(int units,
                long value)
Adds a number of units to this TimeSpan.

Parameters:
units - the type of unit to add to this TimeSpan.
value - the number of units to add to this TimeSpan.

compare

public static int compare(TimeSpan first,
                          TimeSpan second)
Compares two TimeSpan objects.

Parameters:
first - first TimeSpan to use in the compare.
second - second TimeSpan to use in the compare.
Returns:
a negative integer, zero, or a positive integer as the first TimeSpan is less than, equal to, or greater than the second TimeSpan.

duration

public TimeSpan duration()
Returns a TimeSpan whose value is the absolute value of this TimeSpan.

Returns:
a TimeSpan whose value is the absolute value of this TimeSpan.

negate

public TimeSpan negate()
Returns a TimeSpan whose value is the negated value of this TimeSpan.

Returns:
a TimeSpan whose value is the negated value of this TimeSpan.

subtract

public void subtract(TimeSpan timespan)
Subtracts a TimeSpan from this TimeSpan.

Parameters:
timespan - the TimeSpan to subtract from this TimeSpan.

subtract

public void subtract(int units,
                     long value)
Subtracts a number of units from this TimeSpan.

Parameters:
units - the type of unit to subtract from this TimeSpan.
value - the number of units to subtract from this TimeSpan.

parse

public static TimeSpan parse(java.lang.String s)
                      throws java.lang.Exception
Throws:
java.lang.Exception