ICU 55.1 55.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
reldatefmt.h
Go to the documentation of this file.
1 /*
2 *****************************************************************************
3 * Copyright (C) 2014-2015, International Business Machines Corporation and
4 * others.
5 * All Rights Reserved.
6 *****************************************************************************
7 *
8 * File RELDATEFMT.H
9 *****************************************************************************
10 */
11
12 #ifndef __RELDATEFMT_H
13 #define __RELDATEFMT_H
14
15 #include "unicode/utypes.h"
16 #include "unicode/uobject.h"
17 #include "unicode/udisplaycontext.h"
18 #include "unicode/locid.h"
19
25 #if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_BREAK_ITERATION
26
27 #ifndef U_HIDE_DRAFT_API
28
33 typedef enum UDateRelativeDateTimeFormatterStyle {
34
39 UDAT_STYLE_LONG,
40
45 UDAT_STYLE_SHORT,
46
51 UDAT_STYLE_NARROW,
52
57 UDAT_STYLE_COUNT
58 } UDateRelativeDateTimeFormatterStyle;
59
60 #endif /* U_HIDE_DRAFT_API */
61
67 typedef enum UDateRelativeUnit {
68
73 UDAT_RELATIVE_SECONDS,
74
79 UDAT_RELATIVE_MINUTES,
80
85 UDAT_RELATIVE_HOURS,
86
91 UDAT_RELATIVE_DAYS,
92
97 UDAT_RELATIVE_WEEKS,
98
103 UDAT_RELATIVE_MONTHS,
104
109 UDAT_RELATIVE_YEARS,
110
115 UDAT_RELATIVE_UNIT_COUNT
116 } UDateRelativeUnit;
117
122 typedef enum UDateAbsoluteUnit {
123
124 // Days of week have to remain together and in order from Sunday to
125 // Saturday.
130 UDAT_ABSOLUTE_SUNDAY,
131
136 UDAT_ABSOLUTE_MONDAY,
137
142 UDAT_ABSOLUTE_TUESDAY,
143
148 UDAT_ABSOLUTE_WEDNESDAY,
149
154 UDAT_ABSOLUTE_THURSDAY,
155
160 UDAT_ABSOLUTE_FRIDAY,
161
166 UDAT_ABSOLUTE_SATURDAY,
167
172 UDAT_ABSOLUTE_DAY,
173
178 UDAT_ABSOLUTE_WEEK,
179
184 UDAT_ABSOLUTE_MONTH,
185
190 UDAT_ABSOLUTE_YEAR,
191
196 UDAT_ABSOLUTE_NOW,
197
202 UDAT_ABSOLUTE_UNIT_COUNT
203 } UDateAbsoluteUnit;
204
210 typedef enum UDateDirection {
211
216 UDAT_DIRECTION_LAST_2,
217
222 UDAT_DIRECTION_LAST,
223
228 UDAT_DIRECTION_THIS,
229
234 UDAT_DIRECTION_NEXT,
235
240 UDAT_DIRECTION_NEXT_2,
241
246 UDAT_DIRECTION_PLAIN,
247
252 UDAT_DIRECTION_COUNT
253 } UDateDirection;
254
255
256 U_NAMESPACE_BEGIN
257
258 class RelativeDateTimeCacheData;
259 class SharedNumberFormat;
260 class SharedPluralRules;
261 class SharedBreakIterator;
262 class NumberFormat;
263 class UnicodeString;
264
333 class U_I18N_API RelativeDateTimeFormatter : public UObject {
334 public:
335
340 RelativeDateTimeFormatter(UErrorCode& status);
341
346 RelativeDateTimeFormatter(const Locale& locale, UErrorCode& status);
347
358 RelativeDateTimeFormatter(
359 const Locale& locale, NumberFormat *nfToAdopt, UErrorCode& status);
360
361 #ifndef U_HIDE_DRAFT_API
362
377 RelativeDateTimeFormatter(
378 const Locale& locale,
379 NumberFormat *nfToAdopt,
380 UDateRelativeDateTimeFormatterStyle style,
381 UDisplayContext capitalizationContext,
382 UErrorCode& status);
383 #endif /* U_HIDE_DRAFT_API */
384
389 RelativeDateTimeFormatter(const RelativeDateTimeFormatter& other);
390
395 RelativeDateTimeFormatter& operator=(
396 const RelativeDateTimeFormatter& other);
397
402 virtual ~RelativeDateTimeFormatter();
403
419 UnicodeString& format(
420 double quantity,
421 UDateDirection direction,
422 UDateRelativeUnit unit,
423 UnicodeString& appendTo,
424 UErrorCode& status) const;
425
438 UnicodeString& format(
439 UDateDirection direction,
440 UDateAbsoluteUnit unit,
441 UnicodeString& appendTo,
442 UErrorCode& status) const;
443
456 UnicodeString& combineDateAndTime(
457 const UnicodeString& relativeDateString,
458 const UnicodeString& timeString,
459 UnicodeString& appendTo,
460 UErrorCode& status) const;
461
467 const NumberFormat& getNumberFormat() const;
468
469 #ifndef U_HIDE_DRAFT_API
470
475 UDisplayContext getCapitalizationContext() const;
476
482 UDateRelativeDateTimeFormatterStyle getFormatStyle() const;
483 #endif /* U_HIDE_DRAFT_API */
484
485 private:
486 const RelativeDateTimeCacheData* fCache;
487 const SharedNumberFormat *fNumberFormat;
488 const SharedPluralRules *fPluralRules;
489 UDateRelativeDateTimeFormatterStyle fStyle;
490 UDisplayContext fContext;
491 const SharedBreakIterator *fOptBreakIterator;
492 Locale fLocale;
493 void init(
494 NumberFormat *nfToAdopt,
495 BreakIterator *brkIter,
496 UErrorCode &status);
497 void adjustForContext(UnicodeString &) const;
498 };
499
500 U_NAMESPACE_END
501
502 #endif /* !UCONFIG_NO_FORMATTING && !UCONFIG_NO_BREAK_ITERATION*/
503 #endif