Main Page   Class Hierarchy   Compound List   File List   Header Files   Sources   Compound Members   File Members  

udat.h File Reference

Date Format C API. More...


Typedefs

typedef void* UDateFormat
A date formatter. More...

typedef enum UDateFormatStyle UDateFormatStyle
typedef enum UDateFormatSymbolType UDateFormatSymbolType
typedef struct UDateFormatSymbols UDateFormatSymbols

Enumerations

enum  UDateFormatStyle { UDAT_FULL, UDAT_LONG, UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_NONE }
The possible date/time format styles. More...

enum  UDateFormatSymbolType { UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, UDAT_LOCALIZED_CHARS }
The possible types of date format symbols. More...


Functions

U_CAPI UDateFormatudat_open (UDateFormatStyle timeStyle, UDateFormatStyle dateStyle, const char *locale, const UChar *tzID, int32_t tzIDLength, UErrorCode *status)
Open a new UDateFormat for formatting and parsing dates and times. More...

U_CAPI UDateFormatudat_openPattern ( const UChar *pattern, int32_t patternLength, const char *locale, UErrorCode *status)
Open a new UDateFormat for formatting dates and times. More...

U_CAPI void udat_close (UDateFormat* format)
Close a UDateFormat. More...

U_CAPI UDateFormatudat_clone (const UDateFormat *fmt, UErrorCode *status)
Open a copy of a UDateFormat. More...

U_CAPI int32_t udat_format ( const UDateFormat* format, UDate dateToFormat, UChar* result, int32_t resultLength, UFieldPosition* position, UErrorCode* status)
Format a date using an UDateFormat. More...

U_CAPI UDate udat_parse ( const UDateFormat* format, const UChar* text, int32_t textLength, int32_t *parsePos, UErrorCode *status)
Parse a string into an date/time using a UDateFormat. More...

U_CAPI UBool udat_isLenient (const UDateFormat* fmt)
Determine if an UDateFormat will perform lenient parsing. More...

U_CAPI void udat_setLenient ( UDateFormat* fmt, UBool isLenient)
Specify whether an UDateFormat will perform lenient parsing. More...

U_CAPI const UCalendarudat_getCalendar (const UDateFormat* fmt)
Get the UCalendar associated with an UDateFormat. More...

U_CAPI void udat_setCalendar ( UDateFormat* fmt, const UCalendar* calendarToSet)
Set the UCalendar associated with an UDateFormat. More...

U_CAPI const UNumberFormatudat_getNumberFormat (const UDateFormat* fmt)
Get the UNumberFormat associated with an UDateFormat. More...

U_CAPI void udat_setNumberFormat ( UDateFormat* fmt, const UNumberFormat* numberFormatToSet)
Set the UNumberFormat associated with an UDateFormat. More...

U_CAPI const char* udat_getAvailable (int32_t index)
Get a locale for which date/time formatting patterns are available. More...

U_CAPI int32_t udat_countAvailable (void)
Determine how many locales have date/time formatting patterns available. More...

U_CAPI UDate udat_get2DigitYearStart ( const UDateFormat *fmt, UErrorCode *status)
Get the year relative to which all 2-digit years are interpreted. More...

U_CAPI void udat_set2DigitYearStart ( UDateFormat *fmt, UDate d, UErrorCode *status)
Set the year relative to which all 2-digit years will be interpreted. More...

U_CAPI int32_t udat_toPattern ( const UDateFormat *fmt, UBool localized, UChar *result, int32_t resultLength, UErrorCode *status)
Extract the pattern from a UDateFormat. More...

U_CAPI void udat_applyPattern ( UDateFormat *format, UBool localized, const UChar *pattern, int32_t patternLength)
Set the pattern used by an UDateFormat. More...

U_CAPI int32_t udat_getSymbols (const UDateFormat *fmt, UDateFormatSymbolType type, int32_t index, UChar *result, int32_t resultLength, UErrorCode *status)
Get the symbols associated with an UDateFormat. More...

U_CAPI int32_t udat_countSymbols ( const UDateFormat *fmt, UDateFormatSymbolType type)
Count the number of particular symbols for an UDateFormat. More...

U_CAPI void udat_setSymbols ( UDateFormat *format, UDateFormatSymbolType type, int32_t index, UChar *value, int32_t valueLength, UErrorCode *status)
Set the symbols associated with an UDateFormat. More...


