Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/unicode/reldatefmt.h @ 69:33d812a61356
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 17:55:14 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 69:33d812a61356 |
---|---|
1 // © 2016 and later: Unicode, Inc. and others. | |
2 // License & terms of use: http://www.unicode.org/copyright.html | |
3 /* | |
4 ***************************************************************************** | |
5 * Copyright (C) 2014-2016, International Business Machines Corporation and | |
6 * others. | |
7 * All Rights Reserved. | |
8 ***************************************************************************** | |
9 * | |
10 * File RELDATEFMT.H | |
11 ***************************************************************************** | |
12 */ | |
13 | |
14 #ifndef __RELDATEFMT_H | |
15 #define __RELDATEFMT_H | |
16 | |
17 #include "unicode/utypes.h" | |
18 | |
19 #if U_SHOW_CPLUSPLUS_API | |
20 | |
21 #include "unicode/uobject.h" | |
22 #include "unicode/udisplaycontext.h" | |
23 #include "unicode/ureldatefmt.h" | |
24 #include "unicode/locid.h" | |
25 #include "unicode/formattedvalue.h" | |
26 | |
27 /** | |
28 * \file | |
29 * \brief C++ API: Formats relative dates such as "1 day ago" or "tomorrow" | |
30 */ | |
31 | |
32 #if !UCONFIG_NO_FORMATTING | |
33 | |
34 /** | |
35 * Represents the unit for formatting a relative date. e.g "in 5 days" | |
36 * or "in 3 months" | |
37 * @stable ICU 53 | |
38 */ | |
39 typedef enum UDateRelativeUnit { | |
40 | |
41 /** | |
42 * Seconds | |
43 * @stable ICU 53 | |
44 */ | |
45 UDAT_RELATIVE_SECONDS, | |
46 | |
47 /** | |
48 * Minutes | |
49 * @stable ICU 53 | |
50 */ | |
51 UDAT_RELATIVE_MINUTES, | |
52 | |
53 /** | |
54 * Hours | |
55 * @stable ICU 53 | |
56 */ | |
57 UDAT_RELATIVE_HOURS, | |
58 | |
59 /** | |
60 * Days | |
61 * @stable ICU 53 | |
62 */ | |
63 UDAT_RELATIVE_DAYS, | |
64 | |
65 /** | |
66 * Weeks | |
67 * @stable ICU 53 | |
68 */ | |
69 UDAT_RELATIVE_WEEKS, | |
70 | |
71 /** | |
72 * Months | |
73 * @stable ICU 53 | |
74 */ | |
75 UDAT_RELATIVE_MONTHS, | |
76 | |
77 /** | |
78 * Years | |
79 * @stable ICU 53 | |
80 */ | |
81 UDAT_RELATIVE_YEARS, | |
82 | |
83 #ifndef U_HIDE_DEPRECATED_API | |
84 /** | |
85 * One more than the highest normal UDateRelativeUnit value. | |
86 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. | |
87 */ | |
88 UDAT_RELATIVE_UNIT_COUNT | |
89 #endif // U_HIDE_DEPRECATED_API | |
90 } UDateRelativeUnit; | |
91 | |
92 /** | |
93 * Represents an absolute unit. | |
94 * @stable ICU 53 | |
95 */ | |
96 typedef enum UDateAbsoluteUnit { | |
97 | |
98 // Days of week have to remain together and in order from Sunday to | |
99 // Saturday. | |
100 /** | |
101 * Sunday | |
102 * @stable ICU 53 | |
103 */ | |
104 UDAT_ABSOLUTE_SUNDAY, | |
105 | |
106 /** | |
107 * Monday | |
108 * @stable ICU 53 | |
109 */ | |
110 UDAT_ABSOLUTE_MONDAY, | |
111 | |
112 /** | |
113 * Tuesday | |
114 * @stable ICU 53 | |
115 */ | |
116 UDAT_ABSOLUTE_TUESDAY, | |
117 | |
118 /** | |
119 * Wednesday | |
120 * @stable ICU 53 | |
121 */ | |
122 UDAT_ABSOLUTE_WEDNESDAY, | |
123 | |
124 /** | |
125 * Thursday | |
126 * @stable ICU 53 | |
127 */ | |
128 UDAT_ABSOLUTE_THURSDAY, | |
129 | |
130 /** | |
131 * Friday | |
132 * @stable ICU 53 | |
133 */ | |
134 UDAT_ABSOLUTE_FRIDAY, | |
135 | |
136 /** | |
137 * Saturday | |
138 * @stable ICU 53 | |
139 */ | |
140 UDAT_ABSOLUTE_SATURDAY, | |
141 | |
142 /** | |
143 * Day | |
144 * @stable ICU 53 | |
145 */ | |
146 UDAT_ABSOLUTE_DAY, | |
147 | |
148 /** | |
149 * Week | |
150 * @stable ICU 53 | |
151 */ | |
152 UDAT_ABSOLUTE_WEEK, | |
153 | |
154 /** | |
155 * Month | |
156 * @stable ICU 53 | |
157 */ | |
158 UDAT_ABSOLUTE_MONTH, | |
159 | |
160 /** | |
161 * Year | |
162 * @stable ICU 53 | |
163 */ | |
164 UDAT_ABSOLUTE_YEAR, | |
165 | |
166 /** | |
167 * Now | |
168 * @stable ICU 53 | |
169 */ | |
170 UDAT_ABSOLUTE_NOW, | |
171 | |
172 /** | |
173 * Quarter | |
174 * @stable ICU 63 | |
175 */ | |
176 UDAT_ABSOLUTE_QUARTER, | |
177 | |
178 #ifndef U_HIDE_DRAFT_API | |
179 /** | |
180 * Hour | |
181 * @draft ICU 65 | |
182 */ | |
183 UDAT_ABSOLUTE_HOUR, | |
184 | |
185 /** | |
186 * Minute | |
187 * @draft ICU 65 | |
188 */ | |
189 UDAT_ABSOLUTE_MINUTE, | |
190 #endif // U_HIDE_DRAFT_API | |
191 | |
192 #ifndef U_HIDE_DEPRECATED_API | |
193 /** | |
194 * One more than the highest normal UDateAbsoluteUnit value. | |
195 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. | |
196 */ | |
197 UDAT_ABSOLUTE_UNIT_COUNT = UDAT_ABSOLUTE_NOW + 4 | |
198 #endif // U_HIDE_DEPRECATED_API | |
199 } UDateAbsoluteUnit; | |
200 | |
201 /** | |
202 * Represents a direction for an absolute unit e.g "Next Tuesday" | |
203 * or "Last Tuesday" | |
204 * @stable ICU 53 | |
205 */ | |
206 typedef enum UDateDirection { | |
207 | |
208 /** | |
209 * Two before. Not fully supported in every locale. | |
210 * @stable ICU 53 | |
211 */ | |
212 UDAT_DIRECTION_LAST_2, | |
213 | |
214 /** | |
215 * Last | |
216 * @stable ICU 53 | |
217 */ | |
218 UDAT_DIRECTION_LAST, | |
219 | |
220 /** | |
221 * This | |
222 * @stable ICU 53 | |
223 */ | |
224 UDAT_DIRECTION_THIS, | |
225 | |
226 /** | |
227 * Next | |
228 * @stable ICU 53 | |
229 */ | |
230 UDAT_DIRECTION_NEXT, | |
231 | |
232 /** | |
233 * Two after. Not fully supported in every locale. | |
234 * @stable ICU 53 | |
235 */ | |
236 UDAT_DIRECTION_NEXT_2, | |
237 | |
238 /** | |
239 * Plain, which means the absence of a qualifier. | |
240 * @stable ICU 53 | |
241 */ | |
242 UDAT_DIRECTION_PLAIN, | |
243 | |
244 #ifndef U_HIDE_DEPRECATED_API | |
245 /** | |
246 * One more than the highest normal UDateDirection value. | |
247 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. | |
248 */ | |
249 UDAT_DIRECTION_COUNT | |
250 #endif // U_HIDE_DEPRECATED_API | |
251 } UDateDirection; | |
252 | |
253 #if !UCONFIG_NO_BREAK_ITERATION | |
254 | |
255 U_NAMESPACE_BEGIN | |
256 | |
257 class BreakIterator; | |
258 class RelativeDateTimeCacheData; | |
259 class SharedNumberFormat; | |
260 class SharedPluralRules; | |
261 class SharedBreakIterator; | |
262 class NumberFormat; | |
263 class UnicodeString; | |
264 class FormattedRelativeDateTime; | |
265 class FormattedRelativeDateTimeData; | |
266 | |
267 /** | |
268 * An immutable class containing the result of a relative datetime formatting operation. | |
269 * | |
270 * Instances of this class are immutable and thread-safe. | |
271 * | |
272 * Not intended for public subclassing. | |
273 * | |
274 * @stable ICU 64 | |
275 */ | |
276 class U_I18N_API FormattedRelativeDateTime : public UMemory, public FormattedValue { | |
277 public: | |
278 /** | |
279 * Default constructor; makes an empty FormattedRelativeDateTime. | |
280 * @stable ICU 64 | |
281 */ | |
282 FormattedRelativeDateTime() : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {} | |
283 | |
284 /** | |
285 * Move constructor: Leaves the source FormattedRelativeDateTime in an undefined state. | |
286 * @stable ICU 64 | |
287 */ | |
288 FormattedRelativeDateTime(FormattedRelativeDateTime&& src) U_NOEXCEPT; | |
289 | |
290 /** | |
291 * Destruct an instance of FormattedRelativeDateTime. | |
292 * @stable ICU 64 | |
293 */ | |
294 virtual ~FormattedRelativeDateTime() U_OVERRIDE; | |
295 | |
296 /** Copying not supported; use move constructor instead. */ | |
297 FormattedRelativeDateTime(const FormattedRelativeDateTime&) = delete; | |
298 | |
299 /** Copying not supported; use move assignment instead. */ | |
300 FormattedRelativeDateTime& operator=(const FormattedRelativeDateTime&) = delete; | |
301 | |
302 /** | |
303 * Move assignment: Leaves the source FormattedRelativeDateTime in an undefined state. | |
304 * @stable ICU 64 | |
305 */ | |
306 FormattedRelativeDateTime& operator=(FormattedRelativeDateTime&& src) U_NOEXCEPT; | |
307 | |
308 /** @copydoc FormattedValue::toString() */ | |
309 UnicodeString toString(UErrorCode& status) const U_OVERRIDE; | |
310 | |
311 /** @copydoc FormattedValue::toTempString() */ | |
312 UnicodeString toTempString(UErrorCode& status) const U_OVERRIDE; | |
313 | |
314 /** @copydoc FormattedValue::appendTo() */ | |
315 Appendable &appendTo(Appendable& appendable, UErrorCode& status) const U_OVERRIDE; | |
316 | |
317 /** @copydoc FormattedValue::nextPosition() */ | |
318 UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const U_OVERRIDE; | |
319 | |
320 private: | |
321 FormattedRelativeDateTimeData *fData; | |
322 UErrorCode fErrorCode; | |
323 explicit FormattedRelativeDateTime(FormattedRelativeDateTimeData *results) | |
324 : fData(results), fErrorCode(U_ZERO_ERROR) {} | |
325 explicit FormattedRelativeDateTime(UErrorCode errorCode) | |
326 : fData(nullptr), fErrorCode(errorCode) {} | |
327 friend class RelativeDateTimeFormatter; | |
328 }; | |
329 | |
330 /** | |
331 * Formats simple relative dates. There are two types of relative dates that | |
332 * it handles: | |
333 * <ul> | |
334 * <li>relative dates with a quantity e.g "in 5 days"</li> | |
335 * <li>relative dates without a quantity e.g "next Tuesday"</li> | |
336 * </ul> | |
337 * <p> | |
338 * This API is very basic and is intended to be a building block for more | |
339 * fancy APIs. The caller tells it exactly what to display in a locale | |
340 * independent way. While this class automatically provides the correct plural | |
341 * forms, the grammatical form is otherwise as neutral as possible. It is the | |
342 * caller's responsibility to handle cut-off logic such as deciding between | |
343 * displaying "in 7 days" or "in 1 week." This API supports relative dates | |
344 * involving one single unit. This API does not support relative dates | |
345 * involving compound units, | |
346 * e.g "in 5 days and 4 hours" nor does it support parsing. | |
347 * <p> | |
348 * This class is mostly thread safe and immutable with the following caveats: | |
349 * 1. The assignment operator violates Immutability. It must not be used | |
350 * concurrently with other operations. | |
351 * 2. Caller must not hold onto adopted pointers. | |
352 * <p> | |
353 * This class is not intended for public subclassing. | |
354 * <p> | |
355 * Here are some examples of use: | |
356 * <blockquote> | |
357 * <pre> | |
358 * UErrorCode status = U_ZERO_ERROR; | |
359 * UnicodeString appendTo; | |
360 * RelativeDateTimeFormatter fmt(status); | |
361 * // Appends "in 1 day" | |
362 * fmt.format( | |
363 * 1, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, appendTo, status); | |
364 * // Appends "in 3 days" | |
365 * fmt.format( | |
366 * 3, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, appendTo, status); | |
367 * // Appends "3.2 years ago" | |
368 * fmt.format( | |
369 * 3.2, UDAT_DIRECTION_LAST, UDAT_RELATIVE_YEARS, appendTo, status); | |
370 * // Appends "last Sunday" | |
371 * fmt.format(UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_SUNDAY, appendTo, status); | |
372 * // Appends "this Sunday" | |
373 * fmt.format(UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_SUNDAY, appendTo, status); | |
374 * // Appends "next Sunday" | |
375 * fmt.format(UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_SUNDAY, appendTo, status); | |
376 * // Appends "Sunday" | |
377 * fmt.format(UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_SUNDAY, appendTo, status); | |
378 * | |
379 * // Appends "yesterday" | |
380 * fmt.format(UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_DAY, appendTo, status); | |
381 * // Appends "today" | |
382 * fmt.format(UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_DAY, appendTo, status); | |
383 * // Appends "tomorrow" | |
384 * fmt.format(UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_DAY, appendTo, status); | |
385 * // Appends "now" | |
386 * fmt.format(UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_NOW, appendTo, status); | |
387 * | |
388 * </pre> | |
389 * </blockquote> | |
390 * <p> | |
391 * In the future, we may add more forms, such as abbreviated/short forms | |
392 * (3 secs ago), and relative day periods ("yesterday afternoon"), etc. | |
393 * | |
394 * The RelativeDateTimeFormatter class is not intended for public subclassing. | |
395 * | |
396 * @stable ICU 53 | |
397 */ | |
398 class U_I18N_API RelativeDateTimeFormatter : public UObject { | |
399 public: | |
400 | |
401 /** | |
402 * Create RelativeDateTimeFormatter with default locale. | |
403 * @stable ICU 53 | |
404 */ | |
405 RelativeDateTimeFormatter(UErrorCode& status); | |
406 | |
407 /** | |
408 * Create RelativeDateTimeFormatter with given locale. | |
409 * @stable ICU 53 | |
410 */ | |
411 RelativeDateTimeFormatter(const Locale& locale, UErrorCode& status); | |
412 | |
413 /** | |
414 * Create RelativeDateTimeFormatter with given locale and NumberFormat. | |
415 * | |
416 * @param locale the locale | |
417 * @param nfToAdopt Constructed object takes ownership of this pointer. | |
418 * It is an error for caller to delete this pointer or change its | |
419 * contents after calling this constructor. | |
420 * @param status Any error is returned here. | |
421 * @stable ICU 53 | |
422 */ | |
423 RelativeDateTimeFormatter( | |
424 const Locale& locale, NumberFormat *nfToAdopt, UErrorCode& status); | |
425 | |
426 /** | |
427 * Create RelativeDateTimeFormatter with given locale, NumberFormat, | |
428 * and capitalization context. | |
429 * | |
430 * @param locale the locale | |
431 * @param nfToAdopt Constructed object takes ownership of this pointer. | |
432 * It is an error for caller to delete this pointer or change its | |
433 * contents after calling this constructor. Caller may pass NULL for | |
434 * this argument if they want default number format behavior. | |
435 * @param style the format style. The UDAT_RELATIVE bit field has no effect. | |
436 * @param capitalizationContext A value from UDisplayContext that pertains to | |
437 * capitalization. | |
438 * @param status Any error is returned here. | |
439 * @stable ICU 54 | |
440 */ | |
441 RelativeDateTimeFormatter( | |
442 const Locale& locale, | |
443 NumberFormat *nfToAdopt, | |
444 UDateRelativeDateTimeFormatterStyle style, | |
445 UDisplayContext capitalizationContext, | |
446 UErrorCode& status); | |
447 | |
448 /** | |
449 * Copy constructor. | |
450 * @stable ICU 53 | |
451 */ | |
452 RelativeDateTimeFormatter(const RelativeDateTimeFormatter& other); | |
453 | |
454 /** | |
455 * Assignment operator. | |
456 * @stable ICU 53 | |
457 */ | |
458 RelativeDateTimeFormatter& operator=( | |
459 const RelativeDateTimeFormatter& other); | |
460 | |
461 /** | |
462 * Destructor. | |
463 * @stable ICU 53 | |
464 */ | |
465 virtual ~RelativeDateTimeFormatter(); | |
466 | |
467 /** | |
468 * Formats a relative date with a quantity such as "in 5 days" or | |
469 * "3 months ago" | |
470 * | |
471 * This method returns a String. To get more information about the | |
472 * formatting result, use formatToValue(). | |
473 * | |
474 * @param quantity The numerical amount e.g 5. This value is formatted | |
475 * according to this object's NumberFormat object. | |
476 * @param direction NEXT means a future relative date; LAST means a past | |
477 * relative date. If direction is anything else, this method sets | |
478 * status to U_ILLEGAL_ARGUMENT_ERROR. | |
479 * @param unit the unit e.g day? month? year? | |
480 * @param appendTo The string to which the formatted result will be | |
481 * appended | |
482 * @param status ICU error code returned here. | |
483 * @return appendTo | |
484 * @stable ICU 53 | |
485 */ | |
486 UnicodeString& format( | |
487 double quantity, | |
488 UDateDirection direction, | |
489 UDateRelativeUnit unit, | |
490 UnicodeString& appendTo, | |
491 UErrorCode& status) const; | |
492 | |
493 /** | |
494 * Formats a relative date with a quantity such as "in 5 days" or | |
495 * "3 months ago" | |
496 * | |
497 * This method returns a FormattedRelativeDateTime, which exposes more | |
498 * information than the String returned by format(). | |
499 * | |
500 * @param quantity The numerical amount e.g 5. This value is formatted | |
501 * according to this object's NumberFormat object. | |
502 * @param direction NEXT means a future relative date; LAST means a past | |
503 * relative date. If direction is anything else, this method sets | |
504 * status to U_ILLEGAL_ARGUMENT_ERROR. | |
505 * @param unit the unit e.g day? month? year? | |
506 * @param status ICU error code returned here. | |
507 * @return The formatted relative datetime | |
508 * @stable ICU 64 | |
509 */ | |
510 FormattedRelativeDateTime formatToValue( | |
511 double quantity, | |
512 UDateDirection direction, | |
513 UDateRelativeUnit unit, | |
514 UErrorCode& status) const; | |
515 | |
516 /** | |
517 * Formats a relative date without a quantity. | |
518 * | |
519 * This method returns a String. To get more information about the | |
520 * formatting result, use formatToValue(). | |
521 * | |
522 * @param direction NEXT, LAST, THIS, etc. | |
523 * @param unit e.g SATURDAY, DAY, MONTH | |
524 * @param appendTo The string to which the formatted result will be | |
525 * appended. If the value of direction is documented as not being fully | |
526 * supported in all locales then this method leaves appendTo unchanged if | |
527 * no format string is available. | |
528 * @param status ICU error code returned here. | |
529 * @return appendTo | |
530 * @stable ICU 53 | |
531 */ | |
532 UnicodeString& format( | |
533 UDateDirection direction, | |
534 UDateAbsoluteUnit unit, | |
535 UnicodeString& appendTo, | |
536 UErrorCode& status) const; | |
537 | |
538 /** | |
539 * Formats a relative date without a quantity. | |
540 * | |
541 * This method returns a FormattedRelativeDateTime, which exposes more | |
542 * information than the String returned by format(). | |
543 * | |
544 * If the string is not available in the requested locale, the return | |
545 * value will be empty (calling toString will give an empty string). | |
546 * | |
547 * @param direction NEXT, LAST, THIS, etc. | |
548 * @param unit e.g SATURDAY, DAY, MONTH | |
549 * @param status ICU error code returned here. | |
550 * @return The formatted relative datetime | |
551 * @stable ICU 64 | |
552 */ | |
553 FormattedRelativeDateTime formatToValue( | |
554 UDateDirection direction, | |
555 UDateAbsoluteUnit unit, | |
556 UErrorCode& status) const; | |
557 | |
558 /** | |
559 * Format a combination of URelativeDateTimeUnit and numeric offset | |
560 * using a numeric style, e.g. "1 week ago", "in 1 week", | |
561 * "5 weeks ago", "in 5 weeks". | |
562 * | |
563 * This method returns a String. To get more information about the | |
564 * formatting result, use formatNumericToValue(). | |
565 * | |
566 * @param offset The signed offset for the specified unit. This | |
567 * will be formatted according to this object's | |
568 * NumberFormat object. | |
569 * @param unit The unit to use when formatting the relative | |
570 * date, e.g. UDAT_REL_UNIT_WEEK, | |
571 * UDAT_REL_UNIT_FRIDAY. | |
572 * @param appendTo The string to which the formatted result will be | |
573 * appended. | |
574 * @param status ICU error code returned here. | |
575 * @return appendTo | |
576 * @stable ICU 57 | |
577 */ | |
578 UnicodeString& formatNumeric( | |
579 double offset, | |
580 URelativeDateTimeUnit unit, | |
581 UnicodeString& appendTo, | |
582 UErrorCode& status) const; | |
583 | |
584 /** | |
585 * Format a combination of URelativeDateTimeUnit and numeric offset | |
586 * using a numeric style, e.g. "1 week ago", "in 1 week", | |
587 * "5 weeks ago", "in 5 weeks". | |
588 * | |
589 * This method returns a FormattedRelativeDateTime, which exposes more | |
590 * information than the String returned by formatNumeric(). | |
591 * | |
592 * @param offset The signed offset for the specified unit. This | |
593 * will be formatted according to this object's | |
594 * NumberFormat object. | |
595 * @param unit The unit to use when formatting the relative | |
596 * date, e.g. UDAT_REL_UNIT_WEEK, | |
597 * UDAT_REL_UNIT_FRIDAY. | |
598 * @param status ICU error code returned here. | |
599 * @return The formatted relative datetime | |
600 * @stable ICU 64 | |
601 */ | |
602 FormattedRelativeDateTime formatNumericToValue( | |
603 double offset, | |
604 URelativeDateTimeUnit unit, | |
605 UErrorCode& status) const; | |
606 | |
607 /** | |
608 * Format a combination of URelativeDateTimeUnit and numeric offset | |
609 * using a text style if possible, e.g. "last week", "this week", | |
610 * "next week", "yesterday", "tomorrow". Falls back to numeric | |
611 * style if no appropriate text term is available for the specified | |
612 * offset in the object's locale. | |
613 * | |
614 * This method returns a String. To get more information about the | |
615 * formatting result, use formatToValue(). | |
616 * | |
617 * @param offset The signed offset for the specified unit. | |
618 * @param unit The unit to use when formatting the relative | |
619 * date, e.g. UDAT_REL_UNIT_WEEK, | |
620 * UDAT_REL_UNIT_FRIDAY. | |
621 * @param appendTo The string to which the formatted result will be | |
622 * appended. | |
623 * @param status ICU error code returned here. | |
624 * @return appendTo | |
625 * @stable ICU 57 | |
626 */ | |
627 UnicodeString& format( | |
628 double offset, | |
629 URelativeDateTimeUnit unit, | |
630 UnicodeString& appendTo, | |
631 UErrorCode& status) const; | |
632 | |
633 /** | |
634 * Format a combination of URelativeDateTimeUnit and numeric offset | |
635 * using a text style if possible, e.g. "last week", "this week", | |
636 * "next week", "yesterday", "tomorrow". Falls back to numeric | |
637 * style if no appropriate text term is available for the specified | |
638 * offset in the object's locale. | |
639 * | |
640 * This method returns a FormattedRelativeDateTime, which exposes more | |
641 * information than the String returned by format(). | |
642 * | |
643 * @param offset The signed offset for the specified unit. | |
644 * @param unit The unit to use when formatting the relative | |
645 * date, e.g. UDAT_REL_UNIT_WEEK, | |
646 * UDAT_REL_UNIT_FRIDAY. | |
647 * @param status ICU error code returned here. | |
648 * @return The formatted relative datetime | |
649 * @stable ICU 64 | |
650 */ | |
651 FormattedRelativeDateTime formatToValue( | |
652 double offset, | |
653 URelativeDateTimeUnit unit, | |
654 UErrorCode& status) const; | |
655 | |
656 /** | |
657 * Combines a relative date string and a time string in this object's | |
658 * locale. This is done with the same date-time separator used for the | |
659 * default calendar in this locale. | |
660 * | |
661 * @param relativeDateString the relative date, e.g 'yesterday' | |
662 * @param timeString the time e.g '3:45' | |
663 * @param appendTo concatenated date and time appended here | |
664 * @param status ICU error code returned here. | |
665 * @return appendTo | |
666 * @stable ICU 53 | |
667 */ | |
668 UnicodeString& combineDateAndTime( | |
669 const UnicodeString& relativeDateString, | |
670 const UnicodeString& timeString, | |
671 UnicodeString& appendTo, | |
672 UErrorCode& status) const; | |
673 | |
674 /** | |
675 * Returns the NumberFormat this object is using. | |
676 * | |
677 * @stable ICU 53 | |
678 */ | |
679 const NumberFormat& getNumberFormat() const; | |
680 | |
681 /** | |
682 * Returns the capitalization context. | |
683 * | |
684 * @stable ICU 54 | |
685 */ | |
686 UDisplayContext getCapitalizationContext() const; | |
687 | |
688 /** | |
689 * Returns the format style. | |
690 * | |
691 * @stable ICU 54 | |
692 */ | |
693 UDateRelativeDateTimeFormatterStyle getFormatStyle() const; | |
694 | |
695 private: | |
696 const RelativeDateTimeCacheData* fCache; | |
697 const SharedNumberFormat *fNumberFormat; | |
698 const SharedPluralRules *fPluralRules; | |
699 UDateRelativeDateTimeFormatterStyle fStyle; | |
700 UDisplayContext fContext; | |
701 const SharedBreakIterator *fOptBreakIterator; | |
702 Locale fLocale; | |
703 void init( | |
704 NumberFormat *nfToAdopt, | |
705 BreakIterator *brkIter, | |
706 UErrorCode &status); | |
707 UnicodeString& adjustForContext(UnicodeString &) const; | |
708 UBool checkNoAdjustForContext(UErrorCode& status) const; | |
709 | |
710 template<typename F, typename... Args> | |
711 UnicodeString& doFormat( | |
712 F callback, | |
713 UnicodeString& appendTo, | |
714 UErrorCode& status, | |
715 Args... args) const; | |
716 | |
717 template<typename F, typename... Args> | |
718 FormattedRelativeDateTime doFormatToValue( | |
719 F callback, | |
720 UErrorCode& status, | |
721 Args... args) const; | |
722 | |
723 void formatImpl( | |
724 double quantity, | |
725 UDateDirection direction, | |
726 UDateRelativeUnit unit, | |
727 FormattedRelativeDateTimeData& output, | |
728 UErrorCode& status) const; | |
729 void formatAbsoluteImpl( | |
730 UDateDirection direction, | |
731 UDateAbsoluteUnit unit, | |
732 FormattedRelativeDateTimeData& output, | |
733 UErrorCode& status) const; | |
734 void formatNumericImpl( | |
735 double offset, | |
736 URelativeDateTimeUnit unit, | |
737 FormattedRelativeDateTimeData& output, | |
738 UErrorCode& status) const; | |
739 void formatRelativeImpl( | |
740 double offset, | |
741 URelativeDateTimeUnit unit, | |
742 FormattedRelativeDateTimeData& output, | |
743 UErrorCode& status) const; | |
744 }; | |
745 | |
746 U_NAMESPACE_END | |
747 | |
748 #endif /* !UCONFIG_NO_BREAK_ITERATION */ | |
749 #endif /* !UCONFIG_NO_FORMATTING */ | |
750 | |
751 #endif /* U_SHOW_CPLUSPLUS_API */ | |
752 | |
753 #endif /* __RELDATEFMT_H */ |