michael@0: /* michael@0: ******************************************************************************** michael@0: * Copyright (C) 1997-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ******************************************************************************** michael@0: * michael@0: * File DATEFMT.H michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 02/19/97 aliu Converted from java. michael@0: * 04/01/97 aliu Added support for centuries. michael@0: * 07/23/98 stephen JDK 1.2 sync michael@0: * 11/15/99 weiv Added support for week of year/day of week formatting michael@0: ******************************************************************************** michael@0: */ michael@0: michael@0: #ifndef DATEFMT_H michael@0: #define DATEFMT_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/udat.h" michael@0: #include "unicode/calendar.h" michael@0: #include "unicode/numfmt.h" michael@0: #include "unicode/format.h" michael@0: #include "unicode/locid.h" michael@0: #include "unicode/enumset.h" michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: Abstract class for converting dates. michael@0: */ michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class TimeZone; michael@0: class DateTimePatternGenerator; michael@0: michael@0: // explicit template instantiation. see digitlst.h michael@0: #if defined (_MSC_VER) michael@0: template class U_I18N_API EnumSet; michael@0: #endif michael@0: michael@0: /** michael@0: * DateFormat is an abstract class for a family of classes that convert dates and michael@0: * times from their internal representations to textual form and back again in a michael@0: * language-independent manner. Converting from the internal representation (milliseconds michael@0: * since midnight, January 1, 1970) to text is known as "formatting," and converting michael@0: * from text to millis is known as "parsing." We currently define only one concrete michael@0: * subclass of DateFormat: SimpleDateFormat, which can handle pretty much all normal michael@0: * date formatting and parsing actions. michael@0: *

michael@0: * DateFormat helps you to format and parse dates for any locale. Your code can michael@0: * be completely independent of the locale conventions for months, days of the michael@0: * week, or even the calendar format: lunar vs. solar. michael@0: *

michael@0: * To format a date for the current Locale, use one of the static factory michael@0: * methods: michael@0: *

michael@0:  * \code
michael@0:  *      DateFormat* dfmt = DateFormat::createDateInstance();
michael@0:  *      UDate myDate = Calendar::getNow();
michael@0:  *      UnicodeString myString;
michael@0:  *      myString = dfmt->format( myDate, myString );
michael@0:  * \endcode
michael@0:  * 
michael@0: * If you are formatting multiple numbers, it is more efficient to get the michael@0: * format and use it multiple times so that the system doesn't have to fetch the michael@0: * information about the local language and country conventions multiple times. michael@0: *
michael@0:  * \code
michael@0:  *      DateFormat* df = DateFormat::createDateInstance();
michael@0:  *      UnicodeString myString;
michael@0:  *      UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values
michael@0:  *      for (int32_t i = 0; i < 3; ++i) {
michael@0:  *          myString.remove();
michael@0:  *          cout << df->format( myDateArr[i], myString ) << endl;
michael@0:  *      }
michael@0:  * \endcode
michael@0:  * 
michael@0: * To get specific fields of a date, you can use UFieldPosition to michael@0: * get specific fields. michael@0: *
michael@0:  * \code
michael@0:  *      DateFormat* dfmt = DateFormat::createDateInstance();
michael@0:  *      FieldPosition pos(DateFormat::YEAR_FIELD);
michael@0:  *      UnicodeString myString;
michael@0:  *      myString = dfmt->format( myDate, myString );
michael@0:  *      cout << myString << endl;
michael@0:  *      cout << pos.getBeginIndex() << "," << pos. getEndIndex() << endl;
michael@0:  * \endcode
michael@0:  * 
michael@0: * To format a date for a different Locale, specify it in the call to michael@0: * createDateInstance(). michael@0: *
michael@0:  * \code
michael@0:  *       DateFormat* df =
michael@0:  *           DateFormat::createDateInstance( DateFormat::SHORT, Locale::getFrance());
michael@0:  * \endcode
michael@0:  * 
michael@0: * You can use a DateFormat to parse also. michael@0: *
michael@0:  * \code
michael@0:  *       UErrorCode status = U_ZERO_ERROR;
michael@0:  *       UDate myDate = df->parse(myString, status);
michael@0:  * \endcode
michael@0:  * 
michael@0: * Use createDateInstance() to produce the normal date format for that country. michael@0: * There are other static factory methods available. Use createTimeInstance() michael@0: * to produce the normal time format for that country. Use createDateTimeInstance() michael@0: * to produce a DateFormat that formats both date and time. You can pass in michael@0: * different options to these factory methods to control the length of the michael@0: * result; from SHORT to MEDIUM to LONG to FULL. The exact result depends on the michael@0: * locale, but generally: michael@0: * michael@0: * You can also set the time zone on the format if you wish. If you want even michael@0: * more control over the format or parsing, (or want to give your users more michael@0: * control), you can try casting the DateFormat you get from the factory methods michael@0: * to a SimpleDateFormat. This will work for the majority of countries; just michael@0: * remember to chck getDynamicClassID() before carrying out the cast. michael@0: *

