GDate Class

com.bea.xml
GDate Class

public final class GDate

    extends Object
    implements GDateSpecification, Serializable

Represents an XML Schema-compatible Gregorian date.

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.


Hierarchy
Object
  GDate
All Implemented Interfaces

GDateSpecification, Serializable

Constructor Summary

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, 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.
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(CharSequence string)

Constructs a GDate based on a lexical representation.
GDate(Calendar calendar)

Constructs a GDate based on a java.util.Calendar.
GDate(Date date)

Constructs a GDate based on a java.util.Date.
 

Method Summary

public GDate
add(GDurationSpecification duration)
Adds a duration to this GDate, and returns a new GDate.
public String
canonicalString()
The canonical string representation.
public int
compareToGDate(GDateSpecification datespec)
Comparison to another GDate.
public boolean
equals(Object obj)
GDate is an immutable class, and equality is computed based on its canonical value.
public 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.
public XmlCalendar
getCalendar()
Retrieves the value of the current time as an XmlCalendar.
public Date
getDate()
Retrieves the value of the current time as a java.util.Date instance.
public final int
getDay()
Gets the day-of-month.
public int
getFlags()
Returns a combination of flags indicating the information contained by this GDate.
public final BigDecimal
getFraction()
Gets the fraction-of-second.
public final int
getHour()
Gets the hour-of-day.
public int
getJulianDate()
Returns the Julian date corresponding to this Gregorian date.
public int
getMillisecond()
Gets the rounded millisecond value.
public final int
getMinute()
Gets the minute-of-hour.
public final int
getMonth()
Gets the month-of-year.
public final int
getSecond()
Gets the second-of-minute.
public final int
getTimeZoneHour()
Gets the time zone hour.
public final int
getTimeZoneMinute()
Gets the time zone minutes.
public final int
getTimeZoneSign()
Gets the time zone sign.
public final int
getYear()
Gets the year.
public final boolean
hasDate()
True if this date/time specification specifies a full date (year, month, day)
public final boolean
hasDay()
True if this date/time specification specifies a day-of-month.
public int
hashCode()
Returns a hash code for this GDate.
public final boolean
hasMonth()
True if this date/time specification specifies a month-of-year.
public final boolean
hasTime()
True if this date/time specification specifies a time-of-day.
public final boolean
hasTimeZone()
True if this date/time specification specifies a timezone.
public final boolean
hasYear()
True if this date/time specification specifies a year.
public final boolean
isImmutable()
Returns true: all GDate instances are immutable.
public boolean
isValid()
True if this GDate corresponds to a valid gregorian date value in XML schema.
public GDate
subtract(GDurationSpecification duration)
Adds a duration to this GDate, and returns a new GDate.
public String
toString()
The natural string representation.
 
Methods from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
   
Methods from interface com.bea.xml.GDateSpecification
canonicalString, compareToGDate, getBuiltinTypeCode, getCalendar, getDate, getDay, getFlags, getFraction, getHour, getJulianDate, getMillisecond, getMinute, getMonth, getSecond, getTimeZoneHour, getTimeZoneMinute, getTimeZoneSign, getYear, hasDate, hasDay, hasMonth, hasTime, hasTimeZone, hasYear, isImmutable, isValid, toString
 

Constructor Detail

GDate

public GDate(GDateSpecification gdate)
Constructs a GDate based on another GDateSpecification.

GDate

public 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.

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.


GDate

public 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.

Note that by not specifying the timezone the GDate becomes partially unordered with respect to times that do have a specified timezone.


GDate

public GDate(CharSequence string)
Constructs a GDate based on a lexical representation.

GDate

public GDate(Calendar calendar)
Constructs a GDate based on a java.util.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 com.bea.xml.XmlCalendar is stable if you re-get a set field, so it does not have the same problem.


GDate

public GDate(Date date)
Constructs a GDate based on a java.util.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.

 

Method Detail

add(GDurationSpecification) Method

