2 * Copyright (C) 1997-2016, International Business Machines Corporation and
3 * others. All Rights Reserved.
4 *******************************************************************************
8 * Modification History:
10 * Date Name Description
11 * 02/19/97 aliu Converted from java.
12 * 07/09/97 helena Make ParsePosition into a class.
13 * 07/21/98 stephen Added GMT_PLUS, GMT_MINUS
14 * Changed setTwoDigitStartDate to set2DigitYearStart
15 * Changed getTwoDigitStartDate to get2DigitYearStart
16 * Removed subParseLong
17 * Removed getZoneIndex (added in DateFormatSymbols)
18 * 06/14/99 stephen Removed fgTimeZoneDataSuffix
19 * 10/14/99 aliu Updated class doc to describe 2-digit year parsing
21 *******************************************************************************
27 #include "unicode/utypes.h"
31 * \brief C++ API: Format and parse dates in a language-independent manner.
34 #if !UCONFIG_NO_FORMATTING
36 #include "unicode/datefmt.h"
37 #include "unicode/udisplaycontext.h"
38 #include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */
39 #include "unicode/brkiter.h"
43 class DateFormatSymbols
;
46 class FieldPositionHandler
;
48 class SharedNumberFormat
;
49 class SimpleDateFormatMutableNFs
;
53 * SimpleDateFormat is a concrete class for formatting and parsing dates in a
54 * language-independent manner. It allows for formatting (millis -> text),
55 * parsing (text -> millis), and normalization. Formats/Parses a date or time,
56 * which is the standard milliseconds since 24:00 GMT, Jan 1, 1970.
58 * Clients are encouraged to create a date-time formatter using DateFormat::getInstance(),
59 * getDateInstance(), getDateInstance(), or getDateTimeInstance() rather than
60 * explicitly constructing an instance of SimpleDateFormat. This way, the client
61 * is guaranteed to get an appropriate formatting pattern for whatever locale the
62 * program is running in. However, if the client needs something more unusual than
63 * the default patterns in the locales, he can construct a SimpleDateFormat directly
64 * and give it an appropriate pattern (or use one of the factory methods on DateFormat
65 * and modify the pattern after the fact with toPattern() and applyPattern().
67 * <p><strong>Date and Time Patterns:</strong></p>
69 * <p>Date and time formats are specified by <em>date and time pattern</em> strings.
70 * Within date and time pattern strings, all unquoted ASCII letters [A-Za-z] are reserved
71 * as pattern letters representing calendar fields. <code>SimpleDateFormat</code> supports
72 * the date and time formatting algorithm and pattern letters defined by
73 * <a href="http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table">UTS#35
74 * Unicode Locale Data Markup Language (LDML)</a> and further documented for ICU in the
75 * <a href="https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table">ICU
76 * User Guide</a>. The following pattern letters are currently available (note that the actual
77 * values depend on CLDR and may change from the examples shown here):</p>
82 * <th style="text-align: center">Sym.</th>
83 * <th style="text-align: center">No.</th>
85 * <th>Description</th>
88 * <th rowspan="3">era</th>
89 * <td style="text-align: center" rowspan="3">G</td>
90 * <td style="text-align: center">1..3</td>
92 * <td rowspan="3">Era - Replaced with the Era string for the current date. One to three letters for the
93 * abbreviated form, four letters for the long (wide) form, five for the narrow form.</td>
96 * <td style="text-align: center">4</td>
97 * <td>Anno Domini</td>
100 * <td style="text-align: center">5</td>
104 * <th rowspan="6">year</th>
105 * <td style="text-align: center">y</td>
106 * <td style="text-align: center">1..n</td>
108 * <td>Year. Normally the length specifies the padding, but for two letters it also specifies the maximum
109 * length. Example:<div align="center">
111 * <table border="1" cellpadding="2" cellspacing="0">
114 * <th style="text-align: right">y</th>
115 * <th style="text-align: right">yy</th>
116 * <th style="text-align: right">yyy</th>
117 * <th style="text-align: right">yyyy</th>
118 * <th style="text-align: right">yyyyy</th>
122 * <td style="text-align: right">1</td>
123 * <td style="text-align: right">01</td>
124 * <td style="text-align: right">001</td>
125 * <td style="text-align: right">0001</td>
126 * <td style="text-align: right">00001</td>
130 * <td style="text-align: right">12</td>
131 * <td style="text-align: right">12</td>
132 * <td style="text-align: right">012</td>
133 * <td style="text-align: right">0012</td>
134 * <td style="text-align: right">00012</td>
138 * <td style="text-align: right">123</td>
139 * <td style="text-align: right">23</td>
140 * <td style="text-align: right">123</td>
141 * <td style="text-align: right">0123</td>
142 * <td style="text-align: right">00123</td>
146 * <td style="text-align: right">1234</td>
147 * <td style="text-align: right">34</td>
148 * <td style="text-align: right">1234</td>
149 * <td style="text-align: right">1234</td>
150 * <td style="text-align: right">01234</td>
154 * <td style="text-align: right">12345</td>
155 * <td style="text-align: right">45</td>
156 * <td style="text-align: right">12345</td>
157 * <td style="text-align: right">12345</td>
158 * <td style="text-align: right">12345</td>
165 * <td style="text-align: center">Y</td>
166 * <td style="text-align: center">1..n</td>
168 * <td>Year (in "Week of Year" based calendars). Normally the length specifies the padding,
169 * but for two letters it also specifies the maximum length. This year designation is used in ISO
170 * year-week calendar as defined by ISO 8601, but can be used in non-Gregorian based calendar systems
171 * where week date processing is desired. May not always be the same value as calendar year.</td>
174 * <td style="text-align: center">u</td>
175 * <td style="text-align: center">1..n</td>
177 * <td>Extended year. This is a single number designating the year of this calendar system, encompassing
178 * all supra-year fields. For example, for the Julian calendar system, year numbers are positive, with an
179 * era of BCE or CE. An extended year value for the Julian calendar system assigns positive values to CE
180 * years and negative values to BCE years, with 1 BCE being year 0.</td>
183 * <td style="text-align: center" rowspan="3">U</td>
184 * <td style="text-align: center">1..3</td>
185 * <td>甲子</td>
186 * <td rowspan="3">Cyclic year name. Calendars such as the Chinese lunar calendar (and related calendars)
187 * and the Hindu calendars use 60-year cycles of year names. Use one through three letters for the abbreviated
188 * name, four for the full (wide) name, or five for the narrow name (currently the data only provides abbreviated names,
189 * which will be used for all requested name widths). If the calendar does not provide cyclic year name data,
190 * or if the year value to be formatted is out of the range of years for which cyclic name data is provided,
191 * then numeric formatting is used (behaves like 'y').</td>
194 * <td style="text-align: center">4</td>
195 * <td>(currently also 甲子)</td>
198 * <td style="text-align: center">5</td>
199 * <td>(currently also 甲子)</td>
202 * <th rowspan="6">quarter</th>
203 * <td rowspan="3" style="text-align: center">Q</td>
204 * <td style="text-align: center">1..2</td>
206 * <td rowspan="3">Quarter - Use one or two for the numerical quarter, three for the abbreviation, or four for the
207 * full (wide) name (five for the narrow name is not yet supported).</td>
210 * <td style="text-align: center">3</td>
214 * <td style="text-align: center">4</td>
215 * <td>2nd quarter</td>
218 * <td rowspan="3" style="text-align: center">q</td>
219 * <td style="text-align: center">1..2</td>
221 * <td rowspan="3"><b>Stand-Alone</b> Quarter - Use one or two for the numerical quarter, three for the abbreviation,
222 * or four for the full name (five for the narrow name is not yet supported).</td>
225 * <td style="text-align: center">3</td>
229 * <td style="text-align: center">4</td>
230 * <td>2nd quarter</td>
233 * <th rowspan="8">month</th>
234 * <td rowspan="4" style="text-align: center">M</td>
235 * <td style="text-align: center">1..2</td>
237 * <td rowspan="4">Month - Use one or two for the numerical month, three for the abbreviation, four for
238 * the full (wide) name, or five for the narrow name. With two ("MM"), the month number is zero-padded
239 * if necessary (e.g. "08")</td>
242 * <td style="text-align: center">3</td>
246 * <td style="text-align: center">4</td>
250 * <td style="text-align: center">5</td>
254 * <td rowspan="4" style="text-align: center">L</td>
255 * <td style="text-align: center">1..2</td>
257 * <td rowspan="4"><b>Stand-Alone</b> Month - Use one or two for the numerical month, three for the abbreviation,
258 * four for the full (wide) name, or 5 for the narrow name. With two ("LL"), the month number is zero-padded if
259 * necessary (e.g. "08")</td>
262 * <td style="text-align: center">3</td>
266 * <td style="text-align: center">4</td>
270 * <td style="text-align: center">5</td>
274 * <th rowspan="2">week</th>
275 * <td style="text-align: center">w</td>
276 * <td style="text-align: center">1..2</td>
278 * <td>Week of Year. Use "w" to show the minimum number of digits, or "ww" to always show two digits
279 * (zero-padding if necessary, e.g. "08").</td>
282 * <td style="text-align: center">W</td>
283 * <td style="text-align: center">1</td>
285 * <td>Week of Month</td>
288 * <th rowspan="4">day</th>
289 * <td style="text-align: center">d</td>
290 * <td style="text-align: center">1..2</td>
292 * <td>Date - Day of the month. Use "d" to show the minimum number of digits, or "dd" to always show
293 * two digits (zero-padding if necessary, e.g. "08").</td>
296 * <td style="text-align: center">D</td>
297 * <td style="text-align: center">1..3</td>
299 * <td>Day of year</td>
302 * <td style="text-align: center">F</td>
303 * <td style="text-align: center">1</td>
305 * <td>Day of Week in Month. The example is for the 2nd Wed in July</td>
308 * <td style="text-align: center">g</td>
309 * <td style="text-align: center">1..n</td>
311 * <td>Modified Julian day. This is different from the conventional Julian day number in two regards.
312 * First, it demarcates days at local zone midnight, rather than noon GMT. Second, it is a local number;
313 * that is, it depends on the local time zone. It can be thought of as a single number that encompasses
314 * all the date-related fields.</td>
317 * <th rowspan="14">week<br>
319 * <td rowspan="4" style="text-align: center">E</td>
320 * <td style="text-align: center">1..3</td>
322 * <td rowspan="4">Day of week - Use one through three letters for the short day, four for the full (wide) name,
323 * five for the narrow name, or six for the short name.</td>
326 * <td style="text-align: center">4</td>
330 * <td style="text-align: center">5</td>
334 * <td style="text-align: center">6</td>
338 * <td rowspan="5" style="text-align: center">e</td>
339 * <td style="text-align: center">1..2</td>
341 * <td rowspan="5">Local day of week. Same as E except adds a numeric value that will depend on the local
342 * starting day of the week, using one or two letters. For this example, Monday is the first day of the week.</td>
345 * <td style="text-align: center">3</td>
349 * <td style="text-align: center">4</td>
353 * <td style="text-align: center">5</td>
357 * <td style="text-align: center">6</td>
361 * <td rowspan="5" style="text-align: center">c</td>
362 * <td style="text-align: center">1</td>
364 * <td rowspan="5"><b>Stand-Alone</b> local day of week - Use one letter for the local numeric value (same
365 * as 'e'), three for the short day, four for the full (wide) name, five for the narrow name, or six for
366 * the short name.</td>
369 * <td style="text-align: center">3</td>
373 * <td style="text-align: center">4</td>
377 * <td style="text-align: center">5</td>
381 * <td style="text-align: center">6</td>
386 * <td style="text-align: center">a</td>
387 * <td style="text-align: center">1</td>
392 * <th rowspan="4">hour</th>
393 * <td style="text-align: center">h</td>
394 * <td style="text-align: center">1..2</td>
396 * <td>Hour [1-12]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern
397 * generation, it should match the 12-hour-cycle format preferred by the locale (h or K); it should not match
398 * a 24-hour-cycle format (H or k). Use hh for zero padding.</td>
401 * <td style="text-align: center">H</td>
402 * <td style="text-align: center">1..2</td>
404 * <td>Hour [0-23]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern
405 * generation, it should match the 24-hour-cycle format preferred by the locale (H or k); it should not match a
406 * 12-hour-cycle format (h or K). Use HH for zero padding.</td>
409 * <td style="text-align: center">K</td>
410 * <td style="text-align: center">1..2</td>
412 * <td>Hour [0-11]. When used in a skeleton, only matches K or h, see above. Use KK for zero padding.</td>
415 * <td style="text-align: center">k</td>
416 * <td style="text-align: center">1..2</td>
418 * <td>Hour [1-24]. When used in a skeleton, only matches k or H, see above. Use kk for zero padding.</td>
422 * <td style="text-align: center">m</td>
423 * <td style="text-align: center">1..2</td>
425 * <td>Minute. Use "m" to show the minimum number of digits, or "mm" to always show two digits
426 * (zero-padding if necessary, e.g. "08").</td>
429 * <th rowspan="3">second</th>
430 * <td style="text-align: center">s</td>
431 * <td style="text-align: center">1..2</td>
433 * <td>Second. Use "s" to show the minimum number of digits, or "ss" to always show two digits
434 * (zero-padding if necessary, e.g. "08").</td>
437 * <td style="text-align: center">S</td>
438 * <td style="text-align: center">1..n</td>
440 * <td>Fractional Second - truncates (like other time fields) to the count of letters when formatting.
441 * Appends zeros if more than 3 letters specified. Truncates at three significant digits when parsing.
442 * (example shows display using pattern SSSS for seconds value 12.34567)</td>
445 * <td style="text-align: center">A</td>
446 * <td style="text-align: center">1..n</td>
448 * <td>Milliseconds in day. This field behaves <i>exactly</i> like a composite of all time-related fields,
449 * not including the zone fields. As such, it also reflects discontinuities of those fields on DST transition
450 * days. On a day of DST onset, it will jump forward. On a day of DST cessation, it will jump backward. This
451 * reflects the fact that is must be combined with the offset field to obtain a unique local time value.</td>
454 * <th rowspan="23">zone</th>
455 * <td rowspan="2" style="text-align: center">z</td>
456 * <td style="text-align: center">1..3</td>
458 * <td>The <i>short specific non-location format</i>.
459 * Where that is unavailable, falls back to the <i>short localized GMT format</i> ("O").</td>
462 * <td style="text-align: center">4</td>
463 * <td>Pacific Daylight Time</td>
464 * <td>The <i>long specific non-location format</i>.
465 * Where that is unavailable, falls back to the <i>long localized GMT format</i> ("OOOO").</td>
468 * <td rowspan="3" style="text-align: center">Z</td>
469 * <td style="text-align: center">1..3</td>
471 * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
472 * The format is equivalent to RFC 822 zone format (when optional seconds field is absent).
473 * This is equivalent to the "xxxx" specifier.</td>
476 * <td style="text-align: center">4</td>
478 * <td>The <i>long localized GMT format</i>.
479 * This is equivalent to the "OOOO" specifier.</td>
482 * <td style="text-align: center">5</td>
485 * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
486 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.
487 * This is equivalent to the "XXXXX" specifier.</td>
490 * <td rowspan="2" style="text-align: center">O</td>
491 * <td style="text-align: center">1</td>
493 * <td>The <i>short localized GMT format</i>.</td>
496 * <td style="text-align: center">4</td>
498 * <td>The <i>long localized GMT format</i>.</td>
501 * <td rowspan="2" style="text-align: center">v</td>
502 * <td style="text-align: center">1</td>
504 * <td>The <i>short generic non-location format</i>.
505 * Where that is unavailable, falls back to the <i>generic location format</i> ("VVVV"),
506 * then the <i>short localized GMT format</i> as the final fallback.</td>
509 * <td style="text-align: center">4</td>
510 * <td>Pacific Time</td>
511 * <td>The <i>long generic non-location format</i>.
512 * Where that is unavailable, falls back to <i>generic location format</i> ("VVVV").
515 * <td rowspan="4" style="text-align: center">V</td>
516 * <td style="text-align: center">1</td>
518 * <td>The short time zone ID.
519 * Where that is unavailable, the special short time zone ID <i>unk</i> (Unknown Zone) is used.<br>
520 * <i><b>Note</b>: This specifier was originally used for a variant of the short specific non-location format,
521 * but it was deprecated in the later version of the LDML specification. In CLDR 23/ICU 51, the definition of
522 * the specifier was changed to designate a short time zone ID.</i></td>
525 * <td style="text-align: center">2</td>
526 * <td>America/Los_Angeles</td>
527 * <td>The long time zone ID.</td>
530 * <td style="text-align: center">3</td>
531 * <td>Los Angeles</td>
532 * <td>The exemplar city (location) for the time zone.
533 * Where that is unavailable, the localized exemplar city name for the special zone <i>Etc/Unknown</i> is used
534 * as the fallback (for example, "Unknown City"). </td>
537 * <td style="text-align: center">4</td>
538 * <td>Los Angeles Time</td>
539 * <td>The <i>generic location format</i>.
540 * Where that is unavailable, falls back to the <i>long localized GMT format</i> ("OOOO";
541 * Note: Fallback is only necessary with a GMT-style Time Zone ID, like Etc/GMT-830.)<br>
542 * This is especially useful when presenting possible timezone choices for user selection,
543 * since the naming is more uniform than the "v" format.</td>
546 * <td rowspan="5" style="text-align: center">X</td>
547 * <td style="text-align: center">1</td>
551 * <td>The <i>ISO8601 basic format</i> with hours field and optional minutes field.
552 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
555 * <td style="text-align: center">2</td>
558 * <td>The <i>ISO8601 basic format</i> with hours and minutes fields.
559 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
562 * <td style="text-align: center">3</td>
565 * <td>The <i>ISO8601 extended format</i> with hours and minutes fields.
566 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
569 * <td style="text-align: center">4</td>
573 * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
574 * (Note: The seconds field is not supported by the ISO8601 specification.)
575 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
578 * <td style="text-align: center">5</td>
582 * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
583 * (Note: The seconds field is not supported by the ISO8601 specification.)
584 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
587 * <td rowspan="5" style="text-align: center">x</td>
588 * <td style="text-align: center">1</td>
591 * <td>The <i>ISO8601 basic format</i> with hours field and optional minutes field.</td>
594 * <td style="text-align: center">2</td>
596 * <td>The <i>ISO8601 basic format</i> with hours and minutes fields.</td>
599 * <td style="text-align: center">3</td>
601 * <td>The <i>ISO8601 extended format</i> with hours and minutes fields.</td>
604 * <td style="text-align: center">4</td>
607 * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
608 * (Note: The seconds field is not supported by the ISO8601 specification.)</td>
611 * <td style="text-align: center">5</td>
614 * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
615 * (Note: The seconds field is not supported by the ISO8601 specification.)</td>
620 * Any characters in the pattern that are not in the ranges of ['a'..'z'] and
621 * ['A'..'Z'] will be treated as quoted text. For instance, characters
622 * like ':', '.', ' ', '#' and '@' will appear in the resulting time text
623 * even they are not embraced within single quotes.
625 * A pattern containing any invalid pattern letter will result in a failing
626 * UErrorCode result during formatting or parsing.
628 * Examples using the US locale:
631 * Format Pattern Result
632 * -------------- -------
633 * "yyyy.MM.dd G 'at' HH:mm:ss vvvv" ->> 1996.07.10 AD at 15:08:56 Pacific Time
634 * "EEE, MMM d, ''yy" ->> Wed, July 10, '96
635 * "h:mm a" ->> 12:08 PM
636 * "hh 'o''clock' a, zzzz" ->> 12 o'clock PM, Pacific Daylight Time
637 * "K:mm a, vvv" ->> 0:00 PM, PT
638 * "yyyyy.MMMMM.dd GGG hh:mm aaa" ->> 1996.July.10 AD 12:08 PM
644 * UErrorCode success = U_ZERO_ERROR;
645 * SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "PST");
646 * pdt->setStartRule( Calendar::APRIL, 1, Calendar::SUNDAY, 2*60*60*1000);
647 * pdt->setEndRule( Calendar::OCTOBER, -1, Calendar::SUNDAY, 2*60*60*1000);
649 * // Format the current time.
650 * SimpleDateFormat* formatter
651 * = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz", success );
652 * GregorianCalendar cal(success);
653 * UDate currentTime_1 = cal.getTime(success);
654 * FieldPosition fp(0);
655 * UnicodeString dateString;
656 * formatter->format( currentTime_1, dateString, fp );
657 * cout << "result: " << dateString << endl;
659 * // Parse the previous string back into a Date.
660 * ParsePosition pp(0);
661 * UDate currentTime_2 = formatter->parse(dateString, pp );
664 * In the above example, the time value "currentTime_2" obtained from parsing
665 * will be equal to currentTime_1. However, they may not be equal if the am/pm
666 * marker 'a' is left out from the format pattern while the "hour in am/pm"
667 * pattern symbol is used. This information loss can happen when formatting the
671 * When parsing a date string using the abbreviated year pattern ("y" or "yy"),
672 * SimpleDateFormat must interpret the abbreviated year
673 * relative to some century. It does this by adjusting dates to be
674 * within 80 years before and 20 years after the time the SimpleDateFormat
675 * instance is created. For example, using a pattern of "MM/dd/yy" and a
676 * SimpleDateFormat instance created on Jan 1, 1997, the string
677 * "01/11/12" would be interpreted as Jan 11, 2012 while the string "05/04/64"
678 * would be interpreted as May 4, 1964.
679 * During parsing, only strings consisting of exactly two digits, as defined by
680 * <code>Unicode::isDigit()</code>, will be parsed into the default century.
681 * Any other numeric string, such as a one digit string, a three or more digit
682 * string, or a two digit string that isn't all digits (for example, "-1"), is
683 * interpreted literally. So "01/02/3" or "01/02/003" are parsed (for the
684 * Gregorian calendar), using the same pattern, as Jan 2, 3 AD. Likewise (but
685 * only in lenient parse mode, the default) "01/02/-3" is parsed as Jan 2, 4 BC.
688 * If the year pattern has more than two 'y' characters, the year is
689 * interpreted literally, regardless of the number of digits. So using the
690 * pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
693 * When numeric fields abut one another directly, with no intervening delimiter
694 * characters, they constitute a run of abutting numeric fields. Such runs are
695 * parsed specially. For example, the format "HHmmss" parses the input text
696 * "123456" to 12:34:56, parses the input text "12345" to 1:23:45, and fails to
697 * parse "1234". In other words, the leftmost field of the run is flexible,
698 * while the others keep a fixed width. If the parse fails anywhere in the run,
699 * then the leftmost field is shortened by one character, and the entire run is
700 * parsed again. This is repeated until either the parse succeeds or the
701 * leftmost field is one character in length. If the parse still fails at that
702 * point, the parse of the run fails.
705 * For time zones that have no names, SimpleDateFormat uses strings GMT+hours:minutes or
708 * The calendar defines what is the first day of the week, the first week of the
709 * year, whether hours are zero based or not (0 vs 12 or 24), and the timezone.
710 * There is one common number format to handle all the numbers; the digit count
711 * is handled programmatically according to the pattern.
713 * <p><em>User subclasses are not supported.</em> While clients may write
714 * subclasses, such code will not necessarily work and will not be
715 * guaranteed to work stably from release to release.
717 class U_I18N_API SimpleDateFormat
: public DateFormat
{
720 * Construct a SimpleDateFormat using the default pattern for the default
723 * [Note:] Not all locales support SimpleDateFormat; for full generality,
724 * use the factory methods in the DateFormat class.
725 * @param status Output param set to success/failure code.
728 SimpleDateFormat(UErrorCode
& status
);
731 * Construct a SimpleDateFormat using the given pattern and the default locale.
732 * The locale is used to obtain the symbols used in formatting (e.g., the
733 * names of the months), but not to provide the pattern.
735 * [Note:] Not all locales support SimpleDateFormat; for full generality,
736 * use the factory methods in the DateFormat class.
737 * @param pattern the pattern for the format.
738 * @param status Output param set to success/failure code.
741 SimpleDateFormat(const UnicodeString
& pattern
,
745 * Construct a SimpleDateFormat using the given pattern, numbering system override, and the default locale.
746 * The locale is used to obtain the symbols used in formatting (e.g., the
747 * names of the months), but not to provide the pattern.
749 * A numbering system override is a string containing either the name of a known numbering system,
750 * or a set of field and numbering system pairs that specify which fields are to be formattied with
751 * the alternate numbering system. For example, to specify that all numeric fields in the specified
752 * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
753 * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering,
754 * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon
755 * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
758 * [Note:] Not all locales support SimpleDateFormat; for full generality,
759 * use the factory methods in the DateFormat class.
760 * @param pattern the pattern for the format.
761 * @param override the override string.
762 * @param status Output param set to success/failure code.
765 SimpleDateFormat(const UnicodeString
& pattern
,
766 const UnicodeString
& override
,
770 * Construct a SimpleDateFormat using the given pattern and locale.
771 * The locale is used to obtain the symbols used in formatting (e.g., the
772 * names of the months), but not to provide the pattern.
774 * [Note:] Not all locales support SimpleDateFormat; for full generality,
775 * use the factory methods in the DateFormat class.
776 * @param pattern the pattern for the format.
777 * @param locale the given locale.
778 * @param status Output param set to success/failure code.
781 SimpleDateFormat(const UnicodeString
& pattern
,
782 const Locale
& locale
,
786 * Construct a SimpleDateFormat using the given pattern, numbering system override, and locale.
787 * The locale is used to obtain the symbols used in formatting (e.g., the
788 * names of the months), but not to provide the pattern.
790 * A numbering system override is a string containing either the name of a known numbering system,
791 * or a set of field and numbering system pairs that specify which fields are to be formattied with
792 * the alternate numbering system. For example, to specify that all numeric fields in the specified
793 * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
794 * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering,
795 * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon
796 * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
798 * [Note:] Not all locales support SimpleDateFormat; for full generality,
799 * use the factory methods in the DateFormat class.
800 * @param pattern the pattern for the format.
801 * @param override the numbering system override.
802 * @param locale the given locale.
803 * @param status Output param set to success/failure code.
806 SimpleDateFormat(const UnicodeString
& pattern
,
807 const UnicodeString
& override
,
808 const Locale
& locale
,
812 * Construct a SimpleDateFormat using the given pattern and locale-specific
813 * symbol data. The formatter takes ownership of the DateFormatSymbols object;
814 * the caller is no longer responsible for deleting it.
815 * @param pattern the given pattern for the format.
816 * @param formatDataToAdopt the symbols to be adopted.
817 * @param status Output param set to success/faulure code.
820 SimpleDateFormat(const UnicodeString
& pattern
,
821 DateFormatSymbols
* formatDataToAdopt
,
825 * Construct a SimpleDateFormat using the given pattern and locale-specific
826 * symbol data. The DateFormatSymbols object is NOT adopted; the caller
827 * remains responsible for deleting it.
828 * @param pattern the given pattern for the format.
829 * @param formatData the formatting symbols to be use.
830 * @param status Output param set to success/faulure code.
833 SimpleDateFormat(const UnicodeString
& pattern
,
834 const DateFormatSymbols
& formatData
,
841 SimpleDateFormat(const SimpleDateFormat
&);
844 * Assignment operator.
847 SimpleDateFormat
& operator=(const SimpleDateFormat
&);
853 virtual ~SimpleDateFormat();
856 * Clone this Format object polymorphically. The caller owns the result and
857 * should delete it when done.
858 * @return A copy of the object.
861 virtual Format
* clone(void) const;
864 * Return true if the given Format objects are semantically equal. Objects
865 * of different subclasses are considered unequal.
866 * @param other the object to be compared with.
867 * @return true if the given Format objects are semantically equal.
870 virtual UBool
operator==(const Format
& other
) const;
873 using DateFormat::format
;
876 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
877 * 1, 1970. Overrides DateFormat pure virtual method.
879 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
880 * 1996.07.10 AD at 15:08:56 PDT
882 * @param cal Calendar set to the date and time to be formatted
883 * into a date/time string.
884 * @param appendTo Output parameter to receive result.
885 * Result is appended to existing contents.
886 * @param pos The formatting position. On input: an alignment field,
887 * if desired. On output: the offsets of the alignment field.
888 * @return Reference to 'appendTo' parameter.
891 virtual UnicodeString
& format( Calendar
& cal
,
892 UnicodeString
& appendTo
,
893 FieldPosition
& pos
) const;
896 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
897 * 1, 1970. Overrides DateFormat pure virtual method.
899 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
900 * 1996.07.10 AD at 15:08:56 PDT
902 * @param cal Calendar set to the date and time to be formatted
903 * into a date/time string.
904 * @param appendTo Output parameter to receive result.
905 * Result is appended to existing contents.
906 * @param posIter On return, can be used to iterate over positions
907 * of fields generated by this format call. Field values
908 * are defined in UDateFormatField.
909 * @param status Input/output param set to success/failure code.
910 * @return Reference to 'appendTo' parameter.
913 virtual UnicodeString
& format( Calendar
& cal
,
914 UnicodeString
& appendTo
,
915 FieldPositionIterator
* posIter
,
916 UErrorCode
& status
) const;
918 using DateFormat::parse
;
921 * Parse a date/time string beginning at the given parse position. For
922 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
923 * that is equivalent to Date(837039928046).
925 * By default, parsing is lenient: If the input is not in the form used by
926 * this object's format method but can still be parsed as a date, then the
927 * parse succeeds. Clients may insist on strict adherence to the format by
928 * calling setLenient(false).
929 * @see DateFormat::setLenient(boolean)
931 * @param text The date/time string to be parsed
932 * @param cal A Calendar set on input to the date and time to be used for
933 * missing values in the date/time string being parsed, and set
934 * on output to the parsed date/time. When the calendar type is
935 * different from the internal calendar held by this SimpleDateFormat
936 * instance, the internal calendar will be cloned to a work
937 * calendar set to the same milliseconds and time zone as the
938 * cal parameter, field values will be parsed based on the work
939 * calendar, then the result (milliseconds and time zone) will
940 * be set in this calendar.
941 * @param pos On input, the position at which to start parsing; on
942 * output, the position at which parsing terminated, or the
943 * start position if the parse failed.
946 virtual void parse( const UnicodeString
& text
,
948 ParsePosition
& pos
) const;
952 * Set the start UDate used to interpret two-digit year strings.
953 * When dates are parsed having 2-digit year strings, they are placed within
954 * a assumed range of 100 years starting on the two digit start date. For
955 * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
956 * some other year. SimpleDateFormat chooses a year so that the resultant
957 * date is on or after the two digit start date and within 100 years of the
958 * two digit start date.
960 * By default, the two digit start date is set to 80 years before the current
961 * time at which a SimpleDateFormat object is created.
962 * @param d start UDate used to interpret two-digit year strings.
963 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
964 * an error value if there was a parse error.
967 virtual void set2DigitYearStart(UDate d
, UErrorCode
& status
);
970 * Get the start UDate used to interpret two-digit year strings.
971 * When dates are parsed having 2-digit year strings, they are placed within
972 * a assumed range of 100 years starting on the two digit start date. For
973 * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
974 * some other year. SimpleDateFormat chooses a year so that the resultant
975 * date is on or after the two digit start date and within 100 years of the
976 * two digit start date.
978 * By default, the two digit start date is set to 80 years before the current
979 * time at which a SimpleDateFormat object is created.
980 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
981 * an error value if there was a parse error.
984 UDate
get2DigitYearStart(UErrorCode
& status
) const;
987 * Return a pattern string describing this date format.
988 * @param result Output param to receive the pattern.
989 * @return A reference to 'result'.
992 virtual UnicodeString
& toPattern(UnicodeString
& result
) const;
995 * Return a localized pattern string describing this date format.
996 * In most cases, this will return the same thing as toPattern(),
997 * but a locale can specify characters to use in pattern descriptions
998 * in place of the ones described in this class's class documentation.
999 * (Presumably, letters that would be more mnemonic in that locale's
1000 * language.) This function would produce a pattern using those
1003 * @param result Receives the localized pattern.
1004 * @param status Output param set to success/failure code on
1005 * exit. If the pattern is invalid, this will be
1006 * set to a failure result.
1007 * @return A reference to 'result'.
1010 virtual UnicodeString
& toLocalizedPattern(UnicodeString
& result
,
1011 UErrorCode
& status
) const;
1014 * Apply the given unlocalized pattern string to this date format.
1015 * (i.e., after this call, this formatter will format dates according to
1018 * @param pattern The pattern to be applied.
1021 virtual void applyPattern(const UnicodeString
& pattern
);
1024 * Apply the given localized pattern string to this date format.
1025 * (see toLocalizedPattern() for more information on localized patterns.)
1027 * @param pattern The localized pattern to be applied.
1028 * @param status Output param set to success/failure code on
1029 * exit. If the pattern is invalid, this will be
1030 * set to a failure result.
1033 virtual void applyLocalizedPattern(const UnicodeString
& pattern
,
1034 UErrorCode
& status
);
1037 * Gets the date/time formatting symbols (this is an object carrying
1038 * the various strings and other symbols used in formatting: e.g., month
1039 * names and abbreviations, time zone names, AM/PM strings, etc.)
1040 * @return a copy of the date-time formatting data associated
1041 * with this date-time formatter.
1044 virtual const DateFormatSymbols
* getDateFormatSymbols(void) const;
1047 * Set the date/time formatting symbols. The caller no longer owns the
1048 * DateFormatSymbols object and should not delete it after making this call.
1049 * @param newFormatSymbols the given date-time formatting symbols to copy.
1052 virtual void adoptDateFormatSymbols(DateFormatSymbols
* newFormatSymbols
);
1055 * Set the date/time formatting data.
1056 * @param newFormatSymbols the given date-time formatting symbols to copy.
1059 virtual void setDateFormatSymbols(const DateFormatSymbols
& newFormatSymbols
);
1062 * Return the class ID for this class. This is useful only for comparing to
1063 * a return value from getDynamicClassID(). For example:
1065 * . Base* polymorphic_pointer = createPolymorphicObject();
1066 * . if (polymorphic_pointer->getDynamicClassID() ==
1067 * . erived::getStaticClassID()) ...
1069 * @return The class ID for all objects of this class.
1072 static UClassID U_EXPORT2
getStaticClassID(void);
1075 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
1076 * method is to implement a simple version of RTTI, since not all C++
1077 * compilers support genuine RTTI. Polymorphic operator==() and clone()
1078 * methods call this method.
1080 * @return The class ID for this object. All objects of a
1081 * given class have the same class ID. Objects of
1082 * other classes have different class IDs.
1085 virtual UClassID
getDynamicClassID(void) const;
1088 * Set the calendar to be used by this date format. Initially, the default
1089 * calendar for the specified or default locale is used. The caller should
1090 * not delete the Calendar object after it is adopted by this call.
1091 * Adopting a new calendar will change to the default symbols.
1093 * @param calendarToAdopt Calendar object to be adopted.
1096 virtual void adoptCalendar(Calendar
* calendarToAdopt
);
1098 /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
1100 * Sets the TimeZoneFormat to be used by this date/time formatter.
1101 * The caller should not delete the TimeZoneFormat object after
1102 * it is adopted by this call.
1103 * @param timeZoneFormatToAdopt The TimeZoneFormat object to be adopted.
1104 * @internal ICU 49 technology preview
1106 virtual void adoptTimeZoneFormat(TimeZoneFormat
* timeZoneFormatToAdopt
);
1109 * Sets the TimeZoneFormat to be used by this date/time formatter.
1110 * @param newTimeZoneFormat The TimeZoneFormat object to copy.
1111 * @internal ICU 49 technology preview
1113 virtual void setTimeZoneFormat(const TimeZoneFormat
& newTimeZoneFormat
);
1116 * Gets the time zone format object associated with this date/time formatter.
1117 * @return the time zone format associated with this date/time formatter.
1118 * @internal ICU 49 technology preview
1120 virtual const TimeZoneFormat
* getTimeZoneFormat(void) const;
1123 * Set a particular UDisplayContext value in the formatter, such as
1124 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. Note: For getContext, see
1126 * @param value The UDisplayContext value to set.
1127 * @param status Input/output status. If at entry this indicates a failure
1128 * status, the function will do nothing; otherwise this will be
1129 * updated with any new status from the function.
1132 virtual void setContext(UDisplayContext value
, UErrorCode
& status
);
1135 * Overrides base class method and
1136 * This method clears per field NumberFormat instances
1137 * previously set by {@see adoptNumberFormat(const UnicodeString&, NumberFormat*, UErrorCode)}
1138 * @param adoptNF the NumbeferFormat used
1141 void adoptNumberFormat(NumberFormat
*formatToAdopt
);
1144 * Allow the user to set the NumberFormat for several fields
1145 * It can be a single field like: "y"(year) or "M"(month)
1146 * It can be several field combined together: "yM"(year and month)
1148 * 1 symbol field is enough for multiple symbol field (so "y" will override "yy", "yyy")
1149 * If the field is not numeric, then override has no effect (like "MMM" will use abbreviation, not numerical field)
1150 * Per field NumberFormat can also be cleared in {@see DateFormat::setNumberFormat(const NumberFormat& newNumberFormat)}
1152 * @param fields the fields to override(like y)
1153 * @param adoptNF the NumbeferFormat used
1154 * @param status Receives a status code, which will be U_ZERO_ERROR
1155 * if the operation succeeds.
1158 void adoptNumberFormat(const UnicodeString
& fields
, NumberFormat
*formatToAdopt
, UErrorCode
&status
);
1161 * Get the numbering system to be used for a particular field.
1162 * @param field The UDateFormatField to get
1165 const NumberFormat
* getNumberFormatForField(UChar field
) const;
1167 #ifndef U_HIDE_INTERNAL_API
1169 * This is for ICU internal use only. Please do not use.
1170 * Check whether the 'field' is smaller than all the fields covered in
1171 * pattern, return TRUE if it is. The sequence of calendar field,
1172 * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
1173 * @param field the calendar field need to check against
1174 * @return TRUE if the 'field' is smaller than all the fields
1175 * covered in pattern. FALSE otherwise.
1178 UBool
isFieldUnitIgnored(UCalendarDateFields field
) const;
1182 * This is for ICU internal use only. Please do not use.
1183 * Check whether the 'field' is smaller than all the fields covered in
1184 * pattern, return TRUE if it is. The sequence of calendar field,
1185 * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
1186 * @param pattern the pattern to check against
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 static UBool
isFieldUnitIgnored(const UnicodeString
& pattern
,
1193 UCalendarDateFields field
);
1196 * This is for ICU internal use only. Please do not use.
1197 * Get the locale of this simple date formatter.
1198 * It is used in DateIntervalFormat.
1200 * @return locale in this simple date formatter
1203 const Locale
& getSmpFmtLocale(void) const;
1204 #endif /* U_HIDE_INTERNAL_API */
1207 friend class DateFormat
;
1209 void initializeDefaultCentury(void);
1211 void initializeBooleanAttributes(void);
1213 SimpleDateFormat(); // default constructor not implemented
1216 * Used by the DateFormat factory methods to construct a SimpleDateFormat.
1217 * @param timeStyle the time style.
1218 * @param dateStyle the date style.
1219 * @param locale the given locale.
1220 * @param status Output param set to success/failure code on
1223 SimpleDateFormat(EStyle timeStyle
, EStyle dateStyle
, const Locale
& locale
, UErrorCode
& status
);
1226 * Construct a SimpleDateFormat for the given locale. If no resource data
1227 * is available, create an object of last resort, using hard-coded strings.
1228 * This is an internal method, called by DateFormat. It should never fail.
1229 * @param locale the given locale.
1230 * @param status Output param set to success/failure code on
1233 SimpleDateFormat(const Locale
& locale
, UErrorCode
& status
); // Use default pattern
1236 * Hook called by format(... FieldPosition& ...) and format(...FieldPositionIterator&...)
1238 UnicodeString
& _format(Calendar
& cal
, UnicodeString
& appendTo
, FieldPositionHandler
& handler
, UErrorCode
& status
) const;
1241 * Called by format() to format a single field.
1243 * @param appendTo Output parameter to receive result.
1244 * Result is appended to existing contents.
1245 * @param ch The format character we encountered in the pattern.
1246 * @param count Number of characters in the current pattern symbol (e.g.,
1247 * "yyyy" in the pattern would result in a call to this function
1248 * with ch equal to 'y' and count equal to 4)
1249 * @param capitalizationContext Capitalization context for this date format.
1250 * @param fieldNum Zero-based numbering of current field within the overall format.
1251 * @param handler Records information about field positions.
1252 * @param cal Calendar to use
1253 * @param status Receives a status code, which will be U_ZERO_ERROR if the operation
1256 void subFormat(UnicodeString
&appendTo
,
1259 UDisplayContext capitalizationContext
,
1261 FieldPositionHandler
& handler
,
1263 SimpleDateFormatMutableNFs
&mutableNFs
,
1264 UErrorCode
& status
) const; // in case of illegal argument
1267 * Used by subFormat() to format a numeric value.
1268 * Appends to toAppendTo a string representation of "value"
1269 * having a number of digits between "minDigits" and
1270 * "maxDigits". Uses the DateFormat's NumberFormat.
1272 * @param currentNumberFormat
1273 * @param appendTo Output parameter to receive result.
1274 * Formatted number is appended to existing contents.
1275 * @param value Value to format.
1276 * @param minDigits Minimum number of digits the result should have
1277 * @param maxDigits Maximum number of digits the result should have
1279 void zeroPaddingNumber(NumberFormat
*currentNumberFormat
,
1280 UnicodeString
&appendTo
,
1283 int32_t maxDigits
) const;
1286 * Return true if the given format character, occuring count
1287 * times, represents a numeric field.
1289 static UBool
isNumeric(UChar formatChar
, int32_t count
);
1292 * Returns TRUE if the patternOffset is at the start of a numeric field.
1294 static UBool
isAtNumericField(const UnicodeString
&pattern
, int32_t patternOffset
);
1297 * Returns TRUE if the patternOffset is right after a non-numeric field.
1299 static UBool
isAfterNonNumericField(const UnicodeString
&pattern
, int32_t patternOffset
);
1302 * initializes fCalendar from parameters. Returns fCalendar as a convenience.
1303 * @param adoptZone Zone to be adopted, or NULL for TimeZone::createDefault().
1304 * @param locale Locale of the calendar
1305 * @param status Error code
1306 * @return the newly constructed fCalendar
1308 Calendar
*initializeCalendar(TimeZone
* adoptZone
, const Locale
& locale
, UErrorCode
& status
);
1311 * Called by several of the constructors to load pattern data and formatting symbols
1312 * out of a resource bundle and initialize the locale based on it.
1313 * @param timeStyle The time style, as passed to DateFormat::createDateInstance().
1314 * @param dateStyle The date style, as passed to DateFormat::createTimeInstance().
1315 * @param locale The locale to load the patterns from.
1316 * @param status Filled in with an error code if loading the data from the
1319 void construct(EStyle timeStyle
, EStyle dateStyle
, const Locale
& locale
, UErrorCode
& status
);
1322 * Called by construct() and the various constructors to set up the SimpleDateFormat's
1323 * Calendar and NumberFormat objects.
1324 * @param locale The locale for which we want a Calendar and a NumberFormat.
1325 * @param status Filled in with an error code if creating either subobject fails.
1327 void initialize(const Locale
& locale
, UErrorCode
& status
);
1330 * Private code-size reduction function used by subParse.
1331 * @param text the time text being parsed.
1332 * @param start where to start parsing.
1333 * @param field the date field being parsed.
1334 * @param stringArray the string array to parsed.
1335 * @param stringArrayCount the size of the array.
1336 * @param monthPattern pointer to leap month pattern, or NULL if none.
1337 * @param cal a Calendar set to the date and time to be formatted
1338 * into a date/time string.
1339 * @return the new start position if matching succeeded; a negative number
1340 * indicating matching failure, otherwise.
1342 int32_t matchString(const UnicodeString
& text
, int32_t start
, UCalendarDateFields field
,
1343 const UnicodeString
* stringArray
, int32_t stringArrayCount
,
1344 const UnicodeString
* monthPattern
, Calendar
& cal
) const;
1347 * Private code-size reduction function used by subParse.
1348 * @param text the time text being parsed.
1349 * @param start where to start parsing.
1350 * @param field the date field being parsed.
1351 * @param stringArray the string array to parsed.
1352 * @param stringArrayCount the size of the array.
1353 * @param cal a Calendar set to the date and time to be formatted
1354 * into a date/time string.
1355 * @return the new start position if matching succeeded; a negative number
1356 * indicating matching failure, otherwise.
1358 int32_t matchQuarterString(const UnicodeString
& text
, int32_t start
, UCalendarDateFields field
,
1359 const UnicodeString
* stringArray
, int32_t stringArrayCount
, Calendar
& cal
) const;
1362 * Used by subParse() to match localized day period strings.
1364 int32_t matchDayPeriodStrings(const UnicodeString
& text
, int32_t start
,
1365 const UnicodeString
* stringArray
, int32_t stringArrayCount
,
1366 int32_t &dayPeriod
) const;
1369 * Private function used by subParse to match literal pattern text.
1371 * @param pattern the pattern string
1372 * @param patternOffset the starting offset into the pattern text. On
1373 * outupt will be set the offset of the first non-literal character in the pattern
1374 * @param text the text being parsed
1375 * @param textOffset the starting offset into the text. On output
1376 * will be set to the offset of the character after the match
1377 * @param whitespaceLenient <code>TRUE</code> if whitespace parse is lenient, <code>FALSE</code> otherwise.
1378 * @param partialMatchLenient <code>TRUE</code> if partial match parse is lenient, <code>FALSE</code> otherwise.
1379 * @param oldLeniency <code>TRUE</code> if old leniency control is lenient, <code>FALSE</code> otherwise.
1381 * @return <code>TRUE</code> if the literal text could be matched, <code>FALSE</code> otherwise.
1383 static UBool
matchLiterals(const UnicodeString
&pattern
, int32_t &patternOffset
,
1384 const UnicodeString
&text
, int32_t &textOffset
,
1385 UBool whitespaceLenient
, UBool partialMatchLenient
, UBool oldLeniency
);
1388 * Private member function that converts the parsed date strings into
1389 * timeFields. Returns -start (for ParsePosition) if failed.
1390 * @param text the time text to be parsed.
1391 * @param start where to start parsing.
1392 * @param ch the pattern character for the date field text to be parsed.
1393 * @param count the count of a pattern character.
1394 * @param obeyCount if true then the count is strictly obeyed.
1395 * @param allowNegative
1396 * @param ambiguousYear If true then the two-digit year == the default start year.
1397 * @param saveHebrewMonth Used to hang onto month until year is known.
1398 * @param cal a Calendar set to the date and time to be formatted
1399 * into a date/time string.
1401 * @param numericLeapMonthFormatter If non-null, used to parse numeric leap months.
1402 * @param tzTimeType the type of parsed time zone - standard, daylight or unknown (output).
1403 * This parameter can be NULL if caller does not need the information.
1404 * @return the new start position if matching succeeded; a negative number
1405 * indicating matching failure, otherwise.
1407 int32_t subParse(const UnicodeString
& text
, int32_t& start
, UChar ch
, int32_t count
,
1408 UBool obeyCount
, UBool allowNegative
, UBool ambiguousYear
[], int32_t& saveHebrewMonth
, Calendar
& cal
,
1409 int32_t patLoc
, MessageFormat
* numericLeapMonthFormatter
, UTimeZoneFormatTimeType
*tzTimeType
, SimpleDateFormatMutableNFs
&mutableNFs
,
1410 int32_t *dayPeriod
=NULL
) const;
1412 void parseInt(const UnicodeString
& text
,
1413 Formattable
& number
,
1415 UBool allowNegative
,
1416 NumberFormat
*fmt
) const;
1418 void parseInt(const UnicodeString
& text
,
1419 Formattable
& number
,
1422 UBool allowNegative
,
1423 NumberFormat
*fmt
) const;
1425 int32_t checkIntSuffix(const UnicodeString
& text
, int32_t start
,
1426 int32_t patLoc
, UBool isNegative
) const;
1429 * Translate a pattern, mapping each character in the from string to the
1430 * corresponding character in the to string. Return an error if the original
1431 * pattern contains an unmapped character, or if a quote is unmatched.
1432 * Quoted (single quotes only) material is not translated.
1433 * @param originalPattern the original pattern.
1434 * @param translatedPattern Output param to receive the translited pattern.
1435 * @param from the characters to be translited from.
1436 * @param to the characters to be translited to.
1437 * @param status Receives a status code, which will be U_ZERO_ERROR
1438 * if the operation succeeds.
1440 static void translatePattern(const UnicodeString
& originalPattern
,
1441 UnicodeString
& translatedPattern
,
1442 const UnicodeString
& from
,
1443 const UnicodeString
& to
,
1444 UErrorCode
& status
);
1447 * Sets the starting date of the 100-year window that dates with 2-digit years
1448 * are considered to fall within.
1449 * @param startDate the start date
1450 * @param status Receives a status code, which will be U_ZERO_ERROR
1451 * if the operation succeeds.
1453 void parseAmbiguousDatesAsAfter(UDate startDate
, UErrorCode
& status
);
1456 * Return the length matched by the given affix, or -1 if none.
1457 * Runs of white space in the affix, match runs of white space in
1459 * @param affix pattern string, taken as a literal
1460 * @param input input text
1461 * @param pos offset into input at which to begin matching
1462 * @return length of input that matches, or -1 if match failure
1464 int32_t compareSimpleAffix(const UnicodeString
& affix
,
1465 const UnicodeString
& input
,
1469 * Skip over a run of zero or more Pattern_White_Space characters at
1472 int32_t skipPatternWhiteSpace(const UnicodeString
& text
, int32_t pos
) const;
1475 * Skip over a run of zero or more isUWhiteSpace() characters at pos
1478 int32_t skipUWhiteSpace(const UnicodeString
& text
, int32_t pos
) const;
1481 * Initialize NumberFormat instances used for numbering system overrides.
1483 void initNumberFormatters(const Locale
&locale
,UErrorCode
&status
);
1486 * Parse the given override string and set up structures for number formats
1488 void processOverrideString(const Locale
&locale
, const UnicodeString
&str
, int8_t type
, UErrorCode
&status
);
1491 * Used to map pattern characters to Calendar field identifiers.
1493 static const UCalendarDateFields fgPatternIndexToCalendarField
[];
1496 * Map index into pattern character string to DateFormat field number
1498 static const UDateFormatField fgPatternIndexToDateFormatField
[];
1501 * Lazy TimeZoneFormat instantiation, semantically const
1503 TimeZoneFormat
*tzFormat() const;
1505 const NumberFormat
* getNumberFormatByIndex(UDateFormatField index
) const;
1508 * Used to map Calendar field to field level.
1509 * The larger the level, the smaller the field unit.
1510 * For example, UCAL_ERA level is 0, UCAL_YEAR level is 10,
1511 * UCAL_MONTH level is 20.
1513 static const int32_t fgCalendarFieldToLevel
[];
1516 * Map calendar field letter into calendar field level.
1518 static int32_t getLevelFromChar(UChar ch
);
1521 * Tell if a character can be used to define a field in a format string.
1523 static UBool
isSyntaxChar(UChar ch
);
1526 * The formatting pattern for this formatter.
1528 UnicodeString fPattern
;
1531 * The numbering system override for dates.
1533 UnicodeString fDateOverride
;
1536 * The numbering system override for times.
1538 UnicodeString fTimeOverride
;
1542 * The original locale used (for reloading symbols)
1547 * A pointer to an object containing the strings to use in formatting (e.g.,
1548 * month and day names, AM and PM strings, time zone names, etc.)
1550 DateFormatSymbols
* fSymbols
; // Owned
1553 * The time zone formatter
1555 TimeZoneFormat
* fTimeZoneFormat
;
1558 * If dates have ambiguous years, we map them into the century starting
1559 * at defaultCenturyStart, which may be any date. If defaultCenturyStart is
1560 * set to SYSTEM_DEFAULT_CENTURY, which it is by default, then the system
1561 * values are used. The instance values defaultCenturyStart and
1562 * defaultCenturyStartYear are only used if explicitly set by the user
1563 * through the API method parseAmbiguousDatesAsAfter().
1565 UDate fDefaultCenturyStart
;
1571 * Sets fHasMinutes and fHasSeconds.
1573 void parsePattern();
1576 * See documentation for defaultCenturyStart.
1578 /*transient*/ int32_t fDefaultCenturyStartYear
;
1580 struct NSOverride
: public UMemory
{
1581 const SharedNumberFormat
*snf
;
1585 NSOverride() : snf(NULL
), hash(0), next(NULL
) {
1591 * The number format in use for each date field. NULL means fall back
1592 * to fNumberFormat in DateFormat.
1594 const SharedNumberFormat
**fSharedNumberFormatters
;
1596 UBool fHaveDefaultCentury
;
1598 BreakIterator
* fCapitalizationBrkIter
;
1602 SimpleDateFormat::get2DigitYearStart(UErrorCode
& /*status*/) const
1604 return fDefaultCenturyStart
;
1609 #endif /* #if !UCONFIG_NO_FORMATTING */