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 !UCONFIG_NO_FORMATTING
28 #include "unicode/udat.h"
29 #include "unicode/calendar.h"
30 #include "unicode/numfmt.h"
31 #include "unicode/format.h"
32 #include "unicode/locid.h"
33 #include "unicode/enumset.h"
34 #include "unicode/udisplaycontext.h"
38 * \brief C++ API: Abstract class for converting dates.
41 #if U_SHOW_CPLUSPLUS_API
45 class DateTimePatternGenerator
;
47 // explicit template instantiation. see digitlst.h
48 // (When building DLLs for Windows this is required.)
49 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
50 template class U_I18N_API EnumSet
<UDateFormatBooleanAttribute
,
52 UDAT_BOOLEAN_ATTRIBUTE_COUNT
>;
56 * DateFormat is an abstract class for a family of classes that convert dates and
57 * times from their internal representations to textual form and back again in a
58 * language-independent manner. Converting from the internal representation (milliseconds
59 * since midnight, January 1, 1970) to text is known as "formatting," and converting
60 * from text to millis is known as "parsing." We currently define only one concrete
61 * subclass of DateFormat: SimpleDateFormat, which can handle pretty much all normal
62 * date formatting and parsing actions.
64 * DateFormat helps you to format and parse dates for any locale. Your code can
65 * be completely independent of the locale conventions for months, days of the
66 * week, or even the calendar format: lunar vs. solar.
68 * To format a date for the current Locale, use one of the static factory
72 * DateFormat* dfmt = DateFormat::createDateInstance();
73 * UDate myDate = Calendar::getNow();
74 * UnicodeString myString;
75 * myString = dfmt->format( myDate, myString );
78 * If you are formatting multiple numbers, it is more efficient to get the
79 * format and use it multiple times so that the system doesn't have to fetch the
80 * information about the local language and country conventions multiple times.
83 * DateFormat* df = DateFormat::createDateInstance();
84 * UnicodeString myString;
85 * UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values
86 * for (int32_t i = 0; i < 3; ++i) {
88 * cout << df->format( myDateArr[i], myString ) << endl;
92 * To get specific fields of a date, you can use UFieldPosition to
93 * get specific fields.
96 * DateFormat* dfmt = DateFormat::createDateInstance();
97 * FieldPosition pos(DateFormat::YEAR_FIELD);
98 * UnicodeString myString;
99 * myString = dfmt->format( myDate, myString );
100 * cout << myString << endl;
101 * cout << pos.getBeginIndex() << "," << pos. getEndIndex() << endl;
104 * To format a date for a different Locale, specify it in the call to
105 * createDateInstance().
109 * DateFormat::createDateInstance( DateFormat::SHORT, Locale::getFrance());
112 * You can use a DateFormat to parse also.
115 * UErrorCode status = U_ZERO_ERROR;
116 * UDate myDate = df->parse(myString, status);
119 * Use createDateInstance() to produce the normal date format for that country.
120 * There are other static factory methods available. Use createTimeInstance()
121 * to produce the normal time format for that country. Use createDateTimeInstance()
122 * to produce a DateFormat that formats both date and time. You can pass in
123 * different options to these factory methods to control the length of the
124 * result; from SHORT to MEDIUM to LONG to FULL. The exact result depends on the
125 * locale, but generally:
127 * <li> SHORT is completely numeric, such as 12/13/52 or 3:30pm
128 * <li> MEDIUM is longer, such as Jan 12, 1952
129 * <li> LONG is longer, such as January 12, 1952 or 3:30:32pm
130 * <li> FULL is pretty completely specified, such as
131 * Tuesday, April 12, 1952 AD or 3:30:42pm PST.
133 * You can also set the time zone on the format if you wish. If you want even
134 * more control over the format or parsing, (or want to give your users more
135 * control), you can try casting the DateFormat you get from the factory methods
136 * to a SimpleDateFormat. This will work for the majority of countries; just
137 * remember to chck getDynamicClassID() before carrying out the cast.
139 * You can also use forms of the parse and format methods with ParsePosition and
140 * FieldPosition to allow you to
142 * <li> Progressively parse through pieces of a string.
143 * <li> Align any particular field, or find out where it is for selection
147 * <p><em>User subclasses are not supported.</em> While clients may write
148 * subclasses, such code will not necessarily work and will not be
149 * guaranteed to work stably from release to release.
151 class U_I18N_API DateFormat
: public Format
{
155 * Constants for various style patterns. These reflect the order of items in
156 * the DateTimePatterns resource. There are 4 time patterns, 4 date patterns,
157 * the default date-time pattern, and 4 date-time patterns. Each block of 4 values
158 * in the resource occurs in the order full, long, medium, short.
170 kDateOffset
= kShort
+ 1,
171 // kFull + kDateOffset = 4
172 // kLong + kDateOffset = 5
173 // kMedium + kDateOffset = 6
174 // kShort + kDateOffset = 7
179 kDateTimeOffset
= kDateTime
+ 1,
180 // kFull + kDateTimeOffset = 9
181 // kLong + kDateTimeOffset = 10
182 // kMedium + kDateTimeOffset = 11
183 // kShort + kDateTimeOffset = 12
186 kRelative
= (1 << 7),
188 kFullRelative
= (kFull
| kRelative
),
190 kLongRelative
= kLong
| kRelative
,
192 kMediumRelative
= kMedium
| kRelative
,
194 kShortRelative
= kShort
| kRelative
,
202 * These constants are provided for backwards compatibility only.
203 * Please use the C++ style constants defined above.
210 DATE_OFFSET
= kDateOffset
,
212 DATE_TIME
= kDateTime
219 virtual ~DateFormat();
222 * Equality operator. Returns true if the two formats have the same behavior.
225 virtual UBool
operator==(const Format
&) const;
228 using Format::format
;
231 * Format an object to produce a string. This method handles Formattable
232 * objects with a UDate type. If a the Formattable object type is not a Date,
233 * then it returns a failing UErrorCode.
235 * @param obj The object to format. Must be a Date.
236 * @param appendTo Output parameter to receive result.
237 * Result is appended to existing contents.
238 * @param pos On input: an alignment field, if desired.
239 * On output: the offsets of the alignment field.
240 * @param status Output param filled with success/failure status.
241 * @return Reference to 'appendTo' parameter.
244 virtual UnicodeString
& format(const Formattable
& obj
,
245 UnicodeString
& appendTo
,
247 UErrorCode
& status
) const;
250 * Format an object to produce a string. This method handles Formattable
251 * objects with a UDate type. If a the Formattable object type is not a Date,
252 * then it returns a failing UErrorCode.
254 * @param obj The object to format. Must be a Date.
255 * @param appendTo Output parameter to receive result.
256 * Result is appended to existing contents.
257 * @param posIter On return, can be used to iterate over positions
258 * of fields generated by this format call. Field values
259 * are defined in UDateFormatField. Can be NULL.
260 * @param status Output param filled with success/failure status.
261 * @return Reference to 'appendTo' parameter.
264 virtual UnicodeString
& format(const Formattable
& obj
,
265 UnicodeString
& appendTo
,
266 FieldPositionIterator
* posIter
,
267 UErrorCode
& status
) const;
269 * Formats a date into a date/time string. This is an abstract method which
270 * concrete subclasses must implement.
272 * On input, the FieldPosition parameter may have its "field" member filled with
273 * an enum value specifying a field. On output, the FieldPosition will be filled
274 * in with the text offsets for that field.
275 * <P> For example, given a time text
276 * "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition.field is
277 * UDAT_YEAR_FIELD, the offsets fieldPosition.beginIndex and
278 * statfieldPositionus.getEndIndex will be set to 0 and 4, respectively.
280 * that if the same time field appears more than once in a pattern, the status will
281 * be set for the first occurence of that time field. For instance,
282 * formatting a UDate to the time string "1 PM PDT (Pacific Daylight Time)"
283 * using the pattern "h a z (zzzz)" and the alignment field
284 * DateFormat::TIMEZONE_FIELD, the offsets fieldPosition.beginIndex and
285 * fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first
286 * occurence of the timezone pattern character 'z'.
288 * @param cal Calendar set to the date and time to be formatted
289 * into a date/time string. When the calendar type is
290 * different from the internal calendar held by this
291 * DateFormat instance, the date and the time zone will
292 * be inherited from the input calendar, but other calendar
293 * field values will be calculated by the internal calendar.
294 * @param appendTo Output parameter to receive result.
295 * Result is appended to existing contents.
296 * @param fieldPosition On input: an alignment field, if desired (see examples above)
297 * On output: the offsets of the alignment field (see examples above)
298 * @return Reference to 'appendTo' parameter.
301 virtual UnicodeString
& format( Calendar
& cal
,
302 UnicodeString
& appendTo
,
303 FieldPosition
& fieldPosition
) const = 0;
306 * Formats a date into a date/time string. Subclasses should implement this method.
308 * @param cal Calendar set to the date and time to be formatted
309 * into a date/time string. When the calendar type is
310 * different from the internal calendar held by this
311 * DateFormat instance, the date and the time zone will
312 * be inherited from the input calendar, but other calendar
313 * field values will be calculated by the internal calendar.
314 * @param appendTo Output parameter to receive result.
315 * Result is appended to existing contents.
316 * @param posIter On return, can be used to iterate over positions
317 * of fields generated by this format call. Field values
318 * are defined in UDateFormatField. Can be NULL.
319 * @param status error status.
320 * @return Reference to 'appendTo' parameter.
323 virtual UnicodeString
& format(Calendar
& cal
,
324 UnicodeString
& appendTo
,
325 FieldPositionIterator
* posIter
,
326 UErrorCode
& status
) const;
328 * Formats a UDate into a date/time string.
330 * On input, the FieldPosition parameter may have its "field" member filled with
331 * an enum value specifying a field. On output, the FieldPosition will be filled
332 * in with the text offsets for that field.
333 * <P> For example, given a time text
334 * "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition.field is
335 * UDAT_YEAR_FIELD, the offsets fieldPosition.beginIndex and
336 * statfieldPositionus.getEndIndex will be set to 0 and 4, respectively.
338 * that if the same time field appears more than once in a pattern, the status will
339 * be set for the first occurence of that time field. For instance,
340 * formatting a UDate to the time string "1 PM PDT (Pacific Daylight Time)"
341 * using the pattern "h a z (zzzz)" and the alignment field
342 * DateFormat::TIMEZONE_FIELD, the offsets fieldPosition.beginIndex and
343 * fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first
344 * occurence of the timezone pattern character 'z'.
346 * @param date UDate to be formatted into a date/time string.
347 * @param appendTo Output parameter to receive result.
348 * Result is appended to existing contents.
349 * @param fieldPosition On input: an alignment field, if desired (see examples above)
350 * On output: the offsets of the alignment field (see examples above)
351 * @return Reference to 'appendTo' parameter.
354 UnicodeString
& format( UDate date
,
355 UnicodeString
& appendTo
,
356 FieldPosition
& fieldPosition
) const;
359 * Formats a UDate into a date/time string.
361 * @param date UDate to be formatted into a date/time string.
362 * @param appendTo Output parameter to receive result.
363 * Result is appended to existing contents.
364 * @param posIter On return, can be used to iterate over positions
365 * of fields generated by this format call. Field values
366 * are defined in UDateFormatField. Can be NULL.
367 * @param status error status.
368 * @return Reference to 'appendTo' parameter.
371 UnicodeString
& format(UDate date
,
372 UnicodeString
& appendTo
,
373 FieldPositionIterator
* posIter
,
374 UErrorCode
& status
) const;
376 * Formats a UDate into a date/time string. If there is a problem, you won't
377 * know, using this method. Use the overloaded format() method which takes a
378 * FieldPosition& to detect formatting problems.
380 * @param date The UDate value to be formatted into a string.
381 * @param appendTo Output parameter to receive result.
382 * Result is appended to existing contents.
383 * @return Reference to 'appendTo' parameter.
386 UnicodeString
& format(UDate date
, UnicodeString
& appendTo
) const;
389 * Parse a date/time string. For example, a time text "07/10/96 4:5 PM, PDT"
390 * will be parsed into a UDate that is equivalent to Date(837039928046).
391 * Parsing begins at the beginning of the string and proceeds as far as
392 * possible. Assuming no parse errors were encountered, this function
393 * doesn't return any information about how much of the string was consumed
394 * by the parsing. If you need that information, use the version of
395 * parse() that takes a ParsePosition.
397 * By default, parsing is lenient: If the input is not in the form used by
398 * this object's format method but can still be parsed as a date, then the
399 * parse succeeds. Clients may insist on strict adherence to the format by
400 * calling setLenient(false).
401 * @see DateFormat::setLenient(boolean)
403 * Note that the normal date formats associated with some calendars - such
404 * as the Chinese lunar calendar - do not specify enough fields to enable
405 * dates to be parsed unambiguously. In the case of the Chinese lunar
406 * calendar, while the year within the current 60-year cycle is specified,
407 * the number of such cycles since the start date of the calendar (in the
408 * ERA field of the Calendar object) is not normally part of the format,
409 * and parsing may assume the wrong era. For cases such as this it is
410 * recommended that clients parse using the method
411 * parse(const UnicodeString&, Calendar& cal, ParsePosition&)
412 * with the Calendar passed in set to the current date, or to a date
413 * within the era/cycle that should be assumed if absent in the format.
415 * @param text The date/time string to be parsed into a UDate value.
416 * @param status Output param to be set to success/failure code. If
417 * 'text' cannot be parsed, it will be set to a failure
419 * @return The parsed UDate value, if successful.
422 virtual UDate
parse( const UnicodeString
& text
,
423 UErrorCode
& status
) const;
426 * Parse a date/time string beginning at the given parse position. For
427 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
428 * that is equivalent to Date(837039928046).
430 * By default, parsing is lenient: If the input is not in the form used by
431 * this object's format method but can still be parsed as a date, then the
432 * parse succeeds. Clients may insist on strict adherence to the format by
433 * calling setLenient(false).
434 * @see DateFormat::setLenient(boolean)
436 * @param text The date/time string to be parsed.
437 * @param cal A Calendar set on input to the date and time to be used for
438 * missing values in the date/time string being parsed, and set
439 * on output to the parsed date/time. When the calendar type is
440 * different from the internal calendar held by this DateFormat
441 * instance, the internal calendar will be cloned to a work
442 * calendar set to the same milliseconds and time zone as the
443 * cal parameter, field values will be parsed based on the work
444 * calendar, then the result (milliseconds and time zone) will
445 * be set in this calendar.
446 * @param pos On input, the position at which to start parsing; on
447 * output, the position at which parsing terminated, or the
448 * start position if the parse failed.
451 virtual void parse( const UnicodeString
& text
,
453 ParsePosition
& pos
) const = 0;
456 * Parse a date/time string beginning at the given parse position. For
457 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
458 * that is equivalent to Date(837039928046).
460 * By default, parsing is lenient: If the input is not in the form used by
461 * this object's format method but can still be parsed as a date, then the
462 * parse succeeds. Clients may insist on strict adherence to the format by
463 * calling setLenient(false).
464 * @see DateFormat::setLenient(boolean)
466 * Note that the normal date formats associated with some calendars - such
467 * as the Chinese lunar calendar - do not specify enough fields to enable
468 * dates to be parsed unambiguously. In the case of the Chinese lunar
469 * calendar, while the year within the current 60-year cycle is specified,
470 * the number of such cycles since the start date of the calendar (in the
471 * ERA field of the Calendar object) is not normally part of the format,
472 * and parsing may assume the wrong era. For cases such as this it is
473 * recommended that clients parse using the method
474 * parse(const UnicodeString&, Calendar& cal, ParsePosition&)
475 * with the Calendar passed in set to the current date, or to a date
476 * within the era/cycle that should be assumed if absent in the format.
478 * @param text The date/time string to be parsed into a UDate value.
479 * @param pos On input, the position at which to start parsing; on
480 * output, the position at which parsing terminated, or the
481 * start position if the parse failed.
482 * @return A valid UDate if the input could be parsed.
485 UDate
parse( const UnicodeString
& text
,
486 ParsePosition
& pos
) const;
489 * Parse a string to produce an object. This methods handles parsing of
490 * date/time strings into Formattable objects with UDate types.
492 * Before calling, set parse_pos.index to the offset you want to start
493 * parsing at in the source. After calling, parse_pos.index is the end of
494 * the text you parsed. If error occurs, index is unchanged.
496 * When parsing, leading whitespace is discarded (with a successful parse),
497 * while trailing whitespace is left as is.
499 * See Format::parseObject() for more.
501 * @param source The string to be parsed into an object.
502 * @param result Formattable to be set to the parse result.
503 * If parse fails, return contents are undefined.
504 * @param parse_pos The position to start parsing at. Upon return
505 * this param is set to the position after the
506 * last character successfully parsed. If the
507 * source is not parsed successfully, this param
508 * will remain unchanged.
511 virtual void parseObject(const UnicodeString
& source
,
513 ParsePosition
& parse_pos
) const;
516 * Create a default date/time formatter that uses the SHORT style for both
517 * the date and the time.
519 * @return A date/time formatter which the caller owns.
522 static DateFormat
* U_EXPORT2
createInstance(void);
525 * Creates a time formatter with the given formatting style for the given
528 * @param style The given formatting style. For example,
529 * SHORT for "h:mm a" in the US locale. Relative
530 * time styles are not currently supported.
531 * @param aLocale The given locale.
532 * @return A time formatter which the caller owns.
535 static DateFormat
* U_EXPORT2
createTimeInstance(EStyle style
= kDefault
,
536 const Locale
& aLocale
= Locale::getDefault());
539 * Creates a date formatter with the given formatting style for the given
542 * @param style The given formatting style. For example, SHORT for "M/d/yy" in the
543 * US locale. As currently implemented, relative date formatting only
544 * affects a limited range of calendar days before or after the
545 * current date, based on the CLDR <field type="day">/<relative> data:
546 * For example, in English, "Yesterday", "Today", and "Tomorrow".
547 * Outside of this range, dates are formatted using the corresponding
548 * non-relative style.
549 * @param aLocale The given locale.
550 * @return A date formatter which the caller owns.
553 static DateFormat
* U_EXPORT2
createDateInstance(EStyle style
= kDefault
,
554 const Locale
& aLocale
= Locale::getDefault());
557 * Creates a date/time formatter with the given formatting styles for the
560 * @param dateStyle The given formatting style for the date portion of the result.
561 * For example, SHORT for "M/d/yy" in the US locale. As currently
562 * implemented, relative date formatting only affects a limited range
563 * of calendar days before or after the current date, based on the
564 * CLDR <field type="day">/<relative> data: For example, in English,
565 * "Yesterday", "Today", and "Tomorrow". Outside of this range, dates
566 * are formatted using the corresponding non-relative style.
567 * @param timeStyle The given formatting style for the time portion of the result.
568 * For example, SHORT for "h:mm a" in the US locale. Relative
569 * time styles are not currently supported.
570 * @param aLocale The given locale.
571 * @return A date/time formatter which the caller owns.
574 static DateFormat
* U_EXPORT2
createDateTimeInstance(EStyle dateStyle
= kDefault
,
575 EStyle timeStyle
= kDefault
,
576 const Locale
& aLocale
= Locale::getDefault());
578 #ifndef U_HIDE_INTERNAL_API
580 * Returns the best pattern given a skeleton and locale.
581 * @param locale the locale
582 * @param skeleton the skeleton
583 * @param status ICU error returned here
584 * @return the best pattern.
585 * @internal For ICU use only.
587 static UnicodeString
getBestPattern(
588 const Locale
&locale
,
589 const UnicodeString
&skeleton
,
591 #endif /* U_HIDE_INTERNAL_API */
594 * Creates a date/time formatter for the given skeleton and
597 * @param skeleton The skeleton e.g "yMMMMd." Fields in the skeleton can
598 * be in any order, and this method uses the locale to
599 * map the skeleton to a pattern that includes locale
600 * specific separators with the fields in the appropriate
601 * order for that locale.
602 * @param status Any error returned here.
603 * @return A date/time formatter which the caller owns.
606 static DateFormat
* U_EXPORT2
createInstanceForSkeleton(
607 const UnicodeString
& skeleton
,
611 * Creates a date/time formatter for the given skeleton and locale.
613 * @param skeleton The skeleton e.g "yMMMMd." Fields in the skeleton can
614 * be in any order, and this method uses the locale to
615 * map the skeleton to a pattern that includes locale
616 * specific separators with the fields in the appropriate
617 * order for that locale.
618 * @param locale The given locale.
619 * @param status Any error returned here.
620 * @return A date/time formatter which the caller owns.
623 static DateFormat
* U_EXPORT2
createInstanceForSkeleton(
624 const UnicodeString
& skeleton
,
625 const Locale
&locale
,
629 * Creates a date/time formatter for the given skeleton and locale.
631 * @param calendarToAdopt the calendar returned DateFormat is to use.
632 * @param skeleton The skeleton e.g "yMMMMd." Fields in the skeleton can
633 * be in any order, and this method uses the locale to
634 * map the skeleton to a pattern that includes locale
635 * specific separators with the fields in the appropriate
636 * order for that locale.
637 * @param locale The given locale.
638 * @param status Any error returned here.
639 * @return A date/time formatter which the caller owns.
642 static DateFormat
* U_EXPORT2
createInstanceForSkeleton(
643 Calendar
*calendarToAdopt
,
644 const UnicodeString
& skeleton
,
645 const Locale
&locale
,
650 * Gets the set of locales for which DateFormats are installed.
651 * @param count Filled in with the number of locales in the list that is returned.
652 * @return the set of locales for which DateFormats are installed. The caller
653 * does NOT own this list and must not delete it.
656 static const Locale
* U_EXPORT2
getAvailableLocales(int32_t& count
);
659 * Returns whether both date/time parsing in the encapsulated Calendar object and DateFormat whitespace &
660 * numeric processing is lenient.
663 virtual UBool
isLenient(void) const;
666 * Specifies whether date/time parsing is to be lenient. With
667 * lenient parsing, the parser may use heuristics to interpret inputs that
668 * do not precisely match this object's format. Without lenient parsing,
669 * inputs must match this object's format more closely.
671 * Note: ICU 53 introduced finer grained control of leniency (and added
672 * new control points) making the preferred method a combination of
673 * setCalendarLenient() & setBooleanAttribute() calls.
674 * This method supports prior functionality but may not support all
675 * future leniency control & behavior of DateFormat. For control of pre 53 leniency,
676 * Calendar and DateFormat whitespace & numeric tolerance, this method is safe to
677 * use. However, mixing leniency control via this method and modification of the
678 * newer attributes via setBooleanAttribute() may produce undesirable
681 * @param lenient True specifies date/time interpretation to be lenient.
682 * @see Calendar::setLenient
685 virtual void setLenient(UBool lenient
);
689 * Returns whether date/time parsing in the encapsulated Calendar object processing is lenient.
692 virtual UBool
isCalendarLenient(void) const;
696 * Specifies whether encapsulated Calendar date/time parsing is to be lenient. With
697 * lenient parsing, the parser may use heuristics to interpret inputs that
698 * do not precisely match this object's format. Without lenient parsing,
699 * inputs must match this object's format more closely.
700 * @param lenient when true, parsing is lenient
701 * @see com.ibm.icu.util.Calendar#setLenient
704 virtual void setCalendarLenient(UBool lenient
);
708 * Gets the calendar associated with this date/time formatter.
709 * The calendar is owned by the formatter and must not be modified.
710 * Also, the calendar does not reflect the results of a parse operation.
711 * To parse to a calendar, use {@link #parse(const UnicodeString&, Calendar& cal, ParsePosition&) const parse(const UnicodeString&, Calendar& cal, ParsePosition&)}
712 * @return the calendar associated with this date/time formatter.
715 virtual const Calendar
* getCalendar(void) const;
718 * Set the calendar to be used by this date format. Initially, the default
719 * calendar for the specified or default locale is used. The caller should
720 * not delete the Calendar object after it is adopted by this call.
721 * Adopting a new calendar will change to the default symbols.
723 * @param calendarToAdopt Calendar object to be adopted.
726 virtual void adoptCalendar(Calendar
* calendarToAdopt
);
729 * Set the calendar to be used by this date format. Initially, the default
730 * calendar for the specified or default locale is used.
732 * @param newCalendar Calendar object to be set.
735 virtual void setCalendar(const Calendar
& newCalendar
);
739 * Gets the number formatter which this date/time formatter uses to format
740 * and parse the numeric portions of the pattern.
741 * @return the number formatter which this date/time formatter uses.
744 virtual const NumberFormat
* getNumberFormat(void) const;
747 * Allows you to set the number formatter. The caller should
748 * not delete the NumberFormat object after it is adopted by this call.
749 * @param formatToAdopt NumberFormat object to be adopted.
752 virtual void adoptNumberFormat(NumberFormat
* formatToAdopt
);
755 * Allows you to set the number formatter.
756 * @param newNumberFormat NumberFormat object to be set.
759 virtual void setNumberFormat(const NumberFormat
& newNumberFormat
);
762 * Returns a reference to the TimeZone used by this DateFormat's calendar.
763 * @return the time zone associated with the calendar of DateFormat.
766 virtual const TimeZone
& getTimeZone(void) const;
769 * Sets the time zone for the calendar of this DateFormat object. The caller
770 * no longer owns the TimeZone object and should not delete it after this call.
771 * @param zoneToAdopt the TimeZone to be adopted.
774 virtual void adoptTimeZone(TimeZone
* zoneToAdopt
);
777 * Sets the time zone for the calendar of this DateFormat object.
778 * @param zone the new time zone.
781 virtual void setTimeZone(const TimeZone
& zone
);
784 * Set a particular UDisplayContext value in the formatter, such as
785 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
786 * @param value The UDisplayContext value to set.
787 * @param status Input/output status. If at entry this indicates a failure
788 * status, the function will do nothing; otherwise this will be
789 * updated with any new status from the function.
792 virtual void setContext(UDisplayContext value
, UErrorCode
& status
);
795 * Get the formatter's UDisplayContext value for the specified UDisplayContextType,
796 * such as UDISPCTX_TYPE_CAPITALIZATION.
797 * @param type The UDisplayContextType whose value to return
798 * @param status Input/output status. If at entry this indicates a failure
799 * status, the function will do nothing; otherwise this will be
800 * updated with any new status from the function.
801 * @return The UDisplayContextValue for the specified type.
804 virtual UDisplayContext
getContext(UDisplayContextType type
, UErrorCode
& status
) const;
807 * Sets an boolean attribute on this DateFormat.
808 * May return U_UNSUPPORTED_ERROR if this instance does not support
809 * the specified attribute.
810 * @param attr the attribute to set
811 * @param newvalue new value
812 * @param status the error type
813 * @return *this - for chaining (example: format.setAttribute(...).setAttribute(...) )
817 virtual DateFormat
& U_EXPORT2
setBooleanAttribute(UDateFormatBooleanAttribute attr
,
822 * Returns a boolean from this DateFormat
823 * May return U_UNSUPPORTED_ERROR if this instance does not support
824 * the specified attribute.
825 * @param attr the attribute to set
826 * @param status the error type
827 * @return the attribute value. Undefined if there is an error.
830 virtual UBool U_EXPORT2
getBooleanAttribute(UDateFormatBooleanAttribute attr
, UErrorCode
&status
) const;
834 * Default constructor. Creates a DateFormat with no Calendar or NumberFormat
835 * associated with it. This constructor depends on the subclasses to fill in
836 * the calendar and numberFormat fields.
845 DateFormat(const DateFormat
&);
848 * Default assignment operator.
851 DateFormat
& operator=(const DateFormat
&);
854 * The calendar that DateFormat uses to produce the time field values needed
855 * to implement date/time formatting. Subclasses should generally initialize
856 * this to the default calendar for the locale associated with this DateFormat.
862 * The number formatter that DateFormat uses to format numbers in dates and
863 * times. Subclasses should generally initialize this to the default number
864 * format for the locale associated with this DateFormat.
867 NumberFormat
* fNumberFormat
;
873 * Gets the date/time formatter with the given formatting styles for the
875 * @param dateStyle the given date formatting style.
876 * @param timeStyle the given time formatting style.
877 * @param inLocale the given locale.
878 * @return a date/time formatter, or 0 on failure.
880 static DateFormat
* U_EXPORT2
create(EStyle timeStyle
, EStyle dateStyle
, const Locale
& inLocale
);
884 * enum set of active boolean attributes for this instance
886 EnumSet
<UDateFormatBooleanAttribute
, 0, UDAT_BOOLEAN_ATTRIBUTE_COUNT
> fBoolFlags
;
889 UDisplayContext fCapitalizationContext
;
890 friend class DateFmtKeyByStyle
;
893 #ifndef U_HIDE_OBSOLETE_API
895 * Field selector for FieldPosition for DateFormat fields.
896 * @obsolete ICU 3.4 use UDateFormatField instead, since this API will be
897 * removed in that release
901 // Obsolete; use UDateFormatField instead
902 kEraField
= UDAT_ERA_FIELD
,
903 kYearField
= UDAT_YEAR_FIELD
,
904 kMonthField
= UDAT_MONTH_FIELD
,
905 kDateField
= UDAT_DATE_FIELD
,
906 kHourOfDay1Field
= UDAT_HOUR_OF_DAY1_FIELD
,
907 kHourOfDay0Field
= UDAT_HOUR_OF_DAY0_FIELD
,
908 kMinuteField
= UDAT_MINUTE_FIELD
,
909 kSecondField
= UDAT_SECOND_FIELD
,
910 kMillisecondField
= UDAT_FRACTIONAL_SECOND_FIELD
,
911 kDayOfWeekField
= UDAT_DAY_OF_WEEK_FIELD
,
912 kDayOfYearField
= UDAT_DAY_OF_YEAR_FIELD
,
913 kDayOfWeekInMonthField
= UDAT_DAY_OF_WEEK_IN_MONTH_FIELD
,
914 kWeekOfYearField
= UDAT_WEEK_OF_YEAR_FIELD
,
915 kWeekOfMonthField
= UDAT_WEEK_OF_MONTH_FIELD
,
916 kAmPmField
= UDAT_AM_PM_FIELD
,
917 kHour1Field
= UDAT_HOUR1_FIELD
,
918 kHour0Field
= UDAT_HOUR0_FIELD
,
919 kTimezoneField
= UDAT_TIMEZONE_FIELD
,
920 kYearWOYField
= UDAT_YEAR_WOY_FIELD
,
921 kDOWLocalField
= UDAT_DOW_LOCAL_FIELD
,
922 kExtendedYearField
= UDAT_EXTENDED_YEAR_FIELD
,
923 kJulianDayField
= UDAT_JULIAN_DAY_FIELD
,
924 kMillisecondsInDayField
= UDAT_MILLISECONDS_IN_DAY_FIELD
,
926 // Obsolete; use UDateFormatField instead
927 ERA_FIELD
= UDAT_ERA_FIELD
,
928 YEAR_FIELD
= UDAT_YEAR_FIELD
,
929 MONTH_FIELD
= UDAT_MONTH_FIELD
,
930 DATE_FIELD
= UDAT_DATE_FIELD
,
931 HOUR_OF_DAY1_FIELD
= UDAT_HOUR_OF_DAY1_FIELD
,
932 HOUR_OF_DAY0_FIELD
= UDAT_HOUR_OF_DAY0_FIELD
,
933 MINUTE_FIELD
= UDAT_MINUTE_FIELD
,
934 SECOND_FIELD
= UDAT_SECOND_FIELD
,
935 MILLISECOND_FIELD
= UDAT_FRACTIONAL_SECOND_FIELD
,
936 DAY_OF_WEEK_FIELD
= UDAT_DAY_OF_WEEK_FIELD
,
937 DAY_OF_YEAR_FIELD
= UDAT_DAY_OF_YEAR_FIELD
,
938 DAY_OF_WEEK_IN_MONTH_FIELD
= UDAT_DAY_OF_WEEK_IN_MONTH_FIELD
,
939 WEEK_OF_YEAR_FIELD
= UDAT_WEEK_OF_YEAR_FIELD
,
940 WEEK_OF_MONTH_FIELD
= UDAT_WEEK_OF_MONTH_FIELD
,
941 AM_PM_FIELD
= UDAT_AM_PM_FIELD
,
942 HOUR1_FIELD
= UDAT_HOUR1_FIELD
,
943 HOUR0_FIELD
= UDAT_HOUR0_FIELD
,
944 TIMEZONE_FIELD
= UDAT_TIMEZONE_FIELD
946 #endif /* U_HIDE_OBSOLETE_API */
950 #endif // U_SHOW_CPLUSPLUS_API
952 #endif /* #if !UCONFIG_NO_FORMATTING */