Class DateTime
java.lang.Object
org.exolab.castor.types.DateTimeBase
org.exolab.castor.types.DateTime
- All Implemented Interfaces:
Serializable, Cloneable
Describe an XML schema DateTime.
The format is defined by W3C XML Schema Recommendation and ISO8601 i.e (-)CCYY-MM-DD'T'HH:MM:SS(.SSSSS)(Z|(+|-)hh:mm)
- Version:
- $Revision: 0000 $
- Author:
- Edward Kuns
- See Also:
-
Field Summary
Fields inherited from class DateTimeBase
EQUALS, GREATER_THAN, INDETERMINATE, LESS_THAN, MAX_TIME_ZONE_COMPARISON_OFFSET, WRONGLY_PLACEDModifier and TypeFieldDescriptionstatic final intPublic constant referring to a Date/Time comparison result of "equals".static final intPublic constant referring to a Date/Time comparison result of "greater than".static final intPublic constant referring to an indeterminate Date/Time comparison.static final intPublic constant referring to a Date/Time comparison result of "less than".protected static final intWhen comparing a date/time with a time zone to one without, the recommendation says that 14 hours is the time zone offset to use for comparison.protected static final StringConvenience String for complaints. -
Constructor Summary
ConstructorsConstructorDescriptionDateTime()Default constructor.DateTime(long dateAsLong) Creates a new XML Schema DateTime instance from a long that represents a Date.DateTime(short[] values) Constructs a XML Schema DateTime instance given all the values of the different date and time (but not time zone) fields.Constructs a DateTime from a String.Creates a new XML Schema DateTime instance from a java.util.Date. -
Method Summary
Modifier and TypeMethodDescriptionshort[]Returns an array of shorts with all the fields that describe this DateTime type.static DateTimeParses a String into a new DateTime instance.static DateTimeparseDateTime(String str) Parses a String into a new DateTime instance.voidsetValues(short[] values) Sets all the fields to the values provided in an Array.toDate()Converts this DateTime into a local java.util.Date.longtoLong()Converts this DateTime into a long value representing a java.util.Date.toString()Converts this DateTime to a string.Methods inherited from class DateTimeBase
addDuration, appendDateString, appendTimeString, appendTimeZoneString, clone, compareTo, equal, equals, getCentury, getDay, getHour, getMilli, getMinute, getMonth, getSeconds, getYear, getZoneHour, getZoneMinute, hasCentury, hasDay, hashCode, hasHour, hasIsNegative, hasMilli, hasMinute, hasMonth, hasSeconds, hasYear, isLeap, isNegative, isUTC, isZoneNegative, normalize, parseDay, parseMonth, parseTime, parseTimeZone, parseYear, setCentury, setDateFormatTimeZone, setDateFormatTimeZone, setDay, setHour, setMilliSecond, setMinute, setMonth, setNegative, setSecond, setSecond, setUTC, setYear, setZone, setZoneHour, setZoneMinute, setZoneNegative, toCalendarModifier and TypeMethodDescriptionvoidaddDuration(Duration duration) Adds a Duration to this Date/Time type as defined in Adding Duration to dateTimes (W3C XML Schema, part 2 appendix E). This version uses the algorithm defined in the document from W3C.protected voidappendDateString(StringBuffer result) protected voidappendTimeString(StringBuffer result) protected voidappendTimeZoneString(StringBuffer result) clone(DateTimeBase dateTime) intcompareTo(DateTimeBase dateTime) Compares two date/time data types.protected booleanequal(DateTimeBase dateTime) Returns true if the present instance of date/time type is equal to the parameter.booleanOverrides the java.lang.Object#equals method.shortshortgetDay()shortgetHour()shortgetMilli()shortshortgetMonth()shortshortgetYear()shortshortbooleanbooleanhasDay()inthashCode()Overrides the java.lang.Object#hashcode method.booleanhasHour()boolean/////////////////////Getter methods//////////////////////////////////////booleanhasMilli()booleanbooleanhasMonth()booleanbooleanhasYear()final booleanisLeap(int year) Returns true if the given year represents a leap year.boolean/////////////////////Getter methods//////////////////////////////////////booleanisUTC()Returns true if this date/time type is UTC, that is, has a time zone assigned.booleanvoidNormalizes a date/time datatype as defined in W3C XML Schema Recommendation document: if a timeZone is present but it is not Z then we convert the date/time datatype to Z using the addition operation defined in Adding Duration to dateTimes (W3C XML Schema, part 2 appendix E).protected static intparseDay(String str, DateTimeBase result, char[] chars, int index, String complaint) protected static intparseMonth(String str, DateTimeBase result, char[] chars, int index, String complaint) protected static intparseTime(String str, DateTimeBase result, char[] chars, int index, String complaint) protected static intparseTimeZone(String str, DateTimeBase result, char[] chars, int index, String complaint) protected static intparseYear(String str, DateTimeBase result, char[] chars, int index, String complaint) /////////// COMMON CODE USED BY EXTENDING CLASSES ///////////////////////voidsetCentury(short century) Set the century field.protected voidSets the time zone in the provided DateFormat.protected voidsetDateFormatTimeZone(Calendar calendar) Sets the time zone in the provided Calendar.voidsetDay(short day) Sets the Day Field.voidsetHour(short hour) Sets the hour field for this date/time type.voidsetMilliSecond(short millisecond) Sets the millisecond field for this date/time type.voidsetMinute(short minute) set the minute field for this date/time type.voidsetMonth(short month) Sets the Month Field.voidSet the negative field to true.voidsetSecond(short second) Sets the seconds field for this date/time type, not including the fractional seconds.voidsetSecond(short second, short millsecond) Sets the seconds field for this date/time type, including fractional seconds.voidsetUTC()Sets the UTC field.voidsetYear(short year) Sets the Year field.voidsetZone(short hour, short minute) Sets the time zone fields for this date/time type.voidsetZoneHour(short hour) Sets the time zone hour field for this date/time type.voidsetZoneMinute(short minute) Sets the time zone minute field for this date/time type.voidsetZoneNegative(boolean zoneNegative) Sets the time zone negative field to true.converts this Date/Time into a local java Calendar.
-
Constructor Details
-
DateTime
public DateTime()Default constructor. -
DateTime
public DateTime(short[] values) Constructs a XML Schema DateTime instance given all the values of the different date and time (but not time zone) fields.By default a DateTime is not UTC, and is local. To set a timezone, you need to separately call
DateTimeBase.setZone(short, short).- Parameters:
values- an array of shorts that represent the different fields of Time.- See Also:
-
DateTime
public DateTime(long dateAsLong) Creates a new XML Schema DateTime instance from a long that represents a Date. No time zone information is set.By default a DateTime is not UTC, and is local. To set a timezone, you need to separately call
DateTimeBase.setZone(short, short).- Parameters:
dateAsLong- java.util.Date represented as a long.
-
DateTime
Creates a new XML Schema DateTime instance from a java.util.Date. No time zone information is set.By default a DateTime is not UTC, and is local. To set a timezone, you need to separately call
DateTimeBase.setZone(short, short).- Parameters:
dateRef- a java.util.Date to convert.
-
DateTime
Constructs a DateTime from a String. The String is expected to be in W3C Schema DateTime format.- Parameters:
date- the string representing the date- Throws:
ParseException- if we are passed an illegal value
-
-
Method Details
-
setValues
public void setValues(short[] values) Sets all the fields to the values provided in an Array. The Array must be at least eight entries long. Extra entries are ignored. The order of entries in the array is as follows:- century
- year
- month
- day
- hour
- minute
- second
- millisecond
setZone. A time zone previously set will not be cleared.- Specified by:
setValuesin classDateTimeBase- Parameters:
values- An array of shorts containing the values for the DateTime
-
getValues
public short[] getValues()Returns an array of shorts with all the fields that describe this DateTime type. The order of entries in the array is as follows:- century
- year
- month
- day
- hour
- minute
- second
- millisecond
- Specified by:
getValuesin classDateTimeBase- Returns:
- an array of short with all the fields that describe this Date type.
-
toDate
Converts this DateTime into a local java.util.Date.- Specified by:
toDatein classDateTimeBase- Returns:
- a local java.util.Date representing this DateTime.
-
toLong
public long toLong()Converts this DateTime into a long value representing a java.util.Date.- Returns:
- This DateTime instance as a long value representing a java.util.Date.
-
toString
-
parse
Parses a String into a new DateTime instance.- Parameters:
str- the string to parse- Returns:
- a new DateTime instance with the value of the parsed string.
- Throws:
ParseException- If the string to parse does not follow the right format
-
parseDateTime
Parses a String into a new DateTime instance.- Parameters:
str- the string to parse- Returns:
- a new DateTime instance with the value of the parsed string.
- Throws:
ParseException- If the string to parse does not follow the right format
-