1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 * Copyright (C) 1997-2016, International Business Machines Corporation and
5 * others. All Rights Reserved.
6 *******************************************************************************
7 *
8 * File SMPDTFMT.H
9 *
10 * Modification History:
11 *
12 * Date Name Description
13 * 02/19/97 aliu Converted from java.
14 * 07/09/97 helena Make ParsePosition into a class.
15 * 07/21/98 stephen Added GMT_PLUS, GMT_MINUS
16 * Changed setTwoDigitStartDate to set2DigitYearStart
17 * Changed getTwoDigitStartDate to get2DigitYearStart
18 * Removed subParseLong
19 * Removed getZoneIndex (added in DateFormatSymbols)
20 * 06/14/99 stephen Removed fgTimeZoneDataSuffix
21 * 10/14/99 aliu Updated class doc to describe 2-digit year parsing
22 * {j28 4182066}.
23 *******************************************************************************
24 */
25
26 #ifndef SMPDTFMT_H
27 #define SMPDTFMT_H
28
29 #include "unicode/utypes.h"
30
31 /**
32 * \file
33 * \brief C++ API: Format and parse dates in a language-independent manner.
34 */
35
36 #if !UCONFIG_NO_FORMATTING
37
38 #include "unicode/datefmt.h"
39 #include "unicode/udisplaycontext.h"
40 #include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */
41 #include "unicode/brkiter.h"
42
43 U_NAMESPACE_BEGIN
44
45 class DateFormatSymbols;
46 class DateFormat;
47 class MessageFormat;
48 class FieldPositionHandler;
49 class TimeZoneFormat;
50 class SharedNumberFormat;
51 class SimpleDateFormatMutableNFs;
52
53 namespace number {
54 class LocalizedNumberFormatter;
55 }
56
57 /**
58 *
59 * SimpleDateFormat is a concrete class for formatting and parsing dates in a
60 * language-independent manner. It allows for formatting (millis -> text),
61 * parsing (text -> millis), and normalization. Formats/Parses a date or time,
62 * which is the standard milliseconds since 24:00 GMT, Jan 1, 1970.
63 * <P>
64 * Clients are encouraged to create a date-time formatter using DateFormat::getInstance(),
65 * getDateInstance(), getDateInstance(), or getDateTimeInstance() rather than
66 * explicitly constructing an instance of SimpleDateFormat. This way, the client
67 * is guaranteed to get an appropriate formatting pattern for whatever locale the
68 * program is running in. However, if the client needs something more unusual than
69 * the default patterns in the locales, he can construct a SimpleDateFormat directly
70 * and give it an appropriate pattern (or use one of the factory methods on DateFormat
71 * and modify the pattern after the fact with toPattern() and applyPattern().
72 *
73 * <p><strong>Date and Time Patterns:</strong></p>
74 *
75 * <p>Date and time formats are specified by <em>date and time pattern</em> strings.
76 * Within date and time pattern strings, all unquoted ASCII letters [A-Za-z] are reserved
77 * as pattern letters representing calendar fields. <code>SimpleDateFormat</code> supports
78 * the date and time formatting algorithm and pattern letters defined by
79 * <a href="http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table">UTS#35
80 * Unicode Locale Data Markup Language (LDML)</a> and further documented for ICU in the
81 * <a href="https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table">ICU
82 * User Guide</a>. The following pattern letters are currently available (note that the actual
83 * values depend on CLDR and may change from the examples shown here):</p>
84 *
85 * <table border="1">
86 * <tr>
87 * <th>Field</th>
88 * <th style="text-align: center">Sym.</th>
89 * <th style="text-align: center">No.</th>
90 * <th>Example</th>
91 * <th>Description</th>
92 * </tr>
93 * <tr>
94 * <th rowspan="3">era</th>
95 * <td style="text-align: center" rowspan="3">G</td>
96 * <td style="text-align: center">1..3</td>
97 * <td>AD</td>
98 * <td rowspan="3">Era - Replaced with the Era string for the current date. One to three letters for the
99 * abbreviated form, four letters for the long (wide) form, five for the narrow form.</td>
100 * </tr>
101 * <tr>
102 * <td style="text-align: center">4</td>
103 * <td>Anno Domini</td>
104 * </tr>
105 * <tr>
106 * <td style="text-align: center">5</td>
107 * <td>A</td>
108 * </tr>
109 * <tr>
110 * <th rowspan="6">year</th>
111 * <td style="text-align: center">y</td>
112 * <td style="text-align: center">1..n</td>
113 * <td>1996</td>
114 * <td>Year. Normally the length specifies the padding, but for two letters it also specifies the maximum
115 * length. Example:<div align="center">
116 * <center>
117 * <table border="1" cellpadding="2" cellspacing="0">
118 * <tr>
119 * <th>Year</th>
120 * <th style="text-align: right">y</th>
121 * <th style="text-align: right">yy</th>
122 * <th style="text-align: right">yyy</th>
123 * <th style="text-align: right">yyyy</th>
124 * <th style="text-align: right">yyyyy</th>
125 * </tr>
126 * <tr>
127 * <td>AD 1</td>
128 * <td style="text-align: right">1</td>
129 * <td style="text-align: right">01</td>
130 * <td style="text-align: right">001</td>
131 * <td style="text-align: right">0001</td>
132 * <td style="text-align: right">00001</td>
133 * </tr>
134 * <tr>
135 * <td>AD 12</td>
136 * <td style="text-align: right">12</td>
137 * <td style="text-align: right">12</td>
138 * <td style="text-align: right">012</td>
139 * <td style="text-align: right">0012</td>
140 * <td style="text-align: right">00012</td>
141 * </tr>
142 * <tr>
143 * <td>AD 123</td>
144 * <td style="text-align: right">123</td>
145 * <td style="text-align: right">23</td>
146 * <td style="text-align: right">123</td>
147 * <td style="text-align: right">0123</td>
148 * <td style="text-align: right">00123</td>
149 * </tr>
150 * <tr>
151 * <td>AD 1234</td>
152 * <td style="text-align: right">1234</td>
153 * <td style="text-align: right">34</td>
154 * <td style="text-align: right">1234</td>
155 * <td style="text-align: right">1234</td>
156 * <td style="text-align: right">01234</td>
157 * </tr>
158 * <tr>
159 * <td>AD 12345</td>
160 * <td style="text-align: right">12345</td>
161 * <td style="text-align: right">45</td>
162 * <td style="text-align: right">12345</td>
163 * <td style="text-align: right">12345</td>
164 * <td style="text-align: right">12345</td>
165 * </tr>
166 * </table>
167 * </center></div>
168 * </td>
169 * </tr>
170 * <tr>
171 * <td style="text-align: center">Y</td>
172 * <td style="text-align: center">1..n</td>
173 * <td>1997</td>
174 * <td>Year (in "Week of Year" based calendars). Normally the length specifies the padding,
175 * but for two letters it also specifies the maximum length. This year designation is used in ISO
176 * year-week calendar as defined by ISO 8601, but can be used in non-Gregorian based calendar systems
177 * where week date processing is desired. May not always be the same value as calendar year.</td>
178 * </tr>
179 * <tr>
180 * <td style="text-align: center">u</td>
181 * <td style="text-align: center">1..n</td>
182 * <td>4601</td>
183 * <td>Extended year. This is a single number designating the year of this calendar system, encompassing
184 * all supra-year fields. For example, for the Julian calendar system, year numbers are positive, with an
185 * era of BCE or CE. An extended year value for the Julian calendar system assigns positive values to CE
186 * years and negative values to BCE years, with 1 BCE being year 0.</td>
187 * </tr>
188 * <tr>
189 * <td style="text-align: center" rowspan="3">U</td>
190 * <td style="text-align: center">1..3</td>
191 * <td>甲子</td>
192 * <td rowspan="3">Cyclic year name. Calendars such as the Chinese lunar calendar (and related calendars)
193 * and the Hindu calendars use 60-year cycles of year names. Use one through three letters for the abbreviated
194 * name, four for the full (wide) name, or five for the narrow name (currently the data only provides abbreviated names,
195 * which will be used for all requested name widths). If the calendar does not provide cyclic year name data,
196 * or if the year value to be formatted is out of the range of years for which cyclic name data is provided,
197 * then numeric formatting is used (behaves like 'y').</td>
198 * </tr>
199 * <tr>
200 * <td style="text-align: center">4</td>
201 * <td>(currently also 甲子)</td>
202 * </tr>
203 * <tr>
204 * <td style="text-align: center">5</td>
205 * <td>(currently also 甲子)</td>
206 * </tr>
207 * <tr>
208 * <th rowspan="6">quarter</th>
209 * <td rowspan="3" style="text-align: center">Q</td>
210 * <td style="text-align: center">1..2</td>
211 * <td>02</td>
212 * <td rowspan="3">Quarter - Use one or two for the numerical quarter, three for the abbreviation, or four for the
213 * full (wide) name (five for the narrow name is not yet supported).</td>
214 * </tr>
215 * <tr>
216 * <td style="text-align: center">3</td>
217 * <td>Q2</td>
218 * </tr>
219 * <tr>
220 * <td style="text-align: center">4</td>
221 * <td>2nd quarter</td>
222 * </tr>
223 * <tr>
224 * <td rowspan="3" style="text-align: center">q</td>
225 * <td style="text-align: center">1..2</td>
226 * <td>02</td>
227 * <td rowspan="3"><b>Stand-Alone</b> Quarter - Use one or two for the numerical quarter, three for the abbreviation,
228 * or four for the full name (five for the narrow name is not yet supported).</td>
229 * </tr>
230 * <tr>
231 * <td style="text-align: center">3</td>
232 * <td>Q2</td>
233 * </tr>
234 * <tr>
235 * <td style="text-align: center">4</td>
236 * <td>2nd quarter</td>
237 * </tr>
238 * <tr>
239 * <th rowspan="8">month</th>
240 * <td rowspan="4" style="text-align: center">M</td>
241 * <td style="text-align: center">1..2</td>
242 * <td>09</td>
243 * <td rowspan="4">Month - Use one or two for the numerical month, three for the abbreviation, four for
244 * the full (wide) name, or five for the narrow name. With two ("MM"), the month number is zero-padded
245 * if necessary (e.g. "08")</td>
246 * </tr>
247 * <tr>
248 * <td style="text-align: center">3</td>
249 * <td>Sep</td>
250 * </tr>
251 * <tr>
252 * <td style="text-align: center">4</td>
253 * <td>September</td>
254 * </tr>
255 * <tr>
256 * <td style="text-align: center">5</td>
257 * <td>S</td>
258 * </tr>
259 * <tr>
260 * <td rowspan="4" style="text-align: center">L</td>
261 * <td style="text-align: center">1..2</td>
262 * <td>09</td>
263 * <td rowspan="4"><b>Stand-Alone</b> Month - Use one or two for the numerical month, three for the abbreviation,
264 * four for the full (wide) name, or 5 for the narrow name. With two ("LL"), the month number is zero-padded if
265 * necessary (e.g. "08")</td>
266 * </tr>
267 * <tr>
268 * <td style="text-align: center">3</td>
269 * <td>Sep</td>
270 * </tr>
271 * <tr>
272 * <td style="text-align: center">4</td>
273 * <td>September</td>
274 * </tr>
275 * <tr>
276 * <td style="text-align: center">5</td>
277 * <td>S</td>
278 * </tr>
279 * <tr>
280 * <th rowspan="2">week</th>
281 * <td style="text-align: center">w</td>
282 * <td style="text-align: center">1..2</td>
283 * <td>27</td>
284 * <td>Week of Year. Use "w" to show the minimum number of digits, or "ww" to always show two digits
285 * (zero-padding if necessary, e.g. "08").</td>
286 * </tr>
287 * <tr>
288 * <td style="text-align: center">W</td>
289 * <td style="text-align: center">1</td>
290 * <td>3</td>
291 * <td>Week of Month</td>
292 * </tr>
293 * <tr>
294 * <th rowspan="4">day</th>
295 * <td style="text-align: center">d</td>
296 * <td style="text-align: center">1..2</td>
297 * <td>1</td>
298 * <td>Date - Day of the month. Use "d" to show the minimum number of digits, or "dd" to always show
299 * two digits (zero-padding if necessary, e.g. "08").</td>
300 * </tr>
301 * <tr>
302 * <td style="text-align: center">D</td>
303 * <td style="text-align: center">1..3</td>
304 * <td>345</td>
305 * <td>Day of year</td>
306 * </tr>
307 * <tr>
308 * <td style="text-align: center">F</td>
309 * <td style="text-align: center">1</td>
310 * <td>2</td>
311 * <td>Day of Week in Month. The example is for the 2nd Wed in July</td>
312 * </tr>
313 * <tr>
314 * <td style="text-align: center">g</td>
315 * <td style="text-align: center">1..n</td>
316 * <td>2451334</td>
317 * <td>Modified Julian day. This is different from the conventional Julian day number in two regards.
318 * First, it demarcates days at local zone midnight, rather than noon GMT. Second, it is a local number;
319 * that is, it depends on the local time zone. It can be thought of as a single number that encompasses
320 * all the date-related fields.</td>
321 * </tr>
322 * <tr>
323 * <th rowspan="14">week<br>
324 * day</th>
325 * <td rowspan="4" style="text-align: center">E</td>
326 * <td style="text-align: center">1..3</td>
327 * <td>Tue</td>
328 * <td rowspan="4">Day of week - Use one through three letters for the short day, four for the full (wide) name,
329 * five for the narrow name, or six for the short name.</td>
330 * </tr>
331 * <tr>
332 * <td style="text-align: center">4</td>
333 * <td>Tuesday</td>
334 * </tr>
335 * <tr>
336 * <td style="text-align: center">5</td>
337 * <td>T</td>
338 * </tr>
339 * <tr>
340 * <td style="text-align: center">6</td>
341 * <td>Tu</td>
342 * </tr>
343 * <tr>
344 * <td rowspan="5" style="text-align: center">e</td>
345 * <td style="text-align: center">1..2</td>
346 * <td>2</td>
347 * <td rowspan="5">Local day of week. Same as E except adds a numeric value that will depend on the local
348 * starting day of the week, using one or two letters. For this example, Monday is the first day of the week.</td>
349 * </tr>
350 * <tr>
351 * <td style="text-align: center">3</td>
352 * <td>Tue</td>
353 * </tr>
354 * <tr>
355 * <td style="text-align: center">4</td>
356 * <td>Tuesday</td>
357 * </tr>
358 * <tr>
359 * <td style="text-align: center">5</td>
360 * <td>T</td>
361 * </tr>
362 * <tr>
363 * <td style="text-align: center">6</td>
364 * <td>Tu</td>
365 * </tr>
366 * <tr>
367 * <td rowspan="5" style="text-align: center">c</td>
368 * <td style="text-align: center">1</td>
369 * <td>2</td>
370 * <td rowspan="5"><b>Stand-Alone</b> local day of week - Use one letter for the local numeric value (same
371 * as 'e'), three for the short day, four for the full (wide) name, five for the narrow name, or six for
372 * the short name.</td>
373 * </tr>
374 * <tr>
375 * <td style="text-align: center">3</td>
376 * <td>Tue</td>
377 * </tr>
378 * <tr>
379 * <td style="text-align: center">4</td>
380 * <td>Tuesday</td>
381 * </tr>
382 * <tr>
383 * <td style="text-align: center">5</td>
384 * <td>T</td>
385 * </tr>
386 * <tr>
387 * <td style="text-align: center">6</td>
388 * <td>Tu</td>
389 * </tr>
390 * <tr>
391 * <th>period</th>
392 * <td style="text-align: center">a</td>
393 * <td style="text-align: center">1</td>
394 * <td>AM</td>
395 * <td>AM or PM</td>
396 * </tr>
397 * <tr>
398 * <th rowspan="4">hour</th>
399 * <td style="text-align: center">h</td>
400 * <td style="text-align: center">1..2</td>
401 * <td>11</td>
402 * <td>Hour [1-12]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern
403 * generation, it should match the 12-hour-cycle format preferred by the locale (h or K); it should not match
404 * a 24-hour-cycle format (H or k). Use hh for zero padding.</td>
405 * </tr>
406 * <tr>
407 * <td style="text-align: center">H</td>
408 * <td style="text-align: center">1..2</td>
409 * <td>13</td>
410 * <td>Hour [0-23]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern
411 * generation, it should match the 24-hour-cycle format preferred by the locale (H or k); it should not match a
412 * 12-hour-cycle format (h or K). Use HH for zero padding.</td>
413 * </tr>
414 * <tr>
415 * <td style="text-align: center">K</td>
416 * <td style="text-align: center">1..2</td>
417 * <td>0</td>
418 * <td>Hour [0-11]. When used in a skeleton, only matches K or h, see above. Use KK for zero padding.</td>
419 * </tr>
420 * <tr>
421 * <td style="text-align: center">k</td>
422 * <td style="text-align: center">1..2</td>
423 * <td>24</td>
424 * <td>Hour [1-24]. When used in a skeleton, only matches k or H, see above. Use kk for zero padding.</td>
425 * </tr>
426 * <tr>
427 * <th>minute</th>
428 * <td style="text-align: center">m</td>
429 * <td style="text-align: center">1..2</td>
430 * <td>59</td>
431 * <td>Minute. Use "m" to show the minimum number of digits, or "mm" to always show two digits
432 * (zero-padding if necessary, e.g. "08").</td>
433 * </tr>
434 * <tr>
435 * <th rowspan="3">second</th>
436 * <td style="text-align: center">s</td>
437 * <td style="text-align: center">1..2</td>
438 * <td>12</td>
439 * <td>Second. Use "s" to show the minimum number of digits, or "ss" to always show two digits
440 * (zero-padding if necessary, e.g. "08").</td>
441 * </tr>
442 * <tr>
443 * <td style="text-align: center">S</td>
444 * <td style="text-align: center">1..n</td>
445 * <td>3450</td>
446 * <td>Fractional Second - truncates (like other time fields) to the count of letters when formatting.
447 * Appends zeros if more than 3 letters specified. Truncates at three significant digits when parsing.
448 * (example shows display using pattern SSSS for seconds value 12.34567)</td>
449 * </tr>
450 * <tr>
451 * <td style="text-align: center">A</td>
452 * <td style="text-align: center">1..n</td>
453 * <td>69540000</td>
454 * <td>Milliseconds in day. This field behaves <i>exactly</i> like a composite of all time-related fields,
455 * not including the zone fields. As such, it also reflects discontinuities of those fields on DST transition
456 * days. On a day of DST onset, it will jump forward. On a day of DST cessation, it will jump backward. This
457 * reflects the fact that is must be combined with the offset field to obtain a unique local time value.</td>
458 * </tr>
459 * <tr>
460 * <th rowspan="23">zone</th>
461 * <td rowspan="2" style="text-align: center">z</td>
462 * <td style="text-align: center">1..3</td>
463 * <td>PDT</td>
464 * <td>The <i>short specific non-location format</i>.
465 * Where that is unavailable, falls back to the <i>short localized GMT format</i> ("O").</td>
466 * </tr>
467 * <tr>
468 * <td style="text-align: center">4</td>
469 * <td>Pacific Daylight Time</td>
470 * <td>The <i>long specific non-location format</i>.
471 * Where that is unavailable, falls back to the <i>long localized GMT format</i> ("OOOO").</td>
472 * </tr>
473 * <tr>
474 * <td rowspan="3" style="text-align: center">Z</td>
475 * <td style="text-align: center">1..3</td>
476 * <td>-0800</td>
477 * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
478 * The format is equivalent to RFC 822 zone format (when optional seconds field is absent).
479 * This is equivalent to the "xxxx" specifier.</td>
480 * </tr>
481 * <tr>
482 * <td style="text-align: center">4</td>
483 * <td>GMT-8:00</td>
484 * <td>The <i>long localized GMT format</i>.
485 * This is equivalent to the "OOOO" specifier.</td>
486 * </tr>
487 * <tr>
488 * <td style="text-align: center">5</td>
489 * <td>-08:00<br>
490 * -07:52:58</td>
491 * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
492 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.
493 * This is equivalent to the "XXXXX" specifier.</td>
494 * </tr>
495 * <tr>
496 * <td rowspan="2" style="text-align: center">O</td>
497 * <td style="text-align: center">1</td>
498 * <td>GMT-8</td>
499 * <td>The <i>short localized GMT format</i>.</td>
500 * </tr>
501 * <tr>
502 * <td style="text-align: center">4</td>
503 * <td>GMT-08:00</td>
504 * <td>The <i>long localized GMT format</i>.</td>
505 * </tr>
506 * <tr>
507 * <td rowspan="2" style="text-align: center">v</td>
508 * <td style="text-align: center">1</td>
509 * <td>PT</td>
510 * <td>The <i>short generic non-location format</i>.
511 * Where that is unavailable, falls back to the <i>generic location format</i> ("VVVV"),
512 * then the <i>short localized GMT format</i> as the final fallback.</td>
513 * </tr>
514 * <tr>
515 * <td style="text-align: center">4</td>
516 * <td>Pacific Time</td>
517 * <td>The <i>long generic non-location format</i>.
518 * Where that is unavailable, falls back to <i>generic location format</i> ("VVVV").
519 * </tr>
520 * <tr>
521 * <td rowspan="4" style="text-align: center">V</td>
522 * <td style="text-align: center">1</td>
523 * <td>uslax</td>
524 * <td>The short time zone ID.
525 * Where that is unavailable, the special short time zone ID <i>unk</i> (Unknown Zone) is used.<br>
526 * <i><b>Note</b>: This specifier was originally used for a variant of the short specific non-location format,
527 * but it was deprecated in the later version of the LDML specification. In CLDR 23/ICU 51, the definition of
528 * the specifier was changed to designate a short time zone ID.</i></td>
529 * </tr>
530 * <tr>
531 * <td style="text-align: center">2</td>
532 * <td>America/Los_Angeles</td>
533 * <td>The long time zone ID.</td>
534 * </tr>
535 * <tr>
536 * <td style="text-align: center">3</td>
537 * <td>Los Angeles</td>
538 * <td>The exemplar city (location) for the time zone.
539 * Where that is unavailable, the localized exemplar city name for the special zone <i>Etc/Unknown</i> is used
540 * as the fallback (for example, "Unknown City"). </td>
541 * </tr>
542 * <tr>
543 * <td style="text-align: center">4</td>
544 * <td>Los Angeles Time</td>
545 * <td>The <i>generic location format</i>.
546 * Where that is unavailable, falls back to the <i>long localized GMT format</i> ("OOOO";
547 * Note: Fallback is only necessary with a GMT-style Time Zone ID, like Etc/GMT-830.)<br>
548 * This is especially useful when presenting possible timezone choices for user selection,
549 * since the naming is more uniform than the "v" format.</td>
550 * </tr>
551 * <tr>
552 * <td rowspan="5" style="text-align: center">X</td>
553 * <td style="text-align: center">1</td>
554 * <td>-08<br>
555 * +0530<br>
556 * Z</td>
557 * <td>The <i>ISO8601 basic format</i> with hours field and optional minutes field.
558 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
559 * </tr>
560 * <tr>
561 * <td style="text-align: center">2</td>
562 * <td>-0800<br>
563 * Z</td>
564 * <td>The <i>ISO8601 basic format</i> with hours and minutes fields.
565 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
566 * </tr>
567 * <tr>
568 * <td style="text-align: center">3</td>
569 * <td>-08:00<br>
570 * Z</td>
571 * <td>The <i>ISO8601 extended format</i> with hours and minutes fields.
572 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
573 * </tr>
574 * <tr>
575 * <td style="text-align: center">4</td>
576 * <td>-0800<br>
577 * -075258<br>
578 * Z</td>
579 * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
580 * (Note: The seconds field is not supported by the ISO8601 specification.)
581 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
582 * </tr>
583 * <tr>
584 * <td style="text-align: center">5</td>
585 * <td>-08:00<br>
586 * -07:52:58<br>
587 * Z</td>
588 * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
589 * (Note: The seconds field is not supported by the ISO8601 specification.)
590 * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
591 * </tr>
592 * <tr>
593 * <td rowspan="5" style="text-align: center">x</td>
594 * <td style="text-align: center">1</td>
595 * <td>-08<br>
596 * +0530</td>
597 * <td>The <i>ISO8601 basic format</i> with hours field and optional minutes field.</td>
598 * </tr>
599 * <tr>
600 * <td style="text-align: center">2</td>
601 * <td>-0800</td>
602 * <td>The <i>ISO8601 basic format</i> with hours and minutes fields.</td>
603 * </tr>
604 * <tr>
605 * <td style="text-align: center">3</td>
606 * <td>-08:00</td>
607 * <td>The <i>ISO8601 extended format</i> with hours and minutes fields.</td>
608 * </tr>
609 * <tr>
610 * <td style="text-align: center">4</td>
611 * <td>-0800<br>
612 * -075258</td>
613 * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
614 * (Note: The seconds field is not supported by the ISO8601 specification.)</td>
615 * </tr>
616 * <tr>
617 * <td style="text-align: center">5</td>
618 * <td>-08:00<br>
619 * -07:52:58</td>
620 * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
621 * (Note: The seconds field is not supported by the ISO8601 specification.)</td>
622 * </tr>
623 * </table>
624 *
625 * <P>
626 * Any characters in the pattern that are not in the ranges of ['a'..'z'] and
627 * ['A'..'Z'] will be treated as quoted text. For instance, characters
628 * like ':', '.', ' ', '#' and '@' will appear in the resulting time text
629 * even they are not embraced within single quotes.
630 * <P>
631 * A pattern containing any invalid pattern letter will result in a failing
632 * UErrorCode result during formatting or parsing.
633 * <P>
634 * Examples using the US locale:
635 * <pre>
636 * \code
637 * Format Pattern Result
638 * -------------- -------
639 * "yyyy.MM.dd G 'at' HH:mm:ss vvvv" ->> 1996.07.10 AD at 15:08:56 Pacific Time
640 * "EEE, MMM d, ''yy" ->> Wed, July 10, '96
641 * "h:mm a" ->> 12:08 PM
642 * "hh 'o''clock' a, zzzz" ->> 12 o'clock PM, Pacific Daylight Time
643 * "K:mm a, vvv" ->> 0:00 PM, PT
644 * "yyyyy.MMMMM.dd GGG hh:mm aaa" ->> 1996.July.10 AD 12:08 PM
645 * \endcode
646 * </pre>
647 * Code Sample:
648 * <pre>
649 * \code
650 * UErrorCode success = U_ZERO_ERROR;
651 * SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "PST");
652 * pdt->setStartRule( Calendar::APRIL, 1, Calendar::SUNDAY, 2*60*60*1000);
653 * pdt->setEndRule( Calendar::OCTOBER, -1, Calendar::SUNDAY, 2*60*60*1000);
654 *
655 * // Format the current time.
656 * SimpleDateFormat* formatter
657 * = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz", success );
658 * GregorianCalendar cal(success);
659 * UDate currentTime_1 = cal.getTime(success);
660 * FieldPosition fp(FieldPosition::DONT_CARE);
661 * UnicodeString dateString;
662 * formatter->format( currentTime_1, dateString, fp );
663 * cout << "result: " << dateString << endl;
664 *
665 * // Parse the previous string back into a Date.
666 * ParsePosition pp(0);
667 * UDate currentTime_2 = formatter->parse(dateString, pp );
668 * \endcode
669 * </pre>
670 * In the above example, the time value "currentTime_2" obtained from parsing
671 * will be equal to currentTime_1. However, they may not be equal if the am/pm
672 * marker 'a' is left out from the format pattern while the "hour in am/pm"
673 * pattern symbol is used. This information loss can happen when formatting the
674 * time in PM.
675 *
676 * <p>
677 * When parsing a date string using the abbreviated year pattern ("y" or "yy"),
678 * SimpleDateFormat must interpret the abbreviated year
679 * relative to some century. It does this by adjusting dates to be
680 * within 80 years before and 20 years after the time the SimpleDateFormat
681 * instance is created. For example, using a pattern of "MM/dd/yy" and a
682 * SimpleDateFormat instance created on Jan 1, 1997, the string
683 * "01/11/12" would be interpreted as Jan 11, 2012 while the string "05/04/64"
684 * would be interpreted as May 4, 1964.
685 * During parsing, only strings consisting of exactly two digits, as defined by
686 * <code>Unicode::isDigit()</code>, will be parsed into the default century.
687 * Any other numeric string, such as a one digit string, a three or more digit
688 * string, or a two digit string that isn't all digits (for example, "-1"), is
689 * interpreted literally. So "01/02/3" or "01/02/003" are parsed (for the
690 * Gregorian calendar), using the same pattern, as Jan 2, 3 AD. Likewise (but
691 * only in lenient parse mode, the default) "01/02/-3" is parsed as Jan 2, 4 BC.
692 *
693 * <p>
694 * If the year pattern has more than two 'y' characters, the year is
695 * interpreted literally, regardless of the number of digits. So using the
696 * pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
697 *
698 * <p>
699 * When numeric fields abut one another directly, with no intervening delimiter
700 * characters, they constitute a run of abutting numeric fields. Such runs are
701 * parsed specially. For example, the format "HHmmss" parses the input text
702 * "123456" to 12:34:56, parses the input text "12345" to 1:23:45, and fails to
703 * parse "1234". In other words, the leftmost field of the run is flexible,
704 * while the others keep a fixed width. If the parse fails anywhere in the run,
705 * then the leftmost field is shortened by one character, and the entire run is
706 * parsed again. This is repeated until either the parse succeeds or the
707 * leftmost field is one character in length. If the parse still fails at that
708 * point, the parse of the run fails.
709 *
710 * <P>
711 * For time zones that have no names, SimpleDateFormat uses strings GMT+hours:minutes or
712 * GMT-hours:minutes.
713 * <P>
714 * The calendar defines what is the first day of the week, the first week of the
715 * year, whether hours are zero based or not (0 vs 12 or 24), and the timezone.
716 * There is one common number format to handle all the numbers; the digit count
717 * is handled programmatically according to the pattern.
718 *
719 * <p><em>User subclasses are not supported.</em> While clients may write
720 * subclasses, such code will not necessarily work and will not be
721 * guaranteed to work stably from release to release.
722 */
723 class U_I18N_API SimpleDateFormat: public DateFormat {
724 public:
725 /**
726 * Construct a SimpleDateFormat using the default pattern for the default
727 * locale.
728 * <P>
729 * [Note:] Not all locales support SimpleDateFormat; for full generality,
730 * use the factory methods in the DateFormat class.
731 * @param status Output param set to success/failure code.
732 * @stable ICU 2.0
733 */
734 SimpleDateFormat(UErrorCode& status);
735
736 /**
737 * Construct a SimpleDateFormat using the given pattern and the default locale.
738 * The locale is used to obtain the symbols used in formatting (e.g., the
739 * names of the months), but not to provide the pattern.
740 * <P>
741 * [Note:] Not all locales support SimpleDateFormat; for full generality,
742 * use the factory methods in the DateFormat class.
743 * @param pattern the pattern for the format.
744 * @param status Output param set to success/failure code.
745 * @stable ICU 2.0
746 */
747 SimpleDateFormat(const UnicodeString& pattern,
748 UErrorCode& status);
749
750 /**
751 * Construct a SimpleDateFormat using the given pattern, numbering system override, and the default locale.
752 * The locale is used to obtain the symbols used in formatting (e.g., the
753 * names of the months), but not to provide the pattern.
754 * <P>
755 * A numbering system override is a string containing either the name of a known numbering system,
756 * or a set of field and numbering system pairs that specify which fields are to be formattied with
757 * the alternate numbering system. For example, to specify that all numeric fields in the specified
758 * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
759 * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering,
760 * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon
761 * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
762 *
763 * <P>
764 * [Note:] Not all locales support SimpleDateFormat; for full generality,
765 * use the factory methods in the DateFormat class.
766 * @param pattern the pattern for the format.
767 * @param override the override string.
768 * @param status Output param set to success/failure code.
769 * @stable ICU 4.2
770 */
771 SimpleDateFormat(const UnicodeString& pattern,
772 const UnicodeString& override,
773 UErrorCode& status);
774
775 /**
776 * Construct a SimpleDateFormat using the given pattern and locale.
777 * The locale is used to obtain the symbols used in formatting (e.g., the
778 * names of the months), but not to provide the pattern.
779 * <P>
780 * [Note:] Not all locales support SimpleDateFormat; for full generality,
781 * use the factory methods in the DateFormat class.
782 * @param pattern the pattern for the format.
783 * @param locale the given locale.
784 * @param status Output param set to success/failure code.
785 * @stable ICU 2.0
786 */
787 SimpleDateFormat(const UnicodeString& pattern,
788 const Locale& locale,
789 UErrorCode& status);
790
791 /**
792 * Construct a SimpleDateFormat using the given pattern, numbering system override, and locale.
793 * The locale is used to obtain the symbols used in formatting (e.g., the
794 * names of the months), but not to provide the pattern.
795 * <P>
796 * A numbering system override is a string containing either the name of a known numbering system,
797 * or a set of field and numbering system pairs that specify which fields are to be formattied with
798 * the alternate numbering system. For example, to specify that all numeric fields in the specified
799 * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
800 * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering,
801 * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon
802 * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
803 * <P>
804 * [Note:] Not all locales support SimpleDateFormat; for full generality,
805 * use the factory methods in the DateFormat class.
806 * @param pattern the pattern for the format.
807 * @param override the numbering system override.
808 * @param locale the given locale.
809 * @param status Output param set to success/failure code.
810 * @stable ICU 4.2
811 */
812 SimpleDateFormat(const UnicodeString& pattern,
813 const UnicodeString& override,
814 const Locale& locale,
815 UErrorCode& status);
816
817 /**
818 * Construct a SimpleDateFormat using the given pattern and locale-specific
819 * symbol data. The formatter takes ownership of the DateFormatSymbols object;
820 * the caller is no longer responsible for deleting it.
821 * @param pattern the given pattern for the format.
822 * @param formatDataToAdopt the symbols to be adopted.
823 * @param status Output param set to success/faulure code.
824 * @stable ICU 2.0
825 */
826 SimpleDateFormat(const UnicodeString& pattern,
827 DateFormatSymbols* formatDataToAdopt,
828 UErrorCode& status);
829
830 /**
831 * Construct a SimpleDateFormat using the given pattern and locale-specific
832 * symbol data. The DateFormatSymbols object is NOT adopted; the caller
833 * remains responsible for deleting it.
834 * @param pattern the given pattern for the format.
835 * @param formatData the formatting symbols to be use.
836 * @param status Output param set to success/faulure code.
837 * @stable ICU 2.0
838 */
839 SimpleDateFormat(const UnicodeString& pattern,
840 const DateFormatSymbols& formatData,
841 UErrorCode& status);
842
843 /**
844 * Copy constructor.
845 * @stable ICU 2.0
846 */
847 SimpleDateFormat(const SimpleDateFormat&);
848
849 /**
850 * Assignment operator.
851 * @stable ICU 2.0
852 */
853 SimpleDateFormat& operator=(const SimpleDateFormat&);
854
855 /**
856 * Destructor.
857 * @stable ICU 2.0
858 */
859 virtual ~SimpleDateFormat();
860
861 /**
862 * Clone this Format object polymorphically. The caller owns the result and
863 * should delete it when done.
864 * @return A copy of the object.
865 * @stable ICU 2.0
866 */
867 virtual Format* clone(void) const;
868
869 /**
870 * Return true if the given Format objects are semantically equal. Objects
871 * of different subclasses are considered unequal.
872 * @param other the object to be compared with.
873 * @return true if the given Format objects are semantically equal.
874 * @stable ICU 2.0
875 */
876 virtual UBool operator==(const Format& other) const;
877
878
879 using DateFormat::format;
880
881 /**
882 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
883 * 1, 1970. Overrides DateFormat pure virtual method.
884 * <P>
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
887 *
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 pos The formatting position. On input: an alignment field,
893 * if desired. On output: the offsets of the alignment field.
894 * @return Reference to 'appendTo' parameter.
895 * @stable ICU 2.1
896 */
897 virtual UnicodeString& format( Calendar& cal,
898 UnicodeString& appendTo,
899 FieldPosition& pos) const;
900
901 /**
902 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
903 * 1, 1970. Overrides DateFormat pure virtual method.
904 * <P>
905 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
906 * 1996.07.10 AD at 15:08:56 PDT
907 *
908 * @param cal Calendar set to the date and time to be formatted
909 * into a date/time string.
910 * @param appendTo Output parameter to receive result.
911 * Result is appended to existing contents.
912 * @param posIter On return, can be used to iterate over positions
913 * of fields generated by this format call. Field values
914 * are defined in UDateFormatField.
915 * @param status Input/output param set to success/failure code.
916 * @return Reference to 'appendTo' parameter.
917 * @stable ICU 4.4
918 */
919 virtual UnicodeString& format( Calendar& cal,
920 UnicodeString& appendTo,
921 FieldPositionIterator* posIter,
922 UErrorCode& status) const;
923
924 using DateFormat::parse;
925
926 /**
927 * Parse a date/time string beginning at the given parse position. For
928 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
929 * that is equivalent to Date(837039928046).
930 * <P>
931 * By default, parsing is lenient: If the input is not in the form used by
932 * this object's format method but can still be parsed as a date, then the
933 * parse succeeds. Clients may insist on strict adherence to the format by
934 * calling setLenient(false).
935 * @see DateFormat::setLenient(boolean)
936 *
937 * @param text The date/time string to be parsed
938 * @param cal A Calendar set on input to the date and time to be used for
939 * missing values in the date/time string being parsed, and set
940 * on output to the parsed date/time. When the calendar type is
941 * different from the internal calendar held by this SimpleDateFormat
942 * instance, the internal calendar will be cloned to a work
943 * calendar set to the same milliseconds and time zone as the
944 * cal parameter, field values will be parsed based on the work
945 * calendar, then the result (milliseconds and time zone) will
946 * be set in this calendar.
947 * @param pos On input, the position at which to start parsing; on
948 * output, the position at which parsing terminated, or the
949 * start position if the parse failed.
950 * @stable ICU 2.1
951 */
952 virtual void parse( const UnicodeString& text,
953 Calendar& cal,
954 ParsePosition& pos) const;
955
956
957 /**
958 * Set the start UDate used to interpret two-digit year strings.
959 * When dates are parsed having 2-digit year strings, they are placed within
960 * a assumed range of 100 years starting on the two digit start date. For
961 * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
962 * some other year. SimpleDateFormat chooses a year so that the resultant
963 * date is on or after the two digit start date and within 100 years of the
964 * two digit start date.
965 * <P>
966 * By default, the two digit start date is set to 80 years before the current
967 * time at which a SimpleDateFormat object is created.
968 * @param d start UDate used to interpret two-digit year strings.
969 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
970 * an error value if there was a parse error.
971 * @stable ICU 2.0
972 */
973 virtual void set2DigitYearStart(UDate d, UErrorCode& status);
974
975 /**
976 * Get the start UDate used to interpret two-digit year strings.
977 * When dates are parsed having 2-digit year strings, they are placed within
978 * a assumed range of 100 years starting on the two digit start date. For
979 * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
980 * some other year. SimpleDateFormat chooses a year so that the resultant
981 * date is on or after the two digit start date and within 100 years of the
982 * two digit start date.
983 * <P>
984 * By default, the two digit start date is set to 80 years before the current
985 * time at which a SimpleDateFormat object is created.
986 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
987 * an error value if there was a parse error.
988 * @stable ICU 2.0
989 */
990 UDate get2DigitYearStart(UErrorCode& status) const;
991
992 /**
993 * Return a pattern string describing this date format.
994 * @param result Output param to receive the pattern.
995 * @return A reference to 'result'.
996 * @stable ICU 2.0
997 */
998 virtual UnicodeString& toPattern(UnicodeString& result) const;
999
1000 /**
1001 * Return a localized pattern string describing this date format.
1002 * In most cases, this will return the same thing as toPattern(),
1003 * but a locale can specify characters to use in pattern descriptions
1004 * in place of the ones described in this class's class documentation.
1005 * (Presumably, letters that would be more mnemonic in that locale's
1006 * language.) This function would produce a pattern using those
1007 * letters.
1008 * <p>
1009 * <b>Note:</b> This implementation depends on DateFormatSymbols::getLocalPatternChars()
1010 * to get localized format pattern characters. ICU does not include
1011 * localized pattern character data, therefore, unless user sets localized
1012 * pattern characters manually, this method returns the same result as
1013 * toPattern().
1014 *
1015 * @param result Receives the localized pattern.
1016 * @param status Output param set to success/failure code on
1017 * exit. If the pattern is invalid, this will be
1018 * set to a failure result.
1019 * @return A reference to 'result'.
1020 * @stable ICU 2.0
1021 */
1022 virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
1023 UErrorCode& status) const;
1024
1025 /**
1026 * Apply the given unlocalized pattern string to this date format.
1027 * (i.e., after this call, this formatter will format dates according to
1028 * the new pattern)
1029 *
1030 * @param pattern The pattern to be applied.
1031 * @stable ICU 2.0
1032 */
1033 virtual void applyPattern(const UnicodeString& pattern);
1034
1035 /**
1036 * Apply the given localized pattern string to this date format.
1037 * (see toLocalizedPattern() for more information on localized patterns.)
1038 *
1039 * @param pattern The localized pattern to be applied.
1040 * @param status Output param set to success/failure code on
1041 * exit. If the pattern is invalid, this will be
1042 * set to a failure result.
1043 * @stable ICU 2.0
1044 */
1045 virtual void applyLocalizedPattern(const UnicodeString& pattern,
1046 UErrorCode& status);
1047
1048 /**
1049 * Gets the date/time formatting symbols (this is an object carrying
1050 * the various strings and other symbols used in formatting: e.g., month
1051 * names and abbreviations, time zone names, AM/PM strings, etc.)
1052 * @return a copy of the date-time formatting data associated
1053 * with this date-time formatter.
1054 * @stable ICU 2.0
1055 */
1056 virtual const DateFormatSymbols* getDateFormatSymbols(void) const;
1057
1058 /**
1059 * Set the date/time formatting symbols. The caller no longer owns the
1060 * DateFormatSymbols object and should not delete it after making this call.
1061 * @param newFormatSymbols the given date-time formatting symbols to copy.
1062 * @stable ICU 2.0
1063 */
1064 virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
1065
1066 /**
1067 * Set the date/time formatting data.
1068 * @param newFormatSymbols the given date-time formatting symbols to copy.
1069 * @stable ICU 2.0
1070 */
1071 virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
1072
1073 /**
1074 * Return the class ID for this class. This is useful only for comparing to
1075 * a return value from getDynamicClassID(). For example:
1076 * <pre>
1077 * . Base* polymorphic_pointer = createPolymorphicObject();
1078 * . if (polymorphic_pointer->getDynamicClassID() ==
1079 * . erived::getStaticClassID()) ...
1080 * </pre>
1081 * @return The class ID for all objects of this class.
1082 * @stable ICU 2.0
1083 */
1084 static UClassID U_EXPORT2 getStaticClassID(void);
1085
1086 /**
1087 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
1088 * method is to implement a simple version of RTTI, since not all C++
1089 * compilers support genuine RTTI. Polymorphic operator==() and clone()
1090 * methods call this method.
1091 *
1092 * @return The class ID for this object. All objects of a
1093 * given class have the same class ID. Objects of
1094 * other classes have different class IDs.
1095 * @stable ICU 2.0
1096 */
1097 virtual UClassID getDynamicClassID(void) const;
1098
1099 /**
1100 * Set the calendar to be used by this date format. Initially, the default
1101 * calendar for the specified or default locale is used. The caller should
1102 * not delete the Calendar object after it is adopted by this call.
1103 * Adopting a new calendar will change to the default symbols.
1104 *
1105 * @param calendarToAdopt Calendar object to be adopted.
1106 * @stable ICU 2.0
1107 */
1108 virtual void adoptCalendar(Calendar* calendarToAdopt);
1109
1110 /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
1111 /**
1112 * Sets the TimeZoneFormat to be used by this date/time formatter.
1113 * The caller should not delete the TimeZoneFormat object after
1114 * it is adopted by this call.
1115 * @param timeZoneFormatToAdopt The TimeZoneFormat object to be adopted.
1116 * @internal ICU 49 technology preview
1117 */
1118 virtual void adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt);
1119
1120 /**
1121 * Sets the TimeZoneFormat to be used by this date/time formatter.
1122 * @param newTimeZoneFormat The TimeZoneFormat object to copy.
1123 * @internal ICU 49 technology preview
1124 */
1125 virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat);
1126
1127 /**
1128 * Gets the time zone format object associated with this date/time formatter.
1129 * @return the time zone format associated with this date/time formatter.
1130 * @internal ICU 49 technology preview
1131 */
1132 virtual const TimeZoneFormat* getTimeZoneFormat(void) const;
1133
1134 /**
1135 * Set a particular UDisplayContext value in the formatter, such as
1136 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. Note: For getContext, see
1137 * DateFormat.
1138 * @param value The UDisplayContext value to set.
1139 * @param status Input/output status. If at entry this indicates a failure
1140 * status, the function will do nothing; otherwise this will be
1141 * updated with any new status from the function.
1142 * @stable ICU 53
1143 */
1144 virtual void setContext(UDisplayContext value, UErrorCode& status);
1145
1146 /**
1147 * Overrides base class method and
1148 * This method clears per field NumberFormat instances
1149 * previously set by {@see adoptNumberFormat(const UnicodeString&, NumberFormat*, UErrorCode)}
1150 * @param formatToAdopt the NumbeferFormat used
1151 * @stable ICU 54
1152 */
1153 void adoptNumberFormat(NumberFormat *formatToAdopt);
1154
1155 /**
1156 * Allow the user to set the NumberFormat for several fields
1157 * It can be a single field like: "y"(year) or "M"(month)
1158 * It can be several field combined together: "yM"(year and month)
1159 * Note:
1160 * 1 symbol field is enough for multiple symbol field (so "y" will override "yy", "yyy")
1161 * If the field is not numeric, then override has no effect (like "MMM" will use abbreviation, not numerical field)
1162 * Per field NumberFormat can also be cleared in {@see DateFormat::setNumberFormat(const NumberFormat& newNumberFormat)}
1163 *
1164 * @param fields the fields to override(like y)
1165 * @param formatToAdopt the NumbeferFormat used
1166 * @param status Receives a status code, which will be U_ZERO_ERROR
1167 * if the operation succeeds.
1168 * @stable ICU 54
1169 */
1170 void adoptNumberFormat(const UnicodeString& fields, NumberFormat *formatToAdopt, UErrorCode &status);
1171
1172 /**
1173 * Get the numbering system to be used for a particular field.
1174 * @param field The UDateFormatField to get
1175 * @stable ICU 54
1176 */
1177 const NumberFormat * getNumberFormatForField(char16_t field) const;
1178
1179 #ifndef U_HIDE_INTERNAL_API
1180 /**
1181 * This is for ICU internal use only. Please do not use.
1182 * Check whether the 'field' is smaller than all the fields covered in
1183 * pattern, return TRUE if it is. The sequence of calendar field,
1184 * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
1185 * @param field the calendar field need to check against
1186 * @return TRUE if the 'field' is smaller than all the fields
1187 * covered in pattern. FALSE otherwise.
1188 * @internal ICU 4.0
1189 */
1190 UBool isFieldUnitIgnored(UCalendarDateFields field) const;
1191
1192
1193 /**
1194 * This is for ICU internal use only. Please do not use.
1195 * Check whether the 'field' is smaller than all the fields covered in
1196 * pattern, return TRUE if it is. The sequence of calendar field,
1197 * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
1198 * @param pattern the pattern to check against
1199 * @param field the calendar field need to check against
1200 * @return TRUE if the 'field' is smaller than all the fields
1201 * covered in pattern. FALSE otherwise.
1202 * @internal ICU 4.0
1203 */
1204 static UBool isFieldUnitIgnored(const UnicodeString& pattern,
1205 UCalendarDateFields field);
1206
1207 /**
1208 * This is for ICU internal use only. Please do not use.
1209 * Get the locale of this simple date formatter.
1210 * It is used in DateIntervalFormat.
1211 *
1212 * @return locale in this simple date formatter
1213 * @internal ICU 4.0
1214 */
1215 const Locale& getSmpFmtLocale(void) const;
1216 #endif /* U_HIDE_INTERNAL_API */
1217
1218 private:
1219 friend class DateFormat;
1220
1221 void initializeDefaultCentury(void);
1222
1223 void initializeBooleanAttributes(void);
1224
1225 SimpleDateFormat(); // default constructor not implemented
1226
1227 /**
1228 * Used by the DateFormat factory methods to construct a SimpleDateFormat.
1229 * @param timeStyle the time style.
1230 * @param dateStyle the date style.
1231 * @param locale the given locale.
1232 * @param status Output param set to success/failure code on
1233 * exit.
1234 */
1235 SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1236
1237 /**
1238 * Construct a SimpleDateFormat for the given locale. If no resource data
1239 * is available, create an object of last resort, using hard-coded strings.
1240 * This is an internal method, called by DateFormat. It should never fail.
1241 * @param locale the given locale.
1242 * @param status Output param set to success/failure code on
1243 * exit.
1244 */
1245 SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
1246
1247 /**
1248 * Hook called by format(... FieldPosition& ...) and format(...FieldPositionIterator&...)
1249 */
1250 UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
1251
1252 /**
1253 * Called by format() to format a single field.
1254 *
1255 * @param appendTo Output parameter to receive result.
1256 * Result is appended to existing contents.
1257 * @param ch The format character we encountered in the pattern.
1258 * @param count Number of characters in the current pattern symbol (e.g.,
1259 * "yyyy" in the pattern would result in a call to this function
1260 * with ch equal to 'y' and count equal to 4)
1261 * @param capitalizationContext Capitalization context for this date format.
1262 * @param fieldNum Zero-based numbering of current field within the overall format.
1263 * @param handler Records information about field positions.
1264 * @param cal Calendar to use
1265 * @param status Receives a status code, which will be U_ZERO_ERROR if the operation
1266 * succeeds.
1267 */
1268 void subFormat(UnicodeString &appendTo,
1269 char16_t ch,
1270 int32_t count,
1271 UDisplayContext capitalizationContext,
1272 int32_t fieldNum,
1273 FieldPositionHandler& handler,
1274 Calendar& cal,
1275 UErrorCode& status) const; // in case of illegal argument
1276
1277 /**
1278 * Used by subFormat() to format a numeric value.
1279 * Appends to toAppendTo a string representation of "value"
1280 * having a number of digits between "minDigits" and
1281 * "maxDigits". Uses the DateFormat's NumberFormat.
1282 *
1283 * @param currentNumberFormat
1284 * @param appendTo Output parameter to receive result.
1285 * Formatted number is appended to existing contents.
1286 * @param value Value to format.
1287 * @param minDigits Minimum number of digits the result should have
1288 * @param maxDigits Maximum number of digits the result should have
1289 */
1290 void zeroPaddingNumber(const NumberFormat *currentNumberFormat,
1291 UnicodeString &appendTo,
1292 int32_t value,
1293 int32_t minDigits,
1294 int32_t maxDigits) const;
1295
1296 /**
1297 * Return true if the given format character, occuring count
1298 * times, represents a numeric field.
1299 */
1300 static UBool isNumeric(char16_t formatChar, int32_t count);
1301
1302 /**
1303 * Returns TRUE if the patternOffset is at the start of a numeric field.
1304 */
1305 static UBool isAtNumericField(const UnicodeString &pattern, int32_t patternOffset);
1306
1307 /**
1308 * Returns TRUE if the patternOffset is right after a non-numeric field.
1309 */
1310 static UBool isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset);
1311
1312 /**
1313 * initializes fCalendar from parameters. Returns fCalendar as a convenience.
1314 * @param adoptZone Zone to be adopted, or NULL for TimeZone::createDefault().
1315 * @param locale Locale of the calendar
1316 * @param status Error code
1317 * @return the newly constructed fCalendar
1318 */
1319 Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
1320
1321 /**
1322 * Called by several of the constructors to load pattern data and formatting symbols
1323 * out of a resource bundle and initialize the locale based on it.
1324 * @param timeStyle The time style, as passed to DateFormat::createDateInstance().
1325 * @param dateStyle The date style, as passed to DateFormat::createTimeInstance().
1326 * @param locale The locale to load the patterns from.
1327 * @param status Filled in with an error code if loading the data from the
1328 * resources fails.
1329 */
1330 void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1331
1332 /**
1333 * Called by construct() and the various constructors to set up the SimpleDateFormat's
1334 * Calendar and NumberFormat objects.
1335 * @param locale The locale for which we want a Calendar and a NumberFormat.
1336 * @param status Filled in with an error code if creating either subobject fails.
1337 */
1338 void initialize(const Locale& locale, UErrorCode& status);
1339
1340 /**
1341 * Private code-size reduction function used by subParse.
1342 * @param text the time text being parsed.
1343 * @param start where to start parsing.
1344 * @param field the date field being parsed.
1345 * @param stringArray the string array to parsed.
1346 * @param stringArrayCount the size of the array.
1347 * @param monthPattern pointer to leap month pattern, or NULL if none.
1348 * @param cal a Calendar set to the date and time to be formatted
1349 * into a date/time string.
1350 * @return the new start position if matching succeeded; a negative number
1351 * indicating matching failure, otherwise.
1352 */
1353 int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1354 const UnicodeString* stringArray, int32_t stringArrayCount,
1355 const UnicodeString* monthPattern, Calendar& cal) const;
1356
1357 /**
1358 * Private code-size reduction function used by subParse.
1359 * @param text the time text being parsed.
1360 * @param start where to start parsing.
1361 * @param field the date field being parsed.
1362 * @param stringArray the string array to parsed.
1363 * @param stringArrayCount the size of the array.
1364 * @param cal a Calendar set to the date and time to be formatted
1365 * into a date/time string.
1366 * @return the new start position if matching succeeded; a negative number
1367 * indicating matching failure, otherwise.
1368 */
1369 int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1370 const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
1371
1372 /**
1373 * Used by subParse() to match localized day period strings.
1374 */
1375 int32_t matchDayPeriodStrings(const UnicodeString& text, int32_t start,
1376 const UnicodeString* stringArray, int32_t stringArrayCount,
1377 int32_t &dayPeriod) const;
1378
1379 /**
1380 * Private function used by subParse to match literal pattern text.
1381 *
1382 * @param pattern the pattern string
1383 * @param patternOffset the starting offset into the pattern text. On
1384 * outupt will be set the offset of the first non-literal character in the pattern
1385 * @param text the text being parsed
1386 * @param textOffset the starting offset into the text. On output
1387 * will be set to the offset of the character after the match
1388 * @param whitespaceLenient <code>TRUE</code> if whitespace parse is lenient, <code>FALSE</code> otherwise.
1389 * @param partialMatchLenient <code>TRUE</code> if partial match parse is lenient, <code>FALSE</code> otherwise.
1390 * @param oldLeniency <code>TRUE</code> if old leniency control is lenient, <code>FALSE</code> otherwise.
1391 *
1392 * @return <code>TRUE</code> if the literal text could be matched, <code>FALSE</code> otherwise.
1393 */
1394 static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
1395 const UnicodeString &text, int32_t &textOffset,
1396 UBool whitespaceLenient, UBool partialMatchLenient, UBool oldLeniency);
1397
1398 /**
1399 * Private member function that converts the parsed date strings into
1400 * timeFields. Returns -start (for ParsePosition) if failed.
1401 * @param text the time text to be parsed.
1402 * @param start where to start parsing.
1403 * @param ch the pattern character for the date field text to be parsed.
1404 * @param count the count of a pattern character.
1405 * @param obeyCount if true then the count is strictly obeyed.
1406 * @param allowNegative
1407 * @param ambiguousYear If true then the two-digit year == the default start year.
1408 * @param saveHebrewMonth Used to hang onto month until year is known.
1409 * @param cal a Calendar set to the date and time to be formatted
1410 * into a date/time string.
1411 * @param patLoc
1412 * @param numericLeapMonthFormatter If non-null, used to parse numeric leap months.
1413 * @param tzTimeType the type of parsed time zone - standard, daylight or unknown (output).
1414 * This parameter can be NULL if caller does not need the information.
1415 * @return the new start position if matching succeeded; a negative number
1416 * indicating matching failure, otherwise.
1417 */
1418 int32_t subParse(const UnicodeString& text, int32_t& start, char16_t ch, int32_t count,
1419 UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
1420 int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType,
1421 int32_t *dayPeriod=NULL) const;
1422
1423 void parseInt(const UnicodeString& text,
1424 Formattable& number,
1425 ParsePosition& pos,
1426 UBool allowNegative,
1427 const NumberFormat *fmt) const;
1428
1429 void parseInt(const UnicodeString& text,
1430 Formattable& number,
1431 int32_t maxDigits,
1432 ParsePosition& pos,
1433 UBool allowNegative,
1434 const NumberFormat *fmt) const;
1435
1436 int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
1437 int32_t patLoc, UBool isNegative) const;
1438
1439 /**
1440 * Counts number of digit code points in the specified text.
1441 *
1442 * @param text input text
1443 * @param start start index, inclusive
1444 * @param end end index, exclusive
1445 * @return number of digits found in the text in the specified range.
1446 */
1447 int32_t countDigits(const UnicodeString& text, int32_t start, int32_t end) const;
1448
1449 /**
1450 * Translate a pattern, mapping each character in the from string to the
1451 * corresponding character in the to string. Return an error if the original
1452 * pattern contains an unmapped character, or if a quote is unmatched.
1453 * Quoted (single quotes only) material is not translated.
1454 * @param originalPattern the original pattern.
1455 * @param translatedPattern Output param to receive the translited pattern.
1456 * @param from the characters to be translited from.
1457 * @param to the characters to be translited to.
1458 * @param status Receives a status code, which will be U_ZERO_ERROR
1459 * if the operation succeeds.
1460 */
1461 static void translatePattern(const UnicodeString& originalPattern,
1462 UnicodeString& translatedPattern,
1463 const UnicodeString& from,
1464 const UnicodeString& to,
1465 UErrorCode& status);
1466
1467 /**
1468 * Sets the starting date of the 100-year window that dates with 2-digit years
1469 * are considered to fall within.
1470 * @param startDate the start date
1471 * @param status Receives a status code, which will be U_ZERO_ERROR
1472 * if the operation succeeds.
1473 */
1474 void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
1475
1476 /**
1477 * Return the length matched by the given affix, or -1 if none.
1478 * Runs of white space in the affix, match runs of white space in
1479 * the input.
1480 * @param affix pattern string, taken as a literal
1481 * @param input input text
1482 * @param pos offset into input at which to begin matching
1483 * @return length of input that matches, or -1 if match failure
1484 */
1485 int32_t compareSimpleAffix(const UnicodeString& affix,
1486 const UnicodeString& input,
1487 int32_t pos) const;
1488
1489 /**
1490 * Skip over a run of zero or more Pattern_White_Space characters at
1491 * pos in text.
1492 */
1493 int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
1494
1495 /**
1496 * Skip over a run of zero or more isUWhiteSpace() characters at pos
1497 * in text.
1498 */
1499 int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
1500
1501 /**
1502 * Initialize LocalizedNumberFormatter instances used for speedup.
1503 */
1504 void initFastNumberFormatters(UErrorCode& status);
1505
1506 /**
1507 * Delete the LocalizedNumberFormatter instances used for speedup.
1508 */
1509 void freeFastNumberFormatters();
1510
1511 /**
1512 * Initialize NumberFormat instances used for numbering system overrides.
1513 */
1514 void initNumberFormatters(const Locale &locale,UErrorCode &status);
1515
1516 /**
1517 * Parse the given override string and set up structures for number formats
1518 */
1519 void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
1520
1521 /**
1522 * Used to map pattern characters to Calendar field identifiers.
1523 */
1524 static const UCalendarDateFields fgPatternIndexToCalendarField[];
1525
1526 /**
1527 * Map index into pattern character string to DateFormat field number
1528 */
1529 static const UDateFormatField fgPatternIndexToDateFormatField[];
1530
1531 /**
1532 * Lazy TimeZoneFormat instantiation, semantically const
1533 */
1534 TimeZoneFormat *tzFormat(UErrorCode &status) const;
1535
1536 const NumberFormat* getNumberFormatByIndex(UDateFormatField index) const;
1537
1538 /**
1539 * Used to map Calendar field to field level.
1540 * The larger the level, the smaller the field unit.
1541 * For example, UCAL_ERA level is 0, UCAL_YEAR level is 10,
1542 * UCAL_MONTH level is 20.
1543 */
1544 static const int32_t fgCalendarFieldToLevel[];
1545
1546 /**
1547 * Map calendar field letter into calendar field level.
1548 */
1549 static int32_t getLevelFromChar(char16_t ch);
1550
1551 /**
1552 * Tell if a character can be used to define a field in a format string.
1553 */
1554 static UBool isSyntaxChar(char16_t ch);
1555
1556 /**
1557 * The formatting pattern for this formatter.
1558 */
1559 UnicodeString fPattern;
1560
1561 /**
1562 * The numbering system override for dates.
1563 */
1564 UnicodeString fDateOverride;
1565
1566 /**
1567 * The numbering system override for times.
1568 */
1569 UnicodeString fTimeOverride;
1570
1571
1572 /**
1573 * The original locale used (for reloading symbols)
1574 */
1575 Locale fLocale;
1576
1577 /**
1578 * A pointer to an object containing the strings to use in formatting (e.g.,
1579 * month and day names, AM and PM strings, time zone names, etc.)
1580 */
1581 DateFormatSymbols* fSymbols; // Owned
1582
1583 /**
1584 * The time zone formatter
1585 */
1586 TimeZoneFormat* fTimeZoneFormat;
1587
1588 /**
1589 * If dates have ambiguous years, we map them into the century starting
1590 * at defaultCenturyStart, which may be any date. If defaultCenturyStart is
1591 * set to SYSTEM_DEFAULT_CENTURY, which it is by default, then the system
1592 * values are used. The instance values defaultCenturyStart and
1593 * defaultCenturyStartYear are only used if explicitly set by the user
1594 * through the API method parseAmbiguousDatesAsAfter().
1595 */
1596 UDate fDefaultCenturyStart;
1597
1598 UBool fHasMinute;
1599 UBool fHasSecond;
1600
1601 /**
1602 * Sets fHasMinutes and fHasSeconds.
1603 */
1604 void parsePattern();
1605
1606 /**
1607 * See documentation for defaultCenturyStart.
1608 */
1609 /*transient*/ int32_t fDefaultCenturyStartYear;
1610
1611 struct NSOverride : public UMemory {
1612 const SharedNumberFormat *snf;
1613 int32_t hash;
1614 NSOverride *next;
1615 void free();
NSOverrideNSOverride1616 NSOverride() : snf(NULL), hash(0), next(NULL) {
1617 }
1618 ~NSOverride();
1619 };
1620
1621 /**
1622 * The number format in use for each date field. NULL means fall back
1623 * to fNumberFormat in DateFormat.
1624 */
1625 const SharedNumberFormat **fSharedNumberFormatters;
1626
1627 enum NumberFormatterKey {
1628 SMPDTFMT_NF_1x10,
1629 SMPDTFMT_NF_2x10,
1630 SMPDTFMT_NF_3x10,
1631 SMPDTFMT_NF_4x10,
1632 SMPDTFMT_NF_2x2,
1633 SMPDTFMT_NF_COUNT
1634 };
1635
1636 /**
1637 * Number formatters pre-allocated for fast performance on the most common integer lengths.
1638 */
1639 const number::LocalizedNumberFormatter* fFastNumberFormatters[SMPDTFMT_NF_COUNT] = {};
1640
1641 UBool fHaveDefaultCentury;
1642
1643 BreakIterator* fCapitalizationBrkIter;
1644 };
1645
1646 inline UDate
get2DigitYearStart(UErrorCode &)1647 SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
1648 {
1649 return fDefaultCenturyStart;
1650 }
1651
1652 U_NAMESPACE_END
1653
1654 #endif /* #if !UCONFIG_NO_FORMATTING */
1655
1656 #endif // _SMPDTFMT
1657 //eof
1658