Package org.exolab.castor.types
Class Time
- java.lang.Object
-
- org.exolab.castor.types.DateTimeBase
-
- org.exolab.castor.types.Time
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public class Time extends DateTimeBase
Describes an XML schema Time.The format is defined by W3C XML Schema Recommendation and ISO8601 i.e hh:mm:ss.sss(Z|(+|-)hh:mm)
Deep support of fractional seconds is not implemented. This implementation only supports fractional second resolution of milliseconds.
- Version:
- $Revision: 8100 $
- Author:
- Arnaud Blandin, Edward Kuns
- See Also:
DateTimeBase, Serialized Form
-
-
Field Summary
-
Fields inherited from class org.exolab.castor.types.DateTimeBase
EQUALS, GREATER_THAN, INDETERMINATE, LESS_THAN, MAX_TIME_ZONE_COMPARISON_OFFSET, WRONGLY_PLACED
-
-
Constructor Summary
Constructors Constructor Description Time()No-arg constructor.Time(long l)Constructs a XML Schema Time instance given a long representing the time in milliseconds.Time(long l, boolean utc)Constructs a XML Schema Time instance given a long representing the time in milliseconds.Time(short[] values)Constructs a XML Schema Time instance given all the values of the different fields.Time(java.lang.String time)Constructs a Time given a string representation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description shortgetCentury()shortgetDay()shortgetMonth()short[]getValues()returns an array of short with all the fields that describe this time type.shortgetYear()booleanhasCentury()booleanhasDay()booleanhasIsNegative()booleanhasMonth()booleanhasYear()booleanisNegative()static java.lang.Objectparse(java.lang.String str)parses a String and converts it into a java.lang.Objectstatic TimeparseTime(java.lang.String str)parses a String and converts it into a Time.voidsetCentury(short century)Set the century field.voidsetDay(short month)Sets the Day Field.voidsetMonth(short month)Sets the Month Field.voidsetNegative()Set the negative field to true.voidsetValues(short[] values)Sets all the fields by reading the values in an array.voidsetYear(short year)Sets the Year field.java.util.DatetoDate()converts this Time into a local java Date.longtoLong()Converts this Time instance into a long value based on UTC time zone.java.lang.StringtoString()convert this Time to a string The format is defined by W3C XML Schema Recommendation and ISO8601 i.e hh:mm:ss.sss(Z|(+|-)hh:mm)-
Methods inherited from class org.exolab.castor.types.DateTimeBase
addDuration, appendDateString, appendTimeString, appendTimeZoneString, clone, compareTo, equal, equals, getHour, getMilli, getMinute, getSeconds, getZoneHour, getZoneMinute, hashCode, hasHour, hasMilli, hasMinute, hasSeconds, isLeap, isUTC, isZoneNegative, normalize, parseDay, parseMonth, parseTime, parseTimeZone, parseYear, setDateFormatTimeZone, setDateFormatTimeZone, setHour, setMilliSecond, setMinute, setSecond, setSecond, setUTC, setZone, setZoneHour, setZoneMinute, setZoneNegative, toCalendar
-
-
-
-
Constructor Detail
-
Time
public Time()
No-arg constructor.
-
Time
public Time(short[] values)
Constructs a XML Schema Time instance given all the values of the different fields. By default a Time is not UTC and is local.- Parameters:
values- an array of shorts that represent the different fields of Time.
-
Time
public Time(long l)
Constructs a XML Schema Time instance given a long representing the time in milliseconds. By default a Time is not UTC and is local.- Parameters:
l- The long value that represents the time instance.
-
Time
public Time(long l, boolean utc)Constructs a XML Schema Time instance given a long representing the time in milliseconds.- Parameters:
l- The long value that represents the time instance.utc- Does the long value represent a UTC time?
-
Time
public Time(java.lang.String time) throws java.text.ParseExceptionConstructs a Time given a string representation.- Parameters:
time- the string representation of the Time to instantiate- Throws:
java.text.ParseException- a parse exception is thrown if the string to parse does not follow the rigth format (see the description of this class)
-
-
Method Detail
-
setValues
public void setValues(short[] values)
Sets all the fields by reading the values in an array.if a Time Zone is specified it has to be set by using
setZone.- Specified by:
setValuesin classDateTimeBase- Parameters:
values- an array of shorts with the values the array is supposed to be of length 4 and ordered like that:- hour
- minute
- second
- millisecond
-
getValues
public short[] getValues()
returns an array of short with all the fields that describe this time type.Note:the time zone is not included.
- Specified by:
getValuesin classDateTimeBase- Returns:
- an array of short with all the fields that describe this time type.
-
toLong
public long toLong()
Converts this Time instance into a long value based on UTC time zone.- Returns:
- A long value representing this Time instance.
-
toDate
public java.util.Date toDate()
converts this Time into a local java Date.- Specified by:
toDatein classDateTimeBase- Returns:
- a local date representing this Time
-
toString
public java.lang.String toString()
convert this Time to a string The format is defined by W3C XML Schema Recommendation and ISO8601 i.e hh:mm:ss.sss(Z|(+|-)hh:mm)- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representing this Time
-
parse
public static java.lang.Object parse(java.lang.String str) throws java.text.ParseExceptionparses a String and converts it into a java.lang.Object- Parameters:
str- the string to parse- Returns:
- the java.lang.Object represented by the string
- Throws:
java.text.ParseException- a parse exception is thrown if the string to parse does not follow the rigth format (see the description of this class)
-
parseTime
public static Time parseTime(java.lang.String str) throws java.text.ParseException
parses a String and converts it into a Time.- Parameters:
str- the string to parse- Returns:
- the Time represented by the string
- Throws:
java.text.ParseException- a parse exception is thrown if the string to parse does not follow the rigth format (see the description of this class)
-
hasIsNegative
public boolean hasIsNegative()
- Overrides:
hasIsNegativein classDateTimeBase
-
isNegative
public boolean isNegative()
- Overrides:
isNegativein classDateTimeBase
-
setNegative
public void setNegative()
Description copied from class:DateTimeBaseSet the negative field to true.- Overrides:
setNegativein classDateTimeBase
-
hasCentury
public boolean hasCentury()
- Overrides:
hasCenturyin classDateTimeBase
-
getCentury
public short getCentury()
- Overrides:
getCenturyin classDateTimeBase
-
setCentury
public void setCentury(short century)
Description copied from class:DateTimeBaseSet the century field. Note: year 0000 is not allowed.- Overrides:
setCenturyin classDateTimeBase- Parameters:
century- the value to set
-
hasYear
public boolean hasYear()
- Overrides:
hasYearin classDateTimeBase
-
getYear
public short getYear()
- Overrides:
getYearin classDateTimeBase
-
setYear
public void setYear(short year)
Description copied from class:DateTimeBaseSets the Year field. Note: year 0000 is not allowed.- Overrides:
setYearin classDateTimeBase- Parameters:
year- the year to set
-
hasMonth
public boolean hasMonth()
- Overrides:
hasMonthin classDateTimeBase
-
getMonth
public short getMonth()
- Overrides:
getMonthin classDateTimeBase
-
setMonth
public void setMonth(short month)
Description copied from class:DateTimeBaseSets the Month Field. Note 1 <= month <= 12.- Overrides:
setMonthin classDateTimeBase- Parameters:
month- the value to set up
-
hasDay
public boolean hasDay()
- Overrides:
hasDayin classDateTimeBase
-
getDay
public short getDay()
- Overrides:
getDayin classDateTimeBase
-
setDay
public void setDay(short month)
Description copied from class:DateTimeBaseSets the Day Field. Note: This field is validated before the assignment is done.- Overrides:
setDayin classDateTimeBase- Parameters:
month- the value to set up
-
-