|
||||
Warning, file /include/unicode/datefmt.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /* 0004 ******************************************************************************** 0005 * Copyright (C) 1997-2016, International Business Machines 0006 * Corporation and others. All Rights Reserved. 0007 ******************************************************************************** 0008 * 0009 * File DATEFMT.H 0010 * 0011 * Modification History: 0012 * 0013 * Date Name Description 0014 * 02/19/97 aliu Converted from java. 0015 * 04/01/97 aliu Added support for centuries. 0016 * 07/23/98 stephen JDK 1.2 sync 0017 * 11/15/99 weiv Added support for week of year/day of week formatting 0018 ******************************************************************************** 0019 */ 0020 0021 #ifndef DATEFMT_H 0022 #define DATEFMT_H 0023 0024 #include "unicode/utypes.h" 0025 0026 #if U_SHOW_CPLUSPLUS_API 0027 0028 #if !UCONFIG_NO_FORMATTING 0029 0030 #include "unicode/udat.h" 0031 #include "unicode/calendar.h" 0032 #include "unicode/numfmt.h" 0033 #include "unicode/format.h" 0034 #include "unicode/locid.h" 0035 #include "unicode/enumset.h" 0036 #include "unicode/udisplaycontext.h" 0037 0038 /** 0039 * \file 0040 * \brief C++ API: Abstract class for converting dates. 0041 */ 0042 0043 U_NAMESPACE_BEGIN 0044 0045 class TimeZone; 0046 class DateTimePatternGenerator; 0047 0048 /** 0049 * \cond 0050 * Export an explicit template instantiation. (See digitlst.h, datefmt.h, and others.) 0051 * (When building DLLs for Windows this is required.) 0052 */ 0053 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN && !defined(U_IN_DOXYGEN) 0054 template class U_I18N_API EnumSet<UDateFormatBooleanAttribute, 0055 0, 0056 UDAT_BOOLEAN_ATTRIBUTE_COUNT>; 0057 #endif 0058 /** \endcond */ 0059 0060 /** 0061 * DateFormat is an abstract class for a family of classes that convert dates and 0062 * times from their internal representations to textual form and back again in a 0063 * language-independent manner. Converting from the internal representation (milliseconds 0064 * since midnight, January 1, 1970) to text is known as "formatting," and converting 0065 * from text to millis is known as "parsing." We currently define only one concrete 0066 * subclass of DateFormat: SimpleDateFormat, which can handle pretty much all normal 0067 * date formatting and parsing actions. 0068 * <P> 0069 * DateFormat helps you to format and parse dates for any locale. Your code can 0070 * be completely independent of the locale conventions for months, days of the 0071 * week, or even the calendar format: lunar vs. solar. 0072 * <P> 0073 * To format a date for the current Locale, use one of the static factory 0074 * methods: 0075 * <pre> 0076 * \code 0077 * DateFormat* dfmt = DateFormat::createDateInstance(); 0078 * UDate myDate = Calendar::getNow(); 0079 * UnicodeString myString; 0080 * myString = dfmt->format( myDate, myString ); 0081 * \endcode 0082 * </pre> 0083 * If you are formatting multiple numbers, it is more efficient to get the 0084 * format and use it multiple times so that the system doesn't have to fetch the 0085 * information about the local language and country conventions multiple times. 0086 * <pre> 0087 * \code 0088 * DateFormat* df = DateFormat::createDateInstance(); 0089 * UnicodeString myString; 0090 * UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values 0091 * for (int32_t i = 0; i < 3; ++i) { 0092 * myString.remove(); 0093 * cout << df->format( myDateArr[i], myString ) << endl; 0094 * } 0095 * \endcode 0096 * </pre> 0097 * To get specific fields of a date, you can use UFieldPosition to 0098 * get specific fields. 0099 * <pre> 0100 * \code 0101 * DateFormat* dfmt = DateFormat::createDateInstance(); 0102 * FieldPosition pos(DateFormat::YEAR_FIELD); 0103 * UnicodeString myString; 0104 * myString = dfmt->format( myDate, myString ); 0105 * cout << myString << endl; 0106 * cout << pos.getBeginIndex() << "," << pos. getEndIndex() << endl; 0107 * \endcode 0108 * </pre> 0109 * To format a date for a different Locale, specify it in the call to 0110 * createDateInstance(). 0111 * <pre> 0112 * \code 0113 * DateFormat* df = 0114 * DateFormat::createDateInstance( DateFormat::SHORT, Locale::getFrance()); 0115 * \endcode 0116 * </pre> 0117 * You can use a DateFormat to parse also. 0118 * <pre> 0119 * \code 0120 * UErrorCode status = U_ZERO_ERROR; 0121 * UDate myDate = df->parse(myString, status); 0122 * \endcode 0123 * </pre> 0124 * Use createDateInstance() to produce the normal date format for that country. 0125 * There are other static factory methods available. Use createTimeInstance() 0126 * to produce the normal time format for that country. Use createDateTimeInstance() 0127 * to produce a DateFormat that formats both date and time. You can pass in 0128 * different options to these factory methods to control the length of the 0129 * result; from SHORT to MEDIUM to LONG to FULL. The exact result depends on the 0130 * locale, but generally: 0131 * <ul type=round> 0132 * <li> SHORT is completely numeric, such as 12/13/52 or 3:30pm 0133 * <li> MEDIUM is longer, such as Jan 12, 1952 0134 * <li> LONG is longer, such as January 12, 1952 or 3:30:32pm 0135 * <li> FULL is pretty completely specified, such as 0136 * Tuesday, April 12, 1952 AD or 3:30:42pm PST. 0137 * </ul> 0138 * You can also set the time zone on the format if you wish. If you want even 0139 * more control over the format or parsing, (or want to give your users more 0140 * control), you can try casting the DateFormat you get from the factory methods 0141 * to a SimpleDateFormat. This will work for the majority of countries; just 0142 * remember to check getDynamicClassID() before carrying out the cast. 0143 * <P> 0144 * You can also use forms of the parse and format methods with ParsePosition and 0145 * FieldPosition to allow you to 0146 * <ul type=round> 0147 * <li> Progressively parse through pieces of a string. 0148 * <li> Align any particular field, or find out where it is for selection 0149 * on the screen. 0150 * </ul> 0151 * 0152 * <p><em>User subclasses are not supported.</em> While clients may write 0153 * subclasses, such code will not necessarily work and will not be 0154 * guaranteed to work stably from release to release. 0155 */ 0156 class U_I18N_API DateFormat : public Format { 0157 public: 0158 0159 /** 0160 * Constants for various style patterns. These reflect the order of items in 0161 * the DateTimePatterns resource. There are 4 time patterns, 4 date patterns, 0162 * the default date-time pattern, and 4 date-time patterns. Each block of 4 values 0163 * in the resource occurs in the order full, long, medium, short. 0164 * @stable ICU 2.4 0165 */ 0166 enum EStyle 0167 { 0168 kNone = -1, 0169 0170 kFull = 0, 0171 kLong = 1, 0172 kMedium = 2, 0173 kShort = 3, 0174 0175 kDateOffset = kShort + 1, 0176 // kFull + kDateOffset = 4 0177 // kLong + kDateOffset = 5 0178 // kMedium + kDateOffset = 6 0179 // kShort + kDateOffset = 7 0180 0181 kDateTime = 8, 0182 // Default DateTime 0183 0184 kDateTimeOffset = kDateTime + 1, 0185 // kFull + kDateTimeOffset = 9 0186 // kLong + kDateTimeOffset = 10 0187 // kMedium + kDateTimeOffset = 11 0188 // kShort + kDateTimeOffset = 12 0189 0190 // relative dates 0191 kRelative = (1 << 7), 0192 0193 kFullRelative = (kFull | kRelative), 0194 0195 kLongRelative = kLong | kRelative, 0196 0197 kMediumRelative = kMedium | kRelative, 0198 0199 kShortRelative = kShort | kRelative, 0200 0201 0202 kDefault = kMedium, 0203 0204 0205 0206 /** 0207 * These constants are provided for backwards compatibility only. 0208 * Please use the C++ style constants defined above. 0209 */ 0210 FULL = kFull, 0211 LONG = kLong, 0212 MEDIUM = kMedium, 0213 SHORT = kShort, 0214 DEFAULT = kDefault, 0215 DATE_OFFSET = kDateOffset, 0216 NONE = kNone, 0217 DATE_TIME = kDateTime 0218 }; 0219 0220 /** 0221 * Destructor. 0222 * @stable ICU 2.0 0223 */ 0224 virtual ~DateFormat(); 0225 0226 /** 0227 * Clones this object polymorphically. 0228 * The caller owns the result and should delete it when done. 0229 * @return clone, or nullptr if an error occurred 0230 * @stable ICU 2.0 0231 */ 0232 virtual DateFormat* clone() const override = 0; 0233 0234 /** 0235 * Equality operator. Returns true if the two formats have the same behavior. 0236 * @stable ICU 2.0 0237 */ 0238 virtual bool operator==(const Format&) const override; 0239 0240 0241 using Format::format; 0242 0243 /** 0244 * Format an object to produce a string. This method handles Formattable 0245 * objects with a UDate type. If a the Formattable object type is not a Date, 0246 * then it returns a failing UErrorCode. 0247 * 0248 * @param obj The object to format. Must be a Date. 0249 * @param appendTo Output parameter to receive result. 0250 * Result is appended to existing contents. 0251 * @param pos On input: an alignment field, if desired. 0252 * On output: the offsets of the alignment field. 0253 * @param status Output param filled with success/failure status. 0254 * @return Reference to 'appendTo' parameter. 0255 * @stable ICU 2.0 0256 */ 0257 virtual UnicodeString& format(const Formattable& obj, 0258 UnicodeString& appendTo, 0259 FieldPosition& pos, 0260 UErrorCode& status) const override; 0261 0262 /** 0263 * Format an object to produce a string. This method handles Formattable 0264 * objects with a UDate type. If a the Formattable object type is not a Date, 0265 * then it returns a failing UErrorCode. 0266 * 0267 * @param obj The object to format. Must be a Date. 0268 * @param appendTo Output parameter to receive result. 0269 * Result is appended to existing contents. 0270 * @param posIter On return, can be used to iterate over positions 0271 * of fields generated by this format call. Field values 0272 * are defined in UDateFormatField. Can be nullptr. 0273 * @param status Output param filled with success/failure status. 0274 * @return Reference to 'appendTo' parameter. 0275 * @stable ICU 4.4 0276 */ 0277 virtual UnicodeString& format(const Formattable& obj, 0278 UnicodeString& appendTo, 0279 FieldPositionIterator* posIter, 0280 UErrorCode& status) const override; 0281 /** 0282 * Formats a date into a date/time string. This is an abstract method which 0283 * concrete subclasses must implement. 0284 * <P> 0285 * On input, the FieldPosition parameter may have its "field" member filled with 0286 * an enum value specifying a field. On output, the FieldPosition will be filled 0287 * in with the text offsets for that field. 0288 * <P> For example, given a time text 0289 * "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition.field is 0290 * UDAT_YEAR_FIELD, the offsets fieldPosition.beginIndex and 0291 * statfieldPositionus.getEndIndex will be set to 0 and 4, respectively. 0292 * <P> Notice 0293 * that if the same time field appears more than once in a pattern, the status will 0294 * be set for the first occurrence of that time field. For instance, 0295 * formatting a UDate to the time string "1 PM PDT (Pacific Daylight Time)" 0296 * using the pattern "h a z (zzzz)" and the alignment field 0297 * DateFormat::TIMEZONE_FIELD, the offsets fieldPosition.beginIndex and 0298 * fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first 0299 * occurrence of the timezone pattern character 'z'. 0300 * 0301 * @param cal Calendar set to the date and time to be formatted 0302 * into a date/time string. When the calendar type is 0303 * different from the internal calendar held by this 0304 * DateFormat instance, the date and the time zone will 0305 * be inherited from the input calendar, but other calendar 0306 * field values will be calculated by the internal calendar. 0307 * @param appendTo Output parameter to receive result. 0308 * Result is appended to existing contents. 0309 * @param fieldPosition On input: an alignment field, if desired (see examples above) 0310 * On output: the offsets of the alignment field (see examples above) 0311 * @return Reference to 'appendTo' parameter. 0312 * @stable ICU 2.1 0313 */ 0314 virtual UnicodeString& format( Calendar& cal, 0315 UnicodeString& appendTo, 0316 FieldPosition& fieldPosition) const = 0; 0317 0318 /** 0319 * Formats a date into a date/time string. Subclasses should implement this method. 0320 * 0321 * @param cal Calendar set to the date and time to be formatted 0322 * into a date/time string. When the calendar type is 0323 * different from the internal calendar held by this 0324 * DateFormat instance, the date and the time zone will 0325 * be inherited from the input calendar, but other calendar 0326 * field values will be calculated by the internal calendar. 0327 * @param appendTo Output parameter to receive result. 0328 * Result is appended to existing contents. 0329 * @param posIter On return, can be used to iterate over positions 0330 * of fields generated by this format call. Field values 0331 * are defined in UDateFormatField. Can be nullptr. 0332 * @param status error status. 0333 * @return Reference to 'appendTo' parameter. 0334 * @stable ICU 4.4 0335 */ 0336 virtual UnicodeString& format(Calendar& cal, 0337 UnicodeString& appendTo, 0338 FieldPositionIterator* posIter, 0339 UErrorCode& status) const; 0340 /** 0341 * Formats a UDate into a date/time string. 0342 * <P> 0343 * On input, the FieldPosition parameter may have its "field" member filled with 0344 * an enum value specifying a field. On output, the FieldPosition will be filled 0345 * in with the text offsets for that field. 0346 * <P> For example, given a time text 0347 * "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition.field is 0348 * UDAT_YEAR_FIELD, the offsets fieldPosition.beginIndex and 0349 * statfieldPositionus.getEndIndex will be set to 0 and 4, respectively. 0350 * <P> Notice 0351 * that if the same time field appears more than once in a pattern, the status will 0352 * be set for the first occurrence of that time field. For instance, 0353 * formatting a UDate to the time string "1 PM PDT (Pacific Daylight Time)" 0354 * using the pattern "h a z (zzzz)" and the alignment field 0355 * DateFormat::TIMEZONE_FIELD, the offsets fieldPosition.beginIndex and 0356 * fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first 0357 * occurrence of the timezone pattern character 'z'. 0358 * 0359 * @param date UDate to be formatted into a date/time string. 0360 * @param appendTo Output parameter to receive result. 0361 * Result is appended to existing contents. 0362 * @param fieldPosition On input: an alignment field, if desired (see examples above) 0363 * On output: the offsets of the alignment field (see examples above) 0364 * @return Reference to 'appendTo' parameter. 0365 * @stable ICU 2.0 0366 */ 0367 UnicodeString& format( UDate date, 0368 UnicodeString& appendTo, 0369 FieldPosition& fieldPosition) const; 0370 0371 /** 0372 * Formats a UDate into a date/time string. 0373 * 0374 * @param date UDate to be formatted into a date/time string. 0375 * @param appendTo Output parameter to receive result. 0376 * Result is appended to existing contents. 0377 * @param posIter On return, can be used to iterate over positions 0378 * of fields generated by this format call. Field values 0379 * are defined in UDateFormatField. Can be nullptr. 0380 * @param status error status. 0381 * @return Reference to 'appendTo' parameter. 0382 * @stable ICU 4.4 0383 */ 0384 UnicodeString& format(UDate date, 0385 UnicodeString& appendTo, 0386 FieldPositionIterator* posIter, 0387 UErrorCode& status) const; 0388 /** 0389 * Formats a UDate into a date/time string. If there is a problem, you won't 0390 * know, using this method. Use the overloaded format() method which takes a 0391 * FieldPosition& to detect formatting problems. 0392 * 0393 * @param date The UDate value to be formatted into a string. 0394 * @param appendTo Output parameter to receive result. 0395 * Result is appended to existing contents. 0396 * @return Reference to 'appendTo' parameter. 0397 * @stable ICU 2.0 0398 */ 0399 UnicodeString& format(UDate date, UnicodeString& appendTo) const; 0400 0401 /** 0402 * Parse a date/time string. For example, a time text "07/10/96 4:5 PM, PDT" 0403 * will be parsed into a UDate that is equivalent to Date(837039928046). 0404 * Parsing begins at the beginning of the string and proceeds as far as 0405 * possible. Assuming no parse errors were encountered, this function 0406 * doesn't return any information about how much of the string was consumed 0407 * by the parsing. If you need that information, use the version of 0408 * parse() that takes a ParsePosition. 0409 * <P> 0410 * By default, parsing is lenient: If the input is not in the form used by 0411 * this object's format method but can still be parsed as a date, then the 0412 * parse succeeds. Clients may insist on strict adherence to the format by 0413 * calling setLenient(false). 0414 * @see DateFormat::setLenient(boolean) 0415 * <P> 0416 * Note that the normal date formats associated with some calendars - such 0417 * as the Chinese lunar calendar - do not specify enough fields to enable 0418 * dates to be parsed unambiguously. In the case of the Chinese lunar 0419 * calendar, while the year within the current 60-year cycle is specified, 0420 * the number of such cycles since the start date of the calendar (in the 0421 * ERA field of the Calendar object) is not normally part of the format, 0422 * and parsing may assume the wrong era. For cases such as this it is 0423 * recommended that clients parse using the method 0424 * parse(const UnicodeString&, Calendar& cal, ParsePosition&) 0425 * with the Calendar passed in set to the current date, or to a date 0426 * within the era/cycle that should be assumed if absent in the format. 0427 * 0428 * @param text The date/time string to be parsed into a UDate value. 0429 * @param status Output param to be set to success/failure code. If 0430 * 'text' cannot be parsed, it will be set to a failure 0431 * code. 0432 * @return The parsed UDate value, if successful. 0433 * @stable ICU 2.0 0434 */ 0435 virtual UDate parse( const UnicodeString& text, 0436 UErrorCode& status) const; 0437 0438 /** 0439 * Parse a date/time string beginning at the given parse position. For 0440 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date 0441 * that is equivalent to Date(837039928046). 0442 * <P> 0443 * By default, parsing is lenient: If the input is not in the form used by 0444 * this object's format method but can still be parsed as a date, then the 0445 * parse succeeds. Clients may insist on strict adherence to the format by 0446 * calling setLenient(false). 0447 * @see DateFormat::setLenient(boolean) 0448 * 0449 * @param text The date/time string to be parsed. 0450 * @param cal A Calendar set on input to the date and time to be used for 0451 * missing values in the date/time string being parsed, and set 0452 * on output to the parsed date/time. When the calendar type is 0453 * different from the internal calendar held by this DateFormat 0454 * instance, the internal calendar will be cloned to a work 0455 * calendar set to the same milliseconds and time zone as the 0456 * cal parameter, field values will be parsed based on the work 0457 * calendar, then the result (milliseconds and time zone) will 0458 * be set in this calendar. 0459 * @param pos On input, the position at which to start parsing; on 0460 * output, the position at which parsing terminated, or the 0461 * start position if the parse failed. 0462 * @stable ICU 2.1 0463 */ 0464 virtual void parse( const UnicodeString& text, 0465 Calendar& cal, 0466 ParsePosition& pos) const = 0; 0467 0468 /** 0469 * Parse a date/time string beginning at the given parse position. For 0470 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date 0471 * that is equivalent to Date(837039928046). 0472 * <P> 0473 * By default, parsing is lenient: If the input is not in the form used by 0474 * this object's format method but can still be parsed as a date, then the 0475 * parse succeeds. Clients may insist on strict adherence to the format by 0476 * calling setLenient(false). 0477 * @see DateFormat::setLenient(boolean) 0478 * <P> 0479 * Note that the normal date formats associated with some calendars - such 0480 * as the Chinese lunar calendar - do not specify enough fields to enable 0481 * dates to be parsed unambiguously. In the case of the Chinese lunar 0482 * calendar, while the year within the current 60-year cycle is specified, 0483 * the number of such cycles since the start date of the calendar (in the 0484 * ERA field of the Calendar object) is not normally part of the format, 0485 * and parsing may assume the wrong era. For cases such as this it is 0486 * recommended that clients parse using the method 0487 * parse(const UnicodeString&, Calendar& cal, ParsePosition&) 0488 * with the Calendar passed in set to the current date, or to a date 0489 * within the era/cycle that should be assumed if absent in the format. 0490 * 0491 * @param text The date/time string to be parsed into a UDate value. 0492 * @param pos On input, the position at which to start parsing; on 0493 * output, the position at which parsing terminated, or the 0494 * start position if the parse failed. 0495 * @return A valid UDate if the input could be parsed. 0496 * @stable ICU 2.0 0497 */ 0498 UDate parse( const UnicodeString& text, 0499 ParsePosition& pos) const; 0500 0501 /** 0502 * Parse a string to produce an object. This methods handles parsing of 0503 * date/time strings into Formattable objects with UDate types. 0504 * <P> 0505 * Before calling, set parse_pos.index to the offset you want to start 0506 * parsing at in the source. After calling, parse_pos.index is the end of 0507 * the text you parsed. If error occurs, index is unchanged. 0508 * <P> 0509 * When parsing, leading whitespace is discarded (with a successful parse), 0510 * while trailing whitespace is left as is. 0511 * <P> 0512 * See Format::parseObject() for more. 0513 * 0514 * @param source The string to be parsed into an object. 0515 * @param result Formattable to be set to the parse result. 0516 * If parse fails, return contents are undefined. 0517 * @param parse_pos The position to start parsing at. Upon return 0518 * this param is set to the position after the 0519 * last character successfully parsed. If the 0520 * source is not parsed successfully, this param 0521 * will remain unchanged. 0522 * @stable ICU 2.0 0523 */ 0524 virtual void parseObject(const UnicodeString& source, 0525 Formattable& result, 0526 ParsePosition& parse_pos) const override; 0527 0528 /** 0529 * Create a default date/time formatter that uses the SHORT style for both 0530 * the date and the time. 0531 * 0532 * @return A date/time formatter which the caller owns. 0533 * @stable ICU 2.0 0534 */ 0535 static DateFormat* U_EXPORT2 createInstance(void); 0536 0537 /** 0538 * Creates a time formatter with the given formatting style for the given 0539 * locale. 0540 * 0541 * @param style The given formatting style. For example, 0542 * SHORT for "h:mm a" in the US locale. Relative 0543 * time styles are not currently supported. 0544 * @param aLocale The given locale. 0545 * @return A time formatter which the caller owns. 0546 * @stable ICU 2.0 0547 */ 0548 static DateFormat* U_EXPORT2 createTimeInstance(EStyle style = kDefault, 0549 const Locale& aLocale = Locale::getDefault()); 0550 0551 /** 0552 * Creates a date formatter with the given formatting style for the given 0553 * const locale. 0554 * 0555 * @param style The given formatting style. For example, SHORT for "M/d/yy" in the 0556 * US locale. As currently implemented, relative date formatting only 0557 * affects a limited range of calendar days before or after the 0558 * current date, based on the CLDR <field type="day">/<relative> data: 0559 * For example, in English, "Yesterday", "Today", and "Tomorrow". 0560 * Outside of this range, dates are formatted using the corresponding 0561 * non-relative style. 0562 * @param aLocale The given locale. 0563 * @return A date formatter which the caller owns. 0564 * @stable ICU 2.0 0565 */ 0566 static DateFormat* U_EXPORT2 createDateInstance(EStyle style = kDefault, 0567 const Locale& aLocale = Locale::getDefault()); 0568 0569 /** 0570 * Creates a date/time formatter with the given formatting styles for the 0571 * given locale. 0572 * 0573 * @param dateStyle The given formatting style for the date portion of the result. 0574 * For example, SHORT for "M/d/yy" in the US locale. As currently 0575 * implemented, relative date formatting only affects a limited range 0576 * of calendar days before or after the current date, based on the 0577 * CLDR <field type="day">/<relative> data: For example, in English, 0578 * "Yesterday", "Today", and "Tomorrow". Outside of this range, dates 0579 * are formatted using the corresponding non-relative style. 0580 * @param timeStyle The given formatting style for the time portion of the result. 0581 * For example, SHORT for "h:mm a" in the US locale. Relative 0582 * time styles are not currently supported. 0583 * @param aLocale The given locale. 0584 * @return A date/time formatter which the caller owns. 0585 * @stable ICU 2.0 0586 */ 0587 static DateFormat* U_EXPORT2 createDateTimeInstance(EStyle dateStyle = kDefault, 0588 EStyle timeStyle = kDefault, 0589 const Locale& aLocale = Locale::getDefault()); 0590 0591 #ifndef U_HIDE_INTERNAL_API 0592 /** 0593 * Returns the best pattern given a skeleton and locale. 0594 * @param locale the locale 0595 * @param skeleton the skeleton 0596 * @param status ICU error returned here 0597 * @return the best pattern. 0598 * @internal For ICU use only. 0599 */ 0600 static UnicodeString getBestPattern( 0601 const Locale &locale, 0602 const UnicodeString &skeleton, 0603 UErrorCode &status); 0604 #endif /* U_HIDE_INTERNAL_API */ 0605 0606 /** 0607 * Creates a date/time formatter for the given skeleton and 0608 * default locale. 0609 * 0610 * @param skeleton The skeleton e.g "yMMMMd." Fields in the skeleton can 0611 * be in any order, and this method uses the locale to 0612 * map the skeleton to a pattern that includes locale 0613 * specific separators with the fields in the appropriate 0614 * order for that locale. 0615 * @param status Any error returned here. 0616 * @return A date/time formatter which the caller owns. 0617 * @stable ICU 55 0618 */ 0619 static DateFormat* U_EXPORT2 createInstanceForSkeleton( 0620 const UnicodeString& skeleton, 0621 UErrorCode &status); 0622 0623 /** 0624 * Creates a date/time formatter for the given skeleton and locale. 0625 * 0626 * @param skeleton The skeleton e.g "yMMMMd." Fields in the skeleton can 0627 * be in any order, and this method uses the locale to 0628 * map the skeleton to a pattern that includes locale 0629 * specific separators with the fields in the appropriate 0630 * order for that locale. 0631 * @param locale The given locale. 0632 * @param status Any error returned here. 0633 * @return A date/time formatter which the caller owns. 0634 * @stable ICU 55 0635 */ 0636 static DateFormat* U_EXPORT2 createInstanceForSkeleton( 0637 const UnicodeString& skeleton, 0638 const Locale &locale, 0639 UErrorCode &status); 0640 0641 /** 0642 * Creates a date/time formatter for the given skeleton and locale. 0643 * 0644 * @param calendarToAdopt the calendar returned DateFormat is to use. 0645 * @param skeleton The skeleton e.g "yMMMMd." Fields in the skeleton can 0646 * be in any order, and this method uses the locale to 0647 * map the skeleton to a pattern that includes locale 0648 * specific separators with the fields in the appropriate 0649 * order for that locale. 0650 * @param locale The given locale. 0651 * @param status Any error returned here. 0652 * @return A date/time formatter which the caller owns. 0653 * @stable ICU 55 0654 */ 0655 static DateFormat* U_EXPORT2 createInstanceForSkeleton( 0656 Calendar *calendarToAdopt, 0657 const UnicodeString& skeleton, 0658 const Locale &locale, 0659 UErrorCode &status); 0660 0661 0662 /** 0663 * Gets the set of locales for which DateFormats are installed. 0664 * @param count Filled in with the number of locales in the list that is returned. 0665 * @return the set of locales for which DateFormats are installed. The caller 0666 * does NOT own this list and must not delete it. 0667 * @stable ICU 2.0 0668 */ 0669 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count); 0670 0671 /** 0672 * Returns whether both date/time parsing in the encapsulated Calendar object and DateFormat whitespace & 0673 * numeric processing is lenient. 0674 * @stable ICU 2.0 0675 */ 0676 virtual UBool isLenient(void) const; 0677 0678 /** 0679 * Specifies whether date/time parsing is to be lenient. With 0680 * lenient parsing, the parser may use heuristics to interpret inputs that 0681 * do not precisely match this object's format. Without lenient parsing, 0682 * inputs must match this object's format more closely. 0683 * 0684 * Note: ICU 53 introduced finer grained control of leniency (and added 0685 * new control points) making the preferred method a combination of 0686 * setCalendarLenient() & setBooleanAttribute() calls. 0687 * This method supports prior functionality but may not support all 0688 * future leniency control & behavior of DateFormat. For control of pre 53 leniency, 0689 * Calendar and DateFormat whitespace & numeric tolerance, this method is safe to 0690 * use. However, mixing leniency control via this method and modification of the 0691 * newer attributes via setBooleanAttribute() may produce undesirable 0692 * results. 0693 * 0694 * @param lenient True specifies date/time interpretation to be lenient. 0695 * @see Calendar::setLenient 0696 * @stable ICU 2.0 0697 */ 0698 virtual void setLenient(UBool lenient); 0699 0700 0701 /** 0702 * Returns whether date/time parsing in the encapsulated Calendar object processing is lenient. 0703 * @stable ICU 53 0704 */ 0705 virtual UBool isCalendarLenient(void) const; 0706 0707 0708 /** 0709 * Specifies whether encapsulated Calendar date/time parsing is to be lenient. With 0710 * lenient parsing, the parser may use heuristics to interpret inputs that 0711 * do not precisely match this object's format. Without lenient parsing, 0712 * inputs must match this object's format more closely. 0713 * @param lenient when true, parsing is lenient 0714 * @see com.ibm.icu.util.Calendar#setLenient 0715 * @stable ICU 53 0716 */ 0717 virtual void setCalendarLenient(UBool lenient); 0718 0719 0720 /** 0721 * Gets the calendar associated with this date/time formatter. 0722 * The calendar is owned by the formatter and must not be modified. 0723 * Also, the calendar does not reflect the results of a parse operation. 0724 * To parse to a calendar, use {@link #parse(const UnicodeString&, Calendar& cal, ParsePosition&) const parse(const UnicodeString&, Calendar& cal, ParsePosition&)} 0725 * @return the calendar associated with this date/time formatter. 0726 * @stable ICU 2.0 0727 */ 0728 virtual const Calendar* getCalendar(void) const; 0729 0730 /** 0731 * Set the calendar to be used by this date format. Initially, the default 0732 * calendar for the specified or default locale is used. The caller should 0733 * not delete the Calendar object after it is adopted by this call. 0734 * Adopting a new calendar will change to the default symbols. 0735 * 0736 * @param calendarToAdopt Calendar object to be adopted. 0737 * @stable ICU 2.0 0738 */ 0739 virtual void adoptCalendar(Calendar* calendarToAdopt); 0740 0741 /** 0742 * Set the calendar to be used by this date format. Initially, the default 0743 * calendar for the specified or default locale is used. 0744 * 0745 * @param newCalendar Calendar object to be set. 0746 * @stable ICU 2.0 0747 */ 0748 virtual void setCalendar(const Calendar& newCalendar); 0749 0750 0751 /** 0752 * Gets the number formatter which this date/time formatter uses to format 0753 * and parse the numeric portions of the pattern. 0754 * @return the number formatter which this date/time formatter uses. 0755 * @stable ICU 2.0 0756 */ 0757 virtual const NumberFormat* getNumberFormat(void) const; 0758 0759 /** 0760 * Allows you to set the number formatter. The caller should 0761 * not delete the NumberFormat object after it is adopted by this call. 0762 * @param formatToAdopt NumberFormat object to be adopted. 0763 * @stable ICU 2.0 0764 */ 0765 virtual void adoptNumberFormat(NumberFormat* formatToAdopt); 0766 0767 /** 0768 * Allows you to set the number formatter. 0769 * @param newNumberFormat NumberFormat object to be set. 0770 * @stable ICU 2.0 0771 */ 0772 virtual void setNumberFormat(const NumberFormat& newNumberFormat); 0773 0774 /** 0775 * Returns a reference to the TimeZone used by this DateFormat's calendar. 0776 * @return the time zone associated with the calendar of DateFormat. 0777 * @stable ICU 2.0 0778 */ 0779 virtual const TimeZone& getTimeZone(void) const; 0780 0781 /** 0782 * Sets the time zone for the calendar of this DateFormat object. The caller 0783 * no longer owns the TimeZone object and should not delete it after this call. 0784 * @param zoneToAdopt the TimeZone to be adopted. 0785 * @stable ICU 2.0 0786 */ 0787 virtual void adoptTimeZone(TimeZone* zoneToAdopt); 0788 0789 /** 0790 * Sets the time zone for the calendar of this DateFormat object. 0791 * @param zone the new time zone. 0792 * @stable ICU 2.0 0793 */ 0794 virtual void setTimeZone(const TimeZone& zone); 0795 0796 /** 0797 * Set a particular UDisplayContext value in the formatter, such as 0798 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. 0799 * @param value The UDisplayContext value to set. 0800 * @param status Input/output status. If at entry this indicates a failure 0801 * status, the function will do nothing; otherwise this will be 0802 * updated with any new status from the function. 0803 * @stable ICU 53 0804 */ 0805 virtual void setContext(UDisplayContext value, UErrorCode& status); 0806 0807 /** 0808 * Get the formatter's UDisplayContext value for the specified UDisplayContextType, 0809 * such as UDISPCTX_TYPE_CAPITALIZATION. 0810 * @param type The UDisplayContextType whose value to return 0811 * @param status Input/output status. If at entry this indicates a failure 0812 * status, the function will do nothing; otherwise this will be 0813 * updated with any new status from the function. 0814 * @return The UDisplayContextValue for the specified type. 0815 * @stable ICU 53 0816 */ 0817 virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const; 0818 0819 /** 0820 * Sets an boolean attribute on this DateFormat. 0821 * May return U_UNSUPPORTED_ERROR if this instance does not support 0822 * the specified attribute. 0823 * @param attr the attribute to set 0824 * @param newvalue new value 0825 * @param status the error type 0826 * @return *this - for chaining (example: format.setAttribute(...).setAttribute(...) ) 0827 * @stable ICU 53 0828 */ 0829 0830 virtual DateFormat& U_EXPORT2 setBooleanAttribute(UDateFormatBooleanAttribute attr, 0831 UBool newvalue, 0832 UErrorCode &status); 0833 0834 /** 0835 * Returns a boolean from this DateFormat 0836 * May return U_UNSUPPORTED_ERROR if this instance does not support 0837 * the specified attribute. 0838 * @param attr the attribute to set 0839 * @param status the error type 0840 * @return the attribute value. Undefined if there is an error. 0841 * @stable ICU 53 0842 */ 0843 virtual UBool U_EXPORT2 getBooleanAttribute(UDateFormatBooleanAttribute attr, UErrorCode &status) const; 0844 0845 protected: 0846 /** 0847 * Default constructor. Creates a DateFormat with no Calendar or NumberFormat 0848 * associated with it. This constructor depends on the subclasses to fill in 0849 * the calendar and numberFormat fields. 0850 * @stable ICU 2.0 0851 */ 0852 DateFormat(); 0853 0854 /** 0855 * Copy constructor. 0856 * @stable ICU 2.0 0857 */ 0858 DateFormat(const DateFormat&); 0859 0860 /** 0861 * Default assignment operator. 0862 * @stable ICU 2.0 0863 */ 0864 DateFormat& operator=(const DateFormat&); 0865 0866 /** 0867 * The calendar that DateFormat uses to produce the time field values needed 0868 * to implement date/time formatting. Subclasses should generally initialize 0869 * this to the default calendar for the locale associated with this DateFormat. 0870 * @stable ICU 2.4 0871 */ 0872 Calendar* fCalendar; 0873 0874 /** 0875 * The number formatter that DateFormat uses to format numbers in dates and 0876 * times. Subclasses should generally initialize this to the default number 0877 * format for the locale associated with this DateFormat. 0878 * @stable ICU 2.4 0879 */ 0880 NumberFormat* fNumberFormat; 0881 0882 0883 private: 0884 0885 /** 0886 * Gets the date/time formatter with the given formatting styles for the 0887 * given locale. 0888 * @param dateStyle the given date formatting style. 0889 * @param timeStyle the given time formatting style. 0890 * @param inLocale the given locale. 0891 * @return a date/time formatter, or 0 on failure. 0892 */ 0893 static DateFormat* U_EXPORT2 create(EStyle timeStyle, EStyle dateStyle, const Locale& inLocale); 0894 0895 0896 /** 0897 * enum set of active boolean attributes for this instance 0898 */ 0899 EnumSet<UDateFormatBooleanAttribute, 0, UDAT_BOOLEAN_ATTRIBUTE_COUNT> fBoolFlags; 0900 0901 0902 UDisplayContext fCapitalizationContext; 0903 friend class DateFmtKeyByStyle; 0904 0905 public: 0906 #ifndef U_HIDE_OBSOLETE_API 0907 /** 0908 * Field selector for FieldPosition for DateFormat fields. 0909 * @obsolete ICU 3.4 use UDateFormatField instead, since this API will be 0910 * removed in that release 0911 */ 0912 enum EField 0913 { 0914 // Obsolete; use UDateFormatField instead 0915 kEraField = UDAT_ERA_FIELD, 0916 kYearField = UDAT_YEAR_FIELD, 0917 kMonthField = UDAT_MONTH_FIELD, 0918 kDateField = UDAT_DATE_FIELD, 0919 kHourOfDay1Field = UDAT_HOUR_OF_DAY1_FIELD, 0920 kHourOfDay0Field = UDAT_HOUR_OF_DAY0_FIELD, 0921 kMinuteField = UDAT_MINUTE_FIELD, 0922 kSecondField = UDAT_SECOND_FIELD, 0923 kMillisecondField = UDAT_FRACTIONAL_SECOND_FIELD, 0924 kDayOfWeekField = UDAT_DAY_OF_WEEK_FIELD, 0925 kDayOfYearField = UDAT_DAY_OF_YEAR_FIELD, 0926 kDayOfWeekInMonthField = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD, 0927 kWeekOfYearField = UDAT_WEEK_OF_YEAR_FIELD, 0928 kWeekOfMonthField = UDAT_WEEK_OF_MONTH_FIELD, 0929 kAmPmField = UDAT_AM_PM_FIELD, 0930 kHour1Field = UDAT_HOUR1_FIELD, 0931 kHour0Field = UDAT_HOUR0_FIELD, 0932 kTimezoneField = UDAT_TIMEZONE_FIELD, 0933 kYearWOYField = UDAT_YEAR_WOY_FIELD, 0934 kDOWLocalField = UDAT_DOW_LOCAL_FIELD, 0935 kExtendedYearField = UDAT_EXTENDED_YEAR_FIELD, 0936 kJulianDayField = UDAT_JULIAN_DAY_FIELD, 0937 kMillisecondsInDayField = UDAT_MILLISECONDS_IN_DAY_FIELD, 0938 0939 // Obsolete; use UDateFormatField instead 0940 ERA_FIELD = UDAT_ERA_FIELD, 0941 YEAR_FIELD = UDAT_YEAR_FIELD, 0942 MONTH_FIELD = UDAT_MONTH_FIELD, 0943 DATE_FIELD = UDAT_DATE_FIELD, 0944 HOUR_OF_DAY1_FIELD = UDAT_HOUR_OF_DAY1_FIELD, 0945 HOUR_OF_DAY0_FIELD = UDAT_HOUR_OF_DAY0_FIELD, 0946 MINUTE_FIELD = UDAT_MINUTE_FIELD, 0947 SECOND_FIELD = UDAT_SECOND_FIELD, 0948 MILLISECOND_FIELD = UDAT_FRACTIONAL_SECOND_FIELD, 0949 DAY_OF_WEEK_FIELD = UDAT_DAY_OF_WEEK_FIELD, 0950 DAY_OF_YEAR_FIELD = UDAT_DAY_OF_YEAR_FIELD, 0951 DAY_OF_WEEK_IN_MONTH_FIELD = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD, 0952 WEEK_OF_YEAR_FIELD = UDAT_WEEK_OF_YEAR_FIELD, 0953 WEEK_OF_MONTH_FIELD = UDAT_WEEK_OF_MONTH_FIELD, 0954 AM_PM_FIELD = UDAT_AM_PM_FIELD, 0955 HOUR1_FIELD = UDAT_HOUR1_FIELD, 0956 HOUR0_FIELD = UDAT_HOUR0_FIELD, 0957 TIMEZONE_FIELD = UDAT_TIMEZONE_FIELD 0958 }; 0959 #endif /* U_HIDE_OBSOLETE_API */ 0960 }; 0961 0962 U_NAMESPACE_END 0963 0964 #endif /* #if !UCONFIG_NO_FORMATTING */ 0965 0966 #endif /* U_SHOW_CPLUSPLUS_API */ 0967 0968 #endif // _DATEFMT 0969 //eof
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |