1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ********************************************************************************
5 * Copyright (C) 1997-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ********************************************************************************
11 * Modification History:
13 * Date Name Description
14 * 02/19/97 aliu Converted from java.
15 * 04/01/97 aliu Added support for centuries.
16 * 07/23/98 stephen JDK 1.2 sync
17 * 11/15/99 weiv Added support for week of year/day of week formatting
18 ********************************************************************************
24 #include "unicode/utypes.h"
26 #if U_SHOW_CPLUSPLUS_API
28 #if !UCONFIG_NO_FORMATTING
30 #include "unicode/udat.h"
31 #include "unicode/calendar.h"
32 #include "unicode/numfmt.h"
33 #include "unicode/format.h"
34 #include "unicode/locid.h"
35 #include "unicode/enumset.h"
36 #include "unicode/udisplaycontext.h"
40 * \brief C++ API: Abstract class for converting dates.
46 class DateTimePatternGenerator
;
50 * Export an explicit template instantiation. (See digitlst.h, datefmt.h, and others.)
51 * (When building DLLs for Windows this is required.)
53 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN && !defined(U_IN_DOXYGEN)
54 template class U_I18N_API EnumSet
<UDateFormatBooleanAttribute
,
56 UDAT_BOOLEAN_ATTRIBUTE_COUNT
>;
61 * DateFormat is an abstract class for a family of classes that convert dates and
62 * times from their internal representations to textual form and back again in a
63 * language-independent manner. Converting from the internal representation (milliseconds
64 * since midnight, January 1, 1970) to text is known as "formatting," and converting
65 * from text to millis is known as "parsing." We currently define only one concrete
66 * subclass of DateFormat: SimpleDateFormat, which can handle pretty much all normal
67 * date formatting and parsing actions.
69 * DateFormat helps you to format and parse dates for any locale. Your code can
70 * be completely independent of the locale conventions for months, days of the
71 * week, or even the calendar format: lunar vs. solar.
73 * To format a date for the current Locale, use one of the static factory
77 * DateFormat* dfmt = DateFormat::createDateInstance();
78 * UDate myDate = Calendar::getNow();
79 * UnicodeString myString;
80 * myString = dfmt->format( myDate, myString );
83 * If you are formatting multiple numbers, it is more efficient to get the
84 * format and use it multiple times so that the system doesn't have to fetch the
85 * information about the local language and country conventions multiple times.
88 * DateFormat* df = DateFormat::createDateInstance();
89 * UnicodeString myString;
90 * UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values
91 * for (int32_t i = 0; i < 3; ++i) {
93 * cout << df->format( myDateArr[i], myString ) << endl;
97 * To get specific fields of a date, you can use UFieldPosition to
98 * get specific fields.
101 * DateFormat* dfmt = DateFormat::createDateInstance();
102 * FieldPosition pos(DateFormat::YEAR_FIELD);
103 * UnicodeString myString;
104 * myString = dfmt->format( myDate, myString );
105 * cout << myString << endl;
106 * cout << pos.getBeginIndex() << "," << pos. getEndIndex() << endl;
109 * To format a date for a different Locale, specify it in the call to
110 * createDateInstance().
114 * DateFormat::createDateInstance( DateFormat::SHORT, Locale::getFrance());
117 * You can use a DateFormat to parse also.
120 * UErrorCode status = U_ZERO_ERROR;
121 * UDate myDate = df->parse(myString, status);
124 * Use createDateInstance() to produce the normal date format for that country.
125 * There are other static factory methods available. Use createTimeInstance()
126 * to produce the normal time format for that country. Use createDateTimeInstance()
127 * to produce a DateFormat that formats both date and time. You can pass in
128 * different options to these factory methods to control the length of the
129 * result; from SHORT to MEDIUM to LONG to FULL. The exact result depends on the
130 * locale, but generally:
132 * <li> SHORT is completely numeric, such as 12/13/52 or 3:30pm
133 * <li> MEDIUM is longer, such as Jan 12, 1952
134 * <li> LONG is longer, such as January 12, 1952 or 3:30:32pm
135 * <li> FULL is pretty completely specified, such as
136 * Tuesday, April 12, 1952 AD or 3:30:42pm PST.
138 * You can also set the time zone on the format if you wish. If you want even
139 * more control over the format or parsing, (or want to give your users more
140 * control), you can try casting the DateFormat you get from the factory methods
141 * to a SimpleDateFormat. This will work for the majority of countries; just
142 * remember to chck getDynamicClassID() before carrying out the cast.
144 * You can also use forms of the parse and format methods with ParsePosition and
145 * FieldPosition to allow you to
147 * <li> Progressively parse through pieces of a string.
148 * <li> Align any particular field, or find out where it is for selection
152 * <p><em>User subclasses are not supported.</em> While clients may write
153 * subclasses, such code will not necessarily work and will not be
154 * guaranteed to work stably from release to release.
156 class U_I18N_API DateFormat
: public Format
{
160 * Constants for various style patterns. These reflect the order of items in
161 * the DateTimePatterns resource. There are 4 time patterns, 4 date patterns,
162 * the default date-time pattern, and 4 date-time patterns. Each block of 4 values
163 * in the resource occurs in the order full, long, medium, short.
175 kDateOffset
= kShort
+ 1,
176 // kFull + kDateOffset = 4
177 // kLong + kDateOffset = 5
178 // kMedium + kDateOffset = 6
179 // kShort + kDateOffset = 7
184 kDateTimeOffset
= kDateTime
+ 1,
185 // kFull + kDateTimeOffset = 9
186 // kLong + kDateTimeOffset = 10
187 // kMedium + kDateTimeOffset = 11
188 // kShort + kDateTimeOffset = 12
191 kRelative
= (1 << 7),
193 kFullRelative
= (kFull
| kRelative
),
195 kLongRelative
= kLong
| kRelative
,
197 kMediumRelative
= kMedium
| kRelative
,
199 kShortRelative
= kShort
| kRelative
,
207 * These constants are provided for backwards compatibility only.
208 * Please use the C++ style constants defined above.
215 DATE_OFFSET
= kDateOffset
,
217 DATE_TIME
= kDateTime
224 virtual ~DateFormat();
227 * Clones this object polymorphically.
228 * The caller owns the result and should delete it when done.
229 * @return clone, or nullptr if an error occurred
232 virtual DateFormat
* clone() const = 0;
235 * Equality operator. Returns true if the two formats have the same behavior.
238 virtual UBool
operator==(const Format
&) const;
241 using Format::format
;
244 * Format an object to produce a string. This method handles Formattable
245 * objects with a UDate type. If a the Formattable object type is not a Date,
246 * then it returns a failing UErrorCode.
248 * @param obj The object to format. Must be a Date.
249 * @param appendTo Output parameter to receive result.
250 * Result is appended to existing contents.
251 * @param pos On input: an alignment field, if desired.
252 * On output: the offsets of the alignment field.
253 * @param status Output param filled with success/failure status.
254 * @return Reference to 'appendTo' parameter.
257 virtual UnicodeString
& format(const Formattable
& obj
,
258 UnicodeString
& appendTo
,
260 UErrorCode
& status
) const;
263 * Format an object to produce a string. This method handles Formattable
264 * objects with a UDate type. If a the Formattable object type is not a Date,
265 * then it returns a failing UErrorCode.
267 * @param obj The object to format. Must be a Date.
268 * @param appendTo Output parameter to receive result.
269 * Result is appended to existing contents.
270 * @param posIter On return, can be used to iterate over positions
271 * of fields generated by this format call. Field values
272 * are defined in UDateFormatField. Can be NULL.
273 * @param status Output param filled with success/failure status.
274 * @return Reference to 'appendTo' parameter.
277 virtual UnicodeString
& format(const Formattable
& obj
,
278 UnicodeString
& appendTo
,
279 FieldPositionIterator
* posIter
,
280 UErrorCode
& status
) const;
282 * Formats a date into a date/time string. This is an abstract method which
283 * concrete subclasses must implement.
285 * On input, the FieldPosition parameter may have its "field" member filled with
286 * an enum value specifying a field. On output, the FieldPosition will be filled
287 * in with the text offsets for that field.
288 * <P> For example, given a time text
289 * "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition.field is
290 * UDAT_YEAR_FIELD, the offsets fieldPosition.beginIndex and
291 * statfieldPositionus.getEndIndex will be set to 0 and 4, respectively.
293 * that if the same time field appears more than once in a pattern, the status will
294 * be set for the first occurence of that time field. For instance,
295 * formatting a UDate to the time string "1 PM PDT (Pacific Daylight Time)"
296 * using the pattern "h a z (zzzz)" and the alignment field
297 * DateFormat::TIMEZONE_FIELD, the offsets fieldPosition.beginIndex and
298 * fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first
299 * occurence of the timezone pattern character 'z'.
301 * @param cal Calendar set to the date and time to be formatted
302 * into a date/time string. When the calendar type is
303 * different from the internal calendar held by this
304 * DateFormat instance, the date and the time zone will
305 * be inherited from the input calendar, but other calendar
306 * field values will be calculated by the internal calendar.
307 * @param appendTo Output parameter to receive result.
308 * Result is appended to existing contents.
309 * @param fieldPosition On input: an alignment field, if desired (see examples above)
310 * On output: the offsets of the alignment field (see examples above)
311 * @return Reference to 'appendTo' parameter.
314 virtual UnicodeString
& format( Calendar
& cal
,
315 UnicodeString
& appendTo
,
316 FieldPosition
& fieldPosition
) const = 0;
319 * Formats a date into a date/time string. Subclasses should implement this method.
321 * @param cal Calendar set to the date and time to be formatted
322 * into a date/time string. When the calendar type is
323 * different from the internal calendar held by this
324 * DateFormat instance, the date and the time zone will
325 * be inherited from the input calendar, but other calendar
326 * field values will be calculated by the internal calendar.
327 * @param appendTo Output parameter to receive result.
328 * Result is appended to existing contents.
329 * @param posIter On return, can be used to iterate over positions
330 * of fields generated by this format call. Field values
331 * are defined in UDateFormatField. Can be NULL.
332 * @param status error status.
333 * @return Reference to 'appendTo' parameter.
336 virtual UnicodeString
& format(Calendar
& cal
,
337 UnicodeString
& appendTo
,
338 FieldPositionIterator
* posIter
,
339 UErrorCode
& status
) const;
341 * Formats a UDate into a date/time string.
343 * On input, the FieldPosition parameter may have its "field" member filled with
344 * an enum value specifying a field. On output, the FieldPosition will be filled
345 * in with the text offsets for that field.
346 * <P> For example, given a time text
347 * "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition.field is
348 * UDAT_YEAR_FIELD, the offsets fieldPosition.beginIndex and
349 * statfieldPositionus.getEndIndex will be set to 0 and 4, respectively.
351 * that if the same time field appears more than once in a pattern, the status will
352 * be set for the first occurence of that time field. For instance,
353 * formatting a UDate to the time string "1 PM PDT (Pacific Daylight Time)"
354 * using the pattern "h a z (zzzz)" and the alignment field
355 * DateFormat::TIMEZONE_FIELD, the offsets fieldPosition.beginIndex and
356 * fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first
357 * occurence of the timezone pattern character 'z'.
359 * @param date UDate to be formatted into a date/time string.
360 * @param appendTo Output parameter to receive result.
361 * Result is appended to existing contents.
362 * @param fieldPosition On input: an alignment field, if desired (see examples above)
363 * On output: the offsets of the alignment field (see examples above)
364 * @return Reference to 'appendTo' parameter.
367 UnicodeString
& format( UDate date
,
368 UnicodeString
& appendTo
,
369 FieldPosition
& fieldPosition
) const;
372 * Formats a UDate into a date/time string.
374 * @param date UDate to be formatted into a date/time string.
375 * @param appendTo Output parameter to receive result.
376 * Result is appended to existing contents.
377 * @param posIter On return, can be used to iterate over positions
378 * of fields generated by this format call. Field values
379 * are defined in UDateFormatField. Can be NULL.
380 * @param status error status.
381 * @return Reference to 'appendTo' parameter.
384 UnicodeString
& format(UDate date
,
385 UnicodeString
& appendTo
,
386 FieldPositionIterator
* posIter
,
387 UErrorCode
& status
) const;
389 * Formats a UDate into a date/time string. If there is a problem, you won't
390 * know, using this method. Use the overloaded format() method which takes a
391 * FieldPosition& to detect formatting problems.
393 * @param date The UDate value to be formatted into a string.
394 * @param appendTo Output parameter to receive result.
395 * Result is appended to existing contents.
396 * @return Reference to 'appendTo' parameter.
399 UnicodeString
& format(UDate date
, UnicodeString
& appendTo
) const;
402 * Parse a date/time string. For example, a time text "07/10/96 4:5 PM, PDT"
403 * will be parsed into a UDate that is equivalent to Date(837039928046).
404 * Parsing begins at the beginning of the string and proceeds as far as
405 * possible. Assuming no parse errors were encountered, this function
406 * doesn't return any information about how much of the string was consumed
407 * by the parsing. If you need that information, use the version of
408 * parse() that takes a ParsePosition.
410 * By default, parsing is lenient: If the input is not in the form used by
411 * this object's format method but can still be parsed as a date, then the
412 * parse succeeds. Clients may insist on strict adherence to the format by
413 * calling setLenient(false).
414 * @see DateFormat::setLenient(boolean)
416 * Note that the normal date formats associated with some calendars - such
417 * as the Chinese lunar calendar - do not specify enough fields to enable
418 * dates to be parsed unambiguously. In the case of the Chinese lunar
419 * calendar, while the year within the current 60-year cycle is specified,
420 * the number of such cycles since the start date of the calendar (in the
421 * ERA field of the Calendar object) is not normally part of the format,
422 * and parsing may assume the wrong era. For cases such as this it is
423 * recommended that clients parse using the method
424 * parse(const UnicodeString&, Calendar& cal, ParsePosition&)
425 * with the Calendar passed in set to the current date, or to a date
426 * within the era/cycle that should be assumed if absent in the format.
428 * @param text The date/time string to be parsed into a UDate value.
429 * @param status Output param to be set to success/failure code. If
430 * 'text' cannot be parsed, it will be set to a failure
432 * @return The parsed UDate value, if successful.
435 virtual UDate
parse( const UnicodeString
& text
,
436 UErrorCode
& status
) const;
439 * Parse a date/time string beginning at the given parse position. For
440 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
441 * that is equivalent to Date(837039928046).
443 * By default, parsing is lenient: If the input is not in the form used by
444 * this object's format method but can still be parsed as a date, then the
445 * parse succeeds. Clients may insist on strict adherence to the format by
446 * calling setLenient(false).
447 * @see DateFormat::setLenient(boolean)
449 * @param text The date/time string to be parsed.
450 * @param cal A Calendar set on input to the date and time to be used for
451 * missing values in the date/time string being parsed, and set
452 * on output to the parsed date/time. When the calendar type is
453 * different from the internal calendar held by this DateFormat
454 * instance, the internal calendar will be cloned to a work
455 * calendar set to the same milliseconds and time zone as the
456 * cal parameter, field values will be parsed based on the work
457 * calendar, then the result (milliseconds and time zone) will
458 * be set in this calendar.
459 * @param pos On input, the position at which to start parsing; on
460 * output, the position at which parsing terminated, or the
461 * start position if the parse failed.
464 virtual void parse( const UnicodeString
& text
,
466 ParsePosition
& pos
) const = 0;
469 * Parse a date/time string beginning at the given parse position. For
470 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
471 * that is equivalent to Date(837039928046).
473 * By default, parsing is lenient: If the input is not in the form used by
474 * this object's format method but can still be parsed as a date, then the
475 * parse succeeds. Clients may insist on strict adherence to the format by
476 * calling setLenient(false).
477 * @see DateFormat::setLenient(boolean)
479 * Note that the normal date formats associated with some calendars - such
480 * as the Chinese lunar calendar - do not specify enough fields to enable
481 * dates to be parsed unambiguously. In the case of the Chinese lunar
482 * calendar, while the year within the current 60-year cycle is specified,
483 * the number of such cycles since the start date of the calendar (in the
484 * ERA field of the Calendar object) is not normally part of the format,
485 * and parsing may assume the wrong era. For cases such as this it is
486 * recommended that clients parse using the method
487 * parse(const UnicodeString&, Calendar& cal, ParsePosition&)
488 * with the Calendar passed in set to the current date, or to a date
489 * within the era/cycle that should be assumed if absent in the format.
491 * @param text The date/time string to be parsed into a UDate value.
492 * @param pos On input, the position at which to start parsing; on
493 * output, the position at which parsing terminated, or the
494 * start position if the parse failed.
495 * @return A valid UDate if the input could be parsed.
498 UDate
parse( const UnicodeString
& text
,
499 ParsePosition
& pos
) const;
502 * Parse a string to produce an object. This methods handles parsing of
503 * date/time strings into Formattable objects with UDate types.
505 * Before calling, set parse_pos.index to the offset you want to start
506 * parsing at in the source. After calling, parse_pos.index is the end of
507 * the text you parsed. If error occurs, index is unchanged.
509 * When parsing, leading whitespace is discarded (with a successful parse),
510 * while trailing whitespace is left as is.
512 * See Format::parseObject() for more.
514 * @param source The string to be parsed into an object.
515 * @param result Formattable to be set to the parse result.
516 * If parse fails, return contents are undefined.
517 * @param parse_pos The position to start parsing at. Upon return
518 * this param is set to the position after the
519 * last character successfully parsed. If the
520 * source is not parsed successfully, this param
521 * will remain unchanged.
524 virtual void parseObject(const UnicodeString
& source
,
526 ParsePosition
& parse_pos
) const;
529 * Create a default date/time formatter that uses the SHORT style for both
530 * the date and the time.
532 * @return A date/time formatter which the caller owns.
535 static DateFormat
* U_EXPORT2
createInstance(void);
538 * Creates a time formatter with the given formatting style for the given
541 * @param style The given formatting style. For example,
542 * SHORT for "h:mm a" in the US locale. Relative
543 * time styles are not currently supported.
544 * @param aLocale The given locale.
545 * @return A time formatter which the caller owns.
548 static DateFormat
* U_EXPORT2
createTimeInstance(EStyle style
= kDefault
,
549 const Locale
& aLocale
= Locale::getDefault());
552 * Creates a date formatter with the given formatting style for the given
555 * @param style The given formatting style. For example, SHORT for "M/d/yy" in the
556 * US locale. As currently implemented, relative date formatting only
557 * affects a limited range of calendar days before or after the
558 * current date, based on the CLDR <field type="day">/<relative> data:
559 * For example, in English, "Yesterday", "Today", and "Tomorrow".
560 * Outside of this range, dates are formatted using the corresponding
561 * non-relative style.
562 * @param aLocale The given locale.
563 * @return A date formatter which the caller owns.
566 static DateFormat
* U_EXPORT2
createDateInstance(EStyle style
= kDefault
,
567 const Locale
& aLocale
= Locale::getDefault());
570 * Creates a date/time formatter with the given formatting styles for the
573 * @param dateStyle The given formatting style for the date portion of the result.
574 * For example, SHORT for "M/d/yy" in the US locale. As currently
575 * implemented, relative date formatting only affects a limited range
576 * of calendar days before or after the current date, based on the
577 * CLDR <field type="day">/<relative> data: For example, in English,
578 * "Yesterday", "Today", and "Tomorrow". Outside of this range, dates
579 * are formatted using the corresponding non-relative style.
580 * @param timeStyle The given formatting style for the time portion of the result.
581 * For example, SHORT for "h:mm a" in the US locale. Relative
582 * time styles are not currently supported.
583 * @param aLocale The given locale.
584 * @return A date/time formatter which the caller owns.
587 static DateFormat
* U_EXPORT2
createDateTimeInstance(EStyle dateStyle
= kDefault
,
588 EStyle timeStyle
= kDefault
,
589 const Locale
& aLocale
= Locale::getDefault());
591 #ifndef U_HIDE_INTERNAL_API
593 * Returns the best pattern given a skeleton and locale.
594 * @param locale the locale
595 * @param skeleton the skeleton
596 * @param status ICU error returned here
597 * @return the best pattern.
598 * @internal For ICU use only.
600 static UnicodeString
getBestPattern(
601 const Locale
&locale
,
602 const UnicodeString
&skeleton
,
604 #endif /* U_HIDE_INTERNAL_API */
607 * Creates a date/time formatter for the given skeleton and
610 * @param skeleton The skeleton e.g "yMMMMd." Fields in the skeleton can
611 * be in any order, and this method uses the locale to
612 * map the skeleton to a pattern that includes locale
613 * specific separators with the fields in the appropriate
614 * order for that locale.
615 * @param status Any error returned here.
616 * @return A date/time formatter which the caller owns.
619 static DateFormat
* U_EXPORT2
createInstanceForSkeleton(
620 const UnicodeString
& skeleton
,
624 * Creates a date/time formatter for the given skeleton and locale.
626 * @param skeleton The skeleton e.g "yMMMMd." Fields in the skeleton can
627 * be in any order, and this method uses the locale to
628 * map the skeleton to a pattern that includes locale
629 * specific separators with the fields in the appropriate
630 * order for that locale.
631 * @param locale The given locale.
632 * @param status Any error returned here.
633 * @return A date/time formatter which the caller owns.
636 static DateFormat
* U_EXPORT2
createInstanceForSkeleton(
637 const UnicodeString
& skeleton
,
638 const Locale
&locale
,
642 * Creates a date/time formatter for the given skeleton and locale.
644 * @param calendarToAdopt the calendar returned DateFormat is to use.
645 * @param skeleton The skeleton e.g "yMMMMd." Fields in the skeleton can
646 * be in any order, and this method uses the locale to
647 * map the skeleton to a pattern that includes locale
648 * specific separators with the fields in the appropriate
649 * order for that locale.
650 * @param locale The given locale.
651 * @param status Any error returned here.
652 * @return A date/time formatter which the caller owns.
655 static DateFormat
* U_EXPORT2
createInstanceForSkeleton(
656 Calendar
*calendarToAdopt
,
657 const UnicodeString
& skeleton
,
658 const Locale
&locale
,
663 * Gets the set of locales for which DateFormats are installed.
664 * @param count Filled in with the number of locales in the list that is returned.
665 * @return the set of locales for which DateFormats are installed. The caller
666 * does NOT own this list and must not delete it.
669 static const Locale
* U_EXPORT2
getAvailableLocales(int32_t& count
);
672 * Returns whether both date/time parsing in the encapsulated Calendar object and DateFormat whitespace &
673 * numeric processing is lenient.
676 virtual UBool
isLenient(void) const;
679 * Specifies whether date/time parsing is to be lenient. With
680 * lenient parsing, the parser may use heuristics to interpret inputs that
681 * do not precisely match this object's format. Without lenient parsing,
682 * inputs must match this object's format more closely.
684 * Note: ICU 53 introduced finer grained control of leniency (and added
685 * new control points) making the preferred method a combination of
686 * setCalendarLenient() & setBooleanAttribute() calls.
687 * This method supports prior functionality but may not support all
688 * future leniency control & behavior of DateFormat. For control of pre 53 leniency,
689 * Calendar and DateFormat whitespace & numeric tolerance, this method is safe to
690 * use. However, mixing leniency control via this method and modification of the
691 * newer attributes via setBooleanAttribute() may produce undesirable
694 * @param lenient True specifies date/time interpretation to be lenient.
695 * @see Calendar::setLenient
698 virtual void setLenient(UBool lenient
);
702 * Returns whether date/time parsing in the encapsulated Calendar object processing is lenient.
705 virtual UBool
isCalendarLenient(void) const;
709 * Specifies whether encapsulated Calendar date/time parsing is to be lenient. With
710 * lenient parsing, the parser may use heuristics to interpret inputs that
711 * do not precisely match this object's format. Without lenient parsing,
712 * inputs must match this object's format more closely.
713 * @param lenient when true, parsing is lenient
714 * @see com.ibm.icu.util.Calendar#setLenient
717 virtual void setCalendarLenient(UBool lenient
);
721 * Gets the calendar associated with this date/time formatter.
722 * The calendar is owned by the formatter and must not be modified.
723 * Also, the calendar does not reflect the results of a parse operation.
724 * To parse to a calendar, use {@link #parse(const UnicodeString&, Calendar& cal, ParsePosition&) const parse(const UnicodeString&, Calendar& cal, ParsePosition&)}
725 * @return the calendar associated with this date/time formatter.
728 virtual const Calendar
* getCalendar(void) const;
731 * Set the calendar to be used by this date format. Initially, the default
732 * calendar for the specified or default locale is used. The caller should
733 * not delete the Calendar object after it is adopted by this call.
734 * Adopting a new calendar will change to the default symbols.
736 * @param calendarToAdopt Calendar object to be adopted.
739 virtual void adoptCalendar(Calendar
* calendarToAdopt
);
742 * Set the calendar to be used by this date format. Initially, the default
743 * calendar for the specified or default locale is used.
745 * @param newCalendar Calendar object to be set.
748 virtual void setCalendar(const Calendar
& newCalendar
);
752 * Gets the number formatter which this date/time formatter uses to format
753 * and parse the numeric portions of the pattern.
754 * @return the number formatter which this date/time formatter uses.
757 virtual const NumberFormat
* getNumberFormat(void) const;
760 * Allows you to set the number formatter. The caller should
761 * not delete the NumberFormat object after it is adopted by this call.
762 * @param formatToAdopt NumberFormat object to be adopted.
765 virtual void adoptNumberFormat(NumberFormat
* formatToAdopt
);
768 * Allows you to set the number formatter.
769 * @param newNumberFormat NumberFormat object to be set.
772 virtual void setNumberFormat(const NumberFormat
& newNumberFormat
);
775 * Returns a reference to the TimeZone used by this DateFormat's calendar.
776 * @return the time zone associated with the calendar of DateFormat.
779 virtual const TimeZone
& getTimeZone(void) const;
782 * Sets the time zone for the calendar of this DateFormat object. The caller
783 * no longer owns the TimeZone object and should not delete it after this call.
784 * @param zoneToAdopt the TimeZone to be adopted.
787 virtual void adoptTimeZone(TimeZone
* zoneToAdopt
);
790 * Sets the time zone for the calendar of this DateFormat object.
791 * @param zone the new time zone.
794 virtual void setTimeZone(const TimeZone
& zone
);
797 * Set a particular UDisplayContext value in the formatter, such as
798 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
799 * @param value The UDisplayContext value to set.
800 * @param status Input/output status. If at entry this indicates a failure
801 * status, the function will do nothing; otherwise this will be
802 * updated with any new status from the function.
805 virtual void setContext(UDisplayContext value
, UErrorCode
& status
);
808 * Get the formatter's UDisplayContext value for the specified UDisplayContextType,
809 * such as UDISPCTX_TYPE_CAPITALIZATION.
810 * @param type The UDisplayContextType whose value to return
811 * @param status Input/output status. If at entry this indicates a failure
812 * status, the function will do nothing; otherwise this will be
813 * updated with any new status from the function.
814 * @return The UDisplayContextValue for the specified type.
817 virtual UDisplayContext
getContext(UDisplayContextType type
, UErrorCode
& status
) const;
820 * Sets an boolean attribute on this DateFormat.
821 * May return U_UNSUPPORTED_ERROR if this instance does not support
822 * the specified attribute.
823 * @param attr the attribute to set
824 * @param newvalue new value
825 * @param status the error type
826 * @return *this - for chaining (example: format.setAttribute(...).setAttribute(...) )
830 virtual DateFormat
& U_EXPORT2
setBooleanAttribute(UDateFormatBooleanAttribute attr
,
835 * Returns a boolean from this DateFormat
836 * May return U_UNSUPPORTED_ERROR if this instance does not support
837 * the specified attribute.
838 * @param attr the attribute to set
839 * @param status the error type
840 * @return the attribute value. Undefined if there is an error.
843 virtual UBool U_EXPORT2
getBooleanAttribute(UDateFormatBooleanAttribute attr
, UErrorCode
&status
) const;
847 * Default constructor. Creates a DateFormat with no Calendar or NumberFormat
848 * associated with it. This constructor depends on the subclasses to fill in
849 * the calendar and numberFormat fields.
858 DateFormat(const DateFormat
&);
861 * Default assignment operator.
864 DateFormat
& operator=(const DateFormat
&);
867 * The calendar that DateFormat uses to produce the time field values needed
868 * to implement date/time formatting. Subclasses should generally initialize
869 * this to the default calendar for the locale associated with this DateFormat.
875 * The number formatter that DateFormat uses to format numbers in dates and
876 * times. Subclasses should generally initialize this to the default number
877 * format for the locale associated with this DateFormat.
880 NumberFormat
* fNumberFormat
;
886 * Gets the date/time formatter with the given formatting styles for the
888 * @param dateStyle the given date formatting style.
889 * @param timeStyle the given time formatting style.
890 * @param inLocale the given locale.
891 * @return a date/time formatter, or 0 on failure.
893 static DateFormat
* U_EXPORT2
create(EStyle timeStyle
, EStyle dateStyle
, const Locale
& inLocale
);
897 * enum set of active boolean attributes for this instance
899 EnumSet
<UDateFormatBooleanAttribute
, 0, UDAT_BOOLEAN_ATTRIBUTE_COUNT
> fBoolFlags
;
902 UDisplayContext fCapitalizationContext
;
903 friend class DateFmtKeyByStyle
;
906 #ifndef U_HIDE_OBSOLETE_API
908 * Field selector for FieldPosition for DateFormat fields.
909 * @obsolete ICU 3.4 use UDateFormatField instead, since this API will be
910 * removed in that release
914 // Obsolete; use UDateFormatField instead
915 kEraField
= UDAT_ERA_FIELD
,
916 kYearField
= UDAT_YEAR_FIELD
,
917 kMonthField
= UDAT_MONTH_FIELD
,
918 kDateField
= UDAT_DATE_FIELD
,
919 kHourOfDay1Field
= UDAT_HOUR_OF_DAY1_FIELD
,
920 kHourOfDay0Field
= UDAT_HOUR_OF_DAY0_FIELD
,
921 kMinuteField
= UDAT_MINUTE_FIELD
,
922 kSecondField
= UDAT_SECOND_FIELD
,
923 kMillisecondField
= UDAT_FRACTIONAL_SECOND_FIELD
,
924 kDayOfWeekField
= UDAT_DAY_OF_WEEK_FIELD
,
925 kDayOfYearField
= UDAT_DAY_OF_YEAR_FIELD
,
926 kDayOfWeekInMonthField
= UDAT_DAY_OF_WEEK_IN_MONTH_FIELD
,
927 kWeekOfYearField
= UDAT_WEEK_OF_YEAR_FIELD
,
928 kWeekOfMonthField
= UDAT_WEEK_OF_MONTH_FIELD
,
929 kAmPmField
= UDAT_AM_PM_FIELD
,
930 kHour1Field
= UDAT_HOUR1_FIELD
,
931 kHour0Field
= UDAT_HOUR0_FIELD
,
932 kTimezoneField
= UDAT_TIMEZONE_FIELD
,
933 kYearWOYField
= UDAT_YEAR_WOY_FIELD
,
934 kDOWLocalField
= UDAT_DOW_LOCAL_FIELD
,
935 kExtendedYearField
= UDAT_EXTENDED_YEAR_FIELD
,
936 kJulianDayField
= UDAT_JULIAN_DAY_FIELD
,
937 kMillisecondsInDayField
= UDAT_MILLISECONDS_IN_DAY_FIELD
,
939 // Obsolete; use UDateFormatField instead
940 ERA_FIELD
= UDAT_ERA_FIELD
,
941 YEAR_FIELD
= UDAT_YEAR_FIELD
,
942 MONTH_FIELD
= UDAT_MONTH_FIELD
,
943 DATE_FIELD
= UDAT_DATE_FIELD
,
944 HOUR_OF_DAY1_FIELD
= UDAT_HOUR_OF_DAY1_FIELD
,
945 HOUR_OF_DAY0_FIELD
= UDAT_HOUR_OF_DAY0_FIELD
,
946 MINUTE_FIELD
= UDAT_MINUTE_FIELD
,
947 SECOND_FIELD
= UDAT_SECOND_FIELD
,
948 MILLISECOND_FIELD
= UDAT_FRACTIONAL_SECOND_FIELD
,
949 DAY_OF_WEEK_FIELD
= UDAT_DAY_OF_WEEK_FIELD
,
950 DAY_OF_YEAR_FIELD
= UDAT_DAY_OF_YEAR_FIELD
,
951 DAY_OF_WEEK_IN_MONTH_FIELD
= UDAT_DAY_OF_WEEK_IN_MONTH_FIELD
,
952 WEEK_OF_YEAR_FIELD
= UDAT_WEEK_OF_YEAR_FIELD
,
953 WEEK_OF_MONTH_FIELD
= UDAT_WEEK_OF_MONTH_FIELD
,
954 AM_PM_FIELD
= UDAT_AM_PM_FIELD
,
955 HOUR1_FIELD
= UDAT_HOUR1_FIELD
,
956 HOUR0_FIELD
= UDAT_HOUR0_FIELD
,
957 TIMEZONE_FIELD
= UDAT_TIMEZONE_FIELD
959 #endif /* U_HIDE_OBSOLETE_API */
964 #endif /* #if !UCONFIG_NO_FORMATTING */
966 #endif /* U_SHOW_CPLUSPLUS_API */