Variables

struct UDateFormatSymbols
Date format symbols. More...


Detailed Description

Date Format C API.

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

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

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

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

You can also use forms of the parse and format methods with Parse Position and UFieldPosition to allow you to

Definition in file udat.h.


Typedef Documentation

typedef void* UDateFormat

A date formatter.

For usage in C programs.

Definition at line 98 of file udat.h.

typedef enum UDateFormatStyle UDateFormatStyle

Definition at line 115 of file udat.h.

typedef enum UDateFormatSymbolType UDateFormatSymbolType

Definition at line 405 of file udat.h.

typedef struct UDateFormatSymbols UDateFormatSymbols

Definition at line 411 of file udat.h.


Enumeration Type Documentation

enum UDateFormatStyle

The possible date/time format styles.

Enumeration values:
UDAT_FULL   Full style.
UDAT_LONG   Long style.
UDAT_MEDIUM   Medium style.
UDAT_SHORT   Short style.
UDAT_DEFAULT   Default style.
UDAT_NONE   No style.

Definition at line 101 of file udat.h.

enum UDateFormatSymbolType

The possible types of date format symbols.

Enumeration values:
UDAT_ERAS   The era names, for example AD.
UDAT_MONTHS   The month names, for example February.
UDAT_SHORT_MONTHS   The short month names, for example Feb.
UDAT_WEEKDAYS   The weekday names, for example Monday.
UDAT_SHORT_WEEKDAYS   The short weekday names, for example Mon.
UDAT_AM_PMS   The AM/PM names, for example AM.
UDAT_LOCALIZED_CHARS   The localized characters.

Definition at line 389 of file udat.h.


Function Documentation

U_CAPI UDateFormat * udat_open (UDateFormatStyle timeStyle, UDateFormatStyle dateStyle, const char * locale, const UChar * tzID, int32_t tzIDLength, UErrorCode * status)

Open a new UDateFormat for formatting and parsing dates and times.

A UDateFormat may be used to format dates in calls to \Ref{udat_format}, and to parse dates in calls to \Ref{udat_parse}.

Parameters:
timeStyle   The style used to format times; one of UDAT_FULL_STYLE, UDAT_LONG_STYLE, UDAT_MEDIUM_STYLE, UDAT_SHORT_STYLE, or UDAT_DEFAULT_STYLE
dateStyle   The style used to format dates; one of UDAT_FULL_STYLE, UDAT_LONG_STYLE, UDAT_MEDIUM_STYLE, UDAT_SHORT_STYLE, or UDAT_DEFAULT_STYLE
locale   The locale specifying the formatting conventions
tzID   A timezone ID specifying the timezone to use. If 0, use the default timezone.
tzIDLength   The length of tzID, or -1 if null-terminated.
status   A pointer to an UErrorCode to receive any errors
Returns:
A pointer to a UDateFormat to use for formatting dates and times, or 0 if an error occurred.
See also:
udat_openPattern()
Draft:

U_CAPI UDateFormat * udat_openPattern (const UChar * pattern, int32_t patternLength, const char * locale, UErrorCode * status)

Open a new UDateFormat for formatting dates and times.

A UDateFormat may be used to format dates in calls to \Ref{udat_format}, and to parse dates in calls to \Ref{udat_parse}.

Parameters:
pattern   A pattern specifying the format to use.
patternLength   The number of characters in the pattern, or -1 if null-terminated.
locale   The locale specifying the formatting conventions
status   A pointer to an UErrorCode to receive any errors
Returns:
A pointer to a UDateFormat to use for formatting dates and times, or 0 if an error occurred.
See also:
udat_open()
Draft:

U_CAPI void udat_close (UDateFormat * format)

Close a UDateFormat.

Once closed, a UDateFormat may no longer be used.

Parameters:
fmt   The formatter to close.
Stable:

U_CAPI UDateFormat * udat_clone (const UDateFormat * fmt, UErrorCode * status)

Open a copy of a UDateFormat.

This function performs a deep copy.

Parameters:
fmt   The format to copy
status   A pointer to an UErrorCode to receive any errors.
Returns:
A pointer to a UDateFormat identical to fmt.
Stable:

