java.io.Serializable
, java.lang.Cloneable
public abstract class DateTimeBase
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
The validation of the date/time fields is done in the set methods and follows the ISO8601 Date and Time Format.
Note: the Castor date/time types are mutable, unlike the date/time types of the JDK in Java2. This is needed by the Marshaling framework.
DateTime
,
Date
,
Time
,
Serialized FormModifier and Type | Field | Description |
---|---|---|
static int |
EQUALS |
Public constant referring to a Date/Time comparison result of "equals".
|
static int |
GREATER_THAN |
Public constant referring to a Date/Time comparison result of "greater than".
|
static int |
INDETERMINATE |
Public constant referring to an indeterminate Date/Time comparison.
|
static int |
LESS_THAN |
Public constant referring to a Date/Time comparison result of "less than".
|
protected static int |
MAX_TIME_ZONE_COMPARISON_OFFSET |
When 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 java.lang.String |
WRONGLY_PLACED |
Convenience String for complaints.
|
Constructor | Description |
---|---|
DateTimeBase() |
Modifier and Type | Method | Description |
---|---|---|
void |
addDuration(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 void |
appendDateString(java.lang.StringBuffer result) |
|
protected void |
appendTimeString(java.lang.StringBuffer result) |
|
protected void |
appendTimeZoneString(java.lang.StringBuffer result) |
|
DateTimeBase |
clone(DateTimeBase dateTime) |
|
int |
compareTo(DateTimeBase dateTime) |
Compares two date/time data types.
|
protected boolean |
equal(DateTimeBase dateTime) |
Returns true if the present instance of date/time type is equal to the
parameter.
|
boolean |
equals(java.lang.Object object) |
Overrides the java.lang.Object#equals method.
|
short |
getCentury() |
|
short |
getDay() |
|
short |
getHour() |
|
short |
getMilli() |
|
short |
getMinute() |
|
short |
getMonth() |
|
short |
getSeconds() |
|
abstract short[] |
getValues() |
returns an array of short with all the fields that describe a date/time
type.
|
short |
getYear() |
|
short |
getZoneHour() |
|
short |
getZoneMinute() |
|
boolean |
hasCentury() |
|
boolean |
hasDay() |
|
int |
hashCode() |
Overrides the java.lang.Object#hashcode method.
|
boolean |
hasHour() |
|
boolean |
hasIsNegative() |
|
boolean |
hasMilli() |
|
boolean |
hasMinute() |
|
boolean |
hasMonth() |
|
boolean |
hasSeconds() |
|
boolean |
hasYear() |
|
boolean |
isLeap(int year) |
Returns true if the given year represents a leap year.
|
boolean |
isNegative() |
|
boolean |
isUTC() |
Returns true if this date/time type is UTC, that is, has a time zone
assigned.
|
boolean |
isZoneNegative() |
|
void |
normalize() |
Normalizes 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 int |
parseDay(java.lang.String str,
DateTimeBase result,
char[] chars,
int index,
java.lang.String complaint) |
|
protected static int |
parseMonth(java.lang.String str,
DateTimeBase result,
char[] chars,
int index,
java.lang.String complaint) |
|
protected static int |
parseTime(java.lang.String str,
DateTimeBase result,
char[] chars,
int index,
java.lang.String complaint) |
|
protected static int |
parseTimeZone(java.lang.String str,
DateTimeBase result,
char[] chars,
int index,
java.lang.String complaint) |
|
protected static int |
parseYear(java.lang.String str,
DateTimeBase result,
char[] chars,
int index,
java.lang.String complaint) |
|
void |
setCentury(short century) |
Set the century field.
|
protected void |
setDateFormatTimeZone(java.text.DateFormat df) |
Sets the time zone in the provided DateFormat.
|
protected void |
setDateFormatTimeZone(java.util.Calendar calendar) |
Sets the time zone in the provided Calendar.
|
void |
setDay(short day) |
Sets the Day Field.
|
void |
setHour(short hour) |
Sets the hour field for this date/time type.
|
void |
setMilliSecond(short millisecond) |
Sets the millisecond field for this date/time type.
|
void |
setMinute(short minute) |
set the minute field for this date/time type.
|
void |
setMonth(short month) |
Sets the Month Field.
|
void |
setNegative() |
Set the negative field to true.
|
void |
setSecond(short second) |
Sets the seconds field for this date/time type, not including the
fractional seconds.
|
void |
setSecond(short second,
short millsecond) |
Sets the seconds field for this date/time type, including fractional
seconds.
|
void |
setUTC() |
Sets the UTC field.
|
abstract void |
setValues(short[] values) |
Sets all the fields by reading the values in an array.
|
void |
setYear(short year) |
Sets the Year field.
|
void |
setZone(short hour,
short minute) |
Sets the time zone fields for this date/time type.
|
void |
setZoneHour(short hour) |
Sets the time zone hour field for this date/time type.
|
void |
setZoneMinute(short minute) |
Sets the time zone minute field for this date/time type.
|
void |
setZoneNegative(boolean zoneNegative) |
Sets the time zone negative field to true.
|
java.util.Calendar |
toCalendar() |
converts this Date/Time into a local java Calendar.
|
abstract java.util.Date |
toDate() |
Returns a java.util.Date that represents the XML Schema Date datatype.
|
public static final int INDETERMINATE
public static final int LESS_THAN
public static final int EQUALS
public static final int GREATER_THAN
protected static final int MAX_TIME_ZONE_COMPARISON_OFFSET
protected static final java.lang.String WRONGLY_PLACED
public abstract java.util.Date toDate()
public abstract void setValues(short[] values)
values
- an array of shorts with the values.public abstract short[] getValues()
public final boolean isLeap(int year)
year
- the year to test where 0 < year <= 9999public void setNegative() throws java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
- this exception is thrown when changing the value of the
"century+year is negative" field is not allowed.public void setCentury(short century) throws java.lang.UnsupportedOperationException
century
- the value to setjava.lang.UnsupportedOperationException
- this exception is thrown when changing the value of the
century field is not allowedpublic void setYear(short year) throws java.lang.UnsupportedOperationException
year
- the year to setjava.lang.UnsupportedOperationException
- in an overridden method in a derived class if that derived
class does not support the year element.public void setMonth(short month) throws java.lang.UnsupportedOperationException
month
- the value to set upjava.lang.UnsupportedOperationException
- in an overridden method in a derived class if that derived
class does not support the month element.public void setDay(short day) throws java.lang.UnsupportedOperationException
day
- the value to set upjava.lang.UnsupportedOperationException
- in an overridden method in a derived class if that derived
class does not support the day element.public void setHour(short hour) throws java.lang.UnsupportedOperationException
hour
- the hour to setjava.lang.UnsupportedOperationException
- this exception is thrown when changing the value of the hour
field is not allowedpublic void setMinute(short minute) throws java.lang.UnsupportedOperationException
minute
- the minute to set.java.lang.UnsupportedOperationException
- this exception is thrown when changing the value of the
minute field is not allowedpublic void setSecond(short second, short millsecond) throws java.lang.UnsupportedOperationException
second
- the second to setmillsecond
- the millisecond to setjava.lang.UnsupportedOperationException
- this exception is thrown when changing the value of the
second field is not allowedpublic void setSecond(short second) throws java.lang.UnsupportedOperationException
second
- the second to setjava.lang.UnsupportedOperationException
- this exception is thrown when changing the value of the
second field is not allowedpublic void setMilliSecond(short millisecond) throws java.lang.UnsupportedOperationException
millisecond
- the millisecond to setjava.lang.UnsupportedOperationException
- this exception is thrown when changing the value of the
millisecond field is not allowedpublic void setUTC()
public void setZoneNegative(boolean zoneNegative)
zoneNegative
- indicates whether or not the time zone is negative.java.lang.UnsupportedOperationException
- this exception is thrown when changing the time zone fields
is not allowedpublic void setZone(short hour, short minute)
For a negative time zone, you first assign the absolute value of the time
zone using this method and then you call
setZoneNegative(boolean)
.
hour
- The time zone hour to set. Must be positive.minute
- The time zone minute to set.java.lang.UnsupportedOperationException
- this exception is thrown when changing the value of the time
zone fields is not allowedpublic void setZoneHour(short hour)
For a negative time zone, you first assign the absolute value of the time
zone using this method and then you call
setZoneNegative(boolean)
.
hour
- the time zone hour to set. Must be positive.java.lang.UnsupportedOperationException
- this exception is thrown when changing the value of the time
zone fields is not allowedpublic void setZoneMinute(short minute)
minute
- the time zone minute to setjava.lang.UnsupportedOperationException
- this exception is thrown when changing the value of the time
zone fields is not allowedpublic boolean isNegative() throws java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
public short getCentury() throws java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
public short getYear() throws java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
public short getMonth() throws java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
public short getDay() throws java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
public short getHour() throws java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
public short getMinute() throws java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
public short getSeconds() throws java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
public short getMilli() throws java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
public boolean isUTC()
public boolean isZoneNegative()
public short getZoneHour()
public short getZoneMinute()
public boolean hasIsNegative()
public boolean hasCentury()
public boolean hasYear()
public boolean hasMonth()
public boolean hasDay()
public boolean hasHour()
public boolean hasMinute()
public boolean hasSeconds()
public boolean hasMilli()
public void addDuration(Duration duration)
The modified Date/Time instance will keep the same time zone it started with, if any.
Don't use getter methods but use direct field access for dateTime in order to have the behaviour defined in the Recommendation document.
duration
- the duration to addpublic void normalize()
public int compareTo(DateTimeBase dateTime)
The returned value will be one of:
FIXME: This code does not compare time zones properly for date/time types that do not contain a time.
dateTime
- the dateTime to compare with the current instance.public DateTimeBase clone(DateTimeBase dateTime) throws java.lang.CloneNotSupportedException
java.lang.CloneNotSupportedException
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
equals(Object)
protected boolean equal(DateTimeBase dateTime)
The equals relation is as defined in the W3C XML Schema Recommendation, part2.
dateTime
- the date/time type to compare with the present instancepublic java.util.Calendar toCalendar()
protected static int parseYear(java.lang.String str, DateTimeBase result, char[] chars, int index, java.lang.String complaint) throws java.text.ParseException
java.text.ParseException
protected static int parseMonth(java.lang.String str, DateTimeBase result, char[] chars, int index, java.lang.String complaint) throws java.text.ParseException
java.text.ParseException
protected static int parseDay(java.lang.String str, DateTimeBase result, char[] chars, int index, java.lang.String complaint) throws java.text.ParseException
java.text.ParseException
protected static int parseTime(java.lang.String str, DateTimeBase result, char[] chars, int index, java.lang.String complaint) throws java.text.ParseException
java.text.ParseException
protected static int parseTimeZone(java.lang.String str, DateTimeBase result, char[] chars, int index, java.lang.String complaint) throws java.text.ParseException
java.text.ParseException
protected void setDateFormatTimeZone(java.text.DateFormat df)
df
- protected void setDateFormatTimeZone(java.util.Calendar calendar)
calendar
- protected void appendDateString(java.lang.StringBuffer result)
protected void appendTimeString(java.lang.StringBuffer result)
protected void appendTimeZoneString(java.lang.StringBuffer result)
Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com