Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-22 09:09:31

0001 // © 2016 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 /*
0004 * Copyright (C) 1997-2016, International Business Machines Corporation and
0005 * others. All Rights Reserved.
0006 *******************************************************************************
0007 *
0008 * File SMPDTFMT.H
0009 *
0010 * Modification History:
0011 *
0012 *   Date        Name        Description
0013 *   02/19/97    aliu        Converted from java.
0014 *   07/09/97    helena      Make ParsePosition into a class.
0015 *   07/21/98    stephen     Added GMT_PLUS, GMT_MINUS
0016 *                            Changed setTwoDigitStartDate to set2DigitYearStart
0017 *                            Changed getTwoDigitStartDate to get2DigitYearStart
0018 *                            Removed subParseLong
0019 *                            Removed getZoneIndex (added in DateFormatSymbols)
0020 *   06/14/99    stephen     Removed fgTimeZoneDataSuffix
0021 *   10/14/99    aliu        Updated class doc to describe 2-digit year parsing
0022 *                           {j28 4182066}.
0023 *******************************************************************************
0024 */
0025 
0026 #ifndef SMPDTFMT_H
0027 #define SMPDTFMT_H
0028 
0029 #include "unicode/utypes.h"
0030 
0031 #if U_SHOW_CPLUSPLUS_API
0032 
0033 /**
0034  * \file
0035  * \brief C++ API: Format and parse dates in a language-independent manner.
0036  */
0037 
0038 #if !UCONFIG_NO_FORMATTING
0039 
0040 #include "unicode/datefmt.h"
0041 #include "unicode/udisplaycontext.h"
0042 #include "unicode/tzfmt.h"  /* for UTimeZoneFormatTimeType */
0043 #include "unicode/brkiter.h"
0044 
0045 U_NAMESPACE_BEGIN
0046 
0047 class DateFormatSymbols;
0048 class DateFormat;
0049 class MessageFormat;
0050 class FieldPositionHandler;
0051 class TimeZoneFormat;
0052 class SharedNumberFormat;
0053 class SimpleDateFormatMutableNFs;
0054 class DateIntervalFormat;
0055 
0056 namespace number {
0057 class LocalizedNumberFormatter;
0058 class SimpleNumberFormatter;
0059 }
0060 
0061 /**
0062  *
0063  * SimpleDateFormat is a concrete class for formatting and parsing dates in a
0064  * language-independent manner. It allows for formatting (millis -> text),
0065  * parsing (text -> millis), and normalization. Formats/Parses a date or time,
0066  * which is the standard milliseconds since 24:00 GMT, Jan 1, 1970.
0067  * <P>
0068  * Clients are encouraged to create a date-time formatter using DateFormat::getInstance(),
0069  * getDateInstance(), getDateInstance(), or getDateTimeInstance() rather than
0070  * explicitly constructing an instance of SimpleDateFormat.  This way, the client
0071  * is guaranteed to get an appropriate formatting pattern for whatever locale the
0072  * program is running in.  If the client needs more control, they should consider using
0073  * DateFormat::createInstanceForSkeleton().  However, if the client needs something more unusual than
0074  * the default patterns in the locales, he can construct a SimpleDateFormat directly
0075  * and give it an appropriate pattern (or use one of the factory methods on DateFormat
0076  * and modify the pattern after the fact with toPattern() and applyPattern().
0077  *
0078  * <p><strong>Date and Time Patterns:</strong></p>
0079  *
0080  * <p>Date and time formats are specified by <em>date and time pattern</em> strings.
0081  * The full syntax for date and time patterns can be found at
0082  * <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>.
0083  *
0084  * Within date and time pattern strings, all unquoted ASCII letters [A-Za-z] are reserved
0085  * as pattern letters representing calendar fields. Some of the most commonly used pattern letters are:</p>
0086  *
0087  * <table border="1">
0088  *     <tr>
0089  *         <th style="text-align: center">Sym.</th>
0090  *         <th style="text-align: center">No.</th>
0091  *         <th>Example</th>
0092  *         <th>Description</th>
0093  *     </tr>
0094  *     <tr>
0095  *         <td style="text-align: center">G</td>
0096  *         <td style="text-align: center">1..3</td>
0097  *         <td>AD</td>
0098  *         <td>Era - Replaced with the Era string for the current date. One to three letters for the
0099  *         abbreviated form, four letters for the long (wide) form, five for the narrow form.</td>
0100  *     </tr>
0101  *     <tr>
0102  *         <td style="text-align: center">y</td>
0103  *         <td style="text-align: center">1..n</td>
0104  *         <td>1996</td>
0105  *         <td>Year. Normally the length specifies the padding, but for two letters it also specifies the maximum
0106  *         length. Example:<div style="text-align: center">
0107  *             <center>
0108  *             <table border="1" cellpadding="2" cellspacing="0">
0109  *                 <tr>
0110  *                     <th>Year</th>
0111  *                     <th style="text-align: right">y</th>
0112  *                     <th style="text-align: right">yy</th>
0113  *                     <th style="text-align: right">yyy</th>
0114  *                     <th style="text-align: right">yyyy</th>
0115  *                     <th style="text-align: right">yyyyy</th>
0116  *                 </tr>
0117  *                 <tr>
0118  *                     <td>AD 1</td>
0119  *                     <td style="text-align: right">1</td>
0120  *                     <td style="text-align: right">01</td>
0121  *                     <td style="text-align: right">001</td>
0122  *                     <td style="text-align: right">0001</td>
0123  *                     <td style="text-align: right">00001</td>
0124  *                 </tr>
0125  *                 <tr>
0126  *                     <td>AD 12</td>
0127  *                     <td style="text-align: right">12</td>
0128  *                     <td style="text-align: right">12</td>
0129  *                     <td style="text-align: right">012</td>
0130  *                     <td style="text-align: right">0012</td>
0131  *                     <td style="text-align: right">00012</td>
0132  *                 </tr>
0133  *                 <tr>
0134  *                     <td>AD 123</td>
0135  *                     <td style="text-align: right">123</td>
0136  *                     <td style="text-align: right">23</td>
0137  *                     <td style="text-align: right">123</td>
0138  *                     <td style="text-align: right">0123</td>
0139  *                     <td style="text-align: right">00123</td>
0140  *                 </tr>
0141  *                 <tr>
0142  *                     <td>AD 1234</td>
0143  *                     <td style="text-align: right">1234</td>
0144  *                     <td style="text-align: right">34</td>
0145  *                     <td style="text-align: right">1234</td>
0146  *                     <td style="text-align: right">1234</td>
0147  *                     <td style="text-align: right">01234</td>
0148  *                 </tr>
0149  *                 <tr>
0150  *                     <td>AD 12345</td>
0151  *                     <td style="text-align: right">12345</td>
0152  *                     <td style="text-align: right">45</td>
0153  *                     <td style="text-align: right">12345</td>
0154  *                     <td style="text-align: right">12345</td>
0155  *                     <td style="text-align: right">12345</td>
0156  *                 </tr>
0157  *             </table>
0158  *             </center></div>
0159  *         </td>
0160  *     </tr>
0161  *     <tr>
0162  *         <td rowspan="3" style="text-align: center">Q</td>
0163  *         <td style="text-align: center">1..2</td>
0164  *         <td>02</td>
0165  *         <td rowspan="3">Quarter - Use one or two for the numerical quarter, three for the abbreviation, or four
0166  *         for the full (wide) name (five for the narrow name is not yet supported).</td>
0167  *     </tr>
0168  *     <tr>
0169  *         <td style="text-align: center">3</td>
0170  *         <td>Q2</td>
0171  *     </tr>
0172  *     <tr>
0173  *         <td style="text-align: center">4</td>
0174  *         <td>2nd quarter</td>
0175  *     </tr>
0176  *     <tr>
0177  *         <td rowspan="4" style="text-align: center">M</td>
0178  *         <td style="text-align: center">1..2</td>
0179  *         <td>09</td>
0180  *         <td rowspan="4">Month - Use one or two for the numerical month, three for the abbreviation, four for
0181  *         the full (wide) name, or five for the narrow name. With two ("MM"), the month number is zero-padded
0182  *         if necessary (e.g. "08").</td>
0183  *     </tr>
0184  *     <tr>
0185  *         <td style="text-align: center">3</td>
0186  *         <td>Sep</td>
0187  *     </tr>
0188  *     <tr>
0189  *         <td style="text-align: center">4</td>
0190  *         <td>September</td>
0191  *     </tr>
0192  *     <tr>
0193  *         <td style="text-align: center">5</td>
0194  *         <td>S</td>
0195  *     </tr>
0196  *     <tr>
0197  *         <td style="text-align: center">d</td>
0198  *         <td style="text-align: center">1..2</td>
0199  *         <td>1</td>
0200  *         <td>Date - Day of the month. Use "d" to show the minimum number of digits, or "dd" to always show
0201  *         two digits (zero-padding if necessary, e.g. "08").</td>
0202  *     </tr>
0203  *     <tr>
0204  *         <td rowspan="4" style="text-align: center">E</td>
0205  *         <td style="text-align: center">1..3</td>
0206  *         <td>Tue</td>
0207  *         <td rowspan="4">Day of week - Use one through three letters for the short day, four for the full (wide) name,
0208  *         five for the narrow name, or six for the short name.</td>
0209  *     </tr>
0210  *     <tr>
0211  *         <td style="text-align: center">4</td>
0212  *         <td>Tuesday</td>
0213  *     </tr>
0214  *     <tr>
0215  *         <td style="text-align: center">5</td>
0216  *         <td>T</td>
0217  *     </tr>
0218  *     <tr>
0219  *         <td style="text-align: center">6</td>
0220  *         <td>Tu</td>
0221  *     </tr>
0222  *     <tr>
0223  *         <td style="text-align: center">a</td>
0224  *         <td style="text-align: center">1</td>
0225  *         <td>AM</td>
0226  *         <td>AM or PM</td>
0227  *     </tr>
0228  *     <tr>
0229  *         <td style="text-align: center">h</td>
0230  *         <td style="text-align: center">1..2</td>
0231  *         <td>11</td>
0232  *         <td>Hour [1-12]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern
0233  *         generation, it should match the 12-hour-cycle format preferred by the locale (h or K); it should not match
0234  *         a 24-hour-cycle format (H or k). Use hh for zero padding.</td>
0235  *     </tr>
0236  *     <tr>
0237  *         <td style="text-align: center">H</td>
0238  *         <td style="text-align: center">1..2</td>
0239  *         <td>13</td>
0240  *         <td>Hour [0-23]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern
0241  *         generation, it should match the 24-hour-cycle format preferred by the locale (H or k); it should not match a
0242  *         12-hour-cycle format (h or K). Use HH for zero padding.</td>
0243  *     </tr>
0244  *     <tr>
0245  *         <td style="text-align: center">m</td>
0246  *         <td style="text-align: center">1..2</td>
0247  *         <td>59</td>
0248  *         <td>Minute. Use "m" to show the minimum number of digits, or "mm" to always show two digits
0249  *         (zero-padding if necessary, e.g. "08")..</td>
0250  *     </tr>
0251  *     <tr>
0252  *         <td style="text-align: center">s</td>
0253  *         <td style="text-align: center">1..2</td>
0254  *         <td>12</td>
0255  *         <td>Second. Use "s" to show the minimum number of digits, or "ss" to always show two digits
0256  *         (zero-padding if necessary, e.g. "08").</td>
0257  *     </tr>
0258  *     <tr>
0259  *         <td rowspan="2" style="text-align: center">z</td>
0260  *         <td style="text-align: center">1..3</td>
0261  *         <td>PDT</td>
0262  *         <td>Time zone.  The <i>short specific non-location format</i>.
0263  *         Where that is unavailable, falls back to the <i>short localized GMT format</i> ("O").</td>
0264  *     </tr>
0265  *     <tr>
0266  *         <td style="text-align: center">4</td>
0267  *         <td>Pacific Daylight Time</td>
0268  *         <td>The <i>long specific non-location format</i>.
0269  *         Where that is unavailable, falls back to the <i>long localized GMT format</i> ("OOOO").</td>
0270  *     </tr>
0271  *     <tr>
0272  *         <td rowspan="2" style="text-align: center">v</td>
0273  *         <td style="text-align: center">1</td>
0274  *         <td>PT</td>
0275  *         <td>Time zone. The <i>short generic non-location format</i>.
0276  *         Where that is unavailable, falls back to the <i>generic location format</i> ("VVVV"),
0277  *         then the <i>short localized GMT format</i> as the final fallback.</td>
0278  *     </tr>
0279  *     <tr>
0280  *         <td style="text-align: center">4</td>
0281  *         <td>Pacific Time</td>
0282  *         <td>The <i>long generic non-location format</i>.
0283  *         Where that is unavailable, falls back to <i>generic location format</i> ("VVVV").
0284  *     </tr>
0285  * </table>
0286  *
0287  * <P>
0288  * Any characters in the pattern that are not in the ranges of ['a'..'z'] and
0289  * ['A'..'Z'] will be treated as quoted text. For instance, characters
0290  * like ':', '.', ' ', '#' and '@' will appear in the resulting time text
0291  * even they are not embraced within single quotes.
0292  * <P>
0293  * A pattern containing any invalid pattern letter will result in a failing
0294  * UErrorCode result during formatting or parsing.
0295  * <P>
0296  * Examples using the US locale:
0297  * <pre>
0298  * \code
0299  *    Format Pattern                         Result
0300  *    --------------                         -------
0301  *    "yyyy.MM.dd G 'at' HH:mm:ss vvvv" ->>  1996.07.10 AD at 15:08:56 Pacific Time
0302  *    "EEE, MMM d, ''yy"                ->>  Wed, July 10, '96
0303  *    "h:mm a"                          ->>  12:08 PM
0304  *    "hh 'o''clock' a, zzzz"           ->>  12 o'clock PM, Pacific Daylight Time
0305  *    "K:mm a, vvv"                     ->>  0:00 PM, PT
0306  *    "yyyyy.MMMMM.dd GGG hh:mm aaa"    ->>  1996.July.10 AD 12:08 PM
0307  * \endcode
0308  * </pre>
0309  * Code Sample:
0310  * <pre>
0311  * \code
0312  *     UErrorCode success = U_ZERO_ERROR;
0313  *     SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "PST");
0314  *     pdt->setStartRule( Calendar::APRIL, 1, Calendar::SUNDAY, 2*60*60*1000);
0315  *     pdt->setEndRule( Calendar::OCTOBER, -1, Calendar::SUNDAY, 2*60*60*1000);
0316  *
0317  *     // Format the current time.
0318  *     SimpleDateFormat* formatter
0319  *         = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz", success );
0320  *     GregorianCalendar cal(success);
0321  *     UDate currentTime_1 = cal.getTime(success);
0322  *     FieldPosition fp(FieldPosition::DONT_CARE);
0323  *     UnicodeString dateString;
0324  *     formatter->format( currentTime_1, dateString, fp );
0325  *     cout << "result: " << dateString << endl;
0326  *
0327  *     // Parse the previous string back into a Date.
0328  *     ParsePosition pp(0);
0329  *     UDate currentTime_2 = formatter->parse(dateString, pp );
0330  * \endcode
0331  * </pre>
0332  * In the above example, the time value "currentTime_2" obtained from parsing
0333  * will be equal to currentTime_1. However, they may not be equal if the am/pm
0334  * marker 'a' is left out from the format pattern while the "hour in am/pm"
0335  * pattern symbol is used. This information loss can happen when formatting the
0336  * time in PM.
0337  *
0338  * <p>
0339  * When parsing a date string using the abbreviated year pattern ("y" or "yy"),
0340  * SimpleDateFormat must interpret the abbreviated year
0341  * relative to some century.  It does this by adjusting dates to be
0342  * within 80 years before and 20 years after the time the SimpleDateFormat
0343  * instance is created. For example, using a pattern of "MM/dd/yy" and a
0344  * SimpleDateFormat instance created on Jan 1, 1997,  the string
0345  * "01/11/12" would be interpreted as Jan 11, 2012 while the string "05/04/64"
0346  * would be interpreted as May 4, 1964.
0347  * During parsing, only strings consisting of exactly two digits, as defined by
0348  * <code>Unicode::isDigit()</code>, will be parsed into the default century.
0349  * Any other numeric string, such as a one digit string, a three or more digit
0350  * string, or a two digit string that isn't all digits (for example, "-1"), is
0351  * interpreted literally.  So "01/02/3" or "01/02/003" are parsed (for the
0352  * Gregorian calendar), using the same pattern, as Jan 2, 3 AD.  Likewise (but
0353  * only in lenient parse mode, the default) "01/02/-3" is parsed as Jan 2, 4 BC.
0354  *
0355  * <p>
0356  * If the year pattern has more than two 'y' characters, the year is
0357  * interpreted literally, regardless of the number of digits.  So using the
0358  * pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
0359  *
0360  * <p>
0361  * When numeric fields abut one another directly, with no intervening delimiter
0362  * characters, they constitute a run of abutting numeric fields.  Such runs are
0363  * parsed specially.  For example, the format "HHmmss" parses the input text
0364  * "123456" to 12:34:56, parses the input text "12345" to 1:23:45, and fails to
0365  * parse "1234".  In other words, the leftmost field of the run is flexible,
0366  * while the others keep a fixed width.  If the parse fails anywhere in the run,
0367  * then the leftmost field is shortened by one character, and the entire run is
0368  * parsed again. This is repeated until either the parse succeeds or the
0369  * leftmost field is one character in length.  If the parse still fails at that
0370  * point, the parse of the run fails.
0371  *
0372  * <P>
0373  * For time zones that have no names, SimpleDateFormat uses strings GMT+hours:minutes or
0374  * GMT-hours:minutes.
0375  * <P>
0376  * The calendar defines what is the first day of the week, the first week of the
0377  * year, whether hours are zero based or not (0 vs 12 or 24), and the timezone.
0378  * There is one common number format to handle all the numbers; the digit count
0379  * is handled programmatically according to the pattern.
0380  *
0381  * <p><em>User subclasses are not supported.</em> While clients may write
0382  * subclasses, such code will not necessarily work and will not be
0383  * guaranteed to work stably from release to release.
0384  */
0385 class U_I18N_API SimpleDateFormat: public DateFormat {
0386 public:
0387     /**
0388      * Construct a SimpleDateFormat using the default pattern for the default
0389      * locale.
0390      * <P>
0391      * [Note:] Not all locales support SimpleDateFormat; for full generality,
0392      * use the factory methods in the DateFormat class.
0393      * @param status    Output param set to success/failure code.
0394      * @stable ICU 2.0
0395      */
0396     SimpleDateFormat(UErrorCode& status);
0397 
0398     /**
0399      * Construct a SimpleDateFormat using the given pattern and the default locale.
0400      * The locale is used to obtain the symbols used in formatting (e.g., the
0401      * names of the months), but not to provide the pattern.
0402      * <P>
0403      * [Note:] Not all locales support SimpleDateFormat; for full generality,
0404      * use the factory methods in the DateFormat class.
0405      * @param pattern    the pattern for the format.
0406      * @param status     Output param set to success/failure code.
0407      * @stable ICU 2.0
0408      */
0409     SimpleDateFormat(const UnicodeString& pattern,
0410                      UErrorCode& status);
0411 
0412     /**
0413      * Construct a SimpleDateFormat using the given pattern, numbering system override, and the default locale.
0414      * The locale is used to obtain the symbols used in formatting (e.g., the
0415      * names of the months), but not to provide the pattern.
0416      * <P>
0417      * A numbering system override is a string containing either the name of a known numbering system,
0418      * or a set of field and numbering system pairs that specify which fields are to be formatted with
0419      * the alternate numbering system.  For example, to specify that all numeric fields in the specified
0420      * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
0421      * as "thai".  To specify that just the year portion of the date be formatted using Hebrew numbering,
0422      * use the override string "y=hebrew".  Numbering system overrides can be combined using a semi-colon
0423      * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
0424      *
0425      * <P>
0426      * [Note:] Not all locales support SimpleDateFormat; for full generality,
0427      * use the factory methods in the DateFormat class.
0428      * @param pattern    the pattern for the format.
0429      * @param override   the override string.
0430      * @param status     Output param set to success/failure code.
0431      * @stable ICU 4.2
0432      */
0433     SimpleDateFormat(const UnicodeString& pattern,
0434                      const UnicodeString& override,
0435                      UErrorCode& status);
0436 
0437     /**
0438      * Construct a SimpleDateFormat using the given pattern and locale.
0439      * The locale is used to obtain the symbols used in formatting (e.g., the
0440      * names of the months), but not to provide the pattern.
0441      * <P>
0442      * [Note:] Not all locales support SimpleDateFormat; for full generality,
0443      * use the factory methods in the DateFormat class.
0444      * @param pattern    the pattern for the format.
0445      * @param locale     the given locale.
0446      * @param status     Output param set to success/failure code.
0447      * @stable ICU 2.0
0448      */
0449     SimpleDateFormat(const UnicodeString& pattern,
0450                      const Locale& locale,
0451                      UErrorCode& status);
0452 
0453     /**
0454      * Construct a SimpleDateFormat using the given pattern, numbering system override, and locale.
0455      * The locale is used to obtain the symbols used in formatting (e.g., the
0456      * names of the months), but not to provide the pattern.
0457      * <P>
0458      * A numbering system override is a string containing either the name of a known numbering system,
0459      * or a set of field and numbering system pairs that specify which fields are to be formatted with
0460      * the alternate numbering system.  For example, to specify that all numeric fields in the specified
0461      * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
0462      * as "thai".  To specify that just the year portion of the date be formatted using Hebrew numbering,
0463      * use the override string "y=hebrew".  Numbering system overrides can be combined using a semi-colon
0464      * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
0465      * <P>
0466      * [Note:] Not all locales support SimpleDateFormat; for full generality,
0467      * use the factory methods in the DateFormat class.
0468      * @param pattern    the pattern for the format.
0469      * @param override   the numbering system override.
0470      * @param locale     the given locale.
0471      * @param status     Output param set to success/failure code.
0472      * @stable ICU 4.2
0473      */
0474     SimpleDateFormat(const UnicodeString& pattern,
0475                      const UnicodeString& override,
0476                      const Locale& locale,
0477                      UErrorCode& status);
0478 
0479     /**
0480      * Construct a SimpleDateFormat using the given pattern and locale-specific
0481      * symbol data.  The formatter takes ownership of the DateFormatSymbols object;
0482      * the caller is no longer responsible for deleting it.
0483      * @param pattern           the given pattern for the format.
0484      * @param formatDataToAdopt the symbols to be adopted.
0485      * @param status            Output param set to success/faulure code.
0486      * @stable ICU 2.0
0487      */
0488     SimpleDateFormat(const UnicodeString& pattern,
0489                      DateFormatSymbols* formatDataToAdopt,
0490                      UErrorCode& status);
0491 
0492     /**
0493      * Construct a SimpleDateFormat using the given pattern and locale-specific
0494      * symbol data.  The DateFormatSymbols object is NOT adopted; the caller
0495      * remains responsible for deleting it.
0496      * @param pattern           the given pattern for the format.
0497      * @param formatData        the formatting symbols to be use.
0498      * @param status            Output param set to success/faulure code.
0499      * @stable ICU 2.0
0500      */
0501     SimpleDateFormat(const UnicodeString& pattern,
0502                      const DateFormatSymbols& formatData,
0503                      UErrorCode& status);
0504 
0505     /**
0506      * Copy constructor.
0507      * @stable ICU 2.0
0508      */
0509     SimpleDateFormat(const SimpleDateFormat&);
0510 
0511     /**
0512      * Assignment operator.
0513      * @stable ICU 2.0
0514      */
0515     SimpleDateFormat& operator=(const SimpleDateFormat&);
0516 
0517     /**
0518      * Destructor.
0519      * @stable ICU 2.0
0520      */
0521     virtual ~SimpleDateFormat();
0522 
0523     /**
0524      * Clone this Format object polymorphically. The caller owns the result and
0525      * should delete it when done.
0526      * @return    A copy of the object.
0527      * @stable ICU 2.0
0528      */
0529     virtual SimpleDateFormat* clone() const override;
0530 
0531     /**
0532      * Return true if the given Format objects are semantically equal. Objects
0533      * of different subclasses are considered unequal.
0534      * @param other    the object to be compared with.
0535      * @return         true if the given Format objects are semantically equal.
0536      * @stable ICU 2.0
0537      */
0538     virtual bool operator==(const Format& other) const override;
0539 
0540 
0541     using DateFormat::format;
0542 
0543     /**
0544      * Format a date or time, which is the standard millis since 24:00 GMT, Jan
0545      * 1, 1970. Overrides DateFormat pure virtual method.
0546      * <P>
0547      * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
0548      * 1996.07.10 AD at 15:08:56 PDT
0549      *
0550      * @param cal       Calendar set to the date and time to be formatted
0551      *                  into a date/time string.
0552      * @param appendTo  Output parameter to receive result.
0553      *                  Result is appended to existing contents.
0554      * @param pos       The formatting position. On input: an alignment field,
0555      *                  if desired. On output: the offsets of the alignment field.
0556      * @return          Reference to 'appendTo' parameter.
0557      * @stable ICU 2.1
0558      */
0559     virtual UnicodeString& format(  Calendar& cal,
0560                                     UnicodeString& appendTo,
0561                                     FieldPosition& pos) const override;
0562 
0563     /**
0564      * Format a date or time, which is the standard millis since 24:00 GMT, Jan
0565      * 1, 1970. Overrides DateFormat pure virtual method.
0566      * <P>
0567      * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
0568      * 1996.07.10 AD at 15:08:56 PDT
0569      *
0570      * @param cal       Calendar set to the date and time to be formatted
0571      *                  into a date/time string.
0572      * @param appendTo  Output parameter to receive result.
0573      *                  Result is appended to existing contents.
0574      * @param posIter   On return, can be used to iterate over positions
0575      *                  of fields generated by this format call.  Field values
0576      *                  are defined in UDateFormatField.
0577      * @param status    Input/output param set to success/failure code.
0578      * @return          Reference to 'appendTo' parameter.
0579      * @stable ICU 4.4
0580      */
0581     virtual UnicodeString& format(  Calendar& cal,
0582                                     UnicodeString& appendTo,
0583                                     FieldPositionIterator* posIter,
0584                                     UErrorCode& status) const override;
0585 
0586     using DateFormat::parse;
0587 
0588     /**
0589      * Parse a date/time string beginning at the given parse position. For
0590      * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
0591      * that is equivalent to Date(837039928046).
0592      * <P>
0593      * By default, parsing is lenient: If the input is not in the form used by
0594      * this object's format method but can still be parsed as a date, then the
0595      * parse succeeds. Clients may insist on strict adherence to the format by
0596      * calling setLenient(false).
0597      * @see DateFormat::setLenient(boolean)
0598      *
0599      * @param text  The date/time string to be parsed
0600      * @param cal   A Calendar set on input to the date and time to be used for
0601      *              missing values in the date/time string being parsed, and set
0602      *              on output to the parsed date/time. When the calendar type is
0603      *              different from the internal calendar held by this SimpleDateFormat
0604      *              instance, the internal calendar will be cloned to a work
0605      *              calendar set to the same milliseconds and time zone as the
0606      *              cal parameter, field values will be parsed based on the work
0607      *              calendar, then the result (milliseconds and time zone) will
0608      *              be set in this calendar.
0609      * @param pos   On input, the position at which to start parsing; on
0610      *              output, the position at which parsing terminated, or the
0611      *              start position if the parse failed.
0612      * @stable ICU 2.1
0613      */
0614     virtual void parse( const UnicodeString& text,
0615                         Calendar& cal,
0616                         ParsePosition& pos) const override;
0617 
0618 
0619     /**
0620      * Set the start UDate used to interpret two-digit year strings.
0621      * When dates are parsed having 2-digit year strings, they are placed within
0622      * a assumed range of 100 years starting on the two digit start date.  For
0623      * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
0624      * some other year.  SimpleDateFormat chooses a year so that the resultant
0625      * date is on or after the two digit start date and within 100 years of the
0626      * two digit start date.
0627      * <P>
0628      * By default, the two digit start date is set to 80 years before the current
0629      * time at which a SimpleDateFormat object is created.
0630      * @param d      start UDate used to interpret two-digit year strings.
0631      * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
0632      *               an error value if there was a parse error.
0633      * @stable ICU 2.0
0634      */
0635     virtual void set2DigitYearStart(UDate d, UErrorCode& status);
0636 
0637     /**
0638      * Get the start UDate used to interpret two-digit year strings.
0639      * When dates are parsed having 2-digit year strings, they are placed within
0640      * a assumed range of 100 years starting on the two digit start date.  For
0641      * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
0642      * some other year.  SimpleDateFormat chooses a year so that the resultant
0643      * date is on or after the two digit start date and within 100 years of the
0644      * two digit start date.
0645      * <P>
0646      * By default, the two digit start date is set to 80 years before the current
0647      * time at which a SimpleDateFormat object is created.
0648      * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
0649      *               an error value if there was a parse error.
0650      * @stable ICU 2.0
0651      */
0652     UDate get2DigitYearStart(UErrorCode& status) const;
0653 
0654     /**
0655      * Return a pattern string describing this date format.
0656      * @param result Output param to receive the pattern.
0657      * @return       A reference to 'result'.
0658      * @stable ICU 2.0
0659      */
0660     virtual UnicodeString& toPattern(UnicodeString& result) const;
0661 
0662     /**
0663      * Return a localized pattern string describing this date format.
0664      * In most cases, this will return the same thing as toPattern(),
0665      * but a locale can specify characters to use in pattern descriptions
0666      * in place of the ones described in this class's class documentation.
0667      * (Presumably, letters that would be more mnemonic in that locale's
0668      * language.)  This function would produce a pattern using those
0669      * letters.
0670      * <p>
0671      * <b>Note:</b> This implementation depends on DateFormatSymbols::getLocalPatternChars()
0672      * to get localized format pattern characters. ICU does not include
0673      * localized pattern character data, therefore, unless user sets localized
0674      * pattern characters manually, this method returns the same result as
0675      * toPattern().
0676      *
0677      * @param result    Receives the localized pattern.
0678      * @param status    Output param set to success/failure code on
0679      *                  exit. If the pattern is invalid, this will be
0680      *                  set to a failure result.
0681      * @return          A reference to 'result'.
0682      * @stable ICU 2.0
0683      */
0684     virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
0685                                               UErrorCode& status) const;
0686 
0687     /**
0688      * Apply the given unlocalized pattern string to this date format.
0689      * (i.e., after this call, this formatter will format dates according to
0690      * the new pattern)
0691      *
0692      * @param pattern   The pattern to be applied.
0693      * @stable ICU 2.0
0694      */
0695     virtual void applyPattern(const UnicodeString& pattern);
0696 
0697     /**
0698      * Apply the given localized pattern string to this date format.
0699      * (see toLocalizedPattern() for more information on localized patterns.)
0700      *
0701      * @param pattern   The localized pattern to be applied.
0702      * @param status    Output param set to success/failure code on
0703      *                  exit. If the pattern is invalid, this will be
0704      *                  set to a failure result.
0705      * @stable ICU 2.0
0706      */
0707     virtual void applyLocalizedPattern(const UnicodeString& pattern,
0708                                        UErrorCode& status);
0709 
0710     /**
0711      * Gets the date/time formatting symbols (this is an object carrying
0712      * the various strings and other symbols used in formatting: e.g., month
0713      * names and abbreviations, time zone names, AM/PM strings, etc.)
0714      * @return a copy of the date-time formatting data associated
0715      * with this date-time formatter.
0716      * @stable ICU 2.0
0717      */
0718     virtual const DateFormatSymbols* getDateFormatSymbols() const;
0719 
0720     /**
0721      * Set the date/time formatting symbols.  The caller no longer owns the
0722      * DateFormatSymbols object and should not delete it after making this call.
0723      * @param newFormatSymbols the given date-time formatting symbols to copy.
0724      * @stable ICU 2.0
0725      */
0726     virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
0727 
0728     /**
0729      * Set the date/time formatting data.
0730      * @param newFormatSymbols the given date-time formatting symbols to copy.
0731      * @stable ICU 2.0
0732      */
0733     virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
0734 
0735     /**
0736      * Return the class ID for this class. This is useful only for comparing to
0737      * a return value from getDynamicClassID(). For example:
0738      * <pre>
0739      * .   Base* polymorphic_pointer = createPolymorphicObject();
0740      * .   if (polymorphic_pointer->getDynamicClassID() ==
0741      * .       erived::getStaticClassID()) ...
0742      * </pre>
0743      * @return          The class ID for all objects of this class.
0744      * @stable ICU 2.0
0745      */
0746     static UClassID U_EXPORT2 getStaticClassID();
0747 
0748     /**
0749      * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
0750      * method is to implement a simple version of RTTI, since not all C++
0751      * compilers support genuine RTTI. Polymorphic operator==() and clone()
0752      * methods call this method.
0753      *
0754      * @return          The class ID for this object. All objects of a
0755      *                  given class have the same class ID.  Objects of
0756      *                  other classes have different class IDs.
0757      * @stable ICU 2.0
0758      */
0759     virtual UClassID getDynamicClassID() const override;
0760 
0761     /**
0762      * Set the calendar to be used by this date format. Initially, the default
0763      * calendar for the specified or default locale is used.  The caller should
0764      * not delete the Calendar object after it is adopted by this call.
0765      * Adopting a new calendar will change to the default symbols.
0766      *
0767      * @param calendarToAdopt    Calendar object to be adopted.
0768      * @stable ICU 2.0
0769      */
0770     virtual void adoptCalendar(Calendar* calendarToAdopt) override;
0771 
0772     /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
0773     /**
0774      * Sets the TimeZoneFormat to be used by this date/time formatter.
0775      * The caller should not delete the TimeZoneFormat object after
0776      * it is adopted by this call.
0777      * @param timeZoneFormatToAdopt The TimeZoneFormat object to be adopted.
0778      * @internal ICU 49 technology preview
0779      */
0780     virtual void adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt);
0781 
0782     /**
0783      * Sets the TimeZoneFormat to be used by this date/time formatter.
0784      * @param newTimeZoneFormat The TimeZoneFormat object to copy.
0785      * @internal ICU 49 technology preview
0786      */
0787     virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat);
0788 
0789     /**
0790      * Gets the time zone format object associated with this date/time formatter.
0791      * @return the time zone format associated with this date/time formatter.
0792      * @internal ICU 49 technology preview
0793      */
0794     virtual const TimeZoneFormat* getTimeZoneFormat() const;
0795 
0796     /**
0797      * Set a particular UDisplayContext value in the formatter, such as
0798      * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. Note: For getContext, see
0799      * DateFormat.
0800      * @param value The UDisplayContext value to set.
0801      * @param status Input/output status. If at entry this indicates a failure
0802      *               status, the function will do nothing; otherwise this will be
0803      *               updated with any new status from the function.
0804      * @stable ICU 53
0805      */
0806     virtual void setContext(UDisplayContext value, UErrorCode& status) override;
0807 
0808     /**
0809      * Overrides base class method and
0810      * This method clears per field NumberFormat instances
0811      * previously set by {@see adoptNumberFormat(const UnicodeString&, NumberFormat*, UErrorCode)}
0812      * @param formatToAdopt the NumbeferFormat used
0813      * @stable ICU 54
0814      */
0815     void adoptNumberFormat(NumberFormat *formatToAdopt) override;
0816 
0817     /**
0818      * Allow the user to set the NumberFormat for several fields
0819      * It can be a single field like: "y"(year) or "M"(month)
0820      * It can be several field combined together: "yM"(year and month)
0821      * Note:
0822      * 1 symbol field is enough for multiple symbol field (so "y" will override "yy", "yyy")
0823      * If the field is not numeric, then override has no effect (like "MMM" will use abbreviation, not numerical field)
0824      * Per field NumberFormat can also be cleared in {@see DateFormat::setNumberFormat(const NumberFormat& newNumberFormat)}
0825      *
0826      * @param fields  the fields to override(like y)
0827      * @param formatToAdopt the NumbeferFormat used
0828      * @param status  Receives a status code, which will be U_ZERO_ERROR
0829      *                if the operation succeeds.
0830      * @stable ICU 54
0831      */
0832     void adoptNumberFormat(const UnicodeString& fields, NumberFormat *formatToAdopt, UErrorCode &status);
0833 
0834     /**
0835      * Get the numbering system to be used for a particular field.
0836      * @param field The UDateFormatField to get
0837      * @stable ICU 54
0838      */
0839     const NumberFormat * getNumberFormatForField(char16_t field) const;
0840 
0841 #ifndef U_HIDE_INTERNAL_API
0842     /**
0843      * This is for ICU internal use only. Please do not use.
0844      * Check whether the 'field' is smaller than all the fields covered in
0845      * pattern, return true if it is. The sequence of calendar field,
0846      * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
0847      * @param field    the calendar field need to check against
0848      * @return         true if the 'field' is smaller than all the fields
0849      *                 covered in pattern. false otherwise.
0850      * @internal ICU 4.0
0851      */
0852     UBool isFieldUnitIgnored(UCalendarDateFields field) const;
0853 
0854 
0855     /**
0856      * This is for ICU internal use only. Please do not use.
0857      * Check whether the 'field' is smaller than all the fields covered in
0858      * pattern, return true if it is. The sequence of calendar field,
0859      * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
0860      * @param pattern  the pattern to check against
0861      * @param field    the calendar field need to check against
0862      * @return         true if the 'field' is smaller than all the fields
0863      *                 covered in pattern. false otherwise.
0864      * @internal ICU 4.0
0865      */
0866     static UBool isFieldUnitIgnored(const UnicodeString& pattern,
0867                                     UCalendarDateFields field);
0868 
0869     /**
0870      * This is for ICU internal use only. Please do not use.
0871      * Get the locale of this simple date formatter.
0872      * It is used in DateIntervalFormat.
0873      *
0874      * @return   locale in this simple date formatter
0875      * @internal ICU 4.0
0876      */
0877     const Locale& getSmpFmtLocale() const;
0878 #endif  /* U_HIDE_INTERNAL_API */
0879 
0880 private:
0881     friend class DateFormat;
0882     friend class DateIntervalFormat;
0883 
0884     void initializeDefaultCentury();
0885 
0886     void initializeBooleanAttributes();
0887 
0888     SimpleDateFormat() = delete; // default constructor not implemented
0889 
0890     /**
0891      * Used by the DateFormat factory methods to construct a SimpleDateFormat.
0892      * @param timeStyle the time style.
0893      * @param dateStyle the date style.
0894      * @param locale    the given locale.
0895      * @param status    Output param set to success/failure code on
0896      *                  exit.
0897      */
0898     SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
0899 
0900     /**
0901      * Construct a SimpleDateFormat for the given locale.  If no resource data
0902      * is available, create an object of last resort, using hard-coded strings.
0903      * This is an internal method, called by DateFormat.  It should never fail.
0904      * @param locale    the given locale.
0905      * @param status    Output param set to success/failure code on
0906      *                  exit.
0907      */
0908     SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
0909 
0910     /**
0911      * Hook called by format(... FieldPosition& ...) and format(...FieldPositionIterator&...)
0912      */
0913     UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
0914 
0915     /**
0916      * Called by format() to format a single field.
0917      *
0918      * @param appendTo  Output parameter to receive result.
0919      *                  Result is appended to existing contents.
0920      * @param ch        The format character we encountered in the pattern.
0921      * @param count     Number of characters in the current pattern symbol (e.g.,
0922      *                  "yyyy" in the pattern would result in a call to this function
0923      *                  with ch equal to 'y' and count equal to 4)
0924      * @param capitalizationContext Capitalization context for this date format.
0925      * @param fieldNum  Zero-based numbering of current field within the overall format.
0926      * @param handler   Records information about field positions.
0927      * @param cal       Calendar to use
0928      * @param status    Receives a status code, which will be U_ZERO_ERROR if the operation
0929      *                  succeeds.
0930      */
0931     void subFormat(UnicodeString &appendTo,
0932                    char16_t ch,
0933                    int32_t count,
0934                    UDisplayContext capitalizationContext,
0935                    int32_t fieldNum,
0936                    char16_t fieldToOutput,
0937                    FieldPositionHandler& handler,
0938                    Calendar& cal,
0939                    UErrorCode& status) const; // in case of illegal argument
0940 
0941     /**
0942      * Used by subFormat() to format a numeric value.
0943      * Appends to toAppendTo a string representation of "value"
0944      * having a number of digits between "minDigits" and
0945      * "maxDigits".  Uses the DateFormat's NumberFormat.
0946      *
0947      * @param currentNumberFormat
0948      * @param appendTo  Output parameter to receive result.
0949      *                  Formatted number is appended to existing contents.
0950      * @param value     Value to format.
0951      * @param minDigits Minimum number of digits the result should have
0952      * @param maxDigits Maximum number of digits the result should have
0953      */
0954     void zeroPaddingNumber(const NumberFormat *currentNumberFormat,
0955                            UnicodeString &appendTo,
0956                            int32_t value,
0957                            int32_t minDigits,
0958                            int32_t maxDigits) const;
0959 
0960     /**
0961      * Return true if the given format character, occurring count
0962      * times, represents a numeric field.
0963      */
0964     static UBool isNumeric(char16_t formatChar, int32_t count);
0965 
0966     /**
0967      * Returns true if the patternOffset is at the start of a numeric field.
0968      */
0969     static UBool isAtNumericField(const UnicodeString &pattern, int32_t patternOffset);
0970 
0971     /**
0972      * Returns true if the patternOffset is right after a non-numeric field.
0973      */
0974     static UBool isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset);
0975 
0976     /**
0977      * initializes fCalendar from parameters.  Returns fCalendar as a convenience.
0978      * @param adoptZone  Zone to be adopted, or nullptr for TimeZone::createDefault().
0979      * @param locale Locale of the calendar
0980      * @param status Error code
0981      * @return the newly constructed fCalendar
0982      */
0983     Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
0984 
0985     /**
0986      * Called by several of the constructors to load pattern data and formatting symbols
0987      * out of a resource bundle and initialize the locale based on it.
0988      * @param timeStyle     The time style, as passed to DateFormat::createDateInstance().
0989      * @param dateStyle     The date style, as passed to DateFormat::createTimeInstance().
0990      * @param locale        The locale to load the patterns from.
0991      * @param status        Filled in with an error code if loading the data from the
0992      *                      resources fails.
0993      */
0994     void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
0995 
0996     /**
0997      * Called by construct() and the various constructors to set up the SimpleDateFormat's
0998      * Calendar and NumberFormat objects.
0999      * @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();
1292         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
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