michael@0: /* michael@0: * Copyright (C) 1997-2013, International Business Machines Corporation and michael@0: * others. All Rights Reserved. michael@0: ******************************************************************************* michael@0: * michael@0: * File SMPDTFMT.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: * 07/09/97 helena Make ParsePosition into a class. michael@0: * 07/21/98 stephen Added GMT_PLUS, GMT_MINUS michael@0: * Changed setTwoDigitStartDate to set2DigitYearStart michael@0: * Changed getTwoDigitStartDate to get2DigitYearStart michael@0: * Removed subParseLong michael@0: * Removed getZoneIndex (added in DateFormatSymbols) michael@0: * 06/14/99 stephen Removed fgTimeZoneDataSuffix michael@0: * 10/14/99 aliu Updated class doc to describe 2-digit year parsing michael@0: * {j28 4182066}. michael@0: ******************************************************************************* michael@0: */ michael@0: michael@0: #ifndef SMPDTFMT_H michael@0: #define SMPDTFMT_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: Format and parse dates in a language-independent manner. michael@0: */ michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/datefmt.h" michael@0: #include "unicode/udisplaycontext.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class DateFormatSymbols; michael@0: class DateFormat; michael@0: class MessageFormat; michael@0: class FieldPositionHandler; michael@0: class TimeZoneFormat; michael@0: michael@0: /** michael@0: * michael@0: * SimpleDateFormat is a concrete class for formatting and parsing dates in a michael@0: * language-independent manner. It allows for formatting (millis -> text), michael@0: * parsing (text -> millis), and normalization. Formats/Parses a date or time, michael@0: * which is the standard milliseconds since 24:00 GMT, Jan 1, 1970. michael@0: *
michael@0: * Clients are encouraged to create a date-time formatter using DateFormat::getInstance(), michael@0: * getDateInstance(), getDateInstance(), or getDateTimeInstance() rather than michael@0: * explicitly constructing an instance of SimpleDateFormat. This way, the client michael@0: * is guaranteed to get an appropriate formatting pattern for whatever locale the michael@0: * program is running in. However, if the client needs something more unusual than michael@0: * the default patterns in the locales, he can construct a SimpleDateFormat directly michael@0: * and give it an appropriate pattern (or use one of the factory methods on DateFormat michael@0: * and modify the pattern after the fact with toPattern() and applyPattern(). michael@0: * michael@0: *
Date and Time Patterns:
michael@0: * michael@0: *Date and time formats are specified by date and time pattern strings.
michael@0: * Within date and time pattern strings, all unquoted ASCII letters [A-Za-z] are reserved
michael@0: * as pattern letters representing calendar fields. SimpleDateFormat
supports
michael@0: * the date and time formatting algorithm and pattern letters defined by
michael@0: * UTS#35
michael@0: * Unicode Locale Data Markup Language (LDML) and further documented for ICU in the
michael@0: * ICU
michael@0: * User Guide. The following pattern letters are currently available:
Field | michael@0: *Sym. | michael@0: *No. | michael@0: *Example | michael@0: *Description | michael@0: *||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
era | michael@0: *G | michael@0: *1..3 | michael@0: *AD | michael@0: *Era - Replaced with the Era string for the current date. One to three letters for the michael@0: * abbreviated form, four letters for the long form, five for the narrow form. | michael@0: *||||||||||||||||||||||||||||||||||||
4 | michael@0: *Anno Domini | michael@0: *|||||||||||||||||||||||||||||||||||||||
5 | michael@0: *A | michael@0: *|||||||||||||||||||||||||||||||||||||||
year | michael@0: *y | michael@0: *1..n | michael@0: *1996 | michael@0: *Year. Normally the length specifies the padding, but for two letters it also specifies the maximum
michael@0: * length. Example:
michael@0: *
michael@0: *
|
michael@0: * ||||||||||||||||||||||||||||||||||||
Y | michael@0: *1..n | michael@0: *1997 | michael@0: *Year (in "Week of Year" based calendars). Normally the length specifies the padding, michael@0: * but for two letters it also specifies the maximum length. This year designation is used in ISO michael@0: * year-week calendar as defined by ISO 8601, but can be used in non-Gregorian based calendar systems michael@0: * where week date processing is desired. May not always be the same value as calendar year. | michael@0: *|||||||||||||||||||||||||||||||||||||
u | michael@0: *1..n | michael@0: *4601 | michael@0: *Extended year. This is a single number designating the year of this calendar system, encompassing michael@0: * all supra-year fields. For example, for the Julian calendar system, year numbers are positive, with an michael@0: * era of BCE or CE. An extended year value for the Julian calendar system assigns positive values to CE michael@0: * years and negative values to BCE years, with 1 BCE being year 0. | michael@0: *|||||||||||||||||||||||||||||||||||||
U | michael@0: *1..3 | michael@0: *甲子 | michael@0: *Cyclic year name. Calendars such as the Chinese lunar calendar (and related calendars) michael@0: * and the Hindu calendars use 60-year cycles of year names. Use one through three letters for the abbreviated michael@0: * name, four for the full name, or five for the narrow name (currently the data only provides abbreviated names, michael@0: * which will be used for all requested name widths). If the calendar does not provide cyclic year name data, michael@0: * or if the year value to be formatted is out of the range of years for which cyclic name data is provided, michael@0: * then numeric formatting is used (behaves like 'y'). | michael@0: *|||||||||||||||||||||||||||||||||||||
4 | michael@0: *(currently also 甲子) | michael@0: *|||||||||||||||||||||||||||||||||||||||
5 | michael@0: *(currently also 甲子) | michael@0: *|||||||||||||||||||||||||||||||||||||||
quarter | michael@0: *Q | michael@0: *1..2 | michael@0: *02 | michael@0: *Quarter - Use one or two for the numerical quarter, three for the abbreviation, or four michael@0: * for the full name. | michael@0: *||||||||||||||||||||||||||||||||||||
3 | michael@0: *Q2 | michael@0: *|||||||||||||||||||||||||||||||||||||||
4 | michael@0: *2nd quarter | michael@0: *|||||||||||||||||||||||||||||||||||||||
q | michael@0: *1..2 | michael@0: *02 | michael@0: *Stand-Alone Quarter - Use one or two for the numerical quarter, three for the abbreviation, michael@0: * or four for the full name. | michael@0: *|||||||||||||||||||||||||||||||||||||
3 | michael@0: *Q2 | michael@0: *|||||||||||||||||||||||||||||||||||||||
4 | michael@0: *2nd quarter | michael@0: *|||||||||||||||||||||||||||||||||||||||
month | michael@0: *M | michael@0: *1..2 | michael@0: *09 | michael@0: *Month - Use one or two for the numerical month, three for the abbreviation, four for michael@0: * the full name, or five for the narrow name. | michael@0: *||||||||||||||||||||||||||||||||||||
3 | michael@0: *Sept | michael@0: *|||||||||||||||||||||||||||||||||||||||
4 | michael@0: *September | michael@0: *|||||||||||||||||||||||||||||||||||||||
5 | michael@0: *S | michael@0: *|||||||||||||||||||||||||||||||||||||||
L | michael@0: *1..2 | michael@0: *09 | michael@0: *Stand-Alone Month - Use one or two for the numerical month, three for the abbreviation, michael@0: * or four for the full name, or 5 for the narrow name. | michael@0: *|||||||||||||||||||||||||||||||||||||
3 | michael@0: *Sept | michael@0: *|||||||||||||||||||||||||||||||||||||||
4 | michael@0: *September | michael@0: *|||||||||||||||||||||||||||||||||||||||
5 | michael@0: *S | michael@0: *|||||||||||||||||||||||||||||||||||||||
week | michael@0: *w | michael@0: *1..2 | michael@0: *27 | michael@0: *Week of Year. | michael@0: *||||||||||||||||||||||||||||||||||||
W | michael@0: *1 | michael@0: *3 | michael@0: *Week of Month | michael@0: *|||||||||||||||||||||||||||||||||||||
day | michael@0: *d | michael@0: *1..2 | michael@0: *1 | michael@0: *Date - Day of the month | michael@0: *||||||||||||||||||||||||||||||||||||
D | michael@0: *1..3 | michael@0: *345 | michael@0: *Day of year | michael@0: *|||||||||||||||||||||||||||||||||||||
F | michael@0: *1 | michael@0: *2 | michael@0: *Day of Week in Month. The example is for the 2nd Wed in July | michael@0: *|||||||||||||||||||||||||||||||||||||
g | michael@0: *1..n | michael@0: *2451334 | michael@0: *Modified Julian day. This is different from the conventional Julian day number in two regards. michael@0: * First, it demarcates days at local zone midnight, rather than noon GMT. Second, it is a local number; michael@0: * that is, it depends on the local time zone. It can be thought of as a single number that encompasses michael@0: * all the date-related fields. | michael@0: *|||||||||||||||||||||||||||||||||||||
week michael@0: * day |
michael@0: * E | michael@0: *1..3 | michael@0: *Tues | michael@0: *Day of week - Use one through three letters for the short day, or four for the full name, michael@0: * five for the narrow name, or six for the short name. | michael@0: *||||||||||||||||||||||||||||||||||||
4 | michael@0: *Tuesday | michael@0: *|||||||||||||||||||||||||||||||||||||||
5 | michael@0: *T | michael@0: *|||||||||||||||||||||||||||||||||||||||
6 | michael@0: *Tu | michael@0: *|||||||||||||||||||||||||||||||||||||||
e | michael@0: *1..2 | michael@0: *2 | michael@0: *Local day of week. Same as E except adds a numeric value that will depend on the local michael@0: * starting day of the week, using one or two letters. For this example, Monday is the first day of the week. | michael@0: *|||||||||||||||||||||||||||||||||||||
3 | michael@0: *Tues | michael@0: *|||||||||||||||||||||||||||||||||||||||
4 | michael@0: *Tuesday | michael@0: *|||||||||||||||||||||||||||||||||||||||
5 | michael@0: *T | michael@0: *|||||||||||||||||||||||||||||||||||||||
6 | michael@0: *Tu | michael@0: *|||||||||||||||||||||||||||||||||||||||
c | michael@0: *1 | michael@0: *2 | michael@0: *Stand-Alone local day of week - Use one letter for the local numeric value (same michael@0: * as 'e'), three for the short day, four for the full name, five for the narrow name, or six for michael@0: * the short name. | michael@0: *|||||||||||||||||||||||||||||||||||||
3 | michael@0: *Tues | michael@0: *|||||||||||||||||||||||||||||||||||||||
4 | michael@0: *Tuesday | michael@0: *|||||||||||||||||||||||||||||||||||||||
5 | michael@0: *T | michael@0: *|||||||||||||||||||||||||||||||||||||||
6 | michael@0: *Tu | michael@0: *|||||||||||||||||||||||||||||||||||||||
period | michael@0: *a | michael@0: *1 | michael@0: *AM | michael@0: *AM or PM | michael@0: *||||||||||||||||||||||||||||||||||||
hour | michael@0: *h | michael@0: *1..2 | michael@0: *11 | michael@0: *Hour [1-12]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern michael@0: * generation, it should match the 12-hour-cycle format preferred by the locale (h or K); it should not match michael@0: * a 24-hour-cycle format (H or k). Use hh for zero padding. | michael@0: *||||||||||||||||||||||||||||||||||||
H | michael@0: *1..2 | michael@0: *13 | michael@0: *Hour [0-23]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern michael@0: * generation, it should match the 24-hour-cycle format preferred by the locale (H or k); it should not match a michael@0: * 12-hour-cycle format (h or K). Use HH for zero padding. | michael@0: *|||||||||||||||||||||||||||||||||||||
K | michael@0: *1..2 | michael@0: *0 | michael@0: *Hour [0-11]. When used in a skeleton, only matches K or h, see above. Use KK for zero padding. | michael@0: *|||||||||||||||||||||||||||||||||||||
k | michael@0: *1..2 | michael@0: *24 | michael@0: *Hour [1-24]. When used in a skeleton, only matches k or H, see above. Use kk for zero padding. | michael@0: *|||||||||||||||||||||||||||||||||||||
minute | michael@0: *m | michael@0: *1..2 | michael@0: *59 | michael@0: *Minute. Use one or two for zero padding. | michael@0: *||||||||||||||||||||||||||||||||||||
second | michael@0: *s | michael@0: *1..2 | michael@0: *12 | michael@0: *Second. Use one or two for zero padding. | michael@0: *||||||||||||||||||||||||||||||||||||
S | michael@0: *1..n | michael@0: *3456 | michael@0: *Fractional Second - truncates (like other time fields) to the count of letters. michael@0: * (example shows display using pattern SSSS for seconds value 12.34567) | michael@0: *|||||||||||||||||||||||||||||||||||||
A | michael@0: *1..n | michael@0: *69540000 | michael@0: *Milliseconds in day. This field behaves exactly like a composite of all time-related fields, michael@0: * not including the zone fields. As such, it also reflects discontinuities of those fields on DST transition michael@0: * days. On a day of DST onset, it will jump forward. On a day of DST cessation, it will jump backward. This michael@0: * reflects the fact that is must be combined with the offset field to obtain a unique local time value. | michael@0: *|||||||||||||||||||||||||||||||||||||
zone | michael@0: *z | michael@0: *1..3 | michael@0: *PDT | michael@0: *The short specific non-location format. michael@0: * Where that is unavailable, falls back to the short localized GMT format ("O"). | michael@0: *||||||||||||||||||||||||||||||||||||
4 | michael@0: *Pacific Daylight Time | michael@0: *The long specific non-location format. michael@0: * Where that is unavailable, falls back to the long localized GMT format ("OOOO"). | michael@0: *||||||||||||||||||||||||||||||||||||||
Z | michael@0: *1..3 | michael@0: *-0800 | michael@0: *The ISO8601 basic format with hours, minutes and optional seconds fields. michael@0: * The format is equivalent to RFC 822 zone format (when optional seconds field is absent). michael@0: * This is equivalent to the "xxxx" specifier. | michael@0: *|||||||||||||||||||||||||||||||||||||
4 | michael@0: *GMT-8:00 | michael@0: *The long localized GMT format. michael@0: * This is equivalent to the "OOOO" specifier. | michael@0: *||||||||||||||||||||||||||||||||||||||
5 | michael@0: *-08:00 michael@0: * -07:52:58 |
michael@0: * The ISO8601 extended format with hours, minutes and optional seconds fields. michael@0: * The ISO8601 UTC indicator "Z" is used when local time offset is 0. michael@0: * This is equivalent to the "XXXXX" specifier. | michael@0: *||||||||||||||||||||||||||||||||||||||
O | michael@0: *1 | michael@0: *GMT-8 | michael@0: *The short localized GMT format. | michael@0: *|||||||||||||||||||||||||||||||||||||
4 | michael@0: *GMT-08:00 | michael@0: *The long localized GMT format. | michael@0: *||||||||||||||||||||||||||||||||||||||
v | michael@0: *1 | michael@0: *PT | michael@0: *The short generic non-location format. michael@0: * Where that is unavailable, falls back to the generic location format ("VVVV"), michael@0: * then the short localized GMT format as the final fallback. | michael@0: *|||||||||||||||||||||||||||||||||||||
4 | michael@0: *Pacific Time | michael@0: *The long generic non-location format. michael@0: * Where that is unavailable, falls back to generic location format ("VVVV"). michael@0: * | ||||||||||||||||||||||||||||||||||||||
V | michael@0: *1 | michael@0: *uslax | michael@0: *The short time zone ID.
michael@0: * Where that is unavailable, the special short time zone ID unk (Unknown Zone) is used. michael@0: * Note: This specifier was originally used for a variant of the short specific non-location format, michael@0: * but it was deprecated in the later version of the LDML specification. In CLDR 23/ICU 51, the definition of michael@0: * the specifier was changed to designate a short time zone ID. |
michael@0: * |||||||||||||||||||||||||||||||||||||
2 | michael@0: *America/Los_Angeles | michael@0: *The long time zone ID. | michael@0: *||||||||||||||||||||||||||||||||||||||
3 | michael@0: *Los Angeles | michael@0: *The exemplar city (location) for the time zone. michael@0: * Where that is unavailable, the localized exemplar city name for the special zone Etc/Unknown is used michael@0: * as the fallback (for example, "Unknown City"). | michael@0: *||||||||||||||||||||||||||||||||||||||
4 | michael@0: *Los Angeles Time | michael@0: *The generic location format.
michael@0: * Where that is unavailable, falls back to the long localized GMT format ("OOOO";
michael@0: * Note: Fallback is only necessary with a GMT-style Time Zone ID, like Etc/GMT-830.) michael@0: * This is especially useful when presenting possible timezone choices for user selection, michael@0: * since the naming is more uniform than the "v" format. |
michael@0: * ||||||||||||||||||||||||||||||||||||||
X | michael@0: *1 | michael@0: *-08 michael@0: * +0530 michael@0: * Z |
michael@0: * The ISO8601 basic format with hours field and optional minutes field. michael@0: * The ISO8601 UTC indicator "Z" is used when local time offset is 0. | michael@0: *|||||||||||||||||||||||||||||||||||||
2 | michael@0: *-0800 michael@0: * Z |
michael@0: * The ISO8601 basic format with hours and minutes fields. michael@0: * The ISO8601 UTC indicator "Z" is used when local time offset is 0. | michael@0: *||||||||||||||||||||||||||||||||||||||
3 | michael@0: *-08:00 michael@0: * Z |
michael@0: * The ISO8601 extended format with hours and minutes fields. michael@0: * The ISO8601 UTC indicator "Z" is used when local time offset is 0. | michael@0: *||||||||||||||||||||||||||||||||||||||
4 | michael@0: *-0800 michael@0: * -075258 michael@0: * Z |
michael@0: * The ISO8601 basic format with hours, minutes and optional seconds fields. michael@0: * (Note: The seconds field is not supported by the ISO8601 specification.) michael@0: * The ISO8601 UTC indicator "Z" is used when local time offset is 0. | michael@0: *||||||||||||||||||||||||||||||||||||||
5 | michael@0: *-08:00 michael@0: * -07:52:58 michael@0: * Z |
michael@0: * The ISO8601 extended format with hours, minutes and optional seconds fields. michael@0: * (Note: The seconds field is not supported by the ISO8601 specification.) michael@0: * The ISO8601 UTC indicator "Z" is used when local time offset is 0. | michael@0: *||||||||||||||||||||||||||||||||||||||
x | michael@0: *1 | michael@0: *-08 michael@0: * +0530 |
michael@0: * The ISO8601 basic format with hours field and optional minutes field. | michael@0: *|||||||||||||||||||||||||||||||||||||
2 | michael@0: *-0800 | michael@0: *The ISO8601 basic format with hours and minutes fields. | michael@0: *||||||||||||||||||||||||||||||||||||||
3 | michael@0: *-08:00 | michael@0: *The ISO8601 extended format with hours and minutes fields. | michael@0: *||||||||||||||||||||||||||||||||||||||
4 | michael@0: *-0800 michael@0: * -075258 |
michael@0: * The ISO8601 basic format with hours, minutes and optional seconds fields. michael@0: * (Note: The seconds field is not supported by the ISO8601 specification.) | michael@0: *||||||||||||||||||||||||||||||||||||||
5 | michael@0: *-08:00 michael@0: * -07:52:58 |
michael@0: * The ISO8601 extended format with hours, minutes and optional seconds fields. michael@0: * (Note: The seconds field is not supported by the ISO8601 specification.) | michael@0: *
michael@0: * Any characters in the pattern that are not in the ranges of ['a'..'z'] and michael@0: * ['A'..'Z'] will be treated as quoted text. For instance, characters michael@0: * like ':', '.', ' ', '#' and '@' will appear in the resulting time text michael@0: * even they are not embraced within single quotes. michael@0: *
michael@0: * A pattern containing any invalid pattern letter will result in a failing michael@0: * UErrorCode result during formatting or parsing. michael@0: *
michael@0: * Examples using the US locale: michael@0: *
michael@0: * \code michael@0: * Format Pattern Result michael@0: * -------------- ------- michael@0: * "yyyy.MM.dd G 'at' HH:mm:ss vvvv" ->> 1996.07.10 AD at 15:08:56 Pacific Time michael@0: * "EEE, MMM d, ''yy" ->> Wed, July 10, '96 michael@0: * "h:mm a" ->> 12:08 PM michael@0: * "hh 'o''clock' a, zzzz" ->> 12 o'clock PM, Pacific Daylight Time michael@0: * "K:mm a, vvv" ->> 0:00 PM, PT michael@0: * "yyyyy.MMMMM.dd GGG hh:mm aaa" ->> 1996.July.10 AD 12:08 PM michael@0: * \endcode michael@0: *michael@0: * Code Sample: michael@0: *
michael@0: * \code michael@0: * UErrorCode success = U_ZERO_ERROR; michael@0: * SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "PST"); michael@0: * pdt->setStartRule( Calendar::APRIL, 1, Calendar::SUNDAY, 2*60*60*1000); michael@0: * pdt->setEndRule( Calendar::OCTOBER, -1, Calendar::SUNDAY, 2*60*60*1000); michael@0: * michael@0: * // Format the current time. michael@0: * SimpleDateFormat* formatter michael@0: * = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz", success ); michael@0: * GregorianCalendar cal(success); michael@0: * UDate currentTime_1 = cal.getTime(success); michael@0: * FieldPosition fp(0); michael@0: * UnicodeString dateString; michael@0: * formatter->format( currentTime_1, dateString, fp ); michael@0: * cout << "result: " << dateString << endl; michael@0: * michael@0: * // Parse the previous string back into a Date. michael@0: * ParsePosition pp(0); michael@0: * UDate currentTime_2 = formatter->parse(dateString, pp ); michael@0: * \endcode michael@0: *michael@0: * In the above example, the time value "currentTime_2" obtained from parsing michael@0: * will be equal to currentTime_1. However, they may not be equal if the am/pm michael@0: * marker 'a' is left out from the format pattern while the "hour in am/pm" michael@0: * pattern symbol is used. This information loss can happen when formatting the michael@0: * time in PM. michael@0: * michael@0: *
michael@0: * When parsing a date string using the abbreviated year pattern ("y" or "yy"),
michael@0: * SimpleDateFormat must interpret the abbreviated year
michael@0: * relative to some century. It does this by adjusting dates to be
michael@0: * within 80 years before and 20 years after the time the SimpleDateFormat
michael@0: * instance is created. For example, using a pattern of "MM/dd/yy" and a
michael@0: * SimpleDateFormat instance created on Jan 1, 1997, the string
michael@0: * "01/11/12" would be interpreted as Jan 11, 2012 while the string "05/04/64"
michael@0: * would be interpreted as May 4, 1964.
michael@0: * During parsing, only strings consisting of exactly two digits, as defined by
michael@0: * Unicode::isDigit()
, will be parsed into the default century.
michael@0: * Any other numeric string, such as a one digit string, a three or more digit
michael@0: * string, or a two digit string that isn't all digits (for example, "-1"), is
michael@0: * interpreted literally. So "01/02/3" or "01/02/003" are parsed (for the
michael@0: * Gregorian calendar), using the same pattern, as Jan 2, 3 AD. Likewise (but
michael@0: * only in lenient parse mode, the default) "01/02/-3" is parsed as Jan 2, 4 BC.
michael@0: *
michael@0: *
michael@0: * If the year pattern has more than two 'y' characters, the year is michael@0: * interpreted literally, regardless of the number of digits. So using the michael@0: * pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D. michael@0: * michael@0: *
michael@0: * When numeric fields abut one another directly, with no intervening delimiter michael@0: * characters, they constitute a run of abutting numeric fields. Such runs are michael@0: * parsed specially. For example, the format "HHmmss" parses the input text michael@0: * "123456" to 12:34:56, parses the input text "12345" to 1:23:45, and fails to michael@0: * parse "1234". In other words, the leftmost field of the run is flexible, michael@0: * while the others keep a fixed width. If the parse fails anywhere in the run, michael@0: * then the leftmost field is shortened by one character, and the entire run is michael@0: * parsed again. This is repeated until either the parse succeeds or the michael@0: * leftmost field is one character in length. If the parse still fails at that michael@0: * point, the parse of the run fails. michael@0: * michael@0: *
michael@0: * For time zones that have no names, SimpleDateFormat uses strings GMT+hours:minutes or michael@0: * GMT-hours:minutes. michael@0: *
michael@0: * The calendar defines what is the first day of the week, the first week of the michael@0: * year, whether hours are zero based or not (0 vs 12 or 24), and the timezone. michael@0: * There is one common number format to handle all the numbers; the digit count michael@0: * is handled programmatically according to the pattern. 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 SimpleDateFormat: public DateFormat { michael@0: public: michael@0: /** michael@0: * Construct a SimpleDateFormat using the default pattern for the default michael@0: * locale. michael@0: *
michael@0: * [Note:] Not all locales support SimpleDateFormat; for full generality, michael@0: * use the factory methods in the DateFormat class. michael@0: * @param status Output param set to success/failure code. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: SimpleDateFormat(UErrorCode& status); michael@0: michael@0: /** michael@0: * Construct a SimpleDateFormat using the given pattern and the default locale. michael@0: * The locale is used to obtain the symbols used in formatting (e.g., the michael@0: * names of the months), but not to provide the pattern. michael@0: *
michael@0: * [Note:] Not all locales support SimpleDateFormat; for full generality, michael@0: * use the factory methods in the DateFormat class. michael@0: * @param pattern the pattern for the format. michael@0: * @param status Output param set to success/failure code. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: SimpleDateFormat(const UnicodeString& pattern, michael@0: UErrorCode& status); michael@0: michael@0: /** michael@0: * Construct a SimpleDateFormat using the given pattern, numbering system override, and the default locale. michael@0: * The locale is used to obtain the symbols used in formatting (e.g., the michael@0: * names of the months), but not to provide the pattern. michael@0: *
michael@0: * A numbering system override is a string containing either the name of a known numbering system, michael@0: * or a set of field and numbering system pairs that specify which fields are to be formattied with michael@0: * the alternate numbering system. For example, to specify that all numeric fields in the specified michael@0: * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override michael@0: * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering, michael@0: * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon michael@0: * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc. michael@0: * michael@0: *
michael@0: * [Note:] Not all locales support SimpleDateFormat; for full generality, michael@0: * use the factory methods in the DateFormat class. michael@0: * @param pattern the pattern for the format. michael@0: * @param override the override string. michael@0: * @param status Output param set to success/failure code. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: SimpleDateFormat(const UnicodeString& pattern, michael@0: const UnicodeString& override, michael@0: UErrorCode& status); michael@0: michael@0: /** michael@0: * Construct a SimpleDateFormat using the given pattern and locale. michael@0: * The locale is used to obtain the symbols used in formatting (e.g., the michael@0: * names of the months), but not to provide the pattern. michael@0: *
michael@0: * [Note:] Not all locales support SimpleDateFormat; for full generality, michael@0: * use the factory methods in the DateFormat class. michael@0: * @param pattern the pattern for the format. michael@0: * @param locale the given locale. michael@0: * @param status Output param set to success/failure code. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: SimpleDateFormat(const UnicodeString& pattern, michael@0: const Locale& locale, michael@0: UErrorCode& status); michael@0: michael@0: /** michael@0: * Construct a SimpleDateFormat using the given pattern, numbering system override, and locale. michael@0: * The locale is used to obtain the symbols used in formatting (e.g., the michael@0: * names of the months), but not to provide the pattern. michael@0: *
michael@0: * A numbering system override is a string containing either the name of a known numbering system, michael@0: * or a set of field and numbering system pairs that specify which fields are to be formattied with michael@0: * the alternate numbering system. For example, to specify that all numeric fields in the specified michael@0: * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override michael@0: * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering, michael@0: * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon michael@0: * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc. michael@0: *
michael@0: * [Note:] Not all locales support SimpleDateFormat; for full generality, michael@0: * use the factory methods in the DateFormat class. michael@0: * @param pattern the pattern for the format. michael@0: * @param override the numbering system override. michael@0: * @param locale the given locale. michael@0: * @param status Output param set to success/failure code. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: SimpleDateFormat(const UnicodeString& pattern, michael@0: const UnicodeString& override, michael@0: const Locale& locale, michael@0: UErrorCode& status); michael@0: michael@0: /** michael@0: * Construct a SimpleDateFormat using the given pattern and locale-specific michael@0: * symbol data. The formatter takes ownership of the DateFormatSymbols object; michael@0: * the caller is no longer responsible for deleting it. michael@0: * @param pattern the given pattern for the format. michael@0: * @param formatDataToAdopt the symbols to be adopted. michael@0: * @param status Output param set to success/faulure code. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: SimpleDateFormat(const UnicodeString& pattern, michael@0: DateFormatSymbols* formatDataToAdopt, michael@0: UErrorCode& status); michael@0: michael@0: /** michael@0: * Construct a SimpleDateFormat using the given pattern and locale-specific michael@0: * symbol data. The DateFormatSymbols object is NOT adopted; the caller michael@0: * remains responsible for deleting it. michael@0: * @param pattern the given pattern for the format. michael@0: * @param formatData the formatting symbols to be use. michael@0: * @param status Output param set to success/faulure code. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: SimpleDateFormat(const UnicodeString& pattern, michael@0: const DateFormatSymbols& formatData, michael@0: UErrorCode& status); michael@0: michael@0: /** michael@0: * Copy constructor. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: SimpleDateFormat(const SimpleDateFormat&); michael@0: michael@0: /** michael@0: * Assignment operator. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: SimpleDateFormat& operator=(const SimpleDateFormat&); michael@0: michael@0: /** michael@0: * Destructor. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual ~SimpleDateFormat(); michael@0: michael@0: /** michael@0: * Clone this Format object polymorphically. The caller owns the result and michael@0: * should delete it when done. michael@0: * @return A copy of the object. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual Format* clone(void) const; michael@0: michael@0: /** michael@0: * Return true if the given Format objects are semantically equal. Objects michael@0: * of different subclasses are considered unequal. michael@0: * @param other the object to be compared with. michael@0: * @return true if the given Format objects are semantically equal. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UBool operator==(const Format& other) const; michael@0: michael@0: michael@0: using DateFormat::format; michael@0: michael@0: /** michael@0: * Format a date or time, which is the standard millis since 24:00 GMT, Jan michael@0: * 1, 1970. Overrides DateFormat pure virtual method. michael@0: *
michael@0: * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->> michael@0: * 1996.07.10 AD at 15:08:56 PDT michael@0: * michael@0: * @param cal Calendar set to the date and time to be formatted michael@0: * 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 pos The formatting position. On input: an alignment field, michael@0: * if desired. On output: the offsets of the alignment field. 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& pos) const; michael@0: michael@0: /** michael@0: * Format a date or time, which is the standard millis since 24:00 GMT, Jan michael@0: * 1, 1970. Overrides DateFormat pure virtual method. michael@0: *
michael@0: * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->> michael@0: * 1996.07.10 AD at 15:08:56 PDT michael@0: * michael@0: * @param cal Calendar set to the date and time to be formatted michael@0: * 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. michael@0: * @param status Input/output param set to success/failure code. 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: using DateFormat::parse; 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 SimpleDateFormat 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; michael@0: michael@0: michael@0: /** michael@0: * Set the start UDate used to interpret two-digit year strings. michael@0: * When dates are parsed having 2-digit year strings, they are placed within michael@0: * a assumed range of 100 years starting on the two digit start date. For michael@0: * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or michael@0: * some other year. SimpleDateFormat chooses a year so that the resultant michael@0: * date is on or after the two digit start date and within 100 years of the michael@0: * two digit start date. michael@0: *
michael@0: * By default, the two digit start date is set to 80 years before the current michael@0: * time at which a SimpleDateFormat object is created. michael@0: * @param d start UDate used to interpret two-digit year strings. michael@0: * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with michael@0: * an error value if there was a parse error. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void set2DigitYearStart(UDate d, UErrorCode& status); michael@0: michael@0: /** michael@0: * Get the start UDate used to interpret two-digit year strings. michael@0: * When dates are parsed having 2-digit year strings, they are placed within michael@0: * a assumed range of 100 years starting on the two digit start date. For michael@0: * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or michael@0: * some other year. SimpleDateFormat chooses a year so that the resultant michael@0: * date is on or after the two digit start date and within 100 years of the michael@0: * two digit start date. michael@0: *
michael@0: * By default, the two digit start date is set to 80 years before the current michael@0: * time at which a SimpleDateFormat object is created. michael@0: * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with michael@0: * an error value if there was a parse error. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UDate get2DigitYearStart(UErrorCode& status) const; michael@0: michael@0: /** michael@0: * Return a pattern string describing this date format. michael@0: * @param result Output param to receive the pattern. michael@0: * @return A reference to 'result'. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UnicodeString& toPattern(UnicodeString& result) const; michael@0: michael@0: /** michael@0: * Return a localized pattern string describing this date format. michael@0: * In most cases, this will return the same thing as toPattern(), michael@0: * but a locale can specify characters to use in pattern descriptions michael@0: * in place of the ones described in this class's class documentation. michael@0: * (Presumably, letters that would be more mnemonic in that locale's michael@0: * language.) This function would produce a pattern using those michael@0: * letters. michael@0: * michael@0: * @param result Receives the localized pattern. michael@0: * @param status Output param set to success/failure code on michael@0: * exit. If the pattern is invalid, this will be michael@0: * set to a failure result. michael@0: * @return A reference to 'result'. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UnicodeString& toLocalizedPattern(UnicodeString& result, michael@0: UErrorCode& status) const; michael@0: michael@0: /** michael@0: * Apply the given unlocalized pattern string to this date format. michael@0: * (i.e., after this call, this formatter will format dates according to michael@0: * the new pattern) michael@0: * michael@0: * @param pattern The pattern to be applied. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void applyPattern(const UnicodeString& pattern); michael@0: michael@0: /** michael@0: * Apply the given localized pattern string to this date format. michael@0: * (see toLocalizedPattern() for more information on localized patterns.) michael@0: * michael@0: * @param pattern The localized pattern to be applied. michael@0: * @param status Output param set to success/failure code on michael@0: * exit. If the pattern is invalid, this will be michael@0: * set to a failure result. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void applyLocalizedPattern(const UnicodeString& pattern, michael@0: UErrorCode& status); michael@0: michael@0: /** michael@0: * Gets the date/time formatting symbols (this is an object carrying michael@0: * the various strings and other symbols used in formatting: e.g., month michael@0: * names and abbreviations, time zone names, AM/PM strings, etc.) michael@0: * @return a copy of the date-time formatting data associated michael@0: * with this date-time formatter. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual const DateFormatSymbols* getDateFormatSymbols(void) const; michael@0: michael@0: /** michael@0: * Set the date/time formatting symbols. The caller no longer owns the michael@0: * DateFormatSymbols object and should not delete it after making this call. michael@0: * @param newFormatSymbols the given date-time formatting symbols to copy. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols); michael@0: michael@0: /** michael@0: * Set the date/time formatting data. michael@0: * @param newFormatSymbols the given date-time formatting symbols to copy. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols); michael@0: michael@0: /** michael@0: * Return the class ID for this class. This is useful only for comparing to michael@0: * a return value from getDynamicClassID(). For example: michael@0: *
michael@0: * . Base* polymorphic_pointer = createPolymorphicObject(); michael@0: * . if (polymorphic_pointer->getDynamicClassID() == michael@0: * . erived::getStaticClassID()) ... michael@0: *michael@0: * @return The class ID for all objects of this class. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static UClassID U_EXPORT2 getStaticClassID(void); michael@0: michael@0: /** michael@0: * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This michael@0: * method is to implement a simple version of RTTI, since not all C++ michael@0: * compilers support genuine RTTI. Polymorphic operator==() and clone() michael@0: * methods call this method. michael@0: * michael@0: * @return The class ID for this object. All objects of a michael@0: * given class have the same class ID. Objects of michael@0: * other classes have different class IDs. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UClassID getDynamicClassID(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: /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */ michael@0: /** michael@0: * Set a particular UDisplayContext value in the formatter, such as michael@0: * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. michael@0: * @param value The UDisplayContext value to set. michael@0: * @param status Input/output status. If at entry this indicates a failure michael@0: * status, the function will do nothing; otherwise this will be michael@0: * updated with any new status from the function. michael@0: * @draft ICU 51 michael@0: */ michael@0: virtual void setContext(UDisplayContext value, UErrorCode& status); michael@0: michael@0: /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */ michael@0: /** michael@0: * Get the formatter's UDisplayContext value for the specified UDisplayContextType, michael@0: * such as UDISPCTX_TYPE_CAPITALIZATION. michael@0: * @param type The UDisplayContextType whose value to return michael@0: * @param status Input/output status. If at entry this indicates a failure michael@0: * status, the function will do nothing; otherwise this will be michael@0: * updated with any new status from the function. michael@0: * @return The UDisplayContextValue for the specified type. michael@0: * @draft ICU 51 michael@0: */ michael@0: virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const; michael@0: michael@0: /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */ michael@0: /** michael@0: * Sets the TimeZoneFormat to be used by this date/time formatter. michael@0: * The caller should not delete the TimeZoneFormat object after michael@0: * it is adopted by this call. michael@0: * @param timeZoneFormatToAdopt The TimeZoneFormat object to be adopted. michael@0: * @internal ICU 49 technology preview michael@0: */ michael@0: virtual void adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt); michael@0: michael@0: /** michael@0: * Sets the TimeZoneFormat to be used by this date/time formatter. michael@0: * @param newTimeZoneFormat The TimeZoneFormat object to copy. michael@0: * @internal ICU 49 technology preview michael@0: */ michael@0: virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat); michael@0: michael@0: /** michael@0: * Gets the time zone format object associated with this date/time formatter. michael@0: * @return the time zone format associated with this date/time formatter. michael@0: * @internal ICU 49 technology preview michael@0: */ michael@0: virtual const TimeZoneFormat* getTimeZoneFormat(void) const; michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * This is for ICU internal use only. Please do not use. michael@0: * Check whether the 'field' is smaller than all the fields covered in michael@0: * pattern, return TRUE if it is. The sequence of calendar field, michael@0: * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,... michael@0: * @param field the calendar field need to check against michael@0: * @return TRUE if the 'field' is smaller than all the fields michael@0: * covered in pattern. FALSE otherwise. michael@0: * @internal ICU 4.0 michael@0: */ michael@0: UBool isFieldUnitIgnored(UCalendarDateFields field) const; michael@0: michael@0: michael@0: /** michael@0: * This is for ICU internal use only. Please do not use. michael@0: * Check whether the 'field' is smaller than all the fields covered in michael@0: * pattern, return TRUE if it is. The sequence of calendar field, michael@0: * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,... michael@0: * @param pattern the pattern to check against michael@0: * @param field the calendar field need to check against michael@0: * @return TRUE if the 'field' is smaller than all the fields michael@0: * covered in pattern. FALSE otherwise. michael@0: * @internal ICU 4.0 michael@0: */ michael@0: static UBool isFieldUnitIgnored(const UnicodeString& pattern, michael@0: UCalendarDateFields field); michael@0: michael@0: /** michael@0: * This is for ICU internal use only. Please do not use. michael@0: * Get the locale of this simple date formatter. michael@0: * It is used in DateIntervalFormat. michael@0: * michael@0: * @return locale in this simple date formatter michael@0: * @internal ICU 4.0 michael@0: */ michael@0: const Locale& getSmpFmtLocale(void) const; michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: private: michael@0: friend class DateFormat; michael@0: michael@0: void initializeDefaultCentury(void); michael@0: michael@0: SimpleDateFormat(); // default constructor not implemented michael@0: michael@0: /** michael@0: * Used by the DateFormat factory methods to construct a SimpleDateFormat. michael@0: * @param timeStyle the time style. michael@0: * @param dateStyle the date style. michael@0: * @param locale the given locale. michael@0: * @param status Output param set to success/failure code on michael@0: * exit. michael@0: */ michael@0: SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status); michael@0: michael@0: /** michael@0: * Construct a SimpleDateFormat for the given locale. If no resource data michael@0: * is available, create an object of last resort, using hard-coded strings. michael@0: * This is an internal method, called by DateFormat. It should never fail. michael@0: * @param locale the given locale. michael@0: * @param status Output param set to success/failure code on michael@0: * exit. michael@0: */ michael@0: SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern michael@0: michael@0: /** michael@0: * Hook called by format(... FieldPosition& ...) and format(...FieldPositionIterator&...) michael@0: */ michael@0: UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const; michael@0: michael@0: /** michael@0: * Called by format() to format a single field. michael@0: * michael@0: * @param appendTo Output parameter to receive result. michael@0: * Result is appended to existing contents. michael@0: * @param ch The format character we encountered in the pattern. michael@0: * @param count Number of characters in the current pattern symbol (e.g., michael@0: * "yyyy" in the pattern would result in a call to this function michael@0: * with ch equal to 'y' and count equal to 4) michael@0: * @param capitalizationContext Capitalization context for this date format. michael@0: * @param fieldNum Zero-based numbering of current field within the overall format. michael@0: * @param handler Records information about field positions. michael@0: * @param cal Calendar to use michael@0: * @param status Receives a status code, which will be U_ZERO_ERROR if the operation michael@0: * succeeds. michael@0: */ michael@0: void subFormat(UnicodeString &appendTo, michael@0: UChar ch, michael@0: int32_t count, michael@0: UDisplayContext capitalizationContext, michael@0: int32_t fieldNum, michael@0: FieldPositionHandler& handler, michael@0: Calendar& cal, michael@0: UErrorCode& status) const; // in case of illegal argument michael@0: michael@0: /** michael@0: * Used by subFormat() to format a numeric value. michael@0: * Appends to toAppendTo a string representation of "value" michael@0: * having a number of digits between "minDigits" and michael@0: * "maxDigits". Uses the DateFormat's NumberFormat. michael@0: * michael@0: * @param currentNumberFormat michael@0: * @param appendTo Output parameter to receive result. michael@0: * Formatted number is appended to existing contents. michael@0: * @param value Value to format. michael@0: * @param minDigits Minimum number of digits the result should have michael@0: * @param maxDigits Maximum number of digits the result should have michael@0: */ michael@0: void zeroPaddingNumber(NumberFormat *currentNumberFormat, michael@0: UnicodeString &appendTo, michael@0: int32_t value, michael@0: int32_t minDigits, michael@0: int32_t maxDigits) const; michael@0: michael@0: /** michael@0: * Return true if the given format character, occuring count michael@0: * times, represents a numeric field. michael@0: */ michael@0: static UBool isNumeric(UChar formatChar, int32_t count); michael@0: michael@0: /** michael@0: * Returns TRUE if the patternOffset is at the start of a numeric field. michael@0: */ michael@0: static UBool isAtNumericField(const UnicodeString &pattern, int32_t patternOffset); michael@0: michael@0: /** michael@0: * Returns TRUE if the patternOffset is right after a non-numeric field. michael@0: */ michael@0: static UBool isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset); michael@0: michael@0: /** michael@0: * initializes fCalendar from parameters. Returns fCalendar as a convenience. michael@0: * @param adoptZone Zone to be adopted, or NULL for TimeZone::createDefault(). michael@0: * @param locale Locale of the calendar michael@0: * @param status Error code michael@0: * @return the newly constructed fCalendar michael@0: */ michael@0: Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status); michael@0: michael@0: /** michael@0: * initializes fSymbols from parameters. michael@0: * @param locale Locale of the symbols michael@0: * @param calendar Alias to Calendar that will be used. michael@0: * @param status Error code michael@0: */ michael@0: void initializeSymbols(const Locale& locale, Calendar* calendar, UErrorCode& status); michael@0: michael@0: /** michael@0: * Called by several of the constructors to load pattern data and formatting symbols michael@0: * out of a resource bundle and initialize the locale based on it. michael@0: * @param timeStyle The time style, as passed to DateFormat::createDateInstance(). michael@0: * @param dateStyle The date style, as passed to DateFormat::createTimeInstance(). michael@0: * @param locale The locale to load the patterns from. michael@0: * @param status Filled in with an error code if loading the data from the michael@0: * resources fails. michael@0: */ michael@0: void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status); michael@0: michael@0: /** michael@0: * Called by construct() and the various constructors to set up the SimpleDateFormat's michael@0: * Calendar and NumberFormat objects. michael@0: * @param locale The locale for which we want a Calendar and a NumberFormat. michael@0: * @param status Filled in with an error code if creating either subobject fails. michael@0: */ michael@0: void initialize(const Locale& locale, UErrorCode& status); michael@0: michael@0: /** michael@0: * Private code-size reduction function used by subParse. michael@0: * @param text the time text being parsed. michael@0: * @param start where to start parsing. michael@0: * @param field the date field being parsed. michael@0: * @param stringArray the string array to parsed. michael@0: * @param stringArrayCount the size of the array. michael@0: * @param monthPattern pointer to leap month pattern, or NULL if none. michael@0: * @param cal a Calendar set to the date and time to be formatted michael@0: * into a date/time string. michael@0: * @return the new start position if matching succeeded; a negative number michael@0: * indicating matching failure, otherwise. michael@0: */ michael@0: int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field, michael@0: const UnicodeString* stringArray, int32_t stringArrayCount, michael@0: const UnicodeString* monthPattern, Calendar& cal) const; michael@0: michael@0: /** michael@0: * Private code-size reduction function used by subParse. michael@0: * @param text the time text being parsed. michael@0: * @param start where to start parsing. michael@0: * @param field the date field being parsed. michael@0: * @param stringArray the string array to parsed. michael@0: * @param stringArrayCount the size of the array. michael@0: * @param cal a Calendar set to the date and time to be formatted michael@0: * into a date/time string. michael@0: * @return the new start position if matching succeeded; a negative number michael@0: * indicating matching failure, otherwise. michael@0: */ michael@0: int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field, michael@0: const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const; michael@0: michael@0: /** michael@0: * Private function used by subParse to match literal pattern text. michael@0: * michael@0: * @param pattern the pattern string michael@0: * @param patternOffset the starting offset into the pattern text. On michael@0: * outupt will be set the offset of the first non-literal character in the pattern michael@0: * @param text the text being parsed michael@0: * @param textOffset the starting offset into the text. On output michael@0: * will be set to the offset of the character after the match michael@0: * @param lenient
TRUE
if the parse is lenient, FALSE
otherwise.
michael@0: *
michael@0: * @return TRUE
if the literal text could be matched, FALSE
otherwise.
michael@0: */
michael@0: static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
michael@0: const UnicodeString &text, int32_t &textOffset, UBool lenient);
michael@0:
michael@0: /**
michael@0: * Private member function that converts the parsed date strings into
michael@0: * timeFields. Returns -start (for ParsePosition) if failed.
michael@0: * @param text the time text to be parsed.
michael@0: * @param start where to start parsing.
michael@0: * @param ch the pattern character for the date field text to be parsed.
michael@0: * @param count the count of a pattern character.
michael@0: * @param obeyCount if true then the count is strictly obeyed.
michael@0: * @param allowNegative
michael@0: * @param ambiguousYear If true then the two-digit year == the default start year.
michael@0: * @param saveHebrewMonth Used to hang onto month until year is known.
michael@0: * @param cal a Calendar set to the date and time to be formatted
michael@0: * into a date/time string.
michael@0: * @param patLoc
michael@0: * @param numericLeapMonthFormatter If non-null, used to parse numeric leap months.
michael@0: * @return the new start position if matching succeeded; a negative number
michael@0: * indicating matching failure, otherwise.
michael@0: */
michael@0: int32_t subParse(const UnicodeString& text, int32_t& start, UChar ch, int32_t count,
michael@0: UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
michael@0: int32_t patLoc, MessageFormat * numericLeapMonthFormatter) const;
michael@0:
michael@0: void parseInt(const UnicodeString& text,
michael@0: Formattable& number,
michael@0: ParsePosition& pos,
michael@0: UBool allowNegative,
michael@0: NumberFormat *fmt) const;
michael@0:
michael@0: void parseInt(const UnicodeString& text,
michael@0: Formattable& number,
michael@0: int32_t maxDigits,
michael@0: ParsePosition& pos,
michael@0: UBool allowNegative,
michael@0: NumberFormat *fmt) const;
michael@0:
michael@0: int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
michael@0: int32_t patLoc, UBool isNegative) const;
michael@0:
michael@0: /**
michael@0: * Translate a pattern, mapping each character in the from string to the
michael@0: * corresponding character in the to string. Return an error if the original
michael@0: * pattern contains an unmapped character, or if a quote is unmatched.
michael@0: * Quoted (single quotes only) material is not translated.
michael@0: * @param originalPattern the original pattern.
michael@0: * @param translatedPattern Output param to receive the translited pattern.
michael@0: * @param from the characters to be translited from.
michael@0: * @param to the characters to be translited to.
michael@0: * @param status Receives a status code, which will be U_ZERO_ERROR
michael@0: * if the operation succeeds.
michael@0: */
michael@0: static void translatePattern(const UnicodeString& originalPattern,
michael@0: UnicodeString& translatedPattern,
michael@0: const UnicodeString& from,
michael@0: const UnicodeString& to,
michael@0: UErrorCode& status);
michael@0:
michael@0: /**
michael@0: * Sets the starting date of the 100-year window that dates with 2-digit years
michael@0: * are considered to fall within.
michael@0: * @param startDate the start date
michael@0: * @param status Receives a status code, which will be U_ZERO_ERROR
michael@0: * if the operation succeeds.
michael@0: */
michael@0: void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
michael@0:
michael@0: /**
michael@0: * Return the length matched by the given affix, or -1 if none.
michael@0: * Runs of white space in the affix, match runs of white space in
michael@0: * the input.
michael@0: * @param affix pattern string, taken as a literal
michael@0: * @param input input text
michael@0: * @param pos offset into input at which to begin matching
michael@0: * @return length of input that matches, or -1 if match failure
michael@0: */
michael@0: int32_t compareSimpleAffix(const UnicodeString& affix,
michael@0: const UnicodeString& input,
michael@0: int32_t pos) const;
michael@0:
michael@0: /**
michael@0: * Skip over a run of zero or more Pattern_White_Space characters at
michael@0: * pos in text.
michael@0: */
michael@0: int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
michael@0:
michael@0: /**
michael@0: * Skip over a run of zero or more isUWhiteSpace() characters at pos
michael@0: * in text.
michael@0: */
michael@0: int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
michael@0:
michael@0: /**
michael@0: * Initialize NumberFormat instances used for numbering system overrides.
michael@0: */
michael@0: void initNumberFormatters(const Locale &locale,UErrorCode &status);
michael@0:
michael@0: /**
michael@0: * Get the numbering system to be used for a particular field.
michael@0: */
michael@0: NumberFormat * getNumberFormatByIndex(UDateFormatField index) const;
michael@0:
michael@0: /**
michael@0: * Parse the given override string and set up structures for number formats
michael@0: */
michael@0: void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
michael@0:
michael@0: /**
michael@0: * Used to map pattern characters to Calendar field identifiers.
michael@0: */
michael@0: static const UCalendarDateFields fgPatternIndexToCalendarField[];
michael@0:
michael@0: /**
michael@0: * Map index into pattern character string to DateFormat field number
michael@0: */
michael@0: static const UDateFormatField fgPatternIndexToDateFormatField[];
michael@0:
michael@0: /**
michael@0: * Lazy TimeZoneFormat instantiation, semantically const
michael@0: */
michael@0: TimeZoneFormat *tzFormat() const;
michael@0:
michael@0: /**
michael@0: * Used to map Calendar field to field level.
michael@0: * The larger the level, the smaller the field unit.
michael@0: * For example, UCAL_ERA level is 0, UCAL_YEAR level is 10,
michael@0: * UCAL_MONTH level is 20.
michael@0: */
michael@0: static const int32_t fgCalendarFieldToLevel[];
michael@0: static const int32_t fgPatternCharToLevel[];
michael@0:
michael@0: /**
michael@0: * The formatting pattern for this formatter.
michael@0: */
michael@0: UnicodeString fPattern;
michael@0:
michael@0: /**
michael@0: * The numbering system override for dates.
michael@0: */
michael@0: UnicodeString fDateOverride;
michael@0:
michael@0: /**
michael@0: * The numbering system override for times.
michael@0: */
michael@0: UnicodeString fTimeOverride;
michael@0:
michael@0:
michael@0: /**
michael@0: * The original locale used (for reloading symbols)
michael@0: */
michael@0: Locale fLocale;
michael@0:
michael@0: /**
michael@0: * A pointer to an object containing the strings to use in formatting (e.g.,
michael@0: * month and day names, AM and PM strings, time zone names, etc.)
michael@0: */
michael@0: DateFormatSymbols* fSymbols; // Owned
michael@0:
michael@0: /**
michael@0: * The time zone formatter
michael@0: */
michael@0: TimeZoneFormat* fTimeZoneFormat;
michael@0:
michael@0: /**
michael@0: * If dates have ambiguous years, we map them into the century starting
michael@0: * at defaultCenturyStart, which may be any date. If defaultCenturyStart is
michael@0: * set to SYSTEM_DEFAULT_CENTURY, which it is by default, then the system
michael@0: * values are used. The instance values defaultCenturyStart and
michael@0: * defaultCenturyStartYear are only used if explicitly set by the user
michael@0: * through the API method parseAmbiguousDatesAsAfter().
michael@0: */
michael@0: UDate fDefaultCenturyStart;
michael@0:
michael@0: /**
michael@0: * See documentation for defaultCenturyStart.
michael@0: */
michael@0: /*transient*/ int32_t fDefaultCenturyStartYear;
michael@0:
michael@0: int32_t tztype; // here to avoid api change
michael@0:
michael@0: typedef struct NSOverride {
michael@0: NumberFormat *nf;
michael@0: int32_t hash;
michael@0: NSOverride *next;
michael@0: } NSOverride;
michael@0:
michael@0: NumberFormat **fNumberFormatters;
michael@0:
michael@0: NSOverride *fOverrideList;
michael@0:
michael@0: UBool fHaveDefaultCentury;
michael@0:
michael@0: UDisplayContext fCapitalizationContext;
michael@0: };
michael@0:
michael@0: inline UDate
michael@0: SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
michael@0: {
michael@0: return fDefaultCenturyStart;
michael@0: }
michael@0:
michael@0: U_NAMESPACE_END
michael@0:
michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */
michael@0:
michael@0: #endif // _SMPDTFMT
michael@0: //eof