ureldatefmt.h File Reference

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/localpointer.h"
#include "unicode/uformattedvalue.h"

Go to the source code of this file.

Typedefs

typedef struct
URelativeDateTimeFormatter 
URelativeDateTimeFormatter
 C typedef for struct URelativeDateTimeFormatter.
typedef struct
UFormattedRelativeDateTime 
UFormattedRelativeDateTime
 Opaque struct to contain the results of a URelativeDateTimeFormatter operation.

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 and UFieldPosition selectors for format fields defined by RelativeDateTimeFormatter.

More...

Functions

URelativeDateTimeFormatterureldatefmt_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.
void ureldatefmt_close (URelativeDateTimeFormatter *reldatefmt)
 Close a URelativeDateTimeFormatter object.
UFormattedRelativeDateTimeureldatefmt_openResult (UErrorCode *ec)
 Creates an object to hold the result of a URelativeDateTimeFormatter operation.
const UFormattedValueureldatefmt_resultAsValue (const UFormattedRelativeDateTime *ufrdt, UErrorCode *ec)
 Returns a representation of a UFormattedRelativeDateTime as a UFormattedValue, which can be subsequently passed to any API requiring that type.
void ureldatefmt_closeResult (UFormattedRelativeDateTime *ufrdt)
 Releases the UFormattedRelativeDateTime created by ureldatefmt_openResult.
