Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 1 | // © 2016 and later: Unicode, Inc. and others. |
Fredrik Roubert | 64339d3 | 2016-10-21 19:43:16 +0200 | [diff] [blame] | 2 | // License & terms of use: http://www.unicode.org/copyright.html |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 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" |
Victor Chang | 8249390 | 2020-12-23 17:27:56 +0000 | [diff] [blame] | 19 | #include "unicode/uformattedvalue.h" |
Victor Chang | eaf32ab | 2020-08-20 15:50:49 +0100 | [diff] [blame] | 20 | |
Victor Chang | d50596e | 2020-08-20 15:50:49 +0100 | [diff] [blame] | 21 | #if U_SHOW_CPLUSPLUS_API |
| 22 | #include "unicode/localpointer.h" |
| 23 | #endif // U_SHOW_CPLUSPLUS_API |
| 24 | |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 25 | /** |
| 26 | * \file |
| 27 | * \brief C API: URelativeDateTimeFormatter, relative date formatting of unit + numeric offset. |
| 28 | * |
| 29 | * Provides simple formatting of relative dates, in two ways |
| 30 | * <ul> |
| 31 | * <li>relative dates with a quantity e.g "in 5 days"</li> |
| 32 | * <li>relative dates without a quantity e.g "next Tuesday"</li> |
| 33 | * </ul> |
| 34 | * <p> |
| 35 | * This does not provide compound formatting for multiple units, |
| 36 | * other than the ability to combine a time string with a relative date, |
| 37 | * as in "next Tuesday at 3:45 PM". It also does not provide support |
| 38 | * for determining which unit to use, such as deciding between "in 7 days" |
| 39 | * and "in 1 week". |
| 40 | * |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 41 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 42 | */ |
| 43 | |
| 44 | /** |
| 45 | * The formatting style |
| 46 | * @stable ICU 54 |
| 47 | */ |
| 48 | typedef enum UDateRelativeDateTimeFormatterStyle { |
| 49 | /** |
| 50 | * Everything spelled out. |
| 51 | * @stable ICU 54 |
| 52 | */ |
| 53 | UDAT_STYLE_LONG, |
| 54 | |
| 55 | /** |
| 56 | * Abbreviations used when possible. |
| 57 | * @stable ICU 54 |
| 58 | */ |
| 59 | UDAT_STYLE_SHORT, |
| 60 | |
| 61 | /** |
| 62 | * Use the shortest possible form. |
| 63 | * @stable ICU 54 |
| 64 | */ |
| 65 | UDAT_STYLE_NARROW, |
| 66 | |
Fredrik Roubert | 64339d3 | 2016-10-21 19:43:16 +0200 | [diff] [blame] | 67 | #ifndef U_HIDE_DEPRECATED_API |
| 68 | /** |
| 69 | * One more than the highest normal UDateRelativeDateTimeFormatterStyle value. |
| 70 | * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. |
| 71 | */ |
| 72 | UDAT_STYLE_COUNT |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 73 | #endif /* U_HIDE_DEPRECATED_API */ |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 74 | } UDateRelativeDateTimeFormatterStyle; |
| 75 | |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 76 | /** |
| 77 | * Represents the unit for formatting a relative date. e.g "in 5 days" |
| 78 | * or "next year" |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 79 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 80 | */ |
| 81 | typedef enum URelativeDateTimeUnit { |
| 82 | /** |
| 83 | * Specifies that relative unit is year, e.g. "last year", |
| 84 | * "in 5 years". |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 85 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 86 | */ |
| 87 | UDAT_REL_UNIT_YEAR, |
| 88 | /** |
| 89 | * Specifies that relative unit is quarter, e.g. "last quarter", |
| 90 | * "in 5 quarters". |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 91 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 92 | */ |
| 93 | UDAT_REL_UNIT_QUARTER, |
| 94 | /** |
| 95 | * Specifies that relative unit is month, e.g. "last month", |
| 96 | * "in 5 months". |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 97 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 98 | */ |
| 99 | UDAT_REL_UNIT_MONTH, |
| 100 | /** |
| 101 | * Specifies that relative unit is week, e.g. "last week", |
| 102 | * "in 5 weeks". |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 103 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 104 | */ |
| 105 | UDAT_REL_UNIT_WEEK, |
| 106 | /** |
| 107 | * Specifies that relative unit is day, e.g. "yesterday", |
| 108 | * "in 5 days". |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 109 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 110 | */ |
| 111 | UDAT_REL_UNIT_DAY, |
| 112 | /** |
| 113 | * Specifies that relative unit is hour, e.g. "1 hour ago", |
| 114 | * "in 5 hours". |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 115 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 116 | */ |
| 117 | UDAT_REL_UNIT_HOUR, |
| 118 | /** |
| 119 | * Specifies that relative unit is minute, e.g. "1 minute ago", |
| 120 | * "in 5 minutes". |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 121 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 122 | */ |
| 123 | UDAT_REL_UNIT_MINUTE, |
| 124 | /** |
| 125 | * Specifies that relative unit is second, e.g. "1 second ago", |
| 126 | * "in 5 seconds". |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 127 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 128 | */ |
| 129 | UDAT_REL_UNIT_SECOND, |
| 130 | /** |
| 131 | * Specifies that relative unit is Sunday, e.g. "last Sunday", |
| 132 | * "this Sunday", "next Sunday", "in 5 Sundays". |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 133 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 134 | */ |
| 135 | UDAT_REL_UNIT_SUNDAY, |
| 136 | /** |
| 137 | * Specifies that relative unit is Monday, e.g. "last Monday", |
| 138 | * "this Monday", "next Monday", "in 5 Mondays". |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 139 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 140 | */ |
| 141 | UDAT_REL_UNIT_MONDAY, |
| 142 | /** |
| 143 | * Specifies that relative unit is Tuesday, e.g. "last Tuesday", |
| 144 | * "this Tuesday", "next Tuesday", "in 5 Tuesdays". |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 145 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 146 | */ |
| 147 | UDAT_REL_UNIT_TUESDAY, |
| 148 | /** |
| 149 | * Specifies that relative unit is Wednesday, e.g. "last Wednesday", |
| 150 | * "this Wednesday", "next Wednesday", "in 5 Wednesdays". |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 151 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 152 | */ |
| 153 | UDAT_REL_UNIT_WEDNESDAY, |
| 154 | /** |
| 155 | * Specifies that relative unit is Thursday, e.g. "last Thursday", |
| 156 | * "this Thursday", "next Thursday", "in 5 Thursdays". |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 157 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 158 | */ |
| 159 | UDAT_REL_UNIT_THURSDAY, |
| 160 | /** |
| 161 | * Specifies that relative unit is Friday, e.g. "last Friday", |
| 162 | * "this Friday", "next Friday", "in 5 Fridays". |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 163 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 164 | */ |
| 165 | UDAT_REL_UNIT_FRIDAY, |
| 166 | /** |
| 167 | * Specifies that relative unit is Saturday, e.g. "last Saturday", |
| 168 | * "this Saturday", "next Saturday", "in 5 Saturdays". |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 169 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 170 | */ |
| 171 | UDAT_REL_UNIT_SATURDAY, |
Fredrik Roubert | 64339d3 | 2016-10-21 19:43:16 +0200 | [diff] [blame] | 172 | #ifndef U_HIDE_DEPRECATED_API |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 173 | /** |
Fredrik Roubert | 64339d3 | 2016-10-21 19:43:16 +0200 | [diff] [blame] | 174 | * One more than the highest normal URelativeDateTimeUnit value. |
| 175 | * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 176 | */ |
| 177 | UDAT_REL_UNIT_COUNT |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 178 | #endif /* U_HIDE_DEPRECATED_API */ |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 179 | } URelativeDateTimeUnit; |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 180 | |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 181 | /** |
| 182 | * FieldPosition and UFieldPosition selectors for format fields |
| 183 | * defined by RelativeDateTimeFormatter. |
Victor Chang | 8249390 | 2020-12-23 17:27:56 +0000 | [diff] [blame] | 184 | * @stable ICU 64 |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 185 | */ |
| 186 | typedef enum URelativeDateTimeFormatterField { |
| 187 | /** |
| 188 | * Represents a literal text string, like "tomorrow" or "days ago". |
Victor Chang | 8249390 | 2020-12-23 17:27:56 +0000 | [diff] [blame] | 189 | * @stable ICU 64 |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 190 | */ |
| 191 | UDAT_REL_LITERAL_FIELD, |
| 192 | /** |
| 193 | * Represents a number quantity, like "3" in "3 days ago". |
Victor Chang | 8249390 | 2020-12-23 17:27:56 +0000 | [diff] [blame] | 194 | * @stable ICU 64 |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 195 | */ |
| 196 | UDAT_REL_NUMERIC_FIELD, |
| 197 | } URelativeDateTimeFormatterField; |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 198 | |
| 199 | |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 200 | /** |
| 201 | * Opaque URelativeDateTimeFormatter object for use in C programs. |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 202 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 203 | */ |
| 204 | struct URelativeDateTimeFormatter; |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 205 | typedef struct URelativeDateTimeFormatter URelativeDateTimeFormatter; /**< C typedef for struct URelativeDateTimeFormatter. @stable ICU 57 */ |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 206 | |
| 207 | |
| 208 | /** |
| 209 | * Open a new URelativeDateTimeFormatter object for a given locale using the |
| 210 | * specified width and capitalizationContext, along with a number formatter |
| 211 | * (if desired) to override the default formatter that would be used for |
| 212 | * display of numeric field offsets. The default formatter typically rounds |
| 213 | * toward 0 and has a minimum of 0 fraction digits and a maximum of 3 |
| 214 | * fraction digits (i.e. it will show as many decimal places as necessary |
| 215 | * up to 3, without showing trailing 0s). |
| 216 | * |
| 217 | * @param locale |
| 218 | * The locale |
| 219 | * @param nfToAdopt |
| 220 | * A number formatter to set for this URelativeDateTimeFormatter |
| 221 | * object (instead of the default decimal formatter). Ownership of |
| 222 | * this UNumberFormat object will pass to the URelativeDateTimeFormatter |
| 223 | * object (the URelativeDateTimeFormatter adopts the UNumberFormat), |
| 224 | * which becomes responsible for closing it. If the caller wishes to |
| 225 | * retain ownership of the UNumberFormat object, the caller must clone |
| 226 | * it (with unum_clone) and pass the clone to ureldatefmt_open. May be |
| 227 | * NULL to use the default decimal formatter. |
| 228 | * @param width |
| 229 | * The width - wide, short, narrow, etc. |
| 230 | * @param capitalizationContext |
| 231 | * A value from UDisplayContext that pertains to capitalization, e.g. |
| 232 | * UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE. |
| 233 | * @param status |
| 234 | * A pointer to a UErrorCode to receive any errors. |
| 235 | * @return |
| 236 | * A pointer to a URelativeDateTimeFormatter object for the specified locale, |
| 237 | * or NULL if an error occurred. |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 238 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 239 | */ |
Victor Chang | 978167a | 2021-01-18 17:56:33 +0000 | [diff] [blame^] | 240 | U_CAPI URelativeDateTimeFormatter* U_EXPORT2 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 241 | ureldatefmt_open( const char* locale, |
| 242 | UNumberFormat* nfToAdopt, |
| 243 | UDateRelativeDateTimeFormatterStyle width, |
| 244 | UDisplayContext capitalizationContext, |
| 245 | UErrorCode* status ); |
| 246 | |
| 247 | /** |
| 248 | * Close a URelativeDateTimeFormatter object. Once closed it may no longer be used. |
| 249 | * @param reldatefmt |
| 250 | * The URelativeDateTimeFormatter object to close. |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 251 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 252 | */ |
Victor Chang | 978167a | 2021-01-18 17:56:33 +0000 | [diff] [blame^] | 253 | U_CAPI void U_EXPORT2 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 254 | ureldatefmt_close(URelativeDateTimeFormatter *reldatefmt); |
| 255 | |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 256 | struct UFormattedRelativeDateTime; |
| 257 | /** |
| 258 | * Opaque struct to contain the results of a URelativeDateTimeFormatter operation. |
Victor Chang | 8249390 | 2020-12-23 17:27:56 +0000 | [diff] [blame] | 259 | * @stable ICU 64 |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 260 | */ |
| 261 | typedef struct UFormattedRelativeDateTime UFormattedRelativeDateTime; |
| 262 | |
| 263 | /** |
| 264 | * Creates an object to hold the result of a URelativeDateTimeFormatter |
| 265 | * operation. The object can be used repeatedly; it is cleared whenever |
| 266 | * passed to a format function. |
| 267 | * |
| 268 | * @param ec Set if an error occurs. |
| 269 | * @return A pointer needing ownership. |
Victor Chang | 8249390 | 2020-12-23 17:27:56 +0000 | [diff] [blame] | 270 | * @stable ICU 64 |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 271 | */ |
Victor Chang | 978167a | 2021-01-18 17:56:33 +0000 | [diff] [blame^] | 272 | U_CAPI UFormattedRelativeDateTime* U_EXPORT2 |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 273 | ureldatefmt_openResult(UErrorCode* ec); |
| 274 | |
| 275 | /** |
| 276 | * Returns a representation of a UFormattedRelativeDateTime as a UFormattedValue, |
| 277 | * which can be subsequently passed to any API requiring that type. |
| 278 | * |
| 279 | * The returned object is owned by the UFormattedRelativeDateTime and is valid |
| 280 | * only as long as the UFormattedRelativeDateTime is present and unchanged in memory. |
| 281 | * |
| 282 | * You can think of this method as a cast between types. |
| 283 | * |
| 284 | * @param ufrdt The object containing the formatted string. |
| 285 | * @param ec Set if an error occurs. |
| 286 | * @return A UFormattedValue owned by the input object. |
Victor Chang | 8249390 | 2020-12-23 17:27:56 +0000 | [diff] [blame] | 287 | * @stable ICU 64 |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 288 | */ |
Victor Chang | 978167a | 2021-01-18 17:56:33 +0000 | [diff] [blame^] | 289 | U_CAPI const UFormattedValue* U_EXPORT2 |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 290 | ureldatefmt_resultAsValue(const UFormattedRelativeDateTime* ufrdt, UErrorCode* ec); |
| 291 | |
| 292 | /** |
| 293 | * Releases the UFormattedRelativeDateTime created by ureldatefmt_openResult. |
| 294 | * |
| 295 | * @param ufrdt The object to release. |
Victor Chang | 8249390 | 2020-12-23 17:27:56 +0000 | [diff] [blame] | 296 | * @stable ICU 64 |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 297 | */ |
Victor Chang | 978167a | 2021-01-18 17:56:33 +0000 | [diff] [blame^] | 298 | U_CAPI void U_EXPORT2 |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 299 | ureldatefmt_closeResult(UFormattedRelativeDateTime* ufrdt); |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 300 | |
| 301 | |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 302 | #if U_SHOW_CPLUSPLUS_API |
| 303 | |
| 304 | U_NAMESPACE_BEGIN |
| 305 | |
| 306 | /** |
| 307 | * \class LocalURelativeDateTimeFormatterPointer |
| 308 | * "Smart pointer" class, closes a URelativeDateTimeFormatter via ureldatefmt_close(). |
| 309 | * For most methods see the LocalPointerBase base class. |
| 310 | * |
| 311 | * @see LocalPointerBase |
| 312 | * @see LocalPointer |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 313 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 314 | */ |
| 315 | U_DEFINE_LOCAL_OPEN_POINTER(LocalURelativeDateTimeFormatterPointer, URelativeDateTimeFormatter, ureldatefmt_close); |
| 316 | |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 317 | /** |
| 318 | * \class LocalUFormattedRelativeDateTimePointer |
| 319 | * "Smart pointer" class, closes a UFormattedRelativeDateTime via ureldatefmt_closeResult(). |
| 320 | * For most methods see the LocalPointerBase base class. |
| 321 | * |
| 322 | * @see LocalPointerBase |
| 323 | * @see LocalPointer |
Victor Chang | 8249390 | 2020-12-23 17:27:56 +0000 | [diff] [blame] | 324 | * @stable ICU 64 |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 325 | */ |
| 326 | U_DEFINE_LOCAL_OPEN_POINTER(LocalUFormattedRelativeDateTimePointer, UFormattedRelativeDateTime, ureldatefmt_closeResult); |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 327 | |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 328 | U_NAMESPACE_END |
| 329 | |
| 330 | #endif |
| 331 | |
| 332 | /** |
| 333 | * Format a combination of URelativeDateTimeUnit and numeric |
| 334 | * offset using a numeric style, e.g. "1 week ago", "in 1 week", |
| 335 | * "5 weeks ago", "in 5 weeks". |
| 336 | * |
| 337 | * @param reldatefmt |
| 338 | * The URelativeDateTimeFormatter object specifying the |
| 339 | * format conventions. |
| 340 | * @param offset |
| 341 | * The signed offset for the specified unit. This will |
| 342 | * be formatted according to this object's UNumberFormat |
| 343 | * object. |
| 344 | * @param unit |
| 345 | * The unit to use when formatting the relative |
| 346 | * date, e.g. UDAT_REL_UNIT_WEEK, UDAT_REL_UNIT_FRIDAY. |
| 347 | * @param result |
| 348 | * A pointer to a buffer to receive the formatted result. |
| 349 | * @param resultCapacity |
| 350 | * The maximum size of result. |
| 351 | * @param status |
| 352 | * A pointer to a UErrorCode to receive any errors. In |
| 353 | * case of error status, the contents of result are |
| 354 | * undefined. |
| 355 | * @return |
| 356 | * The length of the formatted result; may be greater |
| 357 | * than resultCapacity, in which case an error is returned. |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 358 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 359 | */ |
Victor Chang | 978167a | 2021-01-18 17:56:33 +0000 | [diff] [blame^] | 360 | U_CAPI int32_t U_EXPORT2 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 361 | ureldatefmt_formatNumeric( const URelativeDateTimeFormatter* reldatefmt, |
| 362 | double offset, |
| 363 | URelativeDateTimeUnit unit, |
| 364 | UChar* result, |
| 365 | int32_t resultCapacity, |
| 366 | UErrorCode* status); |
| 367 | |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 368 | /** |
| 369 | * Format a combination of URelativeDateTimeUnit and numeric |
| 370 | * offset using a numeric style, e.g. "1 week ago", "in 1 week", |
| 371 | * "5 weeks ago", "in 5 weeks". |
| 372 | * |
| 373 | * @param reldatefmt |
| 374 | * The URelativeDateTimeFormatter object specifying the |
| 375 | * format conventions. |
| 376 | * @param offset |
| 377 | * The signed offset for the specified unit. This will |
| 378 | * be formatted according to this object's UNumberFormat |
| 379 | * object. |
| 380 | * @param unit |
| 381 | * The unit to use when formatting the relative |
| 382 | * date, e.g. UDAT_REL_UNIT_WEEK, UDAT_REL_UNIT_FRIDAY. |
| 383 | * @param result |
| 384 | * A pointer to a UFormattedRelativeDateTime to populate. |
| 385 | * @param status |
| 386 | * A pointer to a UErrorCode to receive any errors. In |
| 387 | * case of error status, the contents of result are |
| 388 | * undefined. |
Victor Chang | 8249390 | 2020-12-23 17:27:56 +0000 | [diff] [blame] | 389 | * @stable ICU 64 |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 390 | */ |
Victor Chang | 978167a | 2021-01-18 17:56:33 +0000 | [diff] [blame^] | 391 | U_CAPI void U_EXPORT2 |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 392 | ureldatefmt_formatNumericToResult( |
| 393 | const URelativeDateTimeFormatter* reldatefmt, |
| 394 | double offset, |
| 395 | URelativeDateTimeUnit unit, |
| 396 | UFormattedRelativeDateTime* result, |
| 397 | UErrorCode* status); |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 398 | |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 399 | /** |
| 400 | * Format a combination of URelativeDateTimeUnit and numeric offset |
| 401 | * using a text style if possible, e.g. "last week", "this week", |
| 402 | * "next week", "yesterday", "tomorrow". Falls back to numeric |
| 403 | * style if no appropriate text term is available for the specified |
| 404 | * offset in the object's locale. |
| 405 | * |
| 406 | * @param reldatefmt |
| 407 | * The URelativeDateTimeFormatter object specifying the |
| 408 | * format conventions. |
| 409 | * @param offset |
| 410 | * The signed offset for the specified unit. |
| 411 | * @param unit |
| 412 | * The unit to use when formatting the relative |
| 413 | * date, e.g. UDAT_REL_UNIT_WEEK, UDAT_REL_UNIT_FRIDAY. |
| 414 | * @param result |
| 415 | * A pointer to a buffer to receive the formatted result. |
| 416 | * @param resultCapacity |
| 417 | * The maximum size of result. |
| 418 | * @param status |
| 419 | * A pointer to a UErrorCode to receive any errors. In |
| 420 | * case of error status, the contents of result are |
| 421 | * undefined. |
| 422 | * @return |
| 423 | * The length of the formatted result; may be greater |
| 424 | * than resultCapacity, in which case an error is returned. |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 425 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 426 | */ |
Victor Chang | 978167a | 2021-01-18 17:56:33 +0000 | [diff] [blame^] | 427 | U_CAPI int32_t U_EXPORT2 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 428 | ureldatefmt_format( const URelativeDateTimeFormatter* reldatefmt, |
| 429 | double offset, |
| 430 | URelativeDateTimeUnit unit, |
| 431 | UChar* result, |
| 432 | int32_t resultCapacity, |
| 433 | UErrorCode* status); |
| 434 | |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 435 | /** |
| 436 | * Format a combination of URelativeDateTimeUnit and numeric offset |
| 437 | * using a text style if possible, e.g. "last week", "this week", |
| 438 | * "next week", "yesterday", "tomorrow". Falls back to numeric |
| 439 | * style if no appropriate text term is available for the specified |
| 440 | * offset in the object's locale. |
| 441 | * |
| 442 | * This method populates a UFormattedRelativeDateTime, which exposes more |
| 443 | * information than the string populated by format(). |
| 444 | * |
| 445 | * @param reldatefmt |
| 446 | * The URelativeDateTimeFormatter object specifying the |
| 447 | * format conventions. |
| 448 | * @param offset |
| 449 | * The signed offset for the specified unit. |
| 450 | * @param unit |
| 451 | * The unit to use when formatting the relative |
| 452 | * date, e.g. UDAT_REL_UNIT_WEEK, UDAT_REL_UNIT_FRIDAY. |
| 453 | * @param result |
| 454 | * A pointer to a UFormattedRelativeDateTime to populate. |
| 455 | * @param status |
| 456 | * A pointer to a UErrorCode to receive any errors. In |
| 457 | * case of error status, the contents of result are |
| 458 | * undefined. |
Victor Chang | 8249390 | 2020-12-23 17:27:56 +0000 | [diff] [blame] | 459 | * @stable ICU 64 |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 460 | */ |
Victor Chang | 978167a | 2021-01-18 17:56:33 +0000 | [diff] [blame^] | 461 | U_CAPI void U_EXPORT2 |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 462 | ureldatefmt_formatToResult( |
| 463 | const URelativeDateTimeFormatter* reldatefmt, |
| 464 | double offset, |
| 465 | URelativeDateTimeUnit unit, |
| 466 | UFormattedRelativeDateTime* result, |
| 467 | UErrorCode* status); |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 468 | |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 469 | /** |
| 470 | * Combines a relative date string and a time string in this object's |
| 471 | * locale. This is done with the same date-time separator used for the |
| 472 | * default calendar in this locale to produce a result such as |
| 473 | * "yesterday at 3:45 PM". |
| 474 | * |
| 475 | * @param reldatefmt |
| 476 | * The URelativeDateTimeFormatter object specifying the format conventions. |
| 477 | * @param relativeDateString |
| 478 | * The relative date string. |
| 479 | * @param relativeDateStringLen |
| 480 | * The length of relativeDateString; may be -1 if relativeDateString |
| 481 | * is zero-terminated. |
| 482 | * @param timeString |
| 483 | * The time string. |
| 484 | * @param timeStringLen |
| 485 | * The length of timeString; may be -1 if timeString is zero-terminated. |
| 486 | * @param result |
| 487 | * A pointer to a buffer to receive the formatted result. |
| 488 | * @param resultCapacity |
| 489 | * The maximum size of result. |
| 490 | * @param status |
| 491 | * A pointer to a UErrorCode to receive any errors. In case of error status, |
| 492 | * the contents of result are undefined. |
| 493 | * @return |
| 494 | * The length of the formatted result; may be greater than resultCapacity, |
| 495 | * in which case an error is returned. |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 496 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 497 | */ |
Victor Chang | 978167a | 2021-01-18 17:56:33 +0000 | [diff] [blame^] | 498 | U_CAPI int32_t U_EXPORT2 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 499 | ureldatefmt_combineDateAndTime( const URelativeDateTimeFormatter* reldatefmt, |
| 500 | const UChar * relativeDateString, |
| 501 | int32_t relativeDateStringLen, |
| 502 | const UChar * timeString, |
| 503 | int32_t timeStringLen, |
| 504 | UChar* result, |
| 505 | int32_t resultCapacity, |
| 506 | UErrorCode* status ); |
| 507 | |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 508 | #endif /* !UCONFIG_NO_FORMATTING && !UCONFIG_NO_BREAK_ITERATION */ |
| 509 | |
| 510 | #endif |