.
XmlCalendar modifies several key details in the behavior of
GregorianCalendar to make it more useful when dealing with XML dates.
| Constructor: |
public XmlCalendar() {
setGregorianChange(_beginningOfTime); // proleptic
clear();
}
Constructs an empty instance with no fields set. |
public XmlCalendar(String xmlSchemaDateString) {
this(new GDate(xmlSchemaDateString)); // use GDate to parse
}
Constructs an XmlCalendar for a standard XML
schema formatted date string.
The parser accepts any of the following formats:
YYYY-MM-DDThh:mm:ss - dateTime
YYYY-MM-DD - date
hh:mm:ss - time
YYYY - gYear
--MM - gMonth
---DD - gDay
The parser actually accepts all 16 combinations of subsets of
fields (Y, M, D, T) using the same scheme, even for combinations
that are not defined as types in the schema spec, such as
year, day, and time:
YYYY--DDThh:mm:ss - [everything but month specified]
In the string, each field must be padded to its full width, for
example, January must be --01, not just --1.
In particular, a year must be padded to at least four digits, so
"98" is not a valid year, although "1998" and "0098" are both valid
years, unambiguously 19 centuries separated from each other. A year
may also be preceded by a minus symbol: -0001 is 1 BC and -0002 is
2 BC.
Finally a timezone is always allowed (yet optional) at the end.
Timezones must be either "Z" (UTC, which we translate to GMT),
or simple offsets from UTC in the range "-14:00" to "+14:00",
for example: "14:30:00-05:00" specifies 2:30 PM in the
afternoon at UTC-05:00, which is the same as EST.
If a timezone is not specified, the default TimeZone is used. |
public XmlCalendar(GDateSpecification date) {
this(GDate.timeZoneForGDate(date), date);
}
Constructs an XmlCalendar from a GDate.
If the instance is not completed, you can round-trip to an
equivalent GDate by writing "new GDate(new XmlCalendar(gdate))".
However, if you access any of the unset fields of the calendar, all
the fields will be automatically filled in, so partial dates
without timezones or other fields will not round-trip after access. |
public XmlCalendar(Date date) {
this(TimeZone.getDefault(), new GDate(date));
complete();
}
Constructs an XmlCalendar from a Date.
The default TimeZone is used for computing the various fields. |
public XmlCalendar(int year,
int month,
int day,
int hour,
int minute,
int second,
BigDecimal fraction) {
this(TimeZone.getDefault(), new GDate(year, month, day, hour, minute, second, fraction));
}
Constructs an XmlCalendar with the specified year, month, day,
hours, minutes, seconds, and optional fractional seconds, in
the default timezone. |
public XmlCalendar(int year,
int month,
int day,
int hour,
int minute,
int second,
BigDecimal fraction,
int tzSign,
int tzHour,
int tzMinute) {
this(new GDate(year, month, day, hour, minute, second, fraction, tzSign, tzHour, tzMinute));
}
Constructs an XmlCalendar with the specified year, month, day,
hours, minutes, seconds, and optional fractional seconds, in
the specified timezone. |
| Method from org.apache.xmlbeans.XmlCalendar Detail: |
protected void computeTime() {
boolean unsetYear = !isSet(YEAR);
if (unsetYear)
set(YEAR, getDefaultYear());
try
{
super.computeTime();
}
finally
{
if (unsetYear)
clear(YEAR);
}
}
Overrides GregorianCalendar.computeTime to apply a different
default year. (It must be a leap year.) |
public int get(int field) {
if (!isSet(field) || isTimeSet)
return super.get(field); // forces a complete
else
return internalGet(field); // does not force a complete.
}
Gets the value for a given time field.
Unlike the GregorianCalendar implementation, the get() does not
force a complete of all fields. If you wish to force a completion
of all the fields, call getTime() first. |
public static int getDefaultYear() {
if (defaultYear == Integer.MIN_VALUE)
{
try
{
String yearstring = SystemProperties.getProperty("user.defaultyear");
if (yearstring != null)
defaultYear = Integer.parseInt(yearstring);
else
defaultYear = DEFAULT_DEFAULT_YEAR;
}
catch (Throwable t)
{
defaultYear = DEFAULT_DEFAULT_YEAR;
}
}
return defaultYear;
}
Returns the default year that is used when no year is specified. |
public static void setDefaultYear(int year) {
defaultYear = year;
}
Sets the default year to be used when no year is specified. |
public String toString() {
return (new GDate(this)).toString(); // use GDate to print
}
Prints the XmlCalendar using a standard XML Schema
format, as described in XmlCalendar(String s). |