1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 * Copyright (C) 1997-2016, International Business Machines Corporation and
5 * others. All Rights Reserved.
6 *******************************************************************************
10 * Modification History:
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
23 *******************************************************************************
29 #include "unicode/utypes.h"
33 * \brief C++ API: Format and parse dates in a language-independent manner.
36 #if !UCONFIG_NO_FORMATTING
38 #include "unicode/datefmt.h"
39 #include "unicode/udisplaycontext.h"
40 #include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */
41 #include "unicode/brkiter.h"
43 #if U_SHOW_CPLUSPLUS_API
46 class DateFormatSymbols
;
49 class FieldPositionHandler
;
51 class SharedNumberFormat
;
52 class SimpleDateFormatMutableNFs
;
56 * SimpleDateFormat is a concrete class for formatting and parsing dates in a
57 * language-independent manner. It allows for formatting (millis -> text),
58 * parsing (text -> millis), and normalization. Formats/Parses a date or time,
59 * which is the standard milliseconds since 24:00 GMT, Jan 1, 1970.
61 * Clients are encouraged to create a date-time formatter using DateFormat::getInstance(),
62 * getDateInstance(), getDateInstance(), or getDateTimeInstance() rather than
63 * explicitly constructing an instance of SimpleDateFormat. This way, the client
64 * is guaranteed to get an appropriate formatting pattern for whatever locale the
65 * program is running in. However, if the client needs something more unusual than
66 * the default patterns in the locales, he can construct a SimpleDateFormat directly
67 * and give it an appropriate pattern (or use one of the factory methods on DateFormat
68 * and modify the pattern after the fact with toPattern() and applyPattern().
70 * <p><strong>Date and Time Patterns:</strong></p>
72 * <p>Date and time formats are specified by <em>date and time pattern</em> strings.
73 * Within date and time pattern strings, all unquoted ASCII letters [A-Za-z] are reserved
74 * as pattern letters representing calendar fields. <code>SimpleDateFormat</code> supports
75 * the date and time formatting algorithm and pattern letters defined by
76 * <a href="http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table">UTS#35
77 * Unicode Locale Data Markup Language (LDML)</a> and further documented for ICU in the
78 * <a href="https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table">ICU
79 * User Guide</a>. The following pattern letters are currently available (note that the actual
80 * values depend on CLDR and may change from the examples shown here):</p>
85 * <th style="text-align: center">Sym.</th>
86 * <th style="text-align: center">No.</th>
88 * <th>Description</th>
91 * <th rowspan="3">era</th>
92 * <td style="text-align: center" rowspan="3">G</td>
93 * <td style="text-align: center">1..3</td>
95 * <td rowspan="3">Era - Replaced with the Era string for the current date. One to three letters for the
96 * abbreviated form, four letters for the long (wide) form, five for the narrow form.</td>
99 * <td style="text-align: center">4</td>
100 * <td>Anno Domini</td>
103 * <td style="text-align: center">5</td>
107 * <th rowspan="6">year</th>
108 * <td style="text-align: center">y</td>
109 * <td style="text-align: center">1..n</td>
111 * <td>Year. Normally the length specifies the padding, but for two letters it also specifies the maximum
112 * length. Example:<div align="center">
114 * <table border="1" cellpadding="2" cellspacing="0">
117 * <th style="text-align: right">y</th>
118 * <th style="text-align: right">yy</th>
119 * <th style="text-align: right">yyy</th>
120 * <th style="text-align: right">yyyy</th>
121 * <th style="text-align: right">yyyyy</th>
125 * <td style="text-align: right">1</td>
126 * <td style="text-align: right">01</td>
127 * <td style="text-align: right">001</td>
128 * <td style="text-align: right">0001</td>
129 * <td style="text-align: right">00001</td>
133 * <td style="text-align: right">12</td>
134 * <td style="text-align: right">12</td>
135 * <td style="text-align: right">012</td>
136 * <td style="text-align: right">0012</td>
137 * <td style="text-align: right">00012</td>
141 * <td style="text-align: right">123</td>
142 * <td style="text-align: right">23</td>
143 * <td style="text-align: right">123</td>
144 * <td style="text-align: right">0123</td>
145 * <td style="text-align: right">00123</td>
149 * <td style="text-align: right">1234</td>
150 * <td style="text-align: right">34</td>
151 * <td style="text-align: right">1234</td>
152 * <td style="text-align: right">1234</td>
153 * <td style="text-align: right">01234</td>
157 * <td style="text-align: right">12345</td>
158 * <td style="text-align: right">45</td>
159 * <td style="text-align: right">12345</td>
160 * <td style="text-align: right">12345</td>
161 * <td style="text-align: right">12345</td>
168 * <td style="text-align: center">Y</td>
169 * <td style="text-align: center">1..n</td>
171 * <td>Year (in "Week of Year" based calendars). Normally the length specifies the padding,
172 * but for two letters it also specifies the maximum length. This year designation is used in ISO
173 * year-week calendar as defined by ISO 8601, but can be used in non-Gregorian based calendar systems
174 * where week date processing is desired. May not always be the same value as calendar year.</td>
177 * <td style="text-align: center">u</td>
178 * <td style="text-align: center">1..n</td>
180 * <td>Extended year. This is a single number designating the year of this calendar system, encompassing
181 * all supra-year fields. For example, for the Julian calendar system, year numbers are positive, with an
182 * era of BCE or CE. An extended year value for the Julian calendar system assigns positive values to CE
183 * years and negative values to BCE years, with 1 BCE being year 0.</td>
186 * <td style="text-align: center" rowspan="3">U</td>
187 * <td style="text-align: center">1..3</td>
188 * <td>甲子</td>
189 * <td rowspan="3">Cyclic year name. Calendars such as the Chinese lunar calendar (and related calendars)
190 * and the Hindu calendars use 60-year cycles of year names. Use one through three letters for the abbreviated
191 * name, four for the full (wide) name, or five for the narrow name (currently the data only provides abbreviated names,
192 * which will be used for all requested name widths). If the calendar does not provide cyclic year name data,
193 * or if the year value to be formatted is out of the range of years for which cyclic name data is provided,
194 * then numeric formatting is used (behaves like 'y').</td>
197 * <td style="text-align: center">4</td>
198 * <td>(currently also 甲子)</td>
201 * <td style="text-align: center">5</td>
202 * <td>(currently also 甲子)</td>
205 * <th rowspan="6">quarter</th>
206 * <td rowspan="3" style="text-align: center">Q</td>
207 * <td style="text-align: center">1..2</td>
209 * <td rowspan="3">Quarter - Use one or two for the numerical quarter, three for the abbreviation, or four for the
210 * full (wide) name (five for the narrow name is not yet supported).</td>
213 * <td style="text-align: center">3</td>
217 * <td style="text-align: center">4</td>
218 * <td>2nd quarter</td>
221 * <td rowspan="3" style="text-align: center">q</td>
222 * <td style="text-align: center">1..2</td>
224 * <td rowspan="3"><b>Stand-Alone</b> Quarter - Use one or two for the numerical quarter, three for the abbreviation,
225 * or four for the full name (five for the narrow name is not yet supported).</td>
228 * <td style="text-align: center">3</td>
232 * <td style="text-align: center">4</td>
233 * <td>2nd quarter</td>
236 * <th rowspan="8">month</th>
237 * <td rowspan="4" style="text-align: center">M</td>
238 * <td style="text-align: center">1..2</td>
240 * <td rowspan="4">Month - Use one or two for the numerical month, three for the abbreviation, four for
241 * the full (wide) name, or five for the narrow name. With two ("MM"), the month number is zero-padded
242 * if necessary (e.g. "08")</td>
245 * <td style="text-align: center">3</td>
249 * <td style="text-align: center">4</td>
253 * <td style="text-align: center">5</td>
257 * <td rowspan="4" style="text-align: center">L</td>
258 * <td style="text-align: center">1..2</td>
260 * <td rowspan="4"><b>Stand-Alone</b> Month - Use one or two for the numerical month, three for the abbreviation,
261 * four for the full (wide) name, or 5 for the narrow name. With two ("LL"), the month number is zero-padded if
262 * necessary (e.g. "08")</td>
265 * <td style="text-align: center">3</td>
269 * <td style="text-align: center">4</td>
273 * <td style="text-align: center">5</td>
277 * <th rowspan="2">week</th>
278 * <td style="text-align: center">w</td>
279 * <td style="text-align: center">1..2</td>
281 * <td>Week of Year. Use "w" to show the minimum number of digits, or "ww" to always show two digits
282 * (zero-padding if necessary, e.g. "08").</td>
285 * <td style="text-align: center">W</td>
286 * <td style="text-align: center">1</td>
288 * <td>Week of Month</td>
291 * <th rowspan="4">day</th>
292 * <td style="text-align: center">d</td>
293 * <td style="text-align: center">1..2</td>
295 * <td>Date - Day of the month. Use "d" to show the minimum number of digits, or "dd" to always show
296 * two digits (zero-padding if necessary, e.g. "08").</td>
299 * <td style="text-align: center">D</td>
300 * <td style="text-align: center">1..3</td>
302 * <td>Day of year</td>
305 * <td style="text-align: center">F</td>
306 * <td style="text-align: center">1</td>
308 * <td>Day of Week in Month. The example is for the 2nd Wed in July</td>
311 * <td style="text-align: center">g</td>
312 * <td style="text-align: center">1..n</td>
314 * <td>Modified Julian day. This is different from the conventional Julian day number in two regards.
315 * First, it demarcates days at local zone midnight, rather than noon GMT. Second, it is a local number;
316 * that is, it depends on the local time zone. It can be thought of as a single number that encompasses
317 * all the date-related fields.</td>
320 * <th rowspan="14">week<br>
322 * <td rowspan="4" style="text-align: center">E</td>
323 * <td style="text-align: center">1..3</td>
325 * <td rowspan="4">Day of week - Use one through three letters for the short day, four for the full (wide) name,
326 * five for the narrow name, or six for the short name.</td>
329 * <td style="text-align: center">4</td>
333 * <td style="text-align: center">5</td>
337 * <td style="text-align: center">6</td>
341 * <td rowspan="5" style="text-align: center">e</td>
342 * <td style="text-align: center">1..2</td>
344 * <td rowspan="5">Local day of week. Same as E except adds a numeric value that will depend on the local
345 * starting day of the week, using one or two letters. For this example, Monday is the first day of the week.</td>
348 * <td style="text-align: center">3</td>
352 * <td style="text-align: center">4</td>
356 * <td style="text-align: center">5</td>
360 * <td style="text-align: center">6</td>
364 * <td rowspan="5" style="text-align: center">c</td>
365 * <td style="text-align: center">1</td>
367 * <td rowspan="5"><b>Stand-Alone</b> local day of week - Use one letter for the local numeric value (same
368 * as 'e'), three for the short day, four for the full (wide) name, five for the narrow name, or six for
369 * the short name.</td>
372 * <td style="text-align: center">3</td>
376 * <td style="text-align: center">4</td>
380 * <td style="text-align: center">5</td>
384 * <td style="text-align: center">6</td>
389 * <td style="text-align: center">a</td>
390 * <td style="text-align: center">1</td>
395 * <th rowspan="4">hour</th>
396 * <td style="text-align: center">h</td>
397 * <td style="text-align: center">1..2</td>
399 * <td>Hour [1-12]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern
400 * generation, it should match the 12-hour-cycle format preferred by the locale (h or K); it should not match
401 * a 24-hour-cycle format (H or k). Use hh for zero padding.</td>
404 * <td style="text-align: center">H</td>
405 * <td style="text-align: center">1..2</td>
407 * <td>Hour [0-23]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern
408 * generation, it should match the 24-hour-cycle format preferred by the locale (H or k); it should not match a
409 * 12-hour-cycle format (h or K). Use HH for zero padding.</td>
412 * <td style="text-align: center">K</td>
413 * <td style="text-align: center">1..2</td>
415 * <td>Hour [0-11]. When used in a skeleton, only matches K or h, see above. Use KK for zero padding.</td>
418 * <td style="text-align: center">k</td>
419 * <td style="text-align: center">1..2</td>
421 * <td>Hour [1-24]. When used in a skeleton, only matches k or H, see above. Use kk for zero padding.</td>
425 * <td style="text-align: center">m</td>
426 * <td style="text-align: center">1..2</td>
428 * <td>Minute. Use "m" to show the minimum number of digits, or "mm" to always show two digits
429 * (zero-padding if necessary, e.g. "08").</td>
432 * <th rowspan="3">second</th>
433 * <td style="text-align: center">s</td>
434 * <td style="text-align: center">1..2</td>
436 * <td>Second. Use "s" to show the minimum number of digits, or "ss" to always show two digits
437 * (zero-padding if necessary, e.g. "08").</td>
440 * <td style="text-align: center">S</td>
441 * <td style="text-align: center">1..n</td>
443 * <td>Fractional Second - truncates (like other time fields) to the count of letters when formatting.
444 * Appends zeros if more than 3 letters specified. Truncates at three significant digits when parsing.
445 * (example shows display using pattern SSSS for seconds value 12.34567)</td>
448 * <td style="text-align: center">A</td>
449 * <td style="text-align: center">1..n</td>
451 * <td>Milliseconds in day. This field behaves <i>exactly</i> like a composite of all time-related fields,
452 * not including the zone fields. As such, it also reflects discontinuities of those fields on DST transition
453 * days. On a day of DST onset, it will jump forward. On a day of DST cessation, it will jump backward. This
454 * reflects the fact that is must be combined with the offset field to obtain a unique local time value.</td>
457 * <th rowspan="23">zone</th>
458 * <td rowspan="2" style="text-align: center">z</td>
459 * <td style="text-align: center">1..3</td>
461 * <td>The <i>short specific non-location format</i>.
462 * Where that is unavailable, falls back to the <i>short localized GMT format</i> ("O").</td>
465 * <td style="text-align: center">4</td>
466 * <td>Pacific Daylight Time</td>
467 * <td>The <i>long specific non-location format</i>.
468 * Where that is unavailable, falls back to the <i>long localized GMT format</i> ("OOOO").</td>
471 * <td rowspan="3" style="text-align: center">Z</td>
472 * <td style="text-align: center">1..3</td>
474 * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
475 * The format is equivalent to RFC 822 zone format (when optional seconds field is absent).
476 * This is equivalent to the "xxxx" specifier.</td>
479 * <td style="text-align: center">4</td>
481 * <td>The <i>long localized GMT format</i>.
482 * This is equivalent to the "OOOO" specifier.</td>
485 * <td style="text-align: center">5</td>
488 * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
489 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.
490 * This is equivalent to the "XXXXX" specifier.</td>
493 * <td rowspan="2" style="text-align: center">O</td>
494 * <td style="text-align: center">1</td>
496 * <td>The <i>short localized GMT format</i>.</td>
499 * <td style="text-align: center">4</td>
501 * <td>The <i>long localized GMT format</i>.</td>
504 * <td rowspan="2" style="text-align: center">v</td>
505 * <td style="text-align: center">1</td>
507 * <td>The <i>short generic non-location format</i>.
508 * Where that is unavailable, falls back to the <i>generic location format</i> ("VVVV"),
509 * then the <i>short localized GMT format</i> as the final fallback.</td>
512 * <td style="text-align: center">4</td>
513 * <td>Pacific Time</td>
514 * <td>The <i>long generic non-location format</i>.
515 * Where that is unavailable, falls back to <i>generic location format</i> ("VVVV").
518 * <td rowspan="4" style="text-align: center">V</td>
519 * <td style="text-align: center">1</td>
521 * <td>The short time zone ID.
522 * Where that is unavailable, the special short time zone ID <i>unk</i> (Unknown Zone) is used.<br>
523 * <i><b>Note</b>: This specifier was originally used for a variant of the short specific non-location format,
524 * but it was deprecated in the later version of the LDML specification. In CLDR 23/ICU 51, the definition of
525 * the specifier was changed to designate a short time zone ID.</i></td>
528 * <td style="text-align: center">2</td>
529 * <td>America/Los_Angeles</td>
530 * <td>The long time zone ID.</td>
533 * <td style="text-align: center">3</td>
534 * <td>Los Angeles</td>
535 * <td>The exemplar city (location) for the time zone.
536 * Where that is unavailable, the localized exemplar city name for the special zone <i>Etc/Unknown</i> is used
537 * as the fallback (for example, "Unknown City"). </td>
540 * <td style="text-align: center">4</td>
541 * <td>Los Angeles Time</td>
542 * <td>The <i>generic location format</i>.
543 * Where that is unavailable, falls back to the <i>long localized GMT format</i> ("OOOO";
544 * Note: Fallback is only necessary with a GMT-style Time Zone ID, like Etc/GMT-830.)<br>
545 * This is especially useful when presenting possible timezone choices for user selection,
546 * since the naming is more uniform than the "v" format.</td>
549 * <td rowspan="5" style="text-align: center">X</td>
550 * <td style="text-align: center">1</td>
554 * <td>The <i>ISO8601 basic format</i> with hours field and optional minutes field.
555 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
558 * <td style="text-align: center">2</td>
561 * <td>The <i>ISO8601 basic format</i> with hours and minutes fields.
562 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
565 * <td style="text-align: center">3</td>
568 * <td>The <i>ISO8601 extended format</i> with hours and minutes fields.
569 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
572 * <td style="text-align: center">4</td>
576 * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
577 * (Note: The seconds field is not supported by the ISO8601 specification.)
578 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
581 * <td style="text-align: center">5</td>
585 * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
586 * (Note: The seconds field is not supported by the ISO8601 specification.)
587 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
590 * <td rowspan="5" style="text-align: center">x</td>
591 * <td style="text-align: center">1</td>
594 * <td>The <i>ISO8601 basic format</i> with hours field and optional minutes field.</td>
597 * <td style="text-align: center">2</td>
599 * <td>The <i>ISO8601 basic format</i> with hours and minutes fields.</td>
602 * <td style="text-align: center">3</td>
604 * <td>The <i>ISO8601 extended format</i> with hours and minutes fields.</td>
607 * <td style="text-align: center">4</td>
610 * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
611 * (Note: The seconds field is not supported by the ISO8601 specification.)</td>
614 * <td style="text-align: center">5</td>
617 * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
618 * (Note: The seconds field is not supported by the ISO8601 specification.)</td>
623 * Any characters in the pattern that are not in the ranges of ['a'..'z'] and
624 * ['A'..'Z'] will be treated as quoted text. For instance, characters
625 * like ':', '.', ' ', '#' and '@' will appear in the resulting time text
626 * even they are not embraced within single quotes.
628 * A pattern containing any invalid pattern letter will result in a failing
629 * UErrorCode result during formatting or parsing.
631 * Examples using the US locale:
634 * Format Pattern Result
635 * -------------- -------
636 * "yyyy.MM.dd G 'at' HH:mm:ss vvvv" ->> 1996.07.10 AD at 15:08:56 Pacific Time
637 * "EEE, MMM d, ''yy" ->> Wed, July 10, '96
638 * "h:mm a" ->> 12:08 PM
639 * "hh 'o''clock' a, zzzz" ->> 12 o'clock PM, Pacific Daylight Time
640 * "K:mm a, vvv" ->> 0:00 PM, PT
641 * "yyyyy.MMMMM.dd GGG hh:mm aaa" ->> 1996.July.10 AD 12:08 PM
647 * UErrorCode success = U_ZERO_ERROR;
648 * SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "PST");
649 * pdt->setStartRule( Calendar::APRIL, 1, Calendar::SUNDAY, 2*60*60*1000);
650 * pdt->setEndRule( Calendar::OCTOBER, -1, Calendar::SUNDAY, 2*60*60*1000);
652 * // Format the current time.
653 * SimpleDateFormat* formatter
654 * = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz", success );
655 * GregorianCalendar cal(success);
656 * UDate currentTime_1 = cal.getTime(success);
657 * FieldPosition fp(FieldPosition::DONT_CARE);
658 * UnicodeString dateString;
659 * formatter->format( currentTime_1, dateString, fp );
660 * cout << "result: " << dateString << endl;
662 * // Parse the previous string back into a Date.
663 * ParsePosition pp(0);
664 * UDate currentTime_2 = formatter->parse(dateString, pp );
667 * In the above example, the time value "currentTime_2" obtained from parsing
668 * will be equal to currentTime_1. However, they may not be equal if the am/pm
669 * marker 'a' is left out from the format pattern while the "hour in am/pm"
670 * pattern symbol is used. This information loss can happen when formatting the
674 * When parsing a date string using the abbreviated year pattern ("y" or "yy"),
675 * SimpleDateFormat must interpret the abbreviated year
676 * relative to some century. It does this by adjusting dates to be
677 * within 80 years before and 20 years after the time the SimpleDateFormat
678 * instance is created. For example, using a pattern of "MM/dd/yy" and a
679 * SimpleDateFormat instance created on Jan 1, 1997, the string
680 * "01/11/12" would be interpreted as Jan 11, 2012 while the string "05/04/64"
681 * would be interpreted as May 4, 1964.
682 * During parsing, only strings consisting of exactly two digits, as defined by
683 * <code>Unicode::isDigit()</code>, will be parsed into the default century.
684 * Any other numeric string, such as a one digit string, a three or more digit
685 * string, or a two digit string that isn't all digits (for example, "-1"), is
686 * interpreted literally. So "01/02/3" or "01/02/003" are parsed (for the
687 * Gregorian calendar), using the same pattern, as Jan 2, 3 AD. Likewise (but
688 * only in lenient parse mode, the default) "01/02/-3" is parsed as Jan 2, 4 BC.
691 * If the year pattern has more than two 'y' characters, the year is
692 * interpreted literally, regardless of the number of digits. So using the
693 * pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
696 * When numeric fields abut one another directly, with no intervening delimiter
697 * characters, they constitute a run of abutting numeric fields. Such runs are
698 * parsed specially. For example, the format "HHmmss" parses the input text
699 * "123456" to 12:34:56, parses the input text "12345" to 1:23:45, and fails to
700 * parse "1234". In other words, the leftmost field of the run is flexible,
701 * while the others keep a fixed width. If the parse fails anywhere in the run,
702 * then the leftmost field is shortened by one character, and the entire run is
703 * parsed again. This is repeated until either the parse succeeds or the
704 * leftmost field is one character in length. If the parse still fails at that
705 * point, the parse of the run fails.
708 * For time zones that have no names, SimpleDateFormat uses strings GMT+hours:minutes or
711 * The calendar defines what is the first day of the week, the first week of the
712 * year, whether hours are zero based or not (0 vs 12 or 24), and the timezone.
713 * There is one common number format to handle all the numbers; the digit count
714 * is handled programmatically according to the pattern.
716 * <p><em>User subclasses are not supported.</em> While clients may write
717 * subclasses, such code will not necessarily work and will not be
718 * guaranteed to work stably from release to release.
720 class U_I18N_API SimpleDateFormat
: public DateFormat
{
723 * Construct a SimpleDateFormat using the default pattern for the default
726 * [Note:] Not all locales support SimpleDateFormat; for full generality,
727 * use the factory methods in the DateFormat class.
728 * @param status Output param set to success/failure code.
731 SimpleDateFormat(UErrorCode
& status
);
734 * Construct a SimpleDateFormat using the given pattern and the default locale.
735 * The locale is used to obtain the symbols used in formatting (e.g., the
736 * names of the months), but not to provide the pattern.
738 * [Note:] Not all locales support SimpleDateFormat; for full generality,
739 * use the factory methods in the DateFormat class.
740 * @param pattern the pattern for the format.
741 * @param status Output param set to success/failure code.
744 SimpleDateFormat(const UnicodeString
& pattern
,
748 * Construct a SimpleDateFormat using the given pattern, numbering system override, and the default locale.
749 * The locale is used to obtain the symbols used in formatting (e.g., the
750 * names of the months), but not to provide the pattern.
752 * A numbering system override is a string containing either the name of a known numbering system,
753 * or a set of field and numbering system pairs that specify which fields are to be formattied with
754 * the alternate numbering system. For example, to specify that all numeric fields in the specified
755 * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
756 * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering,
757 * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon
758 * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
761 * [Note:] Not all locales support SimpleDateFormat; for full generality,
762 * use the factory methods in the DateFormat class.
763 * @param pattern the pattern for the format.
764 * @param override the override string.
765 * @param status Output param set to success/failure code.
768 SimpleDateFormat(const UnicodeString
& pattern
,
769 const UnicodeString
& override
,
773 * Construct a SimpleDateFormat using the given pattern and locale.
774 * The locale is used to obtain the symbols used in formatting (e.g., the
775 * names of the months), but not to provide the pattern.
777 * [Note:] Not all locales support SimpleDateFormat; for full generality,
778 * use the factory methods in the DateFormat class.
779 * @param pattern the pattern for the format.
780 * @param locale the given locale.
781 * @param status Output param set to success/failure code.
784 SimpleDateFormat(const UnicodeString
& pattern
,
785 const Locale
& locale
,
789 * Construct a SimpleDateFormat using the given pattern, numbering system override, and locale.
790 * The locale is used to obtain the symbols used in formatting (e.g., the
791 * names of the months), but not to provide the pattern.
793 * A numbering system override is a string containing either the name of a known numbering system,
794 * or a set of field and numbering system pairs that specify which fields are to be formattied with
795 * the alternate numbering system. For example, to specify that all numeric fields in the specified
796 * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
797 * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering,
798 * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon
799 * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
801 * [Note:] Not all locales support SimpleDateFormat; for full generality,
802 * use the factory methods in the DateFormat class.
803 * @param pattern the pattern for the format.
804 * @param override the numbering system override.
805 * @param locale the given locale.
806 * @param status Output param set to success/failure code.
809 SimpleDateFormat(const UnicodeString
& pattern
,
810 const UnicodeString
& override
,
811 const Locale
& locale
,
815 * Construct a SimpleDateFormat using the given pattern and locale-specific
816 * symbol data. The formatter takes ownership of the DateFormatSymbols object;
817 * the caller is no longer responsible for deleting it.
818 * @param pattern the given pattern for the format.
819 * @param formatDataToAdopt the symbols to be adopted.
820 * @param status Output param set to success/faulure code.
823 SimpleDateFormat(const UnicodeString
& pattern
,
824 DateFormatSymbols
* formatDataToAdopt
,
828 * Construct a SimpleDateFormat using the given pattern and locale-specific
829 * symbol data. The DateFormatSymbols object is NOT adopted; the caller
830 * remains responsible for deleting it.
831 * @param pattern the given pattern for the format.
832 * @param formatData the formatting symbols to be use.
833 * @param status Output param set to success/faulure code.
836 SimpleDateFormat(const UnicodeString
& pattern
,
837 const DateFormatSymbols
& formatData
,
844 SimpleDateFormat(const SimpleDateFormat
&);
847 * Assignment operator.
850 SimpleDateFormat
& operator=(const SimpleDateFormat
&);
856 virtual ~SimpleDateFormat();
859 * Clone this Format object polymorphically. The caller owns the result and
860 * should delete it when done.
861 * @return A copy of the object.
864 virtual Format
* clone(void) const;
867 * Return true if the given Format objects are semantically equal. Objects
868 * of different subclasses are considered unequal.
869 * @param other the object to be compared with.
870 * @return true if the given Format objects are semantically equal.
873 virtual UBool
operator==(const Format
& other
) const;
876 using DateFormat::format
;
879 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
880 * 1, 1970. Overrides DateFormat pure virtual method.
882 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
883 * 1996.07.10 AD at 15:08:56 PDT
885 * @param cal Calendar set to the date and time to be formatted
886 * into a date/time string.
887 * @param appendTo Output parameter to receive result.
888 * Result is appended to existing contents.
889 * @param pos The formatting position. On input: an alignment field,
890 * if desired. On output: the offsets of the alignment field.
891 * @return Reference to 'appendTo' parameter.
894 virtual UnicodeString
& format( Calendar
& cal
,
895 UnicodeString
& appendTo
,
896 FieldPosition
& pos
) const;
899 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
900 * 1, 1970. Overrides DateFormat pure virtual method.
902 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
903 * 1996.07.10 AD at 15:08:56 PDT
905 * @param cal Calendar set to the date and time to be formatted
906 * into a date/time string.
907 * @param appendTo Output parameter to receive result.
908 * Result is appended to existing contents.
909 * @param posIter On return, can be used to iterate over positions
910 * of fields generated by this format call. Field values
911 * are defined in UDateFormatField.
912 * @param status Input/output param set to success/failure code.
913 * @return Reference to 'appendTo' parameter.
916 virtual UnicodeString
& format( Calendar
& cal
,
917 UnicodeString
& appendTo
,
918 FieldPositionIterator
* posIter
,
919 UErrorCode
& status
) const;
921 using DateFormat::parse
;
924 * Parse a date/time string beginning at the given parse position. For
925 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
926 * that is equivalent to Date(837039928046).
928 * By default, parsing is lenient: If the input is not in the form used by
929 * this object's format method but can still be parsed as a date, then the
930 * parse succeeds. Clients may insist on strict adherence to the format by
931 * calling setLenient(false).
932 * @see DateFormat::setLenient(boolean)
934 * @param text The date/time string to be parsed
935 * @param cal A Calendar set on input to the date and time to be used for
936 * missing values in the date/time string being parsed, and set
937 * on output to the parsed date/time. When the calendar type is
938 * different from the internal calendar held by this SimpleDateFormat
939 * instance, the internal calendar will be cloned to a work
940 * calendar set to the same milliseconds and time zone as the
941 * cal parameter, field values will be parsed based on the work
942 * calendar, then the result (milliseconds and time zone) will
943 * be set in this calendar.
944 * @param pos On input, the position at which to start parsing; on
945 * output, the position at which parsing terminated, or the
946 * start position if the parse failed.
949 virtual void parse( const UnicodeString
& text
,
951 ParsePosition
& pos
) const;
955 * Set the start UDate used to interpret two-digit year strings.
956 * When dates are parsed having 2-digit year strings, they are placed within
957 * a assumed range of 100 years starting on the two digit start date. For
958 * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
959 * some other year. SimpleDateFormat chooses a year so that the resultant
960 * date is on or after the two digit start date and within 100 years of the
961 * two digit start date.
963 * By default, the two digit start date is set to 80 years before the current
964 * time at which a SimpleDateFormat object is created.
965 * @param d start UDate used to interpret two-digit year strings.
966 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
967 * an error value if there was a parse error.
970 virtual void set2DigitYearStart(UDate d
, UErrorCode
& status
);
973 * Get the start UDate used to interpret two-digit year strings.
974 * When dates are parsed having 2-digit year strings, they are placed within
975 * a assumed range of 100 years starting on the two digit start date. For
976 * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
977 * some other year. SimpleDateFormat chooses a year so that the resultant
978 * date is on or after the two digit start date and within 100 years of the
979 * two digit start date.
981 * By default, the two digit start date is set to 80 years before the current
982 * time at which a SimpleDateFormat object is created.
983 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
984 * an error value if there was a parse error.
987 UDate
get2DigitYearStart(UErrorCode
& status
) const;
990 * Return a pattern string describing this date format.
991 * @param result Output param to receive the pattern.
992 * @return A reference to 'result'.
995 virtual UnicodeString
& toPattern(UnicodeString
& result
) const;
998 * Return a localized pattern string describing this date format.
999 * In most cases, this will return the same thing as toPattern(),
1000 * but a locale can specify characters to use in pattern descriptions
1001 * in place of the ones described in this class's class documentation.
1002 * (Presumably, letters that would be more mnemonic in that locale's
1003 * language.) This function would produce a pattern using those
1006 * <b>Note:</b> This implementation depends on DateFormatSymbols::getLocalPatternChars()
1007 * to get localized format pattern characters. ICU does not include
1008 * localized pattern character data, therefore, unless user sets localized
1009 * pattern characters manually, this method returns the same result as
1012 * @param result Receives the localized pattern.
1013 * @param status Output param set to success/failure code on
1014 * exit. If the pattern is invalid, this will be
1015 * set to a failure result.
1016 * @return A reference to 'result'.
1019 virtual UnicodeString
& toLocalizedPattern(UnicodeString
& result
,
1020 UErrorCode
& status
) const;
1023 * Apply the given unlocalized pattern string to this date format.
1024 * (i.e., after this call, this formatter will format dates according to
1027 * @param pattern The pattern to be applied.
1030 virtual void applyPattern(const UnicodeString
& pattern
);
1033 * Apply the given localized pattern string to this date format.
1034 * (see toLocalizedPattern() for more information on localized patterns.)
1036 * @param pattern The localized pattern to be applied.
1037 * @param status Output param set to success/failure code on
1038 * exit. If the pattern is invalid, this will be
1039 * set to a failure result.
1042 virtual void applyLocalizedPattern(const UnicodeString
& pattern
,
1043 UErrorCode
& status
);
1046 * Gets the date/time formatting symbols (this is an object carrying
1047 * the various strings and other symbols used in formatting: e.g., month
1048 * names and abbreviations, time zone names, AM/PM strings, etc.)
1049 * @return a copy of the date-time formatting data associated
1050 * with this date-time formatter.
1053 virtual const DateFormatSymbols
* getDateFormatSymbols(void) const;
1056 * Set the date/time formatting symbols. The caller no longer owns the
1057 * DateFormatSymbols object and should not delete it after making this call.
1058 * @param newFormatSymbols the given date-time formatting symbols to copy.
1061 virtual void adoptDateFormatSymbols(DateFormatSymbols
* newFormatSymbols
);
1064 * Set the date/time formatting data.
1065 * @param newFormatSymbols the given date-time formatting symbols to copy.
1068 virtual void setDateFormatSymbols(const DateFormatSymbols
& newFormatSymbols
);
1071 * Return the class ID for this class. This is useful only for comparing to
1072 * a return value from getDynamicClassID(). For example:
1074 * . Base* polymorphic_pointer = createPolymorphicObject();
1075 * . if (polymorphic_pointer->getDynamicClassID() ==
1076 * . erived::getStaticClassID()) ...
1078 * @return The class ID for all objects of this class.
1081 static UClassID U_EXPORT2
getStaticClassID(void);
1084 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
1085 * method is to implement a simple version of RTTI, since not all C++
1086 * compilers support genuine RTTI. Polymorphic operator==() and clone()
1087 * methods call this method.
1089 * @return The class ID for this object. All objects of a
1090 * given class have the same class ID. Objects of
1091 * other classes have different class IDs.
1094 virtual UClassID
getDynamicClassID(void) const;
1097 * Set the calendar to be used by this date format. Initially, the default
1098 * calendar for the specified or default locale is used. The caller should
1099 * not delete the Calendar object after it is adopted by this call.
1100 * Adopting a new calendar will change to the default symbols.
1102 * @param calendarToAdopt Calendar object to be adopted.
1105 virtual void adoptCalendar(Calendar
* calendarToAdopt
);
1107 /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
1109 * Sets the TimeZoneFormat to be used by this date/time formatter.
1110 * The caller should not delete the TimeZoneFormat object after
1111 * it is adopted by this call.
1112 * @param timeZoneFormatToAdopt The TimeZoneFormat object to be adopted.
1113 * @internal ICU 49 technology preview
1115 virtual void adoptTimeZoneFormat(TimeZoneFormat
* timeZoneFormatToAdopt
);
1118 * Sets the TimeZoneFormat to be used by this date/time formatter.
1119 * @param newTimeZoneFormat The TimeZoneFormat object to copy.
1120 * @internal ICU 49 technology preview
1122 virtual void setTimeZoneFormat(const TimeZoneFormat
& newTimeZoneFormat
);
1125 * Gets the time zone format object associated with this date/time formatter.
1126 * @return the time zone format associated with this date/time formatter.
1127 * @internal ICU 49 technology preview
1129 virtual const TimeZoneFormat
* getTimeZoneFormat(void) const;
1132 * Set a particular UDisplayContext value in the formatter, such as
1133 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. Note: For getContext, see
1135 * @param value The UDisplayContext value to set.
1136 * @param status Input/output status. If at entry this indicates a failure
1137 * status, the function will do nothing; otherwise this will be
1138 * updated with any new status from the function.
1141 virtual void setContext(UDisplayContext value
, UErrorCode
& status
);
1144 * Overrides base class method and
1145 * This method clears per field NumberFormat instances
1146 * previously set by {@see adoptNumberFormat(const UnicodeString&, NumberFormat*, UErrorCode)}
1147 * @param adoptNF the NumbeferFormat used
1150 void adoptNumberFormat(NumberFormat
*formatToAdopt
);
1153 * Allow the user to set the NumberFormat for several fields
1154 * It can be a single field like: "y"(year) or "M"(month)
1155 * It can be several field combined together: "yM"(year and month)
1157 * 1 symbol field is enough for multiple symbol field (so "y" will override "yy", "yyy")
1158 * If the field is not numeric, then override has no effect (like "MMM" will use abbreviation, not numerical field)
1159 * Per field NumberFormat can also be cleared in {@see DateFormat::setNumberFormat(const NumberFormat& newNumberFormat)}
1161 * @param fields the fields to override(like y)
1162 * @param adoptNF the NumbeferFormat used
1163 * @param status Receives a status code, which will be U_ZERO_ERROR
1164 * if the operation succeeds.
1167 void adoptNumberFormat(const UnicodeString
& fields
, NumberFormat
*formatToAdopt
, UErrorCode
&status
);
1170 * Get the numbering system to be used for a particular field.
1171 * @param field The UDateFormatField to get
1174 const NumberFormat
* getNumberFormatForField(char16_t field
) const;
1176 #ifndef U_HIDE_INTERNAL_API
1178 * This is for ICU internal use only. Please do not use.
1179 * Check whether the 'field' is smaller than all the fields covered in
1180 * pattern, return TRUE if it is. The sequence of calendar field,
1181 * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
1182 * @param field the calendar field need to check against
1183 * @return TRUE if the 'field' is smaller than all the fields
1184 * covered in pattern. FALSE otherwise.
1187 UBool
isFieldUnitIgnored(UCalendarDateFields field
) const;
1191 * This is for ICU internal use only. Please do not use.
1192 * Check whether the 'field' is smaller than all the fields covered in
1193 * pattern, return TRUE if it is. The sequence of calendar field,
1194 * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
1195 * @param pattern the pattern to check against
1196 * @param field the calendar field need to check against
1197 * @return TRUE if the 'field' is smaller than all the fields
1198 * covered in pattern. FALSE otherwise.
1201 static UBool
isFieldUnitIgnored(const UnicodeString
& pattern
,
1202 UCalendarDateFields field
);
1205 * This is for ICU internal use only. Please do not use.
1206 * Get the locale of this simple date formatter.
1207 * It is used in DateIntervalFormat.
1209 * @return locale in this simple date formatter
1212 const Locale
& getSmpFmtLocale(void) const;
1216 * This is for ICU internal use only. Please do not use.
1217 * Get the capitalization break iterator of this simple date formatter.
1218 * Should be cloned before using it.
1219 * It is used in udat.
1221 * @return capitalization break iterator
1224 BreakIterator
* getCapitalizationBrkIter(void) const;
1225 #endif /* U_HIDE_INTERNAL_API */
1228 friend class DateFormat
;
1230 void initializeDefaultCentury(void);
1232 void initializeBooleanAttributes(void);
1234 SimpleDateFormat(); // default constructor not implemented
1237 * Used by the DateFormat factory methods to construct a SimpleDateFormat.
1238 * @param timeStyle the time style.
1239 * @param dateStyle the date style.
1240 * @param locale the given locale.
1241 * @param status Output param set to success/failure code on
1244 SimpleDateFormat(EStyle timeStyle
, EStyle dateStyle
, const Locale
& locale
, UErrorCode
& status
);
1247 * Construct a SimpleDateFormat for the given locale. If no resource data
1248 * is available, create an object of last resort, using hard-coded strings.
1249 * This is an internal method, called by DateFormat. It should never fail.
1250 * @param locale the given locale.
1251 * @param status Output param set to success/failure code on
1254 SimpleDateFormat(const Locale
& locale
, UErrorCode
& status
); // Use default pattern
1257 * Hook called by format(... FieldPosition& ...) and format(...FieldPositionIterator&...)
1259 UnicodeString
& _format(Calendar
& cal
, UnicodeString
& appendTo
, FieldPositionHandler
& handler
, UErrorCode
& status
) const;
1262 * Called by format() to format a single field.
1264 * @param appendTo Output parameter to receive result.
1265 * Result is appended to existing contents.
1266 * @param ch The format character we encountered in the pattern.
1267 * @param count Number of characters in the current pattern symbol (e.g.,
1268 * "yyyy" in the pattern would result in a call to this function
1269 * with ch equal to 'y' and count equal to 4)
1270 * @param capitalizationContext Capitalization context for this date format.
1271 * @param fieldNum Zero-based numbering of current field within the overall format.
1272 * @param handler Records information about field positions.
1273 * @param cal Calendar to use
1274 * @param status Receives a status code, which will be U_ZERO_ERROR if the operation
1277 void subFormat(UnicodeString
&appendTo
,
1280 UDisplayContext capitalizationContext
,
1282 FieldPositionHandler
& handler
,
1284 SimpleDateFormatMutableNFs
&mutableNFs
,
1285 UErrorCode
& status
) const; // in case of illegal argument
1288 * Used by subFormat() to format a numeric value.
1289 * Appends to toAppendTo a string representation of "value"
1290 * having a number of digits between "minDigits" and
1291 * "maxDigits". Uses the DateFormat's NumberFormat.
1293 * @param currentNumberFormat
1294 * @param appendTo Output parameter to receive result.
1295 * Formatted number is appended to existing contents.
1296 * @param value Value to format.
1297 * @param minDigits Minimum number of digits the result should have
1298 * @param maxDigits Maximum number of digits the result should have
1300 void zeroPaddingNumber(NumberFormat
*currentNumberFormat
,
1301 UnicodeString
&appendTo
,
1304 int32_t maxDigits
) const;
1307 * Return true if the given format character, occuring count
1308 * times, represents a numeric field.
1310 static UBool
isNumeric(char16_t formatChar
, int32_t count
);
1313 * Returns TRUE if the patternOffset is at the start of a numeric field.
1315 static UBool
isAtNumericField(const UnicodeString
&pattern
, int32_t patternOffset
);
1318 * Returns TRUE if the patternOffset is right after a non-numeric field.
1320 static UBool
isAfterNonNumericField(const UnicodeString
&pattern
, int32_t patternOffset
);
1323 * initializes fCalendar from parameters. Returns fCalendar as a convenience.
1324 * @param adoptZone Zone to be adopted, or NULL for TimeZone::createDefault().
1325 * @param locale Locale of the calendar
1326 * @param status Error code
1327 * @return the newly constructed fCalendar
1329 Calendar
*initializeCalendar(TimeZone
* adoptZone
, const Locale
& locale
, UErrorCode
& status
);
1332 * Called by several of the constructors to load pattern data and formatting symbols
1333 * out of a resource bundle and initialize the locale based on it.
1334 * @param timeStyle The time style, as passed to DateFormat::createDateInstance().
1335 * @param dateStyle The date style, as passed to DateFormat::createTimeInstance().
1336 * @param locale The locale to load the patterns from.
1337 * @param status Filled in with an error code if loading the data from the
1340 void construct(EStyle timeStyle
, EStyle dateStyle
, const Locale
& locale
, UErrorCode
& status
);
1343 * Called by construct() and the various constructors to set up the SimpleDateFormat's
1344 * Calendar and NumberFormat objects.
1345 * @param locale The locale for which we want a Calendar and a NumberFormat.
1346 * @param status Filled in with an error code if creating either subobject fails.
1348 void initialize(const Locale
& locale
, UErrorCode
& status
);
1351 * Private code-size reduction function used by subParse.
1352 * @param text the time text being parsed.
1353 * @param start where to start parsing.
1354 * @param field the date field being parsed.
1355 * @param stringArray the string array to parsed.
1356 * @param stringArrayCount the size of the array.
1357 * @param monthPattern pointer to leap month pattern, or NULL if none.
1358 * @param cal a Calendar set to the date and time to be formatted
1359 * into a date/time string.
1360 * @return the new start position if matching succeeded; a negative number
1361 * indicating matching failure, otherwise.
1363 int32_t matchString(const UnicodeString
& text
, int32_t start
, UCalendarDateFields field
,
1364 const UnicodeString
* stringArray
, int32_t stringArrayCount
,
1365 const UnicodeString
* monthPattern
, Calendar
& cal
) const;
1368 * Private code-size reduction function used by subParse.
1369 * @param text the time text being parsed.
1370 * @param start where to start parsing.
1371 * @param field the date field being parsed.
1372 * @param stringArray the string array to parsed.
1373 * @param stringArrayCount the size of the array.
1374 * @param cal a Calendar set to the date and time to be formatted
1375 * into a date/time string.
1376 * @return the new start position if matching succeeded; a negative number
1377 * indicating matching failure, otherwise.
1379 int32_t matchQuarterString(const UnicodeString
& text
, int32_t start
, UCalendarDateFields field
,
1380 const UnicodeString
* stringArray
, int32_t stringArrayCount
, Calendar
& cal
) const;
1383 * Used by subParse() to match localized day period strings.
1385 int32_t matchDayPeriodStrings(const UnicodeString
& text
, int32_t start
,
1386 const UnicodeString
* stringArray
, int32_t stringArrayCount
,
1387 int32_t &dayPeriod
) const;
1390 * Private function used by subParse to match literal pattern text.
1392 * @param pattern the pattern string
1393 * @param patternOffset the starting offset into the pattern text. On
1394 * outupt will be set the offset of the first non-literal character in the pattern
1395 * @param text the text being parsed
1396 * @param textOffset the starting offset into the text. On output
1397 * will be set to the offset of the character after the match
1398 * @param whitespaceLenient <code>TRUE</code> if whitespace parse is lenient, <code>FALSE</code> otherwise.
1399 * @param partialMatchLenient <code>TRUE</code> if partial match parse is lenient, <code>FALSE</code> otherwise.
1400 * @param oldLeniency <code>TRUE</code> if old leniency control is lenient, <code>FALSE</code> otherwise.
1402 * @return <code>TRUE</code> if the literal text could be matched, <code>FALSE</code> otherwise.
1404 static UBool
matchLiterals(const UnicodeString
&pattern
, int32_t &patternOffset
,
1405 const UnicodeString
&text
, int32_t &textOffset
,
1406 UBool whitespaceLenient
, UBool partialMatchLenient
, UBool oldLeniency
);
1409 * Private member function that converts the parsed date strings into
1410 * timeFields. Returns -start (for ParsePosition) if failed.
1411 * @param text the time text to be parsed.
1412 * @param start where to start parsing.
1413 * @param ch the pattern character for the date field text to be parsed.
1414 * @param count the count of a pattern character.
1415 * @param obeyCount if true then the count is strictly obeyed.
1416 * @param allowNegative
1417 * @param ambiguousYear If true then the two-digit year == the default start year.
1418 * @param saveHebrewMonth Used to hang onto month until year is known.
1419 * @param cal a Calendar set to the date and time to be formatted
1420 * into a date/time string.
1422 * @param numericLeapMonthFormatter If non-null, used to parse numeric leap months.
1423 * @param tzTimeType the type of parsed time zone - standard, daylight or unknown (output).
1424 * This parameter can be NULL if caller does not need the information.
1425 * @return the new start position if matching succeeded; a negative number
1426 * indicating matching failure, otherwise.
1428 int32_t subParse(const UnicodeString
& text
, int32_t& start
, char16_t ch
, int32_t count
,
1429 UBool obeyCount
, UBool allowNegative
, UBool ambiguousYear
[], int32_t& saveHebrewMonth
, Calendar
& cal
,
1430 int32_t patLoc
, MessageFormat
* numericLeapMonthFormatter
, UTimeZoneFormatTimeType
*tzTimeType
, SimpleDateFormatMutableNFs
&mutableNFs
,
1431 int32_t *dayPeriod
=NULL
) const;
1433 void parseInt(const UnicodeString
& text
,
1434 Formattable
& number
,
1436 UBool allowNegative
,
1437 NumberFormat
*fmt
) const;
1439 void parseInt(const UnicodeString
& text
,
1440 Formattable
& number
,
1443 UBool allowNegative
,
1444 NumberFormat
*fmt
) const;
1446 int32_t checkIntSuffix(const UnicodeString
& text
, int32_t start
,
1447 int32_t patLoc
, UBool isNegative
) const;
1450 * Counts number of digit code points in the specified text.
1452 * @param text input text
1453 * @param start start index, inclusive
1454 * @param end end index, exclusive
1455 * @return number of digits found in the text in the specified range.
1457 int32_t countDigits(const UnicodeString
& text
, int32_t start
, int32_t end
) const;
1460 * Translate a pattern, mapping each character in the from string to the
1461 * corresponding character in the to string. Return an error if the original
1462 * pattern contains an unmapped character, or if a quote is unmatched.
1463 * Quoted (single quotes only) material is not translated.
1464 * @param originalPattern the original pattern.
1465 * @param translatedPattern Output param to receive the translited pattern.
1466 * @param from the characters to be translited from.
1467 * @param to the characters to be translited to.
1468 * @param status Receives a status code, which will be U_ZERO_ERROR
1469 * if the operation succeeds.
1471 static void translatePattern(const UnicodeString
& originalPattern
,
1472 UnicodeString
& translatedPattern
,
1473 const UnicodeString
& from
,
1474 const UnicodeString
& to
,
1475 UErrorCode
& status
);
1478 * Sets the starting date of the 100-year window that dates with 2-digit years
1479 * are considered to fall within.
1480 * @param startDate the start date
1481 * @param status Receives a status code, which will be U_ZERO_ERROR
1482 * if the operation succeeds.
1484 void parseAmbiguousDatesAsAfter(UDate startDate
, UErrorCode
& status
);
1487 * Return the length matched by the given affix, or -1 if none.
1488 * Runs of white space in the affix, match runs of white space in
1490 * @param affix pattern string, taken as a literal
1491 * @param input input text
1492 * @param pos offset into input at which to begin matching
1493 * @return length of input that matches, or -1 if match failure
1495 int32_t compareSimpleAffix(const UnicodeString
& affix
,
1496 const UnicodeString
& input
,
1500 * Skip over a run of zero or more Pattern_White_Space characters at
1503 int32_t skipPatternWhiteSpace(const UnicodeString
& text
, int32_t pos
) const;
1506 * Skip over a run of zero or more isUWhiteSpace() characters at pos
1509 int32_t skipUWhiteSpace(const UnicodeString
& text
, int32_t pos
) const;
1512 * Initialize NumberFormat instances used for numbering system overrides.
1514 void initNumberFormatters(const Locale
&locale
,UErrorCode
&status
);
1517 * Parse the given override string and set up structures for number formats
1519 void processOverrideString(const Locale
&locale
, const UnicodeString
&str
, int8_t type
, UErrorCode
&status
);
1522 * Used to map pattern characters to Calendar field identifiers.
1524 static const UCalendarDateFields fgPatternIndexToCalendarField
[];
1527 * Map index into pattern character string to DateFormat field number
1529 static const UDateFormatField fgPatternIndexToDateFormatField
[];
1532 * Lazy TimeZoneFormat instantiation, semantically const
1534 TimeZoneFormat
*tzFormat() const;
1536 const NumberFormat
* getNumberFormatByIndex(UDateFormatField index
) const;
1539 * Used to map Calendar field to field level.
1540 * The larger the level, the smaller the field unit.
1541 * For example, UCAL_ERA level is 0, UCAL_YEAR level is 10,
1542 * UCAL_MONTH level is 20.
1544 static const int32_t fgCalendarFieldToLevel
[];
1547 * Map calendar field letter into calendar field level.
1549 static int32_t getLevelFromChar(char16_t ch
);
1552 * Tell if a character can be used to define a field in a format string.
1554 static UBool
isSyntaxChar(char16_t ch
);
1557 * The formatting pattern for this formatter.
1559 UnicodeString fPattern
;
1562 * The numbering system override for dates.
1564 UnicodeString fDateOverride
;
1567 * The numbering system override for times.
1569 UnicodeString fTimeOverride
;
1573 * The original locale used (for reloading symbols)
1578 * A pointer to an object containing the strings to use in formatting (e.g.,
1579 * month and day names, AM and PM strings, time zone names, etc.)
1581 DateFormatSymbols
* fSymbols
; // Owned
1584 * The time zone formatter
1586 TimeZoneFormat
* fTimeZoneFormat
;
1589 * If dates have ambiguous years, we map them into the century starting
1590 * at defaultCenturyStart, which may be any date. If defaultCenturyStart is
1591 * set to SYSTEM_DEFAULT_CENTURY, which it is by default, then the system
1592 * values are used. The instance values defaultCenturyStart and
1593 * defaultCenturyStartYear are only used if explicitly set by the user
1594 * through the API method parseAmbiguousDatesAsAfter().
1596 UDate fDefaultCenturyStart
;
1602 * Sets fHasMinutes and fHasSeconds.
1604 void parsePattern();
1607 * See documentation for defaultCenturyStart.
1609 /*transient*/ int32_t fDefaultCenturyStartYear
;
1611 struct NSOverride
: public UMemory
{
1612 const SharedNumberFormat
*snf
;
1616 NSOverride() : snf(NULL
), hash(0), next(NULL
) {
1622 * The number format in use for each date field. NULL means fall back
1623 * to fNumberFormat in DateFormat.
1625 const SharedNumberFormat
**fSharedNumberFormatters
;
1627 UBool fHaveDefaultCentury
;
1629 BreakIterator
* fCapitalizationBrkIter
;
1633 SimpleDateFormat::get2DigitYearStart(UErrorCode
& /*status*/) const
1635 return fDefaultCenturyStart
;
1638 inline BreakIterator
*
1639 SimpleDateFormat::getCapitalizationBrkIter() const
1641 return fCapitalizationBrkIter
;
1645 #endif // U_SHOW_CPLUSPLUS_API
1647 #endif /* #if !UCONFIG_NO_FORMATTING */