Coverage Report

Created: 2026-10-31 06:17

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