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