michael@0: /* michael@0: ******************************************************************************* michael@0: * Copyright (C) 1996-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ******************************************************************************* michael@0: */ michael@0: michael@0: #ifndef UDAT_H michael@0: #define UDAT_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/localpointer.h" michael@0: #include "unicode/ucal.h" michael@0: #include "unicode/unum.h" michael@0: #include "unicode/udisplaycontext.h" michael@0: /** michael@0: * \file michael@0: * \brief C API: DateFormat michael@0: * michael@0: *

Date Format C API

michael@0: * michael@0: * Date Format C API consists of functions that convert dates and michael@0: * times from their internal representations to textual form and back again in a michael@0: * language-independent manner. Converting from the internal representation (milliseconds michael@0: * since midnight, January 1, 1970) to text is known as "formatting," and converting michael@0: * from text to millis is known as "parsing." We currently define only one concrete michael@0: * structure UDateFormat, which can handle pretty much all normal michael@0: * date formatting and parsing actions. michael@0: *

michael@0: * Date Format helps you to format and parse dates for any locale. Your code can michael@0: * be completely independent of the locale conventions for months, days of the michael@0: * week, or even the calendar format: lunar vs. solar. michael@0: *

michael@0: * To format a date for the current Locale with default time and date style, michael@0: * use one of the static factory methods: michael@0: *

michael@0:  * \code
michael@0:  *  UErrorCode status = U_ZERO_ERROR;
michael@0:  *  UChar *myString;
michael@0:  *  int32_t myStrlen = 0;
michael@0:  *  UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, -1, &status);
michael@0:  *  myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, NULL, &status);
michael@0:  *  if (status==U_BUFFER_OVERFLOW_ERROR){
michael@0:  *      status=U_ZERO_ERROR;
michael@0:  *      myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
michael@0:  *      udat_format(dfmt, myDate, myString, myStrlen+1, NULL, &status);
michael@0:  *  }
michael@0:  * \endcode
michael@0:  * 
michael@0: * If you are formatting multiple numbers, it is more efficient to get the michael@0: * format and use it multiple times so that the system doesn't have to fetch the michael@0: * information about the local language and country conventions multiple times. michael@0: *
michael@0:  * \code
michael@0:  *  UErrorCode status = U_ZERO_ERROR;
michael@0:  *  int32_t i, myStrlen = 0;
michael@0:  *  UChar* myString;
michael@0:  *  char buffer[1024];
michael@0:  *  UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values
michael@0:  *  UDateFormat* df = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, 0, &status);
michael@0:  *  for (i = 0; i < 3; i++) {
michael@0:  *      myStrlen = udat_format(df, myDateArr[i], NULL, myStrlen, NULL, &status);
michael@0:  *      if(status == U_BUFFER_OVERFLOW_ERROR){
michael@0:  *          status = U_ZERO_ERROR;
michael@0:  *          myString = (UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
michael@0:  *          udat_format(df, myDateArr[i], myString, myStrlen+1, NULL, &status);
michael@0:  *          printf("%s\n", u_austrcpy(buffer, myString) );
michael@0:  *          free(myString);
michael@0:  *      }
michael@0:  *  }
michael@0:  * \endcode
michael@0:  * 
michael@0: * To get specific fields of a date, you can use UFieldPosition to michael@0: * get specific fields. michael@0: *
michael@0:  * \code
michael@0:  *  UErrorCode status = U_ZERO_ERROR;
michael@0:  *  UFieldPosition pos;
michael@0:  *  UChar *myString;
michael@0:  *  int32_t myStrlen = 0;
michael@0:  *  char buffer[1024];
michael@0:  *
michael@0:  *  pos.field = 1;  // Same as the DateFormat::EField enum
michael@0:  *  UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, -1, NULL, 0, &status);
michael@0:  *  myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, &pos, &status);
michael@0:  *  if (status==U_BUFFER_OVERFLOW_ERROR){
michael@0:  *      status=U_ZERO_ERROR;
michael@0:  *      myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
michael@0:  *      udat_format(dfmt, myDate, myString, myStrlen+1, &pos, &status);
michael@0:  *  }
michael@0:  *  printf("date format: %s\n", u_austrcpy(buffer, myString));
michael@0:  *  buffer[pos.endIndex] = 0;   // NULL terminate the string.
michael@0:  *  printf("UFieldPosition position equals %s\n", &buffer[pos.beginIndex]);
michael@0:  * \endcode
michael@0:  * 
michael@0: * To format a date for a different Locale, specify it in the call to michael@0: * udat_open() michael@0: *
michael@0:  * \code
michael@0:  *        UDateFormat* df = udat_open(UDAT_SHORT, UDAT_SHORT, "fr_FR", NULL, -1, NULL, 0, &status);
michael@0:  * \endcode
michael@0:  * 
michael@0: * You can use a DateFormat API udat_parse() to parse. michael@0: *
michael@0:  * \code
michael@0:  *  UErrorCode status = U_ZERO_ERROR;
michael@0:  *  int32_t parsepos=0;
michael@0:  *  UDate myDate = udat_parse(df, myString, u_strlen(myString), &parsepos, &status);
michael@0:  * \endcode
michael@0:  * 
michael@0: * You can pass in different options for the arguments for date and time style michael@0: * to control the length of the result; from SHORT to MEDIUM to LONG to FULL. michael@0: * The exact result depends on the locale, but generally: michael@0: * see UDateFormatStyle for more details michael@0: * michael@0: * You can also set the time zone on the format if you wish. michael@0: *

michael@0: * You can also use forms of the parse and format methods with Parse Position and michael@0: * UFieldPosition to allow you to michael@0: *

michael@0: *

Date and Time Patterns:

michael@0: * michael@0: *

Date and time formats are specified by date and time pattern strings. michael@0: * Within date and time pattern strings, all unquoted ASCII letters [A-Za-z] are reserved michael@0: * as pattern letters representing calendar fields. UDateFormat supports michael@0: * the date and time formatting algorithm and pattern letters defined by michael@0: * UTS#35 michael@0: * Unicode Locale Data Markup Language (LDML) and further documented for ICU in the michael@0: * ICU michael@0: * User Guide.

