2 * Copyright (C) 1997-2013, 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"
41 class DateFormatSymbols
;
44 class FieldPositionHandler
;
49 * SimpleDateFormat is a concrete class for formatting and parsing dates in a
50 * language-independent manner. It allows for formatting (millis -> text),
51 * parsing (text -> millis), and normalization. Formats/Parses a date or time,
52 * which is the standard milliseconds since 24:00 GMT, Jan 1, 1970.
54 * Clients are encouraged to create a date-time formatter using DateFormat::getInstance(),
55 * getDateInstance(), getDateInstance(), or getDateTimeInstance() rather than
56 * explicitly constructing an instance of SimpleDateFormat. This way, the client
57 * is guaranteed to get an appropriate formatting pattern for whatever locale the
58 * program is running in. However, if the client needs something more unusual than
59 * the default patterns in the locales, he can construct a SimpleDateFormat directly
60 * and give it an appropriate pattern (or use one of the factory methods on DateFormat
61 * and modify the pattern after the fact with toPattern() and applyPattern().
63 * <p><strong>Date and Time Patterns:</strong></p>
65 * <p>Date and time formats are specified by <em>date and time pattern</em> strings.
66 * Within date and time pattern strings, all unquoted ASCII letters [A-Za-z] are reserved
67 * as pattern letters representing calendar fields. <code>SimpleDateFormat</code> supports
68 * the date and time formatting algorithm and pattern letters defined by <a href="http://www.unicode.org/reports/tr35/">UTS#35
69 * Unicode Locale Data Markup Language (LDML)</a>. The following pattern letters are
70 * currently available:</p>
75 * <th style="text-align: center">Sym.</th>
76 * <th style="text-align: center">No.</th>
78 * <th>Description</th>
81 * <th rowspan="3">era</th>
82 * <td style="text-align: center" rowspan="3">G</td>
83 * <td style="text-align: center">1..3</td>
85 * <td rowspan="3">Era - Replaced with the Era string for the current date. One to three letters for the
86 * abbreviated form, four letters for the long form, five for the narrow form.</td>
89 * <td style="text-align: center">4</td>
90 * <td>Anno Domini</td>
93 * <td style="text-align: center">5</td>
97 * <th rowspan="6">year</th>
98 * <td style="text-align: center">y</td>
99 * <td style="text-align: center">1..n</td>
101 * <td>Year. Normally the length specifies the padding, but for two letters it also specifies the maximum
102 * length. Example:<div align="center">
104 * <table border="1" cellpadding="2" cellspacing="0">
107 * <th style="text-align: right">y</th>
108 * <th style="text-align: right">yy</th>
109 * <th style="text-align: right">yyy</th>
110 * <th style="text-align: right">yyyy</th>
111 * <th style="text-align: right">yyyyy</th>
115 * <td style="text-align: right">1</td>
116 * <td style="text-align: right">01</td>
117 * <td style="text-align: right">001</td>
118 * <td style="text-align: right">0001</td>
119 * <td style="text-align: right">00001</td>
123 * <td style="text-align: right">12</td>
124 * <td style="text-align: right">12</td>
125 * <td style="text-align: right">012</td>
126 * <td style="text-align: right">0012</td>
127 * <td style="text-align: right">00012</td>
131 * <td style="text-align: right">123</td>
132 * <td style="text-align: right">23</td>
133 * <td style="text-align: right">123</td>
134 * <td style="text-align: right">0123</td>
135 * <td style="text-align: right">00123</td>
139 * <td style="text-align: right">1234</td>
140 * <td style="text-align: right">34</td>
141 * <td style="text-align: right">1234</td>
142 * <td style="text-align: right">1234</td>
143 * <td style="text-align: right">01234</td>
147 * <td style="text-align: right">12345</td>
148 * <td style="text-align: right">45</td>
149 * <td style="text-align: right">12345</td>
150 * <td style="text-align: right">12345</td>
151 * <td style="text-align: right">12345</td>
158 * <td style="text-align: center">Y</td>
159 * <td style="text-align: center">1..n</td>
161 * <td>Year (in "Week of Year" based calendars). Normally the length specifies the padding,
162 * but for two letters it also specifies the maximum length. This year designation is used in ISO
163 * year-week calendar as defined by ISO 8601, but can be used in non-Gregorian based calendar systems
164 * where week date processing is desired. May not always be the same value as calendar year.</td>
167 * <td style="text-align: center">u</td>
168 * <td style="text-align: center">1..n</td>
170 * <td>Extended year. This is a single number designating the year of this calendar system, encompassing
171 * all supra-year fields. For example, for the Julian calendar system, year numbers are positive, with an
172 * era of BCE or CE. An extended year value for the Julian calendar system assigns positive values to CE
173 * years and negative values to BCE years, with 1 BCE being year 0.</td>
176 * <td style="text-align: center" rowspan="3">U</td>
177 * <td style="text-align: center">1..3</td>
178 * <td>甲子</td>
179 * <td rowspan="3">Cyclic year name. Calendars such as the Chinese lunar calendar (and related calendars)
180 * and the Hindu calendars use 60-year cycles of year names. Use one through three letters for the abbreviated
181 * name, four for the full name, or five for the narrow name (currently the data only provides abbreviated names,
182 * which will be used for all requested name widths). If the calendar does not provide cyclic year name data,
183 * or if the year value to be formatted is out of the range of years for which cyclic name data is provided,
184 * then numeric formatting is used (behaves like 'y').</td>
187 * <td style="text-align: center">4</td>
188 * <td>(currently also 甲子)</td>
191 * <td style="text-align: center">5</td>
192 * <td>(currently also 甲子)</td>
195 * <th rowspan="6">quarter</th>
196 * <td rowspan="3" style="text-align: center">Q</td>
197 * <td style="text-align: center">1..2</td>
199 * <td rowspan="3">Quarter - Use one or two for the numerical quarter, three for the abbreviation, or four
200 * for the full name.</td>
203 * <td style="text-align: center">3</td>
207 * <td style="text-align: center">4</td>
208 * <td>2nd quarter</td>
211 * <td rowspan="3" style="text-align: center">q</td>
212 * <td style="text-align: center">1..2</td>
214 * <td rowspan="3"><b>Stand-Alone</b> Quarter - Use one or two for the numerical quarter, three for the abbreviation,
215 * or four for the full name.</td>
218 * <td style="text-align: center">3</td>
222 * <td style="text-align: center">4</td>
223 * <td>2nd quarter</td>
226 * <th rowspan="8">month</th>
227 * <td rowspan="4" style="text-align: center">M</td>
228 * <td style="text-align: center">1..2</td>
230 * <td rowspan="4">Month - Use one or two for the numerical month, three for the abbreviation, four for
231 * the full name, or five for the narrow name.</td>
234 * <td style="text-align: center">3</td>
238 * <td style="text-align: center">4</td>
242 * <td style="text-align: center">5</td>
246 * <td rowspan="4" style="text-align: center">L</td>
247 * <td style="text-align: center">1..2</td>
249 * <td rowspan="4"><b>Stand-Alone</b> Month - Use one or two for the numerical month, three for the abbreviation,
250 * or four for the full name, or 5 for the narrow name.</td>
253 * <td style="text-align: center">3</td>
257 * <td style="text-align: center">4</td>
261 * <td style="text-align: center">5</td>
265 * <th rowspan="2">week</th>
266 * <td style="text-align: center">w</td>
267 * <td style="text-align: center">1..2</td>
269 * <td>Week of Year.</td>
272 * <td style="text-align: center">W</td>
273 * <td style="text-align: center">1</td>
275 * <td>Week of Month</td>
278 * <th rowspan="4">day</th>
279 * <td style="text-align: center">d</td>
280 * <td style="text-align: center">1..2</td>
282 * <td>Date - Day of the month</td>
285 * <td style="text-align: center">D</td>
286 * <td style="text-align: center">1..3</td>
288 * <td>Day of year</td>
291 * <td style="text-align: center">F</td>
292 * <td style="text-align: center">1</td>
294 * <td>Day of Week in Month. The example is for the 2nd Wed in July</td>
297 * <td style="text-align: center">g</td>
298 * <td style="text-align: center">1..n</td>
300 * <td>Modified Julian day. This is different from the conventional Julian day number in two regards.
301 * First, it demarcates days at local zone midnight, rather than noon GMT. Second, it is a local number;
302 * that is, it depends on the local time zone. It can be thought of as a single number that encompasses
303 * all the date-related fields.</td>
306 * <th rowspan="14">week<br>
308 * <td rowspan="4" style="text-align: center">E</td>
309 * <td style="text-align: center">1..3</td>
311 * <td rowspan="4">Day of week - Use one through three letters for the short day, or four for the full name,
312 * five for the narrow name, or six for the short name.</td>
315 * <td style="text-align: center">4</td>
319 * <td style="text-align: center">5</td>
323 * <td style="text-align: center">6</td>
327 * <td rowspan="5" style="text-align: center">e</td>
328 * <td style="text-align: center">1..2</td>
330 * <td rowspan="5">Local day of week. Same as E except adds a numeric value that will depend on the local
331 * starting day of the week, using one or two letters. For this example, Monday is the first day of the week.</td>
334 * <td style="text-align: center">3</td>
338 * <td style="text-align: center">4</td>
342 * <td style="text-align: center">5</td>
346 * <td style="text-align: center">6</td>
350 * <td rowspan="5" style="text-align: center">c</td>
351 * <td style="text-align: center">1</td>
353 * <td rowspan="5"><b>Stand-Alone</b> local day of week - Use one letter for the local numeric value (same
354 * as 'e'), three for the short day, four for the full name, five for the narrow name, or six for
355 * the short name.</td>
358 * <td style="text-align: center">3</td>
362 * <td style="text-align: center">4</td>
366 * <td style="text-align: center">5</td>
370 * <td style="text-align: center">6</td>
375 * <td style="text-align: center">a</td>
376 * <td style="text-align: center">1</td>
381 * <th rowspan="4">hour</th>
382 * <td style="text-align: center">h</td>
383 * <td style="text-align: center">1..2</td>
385 * <td>Hour [1-12]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern
386 * generation, it should match the 12-hour-cycle format preferred by the locale (h or K); it should not match
387 * a 24-hour-cycle format (H or k). Use hh for zero padding.</td>
390 * <td style="text-align: center">H</td>
391 * <td style="text-align: center">1..2</td>
393 * <td>Hour [0-23]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern
394 * generation, it should match the 24-hour-cycle format preferred by the locale (H or k); it should not match a
395 * 12-hour-cycle format (h or K). Use HH for zero padding.</td>
398 * <td style="text-align: center">K</td>
399 * <td style="text-align: center">1..2</td>
401 * <td>Hour [0-11]. When used in a skeleton, only matches K or h, see above. Use KK for zero padding.</td>
404 * <td style="text-align: center">k</td>
405 * <td style="text-align: center">1..2</td>
407 * <td>Hour [1-24]. When used in a skeleton, only matches k or H, see above. Use kk for zero padding.</td>
411 * <td style="text-align: center">m</td>
412 * <td style="text-align: center">1..2</td>
414 * <td>Minute. Use one or two for zero padding.</td>
417 * <th rowspan="3">second</th>
418 * <td style="text-align: center">s</td>
419 * <td style="text-align: center">1..2</td>
421 * <td>Second. Use one or two for zero padding.</td>
424 * <td style="text-align: center">S</td>
425 * <td style="text-align: center">1..n</td>
427 * <td>Fractional Second - truncates (like other time fields) to the count of letters.
428 * (example shows display using pattern SSSS for seconds value 12.34567)</td>
431 * <td style="text-align: center">A</td>
432 * <td style="text-align: center">1..n</td>
434 * <td>Milliseconds in day. This field behaves <i>exactly</i> like a composite of all time-related fields,
435 * not including the zone fields. As such, it also reflects discontinuities of those fields on DST transition
436 * days. On a day of DST onset, it will jump forward. On a day of DST cessation, it will jump backward. This
437 * reflects the fact that is must be combined with the offset field to obtain a unique local time value.</td>
440 * <th rowspan="23">zone</th>
441 * <td rowspan="2" style="text-align: center">z</td>
442 * <td style="text-align: center">1..3</td>
444 * <td>The <i>short specific non-location format</i>.
445 * Where that is unavailable, falls back to the <i>short localized GMT format</i> ("O").</td>
448 * <td style="text-align: center">4</td>
449 * <td>Pacific Daylight Time</td>
450 * <td>The <i>long specific non-location format</i>.
451 * Where that is unavailable, falls back to the <i>long localized GMT format</i> ("OOOO").</td>
454 * <td rowspan="3" style="text-align: center">Z</td>
455 * <td style="text-align: center">1..3</td>
457 * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
458 * The format is equivalent to RFC 822 zone format (when optional seconds field is absent).
459 * This is equivalent to the "xxxx" specifier.</td>
462 * <td style="text-align: center">4</td>
464 * <td>The <i>long localized GMT format</i>.
465 * This is equivalent to the "OOOO" specifier.</td>
468 * <td style="text-align: center">5</td>
471 * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
472 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.
473 * This is equivalent to the "XXXXX" specifier.</td>
476 * <td rowspan="2" style="text-align: center">O</td>
477 * <td style="text-align: center">1</td>
479 * <td>The <i>short localized GMT format</i>.</td>
482 * <td style="text-align: center">4</td>
484 * <td>The <i>long localized GMT format</i>.</td>
487 * <td rowspan="2" style="text-align: center">v</td>
488 * <td style="text-align: center">1</td>
490 * <td>The <i>short generic non-location format</i>.
491 * Where that is unavailable, falls back to the <i>generic location format</i> ("VVVV"),
492 * then the <i>short localized GMT format</i> as the final fallback.</td>
495 * <td style="text-align: center">4</td>
496 * <td>Pacific Time</td>
497 * <td>The <i>long generic non-location format</i>.
498 * Where that is unavailable, falls back to <i>generic location format</i> ("VVVV").
501 * <td rowspan="4" style="text-align: center">V</td>
502 * <td style="text-align: center">1</td>
504 * <td>The short time zone ID.
505 * Where that is unavailable, the special short time zone ID <i>unk</i> (Unknown Zone) is used.<br>
506 * <i><b>Note</b>: This specifier was originally used for a variant of the short specific non-location format,
507 * but it was deprecated in the later version of the LDML specification. In CLDR 23/ICU 51, the definition of
508 * the specifier was changed to designate a short time zone ID.</i></td>
511 * <td style="text-align: center">2</td>
512 * <td>America/Los_Angeles</td>
513 * <td>The long time zone ID.</td>
516 * <td style="text-align: center">3</td>
517 * <td>Los Angeles</td>
518 * <td>The exemplar city (location) for the time zone.
519 * Where that is unavailable, the localized exemplar city name for the special zone <i>Etc/Unknown</i> is used
520 * as the fallback (for example, "Unknown City"). </td>
523 * <td style="text-align: center">4</td>
524 * <td>Los Angeles Time</td>
525 * <td>The <i>generic location format</i>.
526 * Where that is unavailable, falls back to the <i>long localized GMT format</i> ("OOOO";
527 * Note: Fallback is only necessary with a GMT-style Time Zone ID, like Etc/GMT-830.)<br>
528 * This is especially useful when presenting possible timezone choices for user selection,
529 * since the naming is more uniform than the "v" format.</td>
532 * <td rowspan="5" style="text-align: center">X</td>
533 * <td style="text-align: center">1</td>
537 * <td>The <i>ISO8601 basic format</i> with hours field and optional minutes field.
538 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
541 * <td style="text-align: center">2</td>
544 * <td>The <i>ISO8601 basic format</i> with hours and minutes fields.
545 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
548 * <td style="text-align: center">3</td>
551 * <td>The <i>ISO8601 extended format</i> with hours and minutes fields.
552 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
555 * <td style="text-align: center">4</td>
559 * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
560 * (Note: The seconds field is not supported by the ISO8601 specification.)
561 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
564 * <td style="text-align: center">5</td>
568 * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
569 * (Note: The seconds field is not supported by the ISO8601 specification.)
570 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
573 * <td rowspan="5" style="text-align: center">x</td>
574 * <td style="text-align: center">1</td>
577 * <td>The <i>ISO8601 basic format</i> with hours field and optional minutes field.</td>
580 * <td style="text-align: center">2</td>
582 * <td>The <i>ISO8601 basic format</i> with hours and minutes fields.</td>
585 * <td style="text-align: center">3</td>
587 * <td>The <i>ISO8601 extended format</i> with hours and minutes fields.</td>
590 * <td style="text-align: center">4</td>
593 * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
594 * (Note: The seconds field is not supported by the ISO8601 specification.)</td>
597 * <td style="text-align: center">5</td>
600 * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
601 * (Note: The seconds field is not supported by the ISO8601 specification.)</td>
606 * Any characters in the pattern that are not in the ranges of ['a'..'z'] and
607 * ['A'..'Z'] will be treated as quoted text. For instance, characters
608 * like ':', '.', ' ', '#' and '@' will appear in the resulting time text
609 * even they are not embraced within single quotes.
611 * A pattern containing any invalid pattern letter will result in a failing
612 * UErrorCode result during formatting or parsing.
614 * Examples using the US locale:
617 * Format Pattern Result
618 * -------------- -------
619 * "yyyy.MM.dd G 'at' HH:mm:ss vvvv" ->> 1996.07.10 AD at 15:08:56 Pacific Time
620 * "EEE, MMM d, ''yy" ->> Wed, July 10, '96
621 * "h:mm a" ->> 12:08 PM
622 * "hh 'o''clock' a, zzzz" ->> 12 o'clock PM, Pacific Daylight Time
623 * "K:mm a, vvv" ->> 0:00 PM, PT
624 * "yyyyy.MMMMM.dd GGG hh:mm aaa" ->> 1996.July.10 AD 12:08 PM
630 * UErrorCode success = U_ZERO_ERROR;
631 * SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "PST");
632 * pdt->setStartRule( Calendar::APRIL, 1, Calendar::SUNDAY, 2*60*60*1000);
633 * pdt->setEndRule( Calendar::OCTOBER, -1, Calendar::SUNDAY, 2*60*60*1000);
635 * // Format the current time.
636 * SimpleDateFormat* formatter
637 * = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz", success );
638 * GregorianCalendar cal(success);
639 * UDate currentTime_1 = cal.getTime(success);
640 * FieldPosition fp(0);
641 * UnicodeString dateString;
642 * formatter->format( currentTime_1, dateString, fp );
643 * cout << "result: " << dateString << endl;
645 * // Parse the previous string back into a Date.
646 * ParsePosition pp(0);
647 * UDate currentTime_2 = formatter->parse(dateString, pp );
650 * In the above example, the time value "currentTime_2" obtained from parsing
651 * will be equal to currentTime_1. However, they may not be equal if the am/pm
652 * marker 'a' is left out from the format pattern while the "hour in am/pm"
653 * pattern symbol is used. This information loss can happen when formatting the
657 * When parsing a date string using the abbreviated year pattern ("y" or "yy"),
658 * SimpleDateFormat must interpret the abbreviated year
659 * relative to some century. It does this by adjusting dates to be
660 * within 80 years before and 20 years after the time the SimpleDateFormat
661 * instance is created. For example, using a pattern of "MM/dd/yy" and a
662 * SimpleDateFormat instance created on Jan 1, 1997, the string
663 * "01/11/12" would be interpreted as Jan 11, 2012 while the string "05/04/64"
664 * would be interpreted as May 4, 1964.
665 * During parsing, only strings consisting of exactly two digits, as defined by
666 * <code>Unicode::isDigit()</code>, will be parsed into the default century.
667 * Any other numeric string, such as a one digit string, a three or more digit
668 * string, or a two digit string that isn't all digits (for example, "-1"), is
669 * interpreted literally. So "01/02/3" or "01/02/003" are parsed (for the
670 * Gregorian calendar), using the same pattern, as Jan 2, 3 AD. Likewise (but
671 * only in lenient parse mode, the default) "01/02/-3" is parsed as Jan 2, 4 BC.
674 * If the year pattern has more than two 'y' characters, the year is
675 * interpreted literally, regardless of the number of digits. So using the
676 * pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
679 * When numeric fields abut one another directly, with no intervening delimiter
680 * characters, they constitute a run of abutting numeric fields. Such runs are
681 * parsed specially. For example, the format "HHmmss" parses the input text
682 * "123456" to 12:34:56, parses the input text "12345" to 1:23:45, and fails to
683 * parse "1234". In other words, the leftmost field of the run is flexible,
684 * while the others keep a fixed width. If the parse fails anywhere in the run,
685 * then the leftmost field is shortened by one character, and the entire run is
686 * parsed again. This is repeated until either the parse succeeds or the
687 * leftmost field is one character in length. If the parse still fails at that
688 * point, the parse of the run fails.
691 * For time zones that have no names, SimpleDateFormat uses strings GMT+hours:minutes or
694 * The calendar defines what is the first day of the week, the first week of the
695 * year, whether hours are zero based or not (0 vs 12 or 24), and the timezone.
696 * There is one common number format to handle all the numbers; the digit count
697 * is handled programmatically according to the pattern.
699 * <p><em>User subclasses are not supported.</em> While clients may write
700 * subclasses, such code will not necessarily work and will not be
701 * guaranteed to work stably from release to release.
703 class U_I18N_API SimpleDateFormat
: public DateFormat
{
706 * Construct a SimpleDateFormat using the default pattern for the default
709 * [Note:] Not all locales support SimpleDateFormat; for full generality,
710 * use the factory methods in the DateFormat class.
711 * @param status Output param set to success/failure code.
714 SimpleDateFormat(UErrorCode
& status
);
717 * Construct a SimpleDateFormat using the given pattern and the default locale.
718 * The locale is used to obtain the symbols used in formatting (e.g., the
719 * names of the months), but not to provide the pattern.
721 * [Note:] Not all locales support SimpleDateFormat; for full generality,
722 * use the factory methods in the DateFormat class.
723 * @param pattern the pattern for the format.
724 * @param status Output param set to success/failure code.
727 SimpleDateFormat(const UnicodeString
& pattern
,
731 * Construct a SimpleDateFormat using the given pattern, numbering system override, 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 * A numbering system override is a string containing either the name of a known numbering system,
736 * or a set of field and numbering system pairs that specify which fields are to be formattied with
737 * the alternate numbering system. For example, to specify that all numeric fields in the specified
738 * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
739 * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering,
740 * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon
741 * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
744 * [Note:] Not all locales support SimpleDateFormat; for full generality,
745 * use the factory methods in the DateFormat class.
746 * @param pattern the pattern for the format.
747 * @param override the override string.
748 * @param status Output param set to success/failure code.
751 SimpleDateFormat(const UnicodeString
& pattern
,
752 const UnicodeString
& override
,
756 * Construct a SimpleDateFormat using the given pattern and locale.
757 * The locale is used to obtain the symbols used in formatting (e.g., the
758 * names of the months), but not to provide the pattern.
760 * [Note:] Not all locales support SimpleDateFormat; for full generality,
761 * use the factory methods in the DateFormat class.
762 * @param pattern the pattern for the format.
763 * @param locale the given locale.
764 * @param status Output param set to success/failure code.
767 SimpleDateFormat(const UnicodeString
& pattern
,
768 const Locale
& locale
,
772 * Construct a SimpleDateFormat using the given pattern, numbering system override, and locale.
773 * The locale is used to obtain the symbols used in formatting (e.g., the
774 * names of the months), but not to provide the pattern.
776 * A numbering system override is a string containing either the name of a known numbering system,
777 * or a set of field and numbering system pairs that specify which fields are to be formattied with
778 * the alternate numbering system. For example, to specify that all numeric fields in the specified
779 * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
780 * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering,
781 * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon
782 * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
784 * [Note:] Not all locales support SimpleDateFormat; for full generality,
785 * use the factory methods in the DateFormat class.
786 * @param pattern the pattern for the format.
787 * @param override the numbering system override.
788 * @param locale the given locale.
789 * @param status Output param set to success/failure code.
792 SimpleDateFormat(const UnicodeString
& pattern
,
793 const UnicodeString
& override
,
794 const Locale
& locale
,
798 * Construct a SimpleDateFormat using the given pattern and locale-specific
799 * symbol data. The formatter takes ownership of the DateFormatSymbols object;
800 * the caller is no longer responsible for deleting it.
801 * @param pattern the given pattern for the format.
802 * @param formatDataToAdopt the symbols to be adopted.
803 * @param status Output param set to success/faulure code.
806 SimpleDateFormat(const UnicodeString
& pattern
,
807 DateFormatSymbols
* formatDataToAdopt
,
811 * Construct a SimpleDateFormat using the given pattern and locale-specific
812 * symbol data. The DateFormatSymbols object is NOT adopted; the caller
813 * remains responsible for deleting it.
814 * @param pattern the given pattern for the format.
815 * @param formatData the formatting symbols to be use.
816 * @param status Output param set to success/faulure code.
819 SimpleDateFormat(const UnicodeString
& pattern
,
820 const DateFormatSymbols
& formatData
,
827 SimpleDateFormat(const SimpleDateFormat
&);
830 * Assignment operator.
833 SimpleDateFormat
& operator=(const SimpleDateFormat
&);
839 virtual ~SimpleDateFormat();
842 * Clone this Format object polymorphically. The caller owns the result and
843 * should delete it when done.
844 * @return A copy of the object.
847 virtual Format
* clone(void) const;
850 * Return true if the given Format objects are semantically equal. Objects
851 * of different subclasses are considered unequal.
852 * @param other the object to be compared with.
853 * @return true if the given Format objects are semantically equal.
856 virtual UBool
operator==(const Format
& other
) const;
859 using DateFormat::format
;
862 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
863 * 1, 1970. Overrides DateFormat pure virtual method.
865 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
866 * 1996.07.10 AD at 15:08:56 PDT
868 * @param cal Calendar set to the date and time to be formatted
869 * into a date/time string.
870 * @param appendTo Output parameter to receive result.
871 * Result is appended to existing contents.
872 * @param pos The formatting position. On input: an alignment field,
873 * if desired. On output: the offsets of the alignment field.
874 * @return Reference to 'appendTo' parameter.
877 virtual UnicodeString
& format( Calendar
& cal
,
878 UnicodeString
& appendTo
,
879 FieldPosition
& pos
) const;
882 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
883 * 1, 1970. Overrides DateFormat pure virtual method.
885 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
886 * 1996.07.10 AD at 15:08:56 PDT
888 * @param cal Calendar set to the date and time to be formatted
889 * into a date/time string.
890 * @param appendTo Output parameter to receive result.
891 * Result is appended to existing contents.
892 * @param posIter On return, can be used to iterate over positions
893 * of fields generated by this format call. Field values
894 * are defined in UDateFormatField.
895 * @param status Input/output param set to success/failure code.
896 * @return Reference to 'appendTo' parameter.
899 virtual UnicodeString
& format( Calendar
& cal
,
900 UnicodeString
& appendTo
,
901 FieldPositionIterator
* posIter
,
902 UErrorCode
& status
) const;
905 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
906 * 1, 1970. Overrides DateFormat pure virtual method.
908 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
909 * 1996.07.10 AD at 15:08:56 PDT
911 * @param obj A Formattable containing the date-time value to be formatted
912 * into a date-time string. If the type of the Formattable
913 * is a numeric type, it is treated as if it were an
915 * @param appendTo Output parameter to receive result.
916 * Result is appended to existing contents.
917 * @param pos The formatting position. On input: an alignment field,
918 * if desired. On output: the offsets of the alignment field.
919 * @param status Input/output param set to success/failure code.
920 * @return Reference to 'appendTo' parameter.
923 virtual UnicodeString
& format( const Formattable
& obj
,
924 UnicodeString
& appendTo
,
926 UErrorCode
& status
) const;
929 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
930 * 1, 1970. Overrides DateFormat pure virtual method.
932 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
933 * 1996.07.10 AD at 15:08:56 PDT
935 * @param obj A Formattable containing the date-time value to be formatted
936 * into a date-time string. If the type of the Formattable
937 * is a numeric type, it is treated as if it were an
939 * @param appendTo Output parameter to receive result.
940 * Result is appended to existing contents.
941 * @param posIter On return, can be used to iterate over positions
942 * of fields generated by this format call. Field values
943 * are defined in UDateFormatField.
944 * @param status Input/output param set to success/failure code.
945 * @return Reference to 'appendTo' parameter.
948 virtual UnicodeString
& format( const Formattable
& obj
,
949 UnicodeString
& appendTo
,
950 FieldPositionIterator
* posIter
,
951 UErrorCode
& status
) const;
954 * Redeclared DateFormat method.
955 * @param date the Date value to be formatted.
956 * @param appendTo Output parameter to receive result.
957 * Result is appended to existing contents.
958 * @param fieldPosition The formatting position. On input: an alignment field,
959 * if desired. On output: the offsets of the alignment field.
960 * @return Reference to 'appendTo' parameter.
963 UnicodeString
& format(UDate date
,
964 UnicodeString
& appendTo
,
965 FieldPosition
& fieldPosition
) const;
968 * Redeclared DateFormat method.
969 * @param date the Date value to be formatted.
970 * @param appendTo Output parameter to receive result.
971 * Result is appended to existing contents.
972 * @param posIter On return, can be used to iterate over positions
973 * of fields generated by this format call. Field values
974 * are defined in UDateFormatField.
975 * @param status Input/output param set to success/failure code.
976 * @return Reference to 'appendTo' parameter.
979 UnicodeString
& format(UDate date
,
980 UnicodeString
& appendTo
,
981 FieldPositionIterator
* posIter
,
982 UErrorCode
& status
) const;
985 * Redeclared DateFormat method.
986 * @param obj Object to be formatted.
987 * @param appendTo Output parameter to receive result.
988 * Result is appended to existing contents.
989 * @param status Input/output success/failure code.
990 * @return Reference to 'appendTo' parameter.
993 UnicodeString
& format(const Formattable
& obj
,
994 UnicodeString
& appendTo
,
995 UErrorCode
& status
) const;
998 * Redeclared DateFormat method.
999 * @param date Date value to be formatted.
1000 * @param appendTo Output parameter to receive result.
1001 * Result is appended to existing contents.
1002 * @return Reference to 'appendTo' parameter.
1005 UnicodeString
& format(UDate date
, UnicodeString
& appendTo
) const;
1008 * Parse a date/time string beginning at the given parse position. For
1009 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
1010 * that is equivalent to Date(837039928046).
1012 * By default, parsing is lenient: If the input is not in the form used by
1013 * this object's format method but can still be parsed as a date, then the
1014 * parse succeeds. Clients may insist on strict adherence to the format by
1015 * calling setLenient(false).
1016 * @see DateFormat::setLenient(boolean)
1018 * @param text The date/time string to be parsed
1019 * @param cal A Calendar set on input to the date and time to be used for
1020 * missing values in the date/time string being parsed, and set
1021 * on output to the parsed date/time. When the calendar type is
1022 * different from the internal calendar held by this SimpleDateFormat
1023 * instance, the internal calendar will be cloned to a work
1024 * calendar set to the same milliseconds and time zone as the
1025 * cal parameter, field values will be parsed based on the work
1026 * calendar, then the result (milliseconds and time zone) will
1027 * be set in this calendar.
1028 * @param pos On input, the position at which to start parsing; on
1029 * output, the position at which parsing terminated, or the
1030 * start position if the parse failed.
1033 virtual void parse( const UnicodeString
& text
,
1035 ParsePosition
& pos
) const;
1038 * Parse a date/time string starting at the given parse position. For
1039 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
1040 * that is equivalent to Date(837039928046).
1042 * By default, parsing is lenient: If the input is not in the form used by
1043 * this object's format method but can still be parsed as a date, then the
1044 * parse succeeds. Clients may insist on strict adherence to the format by
1045 * calling setLenient(false).
1046 * @see DateFormat::setLenient(boolean)
1048 * Note that the normal date formats associated with some calendars - such
1049 * as the Chinese lunar calendar - do not specify enough fields to enable
1050 * dates to be parsed unambiguously. In the case of the Chinese lunar
1051 * calendar, while the year within the current 60-year cycle is specified,
1052 * the number of such cycles since the start date of the calendar (in the
1053 * ERA field of the Calendar object) is not normally part of the format,
1054 * and parsing may assume the wrong era. For cases such as this it is
1055 * recommended that clients parse using the method
1056 * parse(const UnicodeString&, Calendar& cal, ParsePosition&)
1057 * with the Calendar passed in set to the current date, or to a date
1058 * within the era/cycle that should be assumed if absent in the format.
1060 * @param text The date/time string to be parsed
1061 * @param pos On input, the position at which to start parsing; on
1062 * output, the position at which parsing terminated, or the
1063 * start position if the parse failed.
1064 * @return A valid UDate if the input could be parsed.
1067 UDate
parse( const UnicodeString
& text
,
1068 ParsePosition
& pos
) const;
1072 * Parse a date/time string. For example, a time text "07/10/96 4:5 PM, PDT"
1073 * will be parsed into a UDate that is equivalent to Date(837039928046).
1074 * Parsing begins at the beginning of the string and proceeds as far as
1075 * possible. Assuming no parse errors were encountered, this function
1076 * doesn't return any information about how much of the string was consumed
1077 * by the parsing. If you need that information, use the version of
1078 * parse() that takes a ParsePosition.
1080 * By default, parsing is lenient: If the input is not in the form used by
1081 * this object's format method but can still be parsed as a date, then the
1082 * parse succeeds. Clients may insist on strict adherence to the format by
1083 * calling setLenient(false).
1084 * @see DateFormat::setLenient(boolean)
1086 * Note that the normal date formats associated with some calendars - such
1087 * as the Chinese lunar calendar - do not specify enough fields to enable
1088 * dates to be parsed unambiguously. In the case of the Chinese lunar
1089 * calendar, while the year within the current 60-year cycle is specified,
1090 * the number of such cycles since the start date of the calendar (in the
1091 * ERA field of the Calendar object) is not normally part of the format,
1092 * and parsing may assume the wrong era. For cases such as this it is
1093 * recommended that clients parse using the method
1094 * parse(const UnicodeString&, Calendar& cal, ParsePosition&)
1095 * with the Calendar passed in set to the current date, or to a date
1096 * within the era/cycle that should be assumed if absent in the format.
1098 * @param text The date/time string to be parsed into a UDate value.
1099 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
1100 * an error value if there was a parse error.
1101 * @return A valid UDate if the input could be parsed.
1104 virtual UDate
parse( const UnicodeString
& text
,
1105 UErrorCode
& status
) const;
1108 * Set the start UDate used to interpret two-digit year strings.
1109 * When dates are parsed having 2-digit year strings, they are placed within
1110 * a assumed range of 100 years starting on the two digit start date. For
1111 * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
1112 * some other year. SimpleDateFormat chooses a year so that the resultant
1113 * date is on or after the two digit start date and within 100 years of the
1114 * two digit start date.
1116 * By default, the two digit start date is set to 80 years before the current
1117 * time at which a SimpleDateFormat object is created.
1118 * @param d start UDate used to interpret two-digit year strings.
1119 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
1120 * an error value if there was a parse error.
1123 virtual void set2DigitYearStart(UDate d
, UErrorCode
& status
);
1126 * Get the start UDate used to interpret two-digit year strings.
1127 * When dates are parsed having 2-digit year strings, they are placed within
1128 * a assumed range of 100 years starting on the two digit start date. For
1129 * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
1130 * some other year. SimpleDateFormat chooses a year so that the resultant
1131 * date is on or after the two digit start date and within 100 years of the
1132 * two digit start date.
1134 * By default, the two digit start date is set to 80 years before the current
1135 * time at which a SimpleDateFormat object is created.
1136 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
1137 * an error value if there was a parse error.
1140 UDate
get2DigitYearStart(UErrorCode
& status
) const;
1143 * Return a pattern string describing this date format.
1144 * @param result Output param to receive the pattern.
1145 * @return A reference to 'result'.
1148 virtual UnicodeString
& toPattern(UnicodeString
& result
) const;
1151 * Return a localized pattern string describing this date format.
1152 * In most cases, this will return the same thing as toPattern(),
1153 * but a locale can specify characters to use in pattern descriptions
1154 * in place of the ones described in this class's class documentation.
1155 * (Presumably, letters that would be more mnemonic in that locale's
1156 * language.) This function would produce a pattern using those
1159 * @param result Receives the localized pattern.
1160 * @param status Output param set to success/failure code on
1161 * exit. If the pattern is invalid, this will be
1162 * set to a failure result.
1163 * @return A reference to 'result'.
1166 virtual UnicodeString
& toLocalizedPattern(UnicodeString
& result
,
1167 UErrorCode
& status
) const;
1170 * Apply the given unlocalized pattern string to this date format.
1171 * (i.e., after this call, this formatter will format dates according to
1174 * @param pattern The pattern to be applied.
1177 virtual void applyPattern(const UnicodeString
& pattern
);
1180 * Apply the given localized pattern string to this date format.
1181 * (see toLocalizedPattern() for more information on localized patterns.)
1183 * @param pattern The localized pattern to be applied.
1184 * @param status Output param set to success/failure code on
1185 * exit. If the pattern is invalid, this will be
1186 * set to a failure result.
1189 virtual void applyLocalizedPattern(const UnicodeString
& pattern
,
1190 UErrorCode
& status
);
1193 * Gets the date/time formatting symbols (this is an object carrying
1194 * the various strings and other symbols used in formatting: e.g., month
1195 * names and abbreviations, time zone names, AM/PM strings, etc.)
1196 * @return a copy of the date-time formatting data associated
1197 * with this date-time formatter.
1200 virtual const DateFormatSymbols
* getDateFormatSymbols(void) const;
1203 * Set the date/time formatting symbols. The caller no longer owns the
1204 * DateFormatSymbols object and should not delete it after making this call.
1205 * @param newFormatSymbols the given date-time formatting symbols to copy.
1208 virtual void adoptDateFormatSymbols(DateFormatSymbols
* newFormatSymbols
);
1211 * Set the date/time formatting data.
1212 * @param newFormatSymbols the given date-time formatting symbols to copy.
1215 virtual void setDateFormatSymbols(const DateFormatSymbols
& newFormatSymbols
);
1218 * Return the class ID for this class. This is useful only for comparing to
1219 * a return value from getDynamicClassID(). For example:
1221 * . Base* polymorphic_pointer = createPolymorphicObject();
1222 * . if (polymorphic_pointer->getDynamicClassID() ==
1223 * . erived::getStaticClassID()) ...
1225 * @return The class ID for all objects of this class.
1228 static UClassID U_EXPORT2
getStaticClassID(void);
1231 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
1232 * method is to implement a simple version of RTTI, since not all C++
1233 * compilers support genuine RTTI. Polymorphic operator==() and clone()
1234 * methods call this method.
1236 * @return The class ID for this object. All objects of a
1237 * given class have the same class ID. Objects of
1238 * other classes have different class IDs.
1241 virtual UClassID
getDynamicClassID(void) const;
1244 * Set the calendar to be used by this date format. Initially, the default
1245 * calendar for the specified or default locale is used. The caller should
1246 * not delete the Calendar object after it is adopted by this call.
1247 * Adopting a new calendar will change to the default symbols.
1249 * @param calendarToAdopt Calendar object to be adopted.
1252 virtual void adoptCalendar(Calendar
* calendarToAdopt
);
1254 /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
1256 * Set a particular UDisplayContext value in the formatter, such as
1257 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
1258 * @param value The UDisplayContext value to set.
1259 * @param status Input/output status. If at entry this indicates a failure
1260 * status, the function will do nothing; otherwise this will be
1261 * updated with any new status from the function.
1264 virtual void setContext(UDisplayContext value
, UErrorCode
& status
);
1266 /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
1268 * Get the formatter's UDisplayContext value for the specified UDisplayContextType,
1269 * such as UDISPCTX_TYPE_CAPITALIZATION.
1270 * @param type The UDisplayContextType whose value to return
1271 * @param status Input/output status. If at entry this indicates a failure
1272 * status, the function will do nothing; otherwise this will be
1273 * updated with any new status from the function.
1274 * @return The UDisplayContextValue for the specified type.
1277 virtual UDisplayContext
getContext(UDisplayContextType type
, UErrorCode
& status
) const;
1279 /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
1281 * Sets the TimeZoneFormat to be used by this date/time formatter.
1282 * The caller should not delete the TimeZoneFormat object after
1283 * it is adopted by this call.
1284 * @param timeZoneFormatToAdopt The TimeZoneFormat object to be adopted.
1285 * @internal ICU 49 technology preview
1287 virtual void adoptTimeZoneFormat(TimeZoneFormat
* timeZoneFormatToAdopt
);
1290 * Sets the TimeZoneFormat to be used by this date/time formatter.
1291 * @param newTimeZoneFormat The TimeZoneFormat object to copy.
1292 * @internal ICU 49 technology preview
1294 virtual void setTimeZoneFormat(const TimeZoneFormat
& newTimeZoneFormat
);
1297 * Gets the time zone format object associated with this date/time formatter.
1298 * @return the time zone format associated with this date/time formatter.
1299 * @internal ICU 49 technology preview
1301 virtual const TimeZoneFormat
* getTimeZoneFormat(void) const;
1303 #ifndef U_HIDE_INTERNAL_API
1305 * This is for ICU internal use only. Please do not use.
1306 * Check whether the 'field' is smaller than all the fields covered in
1307 * pattern, return TRUE if it is. The sequence of calendar field,
1308 * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
1309 * @param field the calendar field need to check against
1310 * @return TRUE if the 'field' is smaller than all the fields
1311 * covered in pattern. FALSE otherwise.
1314 UBool
isFieldUnitIgnored(UCalendarDateFields field
) const;
1318 * This is for ICU internal use only. Please do not use.
1319 * Check whether the 'field' is smaller than all the fields covered in
1320 * pattern, return TRUE if it is. The sequence of calendar field,
1321 * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
1322 * @param pattern the pattern to check against
1323 * @param field the calendar field need to check against
1324 * @return TRUE if the 'field' is smaller than all the fields
1325 * covered in pattern. FALSE otherwise.
1328 static UBool
isFieldUnitIgnored(const UnicodeString
& pattern
,
1329 UCalendarDateFields field
);
1332 * This is for ICU internal use only. Please do not use.
1333 * Get the locale of this simple date formatter.
1334 * It is used in DateIntervalFormat.
1336 * @return locale in this simple date formatter
1339 const Locale
& getSmpFmtLocale(void) const;
1340 #endif /* U_HIDE_INTERNAL_API */
1343 friend class DateFormat
;
1345 void initializeDefaultCentury(void);
1347 SimpleDateFormat(); // default constructor not implemented
1350 * Used by the DateFormat factory methods to construct a SimpleDateFormat.
1351 * @param timeStyle the time style.
1352 * @param dateStyle the date style.
1353 * @param locale the given locale.
1354 * @param status Output param set to success/failure code on
1357 SimpleDateFormat(EStyle timeStyle
, EStyle dateStyle
, const Locale
& locale
, UErrorCode
& status
);
1360 * Construct a SimpleDateFormat for the given locale. If no resource data
1361 * is available, create an object of last resort, using hard-coded strings.
1362 * This is an internal method, called by DateFormat. It should never fail.
1363 * @param locale the given locale.
1364 * @param status Output param set to success/failure code on
1367 SimpleDateFormat(const Locale
& locale
, UErrorCode
& status
); // Use default pattern
1370 * Hook called by format(... FieldPosition& ...) and format(...FieldPositionIterator&...)
1372 UnicodeString
& _format(Calendar
& cal
, UnicodeString
& appendTo
, FieldPositionHandler
& handler
, UErrorCode
& status
) const;
1375 * Called by format() to format a single field.
1377 * @param appendTo Output parameter to receive result.
1378 * Result is appended to existing contents.
1379 * @param ch The format character we encountered in the pattern.
1380 * @param count Number of characters in the current pattern symbol (e.g.,
1381 * "yyyy" in the pattern would result in a call to this function
1382 * with ch equal to 'y' and count equal to 4)
1383 * @param capitalizationContext Capitalization context for this date format.
1384 * @param fieldNum Zero-based numbering of current field within the overall format.
1385 * @param handler Records information about field positions.
1386 * @param cal Calendar to use
1387 * @param status Receives a status code, which will be U_ZERO_ERROR if the operation
1390 void subFormat(UnicodeString
&appendTo
,
1393 UDisplayContext capitalizationContext
,
1395 FieldPositionHandler
& handler
,
1397 UErrorCode
& status
) const; // in case of illegal argument
1400 * Used by subFormat() to format a numeric value.
1401 * Appends to toAppendTo a string representation of "value"
1402 * having a number of digits between "minDigits" and
1403 * "maxDigits". Uses the DateFormat's NumberFormat.
1405 * @param currentNumberFormat
1406 * @param appendTo Output parameter to receive result.
1407 * Formatted number is appended to existing contents.
1408 * @param value Value to format.
1409 * @param minDigits Minimum number of digits the result should have
1410 * @param maxDigits Maximum number of digits the result should have
1412 void zeroPaddingNumber(NumberFormat
*currentNumberFormat
,
1413 UnicodeString
&appendTo
,
1417 UBool basicNumFmt
) const;
1420 * Return true if the given format character, occuring count
1421 * times, represents a numeric field.
1423 static UBool
isNumeric(UChar formatChar
, int32_t count
);
1426 * Returns TRUE if the patternOffset is at the start of a numeric field.
1428 static UBool
isAtNumericField(const UnicodeString
&pattern
, int32_t patternOffset
);
1431 * Returns TRUE if the patternOffset is right after a non-numeric field.
1433 static UBool
isAfterNonNumericField(const UnicodeString
&pattern
, int32_t patternOffset
);
1436 * initializes fCalendar from parameters. Returns fCalendar as a convenience.
1437 * @param adoptZone Zone to be adopted, or NULL for TimeZone::createDefault().
1438 * @param locale Locale of the calendar
1439 * @param status Error code
1440 * @return the newly constructed fCalendar
1442 Calendar
*initializeCalendar(TimeZone
* adoptZone
, const Locale
& locale
, UErrorCode
& status
);
1445 * initializes fSymbols from parameters.
1446 * @param locale Locale of the symbols
1447 * @param calendar Alias to Calendar that will be used.
1448 * @param status Error code
1450 void initializeSymbols(const Locale
& locale
, Calendar
* calendar
, UErrorCode
& status
);
1453 * Called by several of the constructors to load pattern data and formatting symbols
1454 * out of a resource bundle and initialize the locale based on it.
1455 * @param timeStyle The time style, as passed to DateFormat::createDateInstance().
1456 * @param dateStyle The date style, as passed to DateFormat::createTimeInstance().
1457 * @param locale The locale to load the patterns from.
1458 * @param status Filled in with an error code if loading the data from the
1461 void construct(EStyle timeStyle
, EStyle dateStyle
, const Locale
& locale
, UErrorCode
& status
);
1464 * Called by construct() and the various constructors to set up the SimpleDateFormat's
1465 * Calendar and NumberFormat objects.
1466 * @param locale The locale for which we want a Calendar and a NumberFormat.
1467 * @param status Filled in with an error code if creating either subobject fails.
1469 void initialize(const Locale
& locale
, UErrorCode
& status
);
1472 * Private code-size reduction function used by subParse.
1473 * @param text the time text being parsed.
1474 * @param start where to start parsing.
1475 * @param field the date field being parsed.
1476 * @param stringArray the string array to parsed.
1477 * @param stringArrayCount the size of the array.
1478 * @param monthPattern pointer to leap month pattern, or NULL if none.
1479 * @param cal a Calendar set to the date and time to be formatted
1480 * into a date/time string.
1481 * @return the new start position if matching succeeded; a negative number
1482 * indicating matching failure, otherwise.
1484 int32_t matchString(const UnicodeString
& text
, int32_t start
, UCalendarDateFields field
,
1485 const UnicodeString
* stringArray
, int32_t stringArrayCount
,
1486 const UnicodeString
* monthPattern
, Calendar
& cal
) const;
1489 * Private code-size reduction function used by subParse.
1490 * @param text the time text being parsed.
1491 * @param start where to start parsing.
1492 * @param field the date field being parsed.
1493 * @param stringArray the string array to parsed.
1494 * @param stringArrayCount the size of the array.
1495 * @param cal a Calendar set to the date and time to be formatted
1496 * into a date/time string.
1497 * @return the new start position if matching succeeded; a negative number
1498 * indicating matching failure, otherwise.
1500 int32_t matchQuarterString(const UnicodeString
& text
, int32_t start
, UCalendarDateFields field
,
1501 const UnicodeString
* stringArray
, int32_t stringArrayCount
, Calendar
& cal
) const;
1504 * Private function used by subParse to match literal pattern text.
1506 * @param pattern the pattern string
1507 * @param patternOffset the starting offset into the pattern text. On
1508 * outupt will be set the offset of the first non-literal character in the pattern
1509 * @param text the text being parsed
1510 * @param textOffset the starting offset into the text. On output
1511 * will be set to the offset of the character after the match
1512 * @param lenient <code>TRUE</code> if the parse is lenient, <code>FALSE</code> otherwise.
1514 * @return <code>TRUE</code> if the literal text could be matched, <code>FALSE</code> otherwise.
1516 static UBool
matchLiterals(const UnicodeString
&pattern
, int32_t &patternOffset
,
1517 const UnicodeString
&text
, int32_t &textOffset
, UBool lenient
);
1520 * Private member function that converts the parsed date strings into
1521 * timeFields. Returns -start (for ParsePosition) if failed.
1522 * @param text the time text to be parsed.
1523 * @param start where to start parsing.
1524 * @param ch the pattern character for the date field text to be parsed.
1525 * @param count the count of a pattern character.
1526 * @param obeyCount if true then the count is strictly obeyed.
1527 * @param allowNegative
1528 * @param ambiguousYear If true then the two-digit year == the default start year.
1529 * @param saveHebrewMonth Used to hang onto month until year is known.
1530 * @param cal a Calendar set to the date and time to be formatted
1531 * into a date/time string.
1533 * @param numericLeapMonthFormatter If non-null, used to parse numeric leap months.
1534 * @return the new start position if matching succeeded; a negative number
1535 * indicating matching failure, otherwise.
1537 int32_t subParse(const UnicodeString
& text
, int32_t& start
, UChar ch
, int32_t count
,
1538 UBool obeyCount
, UBool allowNegative
, UBool ambiguousYear
[], int32_t& saveHebrewMonth
, Calendar
& cal
,
1539 int32_t patLoc
, MessageFormat
* numericLeapMonthFormatter
) const;
1541 void parseInt(const UnicodeString
& text
,
1542 Formattable
& number
,
1544 UBool allowNegative
,
1545 NumberFormat
*fmt
) const;
1547 void parseInt(const UnicodeString
& text
,
1548 Formattable
& number
,
1551 UBool allowNegative
,
1552 NumberFormat
*fmt
) const;
1554 int32_t checkIntSuffix(const UnicodeString
& text
, int32_t start
,
1555 int32_t patLoc
, UBool isNegative
) const;
1558 * Translate a pattern, mapping each character in the from string to the
1559 * corresponding character in the to string. Return an error if the original
1560 * pattern contains an unmapped character, or if a quote is unmatched.
1561 * Quoted (single quotes only) material is not translated.
1562 * @param originalPattern the original pattern.
1563 * @param translatedPattern Output param to receive the translited pattern.
1564 * @param from the characters to be translited from.
1565 * @param to the characters to be translited to.
1566 * @param status Receives a status code, which will be U_ZERO_ERROR
1567 * if the operation succeeds.
1569 static void translatePattern(const UnicodeString
& originalPattern
,
1570 UnicodeString
& translatedPattern
,
1571 const UnicodeString
& from
,
1572 const UnicodeString
& to
,
1573 UErrorCode
& status
);
1576 * Sets the starting date of the 100-year window that dates with 2-digit years
1577 * are considered to fall within.
1578 * @param startDate the start date
1579 * @param status Receives a status code, which will be U_ZERO_ERROR
1580 * if the operation succeeds.
1582 void parseAmbiguousDatesAsAfter(UDate startDate
, UErrorCode
& status
);
1585 * Return the length matched by the given affix, or -1 if none.
1586 * Runs of white space in the affix, match runs of white space in
1588 * @param affix pattern string, taken as a literal
1589 * @param input input text
1590 * @param pos offset into input at which to begin matching
1591 * @return length of input that matches, or -1 if match failure
1593 int32_t compareSimpleAffix(const UnicodeString
& affix
,
1594 const UnicodeString
& input
,
1598 * Skip over a run of zero or more Pattern_White_Space characters at
1601 int32_t skipPatternWhiteSpace(const UnicodeString
& text
, int32_t pos
) const;
1604 * Skip over a run of zero or more isUWhiteSpace() characters at pos
1607 int32_t skipUWhiteSpace(const UnicodeString
& text
, int32_t pos
) const;
1610 * Initialize NumberFormat instances used for numbering system overrides.
1612 void initNumberFormatters(const Locale
&locale
,UErrorCode
&status
);
1615 * Get the numbering system to be used for a particular field.
1617 NumberFormat
* getNumberFormatByIndex(UDateFormatField index
) const;
1620 * Parse the given override string and set up structures for number formats
1622 void processOverrideString(const Locale
&locale
, const UnicodeString
&str
, int8_t type
, UErrorCode
&status
);
1625 * Used to map pattern characters to Calendar field identifiers.
1627 static const UCalendarDateFields fgPatternIndexToCalendarField
[];
1630 * Map index into pattern character string to DateFormat field number
1632 static const UDateFormatField fgPatternIndexToDateFormatField
[];
1635 * Lazy TimeZoneFormat instantiation, semantically const
1637 TimeZoneFormat
*tzFormat() const;
1640 * Used to map Calendar field to field level.
1641 * The larger the level, the smaller the field unit.
1642 * For example, UCAL_ERA level is 0, UCAL_YEAR level is 10,
1643 * UCAL_MONTH level is 20.
1645 static const int32_t fgCalendarFieldToLevel
[];
1646 static const int32_t fgPatternCharToLevel
[];
1649 * The formatting pattern for this formatter.
1651 UnicodeString fPattern
;
1654 * The numbering system override for dates.
1656 UnicodeString fDateOverride
;
1659 * The numbering system override for times.
1661 UnicodeString fTimeOverride
;
1665 * The original locale used (for reloading symbols)
1670 * A pointer to an object containing the strings to use in formatting (e.g.,
1671 * month and day names, AM and PM strings, time zone names, etc.)
1673 DateFormatSymbols
* fSymbols
; // Owned
1676 * The time zone formatter
1678 TimeZoneFormat
* fTimeZoneFormat
;
1681 * If dates have ambiguous years, we map them into the century starting
1682 * at defaultCenturyStart, which may be any date. If defaultCenturyStart is
1683 * set to SYSTEM_DEFAULT_CENTURY, which it is by default, then the system
1684 * values are used. The instance values defaultCenturyStart and
1685 * defaultCenturyStartYear are only used if explicitly set by the user
1686 * through the API method parseAmbiguousDatesAsAfter().
1688 UDate fDefaultCenturyStart
;
1691 * See documentation for defaultCenturyStart.
1693 /*transient*/ int32_t fDefaultCenturyStartYear
;
1695 int32_t tztype
; // here to avoid api change
1697 typedef struct NSOverride
{
1703 NumberFormat
**fNumberFormatters
;
1705 NSOverride
*fOverrideList
;
1707 UBool fHaveDefaultCentury
;
1709 UDisplayContext fCapitalizationContext
;
1713 SimpleDateFormat::get2DigitYearStart(UErrorCode
& /*status*/) const
1715 return fDefaultCenturyStart
;
1718 inline UnicodeString
&
1719 SimpleDateFormat::format(const Formattable
& obj
,
1720 UnicodeString
& appendTo
,
1721 UErrorCode
& status
) const {
1722 // Don't use Format:: - use immediate base class only,
1723 // in case immediate base modifies behavior later.
1724 return DateFormat::format(obj
, appendTo
, status
);
1727 inline UnicodeString
&
1728 SimpleDateFormat::format(const Formattable
& obj
,
1729 UnicodeString
& appendTo
,
1731 UErrorCode
& status
) const
1733 // Don't use Format:: - use immediate base class only,
1734 // in case immediate base modifies behavior later.
1735 return DateFormat::format(obj
, appendTo
, pos
, status
);
1738 inline UnicodeString
&
1739 SimpleDateFormat::format(const Formattable
& obj
,
1740 UnicodeString
& appendTo
,
1741 FieldPositionIterator
* posIter
,
1742 UErrorCode
& status
) const
1744 // Don't use Format:: - use immediate base class only,
1745 // in case immediate base modifies behavior later.
1746 return DateFormat::format(obj
, appendTo
, posIter
, status
);
1749 inline UnicodeString
&
1750 SimpleDateFormat::format(UDate date
,
1751 UnicodeString
& appendTo
,
1752 FieldPosition
& fieldPosition
) const {
1753 // Don't use Format:: - use immediate base class only,
1754 // in case immediate base modifies behavior later.
1755 return DateFormat::format(date
, appendTo
, fieldPosition
);
1758 inline UnicodeString
&
1759 SimpleDateFormat::format(UDate date
,
1760 UnicodeString
& appendTo
,
1761 FieldPositionIterator
* posIter
,
1762 UErrorCode
& status
) const {
1763 // Don't use Format:: - use immediate base class only,
1764 // in case immediate base modifies behavior later.
1765 return DateFormat::format(date
, appendTo
, posIter
, status
);
1768 inline UnicodeString
&
1769 SimpleDateFormat::format(UDate date
, UnicodeString
& appendTo
) const {
1770 return DateFormat::format(date
, appendTo
);
1775 #endif /* #if !UCONFIG_NO_FORMATTING */