U_CAPI int32_t udat_format (const UDateFormat * format, UDate dateToFormat, UChar * result, int32_t resultLength, UFieldPosition * position, UErrorCode * status)

Format a date using an UDateFormat.

The date will be formatted using the conventions specified in \Ref{udat_open} or \Ref{udat_openPattern}

Parameters:
format   The formatter to use
dateToFormat   The date to format
result   A pointer to a buffer to receive the formatted number.
resultLength   The maximum size of result.
pos   If not 0, a UFieldPosition which will receive the information on a specific field.
status   A pointer to an UErrorCode to receive any errors
Returns:
The total buffer size needed; if greater than resultLength, the output was truncated.
See also:
udat_parse()
Draft:

U_CAPI UDate udat_parse (const UDateFormat * format, const UChar * text, int32_t textLength, int32_t * parsePos, UErrorCode * status)

Parse a string into an date/time using a UDateFormat.

The date will be parsed using the conventions specified in \Ref{udat_open} or \Ref{udat_openPattern}

Parameters:
fmt   The formatter to use.
text   The text to parse.
textLength   The length of text, or -1 if null-terminated.
parsePos   If not 0, on input a pointer to an integer specifying the offset at which to begin parsing. If not 0, on output the offset at which parsing ended.
status   A pointer to an UErrorCode to receive any errors
Returns:
The value of the parsed date/time
See also:
udat_format()
Draft:

U_CAPI UBool udat_isLenient (const UDateFormat * fmt)

Determine if an UDateFormat will perform lenient parsing.

With lenient parsing, the parser may use heuristics to interpret inputs that do not precisely match the pattern. With strict parsing, inputs must match the pattern.

Parameters:
fmt   The formatter to query
Returns:
TRUE if fmt is set to perform lenient parsing, FALSE otherwise.
See also:
udat_setLenient()
Stable:

U_CAPI void udat_setLenient (UDateFormat * fmt, UBool isLenient)

Specify whether an UDateFormat will perform lenient parsing.

With lenient parsing, the parser may use heuristics to interpret inputs that do not precisely match the pattern. With strict parsing, inputs must match the pattern.

Parameters:
fmt   The formatter to set
isLenient   TRUE if fmt should perform lenient parsing, FALSE otherwise.
See also:
dat_isLenient
Stable:

U_CAPI const UCalendar * udat_getCalendar (const UDateFormat * fmt)

Get the UCalendar associated with an UDateFormat.

A UDateFormat uses a UCalendar to convert a raw value to, for example, the day of the week.

Parameters:
fmt   The formatter to query.
Returns:
A pointer to the UCalendar used by fmt.
See also:
udat_setCalendar()
Stable:

U_CAPI void udat_setCalendar (UDateFormat * fmt, const UCalendar * calendarToSet)

Set the UCalendar associated with an UDateFormat.

A UDateFormat uses a UCalendar to convert a raw value to, for example, the day of the week.

Parameters:
fmt   The formatter to set.
calendarToSet   A pointer to an UCalendar to be used by fmt.
See also:
udat_setCalendar()
Stable:

U_CAPI const UNumberFormat * udat_getNumberFormat (const UDateFormat * fmt)

Get the UNumberFormat associated with an UDateFormat.

A UDateFormat uses a UNumberFormat to format numbers within a date, for example the day number.

Parameters:
fmt   The formatter to query.
Returns:
A pointer to the UNumberFormat used by fmt to format numbers.
See also:
udat_setNumberFormat()
Stable:

U_CAPI void udat_setNumberFormat (UDateFormat * fmt, const UNumberFormat * numberFormatToSet)

Set the UNumberFormat associated with an UDateFormat.

A UDateFormat uses a UNumberFormat to format numbers within a date, for example the day number.

Parameters:
fmt   The formatter to set.
numberFormatToSet   A pointer to the UNumberFormat to be used by fmt to format numbers.
See also:
udat_getNumberFormat()
Stable:

U_CAPI const char * udat_getAvailable (int32_t index)

Get a locale for which date/time formatting patterns are available.

A UDateFormat in a locale returned by this function will perform the correct formatting and parsing for the locale.

Parameters:
index   The index of the desired locale.
Returns:
A locale for which date/time formatting patterns are available, or 0 if none.
See also:
udat_countAvailable()
Stable:

U_CAPI int32_t udat_countAvailable (void)