int32_t ureldatefmt_formatNumeric (const URelativeDateTimeFormatter *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.
void ureldatefmt_formatNumericToResult (const URelativeDateTimeFormatter *reldatefmt, double offset, URelativeDateTimeUnit unit, UFormattedRelativeDateTime *result, UErrorCode *status)
 Format a combination of URelativeDateTimeUnit and numeric offset using a numeric style, e.g.
int32_t ureldatefmt_format (const URelativeDateTimeFormatter *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.
void ureldatefmt_formatToResult (const URelativeDateTimeFormatter *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.
int32_t ureldatefmt_combineDateAndTime (const URelativeDateTimeFormatter *reldatefmt, const UChar *relativeDateString, int32_t relativeDateStringLen, const UChar *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.

Detailed Description

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".

Stable:
ICU 57

Definition in file ureldatefmt.h.


Typedef Documentation

Opaque struct to contain the results of a URelativeDateTimeFormatter operation.

Stable:
ICU 64

Definition at line 258 of file ureldatefmt.h.

C typedef for struct URelativeDateTimeFormatter.

Stable:
ICU 57

Definition at line 202 of file ureldatefmt.h.


Enumeration Type Documentation

The formatting style.

Stable:
ICU 54
Enumerator:
UDAT_STYLE_LONG 

Everything spelled out.

Stable:
ICU 54
UDAT_STYLE_SHORT 

Abbreviations used when possible.

Stable:
ICU 54
UDAT_STYLE_NARROW 

Use the shortest possible form.

Stable:
ICU 54
UDAT_STYLE_COUNT 

One more than the highest normal UDateRelativeDateTimeFormatterStyle value.

Deprecated:
ICU 58 The numeric value may change over time, see ICU ticket #12420.

Definition at line 45 of file ureldatefmt.h.

FieldPosition and UFieldPosition selectors for format fields defined by RelativeDateTimeFormatter.

Stable:
ICU 64
Enumerator:
UDAT_REL_LITERAL_FIELD 

Represents a literal text string, like "tomorrow" or "days ago".

Stable:
ICU 64
UDAT_REL_NUMERIC_FIELD 

Represents a number quantity, like "3" in "3 days ago".

Stable:
ICU 64

Definition at line 183 of file ureldatefmt.h.

Represents the unit for formatting a relative date.

e.g "in 5 days" or "next year"

Stable:
ICU 57
Enumerator:
UDAT_REL_UNIT_YEAR 

Specifies that relative unit is year, e.g.

"last year", "in 5 years".

Stable:
ICU 57
UDAT_REL_UNIT_QUARTER 

Specifies that relative unit is quarter, e.g.

"last quarter", "in 5 quarters".

Stable:
ICU 57
UDAT_REL_UNIT_MONTH 

Specifies that relative unit is month, e.g.

"last month", "in 5 months".

Stable:
ICU 57
UDAT_REL_UNIT_WEEK 

Specifies that relative unit is week, e.g.

"last week", "in 5 weeks".

Stable:
ICU 57
UDAT_REL_UNIT_DAY 

Specifies that relative unit is day, e.g.

"yesterday", "in 5 days".

Stable:
ICU 57
UDAT_REL_UNIT_HOUR 

Specifies that relative unit is hour, e.g.

"1 hour ago", "in 5 hours".

Stable:
ICU 57
UDAT_REL_UNIT_MINUTE 

Specifies that relative unit is minute, e.g.

"1 minute ago", "in 5 minutes".

Stable:
ICU 57
UDAT_REL_UNIT_SECOND 

Specifies that relative unit is second, e.g.

"1 second ago", "in 5 seconds".

Stable:
ICU 57
UDAT_REL_UNIT_SUNDAY 

Specifies that relative unit is Sunday, e.g.

"last Sunday", "this Sunday", "next Sunday", "in 5 Sundays".

Stable:
ICU 57
UDAT_REL_UNIT_MONDAY 

Specifies that relative unit is Monday, e.g.

"last Monday", "this Monday", "next Monday", "in 5 Mondays".

Stable:
ICU 57
UDAT_REL_UNIT_TUESDAY 

Specifies that relative unit is Tuesday, e.g.

"last Tuesday", "this Tuesday", "next Tuesday", "in 5 Tuesdays".

Stable:
ICU 57
UDAT_REL_UNIT_WEDNESDAY 

Specifies that relative unit is Wednesday, e.g.

"last Wednesday", "this Wednesday", "next Wednesday", "in 5 Wednesdays".

Stable:
ICU 57
UDAT_REL_UNIT_THURSDAY 

Specifies that relative unit is Thursday, e.g.

"last Thursday", "this Thursday", "next Thursday", "in 5 Thursdays".

Stable:
ICU 57
UDAT_REL_UNIT_FRIDAY 

Specifies that relative unit is Friday, e.g.

"last Friday", "this Friday", "next Friday", "in 5 Fridays".

Stable:
ICU 57
UDAT_REL_UNIT_SATURDAY 

Specifies that relative unit is Saturday, e.g.

"last Saturday", "this Saturday", "next Saturday", "in 5 Saturdays".

Stable:
ICU 57
UDAT_REL_UNIT_COUNT 

One more than the highest normal URelativeDateTimeUnit value.

Deprecated:
ICU 58 The numeric value may change over time, see ICU ticket #12420.

Definition at line 78 of file ureldatefmt.h.


Function Documentation

void ureldatefmt_close ( URelativeDateTimeFormatter reldatefmt  ) 

Close a URelativeDateTimeFormatter object.

Once closed it may no longer be used.

Parameters:
reldatefmt The URelativeDateTimeFormatter object to close.
Stable:
ICU 57
void ureldatefmt_closeResult ( UFormattedRelativeDateTime ufrdt  ) 

Releases the UFormattedRelativeDateTime created by ureldatefmt_openResult.

Parameters:
ufrdt The object to release.
Stable:
ICU 64
int32_t ureldatefmt_combineDateAndTime ( const URelativeDateTimeFormatter reldatefmt,
const UChar relativeDateString,
int32_t  relativeDateStringLen,
const UChar 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".

Parameters:
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.
Returns:
The length of the formatted result; may be greater than resultCapacity, in which case an error is returned.
Stable:
ICU 57
int32_t ureldatefmt_format ( const URelativeDateTimeFormatter 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.

Parameters:
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.
Returns:
The length of the formatted result; may be greater than resultCapacity, in which case an error is returned.
Stable:
ICU 57
int32_t ureldatefmt_formatNumeric ( const URelativeDateTimeFormatter 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".

Parameters:
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.
Returns:
The length of the formatted result; may be greater than resultCapacity, in which case an error is returned.
Stable:
ICU 57
void ureldatefmt_formatNumericToResult ( const URelativeDateTimeFormatter 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".

Parameters:
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.
Stable:
ICU 64
void ureldatefmt_formatToResult ( const URelativeDateTimeFormatter 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().

Parameters:
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.
Stable:
ICU 64
URelativeDateTimeFormatter* 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).

Parameters:
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.
Returns:
A pointer to a URelativeDateTimeFormatter object for the specified locale, or NULL if an error occurred.
Stable:
ICU 57
UFormattedRelativeDateTime* 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.

Parameters:
ec Set if an error occurs.
Returns:
A pointer needing ownership.
Stable:
ICU 64
const UFormattedValue* ureldatefmt_resultAsValue ( const UFormattedRelativeDateTime 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.

Parameters:
ufrdt The object containing the formatted string.
ec Set if an error occurs.
Returns:
A UFormattedValue owned by the input object.
Stable:
ICU 64

Generated on 3 Aug 2020 for ICU 67.1 by  doxygen 1.6.1