intl/icu/source/i18n/unicode/smpdtfmt.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial