12005
|
1 |
/*
|
|
2 |
* Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package javax.xml.datatype;
|
|
27 |
|
|
28 |
import javax.xml.namespace.QName;
|
|
29 |
import java.math.BigDecimal;
|
|
30 |
import java.math.BigInteger;
|
|
31 |
import java.util.TimeZone;
|
|
32 |
import java.util.GregorianCalendar;
|
|
33 |
|
|
34 |
/**
|
|
35 |
* <p>Representation for W3C XML Schema 1.0 date/time datatypes.
|
|
36 |
* Specifically, these date/time datatypes are
|
|
37 |
* {@link DatatypeConstants#DATETIME},
|
|
38 |
* {@link DatatypeConstants#TIME},
|
|
39 |
* {@link DatatypeConstants#DATE},
|
|
40 |
* {@link DatatypeConstants#GYEARMONTH},
|
|
41 |
* {@link DatatypeConstants#GMONTHDAY},
|
|
42 |
* {@link DatatypeConstants#GYEAR},
|
|
43 |
* {@link DatatypeConstants#GMONTH}, and
|
|
44 |
* {@link DatatypeConstants#GDAY}
|
|
45 |
* defined in the XML Namespace
|
29999
|
46 |
* {@code "http://www.w3.org/2001/XMLSchema"}.
|
12005
|
47 |
* These datatypes are normatively defined in
|
29999
|
48 |
* <a href="http://www.w3.org/TR/xmlschema-2/#dateTime">W3C XML Schema 1.0 Part 2, Section 3.2.7-14</a>.
|
12005
|
49 |
*
|
|
50 |
* <p>The table below defines the mapping between XML Schema 1.0
|
|
51 |
* date/time datatype fields and this class' fields. It also summarizes
|
|
52 |
* the value constraints for the date and time fields defined in
|
|
53 |
* <a href="http://www.w3.org/TR/xmlschema-2/#isoformats">W3C XML Schema 1.0 Part 2, Appendix D,
|
29999
|
54 |
* <i>ISO 8601 Date and Time Formats</i></a>.
|
12005
|
55 |
*
|
29999
|
56 |
* <a name="datetimefieldmapping"></a>
|
12005
|
57 |
* <table border="2" rules="all" cellpadding="2">
|
|
58 |
* <thead>
|
|
59 |
* <tr>
|
|
60 |
* <th align="center" colspan="3">
|
|
61 |
* Date/Time Datatype Field Mapping Between XML Schema 1.0 and Java Representation
|
|
62 |
* </th>
|
|
63 |
* </tr>
|
|
64 |
* </thead>
|
|
65 |
* <tbody>
|
|
66 |
* <tr>
|
29999
|
67 |
* <th>XML Schema 1.0<br>
|
|
68 |
* datatype<br>
|
12005
|
69 |
* field</th>
|
29999
|
70 |
* <th>Related<br>XMLGregorianCalendar<br>Accessor(s)</th>
|
12005
|
71 |
* <th>Value Range</th>
|
|
72 |
* </tr>
|
|
73 |
* <tr>
|
29999
|
74 |
* <td><a name="datetimefield-year">year</a></td>
|
|
75 |
* <td> {@link #getYear()} + {@link #getEon()} or<br>
|
12005
|
76 |
* {@link #getEonAndYear}
|
|
77 |
* </td>
|
29999
|
78 |
* <td> {@code getYear()} is a value between -(10^9-1) to (10^9)-1
|
|
79 |
* or {@link DatatypeConstants#FIELD_UNDEFINED}.<br>
|
|
80 |
* {@link #getEon()} is high order year value in billion of years.<br>
|
|
81 |
* {@code getEon()} has values greater than or equal to (10^9) or less than or equal to -(10^9).
|
|
82 |
* A value of null indicates field is undefined.<br>
|
12005
|
83 |
* Given that <a href="http://www.w3.org/2001/05/xmlschema-errata#e2-63">XML Schema 1.0 errata</a> states that the year zero
|
|
84 |
* will be a valid lexical value in a future version of XML Schema,
|
|
85 |
* this class allows the year field to be set to zero. Otherwise,
|
|
86 |
* the year field value is handled exactly as described
|
|
87 |
* in the errata and [ISO-8601-1988]. Note that W3C XML Schema 1.0
|
|
88 |
* validation does not allow for the year field to have a value of zero.
|
|
89 |
* </td>
|
|
90 |
* </tr>
|
|
91 |
* <tr>
|
29999
|
92 |
* <td><a name="datetimefield-month">month</a></td>
|
12005
|
93 |
* <td> {@link #getMonth()} </td>
|
|
94 |
* <td> 1 to 12 or {@link DatatypeConstants#FIELD_UNDEFINED} </td>
|
|
95 |
* </tr>
|
|
96 |
* <tr>
|
29999
|
97 |
* <td><a name="datetimefield-day">day</a></td>
|
12005
|
98 |
* <td> {@link #getDay()} </td>
|
29999
|
99 |
* <td> Independent of month, max range is 1 to 31 or {@link DatatypeConstants#FIELD_UNDEFINED}.<br>
|
12005
|
100 |
* The normative value constraint stated relative to month
|
|
101 |
* field's value is in <a href="http://www.w3.org/TR/xmlschema-2/#isoformats">W3C XML Schema 1.0 Part 2, Appendix D</a>.
|
|
102 |
* </td>
|
|
103 |
* </tr>
|
|
104 |
* <tr>
|
29999
|
105 |
* <td><a name="datetimefield-hour">hour</a></td>
|
12005
|
106 |
* <td>{@link #getHour()}</td>
|
|
107 |
* <td>
|
|
108 |
* 0 to 23 or {@link DatatypeConstants#FIELD_UNDEFINED}.
|
|
109 |
* An hour value of 24 is allowed to be set in the lexical space provided the minute and second
|
|
110 |
* field values are zero. However, an hour value of 24 is not allowed in value space and will be
|
|
111 |
* transformed to represent the value of the first instance of the following day as per
|
|
112 |
* <a href="http://www.w3.org/TR/xmlschema-2/#built-in-primitive-datatypes">
|
|
113 |
* XML Schema Part 2: Datatypes Second Edition, 3.2 Primitive datatypes</a>.
|
|
114 |
* </td>
|
|
115 |
* </tr>
|
|
116 |
* <tr>
|
29999
|
117 |
* <td><a name="datetimefield-minute">minute</a></td>
|
12005
|
118 |
* <td> {@link #getMinute()} </td>
|
|
119 |
* <td> 0 to 59 or {@link DatatypeConstants#FIELD_UNDEFINED} </td>
|
|
120 |
* </tr>
|
|
121 |
* <tr>
|
29999
|
122 |
* <td><a name="datetimefield-second">second</a></td>
|
12005
|
123 |
* <td>
|
29999
|
124 |
* {@link #getSecond()} + {@link #getMillisecond()}/1000 or<br>
|
12005
|
125 |
* {@link #getSecond()} + {@link #getFractionalSecond()}
|
|
126 |
* </td>
|
|
127 |
* <td>
|
29999
|
128 |
* {@link #getSecond()} from 0 to 60 or {@link DatatypeConstants#FIELD_UNDEFINED}.<br>
|
|
129 |
* <i>(Note: 60 only allowable for leap second.)</i><br>
|
12005
|
130 |
* {@link #getFractionalSecond()} allows for infinite precision over the range from 0.0 to 1.0 when
|
29999
|
131 |
* the {@link #getSecond()} is defined.<br>
|
|
132 |
* {@code FractionalSecond} is optional and has a value of {@code null} when it is undefined.<br>
|
12005
|
133 |
* {@link #getMillisecond()} is the convenience
|
|
134 |
* millisecond precision of value of {@link #getFractionalSecond()}.
|
|
135 |
* </td>
|
|
136 |
* </tr>
|
|
137 |
* <tr>
|
29999
|
138 |
* <td><a name="datetimefield-timezone">timezone</a></td>
|
12005
|
139 |
* <td> {@link #getTimezone()} </td>
|
|
140 |
* <td> Number of minutes or {@link DatatypeConstants#FIELD_UNDEFINED}.
|
|
141 |
* Value range from -14 hours (-14 * 60 minutes) to 14 hours (14 * 60 minutes).
|
|
142 |
* </td>
|
|
143 |
* </tr>
|
|
144 |
* </tbody>
|
|
145 |
* </table>
|
|
146 |
*
|
|
147 |
* <p>All maximum value space constraints listed for the fields in the table
|
29999
|
148 |
* above are checked by factory methods, {@link DatatypeFactory},
|
12005
|
149 |
* setter methods and parse methods of
|
29999
|
150 |
* this class. {@code IllegalArgumentException} is thrown when a
|
12005
|
151 |
* parameter's value is outside the value constraint for the field or
|
|
152 |
* if the composite
|
|
153 |
* values constitute an invalid XMLGregorianCalendar instance (for example, if
|
|
154 |
* the 31st of June is specified).
|
|
155 |
*
|
|
156 |
* <p>The following operations are defined for this class:
|
|
157 |
* <ul>
|
|
158 |
* <li>accessors/mutators for independent date/time fields</li>
|
|
159 |
* <li>conversion between this class and W3C XML Schema 1.0 lexical representation,
|
|
160 |
* {@link #toString()}, {@link DatatypeFactory#newXMLGregorianCalendar(String lexicalRepresentation)}</li>
|
|
161 |
* <li>conversion between this class and {@link GregorianCalendar},
|
|
162 |
* {@link #toGregorianCalendar(java.util.TimeZone timezone, java.util.Locale aLocale, XMLGregorianCalendar defaults)},
|
|
163 |
* {@link DatatypeFactory}</li>
|
|
164 |
* <li>partial order relation comparator method, {@link #compare(XMLGregorianCalendar xmlGregorianCalendar)}</li>
|
|
165 |
* <li>{@link #equals(Object)} defined relative to {@link #compare(XMLGregorianCalendar xmlGregorianCalendar)}.</li>
|
|
166 |
* <li>addition operation with {@link Duration}
|
|
167 |
* instance as defined in <a href="http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes">
|
|
168 |
* W3C XML Schema 1.0 Part 2, Appendix E, <i>Adding durations to dateTimes</i></a>.
|
|
169 |
* </li>
|
|
170 |
* </ul>
|
|
171 |
*
|
|
172 |
* @author <a href="mailto:Joseph.Fialli@Sun.com">Joseph Fialli</a>
|
|
173 |
* @author <a href="mailto:Kohsuke.Kawaguchi@Sun.com">Kohsuke Kawaguchi</a>
|
|
174 |
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
|
|
175 |
* @author <a href="mailto:Sunitha.Reddy@Sun.com">Sunitha Reddy</a>
|
|
176 |
* @see Duration
|
|
177 |
* @see DatatypeFactory
|
|
178 |
* @since 1.5
|
|
179 |
*/
|
|
180 |
|
|
181 |
public abstract class XMLGregorianCalendar
|
|
182 |
implements Cloneable {
|
|
183 |
|
|
184 |
/**
|
|
185 |
* Default no-arg constructor.
|
|
186 |
*
|
|
187 |
* <p>Note: Always use the {@link DatatypeFactory} to
|
29999
|
188 |
* construct an instance of {@code XMLGregorianCalendar}.
|
12005
|
189 |
* The constructor on this class cannot be guaranteed to
|
|
190 |
* produce an object with a consistent state and may be
|
29999
|
191 |
* removed in the future.
|
12005
|
192 |
*/
|
|
193 |
public XMLGregorianCalendar() {
|
|
194 |
}
|
|
195 |
|
|
196 |
/**
|
29999
|
197 |
* Unset all fields to undefined.
|
12005
|
198 |
*
|
|
199 |
* <p>Set all int fields to {@link DatatypeConstants#FIELD_UNDEFINED} and reference fields
|
29999
|
200 |
* to null.
|
12005
|
201 |
*/
|
|
202 |
public abstract void clear();
|
|
203 |
|
|
204 |
/**
|
29999
|
205 |
* Reset this {@code XMLGregorianCalendar} to its original values.
|
12005
|
206 |
*
|
29999
|
207 |
* <p>{@code XMLGregorianCalendar} is reset to the same values as when it was created with
|
12005
|
208 |
* {@link DatatypeFactory#newXMLGregorianCalendar()},
|
|
209 |
* {@link DatatypeFactory#newXMLGregorianCalendar(String lexicalRepresentation)},
|
|
210 |
* {@link DatatypeFactory#newXMLGregorianCalendar(
|
|
211 |
* BigInteger year,
|
|
212 |
* int month,
|
|
213 |
* int day,
|
|
214 |
* int hour,
|
|
215 |
* int minute,
|
|
216 |
* int second,
|
|
217 |
* BigDecimal fractionalSecond,
|
|
218 |
* int timezone)},
|
|
219 |
* {@link DatatypeFactory#newXMLGregorianCalendar(
|
|
220 |
* int year,
|
|
221 |
* int month,
|
|
222 |
* int day,
|
|
223 |
* int hour,
|
|
224 |
* int minute,
|
|
225 |
* int second,
|
|
226 |
* int millisecond,
|
|
227 |
* int timezone)},
|
|
228 |
* {@link DatatypeFactory#newXMLGregorianCalendar(GregorianCalendar cal)},
|
|
229 |
* {@link DatatypeFactory#newXMLGregorianCalendarDate(
|
|
230 |
* int year,
|
|
231 |
* int month,
|
|
232 |
* int day,
|
|
233 |
* int timezone)},
|
|
234 |
* {@link DatatypeFactory#newXMLGregorianCalendarTime(
|
|
235 |
* int hours,
|
|
236 |
* int minutes,
|
|
237 |
* int seconds,
|
|
238 |
* int timezone)},
|
|
239 |
* {@link DatatypeFactory#newXMLGregorianCalendarTime(
|
|
240 |
* int hours,
|
|
241 |
* int minutes,
|
|
242 |
* int seconds,
|
|
243 |
* BigDecimal fractionalSecond,
|
|
244 |
* int timezone)} or
|
|
245 |
* {@link DatatypeFactory#newXMLGregorianCalendarTime(
|
|
246 |
* int hours,
|
|
247 |
* int minutes,
|
|
248 |
* int seconds,
|
|
249 |
* int milliseconds,
|
|
250 |
* int timezone)}.
|
|
251 |
*
|
29999
|
252 |
* <p>{@code reset()} is designed to allow the reuse of existing {@code XMLGregorianCalendar}s
|
|
253 |
* thus saving resources associated with the creation of new {@code XMLGregorianCalendar}s.
|
12005
|
254 |
*/
|
|
255 |
public abstract void reset();
|
|
256 |
|
|
257 |
/**
|
29999
|
258 |
* Set low and high order component of XSD {@code dateTime} year field.
|
12005
|
259 |
*
|
29999
|
260 |
* <p>Unset this field by invoking the setter with a parameter value of {@code null}.
|
12005
|
261 |
*
|
|
262 |
* @param year value constraints summarized in <a href="#datetimefield-year">year field of date/time field mapping table</a>.
|
|
263 |
*
|
29999
|
264 |
* @throws IllegalArgumentException if {@code year} parameter is
|
12005
|
265 |
* outside value constraints for the field as specified in
|
|
266 |
* <a href="#datetimefieldmapping">date/time field mapping table</a>.
|
|
267 |
*/
|
|
268 |
public abstract void setYear(BigInteger year);
|
|
269 |
|
|
270 |
/**
|
29999
|
271 |
* Set year of XSD {@code dateTime} year field.
|
12005
|
272 |
*
|
|
273 |
* <p>Unset this field by invoking the setter with a parameter value of
|
29999
|
274 |
* {@link DatatypeConstants#FIELD_UNDEFINED}.
|
12005
|
275 |
*
|
29999
|
276 |
* <p>Note: if the absolute value of the {@code year} parameter
|
12005
|
277 |
* is less than 10^9, the eon component of the XSD year field is set to
|
29999
|
278 |
* {@code null} by this method.
|
12005
|
279 |
*
|
|
280 |
* @param year value constraints are summarized in <a href="#datetimefield-year">year field of date/time field mapping table</a>.
|
29999
|
281 |
* If year is {@link DatatypeConstants#FIELD_UNDEFINED}, then eon is set to {@code null}.
|
12005
|
282 |
*/
|
|
283 |
public abstract void setYear(int year);
|
|
284 |
|
|
285 |
/**
|
29999
|
286 |
* Set month.
|
12005
|
287 |
*
|
29999
|
288 |
* <p>Unset this field by invoking the setter with a parameter value of {@link DatatypeConstants#FIELD_UNDEFINED}.
|
12005
|
289 |
*
|
|
290 |
* @param month value constraints summarized in <a href="#datetimefield-month">month field of date/time field mapping table</a>.
|
|
291 |
*
|
29999
|
292 |
* @throws IllegalArgumentException if {@code month} parameter is
|
12005
|
293 |
* outside value constraints for the field as specified in
|
|
294 |
* <a href="#datetimefieldmapping">date/time field mapping table</a>.
|
|
295 |
*/
|
|
296 |
public abstract void setMonth(int month);
|
|
297 |
|
|
298 |
/**
|
29999
|
299 |
* Set days in month.
|
12005
|
300 |
*
|
29999
|
301 |
* <p>Unset this field by invoking the setter with a parameter value of {@link DatatypeConstants#FIELD_UNDEFINED}.
|
12005
|
302 |
*
|
|
303 |
* @param day value constraints summarized in <a href="#datetimefield-day">day field of date/time field mapping table</a>.
|
|
304 |
*
|
29999
|
305 |
* @throws IllegalArgumentException if {@code day} parameter is
|
12005
|
306 |
* outside value constraints for the field as specified in
|
|
307 |
* <a href="#datetimefieldmapping">date/time field mapping table</a>.
|
|
308 |
*/
|
|
309 |
public abstract void setDay(int day);
|
|
310 |
|
|
311 |
/**
|
29999
|
312 |
* Set the number of minutes in the timezone offset.
|
12005
|
313 |
*
|
29999
|
314 |
* <p>Unset this field by invoking the setter with a parameter value of {@link DatatypeConstants#FIELD_UNDEFINED}.
|
12005
|
315 |
*
|
|
316 |
* @param offset value constraints summarized in <a href="#datetimefield-timezone">
|
|
317 |
* timezone field of date/time field mapping table</a>.
|
|
318 |
*
|
29999
|
319 |
* @throws IllegalArgumentException if {@code offset} parameter is
|
12005
|
320 |
* outside value constraints for the field as specified in
|
|
321 |
* <a href="#datetimefieldmapping">date/time field mapping table</a>.
|
|
322 |
*/
|
|
323 |
public abstract void setTimezone(int offset);
|
|
324 |
|
|
325 |
/**
|
29999
|
326 |
* Set time as one unit.
|
12005
|
327 |
*
|
|
328 |
* @param hour value constraints are summarized in
|
|
329 |
* <a href="#datetimefield-hour">hour field of date/time field mapping table</a>.
|
|
330 |
* @param minute value constraints are summarized in
|
|
331 |
* <a href="#datetimefield-minute">minute field of date/time field mapping table</a>.
|
|
332 |
* @param second value constraints are summarized in
|
|
333 |
* <a href="#datetimefield-second">second field of date/time field mapping table</a>.
|
|
334 |
*
|
|
335 |
* @see #setTime(int, int, int, BigDecimal)
|
|
336 |
*
|
|
337 |
* @throws IllegalArgumentException if any parameter is
|
|
338 |
* outside value constraints for the field as specified in
|
|
339 |
* <a href="#datetimefieldmapping">date/time field mapping table</a>.
|
|
340 |
*/
|
|
341 |
public void setTime(int hour, int minute, int second) {
|
|
342 |
|
|
343 |
setTime(
|
|
344 |
hour,
|
|
345 |
minute,
|
|
346 |
second,
|
|
347 |
null // fractional
|
|
348 |
);
|
|
349 |
}
|
|
350 |
|
|
351 |
/**
|
29999
|
352 |
* Set hours.
|
12005
|
353 |
*
|
29999
|
354 |
* <p>Unset this field by invoking the setter with a parameter value of {@link DatatypeConstants#FIELD_UNDEFINED}.
|
12005
|
355 |
*
|
|
356 |
* @param hour value constraints summarized in <a href="#datetimefield-hour">hour field of date/time field mapping table</a>.
|
|
357 |
*
|
29999
|
358 |
* @throws IllegalArgumentException if {@code hour} parameter is outside value constraints for the field as specified in
|
12005
|
359 |
* <a href="#datetimefieldmapping">date/time field mapping table</a>.
|
|
360 |
*/
|
|
361 |
public abstract void setHour(int hour);
|
|
362 |
|
|
363 |
/**
|
29999
|
364 |
* Set minutes.
|
12005
|
365 |
*
|
29999
|
366 |
* <p>Unset this field by invoking the setter with a parameter value of {@link DatatypeConstants#FIELD_UNDEFINED}.
|
12005
|
367 |
*
|
|
368 |
* @param minute value constraints summarized in <a href="#datetimefield-minute">minute field of date/time field mapping table</a>.
|
|
369 |
*
|
29999
|
370 |
* @throws IllegalArgumentException if {@code minute} parameter is outside value constraints for the field as specified in
|
12005
|
371 |
* <a href="#datetimefieldmapping">date/time field mapping table</a>.
|
|
372 |
*/
|
|
373 |
public abstract void setMinute(int minute);
|
|
374 |
|
|
375 |
/**
|
29999
|
376 |
* Set seconds.
|
12005
|
377 |
*
|
29999
|
378 |
* <p>Unset this field by invoking the setter with a parameter value of {@link DatatypeConstants#FIELD_UNDEFINED}.
|
12005
|
379 |
*
|
|
380 |
* @param second value constraints summarized in <a href="#datetimefield-second">second field of date/time field mapping table</a>.
|
|
381 |
*
|
29999
|
382 |
* @throws IllegalArgumentException if {@code second} parameter is outside value constraints for the field as specified in
|
12005
|
383 |
* <a href="#datetimefieldmapping">date/time field mapping table</a>.
|
|
384 |
*/
|
|
385 |
public abstract void setSecond(int second);
|
|
386 |
|
|
387 |
/**
|
29999
|
388 |
* Set milliseconds.
|
12005
|
389 |
*
|
29999
|
390 |
* <p>Unset this field by invoking the setter with a parameter value of {@link DatatypeConstants#FIELD_UNDEFINED}.
|
12005
|
391 |
*
|
|
392 |
* @param millisecond value constraints summarized in
|
|
393 |
* <a href="#datetimefield-second">second field of date/time field mapping table</a>.
|
|
394 |
*
|
29999
|
395 |
* @throws IllegalArgumentException if {@code millisecond} parameter is outside value constraints for the field as specified
|
12005
|
396 |
* in <a href="#datetimefieldmapping">date/time field mapping table</a>.
|
|
397 |
*/
|
|
398 |
public abstract void setMillisecond(int millisecond);
|
|
399 |
|
|
400 |
/**
|
29999
|
401 |
* Set fractional seconds.
|
12005
|
402 |
*
|
29999
|
403 |
* <p>Unset this field by invoking the setter with a parameter value of {@code null}.
|
12005
|
404 |
*
|
|
405 |
* @param fractional value constraints summarized in
|
|
406 |
* <a href="#datetimefield-second">second field of date/time field mapping table</a>.
|
|
407 |
*
|
29999
|
408 |
* @throws IllegalArgumentException if {@code fractional} parameter is outside value constraints for the field as specified
|
12005
|
409 |
* in <a href="#datetimefieldmapping">date/time field mapping table</a>.
|
|
410 |
*/
|
|
411 |
public abstract void setFractionalSecond(BigDecimal fractional);
|
|
412 |
|
|
413 |
|
|
414 |
/**
|
29999
|
415 |
* Set time as one unit, including the optional infinite precision
|
|
416 |
* fractional seconds.
|
12005
|
417 |
*
|
|
418 |
* @param hour value constraints are summarized in
|
|
419 |
* <a href="#datetimefield-hour">hour field of date/time field mapping table</a>.
|
|
420 |
* @param minute value constraints are summarized in
|
|
421 |
* <a href="#datetimefield-minute">minute field of date/time field mapping table</a>.
|
|
422 |
* @param second value constraints are summarized in
|
|
423 |
* <a href="#datetimefield-second">second field of date/time field mapping table</a>.
|
29999
|
424 |
* @param fractional value of {@code null} indicates this optional
|
12005
|
425 |
* field is not set.
|
|
426 |
*
|
|
427 |
* @throws IllegalArgumentException if any parameter is
|
|
428 |
* outside value constraints for the field as specified in
|
|
429 |
* <a href="#datetimefieldmapping">date/time field mapping table</a>.
|
|
430 |
*/
|
|
431 |
public void setTime(
|
|
432 |
int hour,
|
|
433 |
int minute,
|
|
434 |
int second,
|
|
435 |
BigDecimal fractional) {
|
|
436 |
|
|
437 |
setHour(hour);
|
|
438 |
setMinute(minute);
|
|
439 |
setSecond(second);
|
|
440 |
setFractionalSecond(fractional);
|
|
441 |
}
|
|
442 |
|
|
443 |
|
|
444 |
/**
|
29999
|
445 |
* Set time as one unit, including optional milliseconds.
|
12005
|
446 |
*
|
|
447 |
* @param hour value constraints are summarized in
|
|
448 |
* <a href="#datetimefield-hour">hour field of date/time field mapping table</a>.
|
|
449 |
* @param minute value constraints are summarized in
|
|
450 |
* <a href="#datetimefield-minute">minute field of date/time field mapping table</a>.
|
|
451 |
* @param second value constraints are summarized in
|
|
452 |
* <a href="#datetimefield-second">second field of date/time field mapping table</a>.
|
|
453 |
* @param millisecond value of {@link DatatypeConstants#FIELD_UNDEFINED} indicates this
|
|
454 |
* optional field is not set.
|
|
455 |
*
|
|
456 |
* @throws IllegalArgumentException if any parameter is
|
|
457 |
* outside value constraints for the field as specified in
|
|
458 |
* <a href="#datetimefieldmapping">date/time field mapping table</a>.
|
|
459 |
*/
|
|
460 |
public void setTime(int hour, int minute, int second, int millisecond) {
|
|
461 |
|
|
462 |
setHour(hour);
|
|
463 |
setMinute(minute);
|
|
464 |
setSecond(second);
|
|
465 |
setMillisecond(millisecond);
|
|
466 |
}
|
|
467 |
|
|
468 |
/**
|
29999
|
469 |
* Return high order component for XML Schema 1.0 dateTime datatype field for
|
|
470 |
* {@code year}.
|
|
471 |
* {@code null} if this optional part of the year field is not defined.
|
12005
|
472 |
*
|
|
473 |
* <p>Value constraints for this value are summarized in
|
29999
|
474 |
* <a href="#datetimefield-year">year field of date/time field mapping table</a>.
|
|
475 |
* @return eon of this {@code XMLGregorianCalendar}. The value
|
12005
|
476 |
* returned is an integer multiple of 10^9.
|
|
477 |
*
|
|
478 |
* @see #getYear()
|
|
479 |
* @see #getEonAndYear()
|
|
480 |
*/
|
|
481 |
public abstract BigInteger getEon();
|
|
482 |
|
|
483 |
/**
|
29999
|
484 |
* Return low order component for XML Schema 1.0 dateTime datatype field for
|
|
485 |
* {@code year} or {@link DatatypeConstants#FIELD_UNDEFINED}.
|
12005
|
486 |
*
|
|
487 |
* <p>Value constraints for this value are summarized in
|
29999
|
488 |
* <a href="#datetimefield-year">year field of date/time field mapping table</a>.
|
12005
|
489 |
*
|
29999
|
490 |
* @return year of this {@code XMLGregorianCalendar}.
|
12005
|
491 |
*
|
|
492 |
* @see #getEon()
|
|
493 |
* @see #getEonAndYear()
|
|
494 |
*/
|
|
495 |
public abstract int getYear();
|
|
496 |
|
|
497 |
/**
|
29999
|
498 |
* Return XML Schema 1.0 dateTime datatype field for
|
|
499 |
* {@code year}.
|
12005
|
500 |
*
|
|
501 |
* <p>Value constraints for this value are summarized in
|
29999
|
502 |
* <a href="#datetimefield-year">year field of date/time field mapping table</a>.
|
12005
|
503 |
*
|
29999
|
504 |
* @return sum of {@code eon} and {@code BigInteger.valueOf(year)}
|
|
505 |
* when both fields are defined. When only {@code year} is defined,
|
|
506 |
* return it. When both {@code eon} and {@code year} are not
|
|
507 |
* defined, return {@code null}.
|
12005
|
508 |
*
|
|
509 |
* @see #getEon()
|
|
510 |
* @see #getYear()
|
|
511 |
*/
|
|
512 |
public abstract BigInteger getEonAndYear();
|
|
513 |
|
|
514 |
/**
|
29999
|
515 |
* Return number of month or {@link DatatypeConstants#FIELD_UNDEFINED}.
|
12005
|
516 |
*
|
|
517 |
* <p>Value constraints for this value are summarized in
|
29999
|
518 |
* <a href="#datetimefield-month">month field of date/time field mapping table</a>.
|
12005
|
519 |
*
|
29999
|
520 |
* @return year of this {@code XMLGregorianCalendar}.
|
12005
|
521 |
*
|
|
522 |
*/
|
|
523 |
public abstract int getMonth();
|
|
524 |
|
|
525 |
/**
|
29999
|
526 |
* Return day in month or {@link DatatypeConstants#FIELD_UNDEFINED}.
|
12005
|
527 |
*
|
|
528 |
* <p>Value constraints for this value are summarized in
|
29999
|
529 |
* <a href="#datetimefield-day">day field of date/time field mapping table</a>.
|
12005
|
530 |
*
|
|
531 |
* @see #setDay(int)
|
|
532 |
*/
|
|
533 |
public abstract int getDay();
|
|
534 |
|
|
535 |
/**
|
|
536 |
* Return timezone offset in minutes or
|
|
537 |
* {@link DatatypeConstants#FIELD_UNDEFINED} if this optional field is not defined.
|
|
538 |
*
|
|
539 |
* <p>Value constraints for this value are summarized in
|
29999
|
540 |
* <a href="#datetimefield-timezone">timezone field of date/time field mapping table</a>.
|
12005
|
541 |
*
|
|
542 |
* @see #setTimezone(int)
|
|
543 |
*/
|
|
544 |
public abstract int getTimezone();
|
|
545 |
|
|
546 |
/**
|
|
547 |
* Return hours or {@link DatatypeConstants#FIELD_UNDEFINED}.
|
|
548 |
* Returns {@link DatatypeConstants#FIELD_UNDEFINED} if this field is not defined.
|
|
549 |
*
|
|
550 |
* <p>Value constraints for this value are summarized in
|
29999
|
551 |
* <a href="#datetimefield-hour">hour field of date/time field mapping table</a>.
|
12005
|
552 |
* @see #setTime(int, int, int)
|
|
553 |
*/
|
|
554 |
public abstract int getHour();
|
|
555 |
|
|
556 |
/**
|
29999
|
557 |
* Return minutes or {@link DatatypeConstants#FIELD_UNDEFINED}.
|
12005
|
558 |
* Returns {@link DatatypeConstants#FIELD_UNDEFINED} if this field is not defined.
|
|
559 |
*
|
|
560 |
* <p>Value constraints for this value are summarized in
|
29999
|
561 |
* <a href="#datetimefield-minute">minute field of date/time field mapping table</a>.
|
12005
|
562 |
* @see #setTime(int, int, int)
|
|
563 |
*/
|
|
564 |
public abstract int getMinute();
|
|
565 |
|
|
566 |
/**
|
29999
|
567 |
* Return seconds or {@link DatatypeConstants#FIELD_UNDEFINED}.
|
12005
|
568 |
*
|
|
569 |
* <p>Returns {@link DatatypeConstants#FIELD_UNDEFINED} if this field is not defined.
|
|
570 |
* When this field is not defined, the optional xs:dateTime
|
|
571 |
* fractional seconds field, represented by
|
|
572 |
* {@link #getFractionalSecond()} and {@link #getMillisecond()},
|
29999
|
573 |
* must not be defined.
|
12005
|
574 |
*
|
|
575 |
* <p>Value constraints for this value are summarized in
|
29999
|
576 |
* <a href="#datetimefield-second">second field of date/time field mapping table</a>.
|
12005
|
577 |
*
|
29999
|
578 |
* @return Second of this {@code XMLGregorianCalendar}.
|
12005
|
579 |
*
|
|
580 |
* @see #getFractionalSecond()
|
|
581 |
* @see #getMillisecond()
|
|
582 |
* @see #setTime(int, int, int)
|
|
583 |
*/
|
|
584 |
public abstract int getSecond();
|
|
585 |
|
|
586 |
/**
|
29999
|
587 |
* Return millisecond precision of {@link #getFractionalSecond()}.
|
12005
|
588 |
*
|
|
589 |
* <p>This method represents a convenience accessor to infinite
|
|
590 |
* precision fractional second value returned by
|
|
591 |
* {@link #getFractionalSecond()}. The returned value is the rounded
|
|
592 |
* down to milliseconds value of
|
|
593 |
* {@link #getFractionalSecond()}. When {@link #getFractionalSecond()}
|
29999
|
594 |
* returns {@code null}, this method must return
|
|
595 |
* {@link DatatypeConstants#FIELD_UNDEFINED}.
|
12005
|
596 |
*
|
|
597 |
* <p>Value constraints for this value are summarized in
|
29999
|
598 |
* <a href="#datetimefield-second">second field of date/time field mapping table</a>.
|
12005
|
599 |
*
|
29999
|
600 |
* @return Millisecond of this {@code XMLGregorianCalendar}.
|
12005
|
601 |
*
|
|
602 |
* @see #getFractionalSecond()
|
|
603 |
* @see #setTime(int, int, int)
|
|
604 |
*/
|
|
605 |
public int getMillisecond() {
|
|
606 |
|
|
607 |
BigDecimal fractionalSeconds = getFractionalSecond();
|
|
608 |
|
|
609 |
// is field undefined?
|
|
610 |
if (fractionalSeconds == null) {
|
|
611 |
return DatatypeConstants.FIELD_UNDEFINED;
|
|
612 |
}
|
|
613 |
|
|
614 |
return getFractionalSecond().movePointRight(3).intValue();
|
|
615 |
}
|
|
616 |
|
|
617 |
/**
|
29999
|
618 |
* Return fractional seconds.
|
12005
|
619 |
*
|
29999
|
620 |
* <p>{@code null} is returned when this optional field is not defined.
|
12005
|
621 |
*
|
|
622 |
* <p>Value constraints are detailed in
|
29999
|
623 |
* <a href="#datetimefield-second">second field of date/time field mapping table</a>.
|
12005
|
624 |
*
|
|
625 |
* <p>This optional field can only have a defined value when the
|
|
626 |
* xs:dateTime second field, represented by {@link #getSecond()},
|
29999
|
627 |
* does not return {@link DatatypeConstants#FIELD_UNDEFINED}.
|
12005
|
628 |
*
|
29999
|
629 |
* @return fractional seconds of this {@code XMLGregorianCalendar}.
|
12005
|
630 |
*
|
|
631 |
* @see #getSecond()
|
|
632 |
* @see #setTime(int, int, int, BigDecimal)
|
|
633 |
*/
|
|
634 |
public abstract BigDecimal getFractionalSecond();
|
|
635 |
|
|
636 |
// comparisons
|
|
637 |
/**
|
29999
|
638 |
* Compare two instances of W3C XML Schema 1.0 date/time datatypes
|
12005
|
639 |
* according to partial order relation defined in
|
|
640 |
* <a href="http://www.w3.org/TR/xmlschema-2/#dateTime-order">W3C XML Schema 1.0 Part 2, Section 3.2.7.3,
|
29999
|
641 |
* <i>Order relation on dateTime</i></a>.
|
12005
|
642 |
*
|
29999
|
643 |
* <p>{@code xsd:dateTime} datatype field mapping to accessors of
|
12005
|
644 |
* this class are defined in
|
29999
|
645 |
* <a href="#datetimefieldmapping">date/time field mapping table</a>.
|
12005
|
646 |
*
|
29999
|
647 |
* @param xmlGregorianCalendar Instance of {@code XMLGregorianCalendar} to compare
|
12005
|
648 |
*
|
29999
|
649 |
* @return The relationship between {@code this} {@code XMLGregorianCalendar} and
|
|
650 |
* the specified {@code xmlGregorianCalendar} as
|
12005
|
651 |
* {@link DatatypeConstants#LESSER},
|
|
652 |
* {@link DatatypeConstants#EQUAL},
|
|
653 |
* {@link DatatypeConstants#GREATER} or
|
|
654 |
* {@link DatatypeConstants#INDETERMINATE}.
|
|
655 |
*
|
29999
|
656 |
* @throws NullPointerException if {@code xmlGregorianCalendar} is null.
|
12005
|
657 |
*/
|
|
658 |
public abstract int compare(XMLGregorianCalendar xmlGregorianCalendar);
|
|
659 |
|
|
660 |
/**
|
29999
|
661 |
* Normalize this instance to UTC.
|
12005
|
662 |
*
|
29999
|
663 |
* <p>2000-03-04T23:00:00+03:00 normalizes to 2000-03-04T20:00:00Z
|
|
664 |
* <p>Implements W3C XML Schema Part 2, Section 3.2.7.3 (A).
|
12005
|
665 |
*
|
29999
|
666 |
* @return {@code this} {@code XMLGregorianCalendar} normalized to UTC.
|
12005
|
667 |
*/
|
|
668 |
public abstract XMLGregorianCalendar normalize();
|
|
669 |
|
|
670 |
/**
|
29999
|
671 |
* Compares this calendar to the specified object. The result is
|
|
672 |
* {@code true} if and only if the argument is not null and is an
|
|
673 |
* {@code XMLGregorianCalendar} object that represents the same
|
|
674 |
* instant in time as this object.
|
12005
|
675 |
*
|
|
676 |
* @param obj to compare.
|
|
677 |
*
|
29999
|
678 |
* @return {@code true} when {@code obj} is an instance of
|
|
679 |
* {@code XMLGregorianCalendar} and
|
12005
|
680 |
* {@link #compare(XMLGregorianCalendar obj)}
|
|
681 |
* returns {@link DatatypeConstants#EQUAL},
|
29999
|
682 |
* otherwise {@code false}.
|
12005
|
683 |
*/
|
|
684 |
public boolean equals(Object obj) {
|
|
685 |
|
|
686 |
if (obj == null || !(obj instanceof XMLGregorianCalendar)) {
|
|
687 |
return false;
|
|
688 |
}
|
|
689 |
return compare((XMLGregorianCalendar) obj) == DatatypeConstants.EQUAL;
|
|
690 |
}
|
|
691 |
|
|
692 |
/**
|
29999
|
693 |
* Returns a hash code consistent with the definition of the equals method.
|
12005
|
694 |
*
|
|
695 |
* @return hash code of this object.
|
|
696 |
*/
|
|
697 |
public int hashCode() {
|
|
698 |
|
|
699 |
// Following two dates compare to EQUALS since in different timezones.
|
|
700 |
// 2000-01-15T12:00:00-05:00 == 2000-01-15T13:00:00-04:00
|
|
701 |
//
|
|
702 |
// Must ensure both instances generate same hashcode by normalizing
|
|
703 |
// this to UTC timezone.
|
|
704 |
int timezone = getTimezone();
|
|
705 |
if (timezone == DatatypeConstants.FIELD_UNDEFINED) {
|
|
706 |
timezone = 0;
|
|
707 |
}
|
|
708 |
XMLGregorianCalendar gc = this;
|
|
709 |
if (timezone != 0) {
|
|
710 |
gc = this.normalize();
|
|
711 |
}
|
|
712 |
return gc.getYear()
|
|
713 |
+ gc.getMonth()
|
|
714 |
+ gc.getDay()
|
|
715 |
+ gc.getHour()
|
|
716 |
+ gc.getMinute()
|
|
717 |
+ gc.getSecond();
|
|
718 |
}
|
|
719 |
|
|
720 |
/**
|
29999
|
721 |
* Return the lexical representation of {@code this} instance.
|
12005
|
722 |
* The format is specified in
|
|
723 |
* <a href="http://www.w3.org/TR/xmlschema-2/#dateTime-order">XML Schema 1.0 Part 2, Section 3.2.[7-14].1,
|
29999
|
724 |
* <i>Lexical Representation</i>".</a>
|
12005
|
725 |
*
|
|
726 |
* <p>Specific target lexical representation format is determined by
|
29999
|
727 |
* {@link #getXMLSchemaType()}.
|
12005
|
728 |
*
|
29999
|
729 |
* @return XML, as {@code String}, representation of this {@code XMLGregorianCalendar}
|
12005
|
730 |
*
|
|
731 |
* @throws IllegalStateException if the combination of set fields
|
|
732 |
* does not match one of the eight defined XML Schema builtin date/time datatypes.
|
|
733 |
*/
|
|
734 |
public abstract String toXMLFormat();
|
|
735 |
|
|
736 |
/**
|
29999
|
737 |
* Return the name of the XML Schema date/time type that this instance
|
|
738 |
* maps to. Type is computed based on fields that are set.
|
12005
|
739 |
*
|
|
740 |
* <table border="2" rules="all" cellpadding="2">
|
|
741 |
* <thead>
|
|
742 |
* <tr>
|
|
743 |
* <th align="center" colspan="7">
|
29999
|
744 |
* Required fields for XML Schema 1.0 Date/Time Datatypes.<br>
|
12005
|
745 |
* <i>(timezone is optional for all date/time datatypes)</i>
|
|
746 |
* </th>
|
|
747 |
* </tr>
|
|
748 |
* </thead>
|
|
749 |
* <tbody>
|
|
750 |
* <tr>
|
|
751 |
* <td>Datatype</td>
|
|
752 |
* <td>year</td>
|
|
753 |
* <td>month</td>
|
|
754 |
* <td>day</td>
|
|
755 |
* <td>hour</td>
|
|
756 |
* <td>minute</td>
|
|
757 |
* <td>second</td>
|
|
758 |
* </tr>
|
|
759 |
* <tr>
|
|
760 |
* <td>{@link DatatypeConstants#DATETIME}</td>
|
|
761 |
* <td>X</td>
|
|
762 |
* <td>X</td>
|
|
763 |
* <td>X</td>
|
|
764 |
* <td>X</td>
|
|
765 |
* <td>X</td>
|
|
766 |
* <td>X</td>
|
|
767 |
* </tr>
|
|
768 |
* <tr>
|
|
769 |
* <td>{@link DatatypeConstants#DATE}</td>
|
|
770 |
* <td>X</td>
|
|
771 |
* <td>X</td>
|
|
772 |
* <td>X</td>
|
|
773 |
* <td></td>
|
|
774 |
* <td></td>
|
|
775 |
* <td></td>
|
|
776 |
* </tr>
|
|
777 |
* <tr>
|
|
778 |
* <td>{@link DatatypeConstants#TIME}</td>
|
|
779 |
* <td></td>
|
|
780 |
* <td></td>
|
|
781 |
* <td></td>
|
|
782 |
* <td>X</td>
|
|
783 |
* <td>X</td>
|
|
784 |
* <td>X</td>
|
|
785 |
* </tr>
|
|
786 |
* <tr>
|
|
787 |
* <td>{@link DatatypeConstants#GYEARMONTH}</td>
|
|
788 |
* <td>X</td>
|
|
789 |
* <td>X</td>
|
|
790 |
* <td></td>
|
|
791 |
* <td></td>
|
|
792 |
* <td></td>
|
|
793 |
* <td></td>
|
|
794 |
* </tr>
|
|
795 |
* <tr>
|
|
796 |
* <td>{@link DatatypeConstants#GMONTHDAY}</td>
|
|
797 |
* <td></td>
|
|
798 |
* <td>X</td>
|
|
799 |
* <td>X</td>
|
|
800 |
* <td></td>
|
|
801 |
* <td></td>
|
|
802 |
* <td></td>
|
|
803 |
* </tr>
|
|
804 |
* <tr>
|
|
805 |
* <td>{@link DatatypeConstants#GYEAR}</td>
|
|
806 |
* <td>X</td>
|
|
807 |
* <td></td>
|
|
808 |
* <td></td>
|
|
809 |
* <td></td>
|
|
810 |
* <td></td>
|
|
811 |
* <td></td>
|
|
812 |
* </tr>
|
|
813 |
* <tr>
|
|
814 |
* <td>{@link DatatypeConstants#GMONTH}</td>
|
|
815 |
* <td></td>
|
|
816 |
* <td>X</td>
|
|
817 |
* <td></td>
|
|
818 |
* <td></td>
|
|
819 |
* <td></td>
|
|
820 |
* <td></td>
|
|
821 |
* </tr>
|
|
822 |
* <tr>
|
|
823 |
* <td>{@link DatatypeConstants#GDAY}</td>
|
|
824 |
* <td></td>
|
|
825 |
* <td></td>
|
|
826 |
* <td>X</td>
|
|
827 |
* <td></td>
|
|
828 |
* <td></td>
|
|
829 |
* <td></td>
|
|
830 |
* </tr>
|
|
831 |
* </tbody>
|
|
832 |
* </table>
|
|
833 |
*
|
|
834 |
* @throws java.lang.IllegalStateException if the combination of set fields
|
|
835 |
* does not match one of the eight defined XML Schema builtin
|
|
836 |
* date/time datatypes.
|
|
837 |
* @return One of the following class constants:
|
|
838 |
* {@link DatatypeConstants#DATETIME},
|
|
839 |
* {@link DatatypeConstants#TIME},
|
|
840 |
* {@link DatatypeConstants#DATE},
|
|
841 |
* {@link DatatypeConstants#GYEARMONTH},
|
|
842 |
* {@link DatatypeConstants#GMONTHDAY},
|
|
843 |
* {@link DatatypeConstants#GYEAR},
|
|
844 |
* {@link DatatypeConstants#GMONTH} or
|
|
845 |
* {@link DatatypeConstants#GDAY}.
|
|
846 |
*/
|
|
847 |
public abstract QName getXMLSchemaType();
|
|
848 |
|
|
849 |
/**
|
29999
|
850 |
* Returns a {@code String} representation of this {@code XMLGregorianCalendar} {@code Object}.
|
12005
|
851 |
*
|
29999
|
852 |
* <p>The result is a lexical representation generated by {@link #toXMLFormat()}.
|
12005
|
853 |
*
|
29999
|
854 |
* @return A non-{@code null} valid {@code String} representation of this {@code XMLGregorianCalendar}.
|
12005
|
855 |
*
|
|
856 |
* @throws IllegalStateException if the combination of set fields
|
|
857 |
* does not match one of the eight defined XML Schema builtin date/time datatypes.
|
|
858 |
*
|
|
859 |
* @see #toXMLFormat()
|
|
860 |
*/
|
|
861 |
public String toString() {
|
|
862 |
|
|
863 |
return toXMLFormat();
|
|
864 |
}
|
|
865 |
|
|
866 |
/**
|
29999
|
867 |
* Validate instance by {@code getXMLSchemaType()} constraints.
|
12005
|
868 |
* @return true if data values are valid.
|
|
869 |
*/
|
|
870 |
public abstract boolean isValid();
|
|
871 |
|
|
872 |
/**
|
29999
|
873 |
* Add {@code duration} to this instance.
|
12005
|
874 |
*
|
|
875 |
* <p>The computation is specified in
|
|
876 |
* <a href="http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes">XML Schema 1.0 Part 2, Appendix E,
|
29999
|
877 |
* <i>Adding durations to dateTimes</i></a>.
|
12005
|
878 |
* <a href="#datetimefieldmapping">date/time field mapping table</a>
|
29999
|
879 |
* defines the mapping from XML Schema 1.0 {@code dateTime} fields
|
|
880 |
* to this class' representation of those fields.
|
12005
|
881 |
*
|
29999
|
882 |
* @param duration Duration to add to this {@code XMLGregorianCalendar}.
|
12005
|
883 |
*
|
29999
|
884 |
* @throws NullPointerException when {@code duration} parameter is {@code null}.
|
12005
|
885 |
*/
|
|
886 |
public abstract void add(Duration duration);
|
|
887 |
|
|
888 |
/**
|
29999
|
889 |
* Convert this {@code XMLGregorianCalendar} to a {@link GregorianCalendar}.
|
12005
|
890 |
*
|
29999
|
891 |
* <p>When {@code this} instance has an undefined field, this
|
|
892 |
* conversion relies on the {@code java.util.GregorianCalendar} default
|
12005
|
893 |
* for its corresponding field. A notable difference between
|
29999
|
894 |
* XML Schema 1.0 date/time datatypes and {@code java.util.GregorianCalendar}
|
12005
|
895 |
* is that Timezone value is optional for date/time datatypes and it is
|
29999
|
896 |
* a required field for {@code java.util.GregorianCalendar}. See javadoc
|
|
897 |
* for {@code java.util.TimeZone.getDefault()} on how the default
|
|
898 |
* is determined. To explicitly specify the {@code TimeZone}
|
12005
|
899 |
* instance, see
|
29999
|
900 |
* {@link #toGregorianCalendar(TimeZone, Locale, XMLGregorianCalendar)}.
|
12005
|
901 |
*
|
|
902 |
* <table border="2" rules="all" cellpadding="2">
|
|
903 |
* <thead>
|
|
904 |
* <tr>
|
|
905 |
* <th align="center" colspan="2">
|
|
906 |
* Field by Field Conversion from this class to
|
29999
|
907 |
* {@code java.util.GregorianCalendar}
|
12005
|
908 |
* </th>
|
|
909 |
* </tr>
|
|
910 |
* </thead>
|
|
911 |
* <tbody>
|
|
912 |
* <tr>
|
29999
|
913 |
* <td>{@code java.util.GregorianCalendar} field</td>
|
|
914 |
* <td>{@code javax.xml.datatype.XMLGregorianCalendar} field</td>
|
12005
|
915 |
* </tr>
|
|
916 |
* <tr>
|
29999
|
917 |
* <td>{@code ERA}</td>
|
|
918 |
* <td>{@link #getEonAndYear()}{@code .signum() < 0 ? GregorianCalendar.BC : GregorianCalendar.AD}</td>
|
12005
|
919 |
* </tr>
|
|
920 |
* <tr>
|
29999
|
921 |
* <td>{@code YEAR}</td>
|
|
922 |
* <td>{@link #getEonAndYear()}{@code .abs().intValue()}<i>*</i></td>
|
12005
|
923 |
* </tr>
|
|
924 |
* <tr>
|
29999
|
925 |
* <td>{@code MONTH}</td>
|
12005
|
926 |
* <td>{@link #getMonth()} - {@link DatatypeConstants#JANUARY} + {@link GregorianCalendar#JANUARY}</td>
|
|
927 |
* </tr>
|
|
928 |
* <tr>
|
29999
|
929 |
* <td>{@code DAY_OF_MONTH}</td>
|
12005
|
930 |
* <td>{@link #getDay()}</td>
|
|
931 |
* </tr>
|
|
932 |
* <tr>
|
29999
|
933 |
* <td>{@code HOUR_OF_DAY}</td>
|
12005
|
934 |
* <td>{@link #getHour()}</td>
|
|
935 |
* </tr>
|
|
936 |
* <tr>
|
29999
|
937 |
* <td>{@code MINUTE}</td>
|
12005
|
938 |
* <td>{@link #getMinute()}</td>
|
|
939 |
* </tr>
|
|
940 |
* <tr>
|
29999
|
941 |
* <td>{@code SECOND}</td>
|
12005
|
942 |
* <td>{@link #getSecond()}</td>
|
|
943 |
* </tr>
|
|
944 |
* <tr>
|
29999
|
945 |
* <td>{@code MILLISECOND}</td>
|
12005
|
946 |
* <td>get millisecond order from {@link #getFractionalSecond()}<i>*</i> </td>
|
|
947 |
* </tr>
|
|
948 |
* <tr>
|
29999
|
949 |
* <td>{@code GregorianCalendar.setTimeZone(TimeZone)}</td>
|
12005
|
950 |
* <td>{@link #getTimezone()} formatted into Custom timezone id</td>
|
|
951 |
* </tr>
|
|
952 |
* </tbody>
|
|
953 |
* </table>
|
|
954 |
* <i>*</i> designates possible loss of precision during the conversion due
|
|
955 |
* to source datatype having higher precision than target datatype.
|
|
956 |
*
|
|
957 |
* <p>To ensure consistency in conversion implementations, the new
|
29999
|
958 |
* {@code GregorianCalendar} should be instantiated in following
|
12005
|
959 |
* manner.
|
|
960 |
* <ul>
|
29999
|
961 |
* <li>Using {@code timeZone} value as defined above, create a new
|
|
962 |
* {@code java.util.GregorianCalendar(timeZone,Locale.getDefault())}.
|
12005
|
963 |
* </li>
|
|
964 |
* <li>Initialize all GregorianCalendar fields by calling {@link java.util.GregorianCalendar#clear()}.</li>
|
|
965 |
* <li>Obtain a pure Gregorian Calendar by invoking
|
29999
|
966 |
* {@code GregorianCalendar.setGregorianChange(
|
|
967 |
* new Date(Long.MIN_VALUE))}.</li>
|
12005
|
968 |
* <li>Its fields ERA, YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY,
|
|
969 |
* MINUTE, SECOND and MILLISECOND are set using the method
|
29999
|
970 |
* {@code Calendar.set(int,int)}</li>
|
12005
|
971 |
* </ul>
|
|
972 |
*
|
|
973 |
* @see #toGregorianCalendar(java.util.TimeZone, java.util.Locale, XMLGregorianCalendar)
|
|
974 |
*/
|
|
975 |
public abstract GregorianCalendar toGregorianCalendar();
|
|
976 |
|
|
977 |
/**
|
29999
|
978 |
* Convert this {@code XMLGregorianCalendar} along with provided parameters
|
|
979 |
* to a {@link GregorianCalendar} instance.
|
12005
|
980 |
*
|
|
981 |
* <p> Since XML Schema 1.0 date/time datetypes has no concept of
|
|
982 |
* timezone ids or daylight savings timezone ids, this conversion operation
|
|
983 |
* allows the user to explicitly specify one with
|
29999
|
984 |
* {@code timezone} parameter.
|
12005
|
985 |
*
|
29999
|
986 |
* <p>To compute the return value's {@code TimeZone} field,
|
12005
|
987 |
* <ul>
|
29999
|
988 |
* <li>when parameter {@code timeZone} is non-null,
|
12005
|
989 |
* it is the timezone field.</li>
|
29999
|
990 |
* <li>else when {@code this.getTimezone() != FIELD_UNDEFINED},
|
|
991 |
* create a {@code java.util.TimeZone} with a custom timezone id
|
|
992 |
* using the {@code this.getTimezone()}.</li>
|
|
993 |
* <li>else when {@code defaults.getTimezone() != FIELD_UNDEFINED},
|
|
994 |
* create a {@code java.util.TimeZone} with a custom timezone id
|
|
995 |
* using {@code defaults.getTimezone()}.</li>
|
|
996 |
* <li>else use the {@code GregorianCalendar} default timezone value
|
12005
|
997 |
* for the host is defined as specified by
|
29999
|
998 |
* {@code java.util.TimeZone.getDefault()}.</li>
|
|
999 |
* </ul>
|
12005
|
1000 |
*
|
|
1001 |
* <p>To ensure consistency in conversion implementations, the new
|
29999
|
1002 |
* {@code GregorianCalendar} should be instantiated in following
|
12005
|
1003 |
* manner.
|
|
1004 |
* <ul>
|
29999
|
1005 |
* <li>Create a new {@code java.util.GregorianCalendar(TimeZone,
|
|
1006 |
* Locale)} with TimeZone set as specified above and the
|
|
1007 |
* {@code Locale} parameter.
|
12005
|
1008 |
* </li>
|
|
1009 |
* <li>Initialize all GregorianCalendar fields by calling {@link GregorianCalendar#clear()}</li>
|
|
1010 |
* <li>Obtain a pure Gregorian Calendar by invoking
|
29999
|
1011 |
* {@code GregorianCalendar.setGregorianChange(
|
|
1012 |
* new Date(Long.MIN_VALUE))}.</li>
|
12005
|
1013 |
* <li>Its fields ERA, YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY,
|
|
1014 |
* MINUTE, SECOND and MILLISECOND are set using the method
|
29999
|
1015 |
* {@code Calendar.set(int,int)}</li>
|
12005
|
1016 |
* </ul>
|
|
1017 |
*
|
29999
|
1018 |
* @param timezone provide Timezone. {@code null} is a legal value.
|
12005
|
1019 |
* @param aLocale provide explicit Locale. Use default GregorianCalendar locale if
|
29999
|
1020 |
* value is {@code null}.
|
12005
|
1021 |
* @param defaults provide default field values to use when corresponding
|
|
1022 |
* field for this instance is FIELD_UNDEFINED or null.
|
29999
|
1023 |
* If {@code defaults}is {@code null} or a field
|
|
1024 |
* within the specified {@code defaults} is undefined,
|
|
1025 |
* just use {@code java.util.GregorianCalendar} defaults.
|
12005
|
1026 |
* @return a java.util.GregorianCalendar conversion of this instance.
|
|
1027 |
*/
|
|
1028 |
public abstract GregorianCalendar toGregorianCalendar(
|
|
1029 |
java.util.TimeZone timezone,
|
|
1030 |
java.util.Locale aLocale,
|
|
1031 |
XMLGregorianCalendar defaults);
|
|
1032 |
|
|
1033 |
/**
|
29999
|
1034 |
* Returns a {@code java.util.TimeZone} for this class.
|
12005
|
1035 |
*
|
|
1036 |
* <p>If timezone field is defined for this instance,
|
|
1037 |
* returns TimeZone initialized with custom timezone id
|
|
1038 |
* of zoneoffset. If timezone field is undefined,
|
|
1039 |
* try the defaultZoneoffset that was passed in.
|
|
1040 |
* If defaultZoneoffset is FIELD_UNDEFINED, return
|
|
1041 |
* default timezone for this host.
|
29999
|
1042 |
* (Same default as java.util.GregorianCalendar).
|
12005
|
1043 |
*
|
|
1044 |
* @param defaultZoneoffset default zoneoffset if this zoneoffset is
|
|
1045 |
* {@link DatatypeConstants#FIELD_UNDEFINED}.
|
|
1046 |
*
|
|
1047 |
* @return TimeZone for this.
|
|
1048 |
*/
|
|
1049 |
public abstract TimeZone getTimeZone(int defaultZoneoffset);
|
|
1050 |
|
|
1051 |
|
|
1052 |
|
|
1053 |
/**
|
29999
|
1054 |
* Creates and returns a copy of this object.
|
12005
|
1055 |
*
|
29999
|
1056 |
* @return copy of this {@code Object}
|
12005
|
1057 |
*/
|
|
1058 |
public abstract Object clone();
|
|
1059 |
}
|