addDuration
public 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. A later
version may optimize it.
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 add
appendDateString
protected void appendDateString(StringBuffer result)
appendTimeString
protected void appendTimeString(StringBuffer result)
appendTimeZoneString
protected void appendTimeZoneString(StringBuffer result)
compareTo
public int compareTo(DateTimeBase dateTime)
Compares two date/time data types. The algorithm of comparison is defined
in
W3C XML Schema
Recommendation (section 3.2.7.3)
The returned value will be one of:
- INDETERMINATE (-1): this ? dateTime
- LESS_THAN (0): this <32dateTime
- EQUALS (1): this == dateTime
- GREATER_THAN (2): this > dateTime
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.
- the status of the comparison.
equal
protected boolean equal(DateTimeBase dateTime)
Returns true if the present instance of date/time type is equal to the
parameter.
The equals relation is as defined in the W3C XML Schema Recommendation,
part2.
dateTime
- the date/time type to compare with the present instance
- true if the present instance is equal to the parameter false if
not
equals
public boolean equals(Object object)
Overrides the java.lang.Object#equals method.
getCentury
public short getCentury()
throws UnsupportedOperationException
getDay
public short getDay()
throws UnsupportedOperationException
getHour
public short getHour()
throws UnsupportedOperationException
getMilli
public short getMilli()
throws UnsupportedOperationException
getMinute
public short getMinute()
throws UnsupportedOperationException
getMonth
public short getMonth()
throws UnsupportedOperationException
getSeconds
public short getSeconds()
throws UnsupportedOperationException
getValues
public abstract short[] getValues()
returns an array of short with all the fields that describe a date/time
type.
- an array of short with all the fields that describe a date/time
type.
getYear
public short getYear()
throws UnsupportedOperationException
getZoneHour
public short getZoneHour()
getZoneMinute
public short getZoneMinute()
hasCentury
public boolean hasCentury()
hasDay
public boolean hasDay()
hasHour
public boolean hasHour()
hasIsNegative
public boolean hasIsNegative()
hasMilli
public boolean hasMilli()
hasMinute
public boolean hasMinute()
hasMonth
public boolean hasMonth()
hasSeconds
public boolean hasSeconds()
hasYear
public boolean hasYear()
hashCode
public int hashCode()
Overrides the java.lang.Object#hashcode method.
isLeap
public final boolean isLeap(int year)
Returns true if the given year represents a leap year. A specific year is
a leap year if it is either evenly divisible by 400 OR evenly divisible
by 4 and not evenly divisible by 100.
year
- the year to test where 0 <32year <= 9999
- true if the given year represents a leap year
isNegative
public boolean isNegative()
throws UnsupportedOperationException
isUTC
public boolean isUTC()
Returns true if this date/time type is UTC, that is, has a time zone
assigned. A date/time type is UTC if a 'Z' appears at the end of the
lexical representation type or if it contains a time zone.
- true if this type has a time zone assigned, else false.
isZoneNegative
public boolean isZoneNegative()
normalize
public void normalize()
parseDay
protected static int parseDay(String str,
DateTimeBase result,
char[] chars,
int index,
String complaint)
throws ParseException
parseMonth
protected static int parseMonth(String str,
DateTimeBase result,
char[] chars,
int index,
String complaint)
throws ParseException
parseTime
protected static int parseTime(String str,
DateTimeBase result,
char[] chars,
int index,
String complaint)
throws ParseException
parseTimeZone
protected static int parseTimeZone(String str,
DateTimeBase result,
char[] chars,
int index,
String complaint)
throws ParseException
parseYear
protected static int parseYear(String str,
DateTimeBase result,
char[] chars,
int index,
String complaint)
throws ParseException
setCentury
public void setCentury(short century)
throws UnsupportedOperationException
Set the century field. Note: year 0000 is not allowed.
century
- the value to set
setDateFormatTimeZone
protected void setDateFormatTimeZone(Calendar calendar)
Sets the time zone in the provided Calendar.
setDateFormatTimeZone
protected void setDateFormatTimeZone(DateFormat df)
Sets the time zone in the provided DateFormat.
setDay
public void setDay(short day)
throws UnsupportedOperationException
Sets the Day Field. Note: This field is validated before the assignment
is done.
day
- the value to set up
setHour
public void setHour(short hour)
throws UnsupportedOperationException
Sets the hour field for this date/time type.
setMilliSecond
public void setMilliSecond(short millisecond)
throws UnsupportedOperationException
Sets the millisecond field for this date/time type.
millisecond
- the millisecond to set
setMinute
public void setMinute(short minute)
throws UnsupportedOperationException
set the minute field for this date/time type.
minute
- the minute to set.
setMonth
public void setMonth(short month)
throws UnsupportedOperationException
Sets the Month Field. Note 1 <= month <= 12.
month
- the value to set up
setNegative
public void setNegative()
throws UnsupportedOperationException
Set the negative field to true.
setSecond
public void setSecond(short second)
throws UnsupportedOperationException
Sets the seconds field for this date/time type, not including the
fractional seconds. Any fractional seconds previously set is unmodified.
second
- the second to set
setSecond
public void setSecond(short second,
short millsecond)
throws UnsupportedOperationException
Sets the seconds field for this date/time type, including fractional
seconds. (In this implementation, fractional seconds are limited
to milliseconds and are truncated at millseconds if more precision
is provided.)
second
- the second to setmillsecond
- the millisecond to set
setUTC
public void setUTC()
Sets the UTC field.
setValues
public abstract void setValues(short[] values)
Sets all the fields by reading the values in an array.
values
- an array of shorts with the values.
setYear
public void setYear(short year)
throws UnsupportedOperationException
Sets the Year field. Note: year 0000 is not allowed.
setZone
public void setZone(short hour,
short minute)
Sets the time zone fields for this date/time type. A call to this method
means that the date/time type used is UTC.
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.
setZoneHour
public void setZoneHour(short hour)
Sets the time zone hour field for this date/time type. A call to this
method means that the date/time type used is UTC.
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.
setZoneMinute
public void setZoneMinute(short minute)
Sets the time zone minute field for this date/time type. A call to this
method means that the date/time type used is UTC.
minute
- the time zone minute to set
setZoneNegative
public void setZoneNegative(boolean zoneNegative)
Sets the time zone negative field to true.
zoneNegative
- indicates whether or not the time zone is negative.
toCalendar
public Calendar toCalendar()
converts this Date/Time into a local java Calendar.
- a local calendar representing this Date or Time
toDate
public abstract Date toDate()
Returns a java.util.Date that represents the XML Schema Date datatype.
- a java.util.Date that represents the XML Schema Date datatype.