|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.xmlbeans.GDateBuilder
public final class GDateBuilder
Used to build GDates
.
Like GDate, a GDateBuilder represents an Gregorian Date, Time, and Timezone, or subset of information (Year, Month, Day, Time, Timezone, or some combination). Wherever it provides guidance, the XML Schema 1.0 specification (plus published errata) is followed.
Instances may separately set or clear the year, month, day-of-month, and time-of-day. Not all operations are meaningful on all combinations. In particular, timezone normalization is only possible if there is a time, or a time together with a full date.
Field Summary |
---|
Fields inherited from interface org.apache.xmlbeans.GDateSpecification |
---|
HAS_DAY, HAS_MONTH, HAS_TIME, HAS_TIMEZONE, HAS_YEAR |
Constructor Summary | |
---|---|
GDateBuilder()
Constructs a GDateBuilder specifying no date or time |
|
GDateBuilder(java.util.Calendar calendar)
|
|
GDateBuilder(java.lang.CharSequence string)
Constructs a GDateBuilder from a lexical representation. |
|
GDateBuilder(java.util.Date date)
Constructs a GDateBuilder based on a java.util.Date. |
|
GDateBuilder(GDateSpecification gdate)
Construts a GDateBuilder by copying another GDateSpecificaiton. |
|
GDateBuilder(int year,
int month,
int day,
int hour,
int minute,
int second,
java.math.BigDecimal fraction)
Constructs a GDateBuilder with the specified year, month, day, hours, minutes, seconds, and optional fractional seconds, in an unspecified timezone. |
|
GDateBuilder(int year,
int month,
int day,
int hour,
int minute,
int second,
java.math.BigDecimal fraction,
int tzSign,
int tzHour,
int tzMinute)
Constructs an absolute GDateBuilder with the specified year, month, day, hours, minutes, seconds, and optional fractional seconds, and in the timezone specified. |
Method Summary | |
---|---|
void |
addDuration(int sign,
int year,
int month,
int day,
int hour,
int minute,
int second,
java.math.BigDecimal fraction)
Adds a given duration to the date/time. |
void |
addGDuration(GDurationSpecification duration)
Adds a given duration to the date/time. |
java.lang.String |
canonicalString()
The canonical string representation. |
void |
clearDay()
Clears the day-of-month. |
void |
clearMonth()
Clears the month-of-year. |
void |
clearTime()
Clears the time-of-day. |
void |
clearTimeZone()
Clears the timezone. |
void |
clearYear()
Clears the year. |
java.lang.Object |
clone()
Builds another GDateBuilder with the same value as this one. |
int |
compareToGDate(GDateSpecification datespec)
Comparison to another GDate. |
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 . |
java.util.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. |
java.math.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. |
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()
True if the instance is immutable. |
boolean |
isValid()
True if all date fields lie within their legal ranges. |
void |
normalize()
Normalizes the instance, ensuring date and time fields are within their normal ranges. |
void |
normalizeToTimeZone(int tzTotalMinutes)
Normalizes to a time zone specified by a number of offset minutes rather than sign/hour/minute; for example, normalizeToTimeZone(-60) is the same as normalizeToTimeZone(-1, 1, 0). |
void |
normalizeToTimeZone(int tzSign,
int tzHour,
int tzMinute)
If the time and timezone are known, this method changes the timezone to the specified UTC offset, altering minutes, hours, day, month, and year as necessary to ensure that the actual described moment in time is the same. |
void |
setBuiltinTypeCode(int typeCode)
Clears the fields in this GDateBuilder that are not applicable for the given SchemaType date code. |
void |
setDate(java.util.Date date)
Sets the current time and date based on a java.util.Date instance. |
void |
setDay(int day)
Sets the day-of-month. |
void |
setGDate(GDateSpecification gdate)
Copies a GDateSpecification, completely replacing the current information in this GDateBuilder. |
void |
setJulianDate(int julianday)
Sets the Gregorian date based on the given Julian date. |
void |
setMonth(int month)
Sets the month-of-year. |
void |
setTime(int hour,
int minute,
int second,
java.math.BigDecimal fraction)
Sets the time. |
void |
setTimeZone(int tzTotalMinutes)
Sets the time zone based on a number of offset minutes rather than sign/hour/minute; for example, setTimeZone(-60) is the same as setTimeZone(-1, 1, 0). |
void |
setTimeZone(int tzSign,
int tzHour,
int tzMinute)
Sets the time zone without changing the other time fields. |
void |
setYear(int year)
Sets the year. |
void |
subtractGDuration(GDurationSpecification duration)
Subtracts a given duration from the date/time. |
GDate |
toGDate()
Builds a GDate from this GDateBuilder. |
java.lang.String |
toString()
The natural string representation. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public GDateBuilder()
public GDateBuilder(GDateSpecification gdate)
public GDateBuilder(java.lang.CharSequence string)
public GDateBuilder(java.util.Calendar calendar)
public GDateBuilder(int year, int month, int day, int hour, int minute, int second, java.math.BigDecimal fraction)
Note that by not specifying the timezone the GDateBuilder becomes partially unordered with respect to timesthat do have a specified timezone.
year
- The yearmonth
- The month, from 1-12day
- The day of month, from 1-31hour
- The hour of day, from 0-23minute
- The minute of hour, from 0-59second
- The second of minute, from 0-59fraction
- The fraction of second, 0.0 to 0.999... (may be null)public GDateBuilder(int year, int month, int day, int hour, int minute, int second, java.math.BigDecimal fraction, int tzSign, int tzHour, int tzMinute)
Note that you can reexpress the GDateBuilder in any timezone using normalizeToTimeZone(). The normalize() method normalizes to UTC.
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.
year
- the yearmonth
- the month, from 1-12day
- the day of month, from 1-31hour
- the hour of day, from 0-23minute
- the minute of hour, from 0-59second
- the second of minute, from 0-59fraction
- the fraction of second, 0.0 to 0.999... (may be null)tzSign
- the timezone offset sign, either +1, 0, or -1tzHour
- the timezone offset hourtzMinute
- the timezone offset minutepublic GDateBuilder(java.util.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.
date
- the date object to copyMethod Detail |
---|
public java.lang.Object clone()
clone
in class java.lang.Object
public GDate toGDate()
public boolean isImmutable()
isImmutable
in interface GDateSpecification
public int getFlags()
getFlags
in interface GDateSpecification
public final boolean hasTimeZone()
hasTimeZone
in interface GDateSpecification
public final boolean hasYear()
hasYear
in interface GDateSpecification
public final boolean hasMonth()
hasMonth
in interface GDateSpecification
public final boolean hasDay()
hasDay
in interface GDateSpecification
public final boolean hasTime()
hasTime
in interface GDateSpecification
public final boolean hasDate()
hasDate
in interface GDateSpecification
public final int getYear()
getYear
in interface GDateSpecification
public final int getMonth()
getMonth
in interface GDateSpecification
public final int getDay()
getDay
in interface GDateSpecification
public final int getHour()
getHour
in interface GDateSpecification
public final int getMinute()
getMinute
in interface GDateSpecification
public final int getSecond()
getSecond
in interface GDateSpecification
public final java.math.BigDecimal getFraction()
getFraction
in interface GDateSpecification
public final int getMillisecond()
getMillisecond
in interface GDateSpecification
public final int getTimeZoneSign()
getTimeZoneSign
in interface GDateSpecification
public final int getTimeZoneHour()
getTimeZoneHour
in interface GDateSpecification
public final int getTimeZoneMinute()
getTimeZoneMinute
in interface GDateSpecification
public void setYear(int year)
year
- the yearpublic void setMonth(int month)
month
- the month, from 1-12public void setDay(int day)
day
- the day of month, from 1-31public void setTime(int hour, int minute, int second, java.math.BigDecimal fraction)
hour
- the hour of day, from 0-23 or 24 only if min, sec and fraction are 0minute
- the minute of hour, from 0-59second
- the second of minute, from 0-59fraction
- the fraction of second, 0.0 to 0.999... (may be null)public void setTimeZone(int tzSign, int tzHour, int tzMinute)
Timezones must be between -14:00 and +14:00. Sign must be -1 or 1 (or 0 for UTC only), and the offset hours and minute arguments must be nonnegative.
tzSign
- the timezone offset sign, either +1, 0, or -1tzHour
- the timezone offset hourtzMinute
- the timezone offset minutepublic void setTimeZone(int tzTotalMinutes)
public void clearYear()
public void clearMonth()
public void clearDay()
public void clearTime()
public void clearTimeZone()
public boolean isValid()
isValid
in interface GDateSpecification
public void normalize()
If no timezone or no time is specified, or if a partial date is specified, this method does nothing, and leaves the timezone information as-is.
If a time or time and date is specified, this method normalizes the timezone to UTC.
public void normalizeToTimeZone(int tzSign, int tzHour, int tzMinute)
It is an error to operate on instances without a time or timezone, or with a partially specified date.
tzSign
- the timezone offset sign, either +1, 0, or -1tzHour
- the timezone offset hourtzMinute
- the timezone offset minutepublic void normalizeToTimeZone(int tzTotalMinutes)
public void addGDuration(GDurationSpecification duration)
duration
- the duration to addpublic void subtractGDuration(GDurationSpecification duration)
duration
- the duration to subtractpublic void addDuration(int sign, int year, int month, int day, int hour, int minute, int second, java.math.BigDecimal fraction)
sign
- +1 to add, -1 to subtractyear
- the number of years to addmonth
- the number of months to addday
- the number of days to addhour
- the number of hours to addminute
- the number of minutes to addsecond
- the number of seconds to addfraction
- the number of fractional seconds to add (may be null)public final int getJulianDate()
getJulianDate
in interface GDateSpecification
public void setJulianDate(int julianday)
julianday
- the julian day numberpublic void setDate(java.util.Date date)
The timezone offset used is based on the default TimeZone. (The default TimeZone is consulted to incorporate daylight savings offsets if applicable for the current date as well as the base timezone offset.)
If you wish to normalize the timezone, e.g., to UTC, follow this with a call to normalizeToTimeZone.
date
- the Date object to copypublic void setGDate(GDateSpecification gdate)
gdate
- the GDateSpecification to copypublic 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 GDateSpecification
public java.util.Date getDate()
getDate
in interface GDateSpecification
public final int compareToGDate(GDateSpecification datespec)
compareToGDate
in interface GDateSpecification
datespec
- the date to compare againstpublic final 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 GDateSpecification
public void setBuiltinTypeCode(int typeCode)
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
.
typeCode
- the type code to applypublic java.lang.String canonicalString()
canonicalString
in interface GDateSpecification
public final java.lang.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 GDateSpecification
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |