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