michael@0: */ michael@0: michael@0: /** A date formatter. michael@0: * For usage in C programs. michael@0: * @stable ICU 2.6 michael@0: */ michael@0: typedef void* UDateFormat; michael@0: michael@0: /** The possible date/time format styles michael@0: * @stable ICU 2.6 michael@0: */ michael@0: typedef enum UDateFormatStyle { michael@0: /** Full style */ michael@0: UDAT_FULL, michael@0: /** Long style */ michael@0: UDAT_LONG, michael@0: /** Medium style */ michael@0: UDAT_MEDIUM, michael@0: /** Short style */ michael@0: UDAT_SHORT, michael@0: /** Default style */ michael@0: UDAT_DEFAULT = UDAT_MEDIUM, michael@0: michael@0: /** Bitfield for relative date */ michael@0: UDAT_RELATIVE = (1 << 7), michael@0: michael@0: UDAT_FULL_RELATIVE = UDAT_FULL | UDAT_RELATIVE, michael@0: michael@0: UDAT_LONG_RELATIVE = UDAT_LONG | UDAT_RELATIVE, michael@0: michael@0: UDAT_MEDIUM_RELATIVE = UDAT_MEDIUM | UDAT_RELATIVE, michael@0: michael@0: UDAT_SHORT_RELATIVE = UDAT_SHORT | UDAT_RELATIVE, michael@0: michael@0: michael@0: /** No style */ michael@0: UDAT_NONE = -1, michael@0: michael@0: /** michael@0: * Use the pattern given in the parameter to udat_open michael@0: * @see udat_open michael@0: * @stable ICU 50 michael@0: */ michael@0: UDAT_PATTERN = -2, michael@0: michael@0: /** @internal alias to UDAT_PATTERN */ michael@0: UDAT_IGNORE = UDAT_PATTERN michael@0: } UDateFormatStyle; michael@0: michael@0: /* Skeletons for dates. */ michael@0: michael@0: /** michael@0: * Constant for date skeleton with year. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_YEAR "y" michael@0: #ifndef U_HIDE_DRAFT_API michael@0: /** michael@0: * Constant for date skeleton with quarter. michael@0: * @draft ICU 51 michael@0: */ michael@0: #define UDAT_QUARTER "QQQQ" michael@0: /** michael@0: * Constant for date skeleton with abbreviated quarter. michael@0: * @draft ICU 51 michael@0: */ michael@0: #define UDAT_ABBR_QUARTER "QQQ" michael@0: #endif /* U_HIDE_DRAFT_API */ michael@0: /** michael@0: * Constant for date skeleton with year and quarter. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_YEAR_QUARTER "yQQQQ" michael@0: /** michael@0: * Constant for date skeleton with year and abbreviated quarter. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_YEAR_ABBR_QUARTER "yQQQ" michael@0: /** michael@0: * Constant for date skeleton with month. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_MONTH "MMMM" michael@0: /** michael@0: * Constant for date skeleton with abbreviated month. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_ABBR_MONTH "MMM" michael@0: /** michael@0: * Constant for date skeleton with numeric month. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_NUM_MONTH "M" michael@0: /** michael@0: * Constant for date skeleton with year and month. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_YEAR_MONTH "yMMMM" michael@0: /** michael@0: * Constant for date skeleton with year and abbreviated month. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_YEAR_ABBR_MONTH "yMMM" michael@0: /** michael@0: * Constant for date skeleton with year and numeric month. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_YEAR_NUM_MONTH "yM" michael@0: /** michael@0: * Constant for date skeleton with day. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_DAY "d" michael@0: /** michael@0: * Constant for date skeleton with year, month, and day. michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_YEAR_MONTH_DAY "yMMMMd" michael@0: /** michael@0: * Constant for date skeleton with year, abbreviated month, and day. michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_YEAR_ABBR_MONTH_DAY "yMMMd" michael@0: /** michael@0: * Constant for date skeleton with year, numeric month, and day. michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_YEAR_NUM_MONTH_DAY "yMd" michael@0: #ifndef U_HIDE_DRAFT_API michael@0: /** michael@0: * Constant for date skeleton with weekday. michael@0: * @draft ICU 51 michael@0: */ michael@0: #define UDAT_WEEKDAY "EEEE" michael@0: /** michael@0: * Constant for date skeleton with abbreviated weekday. michael@0: * @draft ICU 51 michael@0: */ michael@0: #define UDAT_ABBR_WEEKDAY "E" michael@0: #endif /* U_HIDE_DRAFT_API */ michael@0: /** michael@0: * Constant for date skeleton with year, month, weekday, and day. michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_YEAR_MONTH_WEEKDAY_DAY "yMMMMEEEEd" michael@0: /** michael@0: * Constant for date skeleton with year, abbreviated month, weekday, and day. michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY "yMMMEd" michael@0: /** michael@0: * Constant for date skeleton with year, numeric month, weekday, and day. michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_YEAR_NUM_MONTH_WEEKDAY_DAY "yMEd" michael@0: /** michael@0: * Constant for date skeleton with long month and day. michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_MONTH_DAY "MMMMd" michael@0: /** michael@0: * Constant for date skeleton with abbreviated month and day. michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_ABBR_MONTH_DAY "MMMd" michael@0: /** michael@0: * Constant for date skeleton with numeric month and day. michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_NUM_MONTH_DAY "Md" michael@0: /** michael@0: * Constant for date skeleton with month, weekday, and day. michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_MONTH_WEEKDAY_DAY "MMMMEEEEd" michael@0: /** michael@0: * Constant for date skeleton with abbreviated month, weekday, and day. michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_ABBR_MONTH_WEEKDAY_DAY "MMMEd" michael@0: /** michael@0: * Constant for date skeleton with numeric month, weekday, and day. michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_NUM_MONTH_WEEKDAY_DAY "MEd" michael@0: michael@0: /* Skeletons for times. */ michael@0: michael@0: /** michael@0: * Constant for date skeleton with hour, with the locale's preferred hour format (12 or 24). michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_HOUR "j" michael@0: #ifndef U_HIDE_DRAFT_API michael@0: /** michael@0: * Constant for date skeleton with hour in 24-hour presentation. michael@0: * @draft ICU 51 michael@0: */ michael@0: #define UDAT_HOUR24 "H" michael@0: /** michael@0: * Constant for date skeleton with minute. michael@0: * @draft ICU 51 michael@0: */ michael@0: #define UDAT_MINUTE "m" michael@0: #endif /* U_HIDE_DRAFT_API */ michael@0: /** michael@0: * Constant for date skeleton with hour and minute, with the locale's preferred hour format (12 or 24). michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_HOUR_MINUTE "jm" michael@0: /** michael@0: * Constant for date skeleton with hour and minute in 24-hour presentation. michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_HOUR24_MINUTE "Hm" michael@0: #ifndef U_HIDE_DRAFT_API michael@0: /** michael@0: * Constant for date skeleton with second. michael@0: * @draft ICU 51 michael@0: */ michael@0: #define UDAT_SECOND "s" michael@0: #endif /* U_HIDE_DRAFT_API */ michael@0: /** michael@0: * Constant for date skeleton with hour, minute, and second, michael@0: * with the locale's preferred hour format (12 or 24). michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_HOUR_MINUTE_SECOND "jms" michael@0: /** michael@0: * Constant for date skeleton with hour, minute, and second in michael@0: * 24-hour presentation. michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_HOUR24_MINUTE_SECOND "Hms" michael@0: /** michael@0: * Constant for date skeleton with minute and second. michael@0: * Used in combinations date + time, date + time + zone, or time + zone. michael@0: * @stable ICU 4.0 michael@0: */ michael@0: #define UDAT_MINUTE_SECOND "ms" michael@0: michael@0: /* Skeletons for time zones. */ michael@0: michael@0: #ifndef U_HIDE_DRAFT_API michael@0: /** michael@0: * Constant for generic location format, such as Los Angeles Time; michael@0: * used in combinations date + time + zone, or time + zone. michael@0: * @see LDML Date Format Patterns michael@0: * @see LDML Time Zone Fallback michael@0: * @draft ICU 51 michael@0: */ michael@0: #define UDAT_LOCATION_TZ "VVVV" michael@0: /** michael@0: * Constant for generic non-location format, such as Pacific Time; michael@0: * used in combinations date + time + zone, or time + zone. michael@0: * @see LDML Date Format Patterns michael@0: * @see LDML Time Zone Fallback michael@0: * @draft ICU 51 michael@0: */ michael@0: #define UDAT_GENERIC_TZ "vvvv" michael@0: /** michael@0: * Constant for generic non-location format, abbreviated if possible, such as PT; michael@0: * used in combinations date + time + zone, or time + zone. michael@0: * @see LDML Date Format Patterns michael@0: * @see LDML Time Zone Fallback michael@0: * @draft ICU 51 michael@0: */ michael@0: #define UDAT_ABBR_GENERIC_TZ "v" michael@0: /** michael@0: * Constant for specific non-location format, such as Pacific Daylight Time; michael@0: * used in combinations date + time + zone, or time + zone. michael@0: * @see LDML Date Format Patterns michael@0: * @see LDML Time Zone Fallback michael@0: * @draft ICU 51 michael@0: */ michael@0: #define UDAT_SPECIFIC_TZ "zzzz" michael@0: /** michael@0: * Constant for specific non-location format, abbreviated if possible, such as PDT; michael@0: * used in combinations date + time + zone, or time + zone. michael@0: * @see LDML Date Format Patterns michael@0: * @see LDML Time Zone Fallback michael@0: * @draft ICU 51 michael@0: */ michael@0: #define UDAT_ABBR_SPECIFIC_TZ "z" michael@0: /** michael@0: * Constant for localized GMT/UTC format, such as GMT+8:00 or HPG-8:00; michael@0: * used in combinations date + time + zone, or time + zone. michael@0: * @see LDML Date Format Patterns michael@0: * @see LDML Time Zone Fallback michael@0: * @draft ICU 51 michael@0: */ michael@0: #define UDAT_ABBR_UTC_TZ "ZZZZ" michael@0: #endif /* U_HIDE_DRAFT_API */ michael@0: michael@0: /* deprecated skeleton constants */ michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: /** michael@0: * Constant for date skeleton with standalone month. michael@0: * @deprecated ICU 50 Use UDAT_MONTH instead. michael@0: */ michael@0: #define UDAT_STANDALONE_MONTH "LLLL" michael@0: /** michael@0: * Constant for date skeleton with standalone abbreviated month. michael@0: * @deprecated ICU 50 Use UDAT_ABBR_MONTH instead. michael@0: */ michael@0: #define UDAT_ABBR_STANDALONE_MONTH "LLL" michael@0: michael@0: /** michael@0: * Constant for date skeleton with hour, minute, and generic timezone. michael@0: * @deprecated ICU 50 Use instead UDAT_HOUR_MINUTE UDAT_ABBR_GENERIC_TZ or some other timezone presentation. michael@0: */ michael@0: #define UDAT_HOUR_MINUTE_GENERIC_TZ "jmv" michael@0: /** michael@0: * Constant for date skeleton with hour, minute, and timezone. michael@0: * @deprecated ICU 50 Use instead UDAT_HOUR_MINUTE UDAT_ABBR_SPECIFIC_TZ or some other timezone presentation. michael@0: */ michael@0: #define UDAT_HOUR_MINUTE_TZ "jmz" michael@0: /** michael@0: * Constant for date skeleton with hour and generic timezone. michael@0: * @deprecated ICU 50 Use instead UDAT_HOUR UDAT_ABBR_GENERIC_TZ or some other timezone presentation. michael@0: */ michael@0: #define UDAT_HOUR_GENERIC_TZ "jv" michael@0: /** michael@0: * Constant for date skeleton with hour and timezone. michael@0: * @deprecated ICU 50 Use instead UDAT_HOUR UDAT_ABBR_SPECIFIC_TZ or some other timezone presentation. michael@0: */ michael@0: #define UDAT_HOUR_TZ "jz" michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selectors for format fields michael@0: * defined by DateFormat and UDateFormat. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: typedef enum UDateFormatField { michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'G' field alignment, michael@0: * corresponding to the UCAL_ERA field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_ERA_FIELD = 0, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'y' field alignment, michael@0: * corresponding to the UCAL_YEAR field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_YEAR_FIELD = 1, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'M' field alignment, michael@0: * corresponding to the UCAL_MONTH field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_MONTH_FIELD = 2, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'd' field alignment, michael@0: * corresponding to the UCAL_DATE field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_DATE_FIELD = 3, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'k' field alignment, michael@0: * corresponding to the UCAL_HOUR_OF_DAY field. michael@0: * UDAT_HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock. michael@0: * For example, 23:59 + 01:00 results in 24:59. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_HOUR_OF_DAY1_FIELD = 4, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'H' field alignment, michael@0: * corresponding to the UCAL_HOUR_OF_DAY field. michael@0: * UDAT_HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock. michael@0: * For example, 23:59 + 01:00 results in 00:59. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_HOUR_OF_DAY0_FIELD = 5, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'm' field alignment, michael@0: * corresponding to the UCAL_MINUTE field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_MINUTE_FIELD = 6, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 's' field alignment, michael@0: * corresponding to the UCAL_SECOND field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_SECOND_FIELD = 7, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'S' field alignment, michael@0: * corresponding to the UCAL_MILLISECOND field. michael@0: * michael@0: * Note: Time formats that use 'S' can display a maximum of three michael@0: * significant digits for fractional seconds, corresponding to millisecond michael@0: * resolution and a fractional seconds sub-pattern of SSS. If the michael@0: * sub-pattern is S or SS, the fractional seconds value will be truncated michael@0: * (not rounded) to the number of display places specified. If the michael@0: * fractional seconds sub-pattern is longer than SSS, the additional michael@0: * display places will be filled with zeros. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_FRACTIONAL_SECOND_FIELD = 8, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'E' field alignment, michael@0: * corresponding to the UCAL_DAY_OF_WEEK field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_DAY_OF_WEEK_FIELD = 9, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'D' field alignment, michael@0: * corresponding to the UCAL_DAY_OF_YEAR field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_DAY_OF_YEAR_FIELD = 10, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'F' field alignment, michael@0: * corresponding to the UCAL_DAY_OF_WEEK_IN_MONTH field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_DAY_OF_WEEK_IN_MONTH_FIELD = 11, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'w' field alignment, michael@0: * corresponding to the UCAL_WEEK_OF_YEAR field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_WEEK_OF_YEAR_FIELD = 12, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'W' field alignment, michael@0: * corresponding to the UCAL_WEEK_OF_MONTH field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_WEEK_OF_MONTH_FIELD = 13, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'a' field alignment, michael@0: * corresponding to the UCAL_AM_PM field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_AM_PM_FIELD = 14, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'h' field alignment, michael@0: * corresponding to the UCAL_HOUR field. michael@0: * UDAT_HOUR1_FIELD is used for the one-based 12-hour clock. michael@0: * For example, 11:30 PM + 1 hour results in 12:30 AM. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_HOUR1_FIELD = 15, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'K' field alignment, michael@0: * corresponding to the UCAL_HOUR field. michael@0: * UDAT_HOUR0_FIELD is used for the zero-based 12-hour clock. michael@0: * For example, 11:30 PM + 1 hour results in 00:30 AM. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_HOUR0_FIELD = 16, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'z' field alignment, michael@0: * corresponding to the UCAL_ZONE_OFFSET and michael@0: * UCAL_DST_OFFSET fields. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_TIMEZONE_FIELD = 17, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'Y' field alignment, michael@0: * corresponding to the UCAL_YEAR_WOY field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_YEAR_WOY_FIELD = 18, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'e' field alignment, michael@0: * corresponding to the UCAL_DOW_LOCAL field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_DOW_LOCAL_FIELD = 19, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'u' field alignment, michael@0: * corresponding to the UCAL_EXTENDED_YEAR field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_EXTENDED_YEAR_FIELD = 20, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'g' field alignment, michael@0: * corresponding to the UCAL_JULIAN_DAY field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_JULIAN_DAY_FIELD = 21, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'A' field alignment, michael@0: * corresponding to the UCAL_MILLISECONDS_IN_DAY field. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_MILLISECONDS_IN_DAY_FIELD = 22, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'Z' field alignment, michael@0: * corresponding to the UCAL_ZONE_OFFSET and michael@0: * UCAL_DST_OFFSET fields. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_TIMEZONE_RFC_FIELD = 23, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'v' field alignment, michael@0: * corresponding to the UCAL_ZONE_OFFSET field. michael@0: * @stable ICU 3.4 michael@0: */ michael@0: UDAT_TIMEZONE_GENERIC_FIELD = 24, michael@0: /** michael@0: * FieldPosition selector for 'c' field alignment, michael@0: * corresponding to the {@link #UCAL_DOW_LOCAL} field. michael@0: * This displays the stand alone day name, if available. michael@0: * @stable ICU 3.4 michael@0: */ michael@0: UDAT_STANDALONE_DAY_FIELD = 25, michael@0: michael@0: /** michael@0: * FieldPosition selector for 'L' field alignment, michael@0: * corresponding to the {@link #UCAL_MONTH} field. michael@0: * This displays the stand alone month name, if available. michael@0: * @stable ICU 3.4 michael@0: */ michael@0: UDAT_STANDALONE_MONTH_FIELD = 26, michael@0: michael@0: /** michael@0: * FieldPosition selector for "Q" field alignment, michael@0: * corresponding to quarters. This is implemented michael@0: * using the {@link #UCAL_MONTH} field. This michael@0: * displays the quarter. michael@0: * @stable ICU 3.6 michael@0: */ michael@0: UDAT_QUARTER_FIELD = 27, michael@0: michael@0: /** michael@0: * FieldPosition selector for the "q" field alignment, michael@0: * corresponding to stand-alone quarters. This is michael@0: * implemented using the {@link #UCAL_MONTH} field. michael@0: * This displays the stand-alone quarter. michael@0: * @stable ICU 3.6 michael@0: */ michael@0: UDAT_STANDALONE_QUARTER_FIELD = 28, michael@0: michael@0: /** michael@0: * FieldPosition and UFieldPosition selector for 'V' field alignment, michael@0: * corresponding to the UCAL_ZONE_OFFSET field. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: UDAT_TIMEZONE_SPECIAL_FIELD = 29, michael@0: michael@0: /** michael@0: * FieldPosition selector for "U" field alignment, michael@0: * corresponding to cyclic year names. This is implemented michael@0: * using the {@link #UCAL_YEAR} field. This displays michael@0: * the cyclic year name, if available. michael@0: * @stable ICU 49 michael@0: */ michael@0: UDAT_YEAR_NAME_FIELD = 30, michael@0: michael@0: #ifndef U_HIDE_DRAFT_API michael@0: /** michael@0: * FieldPosition selector for 'O' field alignment, michael@0: * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSETfields. michael@0: * This displays the localized GMT format. michael@0: * @draft ICU 51 michael@0: */ michael@0: UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD = 31, michael@0: michael@0: /** michael@0: * FieldPosition selector for 'X' field alignment, michael@0: * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSETfields. michael@0: * This displays the ISO 8601 local time offset format or UTC indicator ("Z"). michael@0: * @draft ICU 51 michael@0: */ michael@0: UDAT_TIMEZONE_ISO_FIELD = 32, michael@0: michael@0: /** michael@0: * FieldPosition selector for 'x' field alignment, michael@0: * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSETfields. michael@0: * This displays the ISO 8601 local time offset format. michael@0: * @draft ICU 51 michael@0: */ michael@0: UDAT_TIMEZONE_ISO_LOCAL_FIELD = 33, michael@0: #endif /* U_HIDE_DRAFT_API */ michael@0: michael@0: /** michael@0: * Number of FieldPosition and UFieldPosition selectors for michael@0: * DateFormat and UDateFormat. michael@0: * Valid selectors range from 0 to UDAT_FIELD_COUNT-1. michael@0: * This value is subject to change if new fields are defined michael@0: * in the future. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDAT_FIELD_COUNT = 34 michael@0: michael@0: } UDateFormatField; michael@0: michael@0: michael@0: /** michael@0: * Maps from a UDateFormatField to the corresponding UCalendarDateFields. michael@0: * Note: since the mapping is many-to-one, there is no inverse mapping. michael@0: * @param field the UDateFormatField. michael@0: * @return the UCalendarDateField. This will be UCAL_FIELD_COUNT in case michael@0: * of error (e.g., the input field is UDAT_FIELD_COUNT). michael@0: * @stable ICU 4.4 michael@0: */ michael@0: U_STABLE UCalendarDateFields U_EXPORT2 michael@0: udat_toCalendarDateField(UDateFormatField field); michael@0: michael@0: michael@0: /** michael@0: * Open a new UDateFormat for formatting and parsing dates and times. michael@0: * A UDateFormat may be used to format dates in calls to {@link #udat_format }, michael@0: * and to parse dates in calls to {@link #udat_parse }. michael@0: * @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG, michael@0: * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, or UDAT_NONE (relative time styles michael@0: * are not currently supported). michael@0: * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle. michael@0: * @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG, michael@0: * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_FULL_RELATIVE, UDAT_LONG_RELATIVE, michael@0: * UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE. michael@0: * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle. michael@0: * As currently implemented, michael@0: * relative date formatting only affects a limited range of calendar days before or michael@0: * after the current date, based on the CLDR <field type="day">/<relative> data: For michael@0: * example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range, michael@0: * dates are formatted using the corresponding non-relative style. michael@0: * @param locale The locale specifying the formatting conventions michael@0: * @param tzID A timezone ID specifying the timezone to use. If 0, use michael@0: * the default timezone. michael@0: * @param tzIDLength The length of tzID, or -1 if null-terminated. michael@0: * @param pattern A pattern specifying the format to use. michael@0: * @param patternLength The number of characters in the pattern, or -1 if null-terminated. michael@0: * @param status A pointer to an UErrorCode to receive any errors michael@0: * @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if michael@0: * an error occurred. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE UDateFormat* U_EXPORT2 michael@0: udat_open(UDateFormatStyle timeStyle, michael@0: UDateFormatStyle dateStyle, michael@0: const char *locale, michael@0: const UChar *tzID, michael@0: int32_t tzIDLength, michael@0: const UChar *pattern, michael@0: int32_t patternLength, michael@0: UErrorCode *status); michael@0: michael@0: michael@0: /** michael@0: * Close a UDateFormat. michael@0: * Once closed, a UDateFormat may no longer be used. michael@0: * @param format The formatter to close. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: udat_close(UDateFormat* format); michael@0: michael@0: michael@0: /** michael@0: * DateFormat boolean attributes michael@0: * @internal ICU technology preview michael@0: */ michael@0: typedef enum UDateFormatBooleanAttribute { michael@0: /** michael@0: * indicates whether whitespace is allowed. Includes trailing dot tolerance. michael@0: * @internal ICU technology preview michael@0: */ michael@0: UDAT_PARSE_ALLOW_WHITESPACE, michael@0: /** michael@0: * indicates tolerance of numeric data when String data may be assumed. eg: UDAT_YEAR_NAME_FIELD, michael@0: * UDAT_STANDALONE_MONTH_FIELD, UDAT_DAY_OF_WEEK_FIELD michael@0: * @internal ICU technology preview michael@0: */ michael@0: UDAT_PARSE_ALLOW_NUMERIC, michael@0: /** michael@0: * count boolean date format constants michael@0: * @internal ICU technology preview michael@0: */ michael@0: UDAT_BOOLEAN_ATTRIBUTE_COUNT michael@0: } UDateFormatBooleanAttribute; michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * Get a boolean attribute associated with a UDateFormat. michael@0: * An example would be a true value for a key of UDAT_PARSE_ALLOW_WHITESPACE indicating allowing whitespace leniency. michael@0: * If the formatter does not understand the attribute, -1 is returned. michael@0: * @param fmt The formatter to query. michael@0: * @param attr The attribute to query; e.g. UDAT_PARSE_ALLOW_WHITESPACE. michael@0: * @param status A pointer to an UErrorCode to receive any errors michael@0: * @return The value of attr. michael@0: * @internal technology preview michael@0: */ michael@0: U_INTERNAL UBool U_EXPORT2 michael@0: udat_getBooleanAttribute(const UDateFormat* fmt, UDateFormatBooleanAttribute attr, UErrorCode* status); michael@0: michael@0: /** michael@0: * Set a boolean attribute associated with a UDateFormat. michael@0: * An example of a boolean attribute is parse leniency control. If the formatter does not understand michael@0: * the attribute, the call is ignored. michael@0: * @param fmt The formatter to set. michael@0: * @param attr The attribute to set; one of UDAT_PARSE_ALLOW_WHITESPACE or UDAT_PARSE_ALLOW_NUMERIC michael@0: * @param newValue The new value of attr. michael@0: * @param status A pointer to an UErrorCode to receive any errors michael@0: * @internal ICU technology preview michael@0: */ michael@0: U_INTERNAL void U_EXPORT2 michael@0: udat_setBooleanAttribute(UDateFormat *fmt, UDateFormatBooleanAttribute attr, UBool, UErrorCode* status); michael@0: michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: michael@0: michael@0: #if U_SHOW_CPLUSPLUS_API michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: /** michael@0: * \class LocalUDateFormatPointer michael@0: * "Smart pointer" class, closes a UDateFormat via udat_close(). michael@0: * For most methods see the LocalPointerBase base class. michael@0: * michael@0: * @see LocalPointerBase michael@0: * @see LocalPointer michael@0: * @stable ICU 4.4 michael@0: */ michael@0: U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateFormatPointer, UDateFormat, udat_close); michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Open a copy of a UDateFormat. michael@0: * This function performs a deep copy. michael@0: * @param fmt The format to copy michael@0: * @param status A pointer to an UErrorCode to receive any errors. michael@0: * @return A pointer to a UDateFormat identical to fmt. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE UDateFormat* U_EXPORT2 michael@0: udat_clone(const UDateFormat *fmt, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Format a date using an UDateFormat. michael@0: * The date will be formatted using the conventions specified in {@link #udat_open } michael@0: * @param format The formatter to use michael@0: * @param dateToFormat The date to format michael@0: * @param result A pointer to a buffer to receive the formatted number. michael@0: * @param resultLength The maximum size of result. michael@0: * @param position A pointer to a UFieldPosition. On input, position->field michael@0: * is read. On output, position->beginIndex and position->endIndex indicate michael@0: * the beginning and ending indices of field number position->field, if such michael@0: * a field exists. This parameter may be NULL, in which case no field michael@0: * position data is returned. michael@0: * @param status A pointer to an UErrorCode to receive any errors michael@0: * @return The total buffer size needed; if greater than resultLength, the output was truncated. michael@0: * @see udat_parse michael@0: * @see UFieldPosition michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: udat_format( const UDateFormat* format, michael@0: UDate dateToFormat, michael@0: UChar* result, michael@0: int32_t resultLength, michael@0: UFieldPosition* position, michael@0: UErrorCode* status); michael@0: michael@0: /** michael@0: * Parse a string into an date/time using a UDateFormat. michael@0: * The date will be parsed using the conventions specified in {@link #udat_open }. michael@0: *

