Home | History | Annotate | Download | only in unicode
      1 /*
      2  *******************************************************************************
      3  * Copyright (C) 1996-2009, International Business Machines
      4  * Corporation and others. All Rights Reserved.
      5  *******************************************************************************
      6 */
      7 
      8 #ifndef UDAT_H
      9 #define UDAT_H
     10 
     11 #include "unicode/utypes.h"
     12 
     13 #if !UCONFIG_NO_FORMATTING
     14 
     15 #include "unicode/ucal.h"
     16 #include "unicode/unum.h"
     17 /**
     18  * \file
     19  * \brief C API: DateFormat
     20  *
     21  * <h2> Date Format C API</h2>
     22  *
     23  * Date Format C API  consists of functions that convert dates and
     24  * times from their internal representations to textual form and back again in a
     25  * language-independent manner. Converting from the internal representation (milliseconds
     26  * since midnight, January 1, 1970) to text is known as "formatting," and converting
     27  * from text to millis is known as "parsing."  We currently define only one concrete
     28  * structure UDateFormat, which can handle pretty much all normal
     29  * date formatting and parsing actions.
     30  * <P>
     31  * Date Format helps you to format and parse dates for any locale. Your code can
     32  * be completely independent of the locale conventions for months, days of the
     33  * week, or even the calendar format: lunar vs. solar.
     34  * <P>
     35  * To format a date for the current Locale with default time and date style,
     36  * use one of the static factory methods:
     37  * <pre>
     38  * \code
     39  *  UErrorCode status = U_ZERO_ERROR;
     40  *  UChar *myString;
     41  *  int32_t myStrlen = 0;
     42  *  UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, -1, &status);
     43  *  myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, NULL, &status);
     44  *  if (status==U_BUFFER_OVERFLOW_ERROR){
     45  *      status=U_ZERO_ERROR;
     46  *      myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
     47  *      udat_format(dfmt, myDate, myString, myStrlen+1, NULL, &status);
     48  *  }
     49  * \endcode
     50  * </pre>
     51  * If you are formatting multiple numbers, it is more efficient to get the
     52  * format and use it multiple times so that the system doesn't have to fetch the
     53  * information about the local language and country conventions multiple times.
     54  * <pre>
     55  * \code
     56  *  UErrorCode status = U_ZERO_ERROR;
     57  *  int32_t i, myStrlen = 0;
     58  *  UChar* myString;
     59  *  char buffer[1024];
     60  *  UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values
     61  *  UDateFormat* df = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, 0, &status);
     62  *  for (i = 0; i < 3; i++) {
     63  *      myStrlen = udat_format(df, myDateArr[i], NULL, myStrlen, NULL, &status);
     64  *      if(status == U_BUFFER_OVERFLOW_ERROR){
     65  *          status = U_ZERO_ERROR;
     66  *          myString = (UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
     67  *          udat_format(df, myDateArr[i], myString, myStrlen+1, NULL, &status);
     68  *          printf("%s\n", u_austrcpy(buffer, myString) );
     69  *          free(myString);
     70  *      }
     71  *  }
     72  * \endcode
     73  * </pre>
     74  * To get specific fields of a date, you can use UFieldPosition to
     75  * get specific fields.
     76  * <pre>
     77  * \code
     78  *  UErrorCode status = U_ZERO_ERROR;
     79  *  UFieldPosition pos;
     80  *  UChar *myString;
     81  *  int32_t myStrlen = 0;
     82  *  char buffer[1024];
     83  *
     84  *  pos.field = 1;  // Same as the DateFormat::EField enum
     85  *  UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, -1, NULL, 0, &status);
     86  *  myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, &pos, &status);
     87  *  if (status==U_BUFFER_OVERFLOW_ERROR){
     88  *      status=U_ZERO_ERROR;
     89  *      myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
     90  *      udat_format(dfmt, myDate, myString, myStrlen+1, &pos, &status);
     91  *  }
     92  *  printf("date format: %s\n", u_austrcpy(buffer, myString));
     93  *  buffer[pos.endIndex] = 0;   // NULL terminate the string.
     94  *  printf("UFieldPosition position equals %s\n", &buffer[pos.beginIndex]);
     95  * \endcode
     96  * </pre>
     97  * To format a date for a different Locale, specify it in the call to
     98  * udat_open()
     99  * <pre>
    100  * \code
    101  *        UDateFormat* df = udat_open(UDAT_SHORT, UDAT_SHORT, "fr_FR", NULL, -1, NULL, 0, &status);
    102  * \endcode
    103  * </pre>
    104  * You can use a DateFormat API udat_parse() to parse.
    105  * <pre>
    106  * \code
    107  *  UErrorCode status = U_ZERO_ERROR;
    108  *  int32_t parsepos=0;
    109  *  UDate myDate = udat_parse(df, myString, u_strlen(myString), &parsepos, &status);
    110  * \endcode
    111  * </pre>
    112  *  You can pass in different options for the arguments for date and time style
    113  *  to control the length of the result; from SHORT to MEDIUM to LONG to FULL.
    114  *  The exact result depends on the locale, but generally:
    115  *  see UDateFormatStyle for more details
    116  * <ul type=round>
    117  *   <li>   UDAT_SHORT is completely numeric, such as 12/13/52 or 3:30pm
    118  *   <li>   UDAT_MEDIUM is longer, such as Jan 12, 1952
    119  *   <li>   UDAT_LONG is longer, such as January 12, 1952 or 3:30:32pm
    120  *   <li>   UDAT_FULL is pretty completely specified, such as
    121  *          Tuesday, April 12, 1952 AD or 3:30:42pm PST.
    122  * </ul>
    123  * You can also set the time zone on the format if you wish.
    124  * <P>
    125  * You can also use forms of the parse and format methods with Parse Position and
    126  * UFieldPosition to allow you to
    127  * <ul type=round>
    128  *   <li>   Progressively parse through pieces of a string.
    129  *   <li>   Align any particular field, or find out where it is for selection
    130  *          on the screen.
    131  * </ul>
    132  */
    133 
    134 /** A date formatter.
    135  *  For usage in C programs.
    136  *  @stable ICU 2.6
    137  */
    138 typedef void* UDateFormat;
    139 
    140 /** The possible date/time format styles
    141  *  @stable ICU 2.6
    142  */
    143 typedef enum UDateFormatStyle {
    144     /** Full style */
    145     UDAT_FULL,
    146     /** Long style */
    147     UDAT_LONG,
    148     /** Medium style */
    149     UDAT_MEDIUM,
    150     /** Short style */
    151     UDAT_SHORT,
    152     /** Default style */
    153     UDAT_DEFAULT = UDAT_MEDIUM,
    154 
    155     /** Bitfield for relative date */
    156     UDAT_RELATIVE = (1 << 7),
    157 
    158     UDAT_FULL_RELATIVE = UDAT_FULL | UDAT_RELATIVE,
    159 
    160     UDAT_LONG_RELATIVE = UDAT_LONG | UDAT_RELATIVE,
    161 
    162     UDAT_MEDIUM_RELATIVE = UDAT_MEDIUM | UDAT_RELATIVE,
    163 
    164     UDAT_SHORT_RELATIVE = UDAT_SHORT | UDAT_RELATIVE,
    165 
    166 
    167     /** No style */
    168     UDAT_NONE = -1,
    169     /** for internal API use only */
    170     UDAT_IGNORE = -2
    171 
    172 } UDateFormatStyle;
    173 
    174 
    175 /**
    176  * @{
    177  * Below are a set of pre-defined skeletons.
    178  *
    179  * <P>
    180  * A skeleton
    181  * <ol>
    182  * <li>
    183  *    only keeps the field pattern letter and ignores all other parts
    184  *    in a pattern, such as space, punctuations, and string literals.
    185  * </li>
    186  * <li>
    187  *    hides the order of fields.
    188  * </li>
    189  * <li>
    190  *    might hide a field's pattern letter length.
    191  *
    192  *    For those non-digit calendar fields, the pattern letter length is
    193  *    important, such as MMM, MMMM, and MMMMM; EEE and EEEE,
    194  *    and the field's pattern letter length is honored.
    195  *
    196  *    For the digit calendar fields,  such as M or MM, d or dd, yy or yyyy,
    197  *    the field pattern length is ignored and the best match, which is defined
    198  *    in date time patterns, will be returned without honor the field pattern
    199  *    letter length in skeleton.
    200  * </li>
    201  * </ol>
    202  *
    203  * @stable ICU 4.0
    204  */
    205 
    206 #define UDAT_MINUTE_SECOND              "ms"
    207 #define UDAT_HOUR24_MINUTE              "Hm"
    208 #define UDAT_HOUR24_MINUTE_SECOND       "Hms"
    209 #define UDAT_HOUR_MINUTE_SECOND         "hms"
    210 #define UDAT_STANDALONE_MONTH           "LLLL"
    211 #define UDAT_ABBR_STANDALONE_MONTH      "LLL"
    212 #define UDAT_YEAR_QUARTER               "yQQQ"
    213 #define UDAT_YEAR_ABBR_QUARTER          "yQ"
    214 
    215 /** @} */
    216 
    217 /**
    218  * @{
    219  * Below are a set of pre-defined skeletons that
    220  * have pre-defined interval patterns in resource files.
    221  * Users are encouraged to use them in date interval format factory methods.
    222  *
    223  */
    224 #define UDAT_HOUR_MINUTE                "hm"
    225 #define UDAT_YEAR                       "y"
    226 #define UDAT_DAY                        "d"
    227 #define UDAT_NUM_MONTH_WEEKDAY_DAY      "MEd"
    228 #define UDAT_YEAR_NUM_MONTH             "yM"
    229 #define UDAT_NUM_MONTH_DAY              "Md"
    230 #define UDAT_YEAR_NUM_MONTH_WEEKDAY_DAY "yMEd"
    231 #define UDAT_ABBR_MONTH_WEEKDAY_DAY     "MMMEd"
    232 #define UDAT_YEAR_MONTH                 "yMMMM"
    233 #define UDAT_YEAR_ABBR_MONTH            "yMMM"
    234 #define UDAT_MONTH_DAY                  "MMMMd"
    235 #define UDAT_ABBR_MONTH_DAY             "MMMd"
    236 #define UDAT_MONTH_WEEKDAY_DAY          "MMMMEEEEd"
    237 #define UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY "yMMMEd"
    238 #define UDAT_YEAR_MONTH_WEEKDAY_DAY     "yMMMMEEEEd"
    239 #define UDAT_YEAR_MONTH_DAY             "yMMMMd"
    240 #define UDAT_YEAR_ABBR_MONTH_DAY        "yMMMd"
    241 #define UDAT_YEAR_NUM_MONTH_DAY         "yMd"
    242 #define UDAT_NUM_MONTH                  "M"
    243 #define UDAT_ABBR_MONTH                 "MMM"
    244 #define UDAT_MONTH                      "MMMM"
    245 #define UDAT_HOUR_MINUTE_GENERIC_TZ     "hmv"
    246 #define UDAT_HOUR_MINUTE_TZ             "hmz"
    247 #define UDAT_HOUR                       "h"
    248 #define UDAT_HOUR_GENERIC_TZ            "hv"
    249 #define UDAT_HOUR_TZ                    "hz"
    250 
    251 /** @} */
    252 
    253 
    254 /**
    255  * FieldPosition and UFieldPosition selectors for format fields
    256  * defined by DateFormat and UDateFormat.
    257  * @stable ICU 3.0
    258  */
    259 typedef enum UDateFormatField {
    260     /**
    261      * FieldPosition and UFieldPosition selector for 'G' field alignment,
    262      * corresponding to the UCAL_ERA field.
    263      * @stable ICU 3.0
    264      */
    265     UDAT_ERA_FIELD = 0,
    266 
    267     /**
    268      * FieldPosition and UFieldPosition selector for 'y' field alignment,
    269      * corresponding to the UCAL_YEAR field.
    270      * @stable ICU 3.0
    271      */
    272     UDAT_YEAR_FIELD = 1,
    273 
    274     /**
    275      * FieldPosition and UFieldPosition selector for 'M' field alignment,
    276      * corresponding to the UCAL_MONTH field.
    277      * @stable ICU 3.0
    278      */
    279     UDAT_MONTH_FIELD = 2,
    280 
    281     /**
    282      * FieldPosition and UFieldPosition selector for 'd' field alignment,
    283      * corresponding to the UCAL_DATE field.
    284      * @stable ICU 3.0
    285      */
    286     UDAT_DATE_FIELD = 3,
    287 
    288     /**
    289      * FieldPosition and UFieldPosition selector for 'k' field alignment,
    290      * corresponding to the UCAL_HOUR_OF_DAY field.
    291      * UDAT_HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock.
    292      * For example, 23:59 + 01:00 results in 24:59.
    293      * @stable ICU 3.0
    294      */
    295     UDAT_HOUR_OF_DAY1_FIELD = 4,
    296 
    297     /**
    298      * FieldPosition and UFieldPosition selector for 'H' field alignment,
    299      * corresponding to the UCAL_HOUR_OF_DAY field.
    300      * UDAT_HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock.
    301      * For example, 23:59 + 01:00 results in 00:59.
    302      * @stable ICU 3.0
    303      */
    304     UDAT_HOUR_OF_DAY0_FIELD = 5,
    305 
    306     /**
    307      * FieldPosition and UFieldPosition selector for 'm' field alignment,
    308      * corresponding to the UCAL_MINUTE field.
    309      * @stable ICU 3.0
    310      */
    311     UDAT_MINUTE_FIELD = 6,
    312 
    313     /**
    314      * FieldPosition and UFieldPosition selector for 's' field alignment,
    315      * corresponding to the UCAL_SECOND field.
    316      * @stable ICU 3.0
    317      */
    318     UDAT_SECOND_FIELD = 7,
    319 
    320     /**
    321      * FieldPosition and UFieldPosition selector for 'S' field alignment,
    322      * corresponding to the UCAL_MILLISECOND field.
    323      * @stable ICU 3.0
    324      */
    325     UDAT_FRACTIONAL_SECOND_FIELD = 8,
    326 
    327     /**
    328      * FieldPosition and UFieldPosition selector for 'E' field alignment,
    329      * corresponding to the UCAL_DAY_OF_WEEK field.
    330      * @stable ICU 3.0
    331      */
    332     UDAT_DAY_OF_WEEK_FIELD = 9,
    333 
    334     /**
    335      * FieldPosition and UFieldPosition selector for 'D' field alignment,
    336      * corresponding to the UCAL_DAY_OF_YEAR field.
    337      * @stable ICU 3.0
    338      */
    339     UDAT_DAY_OF_YEAR_FIELD = 10,
    340 
    341     /**
    342      * FieldPosition and UFieldPosition selector for 'F' field alignment,
    343      * corresponding to the UCAL_DAY_OF_WEEK_IN_MONTH field.
    344      * @stable ICU 3.0
    345      */
    346     UDAT_DAY_OF_WEEK_IN_MONTH_FIELD = 11,
    347 
    348     /**
    349      * FieldPosition and UFieldPosition selector for 'w' field alignment,
    350      * corresponding to the UCAL_WEEK_OF_YEAR field.
    351      * @stable ICU 3.0
    352      */
    353     UDAT_WEEK_OF_YEAR_FIELD = 12,
    354 
    355     /**
    356      * FieldPosition and UFieldPosition selector for 'W' field alignment,
    357      * corresponding to the UCAL_WEEK_OF_MONTH field.
    358      * @stable ICU 3.0
    359      */
    360     UDAT_WEEK_OF_MONTH_FIELD = 13,
    361 
    362     /**
    363      * FieldPosition and UFieldPosition selector for 'a' field alignment,
    364      * corresponding to the UCAL_AM_PM field.
    365      * @stable ICU 3.0
    366      */
    367     UDAT_AM_PM_FIELD = 14,
    368 
    369     /**
    370      * FieldPosition and UFieldPosition selector for 'h' field alignment,
    371      * corresponding to the UCAL_HOUR field.
    372      * UDAT_HOUR1_FIELD is used for the one-based 12-hour clock.
    373      * For example, 11:30 PM + 1 hour results in 12:30 AM.
    374      * @stable ICU 3.0
    375      */
    376     UDAT_HOUR1_FIELD = 15,
    377 
    378     /**
    379      * FieldPosition and UFieldPosition selector for 'K' field alignment,
    380      * corresponding to the UCAL_HOUR field.
    381      * UDAT_HOUR0_FIELD is used for the zero-based 12-hour clock.
    382      * For example, 11:30 PM + 1 hour results in 00:30 AM.
    383      * @stable ICU 3.0
    384      */
    385     UDAT_HOUR0_FIELD = 16,
    386 
    387     /**
    388      * FieldPosition and UFieldPosition selector for 'z' field alignment,
    389      * corresponding to the UCAL_ZONE_OFFSET and
    390      * UCAL_DST_OFFSET fields.
    391      * @stable ICU 3.0
    392      */
    393     UDAT_TIMEZONE_FIELD = 17,
    394 
    395     /**
    396      * FieldPosition and UFieldPosition selector for 'Y' field alignment,
    397      * corresponding to the UCAL_YEAR_WOY field.
    398      * @stable ICU 3.0
    399      */
    400     UDAT_YEAR_WOY_FIELD = 18,
    401 
    402     /**
    403      * FieldPosition and UFieldPosition selector for 'e' field alignment,
    404      * corresponding to the UCAL_DOW_LOCAL field.
    405      * @stable ICU 3.0
    406      */
    407     UDAT_DOW_LOCAL_FIELD = 19,
    408 
    409     /**
    410      * FieldPosition and UFieldPosition selector for 'u' field alignment,
    411      * corresponding to the UCAL_EXTENDED_YEAR field.
    412      * @stable ICU 3.0
    413      */
    414     UDAT_EXTENDED_YEAR_FIELD = 20,
    415 
    416     /**
    417      * FieldPosition and UFieldPosition selector for 'g' field alignment,
    418      * corresponding to the UCAL_JULIAN_DAY field.
    419      * @stable ICU 3.0
    420      */
    421     UDAT_JULIAN_DAY_FIELD = 21,
    422 
    423     /**
    424      * FieldPosition and UFieldPosition selector for 'A' field alignment,
    425      * corresponding to the UCAL_MILLISECONDS_IN_DAY field.
    426      * @stable ICU 3.0
    427      */
    428     UDAT_MILLISECONDS_IN_DAY_FIELD = 22,
    429 
    430     /**
    431      * FieldPosition and UFieldPosition selector for 'Z' field alignment,
    432      * corresponding to the UCAL_ZONE_OFFSET and
    433      * UCAL_DST_OFFSET fields.
    434      * @stable ICU 3.0
    435      */
    436     UDAT_TIMEZONE_RFC_FIELD = 23,
    437 
    438     /**
    439      * FieldPosition and UFieldPosition selector for 'v' field alignment,
    440      * corresponding to the UCAL_ZONE_OFFSET field.
    441      * @stable ICU 3.4
    442      */
    443     UDAT_TIMEZONE_GENERIC_FIELD = 24,
    444     /**
    445      * FieldPosition selector for 'c' field alignment,
    446      * corresponding to the {@link #UCAL_DATE} field.
    447      * This displays the stand alone day name, if available.
    448      * @stable ICU 3.4
    449      */
    450     UDAT_STANDALONE_DAY_FIELD = 25,
    451 
    452     /**
    453      * FieldPosition selector for 'L' field alignment,
    454      * corresponding to the {@link #UCAL_MONTH} field.
    455      * This displays the stand alone month name, if available.
    456      * @stable ICU 3.4
    457      */
    458     UDAT_STANDALONE_MONTH_FIELD = 26,
    459 
    460     /**
    461      * FieldPosition selector for "Q" field alignment,
    462      * corresponding to quarters. This is implemented
    463      * using the {@link #UCAL_MONTH} field. This
    464      * displays the quarter.
    465      * @stable ICU 3.6
    466      */
    467     UDAT_QUARTER_FIELD = 27,
    468 
    469     /**
    470      * FieldPosition selector for the "q" field alignment,
    471      * corresponding to stand-alone quarters. This is
    472      * implemented using the {@link #UCAL_MONTH} field.
    473      * This displays the stand-alone quarter.
    474      * @stable ICU 3.6
    475      */
    476     UDAT_STANDALONE_QUARTER_FIELD = 28,
    477 
    478     /**
    479      * FieldPosition and UFieldPosition selector for 'V' field alignment,
    480      * corresponding to the UCAL_ZONE_OFFSET field.
    481      * @stable ICU 3.8
    482      */
    483     UDAT_TIMEZONE_SPECIAL_FIELD = 29,
    484 
    485    /**
    486      * Number of FieldPosition and UFieldPosition selectors for
    487      * DateFormat and UDateFormat.
    488      * Valid selectors range from 0 to UDAT_FIELD_COUNT-1.
    489      * This value is subject to change if new fields are defined
    490      * in the future.
    491      * @stable ICU 3.0
    492      */
    493     UDAT_FIELD_COUNT = 30
    494 
    495 } UDateFormatField;
    496 
    497 /**
    498  * Open a new UDateFormat for formatting and parsing dates and times.
    499  * A UDateFormat may be used to format dates in calls to {@link #udat_format },
    500  * and to parse dates in calls to {@link #udat_parse }.
    501  * @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG,
    502  * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, or UDAT_NONE (relative time styles
    503  * are not currently supported)
    504  * @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG,
    505  * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_FULL_RELATIVE, UDAT_LONG_RELATIVE,
    506  * UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE
    507  * @param locale The locale specifying the formatting conventions
    508  * @param tzID A timezone ID specifying the timezone to use.  If 0, use
    509  * the default timezone.
    510  * @param tzIDLength The length of tzID, or -1 if null-terminated.
    511  * @param pattern A pattern specifying the format to use.
    512  * @param patternLength The number of characters in the pattern, or -1 if null-terminated.
    513  * @param status A pointer to an UErrorCode to receive any errors
    514  * @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if
    515  * an error occurred.
    516  * @stable ICU 2.0
    517  */
    518 U_STABLE UDateFormat* U_EXPORT2
    519 udat_open(UDateFormatStyle  timeStyle,
    520           UDateFormatStyle  dateStyle,
    521           const char        *locale,
    522           const UChar       *tzID,
    523           int32_t           tzIDLength,
    524           const UChar       *pattern,
    525           int32_t           patternLength,
    526           UErrorCode        *status);
    527 
    528 
    529 /**
    530 * Close a UDateFormat.
    531 * Once closed, a UDateFormat may no longer be used.
    532 * @param format The formatter to close.
    533 * @stable ICU 2.0
    534 */
    535 U_STABLE void U_EXPORT2
    536 udat_close(UDateFormat* format);
    537 
    538 /**
    539  * Open a copy of a UDateFormat.
    540  * This function performs a deep copy.
    541  * @param fmt The format to copy
    542  * @param status A pointer to an UErrorCode to receive any errors.
    543  * @return A pointer to a UDateFormat identical to fmt.
    544  * @stable ICU 2.0
    545  */
    546 U_STABLE UDateFormat* U_EXPORT2
    547 udat_clone(const UDateFormat *fmt,
    548        UErrorCode *status);
    549 
    550 /**
    551 * Format a date using an UDateFormat.
    552 * The date will be formatted using the conventions specified in {@link #udat_open }
    553 * @param format The formatter to use
    554 * @param dateToFormat The date to format
    555 * @param result A pointer to a buffer to receive the formatted number.
    556 * @param resultLength The maximum size of result.
    557 * @param position A pointer to a UFieldPosition.  On input, position->field
    558 * is read.  On output, position->beginIndex and position->endIndex indicate
    559 * the beginning and ending indices of field number position->field, if such
    560 * a field exists.  This parameter may be NULL, in which case no field
    561 * position data is returned.
    562 * @param status A pointer to an UErrorCode to receive any errors
    563 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
    564 * @see udat_parse
    565 * @see UFieldPosition
    566 * @stable ICU 2.0
    567 */
    568 U_STABLE int32_t U_EXPORT2
    569 udat_format(    const    UDateFormat*    format,
    570                         UDate           dateToFormat,
    571                         UChar*          result,
    572                         int32_t         resultLength,
    573                         UFieldPosition* position,
    574                         UErrorCode*     status);
    575 
    576 /**
    577 * Parse a string into an date/time using a UDateFormat.
    578 * The date will be parsed using the conventions specified in {@link #udat_open }
    579 * @param format The formatter to use.
    580 * @param text The text to parse.
    581 * @param textLength The length of text, or -1 if null-terminated.
    582 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
    583 * to begin parsing.  If not 0, on output the offset at which parsing ended.
    584 * @param status A pointer to an UErrorCode to receive any errors
    585 * @return The value of the parsed date/time
    586 * @see udat_format
    587 * @stable ICU 2.0
    588 */
    589 U_STABLE UDate U_EXPORT2
    590 udat_parse(    const    UDateFormat*    format,
    591             const    UChar*          text,
    592                     int32_t         textLength,
    593                     int32_t         *parsePos,
    594                     UErrorCode      *status);
    595 
    596 /**
    597 * Parse a string into an date/time using a UDateFormat.
    598 * The date will be parsed using the conventions specified in {@link #udat_open }
    599 * @param format The formatter to use.
    600 * @param calendar The calendar in which to store the parsed data.
    601 * @param text The text to parse.
    602 * @param textLength The length of text, or -1 if null-terminated.
    603 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
    604 * to begin parsing.  If not 0, on output the offset at which parsing ended.
    605 * @param status A pointer to an UErrorCode to receive any errors
    606 * @see udat_format
    607 * @stable ICU 2.0
    608 */
    609 U_STABLE void U_EXPORT2
    610 udat_parseCalendar(const    UDateFormat*    format,
    611                             UCalendar*      calendar,
    612                    const    UChar*          text,
    613                             int32_t         textLength,
    614                             int32_t         *parsePos,
    615                             UErrorCode      *status);
    616 
    617 /**
    618 * Determine if an UDateFormat will perform lenient parsing.
    619 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
    620 * precisely match the pattern. With strict parsing, inputs must match the pattern.
    621 * @param fmt The formatter to query
    622 * @return TRUE if fmt is set to perform lenient parsing, FALSE otherwise.
    623 * @see udat_setLenient
    624 * @stable ICU 2.0
    625 */
    626 U_STABLE UBool U_EXPORT2
    627 udat_isLenient(const UDateFormat* fmt);
    628 
    629 /**
    630 * Specify whether an UDateFormat will perform lenient parsing.
    631 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
    632 * precisely match the pattern. With strict parsing, inputs must match the pattern.
    633 * @param fmt The formatter to set
    634 * @param isLenient TRUE if fmt should perform lenient parsing, FALSE otherwise.
    635 * @see dat_isLenient
    636 * @stable ICU 2.0
    637 */
    638 U_STABLE void U_EXPORT2
    639 udat_setLenient(    UDateFormat*    fmt,
    640                     UBool          isLenient);
    641 
    642 /**
    643 * Get the UCalendar associated with an UDateFormat.
    644 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
    645 * the day of the week.
    646 * @param fmt The formatter to query.
    647 * @return A pointer to the UCalendar used by fmt.
    648 * @see udat_setCalendar
    649 * @stable ICU 2.0
    650 */
    651 U_STABLE const UCalendar* U_EXPORT2
    652 udat_getCalendar(const UDateFormat* fmt);
    653 
    654 /**
    655 * Set the UCalendar associated with an UDateFormat.
    656 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
    657 * the day of the week.
    658 * @param fmt The formatter to set.
    659 * @param calendarToSet A pointer to an UCalendar to be used by fmt.
    660 * @see udat_setCalendar
    661 * @stable ICU 2.0
    662 */
    663 U_STABLE void U_EXPORT2
    664 udat_setCalendar(            UDateFormat*    fmt,
    665                     const   UCalendar*      calendarToSet);
    666 
    667 /**
    668 * Get the UNumberFormat associated with an UDateFormat.
    669 * A UDateFormat uses a UNumberFormat to format numbers within a date,
    670 * for example the day number.
    671 * @param fmt The formatter to query.
    672 * @return A pointer to the UNumberFormat used by fmt to format numbers.
    673 * @see udat_setNumberFormat
    674 * @stable ICU 2.0
    675 */
    676 U_STABLE const UNumberFormat* U_EXPORT2
    677 udat_getNumberFormat(const UDateFormat* fmt);
    678 
    679 /**
    680 * Set the UNumberFormat associated with an UDateFormat.
    681 * A UDateFormat uses a UNumberFormat to format numbers within a date,
    682 * for example the day number.
    683 * @param fmt The formatter to set.
    684 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
    685 * @see udat_getNumberFormat
    686 * @stable ICU 2.0
    687 */
    688 U_STABLE void U_EXPORT2
    689 udat_setNumberFormat(            UDateFormat*    fmt,
    690                         const   UNumberFormat*  numberFormatToSet);
    691 
    692 /**
    693 * Get a locale for which date/time formatting patterns are available.
    694 * A UDateFormat in a locale returned by this function will perform the correct
    695 * formatting and parsing for the locale.
    696 * @param localeIndex The index of the desired locale.
    697 * @return A locale for which date/time formatting patterns are available, or 0 if none.
    698 * @see udat_countAvailable
    699 * @stable ICU 2.0
    700 */
    701 U_STABLE const char* U_EXPORT2
    702 udat_getAvailable(int32_t localeIndex);
    703 
    704 /**
    705 * Determine how many locales have date/time  formatting patterns available.
    706 * This function is most useful as determining the loop ending condition for
    707 * calls to {@link #udat_getAvailable }.
    708 * @return The number of locales for which date/time formatting patterns are available.
    709 * @see udat_getAvailable
    710 * @stable ICU 2.0
    711 */
    712 U_STABLE int32_t U_EXPORT2
    713 udat_countAvailable(void);
    714 
    715 /**
    716 * Get the year relative to which all 2-digit years are interpreted.
    717 * For example, if the 2-digit start year is 2100, the year 99 will be
    718 * interpreted as 2199.
    719 * @param fmt The formatter to query.
    720 * @param status A pointer to an UErrorCode to receive any errors
    721 * @return The year relative to which all 2-digit years are interpreted.
    722 * @see udat_Set2DigitYearStart
    723 * @stable ICU 2.0
    724 */
    725 U_STABLE UDate U_EXPORT2
    726 udat_get2DigitYearStart(    const   UDateFormat     *fmt,
    727                                     UErrorCode      *status);
    728 
    729 /**
    730 * Set the year relative to which all 2-digit years will be interpreted.
    731 * For example, if the 2-digit start year is 2100, the year 99 will be
    732 * interpreted as 2199.
    733 * @param fmt The formatter to set.
    734 * @param d The year relative to which all 2-digit years will be interpreted.
    735 * @param status A pointer to an UErrorCode to receive any errors
    736 * @see udat_Set2DigitYearStart
    737 * @stable ICU 2.0
    738 */
    739 U_STABLE void U_EXPORT2
    740 udat_set2DigitYearStart(    UDateFormat     *fmt,
    741                             UDate           d,
    742                             UErrorCode      *status);
    743 
    744 /**
    745 * Extract the pattern from a UDateFormat.
    746 * The pattern will follow the pattern syntax rules.
    747 * @param fmt The formatter to query.
    748 * @param localized TRUE if the pattern should be localized, FALSE otherwise.
    749 * @param result A pointer to a buffer to receive the pattern.
    750 * @param resultLength The maximum size of result.
    751 * @param status A pointer to an UErrorCode to receive any errors
    752 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
    753 * @see udat_applyPattern
    754 * @stable ICU 2.0
    755 */
    756 U_STABLE int32_t U_EXPORT2
    757 udat_toPattern(    const   UDateFormat     *fmt,
    758                         UBool          localized,
    759                         UChar           *result,
    760                         int32_t         resultLength,
    761                         UErrorCode      *status);
    762 
    763 /**
    764 * Set the pattern used by an UDateFormat.
    765 * The pattern should follow the pattern syntax rules.
    766 * @param format The formatter to set.
    767 * @param localized TRUE if the pattern is localized, FALSE otherwise.
    768 * @param pattern The new pattern
    769 * @param patternLength The length of pattern, or -1 if null-terminated.
    770 * @see udat_toPattern
    771 * @stable ICU 2.0
    772 */
    773 U_STABLE void U_EXPORT2
    774 udat_applyPattern(            UDateFormat     *format,
    775                             UBool          localized,
    776                     const   UChar           *pattern,
    777                             int32_t         patternLength);
    778 
    779 /**
    780  * The possible types of date format symbols
    781  * @stable ICU 2.6
    782  */
    783 typedef enum UDateFormatSymbolType {
    784     /** The era names, for example AD */
    785     UDAT_ERAS,
    786     /** The month names, for example February */
    787     UDAT_MONTHS,
    788     /** The short month names, for example Feb. */
    789     UDAT_SHORT_MONTHS,
    790     /** The weekday names, for example Monday */
    791     UDAT_WEEKDAYS,
    792     /** The short weekday names, for example Mon. */
    793     UDAT_SHORT_WEEKDAYS,
    794     /** The AM/PM names, for example AM */
    795     UDAT_AM_PMS,
    796     /** The localized characters */
    797     UDAT_LOCALIZED_CHARS,
    798     /** The long era names, for example Anno Domini */
    799     UDAT_ERA_NAMES,
    800     /** The narrow month names, for example F */
    801     UDAT_NARROW_MONTHS,
    802     /** The narrow weekday names, for example N */
    803     UDAT_NARROW_WEEKDAYS,
    804     /** Standalone context versions of months */
    805     UDAT_STANDALONE_MONTHS,
    806     UDAT_STANDALONE_SHORT_MONTHS,
    807     UDAT_STANDALONE_NARROW_MONTHS,
    808     /** Standalone context versions of weekdays */
    809     UDAT_STANDALONE_WEEKDAYS,
    810     UDAT_STANDALONE_SHORT_WEEKDAYS,
    811     UDAT_STANDALONE_NARROW_WEEKDAYS,
    812     /** The quarters, for example 1st Quarter */
    813     UDAT_QUARTERS,
    814     /** The short quarter names, for example Q1 */
    815     UDAT_SHORT_QUARTERS,
    816     /** Standalone context versions of quarters */
    817     UDAT_STANDALONE_QUARTERS,
    818     UDAT_STANDALONE_SHORT_QUARTERS
    819 
    820 } UDateFormatSymbolType;
    821 
    822 struct UDateFormatSymbols;
    823 /** Date format symbols.
    824  *  For usage in C programs.
    825  *  @stable ICU 2.6
    826  */
    827 typedef struct UDateFormatSymbols UDateFormatSymbols;
    828 
    829 /**
    830 * Get the symbols associated with an UDateFormat.
    831 * The symbols are what a UDateFormat uses to represent locale-specific data,
    832 * for example month or day names.
    833 * @param fmt The formatter to query.
    834 * @param type The type of symbols to get.  One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
    835 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
    836 * @param symbolIndex The desired symbol of type type.
    837 * @param result A pointer to a buffer to receive the pattern.
    838 * @param resultLength The maximum size of result.
    839 * @param status A pointer to an UErrorCode to receive any errors
    840 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
    841 * @see udat_countSymbols
    842 * @see udat_setSymbols
    843 * @stable ICU 2.0
    844 */
    845 U_STABLE int32_t U_EXPORT2
    846 udat_getSymbols(const   UDateFormat             *fmt,
    847                         UDateFormatSymbolType   type,
    848                         int32_t                 symbolIndex,
    849                         UChar                   *result,
    850                         int32_t                 resultLength,
    851                         UErrorCode              *status);
    852 
    853 /**
    854 * Count the number of particular symbols for an UDateFormat.
    855 * This function is most useful as for detemining the loop termination condition
    856 * for calls to {@link #udat_getSymbols }.
    857 * @param fmt The formatter to query.
    858 * @param type The type of symbols to count.  One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
    859 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
    860 * @return The number of symbols of type type.
    861 * @see udat_getSymbols
    862 * @see udat_setSymbols
    863 * @stable ICU 2.0
    864 */
    865 U_STABLE int32_t U_EXPORT2
    866 udat_countSymbols(    const    UDateFormat                *fmt,
    867                             UDateFormatSymbolType    type);
    868 
    869 /**
    870 * Set the symbols associated with an UDateFormat.
    871 * The symbols are what a UDateFormat uses to represent locale-specific data,
    872 * for example month or day names.
    873 * @param format The formatter to set
    874 * @param type The type of symbols to set.  One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
    875 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
    876 * @param symbolIndex The index of the symbol to set of type type.
    877 * @param value The new value
    878 * @param valueLength The length of value, or -1 if null-terminated
    879 * @param status A pointer to an UErrorCode to receive any errors
    880 * @see udat_getSymbols
    881 * @see udat_countSymbols
    882 * @stable ICU 2.0
    883 */
    884 U_STABLE void U_EXPORT2
    885 udat_setSymbols(    UDateFormat             *format,
    886                     UDateFormatSymbolType   type,
    887                     int32_t                 symbolIndex,
    888                     UChar                   *value,
    889                     int32_t                 valueLength,
    890                     UErrorCode              *status);
    891 
    892 /**
    893  * Get the locale for this date format object.
    894  * You can choose between valid and actual locale.
    895  * @param fmt The formatter to get the locale from
    896  * @param type type of the locale we're looking for (valid or actual)
    897  * @param status error code for the operation
    898  * @return the locale name
    899  * @stable ICU 2.8
    900  */
    901 U_STABLE const char* U_EXPORT2
    902 udat_getLocaleByType(const UDateFormat *fmt,
    903                      ULocDataLocaleType type,
    904                      UErrorCode* status);
    905 
    906 /**
    907 * Extract the date pattern from a UDateFormat set for relative date formatting.
    908 * The pattern will follow the pattern syntax rules.
    909 * @param fmt The formatter to query.
    910 * @param result A pointer to a buffer to receive the pattern.
    911 * @param resultLength The maximum size of result.
    912 * @param status A pointer to a UErrorCode to receive any errors
    913 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
    914 * @see udat_applyPatternRelative
    915 * @internal ICU 4.2 technology preview
    916 */
    917 U_INTERNAL int32_t U_EXPORT2
    918 udat_toPatternRelativeDate(const UDateFormat *fmt,
    919                            UChar             *result,
    920                            int32_t           resultLength,
    921                            UErrorCode        *status);
    922 
    923 /**
    924 * Extract the time pattern from a UDateFormat set for relative date formatting.
    925 * The pattern will follow the pattern syntax rules.
    926 * @param fmt The formatter to query.
    927 * @param result A pointer to a buffer to receive the pattern.
    928 * @param resultLength The maximum size of result.
    929 * @param status A pointer to a UErrorCode to receive any errors
    930 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
    931 * @see udat_applyPatternRelative
    932 * @internal ICU 4.2 technology preview
    933 */
    934 U_INTERNAL int32_t U_EXPORT2
    935 udat_toPatternRelativeTime(const UDateFormat *fmt,
    936                            UChar             *result,
    937                            int32_t           resultLength,
    938                            UErrorCode        *status);
    939 
    940 /**
    941 * Set the date & time patterns used by a UDateFormat set for relative date formatting.
    942 * The patterns should follow the pattern syntax rules.
    943 * @param format The formatter to set.
    944 * @param datePattern The new date pattern
    945 * @param datePatternLength The length of datePattern, or -1 if null-terminated.
    946 * @param timePattern The new time pattern
    947 * @param timePatternLength The length of timePattern, or -1 if null-terminated.
    948 * @param status A pointer to a UErrorCode to receive any errors
    949 * @see udat_toPatternRelativeDate, udat_toPatternRelativeTime
    950 * @internal ICU 4.2 technology preview
    951 */
    952 U_INTERNAL void U_EXPORT2
    953 udat_applyPatternRelative(UDateFormat *format,
    954                           const UChar *datePattern,
    955                           int32_t     datePatternLength,
    956                           const UChar *timePattern,
    957                           int32_t     timePatternLength,
    958                           UErrorCode  *status);
    959 
    960 #endif /* #if !UCONFIG_NO_FORMATTING */
    961 
    962 #endif
    963