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