ICU 54.1 54.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, 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
65 typedef enum UDateRelativeUnit {
66
71 UDAT_RELATIVE_SECONDS,
72
77 UDAT_RELATIVE_MINUTES,
78
83 UDAT_RELATIVE_HOURS,
84
89 UDAT_RELATIVE_DAYS,
90
95 UDAT_RELATIVE_WEEKS,
96
101 UDAT_RELATIVE_MONTHS,
102
107 UDAT_RELATIVE_YEARS,
108
113 UDAT_RELATIVE_UNIT_COUNT
114 } UDateRelativeUnit;
115
120 typedef enum UDateAbsoluteUnit {
121
122 // Days of week have to remain together and in order from Sunday to
123 // Saturday.
128 UDAT_ABSOLUTE_SUNDAY,
129
134 UDAT_ABSOLUTE_MONDAY,
135
140 UDAT_ABSOLUTE_TUESDAY,
141
146 UDAT_ABSOLUTE_WEDNESDAY,
147
152 UDAT_ABSOLUTE_THURSDAY,
153
158 UDAT_ABSOLUTE_FRIDAY,
159
164 UDAT_ABSOLUTE_SATURDAY,
165
170 UDAT_ABSOLUTE_DAY,
171
176 UDAT_ABSOLUTE_WEEK,
177
182 UDAT_ABSOLUTE_MONTH,
183
188 UDAT_ABSOLUTE_YEAR,
189
194 UDAT_ABSOLUTE_NOW,
195
200 UDAT_ABSOLUTE_UNIT_COUNT
201 } UDateAbsoluteUnit;
202
208 typedef enum UDateDirection {
209
214 UDAT_DIRECTION_LAST_2,
215
220 UDAT_DIRECTION_LAST,
221
226 UDAT_DIRECTION_THIS,
227
232 UDAT_DIRECTION_NEXT,
233
238 UDAT_DIRECTION_NEXT_2,
239
244 UDAT_DIRECTION_PLAIN,
245
250 UDAT_DIRECTION_COUNT
251 } UDateDirection;
252
253
254 U_NAMESPACE_BEGIN
255
256 class RelativeDateTimeCacheData;
257 class SharedNumberFormat;
258 class SharedPluralRules;
259 class SharedBreakIterator;
260 class NumberFormat;
261 class UnicodeString;
262
331 class U_I18N_API RelativeDateTimeFormatter : public UObject {
332 public:
333
338 RelativeDateTimeFormatter(UErrorCode& status);
339
344 RelativeDateTimeFormatter(const Locale& locale, UErrorCode& status);
345
356 RelativeDateTimeFormatter(
357 const Locale& locale, NumberFormat *nfToAdopt, UErrorCode& status);
358
374 RelativeDateTimeFormatter(
375 const Locale& locale,
376 NumberFormat *nfToAdopt,
377 UDateRelativeDateTimeFormatterStyle style,
378 UDisplayContext capitalizationContext,
379 UErrorCode& status);
380
385 RelativeDateTimeFormatter(const RelativeDateTimeFormatter& other);
386
391 RelativeDateTimeFormatter& operator=(
392 const RelativeDateTimeFormatter& other);
393
398 virtual ~RelativeDateTimeFormatter();
399
415 UnicodeString& format(
416 double quantity,
417 UDateDirection direction,
418 UDateRelativeUnit unit,
419 UnicodeString& appendTo,
420 UErrorCode& status) const;
421
434 UnicodeString& format(
435 UDateDirection direction,
436 UDateAbsoluteUnit unit,
437 UnicodeString& appendTo,
438 UErrorCode& status) const;
439
452 UnicodeString& combineDateAndTime(
453 const UnicodeString& relativeDateString,
454 const UnicodeString& timeString,
455 UnicodeString& appendTo,
456 UErrorCode& status) const;
457
463 const NumberFormat& getNumberFormat() const;
464
470 UDisplayContext getCapitalizationContext() const;
471
477 UDateRelativeDateTimeFormatterStyle getFormatStyle() const;
478 private:
479 const RelativeDateTimeCacheData* fCache;
480 const SharedNumberFormat *fNumberFormat;
481 const SharedPluralRules *fPluralRules;
482 UDateRelativeDateTimeFormatterStyle fStyle;
483 UDisplayContext fContext;
484 const SharedBreakIterator *fOptBreakIterator;
485 Locale fLocale;
486 void init(
487 NumberFormat *nfToAdopt,
488 BreakIterator *brkIter,
489 UErrorCode &status);
490 void adjustForContext(UnicodeString &) const;
491 };
492
493 U_NAMESPACE_END
494
495 #endif /* U_HIDE_DRAFT_API */
496
497 #endif /* !UCONFIG_NO_FORMATTING && !UCONFIG_NO_BREAK_ITERATION*/
498 #endif