Determine how many locales have date/time formatting patterns available.

This function is most useful as determining the loop ending condition for calls to \Ref{udat_getAvailable}.

Returns:
The number of locales for which date/time formatting patterns are available.
See also:
udat_getAvailable()
Stable:

U_CAPI UDate udat_get2DigitYearStart (const UDateFormat * fmt, UErrorCode * status)

Get the year relative to which all 2-digit years are interpreted.

For example, if the 2-digit start year is 2100, the year 99 will be interpreted as 2199.

Parameters:
fmt   The formatter to query.
status   A pointer to an UErrorCode to receive any errors
Returns:
The year relative to which all 2-digit years are interpreted.
See also:
udat_Set2DigitYearStart
Stable:

U_CAPI void udat_set2DigitYearStart (UDateFormat * fmt, UDate d, UErrorCode * status)

Set the year relative to which all 2-digit years will be interpreted.

For example, if the 2-digit start year is 2100, the year 99 will be interpreted as 2199.

Parameters:
fmt   The formatter to set.
d   The year relative to which all 2-digit years will be interpreted.
status   A pointer to an UErrorCode to receive any errors
See also:
udat_Set2DigitYearStart
Stable:

U_CAPI int32_t udat_toPattern (const UDateFormat * fmt, UBool localized, UChar * result, int32_t resultLength, UErrorCode * status)

Extract the pattern from a UDateFormat.

The pattern will follow the pattern syntax rules.

Parameters:
fmt   The formatter to query.
localized   TRUE if the pattern should be localized, FALSE otherwise.
result   A pointer to a buffer to receive the pattern.
resultLength   The maximum size of result.
status   A pointer to an UErrorCode to receive any errors
Returns:
The total buffer size needed; if greater than resultLength, the output was truncated.
See also:
udat_applyPattern()
Draft:

U_CAPI void udat_applyPattern (UDateFormat * format, UBool localized, const UChar * pattern, int32_t patternLength)

Set the pattern used by an UDateFormat.

The pattern should follow the pattern syntax rules.

Parameters:
fmt   The formatter to set.
localized   TRUE if the pattern is localized, FALSE otherwise.
pattern   The new pattern
patternLength   The length of pattern, or -1 if null-terminated.
See also:
udat_toPattern()
Draft:

U_CAPI int32_t udat_getSymbols (const UDateFormat * fmt, UDateFormatSymbolType type, int32_t index, UChar * result, int32_t resultLength, UErrorCode * status)

Get the symbols associated with an UDateFormat.

The symbols are what a UDateFormat uses to represent locale-specific data, for example month or day names.

Parameters:
fmt   The formatter to query.
type   The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
index   The desired symbol of type type.
result   A pointer to a buffer to receive the pattern.
resultLength   The maximum size of result.
status   A pointer to an UErrorCode to receive any errors
Returns:
The total buffer size needed; if greater than resultLength, the output was truncated.
See also:
udat_countSymbols() , udat_setSymbols()
Draft:

U_CAPI int32_t udat_countSymbols (const UDateFormat * fmt, UDateFormatSymbolType type)

Count the number of particular symbols for an UDateFormat.

This function is most useful as for detemining the loop termination condition for calls to \Ref{udat_getSymbols}.

Parameters:
fmt   The formatter to query.
type   The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
Returns:
The number of symbols of type type.
See also:
udat_getSymbols() , udat_setSymbols()
Stable:

U_CAPI void udat_setSymbols (UDateFormat * format, UDateFormatSymbolType type, int32_t index, UChar * value, int32_t valueLength, UErrorCode * status)

Set the symbols associated with an UDateFormat.

The symbols are what a UDateFormat uses to represent locale-specific data, for example month or day names.

Parameters:
fmt   The formatter to set
type   The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
index   The index of the symbol to set of type type.
value   The new value
valueLength   The length of value, or -1 if null-terminated
status   A pointer to an UErrorCode to receive any errors
Returns:
A pointer to result.
See also:
udat_getSymbols() , udat_countSymbols()
Draft:

Variable Documentation

struct UDateFormatSymbols

Date format symbols.

For usage in C programs.

Definition at line 410 of file udat.h.


Generated at Mon Jun 5 12:52:59 2000 for ICU1.5 by doxygen 1.0.0 written by Dimitri van Heesch, © 1997-1999