ICU 65.1 65.1

ureldatefmt.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *****************************************************************************************
5 * Copyright (C) 2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *****************************************************************************************
8 */
9
10 #ifndef URELDATEFMT_H
11 #define URELDATEFMT_H
12
13 #include "unicode/utypes.h"
14
15 #if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_BREAK_ITERATION
16
17 #include "unicode/unum.h"
18 #include "unicode/udisplaycontext.h"
19 #include "unicode/localpointer.h"
20 #include "unicode/uformattedvalue.h"
21
45 typedef enum UDateRelativeDateTimeFormatterStyle {
50 UDAT_STYLE_LONG,
51
56 UDAT_STYLE_SHORT,
57
62 UDAT_STYLE_NARROW,
63
64 #ifndef U_HIDE_DEPRECATED_API
65
69 UDAT_STYLE_COUNT
70 #endif /* U_HIDE_DEPRECATED_API */
71 } UDateRelativeDateTimeFormatterStyle;
72
78 typedef enum URelativeDateTimeUnit {
84 UDAT_REL_UNIT_YEAR,
90 UDAT_REL_UNIT_QUARTER,
96 UDAT_REL_UNIT_MONTH,
102 UDAT_REL_UNIT_WEEK,
108 UDAT_REL_UNIT_DAY,
114 UDAT_REL_UNIT_HOUR,
120 UDAT_REL_UNIT_MINUTE,
126 UDAT_REL_UNIT_SECOND,
132 UDAT_REL_UNIT_SUNDAY,
138 UDAT_REL_UNIT_MONDAY,
144 UDAT_REL_UNIT_TUESDAY,
150 UDAT_REL_UNIT_WEDNESDAY,
156 UDAT_REL_UNIT_THURSDAY,
162 UDAT_REL_UNIT_FRIDAY,
168 UDAT_REL_UNIT_SATURDAY,
169 #ifndef U_HIDE_DEPRECATED_API
170
174 UDAT_REL_UNIT_COUNT
175 #endif /* U_HIDE_DEPRECATED_API */
176 } URelativeDateTimeUnit;
177
178 #ifndef U_HIDE_DRAFT_API
179
184 typedef enum URelativeDateTimeFormatterField {
189 UDAT_REL_LITERAL_FIELD,
194 UDAT_REL_NUMERIC_FIELD,
195 } URelativeDateTimeFormatterField;
196 #endif // U_HIDE_DRAFT_API
197
198
203 struct URelativeDateTimeFormatter;
204 typedef struct URelativeDateTimeFormatter URelativeDateTimeFormatter;
239 U_STABLE URelativeDateTimeFormatter* U_EXPORT2
240 ureldatefmt_open( const char* locale,
241 UNumberFormat* nfToAdopt,
242 UDateRelativeDateTimeFormatterStyle width,
243 UDisplayContext capitalizationContext,
244 UErrorCode* status );
245
252 U_STABLE void U_EXPORT2
253 ureldatefmt_close(URelativeDateTimeFormatter *reldatefmt);
254
255 #ifndef U_HIDE_DRAFT_API
256 struct UFormattedRelativeDateTime;
261 typedef struct UFormattedRelativeDateTime UFormattedRelativeDateTime;
262
272 U_DRAFT UFormattedRelativeDateTime* U_EXPORT2
273 ureldatefmt_openResult(UErrorCode* ec);
274
289 U_DRAFT const UFormattedValue* U_EXPORT2
290 ureldatefmt_resultAsValue(const UFormattedRelativeDateTime* ufrdt, UErrorCode* ec);
291
298 U_DRAFT void U_EXPORT2
299 ureldatefmt_closeResult(UFormattedRelativeDateTime* ufrdt);
300 #endif /* U_HIDE_DRAFT_API */
301
302
303 #if U_SHOW_CPLUSPLUS_API
304
305 U_NAMESPACE_BEGIN
306
316 U_DEFINE_LOCAL_OPEN_POINTER(LocalURelativeDateTimeFormatterPointer, URelativeDateTimeFormatter, ureldatefmt_close);
317
318 #ifndef U_HIDE_DRAFT_API
319
328 U_DEFINE_LOCAL_OPEN_POINTER(LocalUFormattedRelativeDateTimePointer, UFormattedRelativeDateTime, ureldatefmt_closeResult);
329 #endif /* U_HIDE_DRAFT_API */
330
331 U_NAMESPACE_END
332
333 #endif
334
363 U_STABLE int32_t U_EXPORT2
364 ureldatefmt_formatNumeric( const URelativeDateTimeFormatter* reldatefmt,
365 double offset,
366 URelativeDateTimeUnit unit,
367 UChar* result,
368 int32_t resultCapacity,
369 UErrorCode* status);
370
371 #ifndef U_HIDE_DRAFT_API
372
395 U_DRAFT void U_EXPORT2
396 ureldatefmt_formatNumericToResult(
397 const URelativeDateTimeFormatter* reldatefmt,
398 double offset,
399 URelativeDateTimeUnit unit,
400 UFormattedRelativeDateTime* result,
401 UErrorCode* status);
402 #endif /* U_HIDE_DRAFT_API */
403
432 U_STABLE int32_t U_EXPORT2
433 ureldatefmt_format( const URelativeDateTimeFormatter* reldatefmt,
434 double offset,
435 URelativeDateTimeUnit unit,
436 UChar* result,
437 int32_t resultCapacity,
438 UErrorCode* status);
439
440 #ifndef U_HIDE_DRAFT_API
441
467 U_DRAFT void U_EXPORT2
468 ureldatefmt_formatToResult(
469 const URelativeDateTimeFormatter* reldatefmt,
470 double offset,
471 URelativeDateTimeUnit unit,
472 UFormattedRelativeDateTime* result,
473 UErrorCode* status);
474 #endif /* U_HIDE_DRAFT_API */
475
505 U_STABLE int32_t U_EXPORT2
506 ureldatefmt_combineDateAndTime( const URelativeDateTimeFormatter* reldatefmt,
507 const UChar * relativeDateString,
508 int32_t relativeDateStringLen,
509 const UChar * timeString,
510 int32_t timeStringLen,
511 UChar* result,
512 int32_t resultCapacity,
513 UErrorCode* status );
514
515 #endif /* !UCONFIG_NO_FORMATTING && !UCONFIG_NO_BREAK_ITERATION */
516
517 #endif
UDAT_REL_NUMERIC_FIELD
Represents a number quantity, like "3" in "3 days ago".
Definition: ureldatefmt.h:194
UDAT_REL_LITERAL_FIELD
Represents a literal text string, like "tomorrow" or "days ago".
Definition: ureldatefmt.h:189
URelativeDateTimeUnit
URelativeDateTimeUnit
Represents the unit for formatting a relative date.
Definition: ureldatefmt.h:78
ureldatefmt_formatNumeric
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.
uformattedvalue.h
C API: Abstract operations for localized strings.
ureldatefmt_close
void ureldatefmt_close(URelativeDateTimeFormatter *reldatefmt)
Close a URelativeDateTimeFormatter object.
UDAT_REL_UNIT_SECOND
Specifies that relative unit is second, e.g.
Definition: ureldatefmt.h:126
URelativeDateTimeFormatter
struct URelativeDateTimeFormatter URelativeDateTimeFormatter
C typedef for struct URelativeDateTimeFormatter.
Definition: ureldatefmt.h:204
UDAT_REL_UNIT_WEEK
Specifies that relative unit is week, e.g.
Definition: ureldatefmt.h:102
UDAT_REL_UNIT_MONTH
Specifies that relative unit is month, e.g.
Definition: ureldatefmt.h:96
UFormattedRelativeDateTime
struct UFormattedRelativeDateTime UFormattedRelativeDateTime
Opaque struct to contain the results of a URelativeDateTimeFormatter operation.
Definition: ureldatefmt.h:261
UDisplayContext
UDisplayContext
Display context settings.
Definition: udisplaycontext.h:64
URelativeDateTimeFormatterField
URelativeDateTimeFormatterField
FieldPosition and UFieldPosition selectors for format fields defined by RelativeDateTimeFormatter.
Definition: ureldatefmt.h:184
ureldatefmt_formatNumericToResult
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.
UDAT_REL_UNIT_FRIDAY
Specifies that relative unit is Friday, e.g.
Definition: ureldatefmt.h:162
UDAT_REL_UNIT_MONDAY
Specifies that relative unit is Monday, e.g.
Definition: ureldatefmt.h:138
UDAT_STYLE_LONG
Everything spelled out.
Definition: ureldatefmt.h:50
UDAT_REL_UNIT_SATURDAY
Specifies that relative unit is Saturday, e.g.
Definition: ureldatefmt.h:168
udisplaycontext.h
C API: Display context types (enum values)
UDAT_REL_UNIT_MINUTE
Specifies that relative unit is minute, e.g.
Definition: ureldatefmt.h:120
UDAT_REL_UNIT_WEDNESDAY
Specifies that relative unit is Wednesday, e.g.
Definition: ureldatefmt.h:150
UDAT_STYLE_SHORT
Abbreviations used when possible.
Definition: ureldatefmt.h:56
UDAT_REL_UNIT_SUNDAY
Specifies that relative unit is Sunday, e.g.
Definition: ureldatefmt.h:132
ureldatefmt_format
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...
U_DEFINE_LOCAL_OPEN_POINTER
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
Definition: localpointer.h:562
UNumberFormat
void * UNumberFormat
A number formatter.
Definition: unum.h:141
localpointer.h
C++ API: "Smart pointers" for use with and in ICU4C C++ code.
ureldatefmt_open
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 capital...
UDAT_STYLE_COUNT
One more than the highest normal UDateRelativeDateTimeFormatterStyle value.
Definition: ureldatefmt.h:69
ureldatefmt_formatToResult
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...
UDAT_REL_UNIT_QUARTER
Specifies that relative unit is quarter, e.g.
Definition: ureldatefmt.h:90
UDateRelativeDateTimeFormatterStyle
UDateRelativeDateTimeFormatterStyle
The formatting style.
Definition: ureldatefmt.h:45
LocalURelativeDateTimeFormatterPointer
"Smart pointer" class, closes a URelativeDateTimeFormatter via ureldatefmt_close().
UDAT_REL_UNIT_HOUR
Specifies that relative unit is hour, e.g.
Definition: ureldatefmt.h:114
UDAT_STYLE_NARROW
Use the shortest possible form.
Definition: ureldatefmt.h:62
ureldatefmt_closeResult
void ureldatefmt_closeResult(UFormattedRelativeDateTime *ufrdt)
Releases the UFormattedRelativeDateTime created by ureldatefmt_openResult.
UDAT_REL_UNIT_YEAR
Specifies that relative unit is year, e.g.
Definition: ureldatefmt.h:84
ureldatefmt_resultAsValue
const UFormattedValue * ureldatefmt_resultAsValue(const UFormattedRelativeDateTime *ufrdt, UErrorCode *ec)
Returns a representation of a UFormattedRelativeDateTime as a UFormattedValue, which can be subsequen...
UChar
uint16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:378
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
UDAT_REL_UNIT_TUESDAY
Specifies that relative unit is Tuesday, e.g.
Definition: ureldatefmt.h:144
UDAT_REL_UNIT_DAY
Specifies that relative unit is day, e.g.
Definition: ureldatefmt.h:108
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UDAT_REL_UNIT_THURSDAY
Specifies that relative unit is Thursday, e.g.
Definition: ureldatefmt.h:156
ureldatefmt_openResult
UFormattedRelativeDateTime * ureldatefmt_openResult(UErrorCode *ec)
Creates an object to hold the result of a URelativeDateTimeFormatter operation.
LocalUFormattedRelativeDateTimePointer
"Smart pointer" class, closes a UFormattedRelativeDateTime via ureldatefmt_closeResult().
Definition: ureldatefmt.h:316
UFormattedValue
struct UFormattedValue UFormattedValue
An abstract formatted value: a string with associated field attributes.
Definition: uformattedvalue.h:363
UDAT_REL_UNIT_COUNT
One more than the highest normal URelativeDateTimeUnit value.
Definition: ureldatefmt.h:174
U_DRAFT
#define U_DRAFT
This is used to declare a function as a draft public ICU C API.
Definition: umachine.h:113
U_STABLE
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition: umachine.h:111
unum.h
C API: Compatibility APIs for number formatting.
ureldatefmt_combineDateAndTime
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&#39;s locale.