|
© 2005 BEA Systems, Inc. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.bea.p13n.xml.schema.TimeDuration
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.
Constructor Summary | |
protected |
TimeDuration()
Creates an instance of TimeDuration |
Method Summary | |
Object |
clone()
Returns a copy of this TimeDuration. |
int |
compareTo(Object anotherObject)
Compares this TimeDuration with another object. if the other object is a TimeDuration, this method behaves like compareTo(TimeDuration). |
int |
compareTo(TimeDuration anotherTimeDuration)
Compares this TimeDuration to another TimeDuration object. |
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. |
static TimeDuration |
createTimeDuration(String timeDuration)
Given a string, returns an instance of TimeDuration. |
TimeInstant |
getBaseTimeInstant()
Returns the base TimeInstant for this TimeDuration. |
long |
getDays()
Returns the days field |
long |
getHours()
Retuns the hours field |
long |
getMinutes()
Returns the minutes field |
long |
getMonths()
Returns the months field |
boolean |
getPositive()
Returns true if this time duration is positive. |
double |
getSeconds()
Returns the seconds field |
long |
getYears()
Returns the years field |
void |
setBaseTimeInstant(TimeInstant base)
Sets the base TimeInstat for this TimeDuration. |
void |
setDays(long days)
Sets the days field |
void |
setHours(long hours)
Sets the hours field |
void |
setMinutes(long minutes)
Sets the minutes field |
void |
setMonths(long months)
Sets the months field |
void |
setPositive(boolean positive)
Sets the time duration to be positive. |
void |
setSeconds(double seconds)
Sets the seconds field |
void |
setYears(long years)
Sets the years field |
String |
toString()
Returns a XML schema timeDuration compliant string. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
protected TimeDuration()
Method Detail |
public Object clone()
public int compareTo(Object anotherObject)
compareTo
in interface Comparable
IllegalStateException
- thrown when the base
TimeInstant is not specified for this TimeDuration.
IllegalStateException
- thrown when the base
TimeInstant * is not specified for this TimeDuration.public int compareTo(TimeDuration anotherTimeDuration)
public static TimeDuration createTimeDuration(long years, long months, long days, long hours, long minutes, double seconds, boolean isPositive)
months
- months fielddays
- days fieldhours
- hours fieldminutes
- minutes fieldseconds
- seconds fieldisPositive
- sign field
public static TimeDuration createTimeDuration(String timeDuration) throws ParseException
ParseException
- thrown due to illegal string argumentpublic TimeInstant getBaseTimeInstant()
public long getDays()
public long getHours()
public long getMinutes()
public long getMonths()
public boolean getPositive()
public double getSeconds()
public long getYears()
public void setBaseTimeInstant(TimeInstant base)
base
- base TimeInstant for ordering purposespublic void setDays(long days)
days
- days fieldpublic void setHours(long hours)
hours
- hours fieldpublic void setMinutes(long minutes)
minutes
- minutes fieldpublic void setMonths(long months)
months
- months fieldpublic void setPositive(boolean positive)
positive
- true for positive time
duration. false otherwise.public void setSeconds(double seconds)
seconds
- seconds fieldpublic void setYears(long years)
years
- years fieldpublic 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.
|
© 2005 BEA Systems, Inc. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |