public final class GDate extends Object implements GDateSpecification, Serializable
There are many date types in XML Schema, and this type represents the natural union of all those types. A GDate can hold any subset of date fields (Year, Month, Day, Time, Timezone, or some combination). Wherever the specification provides guidance, the guidelines in the XML Schema 1.0 specification (plus published errata) are followed.
Instances may separately have values or no values for the year, month, day-of-month, and time-of-day. Not all operations are meaningful on all combinations.
HAS_DAY, HAS_MONTH, HAS_TIME, HAS_TIMEZONE, HAS_YEAR| Constructor and Description |
|---|
GDate(Calendar calendar)
Constructs a GDate based on a java.util.Calendar.
|
GDate(CharSequence string)
Constructs a GDate based on a lexical representation.
|
GDate(Date date)
Constructs a GDate based on a java.util.Date.
|
GDate(GDateSpecification gdate)
Constructs a GDate based on another GDateSpecification.
|
GDate(int year,
int month,
int day,
int hour,
int minute,
int second,
BigDecimal fraction)
Constructs a GDate with the specified year, month, day,
hours, minutes, seconds, and optional fractional seconds, in
an unspecified timezone.
|
GDate(int year,
int month,
int day,
int hour,
int minute,
int second,
BigDecimal fraction,
int tzSign,
int tzHour,
int tzMinute)
Constructs an absolute GDate with the specified year,
month, day, hours, minutes, seconds, and optional fractional
seconds, and in the timezone specified.
|
| Modifier and Type | Method and Description |
|---|---|
GDate |
add(GDurationSpecification duration)
Adds a duration to this GDate, and returns a new GDate.
|
String |
canonicalString()
The canonical string representation.
|
int |
compareToGDate(GDateSpecification datespec)
Comparison to another GDate.
|
boolean |
equals(Object obj)
GDate is an immutable class, and equality is computed based
on its canonical value.
|
int |
getBuiltinTypeCode()
Returns the builtin type code for the shape of the information
contained in this instance, or 0 if the
instance doesn't contain information corresponding to a
Schema type.
|
XmlCalendar |
getCalendar()
Retrieves the value of the current time as an
XmlCalendar. |
Date |
getDate()
Retrieves the value of the current time as a java.util.Date
instance.
|
int |
getDay()
Gets the day-of-month.
|
int |
getFlags()
Returns a combination of flags indicating the information
contained by this GDate.
|
BigDecimal |
getFraction()
Gets the fraction-of-second.
|
int |
getHour()
Gets the hour-of-day.
|
int |
getJulianDate()
Returns the Julian date corresponding to this Gregorian date.
|
int |
getMillisecond()
Gets the rounded millisecond value.
|
int |
getMinute()
Gets the minute-of-hour.
|
int |
getMonth()
Gets the month-of-year.
|
int |
getSecond()
Gets the second-of-minute.
|
int |
getTimeZoneHour()
Gets the time zone hour.
|
int |
getTimeZoneMinute()
Gets the time zone minutes.
|
int |
getTimeZoneSign()
Gets the time zone sign.
|
int |
getYear()
Gets the year.
|
boolean |
hasDate()
True if this date/time specification specifies a full date (year, month, day)
|
boolean |
hasDay()
True if this date/time specification specifies a day-of-month.
|
int |
hashCode()
Returns a hash code for this GDate.
|
boolean |
hasMonth()
True if this date/time specification specifies a month-of-year.
|
boolean |
hasTime()
True if this date/time specification specifies a time-of-day.
|
boolean |
hasTimeZone()
True if this date/time specification specifies a timezone.
|
boolean |
hasYear()
True if this date/time specification specifies a year.
|
boolean |
isImmutable()
Returns true: all GDate instances are immutable.
|
boolean |
isValid()
True if this GDate corresponds to a valid gregorian date value
in XML schema.
|
GDate |
subtract(GDurationSpecification duration)
Adds a duration to this GDate, and returns a new GDate.
|
String |
toString()
The natural string representation.
|
public GDate(CharSequence string)
public GDate(int year,
int month,
int day,
int hour,
int minute,
int second,
BigDecimal fraction)
Note that by not specifying the timezone the GDate becomes partially unordered with respect to times that do have a specified timezone.
public GDate(int year,
int month,
int day,
int hour,
int minute,
int second,
BigDecimal fraction,
int tzSign,
int tzHour,
int tzMinute)
If you wish to have a time or date that isn't in a specified timezone, then use the constructor that does not include the timezone arguments.
public GDate(Date date)
The current offset of the default timezone is used as the timezone.
For example, if eastern daylight time is in effect at the given date, the timezone on the east coast of the United States translates to GMT-05:00 (EST) + 1:00 (DT offset) == GMT-04:00.
public GDate(Calendar calendar)
If the calendar does not have some fields set, the same absence of information is reflected in the GDate. Note that java.util.GregorianCalendar fills in all fields as soon as any are fetched, so constructing a GDate with the same calendar object twice may result in a different GDate because of a changed calendar. Note that org.apache.xmlbeans.XmlCalendar is stable if you re-get a set field, so it does not have the same problem.
public GDate(GDateSpecification gdate)
public final boolean isImmutable()
isImmutable in interface GDateSpecificationpublic int getFlags()
getFlags in interface GDateSpecificationpublic final boolean hasTimeZone()
hasTimeZone in interface GDateSpecificationpublic final boolean hasYear()
hasYear in interface GDateSpecificationpublic final boolean hasMonth()
hasMonth in interface GDateSpecificationpublic final boolean hasDay()
hasDay in interface GDateSpecificationpublic final boolean hasTime()
hasTime in interface GDateSpecificationpublic final boolean hasDate()
hasDate in interface GDateSpecificationpublic final int getYear()
getYear in interface GDateSpecificationpublic final int getMonth()
getMonth in interface GDateSpecificationpublic final int getDay()
getDay in interface GDateSpecificationpublic final int getHour()
getHour in interface GDateSpecificationpublic final int getMinute()
getMinute in interface GDateSpecificationpublic final int getSecond()
getSecond in interface GDateSpecificationpublic final BigDecimal getFraction()
getFraction in interface GDateSpecificationpublic final int getTimeZoneSign()
getTimeZoneSign in interface GDateSpecificationpublic final int getTimeZoneHour()
This is always positive: for the sign, look at getTimeZoneSign().
getTimeZoneHour in interface GDateSpecificationpublic final int getTimeZoneMinute()
This is always positive: for the sign, look at getTimeZoneSign().
getTimeZoneMinute in interface GDateSpecificationpublic int getMillisecond()
getMillisecond in interface GDateSpecificationpublic String canonicalString()
canonicalString in interface GDateSpecificationpublic boolean isValid()
isValid in interface GDateSpecificationpublic int getJulianDate()
getJulianDate in interface GDateSpecificationpublic XmlCalendar getCalendar()
XmlCalendar.
XmlCalendar is a subclass of GregorianCalendar
which is slightly customized to match XML schema date rules.
The returned XmlCalendar has only those time and date fields
set that are reflected in the GDate object. Because of the way the
Calendar contract works, any information in the isSet() vanishes
as soon as you view any unset field using get() methods.
This means that if it is important to understand which date fields
are set, you must call isSet() first before get().
getCalendar in interface GDateSpecificationpublic Date getDate()
getDate in interface GDateSpecificationpublic int compareToGDate(GDateSpecification datespec)
compareToGDate in interface GDateSpecificationdatespec - the date to compare against.public int getBuiltinTypeCode()
Value will be equal to
SchemaType.BTC_NOT_BUILTIN,
SchemaType.BTC_G_YEAR,
SchemaType.BTC_G_YEAR_MONTH,
SchemaType.BTC_G_MONTH,
SchemaType.BTC_G_MONTH_DAY,
SchemaType.BTC_G_DAY,
SchemaType.BTC_DATE,
SchemaType.BTC_DATE_TIME, or
SchemaType.BTC_TIME.
getBuiltinTypeCode in interface GDateSpecificationpublic GDate add(GDurationSpecification duration)
public GDate subtract(GDurationSpecification duration)
public boolean equals(Object obj)
public int hashCode()
public String toString()
When both time and timezone are specified, this string is not the canonical representation unless the timezone is UTC (Z) (since the same moment in time can be expressed in different timezones). To get a canonical string, use the canonicalString() method.
toString in interface GDateSpecificationtoString in class Object