C API: URelativeDateTimeFormatter, relative date formatting of unit + numeric offset.More...
#include "unicode/utypes.h"#include "unicode/unum.h"#include "unicode/udisplaycontext.h"#include "unicode/uformattedvalue.h"#include "unicode/localpointer.h"Go to the source code of this file.
Namespaces | |
| icu | |
| Filecoll.h. | |
Typedefs | |
| typedef enumUDateRelativeDateTimeFormatterStyle | UDateRelativeDateTimeFormatterStyle |
| The formatting style.More... | |
| typedef enumURelativeDateTimeUnit | URelativeDateTimeUnit |
| Represents the unit for formatting a relative date.More... | |
| typedef enumURelativeDateTimeFormatterField | URelativeDateTimeFormatterField |
| FieldPosition andUFieldPosition selectors for format fields defined by RelativeDateTimeFormatter.More... | |
| typedef structURelativeDateTimeFormatter | URelativeDateTimeFormatter |
| C typedef for struct URelativeDateTimeFormatter.More... | |
| typedef structUFormattedRelativeDateTime | UFormattedRelativeDateTime |
| Opaque struct to contain the results of a URelativeDateTimeFormatter operation.More... | |
Enumerations | |
| enum | UDateRelativeDateTimeFormatterStyle {UDAT_STYLE_LONG,UDAT_STYLE_SHORT,UDAT_STYLE_NARROW,UDAT_STYLE_COUNT } |
| The formatting style.More... | |
| enum | URelativeDateTimeUnit { UDAT_REL_UNIT_YEAR,UDAT_REL_UNIT_QUARTER,UDAT_REL_UNIT_MONTH,UDAT_REL_UNIT_WEEK, UDAT_REL_UNIT_DAY,UDAT_REL_UNIT_HOUR,UDAT_REL_UNIT_MINUTE,UDAT_REL_UNIT_SECOND, UDAT_REL_UNIT_SUNDAY,UDAT_REL_UNIT_MONDAY,UDAT_REL_UNIT_TUESDAY,UDAT_REL_UNIT_WEDNESDAY, UDAT_REL_UNIT_THURSDAY,UDAT_REL_UNIT_FRIDAY,UDAT_REL_UNIT_SATURDAY,UDAT_REL_UNIT_COUNT } |
| Represents the unit for formatting a relative date.More... | |
| enum | URelativeDateTimeFormatterField {UDAT_REL_LITERAL_FIELD,UDAT_REL_NUMERIC_FIELD } |
| FieldPosition andUFieldPosition selectors for format fields defined by RelativeDateTimeFormatter.More... | |
Functions | |
| U_CAPIURelativeDateTimeFormatter * | ureldatefmt_open (const char *locale,UNumberFormat *nfToAdopt,UDateRelativeDateTimeFormatterStyle width,UDisplayContext capitalizationContext,UErrorCode *status) |
| Open a new URelativeDateTimeFormatter object for a given locale using the specified width and capitalizationContext, along with a number formatter (if desired) to override the default formatter that would be used for display of numeric field offsets.More... | |
| U_CAPI void | ureldatefmt_close (URelativeDateTimeFormatter *reldatefmt) |
| Close a URelativeDateTimeFormatter object.More... | |
| U_CAPIUFormattedRelativeDateTime * | ureldatefmt_openResult (UErrorCode *ec) |
| Creates an object to hold the result of a URelativeDateTimeFormatter operation.More... | |
| U_CAPI constUFormattedValue * | ureldatefmt_resultAsValue (constUFormattedRelativeDateTime *ufrdt,UErrorCode *ec) |
| Returns a representation of a UFormattedRelativeDateTime as a UFormattedValue, which can be subsequently passed to any API requiring that type.More... | |
| U_CAPI void | ureldatefmt_closeResult (UFormattedRelativeDateTime *ufrdt) |
| Releases the UFormattedRelativeDateTime created by ureldatefmt_openResult.More... | |
| U_CAPI int32_t | ureldatefmt_formatNumeric (constURelativeDateTimeFormatter *reldatefmt, double offset,URelativeDateTimeUnit unit,UChar *result, int32_t resultCapacity,UErrorCode *status) |
| Format a combination of URelativeDateTimeUnit and numeric offset using a numeric style, e.g.More... | |
| U_CAPI void | ureldatefmt_formatNumericToResult (constURelativeDateTimeFormatter *reldatefmt, double offset,URelativeDateTimeUnit unit,UFormattedRelativeDateTime *result,UErrorCode *status) |
| Format a combination of URelativeDateTimeUnit and numeric offset using a numeric style, e.g.More... | |
| U_CAPI int32_t | ureldatefmt_format (constURelativeDateTimeFormatter *reldatefmt, double offset,URelativeDateTimeUnit unit,UChar *result, int32_t resultCapacity,UErrorCode *status) |
| Format a combination of URelativeDateTimeUnit and numeric offset using a text style if possible, e.g.More... | |
| U_CAPI void | ureldatefmt_formatToResult (constURelativeDateTimeFormatter *reldatefmt, double offset,URelativeDateTimeUnit unit,UFormattedRelativeDateTime *result,UErrorCode *status) |
| Format a combination of URelativeDateTimeUnit and numeric offset using a text style if possible, e.g.More... | |
| U_CAPI int32_t | ureldatefmt_combineDateAndTime (constURelativeDateTimeFormatter *reldatefmt, constUChar *relativeDateString, int32_t relativeDateStringLen, constUChar *timeString, int32_t timeStringLen,UChar *result, int32_t resultCapacity,UErrorCode *status) |
| Combines a relative date string and a time string in this object's locale.More... | |
C API: URelativeDateTimeFormatter, relative date formatting of unit + numeric offset.
Provides simple formatting of relative dates, in two ways
This does not provide compound formatting for multiple units, other than the ability to combine a time string with a relative date, as in "next Tuesday at 3:45 PM". It also does not provide support for determining which unit to use, such as deciding between "in 7 days" and "in 1 week".
Definition in fileureldatefmt.h.
The formatting style.
| typedef structUFormattedRelativeDateTimeUFormattedRelativeDateTime |
Opaque struct to contain the results of a URelativeDateTimeFormatter operation.
Definition at line254 of fileureldatefmt.h.
| typedef structURelativeDateTimeFormatterURelativeDateTimeFormatter |
C typedef for struct URelativeDateTimeFormatter.
Definition at line1 of fileureldatefmt.h.
FieldPosition andUFieldPosition selectors for format fields defined by RelativeDateTimeFormatter.
| typedef enumURelativeDateTimeUnitURelativeDateTimeUnit |
The formatting style.
| Enumerator | |
|---|---|
| UDAT_STYLE_LONG | Everything spelled out.
|
| UDAT_STYLE_SHORT | Abbreviations used when possible.
|
| UDAT_STYLE_NARROW | Use the shortest possible form.
|
| UDAT_STYLE_COUNT | One more than the highest normal UDateRelativeDateTimeFormatterStyle value.
|
Definition at line48 of fileureldatefmt.h.
FieldPosition andUFieldPosition selectors for format fields defined by RelativeDateTimeFormatter.
| Enumerator | |
|---|---|
| UDAT_REL_LITERAL_FIELD | Represents a literal text string, like "tomorrow" or "days ago".
|
| UDAT_REL_NUMERIC_FIELD | Represents a number quantity, like "3" in "3 days ago".
|
Definition at line186 of fileureldatefmt.h.
Represents the unit for formatting a relative date.
e.g "in 5 days" or "next year"
| Enumerator | |
|---|---|
| UDAT_REL_UNIT_YEAR | Specifies that relative unit is year, e.g. "last year", "in 5 years".
|
| UDAT_REL_UNIT_QUARTER | Specifies that relative unit is quarter, e.g. "last quarter", "in 5 quarters".
|
| UDAT_REL_UNIT_MONTH | Specifies that relative unit is month, e.g. "last month", "in 5 months".
|
| UDAT_REL_UNIT_WEEK | Specifies that relative unit is week, e.g. "last week", "in 5 weeks".
|
| UDAT_REL_UNIT_DAY | Specifies that relative unit is day, e.g. "yesterday", "in 5 days".
|
| UDAT_REL_UNIT_HOUR | Specifies that relative unit is hour, e.g. "1 hour ago", "in 5 hours".
|
| UDAT_REL_UNIT_MINUTE | Specifies that relative unit is minute, e.g. "1 minute ago", "in 5 minutes".
|
| UDAT_REL_UNIT_SECOND | Specifies that relative unit is second, e.g. "1 second ago", "in 5 seconds".
|
| UDAT_REL_UNIT_SUNDAY | Specifies that relative unit is Sunday, e.g. "last Sunday", "this Sunday", "next Sunday", "in 5 Sundays".
|
| UDAT_REL_UNIT_MONDAY | Specifies that relative unit is Monday, e.g. "last Monday", "this Monday", "next Monday", "in 5 Mondays".
|
| UDAT_REL_UNIT_TUESDAY | Specifies that relative unit is Tuesday, e.g. "last Tuesday", "this Tuesday", "next Tuesday", "in 5 Tuesdays".
|
| UDAT_REL_UNIT_WEDNESDAY | Specifies that relative unit is Wednesday, e.g. "last Wednesday", "this Wednesday", "next Wednesday", "in 5 Wednesdays".
|
| UDAT_REL_UNIT_THURSDAY | Specifies that relative unit is Thursday, e.g. "last Thursday", "this Thursday", "next Thursday", "in 5 Thursdays".
|
| UDAT_REL_UNIT_FRIDAY | Specifies that relative unit is Friday, e.g. "last Friday", "this Friday", "next Friday", "in 5 Fridays".
|
| UDAT_REL_UNIT_SATURDAY | Specifies that relative unit is Saturday, e.g. "last Saturday", "this Saturday", "next Saturday", "in 5 Saturdays".
|
| UDAT_REL_UNIT_COUNT | One more than the highest normal URelativeDateTimeUnit value.
|
Definition at line81 of fileureldatefmt.h.
| U_CAPI void ureldatefmt_close | ( | URelativeDateTimeFormatter * | reldatefmt | ) |
Close a URelativeDateTimeFormatter object.
Once closed it may no longer be used.
| reldatefmt | The URelativeDateTimeFormatter object to close. |
| U_CAPI void ureldatefmt_closeResult | ( | UFormattedRelativeDateTime * | ufrdt | ) |
Releases the UFormattedRelativeDateTime created by ureldatefmt_openResult.
| ufrdt | The object to release. |
| U_CAPI int32_t ureldatefmt_combineDateAndTime | ( | constURelativeDateTimeFormatter * | reldatefmt, |
| constUChar * | relativeDateString, | ||
| int32_t | relativeDateStringLen, | ||
| constUChar * | timeString, | ||
| int32_t | timeStringLen, | ||
| UChar * | result, | ||
| int32_t | resultCapacity, | ||
| UErrorCode * | status | ||
| ) |
Combines a relative date string and a time string in this object's locale.
This is done with the same date-time separator used for the default calendar in this locale to produce a result such as "yesterday at 3:45 PM".
| reldatefmt | The URelativeDateTimeFormatter object specifying the format conventions. |
| relativeDateString | The relative date string. |
| relativeDateStringLen | The length of relativeDateString; may be -1 if relativeDateString is zero-terminated. |
| timeString | The time string. |
| timeStringLen | The length of timeString; may be -1 if timeString is zero-terminated. |
| result | A pointer to a buffer to receive the formatted result. |
| resultCapacity | The maximum size of result. |
| status | A pointer to a UErrorCode to receive any errors. In case of error status, the contents of result are undefined. |
| U_CAPI int32_t ureldatefmt_format | ( | constURelativeDateTimeFormatter * | reldatefmt, |
| double | offset, | ||
| URelativeDateTimeUnit | unit, | ||
| UChar * | result, | ||
| int32_t | resultCapacity, | ||
| UErrorCode * | status | ||
| ) |
Format a combination of URelativeDateTimeUnit and numeric offset using a text style if possible, e.g.
"last week", "this week", "next week", "yesterday", "tomorrow". Falls back to numeric style if no appropriate text term is available for the specified offset in the object's locale.
| reldatefmt | The URelativeDateTimeFormatter object specifying the format conventions. |
| offset | The signed offset for the specified unit. |
| unit | The unit to use when formatting the relative date, e.g. UDAT_REL_UNIT_WEEK, UDAT_REL_UNIT_FRIDAY. |
| result | A pointer to a buffer to receive the formatted result. |
| resultCapacity | The maximum size of result. |
| status | A pointer to a UErrorCode to receive any errors. In case of error status, the contents of result are undefined. |
| U_CAPI int32_t ureldatefmt_formatNumeric | ( | constURelativeDateTimeFormatter * | reldatefmt, |
| double | offset, | ||
| URelativeDateTimeUnit | unit, | ||
| UChar * | result, | ||
| int32_t | resultCapacity, | ||
| UErrorCode * | status | ||
| ) |
Format a combination of URelativeDateTimeUnit and numeric offset using a numeric style, e.g.
"1 week ago", "in 1 week", "5 weeks ago", "in 5 weeks".
| reldatefmt | The URelativeDateTimeFormatter object specifying the format conventions. |
| offset | The signed offset for the specified unit. This will be formatted according to this object's UNumberFormat object. |
| unit | The unit to use when formatting the relative date, e.g. UDAT_REL_UNIT_WEEK, UDAT_REL_UNIT_FRIDAY. |
| result | A pointer to a buffer to receive the formatted result. |
| resultCapacity | The maximum size of result. |
| status | A pointer to a UErrorCode to receive any errors. In case of error status, the contents of result are undefined. |
| U_CAPI void ureldatefmt_formatNumericToResult | ( | constURelativeDateTimeFormatter * | reldatefmt, |
| double | offset, | ||
| URelativeDateTimeUnit | unit, | ||
| UFormattedRelativeDateTime * | result, | ||
| UErrorCode * | status | ||
| ) |
Format a combination of URelativeDateTimeUnit and numeric offset using a numeric style, e.g.
"1 week ago", "in 1 week", "5 weeks ago", "in 5 weeks".
| reldatefmt | The URelativeDateTimeFormatter object specifying the format conventions. |
| offset | The signed offset for the specified unit. This will be formatted according to this object's UNumberFormat object. |
| unit | The unit to use when formatting the relative date, e.g. UDAT_REL_UNIT_WEEK, UDAT_REL_UNIT_FRIDAY. |
| result | A pointer to a UFormattedRelativeDateTime to populate. |
| status | A pointer to a UErrorCode to receive any errors. In case of error status, the contents of result are undefined. |
| U_CAPI void ureldatefmt_formatToResult | ( | constURelativeDateTimeFormatter * | reldatefmt, |
| double | offset, | ||
| URelativeDateTimeUnit | unit, | ||
| UFormattedRelativeDateTime * | result, | ||
| UErrorCode * | status | ||
| ) |
Format a combination of URelativeDateTimeUnit and numeric offset using a text style if possible, e.g.
"last week", "this week", "next week", "yesterday", "tomorrow". Falls back to numeric style if no appropriate text term is available for the specified offset in the object's locale.
This method populates a UFormattedRelativeDateTime, which exposes more information than the string populated by format().
| reldatefmt | The URelativeDateTimeFormatter object specifying the format conventions. |
| offset | The signed offset for the specified unit. |
| unit | The unit to use when formatting the relative date, e.g. UDAT_REL_UNIT_WEEK, UDAT_REL_UNIT_FRIDAY. |
| result | A pointer to a UFormattedRelativeDateTime to populate. |
| status | A pointer to a UErrorCode to receive any errors. In case of error status, the contents of result are undefined. |
| U_CAPIURelativeDateTimeFormatter* ureldatefmt_open | ( | const char * | locale, |
| UNumberFormat * | nfToAdopt, | ||
| UDateRelativeDateTimeFormatterStyle | width, | ||
| UDisplayContext | capitalizationContext, | ||
| UErrorCode * | status | ||
| ) |
Open a new URelativeDateTimeFormatter object for a given locale using the specified width and capitalizationContext, along with a number formatter (if desired) to override the default formatter that would be used for display of numeric field offsets.
The default formatter typically rounds toward 0 and has a minimum of 0 fraction digits and a maximum of 3 fraction digits (i.e. it will show as many decimal places as necessary up to 3, without showing trailing 0s).
| locale | The locale |
| nfToAdopt | A number formatter to set for this URelativeDateTimeFormatter object (instead of the default decimal formatter). Ownership of this UNumberFormat object will pass to the URelativeDateTimeFormatter object (the URelativeDateTimeFormatter adopts the UNumberFormat), which becomes responsible for closing it. If the caller wishes to retain ownership of the UNumberFormat object, the caller must clone it (with unum_clone) and pass the clone to ureldatefmt_open. May be NULL to use the default decimal formatter. |
| width | The width - wide, short, narrow, etc. |
| capitalizationContext | A value from UDisplayContext that pertains to capitalization, e.g. UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE. |
| status | A pointer to a UErrorCode to receive any errors. |
| U_CAPIUFormattedRelativeDateTime* ureldatefmt_openResult | ( | UErrorCode * | ec | ) |
Creates an object to hold the result of a URelativeDateTimeFormatter operation.
The object can be used repeatedly; it is cleared whenever passed to a format function.
| ec | Set if an error occurs. |
| U_CAPI constUFormattedValue* ureldatefmt_resultAsValue | ( | constUFormattedRelativeDateTime * | ufrdt, |
| UErrorCode * | ec | ||
| ) |
Returns a representation of a UFormattedRelativeDateTime as a UFormattedValue, which can be subsequently passed to any API requiring that type.
The returned object is owned by the UFormattedRelativeDateTime and is valid only as long as the UFormattedRelativeDateTime is present and unchanged in memory.
You can think of this method as a cast between types.
| ufrdt | The object containing the formatted string. |
| ec | Set if an error occurs. |