- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / icu / source / i18n / unicode / datefmt.h
1 /*
2  ********************************************************************************
3  *   Copyright (C) 1997-2010, International Business Machines
4  *   Corporation and others.  All Rights Reserved.
5  ********************************************************************************
6  *
7  * File DATEFMT.H
8  *
9  * Modification History:
10  *
11  *   Date        Name        Description
12  *   02/19/97    aliu        Converted from java.
13  *   04/01/97    aliu        Added support for centuries.
14  *   07/23/98    stephen     JDK 1.2 sync
15  *   11/15/99    weiv        Added support for week of year/day of week formatting
16  ********************************************************************************
17  */
18
19 #ifndef DATEFMT_H
20 #define DATEFMT_H
21
22 #include "unicode/utypes.h"
23
24 #if !UCONFIG_NO_FORMATTING
25
26 #include "unicode/udat.h"
27 #include "unicode/calendar.h"
28 #include "unicode/numfmt.h"
29 #include "unicode/format.h"
30 #include "unicode/locid.h"
31
32 /**
33  * \file
34  * \brief C++ API: Abstract class for converting dates.
35  */
36
37 U_NAMESPACE_BEGIN
38
39 class TimeZone;
40 class DateTimePatternGenerator;
41
42 /**
43  * DateFormat is an abstract class for a family of classes that convert dates and
44  * times from their internal representations to textual form and back again in a
45  * language-independent manner. Converting from the internal representation (milliseconds
46  * since midnight, January 1, 1970) to text is known as "formatting," and converting
47  * from text to millis is known as "parsing."  We currently define only one concrete
48  * subclass of DateFormat: SimpleDateFormat, which can handle pretty much all normal
49  * date formatting and parsing actions.
50  * <P>
51  * DateFormat helps you to format and parse dates for any locale. Your code can
52  * be completely independent of the locale conventions for months, days of the
53  * week, or even the calendar format: lunar vs. solar.
54  * <P>
55  * To format a date for the current Locale, use one of the static factory
56  * methods:
57  * <pre>
58  * \code
59  *      DateFormat* dfmt = DateFormat::createDateInstance();
60  *      UDate myDate = Calendar::getNow();
61  *      UnicodeString myString;
62  *      myString = dfmt->format( myDate, myString );
63  * \endcode
64  * </pre>
65  * If you are formatting multiple numbers, it is more efficient to get the
66  * format and use it multiple times so that the system doesn't have to fetch the
67  * information about the local language and country conventions multiple times.
68  * <pre>
69  * \code
70  *      DateFormat* df = DateFormat::createDateInstance();
71  *      UnicodeString myString;
72  *      UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values
73  *      for (int32_t i = 0; i < 3; ++i) {
74  *          myString.remove();
75  *          cout << df->format( myDateArr[i], myString ) << endl;
76  *      }
77  * \endcode
78  * </pre>
79  * To get specific fields of a date, you can use UFieldPosition to
80  * get specific fields.
81  * <pre>
82  * \code
83  *      DateFormat* dfmt = DateFormat::createDateInstance();
84  *      FieldPosition pos(DateFormat::YEAR_FIELD);
85  *      UnicodeString myString;
86  *      myString = dfmt->format( myDate, myString );
87  *      cout << myString << endl;
88  *      cout << pos.getBeginIndex() << "," << pos. getEndIndex() << endl;
89  * \endcode
90  * </pre>
91  * To format a date for a different Locale, specify it in the call to
92  * createDateInstance().
93  * <pre>
94  * \code
95  *       DateFormat* df =
96  *           DateFormat::createDateInstance( DateFormat::SHORT, Locale::getFrance());
97  * \endcode
98  * </pre>
99  * You can use a DateFormat to parse also.
100  * <pre>
101  * \code
102  *       UErrorCode status = U_ZERO_ERROR;
103  *       UDate myDate = df->parse(myString, status);
104  * \endcode
105  * </pre>
106  * Use createDateInstance() to produce the normal date format for that country.
107  * There are other static factory methods available. Use createTimeInstance()
108  * to produce the normal time format for that country. Use createDateTimeInstance()
109  * to produce a DateFormat that formats both date and time. You can pass in
110  * different options to these factory methods to control the length of the
111  * result; from SHORT to MEDIUM to LONG to FULL. The exact result depends on the
112  * locale, but generally:
113  * <ul type=round>
114  *   <li>   SHORT is completely numeric, such as 12/13/52 or 3:30pm
115  *   <li>   MEDIUM is longer, such as Jan 12, 1952
116  *   <li>   LONG is longer, such as January 12, 1952 or 3:30:32pm
117  *   <li>   FULL is pretty completely specified, such as
118  *          Tuesday, April 12, 1952 AD or 3:30:42pm PST.
119  * </ul>
120  * You can also set the time zone on the format if you wish. If you want even
121  * more control over the format or parsing, (or want to give your users more
122  * control), you can try casting the DateFormat you get from the factory methods
123  * to a SimpleDateFormat. This will work for the majority of countries; just
124  * remember to chck getDynamicClassID() before carrying out the cast.
125  * <P>
126  * You can also use forms of the parse and format methods with ParsePosition and
127  * FieldPosition to allow you to
128  * <ul type=round>
129  *   <li>   Progressively parse through pieces of a string.
130  *   <li>   Align any particular field, or find out where it is for selection
131  *          on the screen.
132  * </ul>
133  *
134  * <p><em>User subclasses are not supported.</em> While clients may write
135  * subclasses, such code will not necessarily work and will not be
136  * guaranteed to work stably from release to release.
137  */
138 class U_I18N_API DateFormat : public Format {
139 public:
140
141     /**
142      * Constants for various style patterns. These reflect the order of items in
143      * the DateTimePatterns resource. There are 4 time patterns, 4 date patterns,
144      * the default date-time pattern, and 4 date-time patterns. Each block of 4 values
145      * in the resource occurs in the order full, long, medium, short.
146      * @stable ICU 2.4
147      */
148     enum EStyle
149     {
150         kNone   = -1,
151
152         kFull   = 0,
153         kLong   = 1,
154         kMedium = 2,
155         kShort  = 3,
156
157         kDateOffset   = kShort + 1,
158      // kFull   + kDateOffset = 4
159      // kLong   + kDateOffset = 5
160      // kMedium + kDateOffset = 6
161      // kShort  + kDateOffset = 7
162
163         kDateTime             = 8,
164      // Default DateTime
165
166         kDateTimeOffset = kDateTime + 1,
167      // kFull   + kDateTimeOffset = 9
168      // kLong   + kDateTimeOffset = 10
169      // kMedium + kDateTimeOffset = 11
170      // kShort  + kDateTimeOffset = 12
171
172         // relative dates
173         kRelative = (1 << 7),
174
175         kFullRelative = (kFull | kRelative),
176
177         kLongRelative = kLong | kRelative,
178
179         kMediumRelative = kMedium | kRelative,
180
181         kShortRelative = kShort | kRelative,
182
183
184         kDefault      = kMedium,
185
186
187
188     /**
189      * These constants are provided for backwards compatibility only.
190      * Please use the C++ style constants defined above.
191      */
192         FULL        = kFull,
193         LONG        = kLong,
194         MEDIUM        = kMedium,
195         SHORT        = kShort,
196         DEFAULT        = kDefault,
197         DATE_OFFSET    = kDateOffset,
198         NONE        = kNone,
199         DATE_TIME    = kDateTime
200     };
201
202     /**
203      * Destructor.
204      * @stable ICU 2.0
205      */
206     virtual ~DateFormat();
207
208     /**
209      * Equality operator.  Returns true if the two formats have the same behavior.
210      * @stable ICU 2.0
211      */
212     virtual UBool operator==(const Format&) const;
213
214
215     using Format::format;
216
217     /**
218      * Format an object to produce a string. This method handles Formattable
219      * objects with a UDate type. If a the Formattable object type is not a Date,
220      * then it returns a failing UErrorCode.
221      *
222      * @param obj       The object to format. Must be a Date.
223      * @param appendTo  Output parameter to receive result.
224      *                  Result is appended to existing contents.
225      * @param pos       On input: an alignment field, if desired.
226      *                  On output: the offsets of the alignment field.
227      * @param status    Output param filled with success/failure status.
228      * @return          Reference to 'appendTo' parameter.
229      * @stable ICU 2.0
230      */
231     virtual UnicodeString& format(const Formattable& obj,
232                                   UnicodeString& appendTo,
233                                   FieldPosition& pos,
234                                   UErrorCode& status) const;
235
236     /**
237      * Format an object to produce a string. This method handles Formattable
238      * objects with a UDate type. If a the Formattable object type is not a Date,
239      * then it returns a failing UErrorCode.
240      *
241      * @param obj       The object to format. Must be a Date.
242      * @param appendTo  Output parameter to receive result.
243      *                  Result is appended to existing contents.
244      * @param posIter   On return, can be used to iterate over positions
245      *                  of fields generated by this format call.  Field values
246      *                  are defined in UDateFormatField.  Can be NULL.
247      * @param status    Output param filled with success/failure status.
248      * @return          Reference to 'appendTo' parameter.
249      * @stable ICU 4.4
250      */
251     virtual UnicodeString& format(const Formattable& obj,
252                                   UnicodeString& appendTo,
253                                   FieldPositionIterator* posIter,
254                                   UErrorCode& status) const;
255     /**
256      * Formats a date into a date/time string. This is an abstract method which
257      * concrete subclasses must implement.
258      * <P>
259      * On input, the FieldPosition parameter may have its "field" member filled with
260      * an enum value specifying a field.  On output, the FieldPosition will be filled
261      * in with the text offsets for that field.
262      * <P> For example, given a time text
263      * "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition.field is
264      * UDAT_YEAR_FIELD, the offsets fieldPosition.beginIndex and
265      * statfieldPositionus.getEndIndex will be set to 0 and 4, respectively.
266      * <P> Notice
267      * that if the same time field appears more than once in a pattern, the status will
268      * be set for the first occurence of that time field. For instance,
269      * formatting a UDate to the time string "1 PM PDT (Pacific Daylight Time)"
270      * using the pattern "h a z (zzzz)" and the alignment field
271      * DateFormat::TIMEZONE_FIELD, the offsets fieldPosition.beginIndex and
272      * fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first
273      * occurence of the timezone pattern character 'z'.
274      *
275      * @param cal           Calendar set to the date and time to be formatted
276      *                      into a date/time string.  When the calendar type is
277      *                      different from the internal calendar held by this
278      *                      DateFormat instance, the date and the time zone will
279      *                      be inherited from the input calendar, but other calendar
280      *                      field values will be calculated by the internal calendar.
281      * @param appendTo      Output parameter to receive result.
282      *                      Result is appended to existing contents.
283      * @param fieldPosition On input: an alignment field, if desired (see examples above)
284      *                      On output: the offsets of the alignment field (see examples above)
285      * @return              Reference to 'appendTo' parameter.
286      * @stable ICU 2.1
287      */
288     virtual UnicodeString& format(  Calendar& cal,
289                                     UnicodeString& appendTo,
290                                     FieldPosition& fieldPosition) const = 0;
291
292     /**
293      * Formats a date into a date/time string. Subclasses should implement this method.
294      *
295      * @param cal       Calendar set to the date and time to be formatted
296      *                  into a date/time string.  When the calendar type is
297      *                  different from the internal calendar held by this
298      *                  DateFormat instance, the date and the time zone will
299      *                  be inherited from the input calendar, but other calendar
300      *                  field values will be calculated by the internal calendar.
301      * @param appendTo  Output parameter to receive result.
302      *                  Result is appended to existing contents.
303      * @param posIter   On return, can be used to iterate over positions
304      *                  of fields generated by this format call.  Field values
305      *                  are defined in UDateFormatField.  Can be NULL.
306      * @param status    error status.
307      * @return          Reference to 'appendTo' parameter.
308      * @stable ICU 4.4
309      */
310     virtual UnicodeString& format(Calendar& cal,
311                                   UnicodeString& appendTo,
312                                   FieldPositionIterator* posIter,
313                                   UErrorCode& status) const;
314     /**
315      * Formats a UDate into a date/time string.
316      * <P>
317      * On input, the FieldPosition parameter may have its "field" member filled with
318      * an enum value specifying a field.  On output, the FieldPosition will be filled
319      * in with the text offsets for that field.
320      * <P> For example, given a time text
321      * "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition.field is
322      * UDAT_YEAR_FIELD, the offsets fieldPosition.beginIndex and
323      * statfieldPositionus.getEndIndex will be set to 0 and 4, respectively.
324      * <P> Notice
325      * that if the same time field appears more than once in a pattern, the status will
326      * be set for the first occurence of that time field. For instance,
327      * formatting a UDate to the time string "1 PM PDT (Pacific Daylight Time)"
328      * using the pattern "h a z (zzzz)" and the alignment field
329      * DateFormat::TIMEZONE_FIELD, the offsets fieldPosition.beginIndex and
330      * fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first
331      * occurence of the timezone pattern character 'z'.
332      *
333      * @param date          UDate to be formatted into a date/time string.
334      * @param appendTo      Output parameter to receive result.
335      *                      Result is appended to existing contents.
336      * @param fieldPosition On input: an alignment field, if desired (see examples above)
337      *                      On output: the offsets of the alignment field (see examples above)
338      * @return              Reference to 'appendTo' parameter.
339      * @stable ICU 2.0
340      */
341     UnicodeString& format(  UDate date,
342                             UnicodeString& appendTo,
343                             FieldPosition& fieldPosition) const;
344
345     /**
346      * Formats a UDate into a date/time string.
347      *
348      * @param date      UDate to be formatted into a date/time string.
349      * @param appendTo  Output parameter to receive result.
350      *                  Result is appended to existing contents.
351      * @param posIter   On return, can be used to iterate over positions
352      *                  of fields generated by this format call.  Field values
353      *                  are defined in UDateFormatField.  Can be NULL.
354      * @param status    error status.
355      * @return          Reference to 'appendTo' parameter.
356      * @stable ICU 4.4
357      */
358     UnicodeString& format(UDate date,
359                           UnicodeString& appendTo,
360                           FieldPositionIterator* posIter,
361                           UErrorCode& status) const;
362     /**
363      * Formats a UDate into a date/time string. If there is a problem, you won't
364      * know, using this method. Use the overloaded format() method which takes a
365      * FieldPosition& to detect formatting problems.
366      *
367      * @param date      The UDate value to be formatted into a string.
368      * @param appendTo  Output parameter to receive result.
369      *                  Result is appended to existing contents.
370      * @return          Reference to 'appendTo' parameter.
371      * @stable ICU 2.0
372      */
373     UnicodeString& format(UDate date, UnicodeString& appendTo) const;
374
375     /**
376      * Redeclared Format method.
377      *
378      * @param obj       The object to be formatted into a string.
379      * @param appendTo  Output parameter to receive result.
380      *                  Result is appended to existing contents.
381      * @param status    Output param filled with success/failure status.
382      * @return          Reference to 'appendTo' parameter.
383      * @stable ICU 2.0
384      */
385     UnicodeString& format(const Formattable& obj,
386                           UnicodeString& appendTo,
387                           UErrorCode& status) const;
388
389     /**
390      * Parse a date/time string.
391      *
392      * @param text      The string to be parsed into a UDate value.
393      * @param status    Output param to be set to success/failure code. If
394      *                  'text' cannot be parsed, it will be set to a failure
395      *                  code.
396      * @result          The parsed UDate value, if successful.
397      * @stable ICU 2.0
398      */
399     virtual UDate parse( const UnicodeString& text,
400                         UErrorCode& status) const;
401
402     /**
403      * Parse a date/time string beginning at the given parse position. For
404      * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
405      * that is equivalent to Date(837039928046).
406      * <P>
407      * By default, parsing is lenient: If the input is not in the form used by
408      * this object's format method but can still be parsed as a date, then the
409      * parse succeeds. Clients may insist on strict adherence to the format by
410      * calling setLenient(false).
411      *
412      * @see DateFormat::setLenient(boolean)
413      *
414      * @param text  The date/time string to be parsed
415      * @param cal   a Calendar set to the date and time to be formatted
416      *              into a date/time string.  When the calendar type
417      *              is different from the internal calendar held by this
418      *              DateFormat instance, calendar field values will be
419      *              parsed based on the internal calendar, then the result
420      *              (time in milliseconds and time zone) will be set in
421      *              this calendar.
422      * @param pos   On input, the position at which to start parsing; on
423      *              output, the position at which parsing terminated, or the
424      *              start position if the parse failed.
425      * @return      A valid UDate if the input could be parsed.
426      * @stable ICU 2.1
427      */
428     virtual void parse( const UnicodeString& text,
429                         Calendar& cal,
430                         ParsePosition& pos) const = 0;
431
432     /**
433      * Parse a date/time string beginning at the given parse position. For
434      * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
435      * that is equivalent to Date(837039928046).
436      * <P>
437      * By default, parsing is lenient: If the input is not in the form used by
438      * this object's format method but can still be parsed as a date, then the
439      * parse succeeds. Clients may insist on strict adherence to the format by
440      * calling setLenient(false).
441      *
442      * @see DateFormat::setLenient(boolean)
443      *
444      * @param text  The date/time string to be parsed
445      * @param pos   On input, the position at which to start parsing; on
446      *              output, the position at which parsing terminated, or the
447      *              start position if the parse failed.
448      * @return      A valid UDate if the input could be parsed.
449      * @stable ICU 2.0
450      */
451     UDate parse( const UnicodeString& text,
452                  ParsePosition& pos) const;
453
454     /**
455      * Parse a string to produce an object. This methods handles parsing of
456      * date/time strings into Formattable objects with UDate types.
457      * <P>
458      * Before calling, set parse_pos.index to the offset you want to start
459      * parsing at in the source. After calling, parse_pos.index is the end of
460      * the text you parsed. If error occurs, index is unchanged.
461      * <P>
462      * When parsing, leading whitespace is discarded (with a successful parse),
463      * while trailing whitespace is left as is.
464      * <P>
465      * See Format::parseObject() for more.
466      *
467      * @param source    The string to be parsed into an object.
468      * @param result    Formattable to be set to the parse result.
469      *                  If parse fails, return contents are undefined.
470      * @param parse_pos The position to start parsing at. Upon return
471      *                  this param is set to the position after the
472      *                  last character successfully parsed. If the
473      *                  source is not parsed successfully, this param
474      *                  will remain unchanged.
475      * @return          A newly created Formattable* object, or NULL
476      *                  on failure.  The caller owns this and should
477      *                  delete it when done.
478      * @stable ICU 2.0
479      */
480     virtual void parseObject(const UnicodeString& source,
481                              Formattable& result,
482                              ParsePosition& parse_pos) const;
483
484     /**
485      * Create a default date/time formatter that uses the SHORT style for both
486      * the date and the time.
487      *
488      * @return A date/time formatter which the caller owns.
489      * @stable ICU 2.0
490      */
491     static DateFormat* U_EXPORT2 createInstance(void);
492
493     /**
494      * Creates a time formatter with the given formatting style for the given
495      * locale.
496      *
497      * @param style     The given formatting style. For example,
498      *                  SHORT for "h:mm a" in the US locale. Relative
499      *                  time styles are not currently supported.
500      * @param aLocale   The given locale.
501      * @return          A time formatter which the caller owns.
502      * @stable ICU 2.0
503      */
504     static DateFormat* U_EXPORT2 createTimeInstance(EStyle style = kDefault,
505                                           const Locale& aLocale = Locale::getDefault());
506
507     /**
508      * Creates a date formatter with the given formatting style for the given
509      * const locale.
510      *
511      * @param style     The given formatting style. For example,
512      *                  SHORT for "M/d/yy" in the US locale.
513      * @param aLocale   The given locale.
514      * @return          A date formatter which the caller owns.
515      * @stable ICU 2.0
516      */
517     static DateFormat* U_EXPORT2 createDateInstance(EStyle style = kDefault,
518                                           const Locale& aLocale = Locale::getDefault());
519
520     /**
521      * Creates a date/time formatter with the given formatting styles for the
522      * given locale.
523      *
524      * @param dateStyle The given formatting style for the date portion of the result.
525      *                  For example, SHORT for "M/d/yy" in the US locale.
526      * @param timeStyle The given formatting style for the time portion of the result.
527      *                  For example, SHORT for "h:mm a" in the US locale. Relative
528      *                  time styles are not currently supported.
529      * @param aLocale   The given locale.
530      * @return          A date/time formatter which the caller owns.
531      * @stable ICU 2.0
532      */
533     static DateFormat* U_EXPORT2 createDateTimeInstance(EStyle dateStyle = kDefault,
534                                               EStyle timeStyle = kDefault,
535                                               const Locale& aLocale = Locale::getDefault());
536
537     /**
538      * Gets the set of locales for which DateFormats are installed.
539      * @param count Filled in with the number of locales in the list that is returned.
540      * @return the set of locales for which DateFormats are installed.  The caller
541      *  does NOT own this list and must not delete it.
542      * @stable ICU 2.0
543      */
544     static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
545
546     /**
547      * Returns true if the formatter is set for lenient parsing.
548      * @stable ICU 2.0
549      */
550     virtual UBool isLenient(void) const;
551
552     /**
553      * Specify whether or not date/time parsing is to be lenient. With lenient
554      * parsing, the parser may use heuristics to interpret inputs that do not
555      * precisely match this object's format. With strict parsing, inputs must
556      * match this object's format.
557      *
558      * @param lenient  True specifies date/time interpretation to be lenient.
559      * @see Calendar::setLenient
560      * @stable ICU 2.0
561      */
562     virtual void setLenient(UBool lenient);
563
564     /**
565      * Gets the calendar associated with this date/time formatter.
566      * @return the calendar associated with this date/time formatter.
567      * @stable ICU 2.0
568      */
569     virtual const Calendar* getCalendar(void) const;
570
571     /**
572      * Set the calendar to be used by this date format. Initially, the default
573      * calendar for the specified or default locale is used.  The caller should
574      * not delete the Calendar object after it is adopted by this call.
575      * Adopting a new calendar will change to the default symbols.
576      *
577      * @param calendarToAdopt    Calendar object to be adopted.
578      * @stable ICU 2.0
579      */
580     virtual void adoptCalendar(Calendar* calendarToAdopt);
581
582     /**
583      * Set the calendar to be used by this date format. Initially, the default
584      * calendar for the specified or default locale is used.
585      *
586      * @param newCalendar Calendar object to be set.
587      * @stable ICU 2.0
588      */
589     virtual void setCalendar(const Calendar& newCalendar);
590
591
592     /**
593      * Gets the number formatter which this date/time formatter uses to format
594      * and parse the numeric portions of the pattern.
595      * @return the number formatter which this date/time formatter uses.
596      * @stable ICU 2.0
597      */
598     virtual const NumberFormat* getNumberFormat(void) const;
599
600     /**
601      * Allows you to set the number formatter.  The caller should
602      * not delete the NumberFormat object after it is adopted by this call.
603      * @param formatToAdopt     NumberFormat object to be adopted.
604      * @stable ICU 2.0
605      */
606     virtual void adoptNumberFormat(NumberFormat* formatToAdopt);
607
608     /**
609      * Allows you to set the number formatter.
610      * @param newNumberFormat  NumberFormat object to be set.
611      * @stable ICU 2.0
612      */
613     virtual void setNumberFormat(const NumberFormat& newNumberFormat);
614
615     /**
616      * Returns a reference to the TimeZone used by this DateFormat's calendar.
617      * @return the time zone associated with the calendar of DateFormat.
618      * @stable ICU 2.0
619      */
620     virtual const TimeZone& getTimeZone(void) const;
621
622     /**
623      * Sets the time zone for the calendar of this DateFormat object. The caller
624      * no longer owns the TimeZone object and should not delete it after this call.
625      * @param zoneToAdopt the TimeZone to be adopted.
626      * @stable ICU 2.0
627      */
628     virtual void adoptTimeZone(TimeZone* zoneToAdopt);
629
630     /**
631      * Sets the time zone for the calendar of this DateFormat object.
632      * @param zone the new time zone.
633      * @stable ICU 2.0
634      */
635     virtual void setTimeZone(const TimeZone& zone);
636
637 protected:
638     /**
639      * Default constructor.  Creates a DateFormat with no Calendar or NumberFormat
640      * associated with it.  This constructor depends on the subclasses to fill in
641      * the calendar and numberFormat fields.
642      * @stable ICU 2.0
643      */
644     DateFormat();
645
646     /**
647      * Copy constructor.
648      * @stable ICU 2.0
649      */
650     DateFormat(const DateFormat&);
651
652     /**
653      * Default assignment operator.
654      * @stable ICU 2.0
655      */
656     DateFormat& operator=(const DateFormat&);
657
658     /**
659      * The calendar that DateFormat uses to produce the time field values needed
660      * to implement date/time formatting. Subclasses should generally initialize
661      * this to the default calendar for the locale associated with this DateFormat.
662      * @stable ICU 2.4
663      */
664     Calendar* fCalendar;
665
666     /**
667      * The number formatter that DateFormat uses to format numbers in dates and
668      * times. Subclasses should generally initialize this to the default number
669      * format for the locale associated with this DateFormat.
670      * @stable ICU 2.4
671      */
672     NumberFormat* fNumberFormat;
673
674 private:
675     /**
676      * Gets the date/time formatter with the given formatting styles for the
677      * given locale.
678      * @param dateStyle the given date formatting style.
679      * @param timeStyle the given time formatting style.
680      * @param inLocale the given locale.
681      * @return a date/time formatter, or 0 on failure.
682      */
683     static DateFormat* U_EXPORT2 create(EStyle timeStyle, EStyle dateStyle, const Locale&);
684
685 public:
686     /**
687      * Field selector for FieldPosition for DateFormat fields.
688      * @obsolete ICU 3.4 use UDateFormatField instead, since this API will be
689      * removed in that release
690      */
691     enum EField
692     {
693         // Obsolete; use UDateFormatField instead
694         kEraField = UDAT_ERA_FIELD,
695         kYearField = UDAT_YEAR_FIELD,
696         kMonthField = UDAT_MONTH_FIELD,
697         kDateField = UDAT_DATE_FIELD,
698         kHourOfDay1Field = UDAT_HOUR_OF_DAY1_FIELD,
699         kHourOfDay0Field = UDAT_HOUR_OF_DAY0_FIELD,
700         kMinuteField = UDAT_MINUTE_FIELD,
701         kSecondField = UDAT_SECOND_FIELD,
702         kMillisecondField = UDAT_FRACTIONAL_SECOND_FIELD,
703         kDayOfWeekField = UDAT_DAY_OF_WEEK_FIELD,
704         kDayOfYearField = UDAT_DAY_OF_YEAR_FIELD,
705         kDayOfWeekInMonthField = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
706         kWeekOfYearField = UDAT_WEEK_OF_YEAR_FIELD,
707         kWeekOfMonthField = UDAT_WEEK_OF_MONTH_FIELD,
708         kAmPmField = UDAT_AM_PM_FIELD,
709         kHour1Field = UDAT_HOUR1_FIELD,
710         kHour0Field = UDAT_HOUR0_FIELD,
711         kTimezoneField = UDAT_TIMEZONE_FIELD,
712         kYearWOYField = UDAT_YEAR_WOY_FIELD,
713         kDOWLocalField = UDAT_DOW_LOCAL_FIELD,
714         kExtendedYearField = UDAT_EXTENDED_YEAR_FIELD,
715         kJulianDayField = UDAT_JULIAN_DAY_FIELD,
716         kMillisecondsInDayField = UDAT_MILLISECONDS_IN_DAY_FIELD,
717
718         // Obsolete; use UDateFormatField instead
719         ERA_FIELD = UDAT_ERA_FIELD,
720         YEAR_FIELD = UDAT_YEAR_FIELD,
721         MONTH_FIELD = UDAT_MONTH_FIELD,
722         DATE_FIELD = UDAT_DATE_FIELD,
723         HOUR_OF_DAY1_FIELD = UDAT_HOUR_OF_DAY1_FIELD,
724         HOUR_OF_DAY0_FIELD = UDAT_HOUR_OF_DAY0_FIELD,
725         MINUTE_FIELD = UDAT_MINUTE_FIELD,
726         SECOND_FIELD = UDAT_SECOND_FIELD,
727         MILLISECOND_FIELD = UDAT_FRACTIONAL_SECOND_FIELD,
728         DAY_OF_WEEK_FIELD = UDAT_DAY_OF_WEEK_FIELD,
729         DAY_OF_YEAR_FIELD = UDAT_DAY_OF_YEAR_FIELD,
730         DAY_OF_WEEK_IN_MONTH_FIELD = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
731         WEEK_OF_YEAR_FIELD = UDAT_WEEK_OF_YEAR_FIELD,
732         WEEK_OF_MONTH_FIELD = UDAT_WEEK_OF_MONTH_FIELD,
733         AM_PM_FIELD = UDAT_AM_PM_FIELD,
734         HOUR1_FIELD = UDAT_HOUR1_FIELD,
735         HOUR0_FIELD = UDAT_HOUR0_FIELD,
736         TIMEZONE_FIELD = UDAT_TIMEZONE_FIELD
737     };
738 };
739
740 inline UnicodeString&
741 DateFormat::format(const Formattable& obj,
742                    UnicodeString& appendTo,
743                    UErrorCode& status) const {
744     return Format::format(obj, appendTo, status);
745 }
746 U_NAMESPACE_END
747
748 #endif /* #if !UCONFIG_NO_FORMATTING */
749
750 #endif // _DATEFMT
751 //eof