Object
Cloneable
, Comparable
, Serializable
This class provides the Java binding for the XML schema type timeDuration as specified in Section 3.2.6 of XML Schema Part 2: Datatypes.
timeDuration represents a duration of time. The value space of timeDuration is a six-dimensional space where the coordinates designate the Gregorial year, month, day, hour, minute, and second components defined in Sec 5.5.3.2 of ISO8601.
Example: P2001Y1M18DT9H0M0S
.
The lexical representation for timeDuration is the ISO 8601 extended format PnYnMnDTnHnMnS, where nY represents the number of years, nM the number of months, nD the number of days, 'T' is the date/time separator, nH the number of hours, nM the number of minutes, nS is the number of seconds. The number of seconds can include decimal digits to arbitrary precision.
The values of year, month, day, hour and minute can be arbitrary integers. The value of second can be any arbitrary decimal. See the Precision Rules below.
Instances of TimeDuration
may be constructed from
timeDuration strings defined as per the XML Schema
Specification. In addition, instances of TimeDuration
may be compared for ordering.
Note on Ordering: As per the current schema
specification, the ordering relation on timeDuration does not hold
for certain values of timeDuration. This is due to the ambiguity
associated with the number of days in a given month. This number
may vary from 28 to 31 depending on how time duration is
applied. For instance, the elapsed time in days/seconds of a given
time duration (say P2M1D, i.e., 2 months and 1 day) from January 1,
1996 and January 1, 2001 are not equal. In order to resolve this
indeterminism, this class requires a base TimeInstant
to be specified to order instances of TimeDuration
. In
case a base time instant is not explicitly specified, this class
uses the current time as the base.
long
and
double
respectively in the Java programming
language.java.util.Date
, java.sql.Date
and
java.sql.Timestamp
) can not represent values of
years, months, days, hours, minutes, and seconds beyond the range
of -2147483648 to 2147483647, this class chooses a higher
precision for these values. Therefore, any conversion of
instances of TimeDuration
to instances of
java.util.Date
, java.sql.Date
and
java.sql.Timestamp
may be subjected rounding and
loss of information. Object
TimeDuration
Cloneable
, Comparable
, Serializable
Constructor Summary |
|
Method Summary |
public |
|
public int |
|
public int | |
public static |
|
public static |
|
public |
|
public long |
|
public long |
|
public long |
|
public long |
|
public boolean |
|
public double |
|
public long |
|
public void |
|
public void |
|
public void |
|
public void |
|
public void |
|
public void |
|
public void |
|
public void |
|
public |
|
Methods from class java.lang. |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods from interface java.lang. |
compareTo |
Constructor Detail |
protected TimeDuration()
Method Detail |
public Object
clone()
Returns a copy of this TimeDuration.
Object.clone()
public int compareTo(TimeDuration
anotherTimeDuration)
Compares this TimeDuration to another TimeDuration object. If a
base TimeInstant has not been specified for this TimeDuration,
this method uses the current time as base.
public int compareTo(Object
anotherObject)
Compares this TimeDuration with another object. if the other
object is a TimeDuration, this method behaves like
compareTo(TimeDuration). Otherwise, it throws a
ClassCastException.
public static TimeDuration
createTimeDuration(long years,
long months,
long days,
long hours,
long minutes,
double seconds,
boolean isPositive)
Given the individual fields, returns an instance of TimeDuration.
public staticGiven a string, returns an instance of TimeDuration.TimeDuration
createTimeDuration(String
timeDuration)
throwsParseException
ParseException
public TimeInstant
getBaseTimeInstant()
Returns the base TimeInstant for this TimeDuration. If a base
TimeInstant has not been set for this TimeDuration, this class
returns a TimeInstant based on the current (and local) time.
public long getDays()Returns the days field
public long getHours()Retuns the hours field
public long getMinutes()Returns the minutes field
public long getMonths()Returns the months field
public boolean getPositive()Returns true if this time duration is positive.
public double getSeconds()Returns the seconds field
public long getYears()Returns the years field
public void setBaseTimeInstant(TimeInstant
base)
Sets the base TimeInstat for this TimeDuration. The base
TimeInstant is required for ordering purposes. This may not be
set if ordering is not required.
public void setDays(long days)Sets the days field
public void setHours(long hours)Sets the hours field
public void setMinutes(long minutes)Sets the minutes field
public void setMonths(long months)Sets the months field
public void setPositive(boolean positive)Sets the time duration to be positive.
public void setSeconds(double seconds)Sets the seconds field
public void setYears(long years)Sets the years field
public String
toString()
Returns a XML schema timeDuration compliant string.
This method uses the following rules:
The above rules imply that this method does not guarantee TimeDuration.createTimeDuration(_string).toString().equals(_string) to be true.
Object.toString()