annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/unicode/smpdtfmt.h @ 69:33d812a61356

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