public GDate add(GDurationSpecification duration)
Adds a duration to this GDate, and returns a new GDate.


canonicalString() Method

public String canonicalString()
The canonical string representation. Specific moments or times-of-day in a specified timezone are normalized to UTC time to produce a canonical string form for them. Other recurring time specifications keep their timezone information.


compareToGDate(GDateSpecification) Method

public int compareToGDate(GDateSpecification datespec)
Comparison to another GDate. Two instances are incomparable if they have different amounts of information.

Parameters

datespec
the date to compare against.

equals(Object) Method

public boolean equals(Object obj)
GDate is an immutable class, and equality is computed based on its canonical value.

Overrides
Object.equals(Object)

getBuiltinTypeCode() Method

public 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.

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.


getCalendar() Method

public XmlCalendar getCalendar()
Retrieves the value of the current time as an 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().


getDate() Method

public Date getDate()
Retrieves the value of the current time as a java.util.Date instance.


getDay() Method

public final int getDay()
Gets the day-of-month. The first day of each month is 1.


getFlags() Method

public int getFlags()
Returns a combination of flags indicating the information contained by this GDate. The five flags are HAS_TIMEZONE, HAS_YEAR, HAS_MONTH, HAS_DAY, and HAS_TIME.


getFraction() Method

public final BigDecimal getFraction()
Gets the fraction-of-second. Range from 0 (inclusive) to 1 (exclusive).


getHour() Method

public final int getHour()
Gets the hour-of-day. Midnight is 0, and 11PM is 23.


getJulianDate() Method

public int getJulianDate()
Returns the Julian date corresponding to this Gregorian date. The Julian date (JD) is a continuous count of days from 1 January 4713 BC (= -4712 January 1).


getMillisecond() Method

public int getMillisecond()
Gets the rounded millisecond value. Range from 0 to 999


getMinute() Method

public final int getMinute()
Gets the minute-of-hour. Range from 0 to 59.


getMonth() Method

public final int getMonth()
Gets the month-of-year. January is 1.


getSecond() Method

public final int getSecond()
Gets the second-of-minute. Range from 0 to 59.


getTimeZoneHour() Method

public final int getTimeZoneHour()
Gets the time zone hour. This is always positive: for the sign, look at getTimeZoneSign().


getTimeZoneMinute() Method

public final int getTimeZoneMinute()
Gets the time zone minutes. This is always positive: for the sign, look at getTimeZoneSign().


getTimeZoneSign() Method

public final int getTimeZoneSign()
Gets the time zone sign. For time zones east of GMT, this is positive; for time zones west, this is negative.


getYear() Method

public final int getYear()
Gets the year. Should be a four-digit year specification.


hasDate() Method

public final boolean hasDate()
True if this date/time specification specifies a full date (year, month, day)


hasDay() Method

public final boolean hasDay()
True if this date/time specification specifies a day-of-month.


hashCode() Method

public int hashCode()
Returns a hash code for this GDate.

Overrides
Object.hashCode()

hasMonth() Method

public final boolean hasMonth()
True if this date/time specification specifies a month-of-year.


hasTime() Method

public final boolean hasTime()
True if this date/time specification specifies a time-of-day.


hasTimeZone() Method

public final boolean hasTimeZone()
True if this date/time specification specifies a timezone.


hasYear() Method

public final boolean hasYear()
True if this date/time specification specifies a year.


isImmutable() Method

public final boolean isImmutable()
Returns true: all GDate instances are immutable.


isValid() Method

public boolean isValid()
True if this GDate corresponds to a valid gregorian date value in XML schema.


subtract(GDurationSpecification) Method

public GDate subtract(GDurationSpecification duration)
Adds a duration to this GDate, and returns a new GDate.


toString() Method

public String toString()
The natural string representation. This represents the information that is available, including timezone. For types that correspond to defined schema types (schemaBuiltinTypeCode() > 0), this provides the natural lexical representation.

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.

Overrides
Object.toString()