Package org.apache.axis.types
Class Duration
- java.lang.Object
-
- org.apache.axis.types.Duration
-
- All Implemented Interfaces:
java.io.Serializable
public class Duration extends java.lang.Object implements java.io.SerializableImplementation of the XML Schema type duration. Duration supports a minimum fractional second precision of milliseconds.- Author:
- Wes Moulder
, Dominik Kacprzak (dominik@opentoolbox.com) - See Also:
- XML Schema 3.2.6, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Duration()Default no-arg constructorDuration(boolean negative, int aYears, int aMonths, int aDays, int aHours, int aMinutes, double aSeconds)Duration(boolean negative, java.util.Calendar calendar)Constructs Duration from a Calendar.Duration(java.lang.String duration)Constructs Duration from a String in an xsd:duration format - PnYnMnDTnHnMnS.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanequals(java.lang.Object object)The equals method compares the time represented by duration object, not its string representation.java.util.CalendargetAsCalendar()Returns duration as a calendar.java.util.CalendargetAsCalendar(java.util.Calendar startTime)Returns duration as a calendar.intgetDays()intgetHours()intgetMinutes()intgetMonths()doublegetSeconds()intgetYears()inthashCode()booleanisNegative()voidparseDate(java.lang.String date)This method parses the date portion of a String that represents xsd:duration - nYnMnD.voidparseTime(java.lang.String time)This method parses the time portion of a String that represents xsd:duration - nHnMnS.voidsetDays(int days)voidsetHours(int hours)voidsetMinutes(int minutes)voidsetMonths(int months)voidsetNegative(boolean negative)voidsetSeconds(double seconds)Sets the seconds.voidsetSeconds(int seconds)Deprecated.usesetSeconds(double)insteadvoidsetYears(int years)java.lang.StringtoString()This returns the xml representation of an xsd:duration object.
-
-
-
Constructor Detail
-
Duration
public Duration()
Default no-arg constructor
-
Duration
public Duration(boolean negative, int aYears, int aMonths, int aDays, int aHours, int aMinutes, double aSeconds)- Parameters:
negative-aYears-aMonths-aDays-aHours-aMinutes-aSeconds-
-
Duration
public Duration(java.lang.String duration) throws java.lang.IllegalArgumentExceptionConstructs Duration from a String in an xsd:duration format - PnYnMnDTnHnMnS.- Parameters:
duration- String- Throws:
SchemaException- if the string doesn't parse correctly.java.lang.IllegalArgumentException
-
Duration
public Duration(boolean negative, java.util.Calendar calendar) throws java.lang.IllegalArgumentExceptionConstructs Duration from a Calendar.- Parameters:
calendar- Calendar- Throws:
java.lang.IllegalArgumentException- if the calendar object does not represent any date nor time.
-
-
Method Detail
-
parseTime
public void parseTime(java.lang.String time) throws java.lang.IllegalArgumentExceptionThis method parses the time portion of a String that represents xsd:duration - nHnMnS.- Parameters:
time-- Throws:
java.lang.IllegalArgumentException- if time does not match pattern
-
parseDate
public void parseDate(java.lang.String date) throws java.lang.IllegalArgumentExceptionThis method parses the date portion of a String that represents xsd:duration - nYnMnD.- Parameters:
date-- Throws:
java.lang.IllegalArgumentException- if date does not match pattern
-
isNegative
public boolean isNegative()
-
getYears
public int getYears()
-
getMonths
public int getMonths()
-
getDays
public int getDays()
-
getHours
public int getHours()
-
getMinutes
public int getMinutes()
-
getSeconds
public double getSeconds()
-
setNegative
public void setNegative(boolean negative)
- Parameters:
negative-
-
setYears
public void setYears(int years)
- Parameters:
years-
-
setMonths
public void setMonths(int months)
- Parameters:
months-
-
setDays
public void setDays(int days)
- Parameters:
days-
-
setHours
public void setHours(int hours)
- Parameters:
hours-
-
setMinutes
public void setMinutes(int minutes)
- Parameters:
minutes-
-
setSeconds
public void setSeconds(int seconds)
Deprecated.usesetSeconds(double)instead- Parameters:
seconds-
-
setSeconds
public void setSeconds(double seconds)
Sets the seconds. NOTE: The fractional value of seconds is rounded up to milliseconds.- Parameters:
seconds- double
-
toString
public java.lang.String toString()
This returns the xml representation of an xsd:duration object.- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object object)
The equals method compares the time represented by duration object, not its string representation. Hence, a duration object representing 65 minutes is considered equal to a duration object representing 1 hour and 5 minutes.- Overrides:
equalsin classjava.lang.Object- Parameters:
object-
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getAsCalendar
public java.util.Calendar getAsCalendar()
Returns duration as a calendar. Due to the way a Calendar class works, the values for particular fields may not be the same as obtained through getter methods. For example, if a duration's object getMonths returns 20, a similar call on a calendar object will return 1 year and 8 months.- Returns:
- Calendar
-
getAsCalendar
public java.util.Calendar getAsCalendar(java.util.Calendar startTime)
Returns duration as a calendar. Due to the way a Calendar class works, the values for particular fields may not be the same as obtained through getter methods. For example, if a Duration's object getMonths returns 20, a similar call on a Calendar object will return 1 year and 8 months.- Parameters:
startTime- Calendar- Returns:
- Calendar
-
-