]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/unicode/smpdtfmt.h
ICU-491.11.1.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / smpdtfmt.h
CommitLineData
b75a7d8f 1/*
4388f060 2* Copyright (C) 1997-2012, International Business Machines Corporation and
729e4ab9 3* others. All Rights Reserved.
b75a7d8f
A
4*******************************************************************************
5*
6* File SMPDTFMT.H
7*
8* Modification History:
9*
10* Date Name Description
11* 02/19/97 aliu Converted from java.
12* 07/09/97 helena Make ParsePosition into a class.
13* 07/21/98 stephen Added GMT_PLUS, GMT_MINUS
14* Changed setTwoDigitStartDate to set2DigitYearStart
15* Changed getTwoDigitStartDate to get2DigitYearStart
16* Removed subParseLong
17* Removed getZoneIndex (added in DateFormatSymbols)
18* 06/14/99 stephen Removed fgTimeZoneDataSuffix
19* 10/14/99 aliu Updated class doc to describe 2-digit year parsing
20* {j28 4182066}.
21*******************************************************************************
22*/
23
24#ifndef SMPDTFMT_H
25#define SMPDTFMT_H
26
27#include "unicode/utypes.h"
28
73c04bcf 29/**
729e4ab9 30 * \file
73c04bcf
A
31 * \brief C++ API: Format and parse dates in a language-independent manner.
32 */
729e4ab9 33
b75a7d8f
A
34#if !UCONFIG_NO_FORMATTING
35
36#include "unicode/datefmt.h"
37
38U_NAMESPACE_BEGIN
39
40class DateFormatSymbols;
41class DateFormat;
46f4442e 42class MessageFormat;
729e4ab9 43class FieldPositionHandler;
4388f060 44class TimeZoneFormat;
b75a7d8f
A
45
46/**
73c04bcf 47 *
b75a7d8f
A
48 * SimpleDateFormat is a concrete class for formatting and parsing dates in a
49 * language-independent manner. It allows for formatting (millis -> text),
50 * parsing (text -> millis), and normalization. Formats/Parses a date or time,
51 * which is the standard milliseconds since 24:00 GMT, Jan 1, 1970.
52 * <P>
53 * Clients are encouraged to create a date-time formatter using DateFormat::getInstance(),
54 * getDateInstance(), getDateInstance(), or getDateTimeInstance() rather than
55 * explicitly constructing an instance of SimpleDateFormat. This way, the client
56 * is guaranteed to get an appropriate formatting pattern for whatever locale the
57 * program is running in. However, if the client needs something more unusual than
58 * the default patterns in the locales, he can construct a SimpleDateFormat directly
59 * and give it an appropriate pattern (or use one of the factory methods on DateFormat
60 * and modify the pattern after the fact with toPattern() and applyPattern().
61 * <P>
62 * Date/Time format syntax:
63 * <P>
64 * The date/time format is specified by means of a string time pattern. In this
65 * pattern, all ASCII letters are reserved as pattern letters, which are defined
66 * as the following:
67 * <pre>
68 * \code
374ca955
A
69 * Symbol Meaning Presentation Example
70 * ------ ------- ------------ -------
71 * G era designator (Text) AD
72 * y year (Number) 1996
73 * Y year (week of year) (Number) 1997
74 * u extended year (Number) 4601
4388f060 75 * U cyclic year name (Text,NumFallback) ren-chen (29)
46f4442e 76 * Q Quarter (Text & Number) Q2 & 02
374ca955
A
77 * M month in year (Text & Number) July & 07
78 * d day in month (Number) 10
79 * h hour in am/pm (1~12) (Number) 12
80 * H hour in day (0~23) (Number) 0
81 * m minute in hour (Number) 30
82 * s second in minute (Number) 55
83 * S fractional second (Number) 978
84 * E day of week (Text) Tuesday
46f4442e 85 * e day of week (local 1~7) (Text & Number) Tues & 2
374ca955
A
86 * D day in year (Number) 189
87 * F day of week in month (Number) 2 (2nd Wed in July)
88 * w week in year (Number) 27
89 * W week in month (Number) 2
90 * a am/pm marker (Text) PM
91 * k hour in day (1~24) (Number) 24
92 * K hour in am/pm (0~11) (Number) 0
4388f060
A
93 * z time zone (Text) PST
94 * zzzz time zone (Text) Pacific Standard Time
374ca955 95 * Z time zone (RFC 822) (Number) -0800
4388f060
A
96 * ZZZZ time zone (RFC 822) (Text & Number) GMT-08:00
97 * ZZZZZ time zone (ISO 8601) (Text & Number) -08:00 & Z
98 * v time zone (generic) (Text) PT
99 * vvvv time zone (generic) (Text) Pacific Time
100 * V time zone (abreviation) (Text) PST
101 * VVVV time zone (location) (Text) United States Time (Los Angeles)
374ca955
A
102 * g Julian day (Number) 2451334
103 * A milliseconds in day (Number) 69540000
46f4442e
A
104 * q stand alone quarter (Text & Number) Q2 & 02
105 * L stand alone month (Text & Number) July & 07
106 * c stand alone day of week (Text & Number) Tuesday & 2
374ca955
A
107 * ' escape for text (Delimiter) 'Date='
108 * '' single quote (Literal) 'o''clock'
b75a7d8f
A
109 * \endcode
110 * </pre>
111 * The count of pattern letters determine the format.
112 * <P>
113 * (Text): 4 or more, use full form, &lt;4, use short or abbreviated form if it
114 * exists. (e.g., "EEEE" produces "Monday", "EEE" produces "Mon")
115 * <P>
116 * (Number): the minimum number of digits. Shorter numbers are zero-padded to
117 * this amount (e.g. if "m" produces "6", "mm" produces "06"). Year is handled
118 * specially; that is, if the count of 'y' is 2, the Year will be truncated to 2 digits.
119 * (e.g., if "yyyy" produces "1997", "yy" produces "97".)
374ca955 120 * Unlike other fields, fractional seconds are padded on the right with zero.
b75a7d8f
A
121 * <P>
122 * (Text & Number): 3 or over, use text, otherwise use number. (e.g., "M" produces "1",
123 * "MM" produces "01", "MMM" produces "Jan", and "MMMM" produces "January".)
124 * <P>
4388f060
A
125 * (Text,NumFallback): Behaves like Text if there is supporting data, like
126 * Number otherwise.
127 * <P>
b75a7d8f
A
128 * Any characters in the pattern that are not in the ranges of ['a'..'z'] and
129 * ['A'..'Z'] will be treated as quoted text. For instance, characters
130 * like ':', '.', ' ', '#' and '@' will appear in the resulting time text
131 * even they are not embraced within single quotes.
132 * <P>
133 * A pattern containing any invalid pattern letter will result in a failing
134 * UErrorCode result during formatting or parsing.
135 * <P>
136 * Examples using the US locale:
137 * <pre>
138 * \code
139 * Format Pattern Result
140 * -------------- -------
73c04bcf 141 * "yyyy.MM.dd G 'at' HH:mm:ss vvvv" ->> 1996.07.10 AD at 15:08:56 Pacific Time
b75a7d8f
A
142 * "EEE, MMM d, ''yy" ->> Wed, July 10, '96
143 * "h:mm a" ->> 12:08 PM
144 * "hh 'o''clock' a, zzzz" ->> 12 o'clock PM, Pacific Daylight Time
73c04bcf 145 * "K:mm a, vvv" ->> 0:00 PM, PT
b75a7d8f
A
146 * "yyyyy.MMMMM.dd GGG hh:mm aaa" ->> 1996.July.10 AD 12:08 PM
147 * \endcode
148 * </pre>
149 * Code Sample:
150 * <pre>
151 * \code
152 * UErrorCode success = U_ZERO_ERROR;
153 * SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "PST");
154 * pdt->setStartRule( Calendar::APRIL, 1, Calendar::SUNDAY, 2*60*60*1000);
155 * pdt->setEndRule( Calendar::OCTOBER, -1, Calendar::SUNDAY, 2*60*60*1000);
156 *
157 * // Format the current time.
158 * SimpleDateFormat* formatter
159 * = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz", success );
160 * GregorianCalendar cal(success);
161 * UDate currentTime_1 = cal.getTime(success);
162 * FieldPosition fp(0);
163 * UnicodeString dateString;
164 * formatter->format( currentTime_1, dateString, fp );
165 * cout << "result: " << dateString << endl;
166 *
167 * // Parse the previous string back into a Date.
168 * ParsePosition pp(0);
169 * UDate currentTime_2 = formatter->parse(dateString, pp );
170 * \endcode
171 * </pre>
172 * In the above example, the time value "currentTime_2" obtained from parsing
173 * will be equal to currentTime_1. However, they may not be equal if the am/pm
174 * marker 'a' is left out from the format pattern while the "hour in am/pm"
175 * pattern symbol is used. This information loss can happen when formatting the
176 * time in PM.
177 *
178 * <p>
179 * When parsing a date string using the abbreviated year pattern ("y" or "yy"),
180 * SimpleDateFormat must interpret the abbreviated year
181 * relative to some century. It does this by adjusting dates to be
182 * within 80 years before and 20 years after the time the SimpleDateFormat
183 * instance is created. For example, using a pattern of "MM/dd/yy" and a
184 * SimpleDateFormat instance created on Jan 1, 1997, the string
185 * "01/11/12" would be interpreted as Jan 11, 2012 while the string "05/04/64"
186 * would be interpreted as May 4, 1964.
187 * During parsing, only strings consisting of exactly two digits, as defined by
188 * <code>Unicode::isDigit()</code>, will be parsed into the default century.
189 * Any other numeric string, such as a one digit string, a three or more digit
190 * string, or a two digit string that isn't all digits (for example, "-1"), is
4388f060
A
191 * interpreted literally. So "01/02/3" or "01/02/003" are parsed (for the
192 * Gregorian calendar), using the same pattern, as Jan 2, 3 AD. Likewise (but
193 * only in lenient parse mode, the default) "01/02/-3" is parsed as Jan 2, 4 BC.
b75a7d8f
A
194 *
195 * <p>
196 * If the year pattern has more than two 'y' characters, the year is
197 * interpreted literally, regardless of the number of digits. So using the
198 * pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
199 *
200 * <p>
201 * When numeric fields abut one another directly, with no intervening delimiter
202 * characters, they constitute a run of abutting numeric fields. Such runs are
203 * parsed specially. For example, the format "HHmmss" parses the input text
204 * "123456" to 12:34:56, parses the input text "12345" to 1:23:45, and fails to
205 * parse "1234". In other words, the leftmost field of the run is flexible,
206 * while the others keep a fixed width. If the parse fails anywhere in the run,
207 * then the leftmost field is shortened by one character, and the entire run is
208 * parsed again. This is repeated until either the parse succeeds or the
209 * leftmost field is one character in length. If the parse still fails at that
210 * point, the parse of the run fails.
211 *
212 * <P>
213 * For time zones that have no names, SimpleDateFormat uses strings GMT+hours:minutes or
214 * GMT-hours:minutes.
215 * <P>
216 * The calendar defines what is the first day of the week, the first week of the
217 * year, whether hours are zero based or not (0 vs 12 or 24), and the timezone.
218 * There is one common number format to handle all the numbers; the digit count
219 * is handled programmatically according to the pattern.
374ca955
A
220 *
221 * <p><em>User subclasses are not supported.</em> While clients may write
222 * subclasses, such code will not necessarily work and will not be
223 * guaranteed to work stably from release to release.
b75a7d8f
A
224 */
225class U_I18N_API SimpleDateFormat: public DateFormat {
226public:
227 /**
228 * Construct a SimpleDateFormat using the default pattern for the default
229 * locale.
230 * <P>
231 * [Note:] Not all locales support SimpleDateFormat; for full generality,
232 * use the factory methods in the DateFormat class.
233 * @param status Output param set to success/failure code.
234 * @stable ICU 2.0
235 */
236 SimpleDateFormat(UErrorCode& status);
237
238 /**
239 * Construct a SimpleDateFormat using the given pattern and the default locale.
240 * The locale is used to obtain the symbols used in formatting (e.g., the
241 * names of the months), but not to provide the pattern.
242 * <P>
243 * [Note:] Not all locales support SimpleDateFormat; for full generality,
244 * use the factory methods in the DateFormat class.
245 * @param pattern the pattern for the format.
246 * @param status Output param set to success/failure code.
247 * @stable ICU 2.0
248 */
249 SimpleDateFormat(const UnicodeString& pattern,
250 UErrorCode& status);
251
729e4ab9
A
252 /**
253 * Construct a SimpleDateFormat using the given pattern, numbering system override, and the default locale.
254 * The locale is used to obtain the symbols used in formatting (e.g., the
255 * names of the months), but not to provide the pattern.
256 * <P>
257 * A numbering system override is a string containing either the name of a known numbering system,
258 * or a set of field and numbering system pairs that specify which fields are to be formattied with
259 * the alternate numbering system. For example, to specify that all numeric fields in the specified
260 * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
261 * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering,
262 * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon
263 * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
264 *
265 * <P>
266 * [Note:] Not all locales support SimpleDateFormat; for full generality,
267 * use the factory methods in the DateFormat class.
268 * @param pattern the pattern for the format.
269 * @param override the override string.
270 * @param status Output param set to success/failure code.
271 * @stable ICU 4.2
272 */
273 SimpleDateFormat(const UnicodeString& pattern,
274 const UnicodeString& override,
275 UErrorCode& status);
276
b75a7d8f
A
277 /**
278 * Construct a SimpleDateFormat using the given pattern and locale.
279 * The locale is used to obtain the symbols used in formatting (e.g., the
280 * names of the months), but not to provide the pattern.
281 * <P>
282 * [Note:] Not all locales support SimpleDateFormat; for full generality,
283 * use the factory methods in the DateFormat class.
284 * @param pattern the pattern for the format.
285 * @param locale the given locale.
286 * @param status Output param set to success/failure code.
287 * @stable ICU 2.0
288 */
289 SimpleDateFormat(const UnicodeString& pattern,
290 const Locale& locale,
291 UErrorCode& status);
292
729e4ab9
A
293 /**
294 * Construct a SimpleDateFormat using the given pattern, numbering system override, and locale.
295 * The locale is used to obtain the symbols used in formatting (e.g., the
296 * names of the months), but not to provide the pattern.
297 * <P>
298 * A numbering system override is a string containing either the name of a known numbering system,
299 * or a set of field and numbering system pairs that specify which fields are to be formattied with
300 * the alternate numbering system. For example, to specify that all numeric fields in the specified
301 * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
302 * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering,
303 * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon
304 * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
305 * <P>
306 * [Note:] Not all locales support SimpleDateFormat; for full generality,
307 * use the factory methods in the DateFormat class.
308 * @param pattern the pattern for the format.
309 * @param override the numbering system override.
310 * @param locale the given locale.
311 * @param status Output param set to success/failure code.
312 * @stable ICU 4.2
313 */
314 SimpleDateFormat(const UnicodeString& pattern,
315 const UnicodeString& override,
316 const Locale& locale,
317 UErrorCode& status);
318
b75a7d8f
A
319 /**
320 * Construct a SimpleDateFormat using the given pattern and locale-specific
321 * symbol data. The formatter takes ownership of the DateFormatSymbols object;
322 * the caller is no longer responsible for deleting it.
323 * @param pattern the given pattern for the format.
324 * @param formatDataToAdopt the symbols to be adopted.
325 * @param status Output param set to success/faulure code.
326 * @stable ICU 2.0
327 */
328 SimpleDateFormat(const UnicodeString& pattern,
329 DateFormatSymbols* formatDataToAdopt,
330 UErrorCode& status);
331
332 /**
333 * Construct a SimpleDateFormat using the given pattern and locale-specific
334 * symbol data. The DateFormatSymbols object is NOT adopted; the caller
335 * remains responsible for deleting it.
336 * @param pattern the given pattern for the format.
337 * @param formatData the formatting symbols to be use.
338 * @param status Output param set to success/faulure code.
339 * @stable ICU 2.0
340 */
341 SimpleDateFormat(const UnicodeString& pattern,
342 const DateFormatSymbols& formatData,
343 UErrorCode& status);
344
345 /**
346 * Copy constructor.
347 * @stable ICU 2.0
348 */
349 SimpleDateFormat(const SimpleDateFormat&);
350
351 /**
352 * Assignment operator.
353 * @stable ICU 2.0
354 */
355 SimpleDateFormat& operator=(const SimpleDateFormat&);
356
357 /**
358 * Destructor.
359 * @stable ICU 2.0
360 */
361 virtual ~SimpleDateFormat();
362
363 /**
364 * Clone this Format object polymorphically. The caller owns the result and
365 * should delete it when done.
366 * @return A copy of the object.
367 * @stable ICU 2.0
368 */
369 virtual Format* clone(void) const;
370
371 /**
372 * Return true if the given Format objects are semantically equal. Objects
373 * of different subclasses are considered unequal.
374 * @param other the object to be compared with.
375 * @return true if the given Format objects are semantically equal.
376 * @stable ICU 2.0
377 */
378 virtual UBool operator==(const Format& other) const;
379
729e4ab9
A
380
381 using DateFormat::format;
382
b75a7d8f
A
383 /**
384 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
385 * 1, 1970. Overrides DateFormat pure virtual method.
386 * <P>
387 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
388 * 1996.07.10 AD at 15:08:56 PDT
389 *
390 * @param cal Calendar set to the date and time to be formatted
391 * into a date/time string.
392 * @param appendTo Output parameter to receive result.
393 * Result is appended to existing contents.
394 * @param pos The formatting position. On input: an alignment field,
395 * if desired. On output: the offsets of the alignment field.
396 * @return Reference to 'appendTo' parameter.
397 * @stable ICU 2.1
398 */
399 virtual UnicodeString& format( Calendar& cal,
400 UnicodeString& appendTo,
401 FieldPosition& pos) const;
402
4388f060
A
403/* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
404 /**
405 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
406 * 1, 1970. Overrides DateFormat pure virtual method.
407 * <P>
408 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
409 * 1996.07.10 AD at 15:08:56 PDT
410 *
411 * @param cal Calendar set to the date and time to be formatted
412 * into a date/time string.
413 * @param types Array of UDateFormatContextTypes for which the corresponding
414 * value specified in the next parameter should override the
415 * formatter's default value for this call (this does not
416 * change the default value).
417 * @param values Array of UDateFormatContextValues corresponding 1-1 to the
418 * UDateFormatContextTypes in the previous parameter.
419 * @param typesAndValuesCount Number of elements in the types and values
420 * arrays.
421 * @param appendTo Output parameter to receive result.
422 * Result is appended to existing contents.
423 * @param pos The formatting position. On input: an alignment field,
424 * if desired. On output: the offsets of the alignment field.
425 * @return Reference to 'appendTo' parameter.
426 * @draft ICU 49
427 */
428 virtual UnicodeString& format( Calendar& cal,
429 const UDateFormatContextType* types,
430 const UDateFormatContextValue* values,
431 int32_t typesAndValuesCount,
432 UnicodeString& appendTo,
433 FieldPosition& pos) const;
434
729e4ab9
A
435 /**
436 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
437 * 1, 1970. Overrides DateFormat pure virtual method.
438 * <P>
439 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
440 * 1996.07.10 AD at 15:08:56 PDT
441 *
442 * @param cal Calendar set to the date and time to be formatted
443 * into a date/time string.
444 * @param appendTo Output parameter to receive result.
445 * Result is appended to existing contents.
446 * @param posIter On return, can be used to iterate over positions
447 * of fields generated by this format call. Field values
448 * are defined in UDateFormatField.
449 * @param status Input/output param set to success/failure code.
450 * @return Reference to 'appendTo' parameter.
451 * @stable ICU 4.4
452 */
453 virtual UnicodeString& format( Calendar& cal,
454 UnicodeString& appendTo,
455 FieldPositionIterator* posIter,
456 UErrorCode& status) const;
457
b75a7d8f
A
458 /**
459 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
460 * 1, 1970. Overrides DateFormat pure virtual method.
461 * <P>
462 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
463 * 1996.07.10 AD at 15:08:56 PDT
464 *
465 * @param obj A Formattable containing the date-time value to be formatted
466 * into a date-time string. If the type of the Formattable
467 * is a numeric type, it is treated as if it were an
468 * instance of Date.
469 * @param appendTo Output parameter to receive result.
470 * Result is appended to existing contents.
471 * @param pos The formatting position. On input: an alignment field,
472 * if desired. On output: the offsets of the alignment field.
729e4ab9 473 * @param status Input/output param set to success/failure code.
b75a7d8f
A
474 * @return Reference to 'appendTo' parameter.
475 * @stable ICU 2.0
476 */
477 virtual UnicodeString& format( const Formattable& obj,
478 UnicodeString& appendTo,
479 FieldPosition& pos,
480 UErrorCode& status) const;
481
729e4ab9
A
482 /**
483 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
484 * 1, 1970. Overrides DateFormat pure virtual method.
485 * <P>
486 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
487 * 1996.07.10 AD at 15:08:56 PDT
488 *
489 * @param obj A Formattable containing the date-time value to be formatted
490 * into a date-time string. If the type of the Formattable
491 * is a numeric type, it is treated as if it were an
492 * instance of Date.
493 * @param appendTo Output parameter to receive result.
494 * Result is appended to existing contents.
495 * @param posIter On return, can be used to iterate over positions
496 * of fields generated by this format call. Field values
497 * are defined in UDateFormatField.
498 * @param status Input/output param set to success/failure code.
499 * @return Reference to 'appendTo' parameter.
500 * @stable ICU 4.4
501 */
502 virtual UnicodeString& format( const Formattable& obj,
503 UnicodeString& appendTo,
504 FieldPositionIterator* posIter,
505 UErrorCode& status) const;
506
b75a7d8f
A
507 /**
508 * Redeclared DateFormat method.
509 * @param date the Date value to be formatted.
510 * @param appendTo Output parameter to receive result.
511 * Result is appended to existing contents.
512 * @param fieldPosition The formatting position. On input: an alignment field,
513 * if desired. On output: the offsets of the alignment field.
514 * @return Reference to 'appendTo' parameter.
515 * @stable ICU 2.1
516 */
517 UnicodeString& format(UDate date,
518 UnicodeString& appendTo,
519 FieldPosition& fieldPosition) const;
520
729e4ab9
A
521 /**
522 * Redeclared DateFormat method.
523 * @param date the Date value to be formatted.
524 * @param appendTo Output parameter to receive result.
525 * Result is appended to existing contents.
526 * @param posIter On return, can be used to iterate over positions
527 * of fields generated by this format call. Field values
528 * are defined in UDateFormatField.
529 * @param status Input/output param set to success/failure code.
530 * @return Reference to 'appendTo' parameter.
531 * @stable ICU 4.4
532 */
533 UnicodeString& format(UDate date,
534 UnicodeString& appendTo,
535 FieldPositionIterator* posIter,
536 UErrorCode& status) const;
537
b75a7d8f
A
538 /**
539 * Redeclared DateFormat method.
540 * @param obj Object to be formatted.
541 * @param appendTo Output parameter to receive result.
542 * Result is appended to existing contents.
543 * @param status Input/output success/failure code.
544 * @return Reference to 'appendTo' parameter.
545 * @stable ICU 2.0
546 */
547 UnicodeString& format(const Formattable& obj,
548 UnicodeString& appendTo,
549 UErrorCode& status) const;
550
551 /**
552 * Redeclared DateFormat method.
553 * @param date Date value to be formatted.
554 * @param appendTo Output parameter to receive result.
555 * Result is appended to existing contents.
556 * @return Reference to 'appendTo' parameter.
557 * @stable ICU 2.0
558 */
559 UnicodeString& format(UDate date, UnicodeString& appendTo) const;
560
561 /**
562 * Parse a date/time string beginning at the given parse position. For
563 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
564 * that is equivalent to Date(837039928046).
565 * <P>
566 * By default, parsing is lenient: If the input is not in the form used by
567 * this object's format method but can still be parsed as a date, then the
568 * parse succeeds. Clients may insist on strict adherence to the format by
569 * calling setLenient(false).
4388f060 570 * @see DateFormat::setLenient(boolean)
b75a7d8f
A
571 *
572 * @param text The date/time string to be parsed
4388f060
A
573 * @param cal A Calendar set on input to the date and time to be used for
574 * missing values in the date/time string being parsed, and set
575 * on output to the parsed date/time. When the calendar type is
576 * different from the internal calendar held by this SimpleDateFormat
577 * instance, the internal calendar will be cloned to a work
578 * calendar set to the same milliseconds and time zone as the
579 * cal parameter, field values will be parsed based on the work
580 * calendar, then the result (milliseconds and time zone) will
581 * be set in this calendar.
b75a7d8f
A
582 * @param pos On input, the position at which to start parsing; on
583 * output, the position at which parsing terminated, or the
584 * start position if the parse failed.
585 * @return A valid UDate if the input could be parsed.
586 * @stable ICU 2.1
587 */
588 virtual void parse( const UnicodeString& text,
589 Calendar& cal,
590 ParsePosition& pos) const;
591
592 /**
593 * Parse a date/time string starting at the given parse position. For
594 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
595 * that is equivalent to Date(837039928046).
596 * <P>
597 * By default, parsing is lenient: If the input is not in the form used by
598 * this object's format method but can still be parsed as a date, then the
599 * parse succeeds. Clients may insist on strict adherence to the format by
600 * calling setLenient(false).
b75a7d8f 601 * @see DateFormat::setLenient(boolean)
4388f060
A
602 * <P>
603 * Note that the normal date formats associated with some calendars - such
604 * as the Chinese lunar calendar - do not specify enough fields to enable
605 * dates to be parsed unambiguously. In the case of the Chinese lunar
606 * calendar, while the year within the current 60-year cycle is specified,
607 * the number of such cycles since the start date of the calendar (in the
608 * ERA field of the Calendar object) is not normally part of the format,
609 * and parsing may assume the wrong era. For cases such as this it is
610 * recommended that clients parse using the method
611 * parse(const UnicodeString&, Calendar& cal, ParsePosition&)
612 * with the Calendar passed in set to the current date, or to a date
613 * within the era/cycle that should be assumed if absent in the format.
b75a7d8f
A
614 *
615 * @param text The date/time string to be parsed
616 * @param pos On input, the position at which to start parsing; on
617 * output, the position at which parsing terminated, or the
618 * start position if the parse failed.
619 * @return A valid UDate if the input could be parsed.
620 * @stable ICU 2.0
621 */
622 UDate parse( const UnicodeString& text,
623 ParsePosition& pos) const;
624
625
626 /**
627 * Parse a date/time string. For example, a time text "07/10/96 4:5 PM, PDT"
628 * will be parsed into a UDate that is equivalent to Date(837039928046).
629 * Parsing begins at the beginning of the string and proceeds as far as
630 * possible. Assuming no parse errors were encountered, this function
631 * doesn't return any information about how much of the string was consumed
632 * by the parsing. If you need that information, use the version of
633 * parse() that takes a ParsePosition.
4388f060
A
634 * <P>
635 * By default, parsing is lenient: If the input is not in the form used by
636 * this object's format method but can still be parsed as a date, then the
637 * parse succeeds. Clients may insist on strict adherence to the format by
638 * calling setLenient(false).
639 * @see DateFormat::setLenient(boolean)
640 * <P>
641 * Note that the normal date formats associated with some calendars - such
642 * as the Chinese lunar calendar - do not specify enough fields to enable
643 * dates to be parsed unambiguously. In the case of the Chinese lunar
644 * calendar, while the year within the current 60-year cycle is specified,
645 * the number of such cycles since the start date of the calendar (in the
646 * ERA field of the Calendar object) is not normally part of the format,
647 * and parsing may assume the wrong era. For cases such as this it is
648 * recommended that clients parse using the method
649 * parse(const UnicodeString&, Calendar& cal, ParsePosition&)
650 * with the Calendar passed in set to the current date, or to a date
651 * within the era/cycle that should be assumed if absent in the format.
b75a7d8f 652 *
4388f060 653 * @param text The date/time string to be parsed into a UDate value.
b75a7d8f
A
654 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
655 * an error value if there was a parse error.
656 * @return A valid UDate if the input could be parsed.
657 * @stable ICU 2.0
658 */
659 virtual UDate parse( const UnicodeString& text,
660 UErrorCode& status) const;
661
662 /**
663 * Set the start UDate used to interpret two-digit year strings.
664 * When dates are parsed having 2-digit year strings, they are placed within
665 * a assumed range of 100 years starting on the two digit start date. For
666 * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
667 * some other year. SimpleDateFormat chooses a year so that the resultant
668 * date is on or after the two digit start date and within 100 years of the
669 * two digit start date.
670 * <P>
671 * By default, the two digit start date is set to 80 years before the current
672 * time at which a SimpleDateFormat object is created.
673 * @param d start UDate used to interpret two-digit year strings.
674 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
675 * an error value if there was a parse error.
676 * @stable ICU 2.0
677 */
678 virtual void set2DigitYearStart(UDate d, UErrorCode& status);
679
680 /**
681 * Get the start UDate used to interpret two-digit year strings.
682 * When dates are parsed having 2-digit year strings, they are placed within
683 * a assumed range of 100 years starting on the two digit start date. For
684 * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
685 * some other year. SimpleDateFormat chooses a year so that the resultant
686 * date is on or after the two digit start date and within 100 years of the
687 * two digit start date.
688 * <P>
689 * By default, the two digit start date is set to 80 years before the current
690 * time at which a SimpleDateFormat object is created.
691 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
692 * an error value if there was a parse error.
693 * @stable ICU 2.0
694 */
695 UDate get2DigitYearStart(UErrorCode& status) const;
696
697 /**
698 * Return a pattern string describing this date format.
699 * @param result Output param to receive the pattern.
700 * @return A reference to 'result'.
701 * @stable ICU 2.0
702 */
703 virtual UnicodeString& toPattern(UnicodeString& result) const;
704
705 /**
706 * Return a localized pattern string describing this date format.
707 * In most cases, this will return the same thing as toPattern(),
708 * but a locale can specify characters to use in pattern descriptions
709 * in place of the ones described in this class's class documentation.
710 * (Presumably, letters that would be more mnemonic in that locale's
711 * language.) This function would produce a pattern using those
712 * letters.
713 *
714 * @param result Receives the localized pattern.
715 * @param status Output param set to success/failure code on
716 * exit. If the pattern is invalid, this will be
717 * set to a failure result.
718 * @return A reference to 'result'.
719 * @stable ICU 2.0
720 */
721 virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
722 UErrorCode& status) const;
723
724 /**
725 * Apply the given unlocalized pattern string to this date format.
726 * (i.e., after this call, this formatter will format dates according to
727 * the new pattern)
728 *
729 * @param pattern The pattern to be applied.
730 * @stable ICU 2.0
731 */
732 virtual void applyPattern(const UnicodeString& pattern);
733
734 /**
735 * Apply the given localized pattern string to this date format.
736 * (see toLocalizedPattern() for more information on localized patterns.)
737 *
738 * @param pattern The localized pattern to be applied.
739 * @param status Output param set to success/failure code on
740 * exit. If the pattern is invalid, this will be
741 * set to a failure result.
742 * @stable ICU 2.0
743 */
744 virtual void applyLocalizedPattern(const UnicodeString& pattern,
745 UErrorCode& status);
746
747 /**
748 * Gets the date/time formatting symbols (this is an object carrying
749 * the various strings and other symbols used in formatting: e.g., month
750 * names and abbreviations, time zone names, AM/PM strings, etc.)
751 * @return a copy of the date-time formatting data associated
752 * with this date-time formatter.
753 * @stable ICU 2.0
754 */
755 virtual const DateFormatSymbols* getDateFormatSymbols(void) const;
756
757 /**
758 * Set the date/time formatting symbols. The caller no longer owns the
759 * DateFormatSymbols object and should not delete it after making this call.
760 * @param newFormatSymbols the given date-time formatting symbols to copy.
761 * @stable ICU 2.0
762 */
763 virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
764
765 /**
766 * Set the date/time formatting data.
767 * @param newFormatSymbols the given date-time formatting symbols to copy.
768 * @stable ICU 2.0
769 */
770 virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
771
772 /**
773 * Return the class ID for this class. This is useful only for comparing to
774 * a return value from getDynamicClassID(). For example:
775 * <pre>
776 * . Base* polymorphic_pointer = createPolymorphicObject();
777 * . if (polymorphic_pointer->getDynamicClassID() ==
778 * . erived::getStaticClassID()) ...
779 * </pre>
780 * @return The class ID for all objects of this class.
781 * @stable ICU 2.0
782 */
374ca955 783 static UClassID U_EXPORT2 getStaticClassID(void);
b75a7d8f
A
784
785 /**
786 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
787 * method is to implement a simple version of RTTI, since not all C++
788 * compilers support genuine RTTI. Polymorphic operator==() and clone()
789 * methods call this method.
790 *
791 * @return The class ID for this object. All objects of a
792 * given class have the same class ID. Objects of
793 * other classes have different class IDs.
794 * @stable ICU 2.0
795 */
796 virtual UClassID getDynamicClassID(void) const;
797
798 /**
799 * Set the calendar to be used by this date format. Initially, the default
800 * calendar for the specified or default locale is used. The caller should
801 * not delete the Calendar object after it is adopted by this call.
802 * Adopting a new calendar will change to the default symbols.
803 *
804 * @param calendarToAdopt Calendar object to be adopted.
805 * @stable ICU 2.0
806 */
807 virtual void adoptCalendar(Calendar* calendarToAdopt);
808
4388f060
A
809/* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
810 /**
811 * Set the formatter's default value for a particular context type,
812 * such as UDAT_CAPITALIZATION.
813 * @param type The context type for which the default value should be set.
814 * @param value The default value to set for the specified context type.
815 * @param status Input/output status. If at entry this indicates a failure
816 * status, the function will do nothing; otherwise this will be
817 * updated with any new status from the function.
818 * @draft ICU 49
819 */
820 virtual void setDefaultContext(UDateFormatContextType type, UDateFormatContextValue value,
821 UErrorCode& status);
822
823/* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
824 /**
825 * Get the formatter's default value for a particular context type,
826 * such as UDAT_CAPITALIZATION.
827 * @param type The context type for which the default value should be obtained.
828 * @param status Input/output status. If at entry this indicates a failure
829 * status, the function will do nothing; otherwise this will be
830 * updated with any new status from the function.
831 * @return The current default value for the specified context type.
832 * @draft ICU 49
833 */
834 virtual int32_t getDefaultContext(UDateFormatContextType type, UErrorCode& status) const;
835
836#ifndef U_HIDE_INTERNAL_API
837 /**
838 * Sets the TimeZoneFormat to be used by this date/time formatter.
839 * The caller should not delete the TimeZoneFormat object after
840 * it is adopted by this call.
841 * @param timeZoneFormatToAdopt The TimeZoneFormat object to be adopted.
842 * @internal ICU 49 technology preview
843 */
844 virtual void adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt);
845
846 /**
847 * Sets the TimeZoneFormat to be used by this date/time formatter.
848 * @param newTimeZoneFormat The TimeZoneFormat object to copy.
849 * @internal ICU 49 technology preview
850 */
851 virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat);
852
853 /**
854 * Gets the time zone format object associated with this date/time formatter.
855 * @return the time zone format associated with this date/time formatter.
856 * @internal ICU 49 technology preview
857 */
858 virtual const TimeZoneFormat* getTimeZoneFormat(void) const;
859#endif /* U_HIDE_INTERNAL_API */
860
861#ifndef U_HIDE_INTERNAL_API
46f4442e
A
862 /**
863 * This is for ICU internal use only. Please do not use.
864 * Check whether the 'field' is smaller than all the fields covered in
729e4ab9 865 * pattern, return TRUE if it is. The sequence of calendar field,
46f4442e
A
866 * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
867 * @param field the calendar field need to check against
729e4ab9 868 * @return TRUE if the 'field' is smaller than all the fields
46f4442e
A
869 * covered in pattern. FALSE otherwise.
870 * @internal ICU 4.0
871 */
872 UBool isFieldUnitIgnored(UCalendarDateFields field) const;
873
874
875 /**
876 * This is for ICU internal use only. Please do not use.
877 * Check whether the 'field' is smaller than all the fields covered in
729e4ab9 878 * pattern, return TRUE if it is. The sequence of calendar field,
46f4442e
A
879 * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
880 * @param pattern the pattern to check against
881 * @param field the calendar field need to check against
729e4ab9 882 * @return TRUE if the 'field' is smaller than all the fields
46f4442e
A
883 * covered in pattern. FALSE otherwise.
884 * @internal ICU 4.0
885 */
729e4ab9 886 static UBool isFieldUnitIgnored(const UnicodeString& pattern,
46f4442e
A
887 UCalendarDateFields field);
888
46f4442e
A
889 /**
890 * This is for ICU internal use only. Please do not use.
891 * Get the locale of this simple date formatter.
892 * It is used in DateIntervalFormat.
893 *
894 * @return locale in this simple date formatter
895 * @internal ICU 4.0
896 */
897 const Locale& getSmpFmtLocale(void) const;
4388f060 898#endif /* U_HIDE_INTERNAL_API */
46f4442e 899
b75a7d8f 900private:
b75a7d8f
A
901 friend class DateFormat;
902
903 void initializeDefaultCentury(void);
904
905 SimpleDateFormat(); // default constructor not implemented
906
907 /**
908 * Used by the DateFormat factory methods to construct a SimpleDateFormat.
909 * @param timeStyle the time style.
910 * @param dateStyle the date style.
911 * @param locale the given locale.
912 * @param status Output param set to success/failure code on
913 * exit.
914 */
915 SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
916
917 /**
918 * Construct a SimpleDateFormat for the given locale. If no resource data
919 * is available, create an object of last resort, using hard-coded strings.
920 * This is an internal method, called by DateFormat. It should never fail.
921 * @param locale the given locale.
922 * @param status Output param set to success/failure code on
923 * exit.
924 */
925 SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
926
729e4ab9
A
927 /**
928 * Hook called by format(... FieldPosition& ...) and format(...FieldPositionIterator&...)
929 */
4388f060
A
930 UnicodeString& _format(Calendar& cal, UDateFormatContextValue capitalizationContext,
931 UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
729e4ab9 932
b75a7d8f
A
933 /**
934 * Called by format() to format a single field.
935 *
936 * @param appendTo Output parameter to receive result.
937 * Result is appended to existing contents.
938 * @param ch The format character we encountered in the pattern.
939 * @param count Number of characters in the current pattern symbol (e.g.,
940 * "yyyy" in the pattern would result in a call to this function
941 * with ch equal to 'y' and count equal to 4)
4388f060
A
942 * @param capitalizationContext Capitalization context for this date format.
943 * @param fieldNum Zero-based numbering of current field within the overall format.
729e4ab9 944 * @param handler Records information about field positions.
4388f060 945 * @param cal Calendar to use
b75a7d8f
A
946 * @param status Receives a status code, which will be U_ZERO_ERROR if the operation
947 * succeeds.
948 */
729e4ab9
A
949 void subFormat(UnicodeString &appendTo,
950 UChar ch,
951 int32_t count,
4388f060
A
952 UDateFormatContextValue capitalizationContext,
953 int32_t fieldNum,
729e4ab9
A
954 FieldPositionHandler& handler,
955 Calendar& cal,
956 UErrorCode& status) const; // in case of illegal argument
b75a7d8f
A
957
958 /**
959 * Used by subFormat() to format a numeric value.
960 * Appends to toAppendTo a string representation of "value"
961 * having a number of digits between "minDigits" and
962 * "maxDigits". Uses the DateFormat's NumberFormat.
963 *
4388f060 964 * @param currentNumberFormat
b75a7d8f
A
965 * @param appendTo Output parameter to receive result.
966 * Formatted number is appended to existing contents.
967 * @param value Value to format.
968 * @param minDigits Minimum number of digits the result should have
969 * @param maxDigits Maximum number of digits the result should have
970 */
729e4ab9
A
971 void zeroPaddingNumber(NumberFormat *currentNumberFormat,
972 UnicodeString &appendTo,
973 int32_t value,
974 int32_t minDigits,
975 int32_t maxDigits) const;
b75a7d8f
A
976
977 /**
978 * Return true if the given format character, occuring count
979 * times, represents a numeric field.
980 */
981 static UBool isNumeric(UChar formatChar, int32_t count);
982
983 /**
984 * initializes fCalendar from parameters. Returns fCalendar as a convenience.
985 * @param adoptZone Zone to be adopted, or NULL for TimeZone::createDefault().
986 * @param locale Locale of the calendar
987 * @param status Error code
988 * @return the newly constructed fCalendar
989 */
990 Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
991
992 /**
993 * initializes fSymbols from parameters.
994 * @param locale Locale of the symbols
995 * @param calendar Alias to Calendar that will be used.
996 * @param status Error code
997 */
998 void initializeSymbols(const Locale& locale, Calendar* calendar, UErrorCode& status);
999
1000 /**
1001 * Called by several of the constructors to load pattern data and formatting symbols
1002 * out of a resource bundle and initialize the locale based on it.
1003 * @param timeStyle The time style, as passed to DateFormat::createDateInstance().
1004 * @param dateStyle The date style, as passed to DateFormat::createTimeInstance().
1005 * @param locale The locale to load the patterns from.
1006 * @param status Filled in with an error code if loading the data from the
1007 * resources fails.
1008 */
1009 void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1010
1011 /**
1012 * Called by construct() and the various constructors to set up the SimpleDateFormat's
1013 * Calendar and NumberFormat objects.
1014 * @param locale The locale for which we want a Calendar and a NumberFormat.
4388f060 1015 * @param status Filled in with an error code if creating either subobject fails.
b75a7d8f
A
1016 */
1017 void initialize(const Locale& locale, UErrorCode& status);
1018
1019 /**
1020 * Private code-size reduction function used by subParse.
1021 * @param text the time text being parsed.
1022 * @param start where to start parsing.
1023 * @param field the date field being parsed.
1024 * @param stringArray the string array to parsed.
1025 * @param stringArrayCount the size of the array.
4388f060 1026 * @param monthPattern pointer to leap month pattern, or NULL if none.
b75a7d8f
A
1027 * @param cal a Calendar set to the date and time to be formatted
1028 * into a date/time string.
1029 * @return the new start position if matching succeeded; a negative number
1030 * indicating matching failure, otherwise.
1031 */
1032 int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
4388f060
A
1033 const UnicodeString* stringArray, int32_t stringArrayCount,
1034 const UnicodeString* monthPattern, Calendar& cal) const;
b75a7d8f 1035
73c04bcf
A
1036 /**
1037 * Private code-size reduction function used by subParse.
1038 * @param text the time text being parsed.
1039 * @param start where to start parsing.
1040 * @param field the date field being parsed.
1041 * @param stringArray the string array to parsed.
1042 * @param stringArrayCount the size of the array.
1043 * @param cal a Calendar set to the date and time to be formatted
1044 * into a date/time string.
1045 * @return the new start position if matching succeeded; a negative number
1046 * indicating matching failure, otherwise.
1047 */
1048 int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1049 const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
46f4442e
A
1050
1051 /**
1052 * Private function used by subParse to match literal pattern text.
1053 *
1054 * @param pattern the pattern string
1055 * @param patternOffset the starting offset into the pattern text. On
1056 * outupt will be set the offset of the first non-literal character in the pattern
1057 * @param text the text being parsed
1058 * @param textOffset the starting offset into the text. On output
1059 * will be set to the offset of the character after the match
1060 * @param lenient <code>TRUE</code> if the parse is lenient, <code>FALSE</code> otherwise.
1061 *
1062 * @return <code>TRUE</code> if the literal text could be matched, <code>FALSE</code> otherwise.
1063 */
1064 static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
1065 const UnicodeString &text, int32_t &textOffset, UBool lenient);
1066
b75a7d8f
A
1067 /**
1068 * Private member function that converts the parsed date strings into
1069 * timeFields. Returns -start (for ParsePosition) if failed.
1070 * @param text the time text to be parsed.
1071 * @param start where to start parsing.
1072 * @param ch the pattern character for the date field text to be parsed.
1073 * @param count the count of a pattern character.
1074 * @param obeyCount if true then the count is strictly obeyed.
4388f060 1075 * @param allowNegative
b75a7d8f 1076 * @param ambiguousYear If true then the two-digit year == the default start year.
729e4ab9 1077 * @param saveHebrewMonth Used to hang onto month until year is known.
b75a7d8f
A
1078 * @param cal a Calendar set to the date and time to be formatted
1079 * into a date/time string.
4388f060
A
1080 * @param patLoc
1081 * @param numericLeapMonthFormatter If non-null, used to parse numeric leap months.
b75a7d8f
A
1082 * @return the new start position if matching succeeded; a negative number
1083 * indicating matching failure, otherwise.
1084 */
1085 int32_t subParse(const UnicodeString& text, int32_t& start, UChar ch, int32_t count,
729e4ab9 1086 UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
4388f060 1087 int32_t patLoc, MessageFormat * numericLeapMonthFormatter) const;
b75a7d8f
A
1088
1089 void parseInt(const UnicodeString& text,
1090 Formattable& number,
1091 ParsePosition& pos,
729e4ab9
A
1092 UBool allowNegative,
1093 NumberFormat *fmt) const;
b75a7d8f 1094
46f4442e
A
1095 void parseInt(const UnicodeString& text,
1096 Formattable& number,
1097 int32_t maxDigits,
1098 ParsePosition& pos,
729e4ab9
A
1099 UBool allowNegative,
1100 NumberFormat *fmt) const;
1101
1102 int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
1103 int32_t patLoc, UBool isNegative) const;
46f4442e 1104
b75a7d8f
A
1105 /**
1106 * Translate a pattern, mapping each character in the from string to the
1107 * corresponding character in the to string. Return an error if the original
1108 * pattern contains an unmapped character, or if a quote is unmatched.
1109 * Quoted (single quotes only) material is not translated.
1110 * @param originalPattern the original pattern.
1111 * @param translatedPattern Output param to receive the translited pattern.
1112 * @param from the characters to be translited from.
1113 * @param to the characters to be translited to.
374ca955 1114 * @param status Receives a status code, which will be U_ZERO_ERROR
b75a7d8f
A
1115 * if the operation succeeds.
1116 */
1117 static void translatePattern(const UnicodeString& originalPattern,
1118 UnicodeString& translatedPattern,
1119 const UnicodeString& from,
1120 const UnicodeString& to,
1121 UErrorCode& status);
1122
1123 /**
1124 * Sets the starting date of the 100-year window that dates with 2-digit years
1125 * are considered to fall within.
1126 * @param startDate the start date
374ca955 1127 * @param status Receives a status code, which will be U_ZERO_ERROR
b75a7d8f
A
1128 * if the operation succeeds.
1129 */
1130 void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
729e4ab9
A
1131
1132 /**
1133 * Return the length matched by the given affix, or -1 if none.
1134 * Runs of white space in the affix, match runs of white space in
1135 * the input.
1136 * @param affix pattern string, taken as a literal
1137 * @param input input text
1138 * @param pos offset into input at which to begin matching
1139 * @return length of input that matches, or -1 if match failure
1140 */
1141 int32_t compareSimpleAffix(const UnicodeString& affix,
1142 const UnicodeString& input,
1143 int32_t pos) const;
1144
1145 /**
4388f060 1146 * Skip over a run of zero or more Pattern_White_Space characters at
729e4ab9
A
1147 * pos in text.
1148 */
4388f060 1149 int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
729e4ab9
A
1150
1151 /**
1152 * Skip over a run of zero or more isUWhiteSpace() characters at pos
1153 * in text.
1154 */
1155 int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
1156
729e4ab9
A
1157 /**
1158 * Initialize NumberFormat instances used for numbering system overrides.
1159 */
1160 void initNumberFormatters(const Locale &locale,UErrorCode &status);
1161
1162 /**
1163 * Get the numbering system to be used for a particular field.
1164 */
1165 NumberFormat * getNumberFormatByIndex(UDateFormatField index) const;
1166
1167 /**
1168 * Parse the given override string and set up structures for number formats
1169 */
1170 void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
1171
b75a7d8f
A
1172 /**
1173 * Used to map pattern characters to Calendar field identifiers.
1174 */
1175 static const UCalendarDateFields fgPatternIndexToCalendarField[];
1176
1177 /**
1178 * Map index into pattern character string to DateFormat field number
1179 */
374ca955 1180 static const UDateFormatField fgPatternIndexToDateFormatField[];
b75a7d8f 1181
4388f060
A
1182 /**
1183 * Lazy TimeZoneFormat instantiation, semantically const
1184 */
1185 TimeZoneFormat *tzFormat() const;
1186
46f4442e
A
1187 /**
1188 * Used to map Calendar field to field level.
1189 * The larger the level, the smaller the field unit.
1190 * For example, UCAL_ERA level is 0, UCAL_YEAR level is 10,
1191 * UCAL_MONTH level is 20.
1192 */
1193 static const int32_t fgCalendarFieldToLevel[];
1194 static const int32_t fgPatternCharToLevel[];
1195
b75a7d8f
A
1196 /**
1197 * The formatting pattern for this formatter.
1198 */
1199 UnicodeString fPattern;
1200
729e4ab9
A
1201 /**
1202 * The numbering system override for dates.
1203 */
1204 UnicodeString fDateOverride;
1205
1206 /**
1207 * The numbering system override for times.
1208 */
1209 UnicodeString fTimeOverride;
1210
1211
b75a7d8f
A
1212 /**
1213 * The original locale used (for reloading symbols)
1214 */
1215 Locale fLocale;
1216
1217 /**
1218 * A pointer to an object containing the strings to use in formatting (e.g.,
1219 * month and day names, AM and PM strings, time zone names, etc.)
1220 */
1221 DateFormatSymbols* fSymbols; // Owned
1222
4388f060
A
1223 /**
1224 * The time zone formatter
1225 */
1226 TimeZoneFormat* fTimeZoneFormat;
1227
b75a7d8f
A
1228 /**
1229 * If dates have ambiguous years, we map them into the century starting
1230 * at defaultCenturyStart, which may be any date. If defaultCenturyStart is
1231 * set to SYSTEM_DEFAULT_CENTURY, which it is by default, then the system
1232 * values are used. The instance values defaultCenturyStart and
1233 * defaultCenturyStartYear are only used if explicitly set by the user
1234 * through the API method parseAmbiguousDatesAsAfter().
1235 */
1236 UDate fDefaultCenturyStart;
1237
1238 /**
1239 * See documentation for defaultCenturyStart.
1240 */
1241 /*transient*/ int32_t fDefaultCenturyStartYear;
b75a7d8f 1242
4388f060 1243 int32_t tztype; // here to avoid api change
46f4442e 1244
729e4ab9
A
1245 typedef struct NSOverride {
1246 NumberFormat *nf;
1247 int32_t hash;
1248 NSOverride *next;
1249 } NSOverride;
1250
729e4ab9
A
1251 NumberFormat **fNumberFormatters;
1252
1253 NSOverride *fOverrideList;
73c04bcf 1254
374ca955 1255 UBool fHaveDefaultCentury;
4388f060
A
1256
1257 UDateFormatContextValue fDefaultCapitalizationContext;
b75a7d8f
A
1258};
1259
b75a7d8f
A
1260inline UDate
1261SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
1262{
1263 return fDefaultCenturyStart;
1264}
1265
1266inline UnicodeString&
1267SimpleDateFormat::format(const Formattable& obj,
1268 UnicodeString& appendTo,
1269 UErrorCode& status) const {
1270 // Don't use Format:: - use immediate base class only,
1271 // in case immediate base modifies behavior later.
1272 return DateFormat::format(obj, appendTo, status);
1273}
1274
729e4ab9
A
1275inline UnicodeString&
1276SimpleDateFormat::format(const Formattable& obj,
1277 UnicodeString& appendTo,
1278 FieldPosition& pos,
1279 UErrorCode& status) const
1280{
1281 // Don't use Format:: - use immediate base class only,
1282 // in case immediate base modifies behavior later.
1283 return DateFormat::format(obj, appendTo, pos, status);
1284}
1285
1286inline UnicodeString&
1287SimpleDateFormat::format(const Formattable& obj,
1288 UnicodeString& appendTo,
1289 FieldPositionIterator* posIter,
1290 UErrorCode& status) const
1291{
1292 // Don't use Format:: - use immediate base class only,
1293 // in case immediate base modifies behavior later.
1294 return DateFormat::format(obj, appendTo, posIter, status);
1295}
1296
b75a7d8f
A
1297inline UnicodeString&
1298SimpleDateFormat::format(UDate date,
1299 UnicodeString& appendTo,
1300 FieldPosition& fieldPosition) const {
1301 // Don't use Format:: - use immediate base class only,
1302 // in case immediate base modifies behavior later.
1303 return DateFormat::format(date, appendTo, fieldPosition);
1304}
1305
729e4ab9
A
1306inline UnicodeString&
1307SimpleDateFormat::format(UDate date,
1308 UnicodeString& appendTo,
1309 FieldPositionIterator* posIter,
1310 UErrorCode& status) const {
1311 // Don't use Format:: - use immediate base class only,
1312 // in case immediate base modifies behavior later.
1313 return DateFormat::format(date, appendTo, posIter, status);
1314}
1315
b75a7d8f
A
1316inline UnicodeString&
1317SimpleDateFormat::format(UDate date, UnicodeString& appendTo) const {
1318 return DateFormat::format(date, appendTo);
1319}
1320
1321U_NAMESPACE_END
1322
1323#endif /* #if !UCONFIG_NO_FORMATTING */
1324
1325#endif // _SMPDTFMT
1326//eof