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
;
53 class DateIntervalFormat
;
56 class LocalizedNumberFormatter
;
61 * SimpleDateFormat is a concrete class for formatting and parsing dates in a
62 * language-independent manner. It allows for formatting (millis -> text),
63 * parsing (text -> millis), and normalization. Formats/Parses a date or time,
64 * which is the standard milliseconds since 24:00 GMT, Jan 1, 1970.
66 * Clients are encouraged to create a date-time formatter using DateFormat::getInstance(),
67 * getDateInstance(), getDateInstance(), or getDateTimeInstance() rather than
68 * explicitly constructing an instance of SimpleDateFormat. This way, the client
69 * is guaranteed to get an appropriate formatting pattern for whatever locale the
70 * program is running in. However, if the client needs something more unusual than
71 * the default patterns in the locales, he can construct a SimpleDateFormat directly
72 * and give it an appropriate pattern (or use one of the factory methods on DateFormat
73 * and modify the pattern after the fact with toPattern() and applyPattern().
75 * <p><strong>Date and Time Patterns:</strong></p>
77 * <p>Date and time formats are specified by <em>date and time pattern</em> strings.
78 * Within date and time pattern strings, all unquoted ASCII letters [A-Za-z] are reserved
79 * as pattern letters representing calendar fields. <code>SimpleDateFormat</code> supports
80 * the date and time formatting algorithm and pattern letters defined by
81 * <a href="http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table">UTS#35
82 * Unicode Locale Data Markup Language (LDML)</a> and further documented for ICU in the
83 * <a href="https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table">ICU
84 * User Guide</a>. The following pattern letters are currently available (note that the actual
85 * values depend on CLDR and may change from the examples shown here):</p>
90 * <th style="text-align: center">Sym.</th>
91 * <th style="text-align: center">No.</th>
93 * <th>Description</th>
96 * <th rowspan="3">era</th>
97 * <td style="text-align: center" rowspan="3">G</td>
98 * <td style="text-align: center">1..3</td>
100 * <td rowspan="3">Era - Replaced with the Era string for the current date. One to three letters for the
101 * abbreviated form, four letters for the long (wide) form, five for the narrow form.</td>
104 * <td style="text-align: center">4</td>
105 * <td>Anno Domini</td>
108 * <td style="text-align: center">5</td>
112 * <th rowspan="6">year</th>
113 * <td style="text-align: center">y</td>
114 * <td style="text-align: center">1..n</td>
116 * <td>Year. Normally the length specifies the padding, but for two letters it also specifies the maximum
117 * length. Example:<div align="center">
119 * <table border="1" cellpadding="2" cellspacing="0">
122 * <th style="text-align: right">y</th>
123 * <th style="text-align: right">yy</th>
124 * <th style="text-align: right">yyy</th>
125 * <th style="text-align: right">yyyy</th>
126 * <th style="text-align: right">yyyyy</th>
130 * <td style="text-align: right">1</td>
131 * <td style="text-align: right">01</td>
132 * <td style="text-align: right">001</td>
133 * <td style="text-align: right">0001</td>
134 * <td style="text-align: right">00001</td>
138 * <td style="text-align: right">12</td>
139 * <td style="text-align: right">12</td>
140 * <td style="text-align: right">012</td>
141 * <td style="text-align: right">0012</td>
142 * <td style="text-align: right">00012</td>
146 * <td style="text-align: right">123</td>
147 * <td style="text-align: right">23</td>
148 * <td style="text-align: right">123</td>
149 * <td style="text-align: right">0123</td>
150 * <td style="text-align: right">00123</td>
154 * <td style="text-align: right">1234</td>
155 * <td style="text-align: right">34</td>
156 * <td style="text-align: right">1234</td>
157 * <td style="text-align: right">1234</td>
158 * <td style="text-align: right">01234</td>
162 * <td style="text-align: right">12345</td>
163 * <td style="text-align: right">45</td>
164 * <td style="text-align: right">12345</td>
165 * <td style="text-align: right">12345</td>
166 * <td style="text-align: right">12345</td>
173 * <td style="text-align: center">Y</td>
174 * <td style="text-align: center">1..n</td>
176 * <td>Year (in "Week of Year" based calendars). Normally the length specifies the padding,
177 * but for two letters it also specifies the maximum length. This year designation is used in ISO
178 * year-week calendar as defined by ISO 8601, but can be used in non-Gregorian based calendar systems
179 * where week date processing is desired. May not always be the same value as calendar year.</td>
182 * <td style="text-align: center">u</td>
183 * <td style="text-align: center">1..n</td>
185 * <td>Extended year. This is a single number designating the year of this calendar system, encompassing
186 * all supra-year fields. For example, for the Julian calendar system, year numbers are positive, with an
187 * era of BCE or CE. An extended year value for the Julian calendar system assigns positive values to CE
188 * years and negative values to BCE years, with 1 BCE being year 0.</td>
191 * <td style="text-align: center" rowspan="3">U</td>
192 * <td style="text-align: center">1..3</td>
193 * <td>甲子</td>
194 * <td rowspan="3">Cyclic year name. Calendars such as the Chinese lunar calendar (and related calendars)
195 * and the Hindu calendars use 60-year cycles of year names. Use one through three letters for the abbreviated
196 * name, four for the full (wide) name, or five for the narrow name (currently the data only provides abbreviated names,
197 * which will be used for all requested name widths). If the calendar does not provide cyclic year name data,
198 * or if the year value to be formatted is out of the range of years for which cyclic name data is provided,
199 * then numeric formatting is used (behaves like 'y').</td>
202 * <td style="text-align: center">4</td>
203 * <td>(currently also 甲子)</td>
206 * <td style="text-align: center">5</td>
207 * <td>(currently also 甲子)</td>
210 * <th rowspan="6">quarter</th>
211 * <td rowspan="3" style="text-align: center">Q</td>
212 * <td style="text-align: center">1..2</td>
214 * <td rowspan="3">Quarter - Use one or two for the numerical quarter, three for the abbreviation, or four for the
215 * full (wide) name (five for the narrow name is not yet supported).</td>
218 * <td style="text-align: center">3</td>
222 * <td style="text-align: center">4</td>
223 * <td>2nd quarter</td>
226 * <td rowspan="3" style="text-align: center">q</td>
227 * <td style="text-align: center">1..2</td>
229 * <td rowspan="3"><b>Stand-Alone</b> Quarter - Use one or two for the numerical quarter, three for the abbreviation,
230 * or four for the full name (five for the narrow name is not yet supported).</td>
233 * <td style="text-align: center">3</td>
237 * <td style="text-align: center">4</td>
238 * <td>2nd quarter</td>
241 * <th rowspan="8">month</th>
242 * <td rowspan="4" style="text-align: center">M</td>
243 * <td style="text-align: center">1..2</td>
245 * <td rowspan="4">Month - Use one or two for the numerical month, three for the abbreviation, four for
246 * the full (wide) name, or five for the narrow name. With two ("MM"), the month number is zero-padded
247 * if necessary (e.g. "08")</td>
250 * <td style="text-align: center">3</td>
254 * <td style="text-align: center">4</td>
258 * <td style="text-align: center">5</td>
262 * <td rowspan="4" style="text-align: center">L</td>
263 * <td style="text-align: center">1..2</td>
265 * <td rowspan="4"><b>Stand-Alone</b> Month - Use one or two for the numerical month, three for the abbreviation,
266 * four for the full (wide) name, or 5 for the narrow name. With two ("LL"), the month number is zero-padded if
267 * necessary (e.g. "08")</td>
270 * <td style="text-align: center">3</td>
274 * <td style="text-align: center">4</td>
278 * <td style="text-align: center">5</td>
282 * <th rowspan="2">week</th>
283 * <td style="text-align: center">w</td>
284 * <td style="text-align: center">1..2</td>
286 * <td>Week of Year. Use "w" to show the minimum number of digits, or "ww" to always show two digits
287 * (zero-padding if necessary, e.g. "08").</td>
290 * <td style="text-align: center">W</td>
291 * <td style="text-align: center">1</td>
293 * <td>Week of Month</td>
296 * <th rowspan="4">day</th>
297 * <td style="text-align: center">d</td>
298 * <td style="text-align: center">1..2</td>
300 * <td>Date - Day of the month. Use "d" to show the minimum number of digits, or "dd" to always show
301 * two digits (zero-padding if necessary, e.g. "08").</td>
304 * <td style="text-align: center">D</td>
305 * <td style="text-align: center">1..3</td>
307 * <td>Day of year</td>
310 * <td style="text-align: center">F</td>
311 * <td style="text-align: center">1</td>
313 * <td>Day of Week in Month. The example is for the 2nd Wed in July</td>
316 * <td style="text-align: center">g</td>
317 * <td style="text-align: center">1..n</td>
319 * <td>Modified Julian day. This is different from the conventional Julian day number in two regards.
320 * First, it demarcates days at local zone midnight, rather than noon GMT. Second, it is a local number;
321 * that is, it depends on the local time zone. It can be thought of as a single number that encompasses
322 * all the date-related fields.</td>
325 * <th rowspan="14">week<br>
327 * <td rowspan="4" style="text-align: center">E</td>
328 * <td style="text-align: center">1..3</td>
330 * <td rowspan="4">Day of week - Use one through three letters for the short day, four for the full (wide) name,
331 * five for the narrow name, or six for the short name.</td>
334 * <td style="text-align: center">4</td>
338 * <td style="text-align: center">5</td>
342 * <td style="text-align: center">6</td>
346 * <td rowspan="5" style="text-align: center">e</td>
347 * <td style="text-align: center">1..2</td>
349 * <td rowspan="5">Local day of week. Same as E except adds a numeric value that will depend on the local
350 * starting day of the week, using one or two letters. For this example, Monday is the first day of the week.</td>
353 * <td style="text-align: center">3</td>
357 * <td style="text-align: center">4</td>
361 * <td style="text-align: center">5</td>
365 * <td style="text-align: center">6</td>
369 * <td rowspan="5" style="text-align: center">c</td>
370 * <td style="text-align: center">1</td>
372 * <td rowspan="5"><b>Stand-Alone</b> local day of week - Use one letter for the local numeric value (same
373 * as 'e'), three for the short day, four for the full (wide) name, five for the narrow name, or six for
374 * the short name.</td>
377 * <td style="text-align: center">3</td>
381 * <td style="text-align: center">4</td>
385 * <td style="text-align: center">5</td>
389 * <td style="text-align: center">6</td>
394 * <td style="text-align: center">a</td>
395 * <td style="text-align: center">1</td>
400 * <th rowspan="4">hour</th>
401 * <td style="text-align: center">h</td>
402 * <td style="text-align: center">1..2</td>
404 * <td>Hour [1-12]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern
405 * generation, it should match the 12-hour-cycle format preferred by the locale (h or K); it should not match
406 * a 24-hour-cycle format (H or k). Use hh for zero padding.</td>
409 * <td style="text-align: center">H</td>
410 * <td style="text-align: center">1..2</td>
412 * <td>Hour [0-23]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern
413 * generation, it should match the 24-hour-cycle format preferred by the locale (H or k); it should not match a
414 * 12-hour-cycle format (h or K). Use HH for zero padding.</td>
417 * <td style="text-align: center">K</td>
418 * <td style="text-align: center">1..2</td>
420 * <td>Hour [0-11]. When used in a skeleton, only matches K or h, see above. Use KK for zero padding.</td>
423 * <td style="text-align: center">k</td>
424 * <td style="text-align: center">1..2</td>
426 * <td>Hour [1-24]. When used in a skeleton, only matches k or H, see above. Use kk for zero padding.</td>
430 * <td style="text-align: center">m</td>
431 * <td style="text-align: center">1..2</td>
433 * <td>Minute. Use "m" to show the minimum number of digits, or "mm" to always show two digits
434 * (zero-padding if necessary, e.g. "08").</td>
437 * <th rowspan="3">second</th>
438 * <td style="text-align: center">s</td>
439 * <td style="text-align: center">1..2</td>
441 * <td>Second. Use "s" to show the minimum number of digits, or "ss" to always show two digits
442 * (zero-padding if necessary, e.g. "08").</td>
445 * <td style="text-align: center">S</td>
446 * <td style="text-align: center">1..n</td>
448 * <td>Fractional Second - truncates (like other time fields) to the count of letters when formatting.
449 * Appends zeros if more than 3 letters specified. Truncates at three significant digits when parsing.
450 * (example shows display using pattern SSSS for seconds value 12.34567)</td>
453 * <td style="text-align: center">A</td>
454 * <td style="text-align: center">1..n</td>
456 * <td>Milliseconds in day. This field behaves <i>exactly</i> like a composite of all time-related fields,
457 * not including the zone fields. As such, it also reflects discontinuities of those fields on DST transition
458 * days. On a day of DST onset, it will jump forward. On a day of DST cessation, it will jump backward. This
459 * reflects the fact that is must be combined with the offset field to obtain a unique local time value.</td>
462 * <th rowspan="23">zone</th>
463 * <td rowspan="2" style="text-align: center">z</td>
464 * <td style="text-align: center">1..3</td>
466 * <td>The <i>short specific non-location format</i>.
467 * Where that is unavailable, falls back to the <i>short localized GMT format</i> ("O").</td>
470 * <td style="text-align: center">4</td>
471 * <td>Pacific Daylight Time</td>
472 * <td>The <i>long specific non-location format</i>.
473 * Where that is unavailable, falls back to the <i>long localized GMT format</i> ("OOOO").</td>
476 * <td rowspan="3" style="text-align: center">Z</td>
477 * <td style="text-align: center">1..3</td>
479 * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
480 * The format is equivalent to RFC 822 zone format (when optional seconds field is absent).
481 * This is equivalent to the "xxxx" specifier.</td>
484 * <td style="text-align: center">4</td>
486 * <td>The <i>long localized GMT format</i>.
487 * This is equivalent to the "OOOO" specifier.</td>
490 * <td style="text-align: center">5</td>
493 * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
494 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.
495 * This is equivalent to the "XXXXX" specifier.</td>
498 * <td rowspan="2" style="text-align: center">O</td>
499 * <td style="text-align: center">1</td>
501 * <td>The <i>short localized GMT format</i>.</td>
504 * <td style="text-align: center">4</td>
506 * <td>The <i>long localized GMT format</i>.</td>
509 * <td rowspan="2" style="text-align: center">v</td>
510 * <td style="text-align: center">1</td>
512 * <td>The <i>short generic non-location format</i>.
513 * Where that is unavailable, falls back to the <i>generic location format</i> ("VVVV"),
514 * then the <i>short localized GMT format</i> as the final fallback.</td>
517 * <td style="text-align: center">4</td>
518 * <td>Pacific Time</td>
519 * <td>The <i>long generic non-location format</i>.
520 * Where that is unavailable, falls back to <i>generic location format</i> ("VVVV").
523 * <td rowspan="4" style="text-align: center">V</td>
524 * <td style="text-align: center">1</td>
526 * <td>The short time zone ID.
527 * Where that is unavailable, the special short time zone ID <i>unk</i> (Unknown Zone) is used.<br>
528 * <i><b>Note</b>: This specifier was originally used for a variant of the short specific non-location format,
529 * but it was deprecated in the later version of the LDML specification. In CLDR 23/ICU 51, the definition of
530 * the specifier was changed to designate a short time zone ID.</i></td>
533 * <td style="text-align: center">2</td>
534 * <td>America/Los_Angeles</td>
535 * <td>The long time zone ID.</td>
538 * <td style="text-align: center">3</td>
539 * <td>Los Angeles</td>
540 * <td>The exemplar city (location) for the time zone.
541 * Where that is unavailable, the localized exemplar city name for the special zone <i>Etc/Unknown</i> is used
542 * as the fallback (for example, "Unknown City"). </td>
545 * <td style="text-align: center">4</td>
546 * <td>Los Angeles Time</td>
547 * <td>The <i>generic location format</i>.
548 * Where that is unavailable, falls back to the <i>long localized GMT format</i> ("OOOO";
549 * Note: Fallback is only necessary with a GMT-style Time Zone ID, like Etc/GMT-830.)<br>
550 * This is especially useful when presenting possible timezone choices for user selection,
551 * since the naming is more uniform than the "v" format.</td>
554 * <td rowspan="5" style="text-align: center">X</td>
555 * <td style="text-align: center">1</td>
559 * <td>The <i>ISO8601 basic format</i> with hours field and optional minutes field.
560 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
563 * <td style="text-align: center">2</td>
566 * <td>The <i>ISO8601 basic format</i> with hours and minutes fields.
567 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
570 * <td style="text-align: center">3</td>
573 * <td>The <i>ISO8601 extended format</i> with hours and minutes fields.
574 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
577 * <td style="text-align: center">4</td>
581 * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
582 * (Note: The seconds field is not supported by the ISO8601 specification.)
583 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
586 * <td style="text-align: center">5</td>
590 * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
591 * (Note: The seconds field is not supported by the ISO8601 specification.)
592 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
595 * <td rowspan="5" style="text-align: center">x</td>
596 * <td style="text-align: center">1</td>
599 * <td>The <i>ISO8601 basic format</i> with hours field and optional minutes field.</td>
602 * <td style="text-align: center">2</td>
604 * <td>The <i>ISO8601 basic format</i> with hours and minutes fields.</td>
607 * <td style="text-align: center">3</td>
609 * <td>The <i>ISO8601 extended format</i> with hours and minutes fields.</td>
612 * <td style="text-align: center">4</td>
615 * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
616 * (Note: The seconds field is not supported by the ISO8601 specification.)</td>
619 * <td style="text-align: center">5</td>
622 * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
623 * (Note: The seconds field is not supported by the ISO8601 specification.)</td>
628 * Any characters in the pattern that are not in the ranges of ['a'..'z'] and
629 * ['A'..'Z'] will be treated as quoted text. For instance, characters
630 * like ':', '.', ' ', '#' and '@' will appear in the resulting time text
631 * even they are not embraced within single quotes.
633 * A pattern containing any invalid pattern letter will result in a failing
634 * UErrorCode result during formatting or parsing.
636 * Examples using the US locale:
639 * Format Pattern Result
640 * -------------- -------
641 * "yyyy.MM.dd G 'at' HH:mm:ss vvvv" ->> 1996.07.10 AD at 15:08:56 Pacific Time
642 * "EEE, MMM d, ''yy" ->> Wed, July 10, '96
643 * "h:mm a" ->> 12:08 PM
644 * "hh 'o''clock' a, zzzz" ->> 12 o'clock PM, Pacific Daylight Time
645 * "K:mm a, vvv" ->> 0:00 PM, PT
646 * "yyyyy.MMMMM.dd GGG hh:mm aaa" ->> 1996.July.10 AD 12:08 PM
652 * UErrorCode success = U_ZERO_ERROR;
653 * SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "PST");
654 * pdt->setStartRule( Calendar::APRIL, 1, Calendar::SUNDAY, 2*60*60*1000);
655 * pdt->setEndRule( Calendar::OCTOBER, -1, Calendar::SUNDAY, 2*60*60*1000);
657 * // Format the current time.
658 * SimpleDateFormat* formatter
659 * = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz", success );
660 * GregorianCalendar cal(success);
661 * UDate currentTime_1 = cal.getTime(success);
662 * FieldPosition fp(FieldPosition::DONT_CARE);
663 * UnicodeString dateString;
664 * formatter->format( currentTime_1, dateString, fp );
665 * cout << "result: " << dateString << endl;
667 * // Parse the previous string back into a Date.
668 * ParsePosition pp(0);
669 * UDate currentTime_2 = formatter->parse(dateString, pp );
672 * In the above example, the time value "currentTime_2" obtained from parsing
673 * will be equal to currentTime_1. However, they may not be equal if the am/pm
674 * marker 'a' is left out from the format pattern while the "hour in am/pm"
675 * pattern symbol is used. This information loss can happen when formatting the
679 * When parsing a date string using the abbreviated year pattern ("y" or "yy"),
680 * SimpleDateFormat must interpret the abbreviated year
681 * relative to some century. It does this by adjusting dates to be
682 * within 80 years before and 20 years after the time the SimpleDateFormat
683 * instance is created. For example, using a pattern of "MM/dd/yy" and a
684 * SimpleDateFormat instance created on Jan 1, 1997, the string
685 * "01/11/12" would be interpreted as Jan 11, 2012 while the string "05/04/64"
686 * would be interpreted as May 4, 1964.
687 * During parsing, only strings consisting of exactly two digits, as defined by
688 * <code>Unicode::isDigit()</code>, will be parsed into the default century.
689 * Any other numeric string, such as a one digit string, a three or more digit
690 * string, or a two digit string that isn't all digits (for example, "-1"), is
691 * interpreted literally. So "01/02/3" or "01/02/003" are parsed (for the
692 * Gregorian calendar), using the same pattern, as Jan 2, 3 AD. Likewise (but
693 * only in lenient parse mode, the default) "01/02/-3" is parsed as Jan 2, 4 BC.
696 * If the year pattern has more than two 'y' characters, the year is
697 * interpreted literally, regardless of the number of digits. So using the
698 * pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
701 * When numeric fields abut one another directly, with no intervening delimiter
702 * characters, they constitute a run of abutting numeric fields. Such runs are
703 * parsed specially. For example, the format "HHmmss" parses the input text
704 * "123456" to 12:34:56, parses the input text "12345" to 1:23:45, and fails to
705 * parse "1234". In other words, the leftmost field of the run is flexible,
706 * while the others keep a fixed width. If the parse fails anywhere in the run,
707 * then the leftmost field is shortened by one character, and the entire run is
708 * parsed again. This is repeated until either the parse succeeds or the
709 * leftmost field is one character in length. If the parse still fails at that
710 * point, the parse of the run fails.
713 * For time zones that have no names, SimpleDateFormat uses strings GMT+hours:minutes or
716 * The calendar defines what is the first day of the week, the first week of the
717 * year, whether hours are zero based or not (0 vs 12 or 24), and the timezone.
718 * There is one common number format to handle all the numbers; the digit count
719 * is handled programmatically according to the pattern.
721 * <p><em>User subclasses are not supported.</em> While clients may write
722 * subclasses, such code will not necessarily work and will not be
723 * guaranteed to work stably from release to release.
725 class U_I18N_API SimpleDateFormat
: public DateFormat
{
728 * Construct a SimpleDateFormat using the default pattern for the default
731 * [Note:] Not all locales support SimpleDateFormat; for full generality,
732 * use the factory methods in the DateFormat class.
733 * @param status Output param set to success/failure code.
736 SimpleDateFormat(UErrorCode
& status
);
739 * Construct a SimpleDateFormat using the given pattern and the default locale.
740 * The locale is used to obtain the symbols used in formatting (e.g., the
741 * names of the months), but not to provide the pattern.
743 * [Note:] Not all locales support SimpleDateFormat; for full generality,
744 * use the factory methods in the DateFormat class.
745 * @param pattern the pattern for the format.
746 * @param status Output param set to success/failure code.
749 SimpleDateFormat(const UnicodeString
& pattern
,
753 * Construct a SimpleDateFormat using the given pattern, numbering system override, and the default locale.
754 * The locale is used to obtain the symbols used in formatting (e.g., the
755 * names of the months), but not to provide the pattern.
757 * A numbering system override is a string containing either the name of a known numbering system,
758 * or a set of field and numbering system pairs that specify which fields are to be formattied with
759 * the alternate numbering system. For example, to specify that all numeric fields in the specified
760 * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
761 * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering,
762 * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon
763 * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
766 * [Note:] Not all locales support SimpleDateFormat; for full generality,
767 * use the factory methods in the DateFormat class.
768 * @param pattern the pattern for the format.
769 * @param override the override string.
770 * @param status Output param set to success/failure code.
773 SimpleDateFormat(const UnicodeString
& pattern
,
774 const UnicodeString
& override
,
778 * Construct a SimpleDateFormat using the given pattern and locale.
779 * The locale is used to obtain the symbols used in formatting (e.g., the
780 * names of the months), but not to provide the pattern.
782 * [Note:] Not all locales support SimpleDateFormat; for full generality,
783 * use the factory methods in the DateFormat class.
784 * @param pattern the pattern for the format.
785 * @param locale the given locale.
786 * @param status Output param set to success/failure code.
789 SimpleDateFormat(const UnicodeString
& pattern
,
790 const Locale
& locale
,
794 * Construct a SimpleDateFormat using the given pattern, numbering system override, and locale.
795 * The locale is used to obtain the symbols used in formatting (e.g., the
796 * names of the months), but not to provide the pattern.
798 * A numbering system override is a string containing either the name of a known numbering system,
799 * or a set of field and numbering system pairs that specify which fields are to be formattied with
800 * the alternate numbering system. For example, to specify that all numeric fields in the specified
801 * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
802 * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering,
803 * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon
804 * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
806 * [Note:] Not all locales support SimpleDateFormat; for full generality,
807 * use the factory methods in the DateFormat class.
808 * @param pattern the pattern for the format.
809 * @param override the numbering system override.
810 * @param locale the given locale.
811 * @param status Output param set to success/failure code.
814 SimpleDateFormat(const UnicodeString
& pattern
,
815 const UnicodeString
& override
,
816 const Locale
& locale
,
820 * Construct a SimpleDateFormat using the given pattern and locale-specific
821 * symbol data. The formatter takes ownership of the DateFormatSymbols object;
822 * the caller is no longer responsible for deleting it.
823 * @param pattern the given pattern for the format.
824 * @param formatDataToAdopt the symbols to be adopted.
825 * @param status Output param set to success/faulure code.
828 SimpleDateFormat(const UnicodeString
& pattern
,
829 DateFormatSymbols
* formatDataToAdopt
,
833 * Construct a SimpleDateFormat using the given pattern and locale-specific
834 * symbol data. The DateFormatSymbols object is NOT adopted; the caller
835 * remains responsible for deleting it.
836 * @param pattern the given pattern for the format.
837 * @param formatData the formatting symbols to be use.
838 * @param status Output param set to success/faulure code.
841 SimpleDateFormat(const UnicodeString
& pattern
,
842 const DateFormatSymbols
& formatData
,
849 SimpleDateFormat(const SimpleDateFormat
&);
852 * Assignment operator.
855 SimpleDateFormat
& operator=(const SimpleDateFormat
&);
861 virtual ~SimpleDateFormat();
864 * Clone this Format object polymorphically. The caller owns the result and
865 * should delete it when done.
866 * @return A copy of the object.
869 virtual Format
* clone(void) const;
872 * Return true if the given Format objects are semantically equal. Objects
873 * of different subclasses are considered unequal.
874 * @param other the object to be compared with.
875 * @return true if the given Format objects are semantically equal.
878 virtual UBool
operator==(const Format
& other
) const;
881 using DateFormat::format
;
884 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
885 * 1, 1970. Overrides DateFormat pure virtual method.
887 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
888 * 1996.07.10 AD at 15:08:56 PDT
890 * @param cal Calendar set to the date and time to be formatted
891 * into a date/time string.
892 * @param appendTo Output parameter to receive result.
893 * Result is appended to existing contents.
894 * @param pos The formatting position. On input: an alignment field,
895 * if desired. On output: the offsets of the alignment field.
896 * @return Reference to 'appendTo' parameter.
899 virtual UnicodeString
& format( Calendar
& cal
,
900 UnicodeString
& appendTo
,
901 FieldPosition
& pos
) const;
904 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
905 * 1, 1970. Overrides DateFormat pure virtual method.
907 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
908 * 1996.07.10 AD at 15:08:56 PDT
910 * @param cal Calendar set to the date and time to be formatted
911 * into a date/time string.
912 * @param appendTo Output parameter to receive result.
913 * Result is appended to existing contents.
914 * @param posIter On return, can be used to iterate over positions
915 * of fields generated by this format call. Field values
916 * are defined in UDateFormatField.
917 * @param status Input/output param set to success/failure code.
918 * @return Reference to 'appendTo' parameter.
921 virtual UnicodeString
& format( Calendar
& cal
,
922 UnicodeString
& appendTo
,
923 FieldPositionIterator
* posIter
,
924 UErrorCode
& status
) const;
926 using DateFormat::parse
;
929 * Parse a date/time string beginning at the given parse position. For
930 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
931 * that is equivalent to Date(837039928046).
933 * By default, parsing is lenient: If the input is not in the form used by
934 * this object's format method but can still be parsed as a date, then the
935 * parse succeeds. Clients may insist on strict adherence to the format by
936 * calling setLenient(false).
937 * @see DateFormat::setLenient(boolean)
939 * @param text The date/time string to be parsed
940 * @param cal A Calendar set on input to the date and time to be used for
941 * missing values in the date/time string being parsed, and set
942 * on output to the parsed date/time. When the calendar type is
943 * different from the internal calendar held by this SimpleDateFormat
944 * instance, the internal calendar will be cloned to a work
945 * calendar set to the same milliseconds and time zone as the
946 * cal parameter, field values will be parsed based on the work
947 * calendar, then the result (milliseconds and time zone) will
948 * be set in this calendar.
949 * @param pos On input, the position at which to start parsing; on
950 * output, the position at which parsing terminated, or the
951 * start position if the parse failed.
954 virtual void parse( const UnicodeString
& text
,
956 ParsePosition
& pos
) const;
960 * Set the start UDate used to interpret two-digit year strings.
961 * When dates are parsed having 2-digit year strings, they are placed within
962 * a assumed range of 100 years starting on the two digit start date. For
963 * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
964 * some other year. SimpleDateFormat chooses a year so that the resultant
965 * date is on or after the two digit start date and within 100 years of the
966 * two digit start date.
968 * By default, the two digit start date is set to 80 years before the current
969 * time at which a SimpleDateFormat object is created.
970 * @param d start UDate used to interpret two-digit year strings.
971 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
972 * an error value if there was a parse error.
975 virtual void set2DigitYearStart(UDate d
, UErrorCode
& status
);
978 * Get the start UDate used to interpret two-digit year strings.
979 * When dates are parsed having 2-digit year strings, they are placed within
980 * a assumed range of 100 years starting on the two digit start date. For
981 * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
982 * some other year. SimpleDateFormat chooses a year so that the resultant
983 * date is on or after the two digit start date and within 100 years of the
984 * two digit start date.
986 * By default, the two digit start date is set to 80 years before the current
987 * time at which a SimpleDateFormat object is created.
988 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
989 * an error value if there was a parse error.
992 UDate
get2DigitYearStart(UErrorCode
& status
) const;
995 * Return a pattern string describing this date format.
996 * @param result Output param to receive the pattern.
997 * @return A reference to 'result'.
1000 virtual UnicodeString
& toPattern(UnicodeString
& result
) const;
1003 * Return a localized pattern string describing this date format.
1004 * In most cases, this will return the same thing as toPattern(),
1005 * but a locale can specify characters to use in pattern descriptions
1006 * in place of the ones described in this class's class documentation.
1007 * (Presumably, letters that would be more mnemonic in that locale's
1008 * language.) This function would produce a pattern using those
1011 * <b>Note:</b> This implementation depends on DateFormatSymbols::getLocalPatternChars()
1012 * to get localized format pattern characters. ICU does not include
1013 * localized pattern character data, therefore, unless user sets localized
1014 * pattern characters manually, this method returns the same result as
1017 * @param result Receives the localized pattern.
1018 * @param status Output param set to success/failure code on
1019 * exit. If the pattern is invalid, this will be
1020 * set to a failure result.
1021 * @return A reference to 'result'.
1024 virtual UnicodeString
& toLocalizedPattern(UnicodeString
& result
,
1025 UErrorCode
& status
) const;
1028 * Apply the given unlocalized pattern string to this date format.
1029 * (i.e., after this call, this formatter will format dates according to
1032 * @param pattern The pattern to be applied.
1035 virtual void applyPattern(const UnicodeString
& pattern
);
1038 * Apply the given localized pattern string to this date format.
1039 * (see toLocalizedPattern() for more information on localized patterns.)
1041 * @param pattern The localized pattern to be applied.
1042 * @param status Output param set to success/failure code on
1043 * exit. If the pattern is invalid, this will be
1044 * set to a failure result.
1047 virtual void applyLocalizedPattern(const UnicodeString
& pattern
,
1048 UErrorCode
& status
);
1051 * Gets the date/time formatting symbols (this is an object carrying
1052 * the various strings and other symbols used in formatting: e.g., month
1053 * names and abbreviations, time zone names, AM/PM strings, etc.)
1054 * @return a copy of the date-time formatting data associated
1055 * with this date-time formatter.
1058 virtual const DateFormatSymbols
* getDateFormatSymbols(void) const;
1061 * Set the date/time formatting symbols. The caller no longer owns the
1062 * DateFormatSymbols object and should not delete it after making this call.
1063 * @param newFormatSymbols the given date-time formatting symbols to copy.
1066 virtual void adoptDateFormatSymbols(DateFormatSymbols
* newFormatSymbols
);
1069 * Set the date/time formatting data.
1070 * @param newFormatSymbols the given date-time formatting symbols to copy.
1073 virtual void setDateFormatSymbols(const DateFormatSymbols
& newFormatSymbols
);
1076 * Return the class ID for this class. This is useful only for comparing to
1077 * a return value from getDynamicClassID(). For example:
1079 * . Base* polymorphic_pointer = createPolymorphicObject();
1080 * . if (polymorphic_pointer->getDynamicClassID() ==
1081 * . erived::getStaticClassID()) ...
1083 * @return The class ID for all objects of this class.
1086 static UClassID U_EXPORT2
getStaticClassID(void);
1089 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
1090 * method is to implement a simple version of RTTI, since not all C++
1091 * compilers support genuine RTTI. Polymorphic operator==() and clone()
1092 * methods call this method.
1094 * @return The class ID for this object. All objects of a
1095 * given class have the same class ID. Objects of
1096 * other classes have different class IDs.
1099 virtual UClassID
getDynamicClassID(void) const;
1102 * Set the calendar to be used by this date format. Initially, the default
1103 * calendar for the specified or default locale is used. The caller should
1104 * not delete the Calendar object after it is adopted by this call.
1105 * Adopting a new calendar will change to the default symbols.
1107 * @param calendarToAdopt Calendar object to be adopted.
1110 virtual void adoptCalendar(Calendar
* calendarToAdopt
);
1112 /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
1114 * Sets the TimeZoneFormat to be used by this date/time formatter.
1115 * The caller should not delete the TimeZoneFormat object after
1116 * it is adopted by this call.
1117 * @param timeZoneFormatToAdopt The TimeZoneFormat object to be adopted.
1118 * @internal ICU 49 technology preview
1120 virtual void adoptTimeZoneFormat(TimeZoneFormat
* timeZoneFormatToAdopt
);
1123 * Sets the TimeZoneFormat to be used by this date/time formatter.
1124 * @param newTimeZoneFormat The TimeZoneFormat object to copy.
1125 * @internal ICU 49 technology preview
1127 virtual void setTimeZoneFormat(const TimeZoneFormat
& newTimeZoneFormat
);
1130 * Gets the time zone format object associated with this date/time formatter.
1131 * @return the time zone format associated with this date/time formatter.
1132 * @internal ICU 49 technology preview
1134 virtual const TimeZoneFormat
* getTimeZoneFormat(void) const;
1137 * Set a particular UDisplayContext value in the formatter, such as
1138 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. Note: For getContext, see
1140 * @param value The UDisplayContext value to set.
1141 * @param status Input/output status. If at entry this indicates a failure
1142 * status, the function will do nothing; otherwise this will be
1143 * updated with any new status from the function.
1146 virtual void setContext(UDisplayContext value
, UErrorCode
& status
);
1149 * Overrides base class method and
1150 * This method clears per field NumberFormat instances
1151 * previously set by {@see adoptNumberFormat(const UnicodeString&, NumberFormat*, UErrorCode)}
1152 * @param formatToAdopt the NumbeferFormat used
1155 void adoptNumberFormat(NumberFormat
*formatToAdopt
);
1158 * Allow the user to set the NumberFormat for several fields
1159 * It can be a single field like: "y"(year) or "M"(month)
1160 * It can be several field combined together: "yM"(year and month)
1162 * 1 symbol field is enough for multiple symbol field (so "y" will override "yy", "yyy")
1163 * If the field is not numeric, then override has no effect (like "MMM" will use abbreviation, not numerical field)
1164 * Per field NumberFormat can also be cleared in {@see DateFormat::setNumberFormat(const NumberFormat& newNumberFormat)}
1166 * @param fields the fields to override(like y)
1167 * @param formatToAdopt the NumbeferFormat used
1168 * @param status Receives a status code, which will be U_ZERO_ERROR
1169 * if the operation succeeds.
1172 void adoptNumberFormat(const UnicodeString
& fields
, NumberFormat
*formatToAdopt
, UErrorCode
&status
);
1175 * Get the numbering system to be used for a particular field.
1176 * @param field The UDateFormatField to get
1179 const NumberFormat
* getNumberFormatForField(char16_t field
) const;
1181 #ifndef U_HIDE_INTERNAL_API
1183 * This is for ICU internal use only. Please do not use.
1184 * Check whether the 'field' is smaller than all the fields covered in
1185 * pattern, return TRUE if it is. The sequence of calendar field,
1186 * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
1187 * @param field the calendar field need to check against
1188 * @return TRUE if the 'field' is smaller than all the fields
1189 * covered in pattern. FALSE otherwise.
1192 UBool
isFieldUnitIgnored(UCalendarDateFields field
) const;
1196 * This is for ICU internal use only. Please do not use.
1197 * Check whether the 'field' is smaller than all the fields covered in
1198 * pattern, return TRUE if it is. The sequence of calendar field,
1199 * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
1200 * @param pattern the pattern to check against
1201 * @param field the calendar field need to check against
1202 * @return TRUE if the 'field' is smaller than all the fields
1203 * covered in pattern. FALSE otherwise.
1206 static UBool
isFieldUnitIgnored(const UnicodeString
& pattern
,
1207 UCalendarDateFields field
);
1210 * This is for ICU internal use only. Please do not use.
1211 * Get the locale of this simple date formatter.
1212 * It is used in DateIntervalFormat.
1214 * @return locale in this simple date formatter
1217 const Locale
& getSmpFmtLocale(void) const;
1221 * This is for ICU internal use only. Please do not use.
1222 * Get the capitalization break iterator of this simple date formatter.
1223 * Should be cloned before using it.
1224 * It is used in udat.
1226 * @return capitalization break iterator
1229 BreakIterator
* getCapitalizationBrkIter(void) const;
1230 #endif /* U_HIDE_INTERNAL_API */
1233 friend class DateFormat
;
1234 friend class DateIntervalFormat
;
1236 void initializeDefaultCentury(void);
1238 void initializeBooleanAttributes(void);
1240 SimpleDateFormat(); // default constructor not implemented
1243 * Used by the DateFormat factory methods to construct a SimpleDateFormat.
1244 * @param timeStyle the time style.
1245 * @param dateStyle the date style.
1246 * @param locale the given locale.
1247 * @param status Output param set to success/failure code on
1250 SimpleDateFormat(EStyle timeStyle
, EStyle dateStyle
, const Locale
& locale
, UErrorCode
& status
);
1253 * Construct a SimpleDateFormat for the given locale. If no resource data
1254 * is available, create an object of last resort, using hard-coded strings.
1255 * This is an internal method, called by DateFormat. It should never fail.
1256 * @param locale the given locale.
1257 * @param status Output param set to success/failure code on
1260 SimpleDateFormat(const Locale
& locale
, UErrorCode
& status
); // Use default pattern
1263 * Hook called by format(... FieldPosition& ...) and format(...FieldPositionIterator&...)
1265 UnicodeString
& _format(Calendar
& cal
, UnicodeString
& appendTo
, FieldPositionHandler
& handler
, UErrorCode
& status
) const;
1268 * Called by format() to format a single field.
1270 * @param appendTo Output parameter to receive result.
1271 * Result is appended to existing contents.
1272 * @param ch The format character we encountered in the pattern.
1273 * @param count Number of characters in the current pattern symbol (e.g.,
1274 * "yyyy" in the pattern would result in a call to this function
1275 * with ch equal to 'y' and count equal to 4)
1276 * @param capitalizationContext Capitalization context for this date format.
1277 * @param fieldNum Zero-based numbering of current field within the overall format.
1278 * @param handler Records information about field positions.
1279 * @param cal Calendar to use
1280 * @param status Receives a status code, which will be U_ZERO_ERROR if the operation
1283 void subFormat(UnicodeString
&appendTo
,
1286 UDisplayContext capitalizationContext
,
1288 FieldPositionHandler
& handler
,
1290 UErrorCode
& status
) const; // in case of illegal argument
1293 * Used by subFormat() to format a numeric value.
1294 * Appends to toAppendTo a string representation of "value"
1295 * having a number of digits between "minDigits" and
1296 * "maxDigits". Uses the DateFormat's NumberFormat.
1298 * @param currentNumberFormat
1299 * @param appendTo Output parameter to receive result.
1300 * Formatted number is appended to existing contents.
1301 * @param value Value to format.
1302 * @param minDigits Minimum number of digits the result should have
1303 * @param maxDigits Maximum number of digits the result should have
1305 void zeroPaddingNumber(const NumberFormat
*currentNumberFormat
,
1306 UnicodeString
&appendTo
,
1309 int32_t maxDigits
) const;
1312 * Return true if the given format character, occuring count
1313 * times, represents a numeric field.
1315 static UBool
isNumeric(char16_t formatChar
, int32_t count
);
1318 * Returns TRUE if the patternOffset is at the start of a numeric field.
1320 static UBool
isAtNumericField(const UnicodeString
&pattern
, int32_t patternOffset
);
1323 * Returns TRUE if the patternOffset is right after a non-numeric field.
1325 static UBool
isAfterNonNumericField(const UnicodeString
&pattern
, int32_t patternOffset
);
1328 * initializes fCalendar from parameters. Returns fCalendar as a convenience.
1329 * @param adoptZone Zone to be adopted, or NULL for TimeZone::createDefault().
1330 * @param locale Locale of the calendar
1331 * @param status Error code
1332 * @return the newly constructed fCalendar
1334 Calendar
*initializeCalendar(TimeZone
* adoptZone
, const Locale
& locale
, UErrorCode
& status
);
1337 * Called by several of the constructors to load pattern data and formatting symbols
1338 * out of a resource bundle and initialize the locale based on it.
1339 * @param timeStyle The time style, as passed to DateFormat::createDateInstance().
1340 * @param dateStyle The date style, as passed to DateFormat::createTimeInstance().
1341 * @param locale The locale to load the patterns from.
1342 * @param status Filled in with an error code if loading the data from the
1345 void construct(EStyle timeStyle
, EStyle dateStyle
, const Locale
& locale
, UErrorCode
& status
);
1348 * Called by construct() and the various constructors to set up the SimpleDateFormat's
1349 * Calendar and NumberFormat objects.
1350 * @param locale The locale for which we want a Calendar and a NumberFormat.
1351 * @param status Filled in with an error code if creating either subobject fails.
1353 void initialize(const Locale
& locale
, UErrorCode
& status
);
1356 * Private code-size reduction function used by subParse.
1357 * @param text the time text being parsed.
1358 * @param start where to start parsing.
1359 * @param field the date field being parsed.
1360 * @param stringArray the string array to parsed.
1361 * @param stringArrayCount the size of the array.
1362 * @param monthPattern pointer to leap month pattern, or NULL if none.
1363 * @param cal a Calendar set to the date and time to be formatted
1364 * into a date/time string.
1365 * @return the new start position if matching succeeded; a negative number
1366 * indicating matching failure, otherwise.
1368 int32_t matchString(const UnicodeString
& text
, int32_t start
, UCalendarDateFields field
,
1369 const UnicodeString
* stringArray
, int32_t stringArrayCount
,
1370 const UnicodeString
* monthPattern
, Calendar
& cal
) const;
1373 * Private code-size reduction function used by subParse.
1374 * @param text the time text being parsed.
1375 * @param start where to start parsing.
1376 * @param field the date field being parsed.
1377 * @param stringArray the string array to parsed.
1378 * @param stringArrayCount the size of the array.
1379 * @param cal a Calendar set to the date and time to be formatted
1380 * into a date/time string.
1381 * @return the new start position if matching succeeded; a negative number
1382 * indicating matching failure, otherwise.
1384 int32_t matchQuarterString(const UnicodeString
& text
, int32_t start
, UCalendarDateFields field
,
1385 const UnicodeString
* stringArray
, int32_t stringArrayCount
, Calendar
& cal
) const;
1388 * Used by subParse() to match localized day period strings.
1390 int32_t matchDayPeriodStrings(const UnicodeString
& text
, int32_t start
,
1391 const UnicodeString
* stringArray
, int32_t stringArrayCount
,
1392 int32_t &dayPeriod
) const;
1395 * Private function used by subParse to match literal pattern text.
1397 * @param pattern the pattern string
1398 * @param patternOffset the starting offset into the pattern text. On
1399 * outupt will be set the offset of the first non-literal character in the pattern
1400 * @param text the text being parsed
1401 * @param textOffset the starting offset into the text. On output
1402 * will be set to the offset of the character after the match
1403 * @param whitespaceLenient <code>TRUE</code> if whitespace parse is lenient, <code>FALSE</code> otherwise.
1404 * @param partialMatchLenient <code>TRUE</code> if partial match parse is lenient, <code>FALSE</code> otherwise.
1405 * @param oldLeniency <code>TRUE</code> if old leniency control is lenient, <code>FALSE</code> otherwise.
1407 * @return <code>TRUE</code> if the literal text could be matched, <code>FALSE</code> otherwise.
1409 static UBool
matchLiterals(const UnicodeString
&pattern
, int32_t &patternOffset
,
1410 const UnicodeString
&text
, int32_t &textOffset
,
1411 UBool whitespaceLenient
, UBool partialMatchLenient
, UBool oldLeniency
);
1414 * Private member function that converts the parsed date strings into
1415 * timeFields. Returns -start (for ParsePosition) if failed.
1416 * @param text the time text to be parsed.
1417 * @param start where to start parsing.
1418 * @param ch the pattern character for the date field text to be parsed.
1419 * @param count the count of a pattern character.
1420 * @param obeyCount if true then the count is strictly obeyed.
1421 * @param allowNegative
1422 * @param ambiguousYear If true then the two-digit year == the default start year.
1423 * @param saveHebrewMonth Used to hang onto month until year is known.
1424 * @param cal a Calendar set to the date and time to be formatted
1425 * into a date/time string.
1427 * @param numericLeapMonthFormatter If non-null, used to parse numeric leap months.
1428 * @param tzTimeType the type of parsed time zone - standard, daylight or unknown (output).
1429 * This parameter can be NULL if caller does not need the information.
1430 * @return the new start position if matching succeeded; a negative number
1431 * indicating matching failure, otherwise.
1433 int32_t subParse(const UnicodeString
& text
, int32_t& start
, char16_t ch
, int32_t count
,
1434 UBool obeyCount
, UBool allowNegative
, UBool ambiguousYear
[], int32_t& saveHebrewMonth
, Calendar
& cal
,
1435 int32_t patLoc
, MessageFormat
* numericLeapMonthFormatter
, UTimeZoneFormatTimeType
*tzTimeType
,
1436 int32_t *dayPeriod
=NULL
) const;
1438 void parseInt(const UnicodeString
& text
,
1439 Formattable
& number
,
1441 UBool allowNegative
,
1442 const NumberFormat
*fmt
) const;
1444 void parseInt(const UnicodeString
& text
,
1445 Formattable
& number
,
1448 UBool allowNegative
,
1449 const NumberFormat
*fmt
) const;
1451 int32_t checkIntSuffix(const UnicodeString
& text
, int32_t start
,
1452 int32_t patLoc
, UBool isNegative
) const;
1455 * Counts number of digit code points in the specified text.
1457 * @param text input text
1458 * @param start start index, inclusive
1459 * @param end end index, exclusive
1460 * @return number of digits found in the text in the specified range.
1462 int32_t countDigits(const UnicodeString
& text
, int32_t start
, int32_t end
) const;
1465 * Translate a pattern, mapping each character in the from string to the
1466 * corresponding character in the to string. Return an error if the original
1467 * pattern contains an unmapped character, or if a quote is unmatched.
1468 * Quoted (single quotes only) material is not translated.
1469 * @param originalPattern the original pattern.
1470 * @param translatedPattern Output param to receive the translited pattern.
1471 * @param from the characters to be translited from.
1472 * @param to the characters to be translited to.
1473 * @param status Receives a status code, which will be U_ZERO_ERROR
1474 * if the operation succeeds.
1476 static void translatePattern(const UnicodeString
& originalPattern
,
1477 UnicodeString
& translatedPattern
,
1478 const UnicodeString
& from
,
1479 const UnicodeString
& to
,
1480 UErrorCode
& status
);
1483 * Sets the starting date of the 100-year window that dates with 2-digit years
1484 * are considered to fall within.
1485 * @param startDate the start date
1486 * @param status Receives a status code, which will be U_ZERO_ERROR
1487 * if the operation succeeds.
1489 void parseAmbiguousDatesAsAfter(UDate startDate
, UErrorCode
& status
);
1492 * Return the length matched by the given affix, or -1 if none.
1493 * Runs of white space in the affix, match runs of white space in
1495 * @param affix pattern string, taken as a literal
1496 * @param input input text
1497 * @param pos offset into input at which to begin matching
1498 * @return length of input that matches, or -1 if match failure
1500 int32_t compareSimpleAffix(const UnicodeString
& affix
,
1501 const UnicodeString
& input
,
1505 * Skip over a run of zero or more Pattern_White_Space characters at
1508 int32_t skipPatternWhiteSpace(const UnicodeString
& text
, int32_t pos
) const;
1511 * Skip over a run of zero or more isUWhiteSpace() characters at pos
1514 int32_t skipUWhiteSpace(const UnicodeString
& text
, int32_t pos
) const;
1517 * Initialize LocalizedNumberFormatter instances used for speedup.
1519 void initFastNumberFormatters(UErrorCode
& status
);
1522 * Delete the LocalizedNumberFormatter instances used for speedup.
1524 void freeFastNumberFormatters();
1527 * Initialize NumberFormat instances used for numbering system overrides.
1529 void initNumberFormatters(const Locale
&locale
,UErrorCode
&status
);
1532 * Parse the given override string and set up structures for number formats
1534 void processOverrideString(const Locale
&locale
, const UnicodeString
&str
, int8_t type
, UErrorCode
&status
);
1537 * Used to map pattern characters to Calendar field identifiers.
1539 static const UCalendarDateFields fgPatternIndexToCalendarField
[];
1542 * Map index into pattern character string to DateFormat field number
1544 static const UDateFormatField fgPatternIndexToDateFormatField
[];
1547 * Lazy TimeZoneFormat instantiation, semantically const
1549 TimeZoneFormat
*tzFormat(UErrorCode
&status
) const;
1551 const NumberFormat
* getNumberFormatByIndex(UDateFormatField index
) const;
1554 * Used to map Calendar field to field level.
1555 * The larger the level, the smaller the field unit.
1556 * For example, UCAL_ERA level is 0, UCAL_YEAR level is 10,
1557 * UCAL_MONTH level is 20.
1559 static const int32_t fgCalendarFieldToLevel
[];
1562 * Map calendar field letter into calendar field level.
1564 static int32_t getLevelFromChar(char16_t ch
);
1567 * Tell if a character can be used to define a field in a format string.
1569 static UBool
isSyntaxChar(char16_t ch
);
1572 * The formatting pattern for this formatter.
1574 UnicodeString fPattern
;
1577 * The numbering system override for dates.
1579 UnicodeString fDateOverride
;
1582 * The numbering system override for times.
1584 UnicodeString fTimeOverride
;
1588 * The original locale used (for reloading symbols)
1593 * A pointer to an object containing the strings to use in formatting (e.g.,
1594 * month and day names, AM and PM strings, time zone names, etc.)
1596 DateFormatSymbols
* fSymbols
; // Owned
1599 * The time zone formatter
1601 TimeZoneFormat
* fTimeZoneFormat
;
1604 * If dates have ambiguous years, we map them into the century starting
1605 * at defaultCenturyStart, which may be any date. If defaultCenturyStart is
1606 * set to SYSTEM_DEFAULT_CENTURY, which it is by default, then the system
1607 * values are used. The instance values defaultCenturyStart and
1608 * defaultCenturyStartYear are only used if explicitly set by the user
1609 * through the API method parseAmbiguousDatesAsAfter().
1611 UDate fDefaultCenturyStart
;
1615 UBool fHasHanYearChar
; // pattern contains the Han year character \u5E74
1618 * Sets fHasMinutes and fHasSeconds.
1620 void parsePattern();
1623 * See documentation for defaultCenturyStart.
1625 /*transient*/ int32_t fDefaultCenturyStartYear
;
1627 struct NSOverride
: public UMemory
{
1628 const SharedNumberFormat
*snf
;
1632 NSOverride() : snf(NULL
), hash(0), next(NULL
) {
1638 * The number format in use for each date field. NULL means fall back
1639 * to fNumberFormat in DateFormat.
1641 const SharedNumberFormat
**fSharedNumberFormatters
;
1643 enum NumberFormatterKey
{
1653 * Number formatters pre-allocated for fast performance on the most common integer lengths.
1655 const number::LocalizedNumberFormatter
* fFastNumberFormatters
[SMPDTFMT_NF_COUNT
] = {};
1657 UBool fHaveDefaultCentury
;
1659 BreakIterator
* fCapitalizationBrkIter
;
1663 SimpleDateFormat::get2DigitYearStart(UErrorCode
& /*status*/) const
1665 return fDefaultCenturyStart
;
1668 inline BreakIterator
*
1669 SimpleDateFormat::getCapitalizationBrkIter() const
1671 return fCapitalizationBrkIter
;
1675 #endif // U_SHOW_CPLUSPLUS_API
1677 #endif /* #if !UCONFIG_NO_FORMATTING */