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" |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 19 | #include "unicode/uformattedvalue.h" |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 20 | |
Victor Chang | eaf32ab | 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 | #ifndef U_HIDE_DRAFT_API |
| 182 | /** |
| 183 | * FieldPosition and UFieldPosition selectors for format fields |
| 184 | * defined by RelativeDateTimeFormatter. |
| 185 | * @draft ICU 64 |
| 186 | */ |
| 187 | typedef enum URelativeDateTimeFormatterField { |
| 188 | /** |
| 189 | * Represents a literal text string, like "tomorrow" or "days ago". |
| 190 | * @draft ICU 64 |
| 191 | */ |
| 192 | UDAT_REL_LITERAL_FIELD, |
| 193 | /** |
| 194 | * Represents a number quantity, like "3" in "3 days ago". |
| 195 | * @draft ICU 64 |
| 196 | */ |
| 197 | UDAT_REL_NUMERIC_FIELD, |
| 198 | } URelativeDateTimeFormatterField; |
| 199 | #endif // U_HIDE_DRAFT_API |
| 200 | |
| 201 | |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 202 | /** |
| 203 | * Opaque URelativeDateTimeFormatter object for use in C programs. |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 204 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 205 | */ |
| 206 | struct URelativeDateTimeFormatter; |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 207 | typedef struct URelativeDateTimeFormatter URelativeDateTimeFormatter; /**< C typedef for struct URelativeDateTimeFormatter. @stable ICU 57 */ |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 208 | |
| 209 | |
| 210 | /** |
| 211 | * Open a new URelativeDateTimeFormatter object for a given locale using the |
| 212 | * specified width and capitalizationContext, along with a number formatter |
| 213 | * (if desired) to override the default formatter that would be used for |
| 214 | * display of numeric field offsets. The default formatter typically rounds |
| 215 | * toward 0 and has a minimum of 0 fraction digits and a maximum of 3 |
| 216 | * fraction digits (i.e. it will show as many decimal places as necessary |
| 217 | * up to 3, without showing trailing 0s). |
| 218 | * |
| 219 | * @param locale |
| 220 | * The locale |
| 221 | * @param nfToAdopt |
| 222 | * A number formatter to set for this URelativeDateTimeFormatter |
| 223 | * object (instead of the default decimal formatter). Ownership of |
| 224 | * this UNumberFormat object will pass to the URelativeDateTimeFormatter |
| 225 | * object (the URelativeDateTimeFormatter adopts the UNumberFormat), |
| 226 | * which becomes responsible for closing it. If the caller wishes to |
| 227 | * retain ownership of the UNumberFormat object, the caller must clone |
| 228 | * it (with unum_clone) and pass the clone to ureldatefmt_open. May be |
| 229 | * NULL to use the default decimal formatter. |
| 230 | * @param width |
| 231 | * The width - wide, short, narrow, etc. |
| 232 | * @param capitalizationContext |
| 233 | * A value from UDisplayContext that pertains to capitalization, e.g. |
| 234 | * UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE. |
| 235 | * @param status |
| 236 | * A pointer to a UErrorCode to receive any errors. |
| 237 | * @return |
| 238 | * A pointer to a URelativeDateTimeFormatter object for the specified locale, |
| 239 | * or NULL if an error occurred. |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 240 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 241 | */ |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 242 | U_STABLE URelativeDateTimeFormatter* U_EXPORT2 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 243 | ureldatefmt_open( const char* locale, |
| 244 | UNumberFormat* nfToAdopt, |
| 245 | UDateRelativeDateTimeFormatterStyle width, |
| 246 | UDisplayContext capitalizationContext, |
| 247 | UErrorCode* status ); |
| 248 | |
| 249 | /** |
| 250 | * Close a URelativeDateTimeFormatter object. Once closed it may no longer be used. |
| 251 | * @param reldatefmt |
| 252 | * The URelativeDateTimeFormatter object to close. |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 253 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 254 | */ |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 255 | U_STABLE void U_EXPORT2 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 256 | ureldatefmt_close(URelativeDateTimeFormatter *reldatefmt); |
| 257 | |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 258 | #ifndef U_HIDE_DRAFT_API |
| 259 | struct UFormattedRelativeDateTime; |
| 260 | /** |
| 261 | * Opaque struct to contain the results of a URelativeDateTimeFormatter operation. |
| 262 | * @draft ICU 64 |
| 263 | */ |
| 264 | typedef struct UFormattedRelativeDateTime UFormattedRelativeDateTime; |
| 265 | |
| 266 | /** |
| 267 | * Creates an object to hold the result of a URelativeDateTimeFormatter |
| 268 | * operation. The object can be used repeatedly; it is cleared whenever |
| 269 | * passed to a format function. |
| 270 | * |
| 271 | * @param ec Set if an error occurs. |
| 272 | * @return A pointer needing ownership. |
| 273 | * @draft ICU 64 |
| 274 | */ |
| 275 | U_DRAFT UFormattedRelativeDateTime* U_EXPORT2 |
| 276 | ureldatefmt_openResult(UErrorCode* ec); |
| 277 | |
| 278 | /** |
| 279 | * Returns a representation of a UFormattedRelativeDateTime as a UFormattedValue, |
| 280 | * which can be subsequently passed to any API requiring that type. |
| 281 | * |
| 282 | * The returned object is owned by the UFormattedRelativeDateTime and is valid |
| 283 | * only as long as the UFormattedRelativeDateTime is present and unchanged in memory. |
| 284 | * |
| 285 | * You can think of this method as a cast between types. |
| 286 | * |
| 287 | * @param ufrdt The object containing the formatted string. |
| 288 | * @param ec Set if an error occurs. |
| 289 | * @return A UFormattedValue owned by the input object. |
| 290 | * @draft ICU 64 |
| 291 | */ |
| 292 | U_DRAFT const UFormattedValue* U_EXPORT2 |
| 293 | ureldatefmt_resultAsValue(const UFormattedRelativeDateTime* ufrdt, UErrorCode* ec); |
| 294 | |
| 295 | /** |
| 296 | * Releases the UFormattedRelativeDateTime created by ureldatefmt_openResult. |
| 297 | * |
| 298 | * @param ufrdt The object to release. |
| 299 | * @draft ICU 64 |
| 300 | */ |
| 301 | U_DRAFT void U_EXPORT2 |
| 302 | ureldatefmt_closeResult(UFormattedRelativeDateTime* ufrdt); |
| 303 | #endif /* U_HIDE_DRAFT_API */ |
| 304 | |
| 305 | |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 306 | #if U_SHOW_CPLUSPLUS_API |
| 307 | |
| 308 | U_NAMESPACE_BEGIN |
| 309 | |
| 310 | /** |
| 311 | * \class LocalURelativeDateTimeFormatterPointer |
| 312 | * "Smart pointer" class, closes a URelativeDateTimeFormatter via ureldatefmt_close(). |
| 313 | * For most methods see the LocalPointerBase base class. |
| 314 | * |
| 315 | * @see LocalPointerBase |
| 316 | * @see LocalPointer |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 317 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 318 | */ |
| 319 | U_DEFINE_LOCAL_OPEN_POINTER(LocalURelativeDateTimeFormatterPointer, URelativeDateTimeFormatter, ureldatefmt_close); |
| 320 | |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 321 | #ifndef U_HIDE_DRAFT_API |
| 322 | /** |
| 323 | * \class LocalUFormattedRelativeDateTimePointer |
| 324 | * "Smart pointer" class, closes a UFormattedRelativeDateTime via ureldatefmt_closeResult(). |
| 325 | * For most methods see the LocalPointerBase base class. |
| 326 | * |
| 327 | * @see LocalPointerBase |
| 328 | * @see LocalPointer |
| 329 | * @draft ICU 64 |
| 330 | */ |
| 331 | U_DEFINE_LOCAL_OPEN_POINTER(LocalUFormattedRelativeDateTimePointer, UFormattedRelativeDateTime, ureldatefmt_closeResult); |
| 332 | #endif /* U_HIDE_DRAFT_API */ |
| 333 | |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 334 | U_NAMESPACE_END |
| 335 | |
| 336 | #endif |
| 337 | |
| 338 | /** |
| 339 | * Format a combination of URelativeDateTimeUnit and numeric |
| 340 | * offset using a numeric style, e.g. "1 week ago", "in 1 week", |
| 341 | * "5 weeks ago", "in 5 weeks". |
| 342 | * |
| 343 | * @param reldatefmt |
| 344 | * The URelativeDateTimeFormatter object specifying the |
| 345 | * format conventions. |
| 346 | * @param offset |
| 347 | * The signed offset for the specified unit. This will |
| 348 | * be formatted according to this object's UNumberFormat |
| 349 | * object. |
| 350 | * @param unit |
| 351 | * The unit to use when formatting the relative |
| 352 | * date, e.g. UDAT_REL_UNIT_WEEK, UDAT_REL_UNIT_FRIDAY. |
| 353 | * @param result |
| 354 | * A pointer to a buffer to receive the formatted result. |
| 355 | * @param resultCapacity |
| 356 | * The maximum size of result. |
| 357 | * @param status |
| 358 | * A pointer to a UErrorCode to receive any errors. In |
| 359 | * case of error status, the contents of result are |
| 360 | * undefined. |
| 361 | * @return |
| 362 | * The length of the formatted result; may be greater |
| 363 | * than resultCapacity, in which case an error is returned. |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 364 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 365 | */ |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 366 | U_STABLE int32_t U_EXPORT2 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 367 | ureldatefmt_formatNumeric( const URelativeDateTimeFormatter* reldatefmt, |
| 368 | double offset, |
| 369 | URelativeDateTimeUnit unit, |
| 370 | UChar* result, |
| 371 | int32_t resultCapacity, |
| 372 | UErrorCode* status); |
| 373 | |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 374 | #ifndef U_HIDE_DRAFT_API |
| 375 | /** |
| 376 | * Format a combination of URelativeDateTimeUnit and numeric |
| 377 | * offset using a numeric style, e.g. "1 week ago", "in 1 week", |
| 378 | * "5 weeks ago", "in 5 weeks". |
| 379 | * |
| 380 | * @param reldatefmt |
| 381 | * The URelativeDateTimeFormatter object specifying the |
| 382 | * format conventions. |
| 383 | * @param offset |
| 384 | * The signed offset for the specified unit. This will |
| 385 | * be formatted according to this object's UNumberFormat |
| 386 | * object. |
| 387 | * @param unit |
| 388 | * The unit to use when formatting the relative |
| 389 | * date, e.g. UDAT_REL_UNIT_WEEK, UDAT_REL_UNIT_FRIDAY. |
| 390 | * @param result |
| 391 | * A pointer to a UFormattedRelativeDateTime to populate. |
| 392 | * @param status |
| 393 | * A pointer to a UErrorCode to receive any errors. In |
| 394 | * case of error status, the contents of result are |
| 395 | * undefined. |
| 396 | * @draft ICU 64 |
| 397 | */ |
| 398 | U_DRAFT void U_EXPORT2 |
| 399 | ureldatefmt_formatNumericToResult( |
| 400 | const URelativeDateTimeFormatter* reldatefmt, |
| 401 | double offset, |
| 402 | URelativeDateTimeUnit unit, |
| 403 | UFormattedRelativeDateTime* result, |
| 404 | UErrorCode* status); |
| 405 | #endif /* U_HIDE_DRAFT_API */ |
| 406 | |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 407 | /** |
| 408 | * Format a combination of URelativeDateTimeUnit and numeric offset |
| 409 | * using a text style if possible, e.g. "last week", "this week", |
| 410 | * "next week", "yesterday", "tomorrow". Falls back to numeric |
| 411 | * style if no appropriate text term is available for the specified |
| 412 | * offset in the object's locale. |
| 413 | * |
| 414 | * @param reldatefmt |
| 415 | * The URelativeDateTimeFormatter object specifying the |
| 416 | * format conventions. |
| 417 | * @param offset |
| 418 | * The signed offset for the specified unit. |
| 419 | * @param unit |
| 420 | * The unit to use when formatting the relative |
| 421 | * date, e.g. UDAT_REL_UNIT_WEEK, UDAT_REL_UNIT_FRIDAY. |
| 422 | * @param result |
| 423 | * A pointer to a buffer to receive the formatted result. |
| 424 | * @param resultCapacity |
| 425 | * The maximum size of result. |
| 426 | * @param status |
| 427 | * A pointer to a UErrorCode to receive any errors. In |
| 428 | * case of error status, the contents of result are |
| 429 | * undefined. |
| 430 | * @return |
| 431 | * The length of the formatted result; may be greater |
| 432 | * than resultCapacity, in which case an error is returned. |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 433 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 434 | */ |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 435 | U_STABLE int32_t U_EXPORT2 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 436 | ureldatefmt_format( const URelativeDateTimeFormatter* reldatefmt, |
| 437 | double offset, |
| 438 | URelativeDateTimeUnit unit, |
| 439 | UChar* result, |
| 440 | int32_t resultCapacity, |
| 441 | UErrorCode* status); |
| 442 | |
Nikita Iashchenko | da0990f | 2019-06-13 19:36:45 +0100 | [diff] [blame] | 443 | #ifndef U_HIDE_DRAFT_API |
| 444 | /** |
| 445 | * Format a combination of URelativeDateTimeUnit and numeric offset |
| 446 | * using a text style if possible, e.g. "last week", "this week", |
| 447 | * "next week", "yesterday", "tomorrow". Falls back to numeric |
| 448 | * style if no appropriate text term is available for the specified |
| 449 | * offset in the object's locale. |
| 450 | * |
| 451 | * This method populates a UFormattedRelativeDateTime, which exposes more |
| 452 | * information than the string populated by format(). |
| 453 | * |
| 454 | * @param reldatefmt |
| 455 | * The URelativeDateTimeFormatter object specifying the |
| 456 | * format conventions. |
| 457 | * @param offset |
| 458 | * The signed offset for the specified unit. |
| 459 | * @param unit |
| 460 | * The unit to use when formatting the relative |
| 461 | * date, e.g. UDAT_REL_UNIT_WEEK, UDAT_REL_UNIT_FRIDAY. |
| 462 | * @param result |
| 463 | * A pointer to a UFormattedRelativeDateTime to populate. |
| 464 | * @param status |
| 465 | * A pointer to a UErrorCode to receive any errors. In |
| 466 | * case of error status, the contents of result are |
| 467 | * undefined. |
| 468 | * @draft ICU 64 |
| 469 | */ |
| 470 | U_DRAFT void U_EXPORT2 |
| 471 | ureldatefmt_formatToResult( |
| 472 | const URelativeDateTimeFormatter* reldatefmt, |
| 473 | double offset, |
| 474 | URelativeDateTimeUnit unit, |
| 475 | UFormattedRelativeDateTime* result, |
| 476 | UErrorCode* status); |
| 477 | #endif /* U_HIDE_DRAFT_API */ |
| 478 | |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 479 | /** |
| 480 | * Combines a relative date string and a time string in this object's |
| 481 | * locale. This is done with the same date-time separator used for the |
| 482 | * default calendar in this locale to produce a result such as |
| 483 | * "yesterday at 3:45 PM". |
| 484 | * |
| 485 | * @param reldatefmt |
| 486 | * The URelativeDateTimeFormatter object specifying the format conventions. |
| 487 | * @param relativeDateString |
| 488 | * The relative date string. |
| 489 | * @param relativeDateStringLen |
| 490 | * The length of relativeDateString; may be -1 if relativeDateString |
| 491 | * is zero-terminated. |
| 492 | * @param timeString |
| 493 | * The time string. |
| 494 | * @param timeStringLen |
| 495 | * The length of timeString; may be -1 if timeString is zero-terminated. |
| 496 | * @param result |
| 497 | * A pointer to a buffer to receive the formatted result. |
| 498 | * @param resultCapacity |
| 499 | * The maximum size of result. |
| 500 | * @param status |
| 501 | * A pointer to a UErrorCode to receive any errors. In case of error status, |
| 502 | * the contents of result are undefined. |
| 503 | * @return |
| 504 | * The length of the formatted result; may be greater than resultCapacity, |
| 505 | * in which case an error is returned. |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 506 | * @stable ICU 57 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 507 | */ |
Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 508 | U_STABLE int32_t U_EXPORT2 |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 509 | ureldatefmt_combineDateAndTime( const URelativeDateTimeFormatter* reldatefmt, |
| 510 | const UChar * relativeDateString, |
| 511 | int32_t relativeDateStringLen, |
| 512 | const UChar * timeString, |
| 513 | int32_t timeStringLen, |
| 514 | UChar* result, |
| 515 | int32_t resultCapacity, |
| 516 | UErrorCode* status ); |
| 517 | |
Fredrik Roubert | 8de051c | 2016-03-10 13:13:27 +0100 | [diff] [blame] | 518 | #endif /* !UCONFIG_NO_FORMATTING && !UCONFIG_NO_BREAK_ITERATION */ |
| 519 | |
| 520 | #endif |