]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/icu/text/DateFormat.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / text / DateFormat.java
1 //##header\r
2 /*\r
3 *   Copyright (C) 1996-2009, International Business Machines\r
4 *   Corporation and others.  All Rights Reserved.\r
5 */\r
6 \r
7 package com.ibm.icu.text;\r
8 \r
9 import java.text.FieldPosition;\r
10 import java.text.ParseException;\r
11 import java.text.ParsePosition;\r
12 import java.util.Date;\r
13 import java.util.Locale;\r
14 import java.util.MissingResourceException;\r
15 \r
16 //#if defined(FOUNDATION10) || defined(J2SE13)\r
17 //#else\r
18 import java.io.InvalidObjectException;\r
19 import java.text.Format;\r
20 import java.util.HashMap;\r
21 import java.util.Map;\r
22 import com.ibm.icu.util.GregorianCalendar;\r
23 //#endif\r
24 \r
25 import com.ibm.icu.impl.ICUResourceBundle;\r
26 import com.ibm.icu.impl.RelativeDateFormat;\r
27 import com.ibm.icu.util.Calendar;\r
28 import com.ibm.icu.util.TimeZone;\r
29 import com.ibm.icu.util.ULocale;\r
30 \r
31 /**\r
32  * DateFormat is an abstract class for date/time formatting subclasses which\r
33  * formats and parses dates or time in a language-independent manner.\r
34  * The date/time formatting subclass, such as SimpleDateFormat, allows for\r
35  * formatting (i.e., date -> text), parsing (text -> date), and\r
36  * normalization.  The date is represented as a <code>Date</code> object or\r
37  * as the milliseconds since January 1, 1970, 00:00:00 GMT.\r
38  *\r
39  * <p>DateFormat provides many class methods for obtaining default date/time\r
40  * formatters based on the default or a given locale and a number of formatting\r
41  * styles. The formatting styles include FULL, LONG, MEDIUM, and SHORT. More\r
42  * detail and examples of using these styles are provided in the method\r
43  * descriptions.\r
44  *\r
45  * <p>DateFormat helps you to format and parse dates for any locale.\r
46  * Your code can be completely independent of the locale conventions for\r
47  * months, days of the week, or even the calendar format: lunar vs. solar.\r
48  *\r
49  * <p>To format a date for the current Locale, use one of the\r
50  * static factory methods:\r
51  * <pre>\r
52  *  myString = DateFormat.getDateInstance().format(myDate);\r
53  * </pre>\r
54  * <p>If you are formatting multiple numbers, it is\r
55  * more efficient to get the format and use it multiple times so that\r
56  * the system doesn't have to fetch the information about the local\r
57  * language and country conventions multiple times.\r
58  * <pre>\r
59  *  DateFormat df = DateFormat.getDateInstance();\r
60  *  for (int i = 0; i < a.length; ++i) {\r
61  *    output.println(df.format(myDate[i]) + "; ");\r
62  *  }\r
63  * </pre>\r
64  * <p>To format a number for a different Locale, specify it in the\r
65  * call to getDateInstance().\r
66  * <pre>\r
67  *  DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);\r
68  * </pre>\r
69  * <p>You can use a DateFormat to parse also.\r
70  * <pre>\r
71  *  myDate = df.parse(myString);\r
72  * </pre>\r
73  * <p>Use getDateInstance to get the normal date format for that country.\r
74  * There are other static factory methods available.\r
75  * Use getTimeInstance to get the time format for that country.\r
76  * Use getDateTimeInstance to get a date and time format. You can pass in \r
77  * different options to these factory methods to control the length of the\r
78  * result; from SHORT to MEDIUM to LONG to FULL. The exact result depends\r
79  * on the locale, but generally:\r
80  * <ul><li>SHORT is completely numeric, such as 12.13.52 or 3:30pm\r
81  * <li>MEDIUM is longer, such as Jan 12, 1952\r
82  * <li>LONG is longer, such as January 12, 1952 or 3:30:32pm\r
83  * <li>FULL is pretty completely specified, such as\r
84  * Tuesday, April 12, 1952 AD or 3:30:42pm PST.\r
85  * </ul>\r
86  *\r
87  * <p>You can also set the time zone on the format if you wish.\r
88  * If you want even more control over the format or parsing,\r
89  * (or want to give your users more control),\r
90  * you can try casting the DateFormat you get from the factory methods\r
91  * to a SimpleDateFormat. This will work for the majority\r
92  * of countries; just remember to put it in a try block in case you\r
93  * encounter an unusual one.\r
94  *\r
95  * <p>You can also use forms of the parse and format methods with\r
96  * ParsePosition and FieldPosition to\r
97  * allow you to\r
98  * <ul><li>progressively parse through pieces of a string.\r
99  * <li>align any particular field, or find out where it is for selection\r
100  * on the screen.\r
101  * </ul>\r
102  *\r
103  * <h4>Synchronization</h4>\r
104  *\r
105  * Date formats are not synchronized. It is recommended to create separate \r
106  * format instances for each thread. If multiple threads access a format \r
107  * concurrently, it must be synchronized externally. \r
108  *\r
109  * @see          UFormat\r
110  * @see          NumberFormat\r
111  * @see          SimpleDateFormat\r
112  * @see          com.ibm.icu.util.Calendar\r
113  * @see          com.ibm.icu.util.GregorianCalendar\r
114  * @see          com.ibm.icu.util.TimeZone\r
115  * @author       Mark Davis, Chen-Lieh Huang, Alan Liu\r
116  * @stable ICU 2.0\r
117  */\r
118 public abstract class DateFormat extends UFormat {\r
119 \r
120     /**\r
121      * The calendar that <code>DateFormat</code> uses to produce the time field\r
122      * values needed to implement date and time formatting.  Subclasses should\r
123      * initialize this to a calendar appropriate for the locale associated with\r
124      * this <code>DateFormat</code>.\r
125      * @serial\r
126      * @stable ICU 2.0\r
127      */\r
128     protected Calendar calendar;\r
129 \r
130     /**\r
131      * The number formatter that <code>DateFormat</code> uses to format numbers\r
132      * in dates and times.  Subclasses should initialize this to a number format\r
133      * appropriate for the locale associated with this <code>DateFormat</code>.\r
134      * @serial\r
135      * @stable ICU 2.0\r
136      */\r
137     protected NumberFormat numberFormat;\r
138 \r
139     /**\r
140      * FieldPosition selector for 'G' field alignment,\r
141      * corresponding to the {@link Calendar#ERA} field.\r
142      * @stable ICU 2.0\r
143      */\r
144     public final static int ERA_FIELD = 0;\r
145 \r
146     /**\r
147      * FieldPosition selector for 'y' field alignment,\r
148      * corresponding to the {@link Calendar#YEAR} field.\r
149      * @stable ICU 2.0\r
150      */\r
151     public final static int YEAR_FIELD = 1;\r
152 \r
153     /**\r
154      * FieldPosition selector for 'M' field alignment,\r
155      * corresponding to the {@link Calendar#MONTH} field.\r
156      * @stable ICU 2.0\r
157      */\r
158     public final static int MONTH_FIELD = 2;\r
159 \r
160     /**\r
161      * FieldPosition selector for 'd' field alignment,\r
162      * corresponding to the {@link Calendar#DATE} field.\r
163      * @stable ICU 2.0\r
164      */\r
165     public final static int DATE_FIELD = 3;\r
166 \r
167     /**\r
168      * FieldPosition selector for 'k' field alignment,\r
169      * corresponding to the {@link Calendar#HOUR_OF_DAY} field.\r
170      * HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock.\r
171      * For example, 23:59 + 01:00 results in 24:59.\r
172      * @stable ICU 2.0\r
173      */\r
174     public final static int HOUR_OF_DAY1_FIELD = 4;\r
175 \r
176     /**\r
177      * FieldPosition selector for 'H' field alignment,\r
178      * corresponding to the {@link Calendar#HOUR_OF_DAY} field.\r
179      * HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock.\r
180      * For example, 23:59 + 01:00 results in 00:59.\r
181      * @stable ICU 2.0\r
182      */\r
183     public final static int HOUR_OF_DAY0_FIELD = 5;\r
184 \r
185     /**\r
186      * FieldPosition selector for 'm' field alignment,\r
187      * corresponding to the {@link Calendar#MINUTE} field.\r
188      * @stable ICU 2.0\r
189      */\r
190     public final static int MINUTE_FIELD = 6;\r
191 \r
192     /**\r
193      * FieldPosition selector for 's' field alignment,\r
194      * corresponding to the {@link Calendar#SECOND} field.\r
195      * @stable ICU 2.0\r
196      */\r
197     public final static int SECOND_FIELD = 7;\r
198 \r
199     /**\r
200      * FieldPosition selector for 'S' field alignment,\r
201      * corresponding to the {@link Calendar#MILLISECOND} field.\r
202      * @stable ICU 3.0\r
203      */\r
204     public final static int FRACTIONAL_SECOND_FIELD = 8;\r
205 \r
206     /**\r
207      * Alias for FRACTIONAL_SECOND_FIELD.\r
208      * @deprecated ICU 3.0 use FRACTIONAL_SECOND_FIELD.\r
209      */\r
210     public final static int MILLISECOND_FIELD = FRACTIONAL_SECOND_FIELD;\r
211 \r
212     /**\r
213      * FieldPosition selector for 'E' field alignment,\r
214      * corresponding to the {@link Calendar#DAY_OF_WEEK} field.\r
215      * @stable ICU 2.0\r
216      */\r
217     public final static int DAY_OF_WEEK_FIELD = 9;\r
218 \r
219     /**\r
220      * FieldPosition selector for 'D' field alignment,\r
221      * corresponding to the {@link Calendar#DAY_OF_YEAR} field.\r
222      * @stable ICU 2.0\r
223      */\r
224     public final static int DAY_OF_YEAR_FIELD = 10;\r
225 \r
226     /**\r
227      * FieldPosition selector for 'F' field alignment,\r
228      * corresponding to the {@link Calendar#DAY_OF_WEEK_IN_MONTH} field.\r
229      * @stable ICU 2.0\r
230      */\r
231     public final static int DAY_OF_WEEK_IN_MONTH_FIELD = 11;\r
232 \r
233     /**\r
234      * FieldPosition selector for 'w' field alignment,\r
235      * corresponding to the {@link Calendar#WEEK_OF_YEAR} field.\r
236      * @stable ICU 2.0\r
237      */\r
238     public final static int WEEK_OF_YEAR_FIELD = 12;\r
239 \r
240     /**\r
241      * FieldPosition selector for 'W' field alignment,\r
242      * corresponding to the {@link Calendar#WEEK_OF_MONTH} field.\r
243      * @stable ICU 2.0\r
244      */\r
245     public final static int WEEK_OF_MONTH_FIELD = 13;\r
246 \r
247     /**\r
248      * FieldPosition selector for 'a' field alignment,\r
249      * corresponding to the {@link Calendar#AM_PM} field.\r
250      * @stable ICU 2.0\r
251      */\r
252     public final static int AM_PM_FIELD = 14;\r
253 \r
254     /**\r
255      * FieldPosition selector for 'h' field alignment,\r
256      * corresponding to the {@link Calendar#HOUR} field.\r
257      * HOUR1_FIELD is used for the one-based 12-hour clock.\r
258      * For example, 11:30 PM + 1 hour results in 12:30 AM.\r
259      * @stable ICU 2.0\r
260      */\r
261     public final static int HOUR1_FIELD = 15;\r
262 \r
263     /**\r
264      * FieldPosition selector for 'K' field alignment,\r
265      * corresponding to the {@link Calendar#HOUR} field.\r
266      * HOUR0_FIELD is used for the zero-based 12-hour clock.\r
267      * For example, 11:30 PM + 1 hour results in 00:30 AM.\r
268      * @stable ICU 2.0\r
269      */\r
270     public final static int HOUR0_FIELD = 16;\r
271 \r
272     /**\r
273      * FieldPosition selector for 'z' field alignment,\r
274      * corresponding to the {@link Calendar#ZONE_OFFSET} and\r
275      * {@link Calendar#DST_OFFSET} fields.\r
276      * @stable ICU 2.0\r
277      */\r
278     public final static int TIMEZONE_FIELD = 17;\r
279 \r
280     /**\r
281      * FieldPosition selector for 'Y' field alignment,\r
282      * corresponding to the {@link Calendar#YEAR_WOY} field.\r
283      * @stable ICU 3.0\r
284      */\r
285     public final static int YEAR_WOY_FIELD = 18;\r
286 \r
287     /**\r
288      * FieldPosition selector for 'e' field alignment,\r
289      * corresponding to the {@link Calendar#DOW_LOCAL} field.\r
290      * @stable ICU 3.0\r
291      */\r
292     public final static int DOW_LOCAL_FIELD = 19;\r
293 \r
294     /**\r
295      * FieldPosition selector for 'u' field alignment,\r
296      * corresponding to the {@link Calendar#EXTENDED_YEAR} field.\r
297      * @stable ICU 3.0\r
298      */\r
299     public final static int EXTENDED_YEAR_FIELD = 20;\r
300 \r
301     /**\r
302      * FieldPosition selector for 'g' field alignment,\r
303      * corresponding to the {@link Calendar#JULIAN_DAY} field.\r
304      * @stable ICU 3.0\r
305      */\r
306     public final static int JULIAN_DAY_FIELD = 21;\r
307 \r
308     /**\r
309      * FieldPosition selector for 'A' field alignment,\r
310      * corresponding to the {@link Calendar#MILLISECONDS_IN_DAY} field.\r
311      * @stable ICU 3.0\r
312      */\r
313     public final static int MILLISECONDS_IN_DAY_FIELD = 22;\r
314 \r
315     /**\r
316      * FieldPosition selector for 'Z' field alignment,\r
317      * corresponding to the {@link Calendar#ZONE_OFFSET} and\r
318      * {@link Calendar#DST_OFFSET} fields.\r
319      * @stable ICU 3.0\r
320      */\r
321     public final static int TIMEZONE_RFC_FIELD = 23;\r
322 \r
323     /**\r
324      * FieldPosition selector for 'v' field alignment,\r
325      * corresponding to the {@link Calendar#ZONE_OFFSET} and\r
326      * {@link Calendar#DST_OFFSET} fields.  This displays the generic zone\r
327      * name, if available.\r
328      * @stable ICU 3.4\r
329      */\r
330     public final static int TIMEZONE_GENERIC_FIELD = 24;\r
331  \r
332 \r
333     \r
334     /**\r
335      * FieldPosition selector for 'c' field alignment,\r
336      * corresponding to the {@link Calendar#DAY_OF_WEEK} field. \r
337      * This displays the stand alone day name, if available.\r
338      * @stable ICU 3.4\r
339      */\r
340     public final static int STANDALONE_DAY_FIELD = 25;\r
341     \r
342     /**\r
343      * FieldPosition selector for 'L' field alignment,\r
344      * corresponding to the {@link Calendar#MONTH} field.  \r
345      * This displays the stand alone month name, if available.\r
346      * @stable ICU 3.4\r
347      */\r
348     public final static int STANDALONE_MONTH_FIELD = 26;\r
349     \r
350     /**\r
351      * FieldPosition selector for 'Q' field alignment,\r
352      * corresponding to the {@link Calendar#MONTH} field.  \r
353      * This displays the quarter.\r
354      * @stable ICU 3.6\r
355      */\r
356     public final static int QUARTER_FIELD = 27;\r
357     \r
358     /**\r
359      * FieldPosition selector for 'q' field alignment,\r
360      * corresponding to the {@link Calendar#MONTH} field.  \r
361      * This displays the stand alone quarter, if available.\r
362      * @stable ICU 3.6\r
363      */\r
364     public final static int STANDALONE_QUARTER_FIELD = 28;\r
365     \r
366     /**\r
367      * FieldPosition selector for 'V' field alignment,\r
368      * corresponding to the {@link Calendar#ZONE_OFFSET} and\r
369      * {@link Calendar#DST_OFFSET} fields.  This displays the fallback timezone\r
370      * name when VVVV is specified, and the short standard or daylight\r
371      * timezone name ignoring commonlyUsed when a single V is specified.\r
372      * @stable ICU 3.8\r
373      */\r
374     public final static int TIMEZONE_SPECIAL_FIELD = 29;\r
375 \r
376     /**\r
377      * Number of FieldPosition selectors for DateFormat.\r
378      * Valid selectors range from 0 to FIELD_COUNT-1.\r
379      * @stable ICU 3.0\r
380      */\r
381     public final static int FIELD_COUNT = 30; // must == DateFormatSymbols.patternChars.length()\r
382 \r
383     // Proclaim serial compatibility with 1.1 FCS\r
384     private static final long serialVersionUID = 7218322306649953788L;\r
385 \r
386     /**\r
387      * Overrides Format.\r
388      * Formats a time object into a time string. Examples of time objects\r
389      * are a time value expressed in milliseconds and a Date object.\r
390      * @param obj must be a Number or a Date or a Calendar.\r
391      * @param toAppendTo the string buffer for the returning time string.\r
392      * @return the formatted time string.\r
393      * @param fieldPosition keeps track of the position of the field\r
394      * within the returned string.\r
395      * On input: an alignment field,\r
396      * if desired. On output: the offsets of the alignment field. For\r
397      * example, given a time text "1996.07.10 AD at 15:08:56 PDT",\r
398      * if the given fieldPosition is DateFormat.YEAR_FIELD, the\r
399      * begin index and end index of fieldPosition will be set to\r
400      * 0 and 4, respectively.\r
401      * Notice that if the same time field appears\r
402      * more than once in a pattern, the fieldPosition will be set for the first\r
403      * occurrence of that time field. For instance, formatting a Date to\r
404      * the time string "1 PM PDT (Pacific Daylight Time)" using the pattern\r
405      * "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD,\r
406      * the begin index and end index of fieldPosition will be set to\r
407      * 5 and 8, respectively, for the first occurrence of the timezone\r
408      * pattern character 'z'.\r
409      * @see java.text.Format\r
410      * @stable ICU 2.0\r
411      */\r
412     public final StringBuffer format(Object obj, StringBuffer toAppendTo,\r
413                                      FieldPosition fieldPosition)\r
414     {\r
415         if (obj instanceof Calendar)\r
416             return format( (Calendar)obj, toAppendTo, fieldPosition );\r
417         else if (obj instanceof Date)\r
418             return format( (Date)obj, toAppendTo, fieldPosition );\r
419         else if (obj instanceof Number)\r
420             return format( new Date(((Number)obj).longValue()),\r
421                           toAppendTo, fieldPosition );\r
422         else \r
423             throw new IllegalArgumentException("Cannot format given Object (" + obj.getClass().getName() + ") as a Date");\r
424     }\r
425 \r
426     /**\r
427      * Formats a date into a date/time string.\r
428      * @param cal a Calendar set to the date and time to be formatted\r
429      * into a date/time string.  When the calendar type is different from\r
430      * the internal calendar held by this DateFormat instance, the date\r
431      * and the time zone will be inherited from the input calendar, but\r
432      * other calendar field values will be calculated by the internal calendar.\r
433      * @param toAppendTo the string buffer for the returning date/time string.\r
434      * @param fieldPosition keeps track of the position of the field\r
435      * within the returned string.\r
436      * On input: an alignment field,\r
437      * if desired. On output: the offsets of the alignment field. For\r
438      * example, given a time text "1996.07.10 AD at 15:08:56 PDT",\r
439      * if the given fieldPosition is DateFormat.YEAR_FIELD, the\r
440      * begin index and end index of fieldPosition will be set to\r
441      * 0 and 4, respectively.\r
442      * Notice that if the same time field appears\r
443      * more than once in a pattern, the fieldPosition will be set for the first\r
444      * occurrence of that time field. For instance, formatting a Date to\r
445      * the time string "1 PM PDT (Pacific Daylight Time)" using the pattern\r
446      * "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD,\r
447      * the begin index and end index of fieldPosition will be set to\r
448      * 5 and 8, respectively, for the first occurrence of the timezone\r
449      * pattern character 'z'.\r
450      * @return the formatted date/time string.\r
451      * @stable ICU 2.0\r
452      */\r
453     public abstract StringBuffer format(Calendar cal, StringBuffer toAppendTo,\r
454                                         FieldPosition fieldPosition);\r
455 \r
456     /**\r
457      * Formats a Date into a date/time string.\r
458      * @param date a Date to be formatted into a date/time string.\r
459      * @param toAppendTo the string buffer for the returning date/time string.\r
460      * @param fieldPosition keeps track of the position of the field\r
461      * within the returned string.\r
462      * On input: an alignment field,\r
463      * if desired. On output: the offsets of the alignment field. For\r
464      * example, given a time text "1996.07.10 AD at 15:08:56 PDT",\r
465      * if the given fieldPosition is DateFormat.YEAR_FIELD, the\r
466      * begin index and end index of fieldPosition will be set to\r
467      * 0 and 4, respectively.\r
468      * Notice that if the same time field appears\r
469      * more than once in a pattern, the fieldPosition will be set for the first\r
470      * occurrence of that time field. For instance, formatting a Date to\r
471      * the time string "1 PM PDT (Pacific Daylight Time)" using the pattern\r
472      * "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD,\r
473      * the begin index and end index of fieldPosition will be set to\r
474      * 5 and 8, respectively, for the first occurrence of the timezone\r
475      * pattern character 'z'.\r
476      * @return the formatted date/time string.\r
477      * @stable ICU 2.0\r
478      */\r
479     public StringBuffer format(Date date, StringBuffer toAppendTo,\r
480                                      FieldPosition fieldPosition) {\r
481         // Use our Calendar object\r
482         calendar.setTime(date);\r
483         return format(calendar, toAppendTo, fieldPosition);\r
484     }\r
485 \r
486     /**\r
487      * Formats a Date into a date/time string.\r
488      * @param date the time value to be formatted into a time string.\r
489      * @return the formatted time string.\r
490      * @stable ICU 2.0\r
491      */\r
492     public final String format(Date date)\r
493     {\r
494         return format(date, new StringBuffer(64),new FieldPosition(0)).toString();\r
495     }\r
496 \r
497     /**\r
498      * Parse a date/time string.\r
499      *\r
500      * @param text  The date/time string to be parsed\r
501      *\r
502      * @return      A Date, or null if the input could not be parsed\r
503      *\r
504      * @exception  ParseException  If the given string cannot be parsed as a date.\r
505      *\r
506      * @see #parse(String, ParsePosition)\r
507      * @stable ICU 2.0\r
508      */\r
509     public Date parse(String text) throws ParseException\r
510     {\r
511         ParsePosition pos = new ParsePosition(0);\r
512         Date result = parse(text, pos);\r
513         if (pos.getIndex() == 0) // ICU4J\r
514             throw new ParseException("Unparseable date: \"" + text + "\"" ,\r
515                                      pos.getErrorIndex()); // ICU4J\r
516         return result;\r
517     }\r
518 \r
519     /**\r
520      * Parse a date/time string according to the given parse position.\r
521      * For example, a time text "07/10/96 4:5 PM, PDT" will be parsed\r
522      * into a Calendar that is equivalent to Date(837039928046).  The\r
523      * caller should clear the calendar before calling this method,\r
524      * unless existing field information is to be kept.\r
525      *\r
526      * <p> By default, parsing is lenient: If the input is not in the form used\r
527      * by this object's format method but can still be parsed as a date, then\r
528      * the parse succeeds.  Clients may insist on strict adherence to the\r
529      * format by calling setLenient(false).\r
530      *\r
531      * @see #setLenient(boolean)\r
532      *\r
533      * @param text  The date/time string to be parsed\r
534      *\r
535      * @param cal   The calendar into which parsed data will be stored.\r
536      *              In general, this should be cleared before calling this\r
537      *              method.  If this parse fails, the calendar may still\r
538      *              have been modified.  When the calendar type is different\r
539      *              from the internal calendar held by this DateFormat\r
540      *              instance, calendar field values will be parsed based\r
541      *              on the internal calendar initialized with the time and\r
542      *              the time zone taken from this calendar, then the\r
543      *              parse result (time in milliseconds and time zone) will\r
544      *              be set back to this calendar.\r
545      *\r
546      * @param pos   On input, the position at which to start parsing; on\r
547      *              output, the position at which parsing terminated, or the\r
548      *              start position if the parse failed.\r
549      * @stable ICU 2.0\r
550      */\r
551     public abstract void parse(String text, Calendar cal, ParsePosition pos);\r
552 \r
553     /**\r
554      * Parse a date/time string according to the given parse position.  For\r
555      * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date\r
556      * that is equivalent to Date(837039928046).\r
557      *\r
558      * <p> By default, parsing is lenient: If the input is not in the form used\r
559      * by this object's format method but can still be parsed as a date, then\r
560      * the parse succeeds.  Clients may insist on strict adherence to the\r
561      * format by calling setLenient(false).\r
562      *\r
563      * @see #setLenient(boolean)\r
564      *\r
565      * @param text  The date/time string to be parsed\r
566      *\r
567      * @param pos   On input, the position at which to start parsing; on\r
568      *              output, the position at which parsing terminated, or the\r
569      *              start position if the parse failed.\r
570      *\r
571      * @return      A Date, or null if the input could not be parsed\r
572      * @stable ICU 2.0\r
573      */\r
574     public Date parse(String text, ParsePosition pos) {\r
575         Date result = null;\r
576         int start = pos.getIndex();\r
577         TimeZone tzsav = calendar.getTimeZone();\r
578         calendar.clear();\r
579         parse(text, calendar, pos);\r
580         if (pos.getIndex() != start) {\r
581             try {\r
582                 result = calendar.getTime();\r
583             } catch (IllegalArgumentException e) {\r
584                 // This occurs if the calendar is non-lenient and there is\r
585                 // an out-of-range field.  We don't know which field was\r
586                 // illegal so we set the error index to the start.\r
587                 pos.setIndex(start);\r
588                 pos.setErrorIndex(start);\r
589             }\r
590         }\r
591         // Restore TimeZone\r
592         calendar.setTimeZone(tzsav);\r
593         return result;\r
594     }\r
595 \r
596     /**\r
597      * Parse a date/time string into an Object.  This convenience method simply\r
598      * calls parse(String, ParsePosition).\r
599      *\r
600      * @see #parse(String, ParsePosition)\r
601      * @stable ICU 2.0\r
602      */\r
603     public Object parseObject (String source, ParsePosition pos)\r
604     {\r
605         return parse(source, pos);\r
606     }\r
607 \r
608     /**\r
609      * Constant for empty style pattern.\r
610      * @stable ICU 3.8\r
611      */\r
612     public static final int NONE = -1;\r
613     \r
614     /**\r
615      * Constant for full style pattern.\r
616      * @stable ICU 2.0\r
617      */\r
618     public static final int FULL = 0;\r
619 \r
620     /**\r
621      * Constant for long style pattern.\r
622      * @stable ICU 2.0\r
623      */\r
624     public static final int LONG = 1;\r
625 \r
626     /**\r
627      * Constant for medium style pattern.\r
628      * @stable ICU 2.0\r
629      */\r
630     public static final int MEDIUM = 2;\r
631 \r
632     /**\r
633      * Constant for short style pattern.\r
634      * @stable ICU 2.0\r
635      */\r
636     public static final int SHORT = 3;\r
637 \r
638     /**\r
639      * Constant for default style pattern.  Its value is MEDIUM.\r
640      * @stable ICU 2.0\r
641      */\r
642     public static final int DEFAULT = MEDIUM;\r
643     \r
644     /**\r
645      * Constant for relative style mask.\r
646      * @stable ICU 3.8\r
647      */\r
648     public static final int RELATIVE = (1 << 7);\r
649 \r
650     /**\r
651      * Constant for relative full style pattern.\r
652      * @stable ICU 3.8\r
653      */\r
654     public static final int RELATIVE_FULL = RELATIVE | FULL;\r
655 \r
656     /**\r
657      * Constant for relative style pattern.\r
658      * @stable ICU 3.8\r
659      */\r
660     public static final int RELATIVE_LONG = RELATIVE | LONG;\r
661 \r
662     /**\r
663      * Constant for relative style pattern.\r
664      * @stable ICU 3.8\r
665      */\r
666     public static final int RELATIVE_MEDIUM = RELATIVE | MEDIUM;\r
667 \r
668     /**\r
669      * Constant for relative style pattern.\r
670      * @stable ICU 3.8\r
671      */\r
672     public static final int RELATIVE_SHORT = RELATIVE | SHORT;\r
673 \r
674     /**\r
675      * Constant for relative default style pattern.\r
676      * @stable ICU 3.8\r
677      */\r
678     public static final int RELATIVE_DEFAULT = RELATIVE | DEFAULT;\r
679 \r
680     /* Below are pre-defined skeletons\r
681      *\r
682      * <P>\r
683      * A skeleton \r
684      * <ul>\r
685      * <li>\r
686      * 1. only keeps the field pattern letter and ignores all other parts \r
687      *    in a pattern, such as space, punctuations, and string literals.\r
688      * <li>\r
689      * 2. hides the order of fields. \r
690      * <li>\r
691      * 3. might hide a field's pattern letter length.\r
692      *\r
693      *    For those non-digit calendar fields, the pattern letter length is \r
694      *    important, such as MMM, MMMM, and MMMMM; E and EEEE, \r
695      *    and the field's pattern letter length is honored.\r
696      *    \r
697      *    For the digit calendar fields,  such as M or MM, d or dd, yy or yyyy, \r
698      *    the field pattern length is ignored and the best match, which is \r
699      *    defined in date time patterns, will be returned without honor \r
700      *    the field pattern letter length in skeleton.\r
701      * </ul>\r
702      */\r
703     /** \r
704      * Constant for date pattern with minute and second.\r
705      * @stable ICU 4.0\r
706      */\r
707     public static final String MINUTE_SECOND = "ms";\r
708 \r
709     /** \r
710      * Constant for date pattern with hour and minute in 24-hour presentation.\r
711      * @stable ICU 4.0\r
712      */\r
713     public static final String HOUR24_MINUTE = "Hm";\r
714 \r
715     /** \r
716      * Constant for date pattern with hour, minute, and second in\r
717      * 24-hour presentation.\r
718      * @stable ICU 4.0\r
719      */\r
720     public static final String HOUR24_MINUTE_SECOND = "Hms";      \r
721 \r
722     /** \r
723      * Constant for date pattern with hour, minute, and second.\r
724      * @stable ICU 4.0\r
725      */\r
726     public static final String HOUR_MINUTE_SECOND = "hms";\r
727 \r
728     /** \r
729      * Constant for date pattern with standalone month.\r
730      * @stable ICU 4.0\r
731      */\r
732     public static final String STANDALONE_MONTH = "LLLL";\r
733 \r
734     /** \r
735      * Constant for date pattern with standalone abbreviated month.\r
736      * @stable ICU 4.0\r
737      */\r
738     public static final String ABBR_STANDALONE_MONTH = "LLL";\r
739 \r
740     /** \r
741      * Constant for date pattern with year and quarter.\r
742      * @stable ICU 4.0\r
743      */\r
744     public static final String YEAR_QUARTER = "yQQQ";\r
745     \r
746     /** \r
747      * Constant for date pattern with year and abbreviated quarter.\r
748      * @stable ICU 4.0\r
749      */\r
750     public static final String YEAR_ABBR_QUARTER = "yQ";\r
751 \r
752     \r
753     /* Below are skeletons that date interval pre-defined in resource file.\r
754      * Users are encouraged to use them in date interval format factory methods.\r
755      */\r
756     /** \r
757      * Constant for date pattern with hour and minute.\r
758      * @stable ICU 4.0\r
759      */\r
760     public static final String HOUR_MINUTE = "hm";\r
761 \r
762     /** \r
763      * Constant for date pattern with year.\r
764      * @stable ICU 4.0\r
765      */\r
766     public static final String YEAR = "y";\r
767 \r
768     /** \r
769      * Constant for date pattern with day.\r
770      * @stable ICU 4.0\r
771      */\r
772     public static final String DAY = "d";\r
773 \r
774     /** \r
775      * Constant for date pattern with numeric month, weekday, and day.\r
776      * @stable ICU 4.0\r
777      */\r
778     public static final String NUM_MONTH_WEEKDAY_DAY = "MEd";\r
779 \r
780     /** \r
781      * Constant for date pattern with year and numeric month.\r
782      * @stable ICU 4.0\r
783      */\r
784     public static final String YEAR_NUM_MONTH = "yM";              \r
785 \r
786     /** \r
787      * Constant for date pattern with numeric month and day.\r
788      * @stable ICU 4.0\r
789      */\r
790     public static final String NUM_MONTH_DAY = "Md";\r
791 \r
792     /** \r
793      * Constant for date pattern with year, numeric month, weekday, and day.\r
794      * @stable ICU 4.0\r
795      */\r
796     public static final String YEAR_NUM_MONTH_WEEKDAY_DAY = "yMEd";\r
797 \r
798     /** \r
799      * Constant for date pattern with abbreviated month, weekday, and day.\r
800      * @stable ICU 4.0\r
801      */\r
802     public static final String ABBR_MONTH_WEEKDAY_DAY = "MMMEd";\r
803 \r
804     /** \r
805      * Constant for date pattern with year and month.\r
806      * @stable ICU 4.0\r
807      */\r
808     public static final String YEAR_MONTH = "yMMMM";\r
809 \r
810     /** \r
811      * Constant for date pattern with year and abbreviated month.\r
812      * @stable ICU 4.0\r
813      */\r
814     public static final String YEAR_ABBR_MONTH = "yMMM";\r
815 \r
816     /** \r
817      * Constant for date pattern having month and day.\r
818      * @stable ICU 4.0\r
819      */\r
820     public static final String MONTH_DAY = "MMMMd";\r
821 \r
822     /** \r
823      * Constant for date pattern with abbreviated month and day.\r
824      * @stable ICU 4.0\r
825      */\r
826     public static final String ABBR_MONTH_DAY = "MMMd"; \r
827 \r
828     /** \r
829      * Constant for date pattern with month, weekday, and day.\r
830      * @stable ICU 4.0\r
831      */\r
832     public static final String MONTH_WEEKDAY_DAY = "MMMMEEEEd";\r
833 \r
834     /** \r
835      * Constant for date pattern with year, abbreviated month, weekday, \r
836      * and day.\r
837      * @stable ICU 4.0\r
838      */\r
839     public static final String YEAR_ABBR_MONTH_WEEKDAY_DAY = "yMMMEd"; \r
840 \r
841     /** \r
842      * Constant for date pattern with year, month, weekday, and day.\r
843      * @stable ICU 4.0\r
844      */\r
845     public static final String YEAR_MONTH_WEEKDAY_DAY = "yMMMMEEEEd";\r
846 \r
847     /** \r
848      * Constant for date pattern with year, month, and day.\r
849      * @stable ICU 4.0\r
850      */\r
851     public static final String YEAR_MONTH_DAY = "yMMMMd";\r
852 \r
853     /** \r
854      * Constant for date pattern with year, abbreviated month, and day.\r
855      * @stable ICU 4.0\r
856      */\r
857     public static final String YEAR_ABBR_MONTH_DAY = "yMMMd";\r
858 \r
859     /** \r
860      * Constant for date pattern with year, numeric month, and day.\r
861      * @stable ICU 4.0\r
862      */\r
863     public static final String YEAR_NUM_MONTH_DAY = "yMd";\r
864 \r
865     /** \r
866      * Constant for date pattern with numeric month.\r
867      * @stable ICU 4.0\r
868      */\r
869     public static final String NUM_MONTH = "M";\r
870 \r
871     /** \r
872      * Constant for date pattern with abbreviated month.\r
873      * @stable ICU 4.0\r
874      */\r
875     public static final String ABBR_MONTH = "MMM";\r
876 \r
877     /** \r
878      * Constant for date pattern with month.\r
879      * @stable ICU 4.0\r
880      */\r
881     public static final String MONTH = "MMMM";\r
882 \r
883     /** \r
884      * Constant for date pattern with hour, minute, and generic timezone.\r
885      * @stable ICU 4.0\r
886      */\r
887     public static final String HOUR_MINUTE_GENERIC_TZ = "hmv";\r
888 \r
889     /** \r
890      * Constant for date pattern with hour, minute, and timezone.\r
891      * @stable ICU 4.0\r
892      */\r
893     public static final String HOUR_MINUTE_TZ = "hmz";\r
894 \r
895     /** \r
896      * Constant for date pattern with hour.\r
897      * @stable ICU 4.0\r
898      */\r
899     public static final String HOUR = "h";\r
900 \r
901     /** \r
902      * Constant for date pattern with hour and generic timezone.\r
903      * @stable ICU 4.0\r
904      */\r
905     public static final String HOUR_GENERIC_TZ = "hv";\r
906 \r
907     /** \r
908      * Constant for date pattern with hour and timezone.\r
909      * @stable ICU 4.0\r
910      */\r
911     public static final String HOUR_TZ = "hz";\r
912 \r
913     /**\r
914      * Gets the time formatter with the default formatting style\r
915      * for the default locale.\r
916      * @return a time formatter.\r
917      * @stable ICU 2.0\r
918      */\r
919     public final static DateFormat getTimeInstance()\r
920     {\r
921         return get(-1, DEFAULT, ULocale.getDefault());\r
922     }\r
923 \r
924     /**\r
925      * Gets the time formatter with the given formatting style\r
926      * for the default locale.\r
927      * @param style the given formatting style. For example,\r
928      * SHORT for "h:mm a" in the US locale.\r
929      * @return a time formatter.\r
930      * @stable ICU 2.0\r
931      */\r
932     public final static DateFormat getTimeInstance(int style)\r
933     {\r
934         return get(-1, style, ULocale.getDefault());\r
935     }\r
936 \r
937     /**\r
938      * Gets the time formatter with the given formatting style\r
939      * for the given locale.\r
940      * @param style the given formatting style. For example,\r
941      * SHORT for "h:mm a" in the US locale.\r
942      * @param aLocale the given locale.\r
943      * @return a time formatter.\r
944      * @stable ICU 2.0\r
945      */\r
946     public final static DateFormat getTimeInstance(int style,\r
947                                                  Locale aLocale)\r
948     {\r
949         return get(-1, style, ULocale.forLocale(aLocale));\r
950     }\r
951 \r
952     /**\r
953      * Gets the time formatter with the given formatting style\r
954      * for the given locale.\r
955      * @param style the given formatting style. For example,\r
956      * SHORT for "h:mm a" in the US locale.\r
957      * @param locale the given ulocale.\r
958      * @return a time formatter.\r
959      * @stable ICU 3.2\r
960      */\r
961     public final static DateFormat getTimeInstance(int style,\r
962                                                  ULocale locale)\r
963     {\r
964         return get(-1, style, locale);\r
965     }\r
966 \r
967     /**\r
968      * Gets the date formatter with the default formatting style\r
969      * for the default locale.\r
970      * @return a date formatter.\r
971      * @stable ICU 2.0\r
972      */\r
973     public final static DateFormat getDateInstance()\r
974     {\r
975         return get(DEFAULT, -1, ULocale.getDefault());\r
976     }\r
977 \r
978     /**\r
979      * Gets the date formatter with the given formatting style\r
980      * for the default locale.\r
981      * @param style the given formatting style. For example,\r
982      * SHORT for "M/d/yy" in the US locale.\r
983      * @return a date formatter.\r
984      * @stable ICU 2.0\r
985      */\r
986     public final static DateFormat getDateInstance(int style)\r
987     {\r
988         return get(style, -1, ULocale.getDefault());\r
989     }\r
990 \r
991     /**\r
992      * Gets the date formatter with the given formatting style\r
993      * for the given locale.\r
994      * @param style the given formatting style. For example,\r
995      * SHORT for "M/d/yy" in the US locale.\r
996      * @param aLocale the given locale.\r
997      * @return a date formatter.\r
998      * @stable ICU 2.0\r
999      */\r
1000     public final static DateFormat getDateInstance(int style,\r
1001                                                  Locale aLocale)\r
1002     {\r
1003         return get(style, -1, ULocale.forLocale(aLocale));\r
1004     }\r
1005 \r
1006     /**\r
1007      * Gets the date formatter with the given formatting style\r
1008      * for the given locale.\r
1009      * @param style the given formatting style. For example,\r
1010      * SHORT for "M/d/yy" in the US locale.\r
1011      * @param locale the given ulocale.\r
1012      * @return a date formatter.\r
1013      * @stable ICU 3.2\r
1014      */\r
1015     public final static DateFormat getDateInstance(int style,\r
1016                                                  ULocale locale)\r
1017     {\r
1018         return get(style, -1, locale);\r
1019     }\r
1020 \r
1021     /**\r
1022      * Gets the date/time formatter with the default formatting style\r
1023      * for the default locale.\r
1024      * @return a date/time formatter.\r
1025      * @stable ICU 2.0\r
1026      */\r
1027     public final static DateFormat getDateTimeInstance()\r
1028     {\r
1029         return get(DEFAULT, DEFAULT, ULocale.getDefault());\r
1030     }\r
1031 \r
1032     /**\r
1033      * Gets the date/time formatter with the given date and time\r
1034      * formatting styles for the default locale.\r
1035      * @param dateStyle the given date formatting style. For example,\r
1036      * SHORT for "M/d/yy" in the US locale.\r
1037      * @param timeStyle the given time formatting style. For example,\r
1038      * SHORT for "h:mm a" in the US locale.\r
1039      * @return a date/time formatter.\r
1040      * @stable ICU 2.0\r
1041      */\r
1042     public final static DateFormat getDateTimeInstance(int dateStyle,\r
1043                                                        int timeStyle)\r
1044     {\r
1045         return get(dateStyle, timeStyle, ULocale.getDefault());\r
1046     }\r
1047 \r
1048     /**\r
1049      * Gets the date/time formatter with the given formatting styles\r
1050      * for the given locale.\r
1051      * @param dateStyle the given date formatting style.\r
1052      * @param timeStyle the given time formatting style.\r
1053      * @param aLocale the given locale.\r
1054      * @return a date/time formatter.\r
1055      * @stable ICU 2.0\r
1056      */\r
1057     public final static DateFormat\r
1058         getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale)\r
1059     {\r
1060         return get(dateStyle, timeStyle, ULocale.forLocale(aLocale));\r
1061     }\r
1062 \r
1063     /**\r
1064      * Gets the date/time formatter with the given formatting styles\r
1065      * for the given locale.\r
1066      * @param dateStyle the given date formatting style.\r
1067      * @param timeStyle the given time formatting style.\r
1068      * @param locale the given ulocale.\r
1069      * @return a date/time formatter.\r
1070      * @stable ICU 3.2\r
1071      */\r
1072     public final static DateFormat\r
1073         getDateTimeInstance(int dateStyle, int timeStyle, ULocale locale)\r
1074     {\r
1075         return get(dateStyle, timeStyle, locale);\r
1076     }\r
1077 \r
1078     /**\r
1079      * Get a default date/time formatter that uses the SHORT style for both the\r
1080      * date and the time.\r
1081      * @stable ICU 2.0\r
1082      */\r
1083     public final static DateFormat getInstance() {\r
1084         return getDateTimeInstance(SHORT, SHORT);\r
1085     }\r
1086 \r
1087     /**\r
1088      * Gets the set of locales for which DateFormats are installed.\r
1089      * @return the set of locales for which DateFormats are installed.\r
1090      * @stable ICU 2.0\r
1091      */\r
1092     public static Locale[] getAvailableLocales()\r
1093     {\r
1094         return ICUResourceBundle.getAvailableLocales(ICUResourceBundle.ICU_BASE_NAME);\r
1095     }\r
1096 \r
1097     /**\r
1098      * Gets the set of locales for which DateFormats are installed.\r
1099      * @return the set of locales for which DateFormats are installed.\r
1100      * @draft ICU 3.2 (retain)\r
1101      * @provisional This API might change or be removed in a future release.\r
1102      */\r
1103     public static ULocale[] getAvailableULocales()\r
1104     {\r
1105         return ICUResourceBundle.getAvailableULocales(ICUResourceBundle.ICU_BASE_NAME);\r
1106     }\r
1107 \r
1108     /**\r
1109      * Set the calendar to be used by this date format.  Initially, the default\r
1110      * calendar for the specified or default locale is used.\r
1111      * @param newCalendar the new Calendar to be used by the date format\r
1112      * @stable ICU 2.0\r
1113      */\r
1114     public void setCalendar(Calendar newCalendar)\r
1115     {\r
1116         this.calendar = newCalendar;\r
1117     }\r
1118 \r
1119     /**\r
1120      * Gets the calendar associated with this date/time formatter.\r
1121      * @return the calendar associated with this date/time formatter.\r
1122      * @stable ICU 2.0\r
1123      */\r
1124     public Calendar getCalendar()\r
1125     {\r
1126         return calendar;\r
1127     }\r
1128 \r
1129     /**\r
1130      * Allows you to set the number formatter.\r
1131      * @param newNumberFormat the given new NumberFormat.\r
1132      * @stable ICU 2.0\r
1133      */\r
1134     public void setNumberFormat(NumberFormat newNumberFormat)\r
1135     {\r
1136         this.numberFormat = newNumberFormat;\r
1137         /*In order to parse String like "11.10.2001" to DateTime correctly \r
1138           in Locale("fr","CH") [Richard/GCL]\r
1139         */\r
1140         this.numberFormat.setParseIntegerOnly(true);\r
1141     }\r
1142 \r
1143     /**\r
1144      * Gets the number formatter which this date/time formatter uses to\r
1145      * format and parse a time.\r
1146      * @return the number formatter which this date/time formatter uses.\r
1147      * @stable ICU 2.0\r
1148      */\r
1149     public NumberFormat getNumberFormat()\r
1150     {\r
1151         return numberFormat;\r
1152     }\r
1153 \r
1154     /**\r
1155      * Sets the time zone for the calendar of this DateFormat object.\r
1156      * @param zone the given new time zone.\r
1157      * @stable ICU 2.0\r
1158      */\r
1159     public void setTimeZone(TimeZone zone)\r
1160     {\r
1161         calendar.setTimeZone(zone);\r
1162     }\r
1163 \r
1164     /**\r
1165      * Gets the time zone.\r
1166      * @return the time zone associated with the calendar of DateFormat.\r
1167      * @stable ICU 2.0\r
1168      */\r
1169     public TimeZone getTimeZone()\r
1170     {\r
1171         return calendar.getTimeZone();\r
1172     }\r
1173 \r
1174     /**\r
1175      * Specify whether or not date/time parsing is to be lenient.  With\r
1176      * lenient parsing, the parser may use heuristics to interpret inputs that\r
1177      * do not precisely match this object's format.  With strict parsing,\r
1178      * inputs must match this object's format.\r
1179      * @param lenient when true, parsing is lenient\r
1180      * @see com.ibm.icu.util.Calendar#setLenient\r
1181      * @stable ICU 2.0\r
1182      */\r
1183     public void setLenient(boolean lenient)\r
1184     {\r
1185         calendar.setLenient(lenient);\r
1186     }\r
1187 \r
1188     /**\r
1189      * Tell whether date/time parsing is to be lenient.\r
1190      * @stable ICU 2.0\r
1191      */\r
1192     public boolean isLenient()\r
1193     {\r
1194         return calendar.isLenient();\r
1195     }\r
1196 \r
1197     /**\r
1198      * Overrides hashCode\r
1199      * @stable ICU 2.0\r
1200      */\r
1201     ///CLOVER:OFF\r
1202     // turn off code coverage since all subclasses override this\r
1203     public int hashCode() {\r
1204         return numberFormat.hashCode();\r
1205         // just enough fields for a reasonable distribution\r
1206     }\r
1207     ///CLOVER:ON\r
1208 \r
1209     /**\r
1210      * Overrides equals\r
1211      * @stable ICU 2.0\r
1212      */\r
1213     public boolean equals(Object obj) {\r
1214         if (this == obj) return true;\r
1215         if (obj == null || getClass() != obj.getClass()) return false;\r
1216         DateFormat other = (DateFormat) obj;\r
1217         return (calendar.isEquivalentTo(other.calendar) &&\r
1218                 numberFormat.equals(other.numberFormat));\r
1219     }\r
1220 \r
1221     /**\r
1222      * Overrides Cloneable\r
1223      * @stable ICU 2.0\r
1224      */\r
1225     public Object clone()\r
1226     {\r
1227         DateFormat other = (DateFormat) super.clone();\r
1228         other.calendar = (Calendar) calendar.clone();\r
1229         other.numberFormat = (NumberFormat) numberFormat.clone();\r
1230         return other;\r
1231     }\r
1232 \r
1233     /**\r
1234      * Creates a DateFormat with the given time and/or date style in the given\r
1235      * locale.\r
1236      * @param dateStyle a value from 0 to 3 indicating the time format,\r
1237      * or -1 to indicate no date\r
1238      * @param timeStyle a value from 0 to 3 indicating the time format,\r
1239      * or -1 to indicate no time\r
1240      * @param loc the locale for the format\r
1241      */\r
1242     private static DateFormat get(int dateStyle, int timeStyle, ULocale loc) {\r
1243         if((timeStyle != -1 && (timeStyle & RELATIVE)>0) || (dateStyle != -1 && (dateStyle & RELATIVE)>0)) {\r
1244             RelativeDateFormat r = new RelativeDateFormat(timeStyle, dateStyle /* offset? */, loc);\r
1245             return r;\r
1246         }\r
1247     \r
1248         if (timeStyle < -1 || timeStyle > 3) {\r
1249             throw new IllegalArgumentException("Illegal time style " + timeStyle);\r
1250         }\r
1251         if (dateStyle < -1 || dateStyle > 3) {\r
1252             throw new IllegalArgumentException("Illegal date style " + dateStyle);\r
1253         }\r
1254         try {\r
1255             Calendar cal = Calendar.getInstance(loc);\r
1256             DateFormat result = cal.getDateTimeFormat(dateStyle, timeStyle, loc);\r
1257             result.setLocale(cal.getLocale(ULocale.VALID_LOCALE),\r
1258                  cal.getLocale(ULocale.ACTUAL_LOCALE));\r
1259             return result;\r
1260         } catch (MissingResourceException e) {\r
1261             ///CLOVER:OFF\r
1262             // coverage requires separate run with no data, so skip\r
1263             return new SimpleDateFormat("M/d/yy h:mm a");\r
1264             ///CLOVER:ON\r
1265         }\r
1266     }\r
1267 \r
1268     /**\r
1269      * Create a new date format.\r
1270      * @stable ICU 2.0\r
1271      */\r
1272     protected DateFormat() {}\r
1273 \r
1274     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
1275 \r
1276     //-------------------------------------------------------------------------\r
1277     // Public static interface for creating custon DateFormats for different\r
1278     // types of Calendars.\r
1279     //-------------------------------------------------------------------------\r
1280     \r
1281     /**\r
1282      * Create a {@link DateFormat} object that can be used to format dates in\r
1283      * the calendar system specified by <code>cal</code>.\r
1284      * <p>\r
1285      * @param cal   The calendar system for which a date format is desired.\r
1286      *\r
1287      * @param dateStyle The type of date format desired.  This can be\r
1288      *              {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},\r
1289      *              etc.\r
1290      *\r
1291      * @param locale The locale for which the date format is desired.\r
1292      * @stable ICU 2.0\r
1293      */\r
1294     static final public DateFormat getDateInstance(Calendar cal, int dateStyle, Locale locale)\r
1295     {\r
1296         return getDateTimeInstance(cal, dateStyle, -1, ULocale.forLocale(locale));\r
1297     }\r
1298     \r
1299     /**\r
1300      * Create a {@link DateFormat} object that can be used to format dates in\r
1301      * the calendar system specified by <code>cal</code>.\r
1302      * <p>\r
1303      * @param cal   The calendar system for which a date format is desired.\r
1304      *\r
1305      * @param dateStyle The type of date format desired.  This can be\r
1306      *              {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},\r
1307      *              etc.\r
1308      *\r
1309      * @param locale The locale for which the date format is desired.\r
1310      * @stable ICU 3.2\r
1311      */\r
1312     static final public DateFormat getDateInstance(Calendar cal, int dateStyle, ULocale locale)\r
1313     {\r
1314         return getDateTimeInstance(cal, dateStyle, -1, locale);\r
1315     }\r
1316     \r
1317     /**\r
1318      * Create a {@link DateFormat} object that can be used to format times in\r
1319      * the calendar system specified by <code>cal</code>.\r
1320      * <p>\r
1321      * <b>Note:</b> When this functionality is moved into the core JDK, this method\r
1322      * will probably be replaced by a new overload of {@link DateFormat#getInstance}.\r
1323      * <p>\r
1324      * @param cal   The calendar system for which a time format is desired.\r
1325      *\r
1326      * @param timeStyle The type of time format desired.  This can be\r
1327      *              {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},\r
1328      *              etc.\r
1329      *\r
1330      * @param locale The locale for which the time format is desired.\r
1331      *\r
1332      * @see DateFormat#getTimeInstance\r
1333      * @stable ICU 2.0\r
1334      */\r
1335     static final public DateFormat getTimeInstance(Calendar cal, int timeStyle, Locale locale)\r
1336     {\r
1337         return getDateTimeInstance(cal, -1, timeStyle, ULocale.forLocale(locale));\r
1338     }\r
1339     \r
1340     /**\r
1341      * Create a {@link DateFormat} object that can be used to format times in\r
1342      * the calendar system specified by <code>cal</code>.\r
1343      * <p>\r
1344      * <b>Note:</b> When this functionality is moved into the core JDK, this method\r
1345      * will probably be replaced by a new overload of {@link DateFormat#getInstance}.\r
1346      * <p>\r
1347      * @param cal   The calendar system for which a time format is desired.\r
1348      *\r
1349      * @param timeStyle The type of time format desired.  This can be\r
1350      *              {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},\r
1351      *              etc.\r
1352      *\r
1353      * @param locale The locale for which the time format is desired.\r
1354      *\r
1355      * @see DateFormat#getTimeInstance\r
1356      * @stable ICU 3.2\r
1357      */\r
1358     static final public DateFormat getTimeInstance(Calendar cal, int timeStyle, ULocale locale)\r
1359     {\r
1360         return getDateTimeInstance(cal, -1, timeStyle, locale);\r
1361     }\r
1362     \r
1363     /**\r
1364      * Create a {@link DateFormat} object that can be used to format dates and times in\r
1365      * the calendar system specified by <code>cal</code>.\r
1366      * <p>\r
1367      * <b>Note:</b> When this functionality is moved into the core JDK, this method\r
1368      * will probably be replaced by a new overload of {@link DateFormat#getInstance}.\r
1369      * <p>\r
1370      * @param cal   The calendar system for which a date/time format is desired.\r
1371      *\r
1372      * @param dateStyle The type of date format desired.  This can be\r
1373      *              {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},\r
1374      *              etc.\r
1375      *\r
1376      * @param timeStyle The type of time format desired.  This can be\r
1377      *              {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},\r
1378      *              etc.\r
1379      *\r
1380      * @param locale The locale for which the date/time format is desired.\r
1381      *\r
1382      * @see DateFormat#getDateTimeInstance\r
1383      * @stable ICU 2.0\r
1384      */\r
1385     static final public DateFormat getDateTimeInstance(Calendar cal, int dateStyle,\r
1386                                                  int timeStyle, Locale locale)\r
1387     {\r
1388         return cal.getDateTimeFormat(dateStyle, timeStyle, ULocale.forLocale(locale));\r
1389     }\r
1390 \r
1391     /**\r
1392      * Create a {@link DateFormat} object that can be used to format dates and times in\r
1393      * the calendar system specified by <code>cal</code>.\r
1394      * <p>\r
1395      * <b>Note:</b> When this functionality is moved into the core JDK, this method\r
1396      * will probably be replaced by a new overload of {@link DateFormat#getInstance}.\r
1397      * <p>\r
1398      * @param cal   The calendar system for which a date/time format is desired.\r
1399      *\r
1400      * @param dateStyle The type of date format desired.  This can be\r
1401      *              {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},\r
1402      *              etc.\r
1403      *\r
1404      * @param timeStyle The type of time format desired.  This can be\r
1405      *              {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},\r
1406      *              etc.\r
1407      *\r
1408      * @param locale The locale for which the date/time format is desired.\r
1409      *\r
1410      * @see DateFormat#getDateTimeInstance\r
1411      * @stable ICU 3.2\r
1412      */\r
1413     static final public DateFormat getDateTimeInstance(Calendar cal, int dateStyle,\r
1414                                                  int timeStyle, ULocale locale)\r
1415     {\r
1416         return cal.getDateTimeFormat(dateStyle, timeStyle, locale);\r
1417     }\r
1418 \r
1419     /**\r
1420      * Convenience overload\r
1421      * @stable ICU 2.0\r
1422      */\r
1423     static final public DateFormat getInstance(Calendar cal, Locale locale) {\r
1424         return getDateTimeInstance(cal, SHORT, SHORT, ULocale.forLocale(locale));\r
1425     }\r
1426 \r
1427     /**\r
1428      * Convenience overload\r
1429      * @stable ICU 3.2\r
1430      * @provisional This API might change or be removed in a future release.\r
1431      */\r
1432     static final public DateFormat getInstance(Calendar cal, ULocale locale) {\r
1433         return getDateTimeInstance(cal, SHORT, SHORT, locale);\r
1434     }\r
1435 \r
1436     /**\r
1437      * Convenience overload\r
1438      * @stable ICU 2.0\r
1439      */\r
1440     static final public DateFormat getInstance(Calendar cal) {\r
1441         return getInstance(cal, ULocale.getDefault());\r
1442     }\r
1443 \r
1444     /**\r
1445      * Convenience overload\r
1446      * @stable ICU 2.0\r
1447      */\r
1448     static final public DateFormat getDateInstance(Calendar cal, int dateStyle) {\r
1449         return getDateInstance(cal, dateStyle, ULocale.getDefault());\r
1450     }\r
1451 \r
1452     /**\r
1453      * Convenience overload\r
1454      * @stable ICU 2.0\r
1455      */\r
1456     static final public DateFormat getTimeInstance(Calendar cal, int timeStyle) {\r
1457         return getTimeInstance(cal, timeStyle, ULocale.getDefault());\r
1458     }\r
1459 \r
1460     /**\r
1461      * Convenience overload\r
1462      * @stable ICU 2.0\r
1463      */\r
1464     static final public DateFormat getDateTimeInstance(Calendar cal, int dateStyle, int timeStyle) {\r
1465         return getDateTimeInstance(cal, dateStyle, timeStyle, ULocale.getDefault());\r
1466     }\r
1467 \r
1468     /**\r
1469      * Convenience overload\r
1470      * @stable ICU 4.0\r
1471      */\r
1472     public final static DateFormat getPatternInstance(String pattern) {\r
1473         return getPatternInstance(pattern, ULocale.getDefault());\r
1474     }\r
1475 \r
1476     /**\r
1477      * Convenience overload\r
1478      * @stable ICU 4.0\r
1479      */\r
1480     public final static DateFormat getPatternInstance(String pattern, Locale locale) {\r
1481         return getPatternInstance(pattern, ULocale.forLocale(locale));\r
1482     }\r
1483 \r
1484     /**\r
1485      * Create a {@link DateFormat} object that can be used to format dates and times in\r
1486      * the given locale.\r
1487      * <p>\r
1488      * <b>Note:</b> When this functionality is moved into the core JDK, this method\r
1489      * will probably be replaced by a new overload of {@link DateFormat#getInstance}.\r
1490      * <p>\r
1491      *\r
1492      * @param pattern The pattern that selects the fields to be formatted. (Uses the \r
1493      *              {@link DateTimePatternGenerator}.) This can be {@link DateFormat#ABBR_MONTH}, \r
1494      *              {@link DateFormat#MONTH_WEEKDAY_DAY}, etc.\r
1495      *\r
1496      * @param locale The locale for which the date/time format is desired.\r
1497      *\r
1498      * @stable ICU 4.0\r
1499      */\r
1500     public final static DateFormat getPatternInstance(String pattern, ULocale locale) {\r
1501         DateTimePatternGenerator generator = DateTimePatternGenerator.getInstance(locale);\r
1502         final String bestPattern = generator.getBestPattern(pattern);\r
1503         return new SimpleDateFormat(bestPattern, locale);\r
1504     }\r
1505 \r
1506     /**\r
1507      * Convenience overload\r
1508      * @stable ICU 4.0\r
1509      */\r
1510     public final static DateFormat getPatternInstance(Calendar cal, String pattern, Locale locale) {\r
1511         return getPatternInstance(cal, pattern, ULocale.forLocale(locale));\r
1512     }\r
1513 \r
1514     /**\r
1515      * Create a {@link DateFormat} object that can be used to format dates and times in\r
1516      * the calendar system specified by <code>cal</code>.\r
1517      * <p>\r
1518      * <b>Note:</b> When this functionality is moved into the core JDK, this method\r
1519      * will probably be replaced by a new overload of {@link DateFormat#getInstance}.\r
1520      * <p>\r
1521      * @param cal   The calendar system for which a date/time format is desired.\r
1522      *\r
1523      * @param pattern The pattern that selects the fields to be formatted. (Uses the \r
1524      *              {@link DateTimePatternGenerator}.)  This can be\r
1525      *              {@link DateFormat#ABBR_MONTH}, {@link DateFormat#MONTH_WEEKDAY_DAY},\r
1526      *              etc.\r
1527      *\r
1528      * @param locale The locale for which the date/time format is desired.\r
1529      *\r
1530      * @stable ICU 4.0\r
1531      */\r
1532     public final static DateFormat getPatternInstance(Calendar cal, String pattern, ULocale locale) {\r
1533         DateTimePatternGenerator generator = DateTimePatternGenerator.getInstance(locale);\r
1534         final String bestPattern = generator.getBestPattern(pattern);\r
1535         SimpleDateFormat format = new SimpleDateFormat(bestPattern, locale);\r
1536         format.setCalendar(cal);\r
1537         return format;\r
1538     }\r
1539 \r
1540 //#if defined(FOUNDATION10) || defined(J2SE13)\r
1541 //#else\r
1542     /**\r
1543      * The instances of this inner class are used as attribute keys and values\r
1544      * in AttributedCharacterIterator that\r
1545      * DateFormat.formatToCharacterIterator() method returns.\r
1546      * <p>\r
1547      * There is no public constructor to this class, the only instances are the\r
1548      * constants defined here.\r
1549      * <p>\r
1550      * @stable ICU 3.8\r
1551      */\r
1552     public static class Field extends Format.Field {\r
1553 \r
1554         private static final long serialVersionUID = -3627456821000730829L;\r
1555 \r
1556         // Max number of calendar fields\r
1557         private static final int CAL_FIELD_COUNT;\r
1558 \r
1559         // Table for mapping calendar field number to DateFormat.Field\r
1560         private static final Field[] CAL_FIELDS;\r
1561  \r
1562         // Map for resolving DateFormat.Field by name\r
1563         private static final Map FIELD_NAME_MAP;\r
1564 \r
1565         static {\r
1566             GregorianCalendar cal = new GregorianCalendar();\r
1567             CAL_FIELD_COUNT = cal.getFieldCount();\r
1568             CAL_FIELDS = new Field[CAL_FIELD_COUNT];\r
1569             FIELD_NAME_MAP = new HashMap(CAL_FIELD_COUNT);\r
1570         }\r
1571 \r
1572         // Java fields -------------------\r
1573 \r
1574         /**\r
1575          * Constant identifying the time of day indicator(am/pm).\r
1576          * @stable ICU 3.8\r
1577          */\r
1578         public static final Field AM_PM = new Field("am pm", Calendar.AM_PM);\r
1579 \r
1580         /**\r
1581          * Constant identifying the day of month field.\r
1582          * @stable ICU 3.8\r
1583          */\r
1584         public static final Field DAY_OF_MONTH = new Field("day of month", Calendar.DAY_OF_MONTH);\r
1585 \r
1586         /**\r
1587          * Constant identifying the day of week field.\r
1588          * @stable ICU 3.8\r
1589          */\r
1590         public static final Field DAY_OF_WEEK = new Field("day of week", Calendar.DAY_OF_WEEK);\r
1591 \r
1592         /**\r
1593          * Constant identifying the day of week in month field.\r
1594          * @stable ICU 3.8\r
1595          */\r
1596         public static final Field DAY_OF_WEEK_IN_MONTH = new Field("day of week in month", Calendar.DAY_OF_WEEK_IN_MONTH);\r
1597 \r
1598         /**\r
1599          * Constant identifying the day of year field.\r
1600          * @stable ICU 3.8\r
1601          */\r
1602         public static final Field DAY_OF_YEAR = new Field("day of year", Calendar.DAY_OF_YEAR);\r
1603 \r
1604         /**\r
1605          * Constant identifying the era field.\r
1606          * @stable ICU 3.8\r
1607          */\r
1608         public static final Field ERA = new Field("era", Calendar.ERA);\r
1609 \r
1610         /**\r
1611          * Constant identifying the hour(0-23) of day field.\r
1612          * @stable ICU 3.8\r
1613          */\r
1614         public static final Field HOUR_OF_DAY0 = new Field("hour of day", Calendar.HOUR_OF_DAY);\r
1615 \r
1616         /**\r
1617          * Constant identifying the hour(1-24) of day field.\r
1618          * @stable ICU 3.8\r
1619          */\r
1620         public static final Field HOUR_OF_DAY1 = new Field("hour of day 1", -1);\r
1621 \r
1622         /**\r
1623          * Constant identifying the hour(0-11) field.\r
1624          * @stable ICU 3.8\r
1625          */\r
1626         public static final Field HOUR0 = new Field("hour", Calendar.HOUR);\r
1627 \r
1628         /**\r
1629          * Constant identifying the hour(1-12) field.\r
1630          * @stable ICU 3.8\r
1631          */\r
1632         public static final Field HOUR1 = new Field("hour 1", -1);\r
1633 \r
1634         /**\r
1635          * Constant identifying the millisecond field.\r
1636          * @stable ICU 3.8\r
1637          */\r
1638         public static final Field MILLISECOND = new Field("millisecond", Calendar.MILLISECOND);\r
1639 \r
1640         /**\r
1641          * Constant identifying the minute field.\r
1642          * @stable ICU 3.8\r
1643          */\r
1644         public static final Field MINUTE = new Field("minute", Calendar.MINUTE);\r
1645 \r
1646         /**\r
1647          * Constant identifying the month field.\r
1648          * @stable ICU 3.8\r
1649          */\r
1650         public static final Field MONTH = new Field("month", Calendar.MONTH);\r
1651 \r
1652         /**\r
1653          * Constant identifying the second field.\r
1654          * @stable ICU 3.8\r
1655          */\r
1656         public static final Field SECOND = new Field("second", Calendar.SECOND);\r
1657 \r
1658         /**\r
1659          * Constant identifying the time zone field.\r
1660          * @stable ICU 3.8\r
1661          */\r
1662         public static final Field TIME_ZONE = new Field("time zone", -1);\r
1663 \r
1664         /**\r
1665          * Constant identifying the week of month field.\r
1666          * @stable ICU 3.8\r
1667          */\r
1668         public static final Field WEEK_OF_MONTH = new Field("week of month", Calendar.WEEK_OF_MONTH);\r
1669 \r
1670         /**\r
1671          * Constant identifying the week of year field.\r
1672          * @stable ICU 3.8\r
1673          */\r
1674         public static final Field WEEK_OF_YEAR = new Field("week of year", Calendar.WEEK_OF_YEAR);\r
1675 \r
1676         /**\r
1677          * Constant identifying the year field.\r
1678          * @stable ICU 3.8\r
1679          */\r
1680         public static final Field YEAR = new Field("year", Calendar.YEAR);\r
1681 \r
1682 \r
1683         // ICU only fields -------------------\r
1684 \r
1685         /**\r
1686          * Constant identifying the local day of week field.\r
1687          * @stable ICU 3.8\r
1688          */\r
1689         public static final Field DOW_LOCAL = new Field("local day of week", Calendar.DOW_LOCAL);\r
1690 \r
1691         /**\r
1692          * Constant identifying the extended year field.\r
1693          * @stable ICU 3.8\r
1694          */\r
1695         public static final Field EXTENDED_YEAR = new Field("extended year", Calendar.EXTENDED_YEAR);\r
1696 \r
1697         /**\r
1698          * Constant identifying the Julian day field.\r
1699          * @stable ICU 3.8\r
1700          */\r
1701         public static final Field JULIAN_DAY = new Field("Julian day", Calendar.JULIAN_DAY);\r
1702 \r
1703         /**\r
1704          * Constant identifying the milliseconds in day field.\r
1705          * @stable ICU 3.8\r
1706          */\r
1707         public static final Field MILLISECONDS_IN_DAY = new Field("milliseconds in day", Calendar.MILLISECONDS_IN_DAY);\r
1708 \r
1709         /**\r
1710          * Constant identifying the year used with week of year field.\r
1711          * @stable ICU 3.8\r
1712          */\r
1713         public static final Field YEAR_WOY = new Field("year for week of year", Calendar.YEAR_WOY);\r
1714 \r
1715         /**\r
1716          * Constant identifying the quarter field.\r
1717          * @stable ICU 3.8\r
1718          */\r
1719         public static final Field QUARTER = new Field("quarter", -1);\r
1720 \r
1721         // Stand alone types are variants for its base types.  So we do not define Field for\r
1722         // them.\r
1723         /*\r
1724         public static final Field STANDALONE_DAY = new Field("stand alone day of week", Calendar.DAY_OF_WEEK);\r
1725         public static final Field STANDALONE_MONTH = new Field("stand alone month", Calendar.MONTH);\r
1726         public static final Field STANDALONE_QUARTER = new Field("stand alone quarter", -1);\r
1727         */\r
1728 \r
1729         // Corresponding calendar field\r
1730         private final int calendarField;\r
1731 \r
1732         /**\r
1733          * Constructs a <code>DateFormat.Field</code> with the given name and\r
1734          * the <code>Calendar</code> field which this attribute represents.  Use -1 for\r
1735          * <code>calendarField</code> if this field does not have a corresponding\r
1736          * <code>Calendar</code> field.\r
1737          * \r
1738          * @param name          Name of the attribute\r
1739          * @param calendarField <code>Calendar</code> field constant\r
1740          * \r
1741          * @stable ICU 3.8\r
1742          */\r
1743         protected Field(String name, int calendarField) {\r
1744             super(name);\r
1745             this.calendarField = calendarField;\r
1746             if (this.getClass() == DateFormat.Field.class) {\r
1747                 FIELD_NAME_MAP.put(name, this);\r
1748                 if (calendarField >= 0 && calendarField < CAL_FIELD_COUNT) {\r
1749                     CAL_FIELDS[calendarField] = this;\r
1750                 }\r
1751             }\r
1752         }\r
1753 \r
1754         /**\r
1755          * Returns the <code>Field</code> constant that corresponds to the <code>\r
1756          * Calendar</code> field <code>calendarField</code>.  If there is no\r
1757          * corresponding <code>Field</code> is available, null is returned.\r
1758          * \r
1759          * @param calendarField <code>Calendar</code> field constant\r
1760          * @return <code>Field</code> associated with the <code>calendarField</code>,\r
1761          * or null if no associated <code>Field</code> is available.\r
1762          * @throws IllegalArgumentException if <code>calendarField</code> is not\r
1763          * a valid <code>Calendar</code> field constant.\r
1764          * \r
1765          * @stable ICU 3.8\r
1766          */\r
1767         public static DateFormat.Field ofCalendarField(int calendarField) {\r
1768             if (calendarField < 0 || calendarField >= CAL_FIELD_COUNT) {\r
1769                 throw new IllegalArgumentException("Calendar field number is out of range");\r
1770             }\r
1771             return CAL_FIELDS[calendarField];\r
1772         }\r
1773         \r
1774         /**\r
1775          * Returns the <code>Calendar</code> field associated with this attribute.\r
1776          * If there is no corresponding <code>Calendar</code> available, this will\r
1777          * return -1.\r
1778          * \r
1779          * @return <code>Calendar</code> constant for this attribute.\r
1780          * \r
1781          * @stable ICU 3.8\r
1782          */\r
1783         public int getCalendarField() {\r
1784             return calendarField;\r
1785         }\r
1786         \r
1787         /**\r
1788          * Resolves instances being deserialized to the predefined constants.\r
1789          * \r
1790          * @throws InvalidObjectException if the constant could not be resolved.\r
1791          * \r
1792          * @stable ICU 3.8\r
1793          */\r
1794         protected Object readResolve() throws InvalidObjectException {\r
1795             ///CLOVER:OFF\r
1796             if (this.getClass() != DateFormat.Field.class) {\r
1797                 throw new InvalidObjectException("A subclass of DateFormat.Field must implement readResolve.");\r
1798             }\r
1799             ///CLOVER:ON\r
1800             Object o = FIELD_NAME_MAP.get(this.getName());\r
1801             ///CLOVER:OFF\r
1802             if (o == null) {\r
1803                 throw new InvalidObjectException("Unknown attribute name.");\r
1804             }\r
1805             ///CLOVER:ON\r
1806             return o;\r
1807         }\r
1808     }\r
1809 //#endif\r
1810     \r
1811 }\r