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