michael@0: * You can also use forms of the parse and format methods with ParsePosition and michael@0: * FieldPosition to allow you to michael@0: *

michael@0: * michael@0: *

User subclasses are not supported. While clients may write michael@0: * subclasses, such code will not necessarily work and will not be michael@0: * guaranteed to work stably from release to release. michael@0: */ michael@0: class U_I18N_API DateFormat : public Format { michael@0: public: michael@0: michael@0: /** michael@0: * Constants for various style patterns. These reflect the order of items in michael@0: * the DateTimePatterns resource. There are 4 time patterns, 4 date patterns, michael@0: * the default date-time pattern, and 4 date-time patterns. Each block of 4 values michael@0: * in the resource occurs in the order full, long, medium, short. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: enum EStyle michael@0: { michael@0: kNone = -1, michael@0: michael@0: kFull = 0, michael@0: kLong = 1, michael@0: kMedium = 2, michael@0: kShort = 3, michael@0: michael@0: kDateOffset = kShort + 1, michael@0: // kFull + kDateOffset = 4 michael@0: // kLong + kDateOffset = 5 michael@0: // kMedium + kDateOffset = 6 michael@0: // kShort + kDateOffset = 7 michael@0: michael@0: kDateTime = 8, michael@0: // Default DateTime michael@0: michael@0: kDateTimeOffset = kDateTime + 1, michael@0: // kFull + kDateTimeOffset = 9 michael@0: // kLong + kDateTimeOffset = 10 michael@0: // kMedium + kDateTimeOffset = 11 michael@0: // kShort + kDateTimeOffset = 12 michael@0: michael@0: // relative dates michael@0: kRelative = (1 << 7), michael@0: michael@0: kFullRelative = (kFull | kRelative), michael@0: michael@0: kLongRelative = kLong | kRelative, michael@0: michael@0: kMediumRelative = kMedium | kRelative, michael@0: michael@0: kShortRelative = kShort | kRelative, michael@0: michael@0: michael@0: kDefault = kMedium, michael@0: michael@0: michael@0: michael@0: /** michael@0: * These constants are provided for backwards compatibility only. michael@0: * Please use the C++ style constants defined above. michael@0: */ michael@0: FULL = kFull, michael@0: LONG = kLong, michael@0: MEDIUM = kMedium, michael@0: SHORT = kShort, michael@0: DEFAULT = kDefault, michael@0: DATE_OFFSET = kDateOffset, michael@0: NONE = kNone, michael@0: DATE_TIME = kDateTime michael@0: }; michael@0: michael@0: /** michael@0: * Destructor. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual ~DateFormat(); michael@0: michael@0: /** michael@0: * Equality operator. Returns true if the two formats have the same behavior. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UBool operator==(const Format&) const; michael@0: michael@0: michael@0: using Format::format; michael@0: michael@0: /** michael@0: * Format an object to produce a string. This method handles Formattable michael@0: * objects with a UDate type. If a the Formattable object type is not a Date, michael@0: * then it returns a failing UErrorCode. michael@0: * michael@0: * @param obj The object to format. Must be a Date. michael@0: * @param appendTo Output parameter to receive result. michael@0: * Result is appended to existing contents. michael@0: * @param pos On input: an alignment field, if desired. michael@0: * On output: the offsets of the alignment field. michael@0: * @param status Output param filled with success/failure status. michael@0: * @return Reference to 'appendTo' parameter. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UnicodeString& format(const Formattable& obj, michael@0: UnicodeString& appendTo, michael@0: FieldPosition& pos, michael@0: UErrorCode& status) const; michael@0: michael@0: /** michael@0: * Format an object to produce a string. This method handles Formattable michael@0: * objects with a UDate type. If a the Formattable object type is not a Date, michael@0: * then it returns a failing UErrorCode. michael@0: * michael@0: * @param obj The object to format. Must be a Date. michael@0: * @param appendTo Output parameter to receive result. michael@0: * Result is appended to existing contents. michael@0: * @param posIter On return, can be used to iterate over positions michael@0: * of fields generated by this format call. Field values michael@0: * are defined in UDateFormatField. Can be NULL. michael@0: * @param status Output param filled with success/failure status. michael@0: * @return Reference to 'appendTo' parameter. michael@0: * @stable ICU 4.4 michael@0: */ michael@0: virtual UnicodeString& format(const Formattable& obj, michael@0: UnicodeString& appendTo, michael@0: FieldPositionIterator* posIter, michael@0: UErrorCode& status) const; michael@0: /** michael@0: * Formats a date into a date/time string. This is an abstract method which michael@0: * concrete subclasses must implement. michael@0: *

michael@0: * On input, the FieldPosition parameter may have its "field" member filled with michael@0: * an enum value specifying a field. On output, the FieldPosition will be filled michael@0: * in with the text offsets for that field. michael@0: *

For example, given a time text michael@0: * "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition.field is michael@0: * UDAT_YEAR_FIELD, the offsets fieldPosition.beginIndex and michael@0: * statfieldPositionus.getEndIndex will be set to 0 and 4, respectively. michael@0: *

Notice michael@0: * that if the same time field appears more than once in a pattern, the status will michael@0: * be set for the first occurence of that time field. For instance, michael@0: * formatting a UDate to the time string "1 PM PDT (Pacific Daylight Time)" michael@0: * using the pattern "h a z (zzzz)" and the alignment field michael@0: * DateFormat::TIMEZONE_FIELD, the offsets fieldPosition.beginIndex and michael@0: * fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first michael@0: * occurence of the timezone pattern character 'z'. michael@0: * michael@0: * @param cal Calendar set to the date and time to be formatted michael@0: * into a date/time string. When the calendar type is michael@0: * different from the internal calendar held by this michael@0: * DateFormat instance, the date and the time zone will michael@0: * be inherited from the input calendar, but other calendar michael@0: * field values will be calculated by the internal calendar. michael@0: * @param appendTo Output parameter to receive result. michael@0: * Result is appended to existing contents. michael@0: * @param fieldPosition On input: an alignment field, if desired (see examples above) michael@0: * On output: the offsets of the alignment field (see examples above) michael@0: * @return Reference to 'appendTo' parameter. michael@0: * @stable ICU 2.1 michael@0: */ michael@0: virtual UnicodeString& format( Calendar& cal, michael@0: UnicodeString& appendTo, michael@0: FieldPosition& fieldPosition) const = 0; michael@0: michael@0: /** michael@0: * Formats a date into a date/time string. Subclasses should implement this method. michael@0: * michael@0: * @param cal Calendar set to the date and time to be formatted michael@0: * into a date/time string. When the calendar type is michael@0: * different from the internal calendar held by this michael@0: * DateFormat instance, the date and the time zone will michael@0: * be inherited from the input calendar, but other calendar michael@0: * field values will be calculated by the internal calendar. michael@0: * @param appendTo Output parameter to receive result. michael@0: * Result is appended to existing contents. michael@0: * @param posIter On return, can be used to iterate over positions michael@0: * of fields generated by this format call. Field values michael@0: * are defined in UDateFormatField. Can be NULL. michael@0: * @param status error status. michael@0: * @return Reference to 'appendTo' parameter. michael@0: * @stable ICU 4.4 michael@0: */ michael@0: virtual UnicodeString& format(Calendar& cal, michael@0: UnicodeString& appendTo, michael@0: FieldPositionIterator* posIter, michael@0: UErrorCode& status) const; michael@0: /** michael@0: * Formats a UDate into a date/time string. michael@0: *

michael@0: * On input, the FieldPosition parameter may have its "field" member filled with michael@0: * an enum value specifying a field. On output, the FieldPosition will be filled michael@0: * in with the text offsets for that field. michael@0: *

For example, given a time text michael@0: * "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition.field is michael@0: * UDAT_YEAR_FIELD, the offsets fieldPosition.beginIndex and michael@0: * statfieldPositionus.getEndIndex will be set to 0 and 4, respectively. michael@0: *

Notice michael@0: * that if the same time field appears more than once in a pattern, the status will michael@0: * be set for the first occurence of that time field. For instance, michael@0: * formatting a UDate to the time string "1 PM PDT (Pacific Daylight Time)" michael@0: * using the pattern "h a z (zzzz)" and the alignment field michael@0: * DateFormat::TIMEZONE_FIELD, the offsets fieldPosition.beginIndex and michael@0: * fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first michael@0: * occurence of the timezone pattern character 'z'. michael@0: * michael@0: * @param date UDate to be formatted into a date/time string. michael@0: * @param appendTo Output parameter to receive result. michael@0: * Result is appended to existing contents. michael@0: * @param fieldPosition On input: an alignment field, if desired (see examples above) michael@0: * On output: the offsets of the alignment field (see examples above) michael@0: * @return Reference to 'appendTo' parameter. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& format( UDate date, michael@0: UnicodeString& appendTo, michael@0: FieldPosition& fieldPosition) const; michael@0: michael@0: /** michael@0: * Formats a UDate into a date/time string. michael@0: * michael@0: * @param date UDate to be formatted into a date/time string. michael@0: * @param appendTo Output parameter to receive result. michael@0: * Result is appended to existing contents. michael@0: * @param posIter On return, can be used to iterate over positions michael@0: * of fields generated by this format call. Field values michael@0: * are defined in UDateFormatField. Can be NULL. michael@0: * @param status error status. michael@0: * @return Reference to 'appendTo' parameter. michael@0: * @stable ICU 4.4 michael@0: */ michael@0: UnicodeString& format(UDate date, michael@0: UnicodeString& appendTo, michael@0: FieldPositionIterator* posIter, michael@0: UErrorCode& status) const; michael@0: /** michael@0: * Formats a UDate into a date/time string. If there is a problem, you won't michael@0: * know, using this method. Use the overloaded format() method which takes a michael@0: * FieldPosition& to detect formatting problems. michael@0: * michael@0: * @param date The UDate value to be formatted into a string. michael@0: * @param appendTo Output parameter to receive result. michael@0: * Result is appended to existing contents. michael@0: * @return Reference to 'appendTo' parameter. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& format(UDate date, UnicodeString& appendTo) const; michael@0: michael@0: /** michael@0: * Parse a date/time string. For example, a time text "07/10/96 4:5 PM, PDT" michael@0: * will be parsed into a UDate that is equivalent to Date(837039928046). michael@0: * Parsing begins at the beginning of the string and proceeds as far as michael@0: * possible. Assuming no parse errors were encountered, this function michael@0: * doesn't return any information about how much of the string was consumed michael@0: * by the parsing. If you need that information, use the version of michael@0: * parse() that takes a ParsePosition. michael@0: *

michael@0: * By default, parsing is lenient: If the input is not in the form used by michael@0: * this object's format method but can still be parsed as a date, then the michael@0: * parse succeeds. Clients may insist on strict adherence to the format by michael@0: * calling setLenient(false). michael@0: * @see DateFormat::setLenient(boolean) michael@0: *

michael@0: * Note that the normal date formats associated with some calendars - such michael@0: * as the Chinese lunar calendar - do not specify enough fields to enable michael@0: * dates to be parsed unambiguously. In the case of the Chinese lunar michael@0: * calendar, while the year within the current 60-year cycle is specified, michael@0: * the number of such cycles since the start date of the calendar (in the michael@0: * ERA field of the Calendar object) is not normally part of the format, michael@0: * and parsing may assume the wrong era. For cases such as this it is michael@0: * recommended that clients parse using the method michael@0: * parse(const UnicodeString&, Calendar& cal, ParsePosition&) michael@0: * with the Calendar passed in set to the current date, or to a date michael@0: * within the era/cycle that should be assumed if absent in the format. michael@0: * michael@0: * @param text The date/time string to be parsed into a UDate value. michael@0: * @param status Output param to be set to success/failure code. If michael@0: * 'text' cannot be parsed, it will be set to a failure michael@0: * code. michael@0: * @return The parsed UDate value, if successful. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UDate parse( const UnicodeString& text, michael@0: UErrorCode& status) const; michael@0: michael@0: /** michael@0: * Parse a date/time string beginning at the given parse position. For michael@0: * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date michael@0: * that is equivalent to Date(837039928046). michael@0: *

michael@0: * By default, parsing is lenient: If the input is not in the form used by michael@0: * this object's format method but can still be parsed as a date, then the michael@0: * parse succeeds. Clients may insist on strict adherence to the format by michael@0: * calling setLenient(false). michael@0: * @see DateFormat::setLenient(boolean) michael@0: * michael@0: * @param text The date/time string to be parsed. michael@0: * @param cal A Calendar set on input to the date and time to be used for michael@0: * missing values in the date/time string being parsed, and set michael@0: * on output to the parsed date/time. When the calendar type is michael@0: * different from the internal calendar held by this DateFormat michael@0: * instance, the internal calendar will be cloned to a work michael@0: * calendar set to the same milliseconds and time zone as the michael@0: * cal parameter, field values will be parsed based on the work michael@0: * calendar, then the result (milliseconds and time zone) will michael@0: * be set in this calendar. michael@0: * @param pos On input, the position at which to start parsing; on michael@0: * output, the position at which parsing terminated, or the michael@0: * start position if the parse failed. michael@0: * @stable ICU 2.1 michael@0: */ michael@0: virtual void parse( const UnicodeString& text, michael@0: Calendar& cal, michael@0: ParsePosition& pos) const = 0; michael@0: michael@0: /** michael@0: * Parse a date/time string beginning at the given parse position. For michael@0: * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date michael@0: * that is equivalent to Date(837039928046). michael@0: *

michael@0: * By default, parsing is lenient: If the input is not in the form used by michael@0: * this object's format method but can still be parsed as a date, then the michael@0: * parse succeeds. Clients may insist on strict adherence to the format by michael@0: * calling setLenient(false). michael@0: * @see DateFormat::setLenient(boolean) michael@0: *

michael@0: * Note that the normal date formats associated with some calendars - such michael@0: * as the Chinese lunar calendar - do not specify enough fields to enable michael@0: * dates to be parsed unambiguously. In the case of the Chinese lunar michael@0: * calendar, while the year within the current 60-year cycle is specified, michael@0: * the number of such cycles since the start date of the calendar (in the michael@0: * ERA field of the Calendar object) is not normally part of the format, michael@0: * and parsing may assume the wrong era. For cases such as this it is michael@0: * recommended that clients parse using the method michael@0: * parse(const UnicodeString&, Calendar& cal, ParsePosition&) michael@0: * with the Calendar passed in set to the current date, or to a date michael@0: * within the era/cycle that should be assumed if absent in the format. michael@0: * michael@0: * @param text The date/time string to be parsed into a UDate value. michael@0: * @param pos On input, the position at which to start parsing; on michael@0: * output, the position at which parsing terminated, or the michael@0: * start position if the parse failed. michael@0: * @return A valid UDate if the input could be parsed. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UDate parse( const UnicodeString& text, michael@0: ParsePosition& pos) const; michael@0: michael@0: /** michael@0: * Parse a string to produce an object. This methods handles parsing of michael@0: * date/time strings into Formattable objects with UDate types. michael@0: *

michael@0: * Before calling, set parse_pos.index to the offset you want to start michael@0: * parsing at in the source. After calling, parse_pos.index is the end of michael@0: * the text you parsed. If error occurs, index is unchanged. michael@0: *

michael@0: * When parsing, leading whitespace is discarded (with a successful parse), michael@0: * while trailing whitespace is left as is. michael@0: *

michael@0: * See Format::parseObject() for more. michael@0: * michael@0: * @param source The string to be parsed into an object. michael@0: * @param result Formattable to be set to the parse result. michael@0: * If parse fails, return contents are undefined. michael@0: * @param parse_pos The position to start parsing at. Upon return michael@0: * this param is set to the position after the michael@0: * last character successfully parsed. If the michael@0: * source is not parsed successfully, this param michael@0: * will remain unchanged. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void parseObject(const UnicodeString& source, michael@0: Formattable& result, michael@0: ParsePosition& parse_pos) const; michael@0: michael@0: /** michael@0: * Create a default date/time formatter that uses the SHORT style for both michael@0: * the date and the time. michael@0: * michael@0: * @return A date/time formatter which the caller owns. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static DateFormat* U_EXPORT2 createInstance(void); michael@0: michael@0: /** michael@0: * Creates a time formatter with the given formatting style for the given michael@0: * locale. michael@0: * michael@0: * @param style The given formatting style. For example, michael@0: * SHORT for "h:mm a" in the US locale. Relative michael@0: * time styles are not currently supported. michael@0: * @param aLocale The given locale. michael@0: * @return A time formatter which the caller owns. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static DateFormat* U_EXPORT2 createTimeInstance(EStyle style = kDefault, michael@0: const Locale& aLocale = Locale::getDefault()); michael@0: michael@0: /** michael@0: * Creates a date formatter with the given formatting style for the given michael@0: * const locale. michael@0: * michael@0: * @param style The given formatting style. For example, SHORT for "M/d/yy" in the michael@0: * US locale. As currently implemented, relative date formatting only michael@0: * affects a limited range of calendar days before or after the michael@0: * current date, based on the CLDR <field type="day">/<relative> data: michael@0: * For example, in English, "Yesterday", "Today", and "Tomorrow". michael@0: * Outside of this range, dates are formatted using the corresponding michael@0: * non-relative style. michael@0: * @param aLocale The given locale. michael@0: * @return A date formatter which the caller owns. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static DateFormat* U_EXPORT2 createDateInstance(EStyle style = kDefault, michael@0: const Locale& aLocale = Locale::getDefault()); michael@0: michael@0: /** michael@0: * Creates a date/time formatter with the given formatting styles for the michael@0: * given locale. michael@0: * michael@0: * @param dateStyle The given formatting style for the date portion of the result. michael@0: * For example, SHORT for "M/d/yy" in the US locale. As currently michael@0: * implemented, relative date formatting only affects a limited range michael@0: * of calendar days before or after the current date, based on the michael@0: * CLDR <field type="day">/<relative> data: For example, in English, michael@0: * "Yesterday", "Today", and "Tomorrow". Outside of this range, dates michael@0: * are formatted using the corresponding non-relative style. michael@0: * @param timeStyle The given formatting style for the time portion of the result. michael@0: * For example, SHORT for "h:mm a" in the US locale. Relative michael@0: * time styles are not currently supported. michael@0: * @param aLocale The given locale. michael@0: * @return A date/time formatter which the caller owns. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static DateFormat* U_EXPORT2 createDateTimeInstance(EStyle dateStyle = kDefault, michael@0: EStyle timeStyle = kDefault, michael@0: const Locale& aLocale = Locale::getDefault()); michael@0: michael@0: /** michael@0: * Gets the set of locales for which DateFormats are installed. michael@0: * @param count Filled in with the number of locales in the list that is returned. michael@0: * @return the set of locales for which DateFormats are installed. The caller michael@0: * does NOT own this list and must not delete it. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count); michael@0: michael@0: /** michael@0: * Returns true if the encapsulated Calendar object is set for lenient parsing. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UBool isLenient(void) const; michael@0: michael@0: /** michael@0: * Specify whether or not date/time parsing is to be lenient. With lenient michael@0: * parsing, the parser may use heuristics to interpret inputs that do not michael@0: * precisely match this object's format. With strict parsing, inputs must michael@0: * match this object's format. michael@0: * michael@0: * Note: This method is specific to the encapsulated Calendar object. DateFormat michael@0: * leniency aspects are controlled by setBooleanAttribute. michael@0: * michael@0: * @param lenient True specifies date/time interpretation to be lenient. michael@0: * @see Calendar::setLenient michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void setLenient(UBool lenient); michael@0: michael@0: /** michael@0: * Gets the calendar associated with this date/time formatter. michael@0: * @return the calendar associated with this date/time formatter. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual const Calendar* getCalendar(void) const; michael@0: michael@0: /** michael@0: * Set the calendar to be used by this date format. Initially, the default michael@0: * calendar for the specified or default locale is used. The caller should michael@0: * not delete the Calendar object after it is adopted by this call. michael@0: * Adopting a new calendar will change to the default symbols. michael@0: * michael@0: * @param calendarToAdopt Calendar object to be adopted. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void adoptCalendar(Calendar* calendarToAdopt); michael@0: michael@0: /** michael@0: * Set the calendar to be used by this date format. Initially, the default michael@0: * calendar for the specified or default locale is used. michael@0: * michael@0: * @param newCalendar Calendar object to be set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void setCalendar(const Calendar& newCalendar); michael@0: michael@0: michael@0: /** michael@0: * Gets the number formatter which this date/time formatter uses to format michael@0: * and parse the numeric portions of the pattern. michael@0: * @return the number formatter which this date/time formatter uses. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual const NumberFormat* getNumberFormat(void) const; michael@0: michael@0: /** michael@0: * Allows you to set the number formatter. The caller should michael@0: * not delete the NumberFormat object after it is adopted by this call. michael@0: * @param formatToAdopt NumberFormat object to be adopted. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void adoptNumberFormat(NumberFormat* formatToAdopt); michael@0: michael@0: /** michael@0: * Allows you to set the number formatter. michael@0: * @param newNumberFormat NumberFormat object to be set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void setNumberFormat(const NumberFormat& newNumberFormat); michael@0: michael@0: /** michael@0: * Returns a reference to the TimeZone used by this DateFormat's calendar. michael@0: * @return the time zone associated with the calendar of DateFormat. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual const TimeZone& getTimeZone(void) const; michael@0: michael@0: /** michael@0: * Sets the time zone for the calendar of this DateFormat object. The caller michael@0: * no longer owns the TimeZone object and should not delete it after this call. michael@0: * @param zoneToAdopt the TimeZone to be adopted. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void adoptTimeZone(TimeZone* zoneToAdopt); michael@0: michael@0: /** michael@0: * Sets the time zone for the calendar of this DateFormat object. michael@0: * @param zone the new time zone. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void setTimeZone(const TimeZone& zone); michael@0: michael@0: /** michael@0: * Set an boolean attribute on this DateFormat. michael@0: * May return U_UNSUPPORTED_ERROR if this instance does not support michael@0: * the specified attribute. michael@0: * @param attr the attribute to set michael@0: * @param newvalue new value michael@0: * @param status the error type michael@0: * @return *this - for chaining (example: format.setAttribute(...).setAttribute(...) ) michael@0: * @internal ICU technology preview michael@0: */ michael@0: michael@0: virtual DateFormat& U_EXPORT2 setBooleanAttribute(UDateFormatBooleanAttribute attr, michael@0: UBool newvalue, michael@0: UErrorCode &status); michael@0: michael@0: /** michael@0: * Get an boolean from this DateFormat michael@0: * May return U_UNSUPPORTED_ERROR if this instance does not support michael@0: * the specified attribute. michael@0: * @param attr the attribute to set michael@0: * @param status the error type michael@0: * @return the attribute value. Undefined if there is an error. michael@0: * @internal ICU technology preview michael@0: */ michael@0: virtual UBool U_EXPORT2 getBooleanAttribute(UDateFormatBooleanAttribute attr, UErrorCode &status) const; michael@0: michael@0: protected: michael@0: /** michael@0: * Default constructor. Creates a DateFormat with no Calendar or NumberFormat michael@0: * associated with it. This constructor depends on the subclasses to fill in michael@0: * the calendar and numberFormat fields. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: DateFormat(); michael@0: michael@0: /** michael@0: * Copy constructor. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: DateFormat(const DateFormat&); michael@0: michael@0: /** michael@0: * Default assignment operator. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: DateFormat& operator=(const DateFormat&); michael@0: michael@0: /** michael@0: * The calendar that DateFormat uses to produce the time field values needed michael@0: * to implement date/time formatting. Subclasses should generally initialize michael@0: * this to the default calendar for the locale associated with this DateFormat. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: Calendar* fCalendar; michael@0: michael@0: /** michael@0: * The number formatter that DateFormat uses to format numbers in dates and michael@0: * times. Subclasses should generally initialize this to the default number michael@0: * format for the locale associated with this DateFormat. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: NumberFormat* fNumberFormat; michael@0: michael@0: michael@0: private: michael@0: /** michael@0: * Gets the date/time formatter with the given formatting styles for the michael@0: * given locale. michael@0: * @param dateStyle the given date formatting style. michael@0: * @param timeStyle the given time formatting style. michael@0: * @param inLocale the given locale. michael@0: * @return a date/time formatter, or 0 on failure. michael@0: */ michael@0: static DateFormat* U_EXPORT2 create(EStyle timeStyle, EStyle dateStyle, const Locale& inLocale); michael@0: michael@0: michael@0: /** michael@0: * enum set of active boolean attributes for this instance michael@0: */ michael@0: EnumSet fBoolFlags; michael@0: michael@0: michael@0: public: michael@0: #ifndef U_HIDE_OBSOLETE_API michael@0: /** michael@0: * Field selector for FieldPosition for DateFormat fields. michael@0: * @obsolete ICU 3.4 use UDateFormatField instead, since this API will be michael@0: * removed in that release michael@0: */ michael@0: enum EField michael@0: { michael@0: // Obsolete; use UDateFormatField instead michael@0: kEraField = UDAT_ERA_FIELD, michael@0: kYearField = UDAT_YEAR_FIELD, michael@0: kMonthField = UDAT_MONTH_FIELD, michael@0: kDateField = UDAT_DATE_FIELD, michael@0: kHourOfDay1Field = UDAT_HOUR_OF_DAY1_FIELD, michael@0: kHourOfDay0Field = UDAT_HOUR_OF_DAY0_FIELD, michael@0: kMinuteField = UDAT_MINUTE_FIELD, michael@0: kSecondField = UDAT_SECOND_FIELD, michael@0: kMillisecondField = UDAT_FRACTIONAL_SECOND_FIELD, michael@0: kDayOfWeekField = UDAT_DAY_OF_WEEK_FIELD, michael@0: kDayOfYearField = UDAT_DAY_OF_YEAR_FIELD, michael@0: kDayOfWeekInMonthField = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD, michael@0: kWeekOfYearField = UDAT_WEEK_OF_YEAR_FIELD, michael@0: kWeekOfMonthField = UDAT_WEEK_OF_MONTH_FIELD, michael@0: kAmPmField = UDAT_AM_PM_FIELD, michael@0: kHour1Field = UDAT_HOUR1_FIELD, michael@0: kHour0Field = UDAT_HOUR0_FIELD, michael@0: kTimezoneField = UDAT_TIMEZONE_FIELD, michael@0: kYearWOYField = UDAT_YEAR_WOY_FIELD, michael@0: kDOWLocalField = UDAT_DOW_LOCAL_FIELD, michael@0: kExtendedYearField = UDAT_EXTENDED_YEAR_FIELD, michael@0: kJulianDayField = UDAT_JULIAN_DAY_FIELD, michael@0: kMillisecondsInDayField = UDAT_MILLISECONDS_IN_DAY_FIELD, michael@0: michael@0: // Obsolete; use UDateFormatField instead michael@0: ERA_FIELD = UDAT_ERA_FIELD, michael@0: YEAR_FIELD = UDAT_YEAR_FIELD, michael@0: MONTH_FIELD = UDAT_MONTH_FIELD, michael@0: DATE_FIELD = UDAT_DATE_FIELD, michael@0: HOUR_OF_DAY1_FIELD = UDAT_HOUR_OF_DAY1_FIELD, michael@0: HOUR_OF_DAY0_FIELD = UDAT_HOUR_OF_DAY0_FIELD, michael@0: MINUTE_FIELD = UDAT_MINUTE_FIELD, michael@0: SECOND_FIELD = UDAT_SECOND_FIELD, michael@0: MILLISECOND_FIELD = UDAT_FRACTIONAL_SECOND_FIELD, michael@0: DAY_OF_WEEK_FIELD = UDAT_DAY_OF_WEEK_FIELD, michael@0: DAY_OF_YEAR_FIELD = UDAT_DAY_OF_YEAR_FIELD, michael@0: DAY_OF_WEEK_IN_MONTH_FIELD = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD, michael@0: WEEK_OF_YEAR_FIELD = UDAT_WEEK_OF_YEAR_FIELD, michael@0: WEEK_OF_MONTH_FIELD = UDAT_WEEK_OF_MONTH_FIELD, michael@0: AM_PM_FIELD = UDAT_AM_PM_FIELD, michael@0: HOUR1_FIELD = UDAT_HOUR1_FIELD, michael@0: HOUR0_FIELD = UDAT_HOUR0_FIELD, michael@0: TIMEZONE_FIELD = UDAT_TIMEZONE_FIELD michael@0: }; michael@0: #endif /* U_HIDE_OBSOLETE_API */ michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: michael@0: #endif // _DATEFMT michael@0: //eof