Class TimeSpan
- java.lang.Object
-
- microsoft.exchange.webservices.data.misc.TimeSpan
-
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<TimeSpan>
public class TimeSpan extends Object implements Comparable<TimeSpan>, Serializable, Cloneable
The Class TimeSpan.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intDAYSConstant for days unit and conversion.static intHOURSConstant for hours unit and conversion.static TimeSpanMAX_VALUERepresents the Maximum TimeSpan value.static intMILLISECONDSConstant for milliseconds unit and conversion.static TimeSpanMIN_VALUERepresents the Minimum TimeSpan value.static intMINUTESConstant for minutes unit and conversion.static intSECONDSConstant for seconds unit and conversion.static TimeSpanZERORepresents the TimeSpan with a value of zero.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int units, long value)Adds a number of units to this TimeSpan.voidadd(TimeSpan timespan)Adds a TimeSpan to this TimeSpan.Objectclone()Returns a clone of this TimeSpan.static intcompare(TimeSpan first, TimeSpan second)Compares two TimeSpan objects.intcompareTo(TimeSpan o)Compares this object with the specified object for order.TimeSpanduration()Returns a TimeSpan whose value is the absolute value of this TimeSpan.booleanequals(Object obj)Indicates whether some other object is "equal to" this one.longgetDays()Gets the number of days (truncated).longgetHours()Gets the number of hours (truncated).longgetMilliseconds()Gets the number of milliseconds.longgetMinutes()Gets the number of minutes (truncated).longgetSeconds()Gets the number of seconds (truncated).doublegetTotalDays()Gets the number of days including fractional days.doublegetTotalHours()Gets the number of hours including fractional hours.longgetTotalMilliseconds()Gets the number of milliseconds.doublegetTotalMinutes()Gets the number of minutes including fractional minutes.doublegetTotalSeconds()Gets the number of seconds including fractional seconds.inthashCode()Returns a hash code value for the object.booleanisNegative()Indicates whether the value of the TimeSpan is negative.booleanisPositive()Indicates whether the value of the TimeSpan is positive.booleanisZero()Indicates whether the value of the TimeSpan is zero.TimeSpannegate()Returns a TimeSpan whose value is the negated value of this TimeSpan.static TimeSpanparse(String s)voidsubtract(int units, long value)Subtracts a number of units from this TimeSpan.static TimeSpansubtract(Date date1, Date date2)Subtracts two Date objects creating a new TimeSpan object.voidsubtract(TimeSpan timespan)Subtracts a TimeSpan from this TimeSpan.StringtoString()Returns a string representation of the object in the format.
-
-
-
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
-
-
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(Date date1, 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(TimeSpan 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:
compareToin interfaceComparable<TimeSpan>- 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(Object obj)
Indicates whether some other object is "equal to" this one. Comparison is based on the number of milliseconds in this TimeSpan.
-
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 byjava.util.Hashtable. The method uses the same algorithm as found in the Long class.- Overrides:
hashCodein classObject- Returns:
- a hash code value for this object.
- See Also:
Object.equals(Object),Hashtable
-
toString
public 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
-
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.
-
-