michael@0: * Note that the normal date formats associated with some calendars - such michael@0: * as the Chinese lunar calendar - do not specify enough fields to enable michael@0: * dates to be parsed unambiguously. In the case of the Chinese lunar michael@0: * calendar, while the year within the current 60-year cycle is specified, michael@0: * the number of such cycles since the start date of the calendar (in the michael@0: * UCAL_ERA field of the UCalendar object) is not normally part of the format, michael@0: * and parsing may assume the wrong era. For cases such as this it is michael@0: * recommended that clients parse using udat_parseCalendar with the UCalendar michael@0: * passed in set to the current date, or to a date within the era/cycle that michael@0: * should be assumed if absent in the format. michael@0: * michael@0: * @param format The formatter to use. michael@0: * @param text The text to parse. michael@0: * @param textLength The length of text, or -1 if null-terminated. michael@0: * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which michael@0: * to begin parsing. If not 0, on output the offset at which parsing ended. michael@0: * @param status A pointer to an UErrorCode to receive any errors michael@0: * @return The value of the parsed date/time michael@0: * @see udat_format michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE UDate U_EXPORT2 michael@0: udat_parse(const UDateFormat* format, michael@0: const UChar* text, michael@0: int32_t textLength, michael@0: int32_t *parsePos, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Parse a string into an date/time using a UDateFormat. michael@0: * The date will be parsed using the conventions specified in {@link #udat_open }. michael@0: * @param format The formatter to use. michael@0: * @param calendar A calendar set on input to the date and time to be used for michael@0: * missing values in the date/time string being parsed, and set michael@0: * on output to the parsed date/time. When the calendar type is michael@0: * different from the internal calendar held by the UDateFormat michael@0: * instance, the internal calendar will be cloned to a work michael@0: * calendar set to the same milliseconds and time zone as this michael@0: * calendar parameter, field values will be parsed based on the michael@0: * work calendar, then the result (milliseconds and time zone) michael@0: * will be set in this calendar. michael@0: * @param text The text to parse. michael@0: * @param textLength The length of text, or -1 if null-terminated. michael@0: * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which michael@0: * to begin parsing. If not 0, on output the offset at which parsing ended. michael@0: * @param status A pointer to an UErrorCode to receive any errors michael@0: * @see udat_format michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: udat_parseCalendar(const UDateFormat* format, michael@0: UCalendar* calendar, michael@0: const UChar* text, michael@0: int32_t textLength, michael@0: int32_t *parsePos, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Determine if an UDateFormat will perform lenient parsing. michael@0: * With lenient parsing, the parser may use heuristics to interpret inputs that do not michael@0: * precisely match the pattern. With strict parsing, inputs must match the pattern. michael@0: * @param fmt The formatter to query michael@0: * @return TRUE if fmt is set to perform lenient parsing, FALSE otherwise. michael@0: * @see udat_setLenient michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: udat_isLenient(const UDateFormat* fmt); michael@0: michael@0: /** michael@0: * Specify whether an UDateFormat will perform lenient parsing. michael@0: * With lenient parsing, the parser may use heuristics to interpret inputs that do not michael@0: * precisely match the pattern. With strict parsing, inputs must match the pattern. michael@0: * @param fmt The formatter to set michael@0: * @param isLenient TRUE if fmt should perform lenient parsing, FALSE otherwise. michael@0: * @see dat_isLenient michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: udat_setLenient( UDateFormat* fmt, michael@0: UBool isLenient); michael@0: michael@0: /** michael@0: * Get the UCalendar associated with an UDateFormat. michael@0: * A UDateFormat uses a UCalendar to convert a raw value to, for example, michael@0: * the day of the week. michael@0: * @param fmt The formatter to query. michael@0: * @return A pointer to the UCalendar used by fmt. michael@0: * @see udat_setCalendar michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE const UCalendar* U_EXPORT2 michael@0: udat_getCalendar(const UDateFormat* fmt); michael@0: michael@0: /** michael@0: * Set the UCalendar associated with an UDateFormat. michael@0: * A UDateFormat uses a UCalendar to convert a raw value to, for example, michael@0: * the day of the week. michael@0: * @param fmt The formatter to set. michael@0: * @param calendarToSet A pointer to an UCalendar to be used by fmt. michael@0: * @see udat_setCalendar michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: udat_setCalendar( UDateFormat* fmt, michael@0: const UCalendar* calendarToSet); michael@0: michael@0: /** michael@0: * Get the UNumberFormat associated with an UDateFormat. michael@0: * A UDateFormat uses a UNumberFormat to format numbers within a date, michael@0: * for example the day number. michael@0: * @param fmt The formatter to query. michael@0: * @return A pointer to the UNumberFormat used by fmt to format numbers. michael@0: * @see udat_setNumberFormat michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE const UNumberFormat* U_EXPORT2 michael@0: udat_getNumberFormat(const UDateFormat* fmt); michael@0: michael@0: /** michael@0: * Set the UNumberFormat associated with an UDateFormat. michael@0: * A UDateFormat uses a UNumberFormat to format numbers within a date, michael@0: * for example the day number. michael@0: * @param fmt The formatter to set. michael@0: * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers. michael@0: * @see udat_getNumberFormat michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: udat_setNumberFormat( UDateFormat* fmt, michael@0: const UNumberFormat* numberFormatToSet); michael@0: michael@0: /** michael@0: * Get a locale for which date/time formatting patterns are available. michael@0: * A UDateFormat in a locale returned by this function will perform the correct michael@0: * formatting and parsing for the locale. michael@0: * @param localeIndex The index of the desired locale. michael@0: * @return A locale for which date/time formatting patterns are available, or 0 if none. michael@0: * @see udat_countAvailable michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE const char* U_EXPORT2 michael@0: udat_getAvailable(int32_t localeIndex); michael@0: michael@0: /** michael@0: * Determine how many locales have date/time formatting patterns available. michael@0: * This function is most useful as determining the loop ending condition for michael@0: * calls to {@link #udat_getAvailable }. michael@0: * @return The number of locales for which date/time formatting patterns are available. michael@0: * @see udat_getAvailable michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: udat_countAvailable(void); michael@0: michael@0: /** michael@0: * Get the year relative to which all 2-digit years are interpreted. michael@0: * For example, if the 2-digit start year is 2100, the year 99 will be michael@0: * interpreted as 2199. michael@0: * @param fmt The formatter to query. michael@0: * @param status A pointer to an UErrorCode to receive any errors michael@0: * @return The year relative to which all 2-digit years are interpreted. michael@0: * @see udat_Set2DigitYearStart michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE UDate U_EXPORT2 michael@0: udat_get2DigitYearStart( const UDateFormat *fmt, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Set the year relative to which all 2-digit years will be interpreted. michael@0: * For example, if the 2-digit start year is 2100, the year 99 will be michael@0: * interpreted as 2199. michael@0: * @param fmt The formatter to set. michael@0: * @param d The year relative to which all 2-digit years will be interpreted. michael@0: * @param status A pointer to an UErrorCode to receive any errors michael@0: * @see udat_Set2DigitYearStart michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: udat_set2DigitYearStart( UDateFormat *fmt, michael@0: UDate d, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Extract the pattern from a UDateFormat. michael@0: * The pattern will follow the pattern syntax rules. michael@0: * @param fmt The formatter to query. michael@0: * @param localized TRUE if the pattern should be localized, FALSE otherwise. michael@0: * @param result A pointer to a buffer to receive the pattern. michael@0: * @param resultLength The maximum size of result. michael@0: * @param status A pointer to an UErrorCode to receive any errors michael@0: * @return The total buffer size needed; if greater than resultLength, the output was truncated. michael@0: * @see udat_applyPattern michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: udat_toPattern( const UDateFormat *fmt, michael@0: UBool localized, michael@0: UChar *result, michael@0: int32_t resultLength, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Set the pattern used by an UDateFormat. michael@0: * The pattern should follow the pattern syntax rules. michael@0: * @param format The formatter to set. michael@0: * @param localized TRUE if the pattern is localized, FALSE otherwise. michael@0: * @param pattern The new pattern michael@0: * @param patternLength The length of pattern, or -1 if null-terminated. michael@0: * @see udat_toPattern michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: udat_applyPattern( UDateFormat *format, michael@0: UBool localized, michael@0: const UChar *pattern, michael@0: int32_t patternLength); michael@0: michael@0: /** michael@0: * The possible types of date format symbols michael@0: * @stable ICU 2.6 michael@0: */ michael@0: typedef enum UDateFormatSymbolType { michael@0: /** The era names, for example AD */ michael@0: UDAT_ERAS, michael@0: /** The month names, for example February */ michael@0: UDAT_MONTHS, michael@0: /** The short month names, for example Feb. */ michael@0: UDAT_SHORT_MONTHS, michael@0: /** The CLDR-style format "wide" weekday names, for example Monday */ michael@0: UDAT_WEEKDAYS, michael@0: /** michael@0: * The CLDR-style format "abbreviated" (not "short") weekday names, for example "Mon." michael@0: * For the CLDR-style format "short" weekday names, use UDAT_SHORTER_WEEKDAYS. michael@0: */ michael@0: UDAT_SHORT_WEEKDAYS, michael@0: /** The AM/PM names, for example AM */ michael@0: UDAT_AM_PMS, michael@0: /** The localized characters */ michael@0: UDAT_LOCALIZED_CHARS, michael@0: /** The long era names, for example Anno Domini */ michael@0: UDAT_ERA_NAMES, michael@0: /** The narrow month names, for example F */ michael@0: UDAT_NARROW_MONTHS, michael@0: /** The CLDR-style format "narrow" weekday names, for example "M" */ michael@0: UDAT_NARROW_WEEKDAYS, michael@0: /** Standalone context versions of months */ michael@0: UDAT_STANDALONE_MONTHS, michael@0: UDAT_STANDALONE_SHORT_MONTHS, michael@0: UDAT_STANDALONE_NARROW_MONTHS, michael@0: /** The CLDR-style stand-alone "wide" weekday names */ michael@0: UDAT_STANDALONE_WEEKDAYS, michael@0: /** michael@0: * The CLDR-style stand-alone "abbreviated" (not "short") weekday names. michael@0: * For the CLDR-style stand-alone "short" weekday names, use UDAT_STANDALONE_SHORTER_WEEKDAYS. michael@0: */ michael@0: UDAT_STANDALONE_SHORT_WEEKDAYS, michael@0: /** The CLDR-style stand-alone "narrow" weekday names */ michael@0: UDAT_STANDALONE_NARROW_WEEKDAYS, michael@0: /** The quarters, for example 1st Quarter */ michael@0: UDAT_QUARTERS, michael@0: /** The short quarter names, for example Q1 */ michael@0: UDAT_SHORT_QUARTERS, michael@0: /** Standalone context versions of quarters */ michael@0: UDAT_STANDALONE_QUARTERS, michael@0: UDAT_STANDALONE_SHORT_QUARTERS, michael@0: #ifndef U_HIDE_DRAFT_API michael@0: /** michael@0: * The CLDR-style short weekday names, e.g. "Su", Mo", etc. michael@0: * These are named "SHORTER" to contrast with the constants using _SHORT_ michael@0: * above, which actually get the CLDR-style *abbreviated* versions of the michael@0: * corresponding names. michael@0: * @draft ICU 51 michael@0: */ michael@0: UDAT_SHORTER_WEEKDAYS, michael@0: /** michael@0: * Standalone version of UDAT_SHORTER_WEEKDAYS. michael@0: * @draft ICU 51 michael@0: */ michael@0: UDAT_STANDALONE_SHORTER_WEEKDAYS michael@0: #endif /* U_HIDE_DRAFT_API */ michael@0: } UDateFormatSymbolType; michael@0: michael@0: struct UDateFormatSymbols; michael@0: /** Date format symbols. michael@0: * For usage in C programs. michael@0: * @stable ICU 2.6 michael@0: */ michael@0: typedef struct UDateFormatSymbols UDateFormatSymbols; michael@0: michael@0: /** michael@0: * Get the symbols associated with an UDateFormat. michael@0: * The symbols are what a UDateFormat uses to represent locale-specific data, michael@0: * for example month or day names. michael@0: * @param fmt The formatter to query. michael@0: * @param type The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, michael@0: * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS michael@0: * @param symbolIndex The desired symbol of type type. michael@0: * @param result A pointer to a buffer to receive the pattern. michael@0: * @param resultLength The maximum size of result. michael@0: * @param status A pointer to an UErrorCode to receive any errors michael@0: * @return The total buffer size needed; if greater than resultLength, the output was truncated. michael@0: * @see udat_countSymbols michael@0: * @see udat_setSymbols michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: udat_getSymbols(const UDateFormat *fmt, michael@0: UDateFormatSymbolType type, michael@0: int32_t symbolIndex, michael@0: UChar *result, michael@0: int32_t resultLength, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Count the number of particular symbols for an UDateFormat. michael@0: * This function is most useful as for detemining the loop termination condition michael@0: * for calls to {@link #udat_getSymbols }. michael@0: * @param fmt The formatter to query. michael@0: * @param type The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, michael@0: * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS michael@0: * @return The number of symbols of type type. michael@0: * @see udat_getSymbols michael@0: * @see udat_setSymbols michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: udat_countSymbols( const UDateFormat *fmt, michael@0: UDateFormatSymbolType type); michael@0: michael@0: /** michael@0: * Set the symbols associated with an UDateFormat. michael@0: * The symbols are what a UDateFormat uses to represent locale-specific data, michael@0: * for example month or day names. michael@0: * @param format The formatter to set michael@0: * @param type The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, michael@0: * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS michael@0: * @param symbolIndex The index of the symbol to set of type type. michael@0: * @param value The new value michael@0: * @param valueLength The length of value, or -1 if null-terminated michael@0: * @param status A pointer to an UErrorCode to receive any errors michael@0: * @see udat_getSymbols michael@0: * @see udat_countSymbols michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: udat_setSymbols( UDateFormat *format, michael@0: UDateFormatSymbolType type, michael@0: int32_t symbolIndex, michael@0: UChar *value, michael@0: int32_t valueLength, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Get the locale for this date format object. michael@0: * You can choose between valid and actual locale. michael@0: * @param fmt The formatter to get the locale from michael@0: * @param type type of the locale we're looking for (valid or actual) michael@0: * @param status error code for the operation michael@0: * @return the locale name michael@0: * @stable ICU 2.8 michael@0: */ michael@0: U_STABLE const char* U_EXPORT2 michael@0: udat_getLocaleByType(const UDateFormat *fmt, michael@0: ULocDataLocaleType type, michael@0: UErrorCode* status); michael@0: michael@0: #ifndef U_HIDE_DRAFT_API michael@0: /** michael@0: * Set a particular UDisplayContext value in the formatter, such as michael@0: * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. michael@0: * @param fmt The formatter for which to set a UDisplayContext value. michael@0: * @param value The UDisplayContext value to set. michael@0: * @param status A pointer to an UErrorCode to receive any errors michael@0: * @draft ICU 51 michael@0: */ michael@0: U_DRAFT void U_EXPORT2 michael@0: udat_setContext(UDateFormat* fmt, UDisplayContext value, UErrorCode* status); michael@0: michael@0: /** michael@0: * Get the formatter's UDisplayContext value for the specified UDisplayContextType, michael@0: * such as UDISPCTX_TYPE_CAPITALIZATION. michael@0: * @param fmt The formatter to query. michael@0: * @param type The UDisplayContextType whose value to return michael@0: * @param status A pointer to an UErrorCode to receive any errors michael@0: * @return The UDisplayContextValue for the specified type. michael@0: * @draft ICU 51 michael@0: */ michael@0: U_DRAFT UDisplayContext U_EXPORT2 michael@0: udat_getContext(UDateFormat* fmt, UDisplayContextType type, UErrorCode* status); michael@0: michael@0: #endif /* U_HIDE_DRAFT_API */ michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * Extract the date pattern from a UDateFormat set for relative date formatting. michael@0: * The pattern will follow the pattern syntax rules. michael@0: * @param fmt The formatter to query. michael@0: * @param result A pointer to a buffer to receive the pattern. michael@0: * @param resultLength The maximum size of result. michael@0: * @param status A pointer to a UErrorCode to receive any errors michael@0: * @return The total buffer size needed; if greater than resultLength, the output was truncated. michael@0: * @see udat_applyPatternRelative michael@0: * @internal ICU 4.2 technology preview michael@0: */ michael@0: U_INTERNAL int32_t U_EXPORT2 michael@0: udat_toPatternRelativeDate(const UDateFormat *fmt, michael@0: UChar *result, michael@0: int32_t resultLength, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Extract the time pattern from a UDateFormat set for relative date formatting. michael@0: * The pattern will follow the pattern syntax rules. michael@0: * @param fmt The formatter to query. michael@0: * @param result A pointer to a buffer to receive the pattern. michael@0: * @param resultLength The maximum size of result. michael@0: * @param status A pointer to a UErrorCode to receive any errors michael@0: * @return The total buffer size needed; if greater than resultLength, the output was truncated. michael@0: * @see udat_applyPatternRelative michael@0: * @internal ICU 4.2 technology preview michael@0: */ michael@0: U_INTERNAL int32_t U_EXPORT2 michael@0: udat_toPatternRelativeTime(const UDateFormat *fmt, michael@0: UChar *result, michael@0: int32_t resultLength, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Set the date & time patterns used by a UDateFormat set for relative date formatting. michael@0: * The patterns should follow the pattern syntax rules. michael@0: * @param format The formatter to set. michael@0: * @param datePattern The new date pattern michael@0: * @param datePatternLength The length of datePattern, or -1 if null-terminated. michael@0: * @param timePattern The new time pattern michael@0: * @param timePatternLength The length of timePattern, or -1 if null-terminated. michael@0: * @param status A pointer to a UErrorCode to receive any errors michael@0: * @see udat_toPatternRelativeDate, udat_toPatternRelativeTime michael@0: * @internal ICU 4.2 technology preview michael@0: */ michael@0: U_INTERNAL void U_EXPORT2 michael@0: udat_applyPatternRelative(UDateFormat *format, michael@0: const UChar *datePattern, michael@0: int32_t datePatternLength, michael@0: const UChar *timePattern, michael@0: int32_t timePatternLength, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * @internal michael@0: * @see udat_open michael@0: */ michael@0: typedef UDateFormat* (U_EXPORT2 *UDateFormatOpener) (UDateFormatStyle timeStyle, michael@0: UDateFormatStyle dateStyle, michael@0: const char *locale, michael@0: const UChar *tzID, michael@0: int32_t tzIDLength, michael@0: const UChar *pattern, michael@0: int32_t patternLength, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Register a provider factory michael@0: * @internal ICU 49 michael@0: */ michael@0: U_INTERNAL void U_EXPORT2 michael@0: udat_registerOpener(UDateFormatOpener opener, UErrorCode *status); michael@0: michael@0: /** michael@0: * Un-Register a provider factory michael@0: * @internal ICU 49 michael@0: */ michael@0: U_INTERNAL UDateFormatOpener U_EXPORT2 michael@0: udat_unregisterOpener(UDateFormatOpener opener, UErrorCode *status); michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: michael@0: #endif