ICU 63.1 63.1

reldatefmt.h
Go to the documentation of this file.
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 #include "unicode/uobject.h"
19 #include "unicode/udisplaycontext.h"
20 #include "unicode/ureldatefmt.h"
21 #include "unicode/locid.h"
22
28 #if !UCONFIG_NO_FORMATTING
29
35 typedef enum UDateRelativeUnit {
36
41 UDAT_RELATIVE_SECONDS,
42
47 UDAT_RELATIVE_MINUTES,
48
53 UDAT_RELATIVE_HOURS,
54
59 UDAT_RELATIVE_DAYS,
60
65 UDAT_RELATIVE_WEEKS,
66
71 UDAT_RELATIVE_MONTHS,
72
77 UDAT_RELATIVE_YEARS,
78
79 #ifndef U_HIDE_DEPRECATED_API
80
84 UDAT_RELATIVE_UNIT_COUNT
85 #endif // U_HIDE_DEPRECATED_API
86 } UDateRelativeUnit;
87
92 typedef enum UDateAbsoluteUnit {
93
94 // Days of week have to remain together and in order from Sunday to
95 // Saturday.
100 UDAT_ABSOLUTE_SUNDAY,
101
106 UDAT_ABSOLUTE_MONDAY,
107
112 UDAT_ABSOLUTE_TUESDAY,
113
118 UDAT_ABSOLUTE_WEDNESDAY,
119
124 UDAT_ABSOLUTE_THURSDAY,
125
130 UDAT_ABSOLUTE_FRIDAY,
131
136 UDAT_ABSOLUTE_SATURDAY,
137
142 UDAT_ABSOLUTE_DAY,
143
148 UDAT_ABSOLUTE_WEEK,
149
154 UDAT_ABSOLUTE_MONTH,
155
160 UDAT_ABSOLUTE_YEAR,
161
166 UDAT_ABSOLUTE_NOW,
167
168 #ifndef U_HIDE_DRAFT_API
169
173 UDAT_ABSOLUTE_QUARTER,
174 #endif // U_HIDE_DRAFT_API
175
176 #ifndef U_HIDE_DEPRECATED_API
177
181 UDAT_ABSOLUTE_UNIT_COUNT = UDAT_ABSOLUTE_NOW + 2
182 #endif // U_HIDE_DEPRECATED_API
183 } UDateAbsoluteUnit;
184
190 typedef enum UDateDirection {
191
196 UDAT_DIRECTION_LAST_2,
197
202 UDAT_DIRECTION_LAST,
203
208 UDAT_DIRECTION_THIS,
209
214 UDAT_DIRECTION_NEXT,
215
220 UDAT_DIRECTION_NEXT_2,
221
226 UDAT_DIRECTION_PLAIN,
227
228 #ifndef U_HIDE_DEPRECATED_API
229
233 UDAT_DIRECTION_COUNT
234 #endif // U_HIDE_DEPRECATED_API
235 } UDateDirection;
236
237 #if !UCONFIG_NO_BREAK_ITERATION
238
239 U_NAMESPACE_BEGIN
240
241 class BreakIterator;
242 class RelativeDateTimeCacheData;
243 class SharedNumberFormat;
244 class SharedPluralRules;
245 class SharedBreakIterator;
246 class NumberFormat;
247 class UnicodeString;
248
317 class U_I18N_API RelativeDateTimeFormatter : public UObject {
318 public:
319
324 RelativeDateTimeFormatter(UErrorCode& status);
325
330 RelativeDateTimeFormatter(const Locale& locale, UErrorCode& status);
331
342 RelativeDateTimeFormatter(
343 const Locale& locale, NumberFormat *nfToAdopt, UErrorCode& status);
344
360 RelativeDateTimeFormatter(
361 const Locale& locale,
362 NumberFormat *nfToAdopt,
363 UDateRelativeDateTimeFormatterStyle style,
364 UDisplayContext capitalizationContext,
365 UErrorCode& status);
366
371 RelativeDateTimeFormatter(const RelativeDateTimeFormatter& other);
372
377 RelativeDateTimeFormatter& operator=(
378 const RelativeDateTimeFormatter& other);
379
384 virtual ~RelativeDateTimeFormatter();
385
401 UnicodeString& format(
402 double quantity,
403 UDateDirection direction,
404 UDateRelativeUnit unit,
405 UnicodeString& appendTo,
406 UErrorCode& status) const;
407
420 UnicodeString& format(
421 UDateDirection direction,
422 UDateAbsoluteUnit unit,
423 UnicodeString& appendTo,
424 UErrorCode& status) const;
425
443 UnicodeString& formatNumeric(
444 double offset,
445 URelativeDateTimeUnit unit,
446 UnicodeString& appendTo,
447 UErrorCode& status) const;
448
466 UnicodeString& format(
467 double offset,
468 URelativeDateTimeUnit unit,
469 UnicodeString& appendTo,
470 UErrorCode& status) const;
471
484 UnicodeString& combineDateAndTime(
485 const UnicodeString& relativeDateString,
486 const UnicodeString& timeString,
487 UnicodeString& appendTo,
488 UErrorCode& status) const;
489
495 const NumberFormat& getNumberFormat() const;
496
502 UDisplayContext getCapitalizationContext() const;
503
509 UDateRelativeDateTimeFormatterStyle getFormatStyle() const;
510
511 private:
512 const RelativeDateTimeCacheData* fCache;
513 const SharedNumberFormat *fNumberFormat;
514 const SharedPluralRules *fPluralRules;
515 UDateRelativeDateTimeFormatterStyle fStyle;
516 UDisplayContext fContext;
517 const SharedBreakIterator *fOptBreakIterator;
518 Locale fLocale;
519 void init(
520 NumberFormat *nfToAdopt,
521 BreakIterator *brkIter,
522 UErrorCode &status);
523 void adjustForContext(UnicodeString &) const;
524 };
525
526 U_NAMESPACE_END
527
528 #endif /* !UCONFIG_NO_BREAK_ITERATION */
529 #endif /* !UCONFIG_NO_FORMATTING */
530 #endif /* __RELDATEFMT_H */
UDAT_ABSOLUTE_DAY
Day.
Definition: reldatefmt.h:142
UDAT_RELATIVE_MINUTES
Minutes.
Definition: reldatefmt.h:47
UDAT_ABSOLUTE_UNIT_COUNT
One more than the highest normal UDateAbsoluteUnit value.
Definition: reldatefmt.h:181
URelativeDateTimeUnit
URelativeDateTimeUnit
Represents the unit for formatting a relative date.
Definition: ureldatefmt.h:77
UDAT_ABSOLUTE_THURSDAY
Thursday.
Definition: reldatefmt.h:124
UDAT_DIRECTION_NEXT_2
Two after.
Definition: reldatefmt.h:220
icu::NumberFormat
Definition: numfmt.h:173
UDAT_ABSOLUTE_QUARTER
Quarter.
Definition: reldatefmt.h:173
UDisplayContext
UDisplayContext
Display context settings.
Definition: udisplaycontext.h:64
UDAT_RELATIVE_WEEKS
Weeks.
Definition: reldatefmt.h:65
UDAT_ABSOLUTE_MONDAY
Monday.
Definition: reldatefmt.h:106
UDAT_ABSOLUTE_FRIDAY
Friday.
Definition: reldatefmt.h:130
UDAT_RELATIVE_YEARS
Years.
Definition: reldatefmt.h:77
udisplaycontext.h
C API: Display context types (enum values)
UDAT_ABSOLUTE_SUNDAY
Sunday.
Definition: reldatefmt.h:100
UDAT_DIRECTION_LAST_2
Two before.
Definition: reldatefmt.h:196
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
ureldatefmt.h
C API: URelativeDateTimeFormatter, relative date formatting of unit + numeric offset.
icu::BreakIterator
The BreakIterator class implements methods for finding the location of boundaries in text...
Definition: brkiter.h:102
UDAT_RELATIVE_DAYS
Days.
Definition: reldatefmt.h:59
UDateRelativeDateTimeFormatterStyle
UDateRelativeDateTimeFormatterStyle
The formatting style.
Definition: ureldatefmt.h:44
UDateDirection
UDateDirection
Represents a direction for an absolute unit e.g "Next Tuesday" or "Last Tuesday". ...
Definition: reldatefmt.h:190
UDAT_DIRECTION_PLAIN
Plain, which means the absence of a qualifier.
Definition: reldatefmt.h:226
icu::RelativeDateTimeFormatter
Formats simple relative dates.
Definition: reldatefmt.h:317
uobject.h
C++ API: Common ICU base class UObject.
UDAT_ABSOLUTE_TUESDAY
Tuesday.
Definition: reldatefmt.h:112
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
UDAT_ABSOLUTE_WEEK
Week.
Definition: reldatefmt.h:148
UDAT_DIRECTION_COUNT
One more than the highest normal UDateDirection value.
Definition: reldatefmt.h:233
UDateAbsoluteUnit
UDateAbsoluteUnit
Represents an absolute unit.
Definition: reldatefmt.h:92
UDAT_ABSOLUTE_YEAR
Year.
Definition: reldatefmt.h:160
UDAT_ABSOLUTE_SATURDAY
Saturday.
Definition: reldatefmt.h:136
locid.h
C++ API: Locale ID object.
UDAT_ABSOLUTE_NOW
Now.
Definition: reldatefmt.h:166
UDAT_DIRECTION_THIS
This.
Definition: reldatefmt.h:208
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UDAT_RELATIVE_HOURS
Hours.
Definition: reldatefmt.h:53
UDAT_ABSOLUTE_WEDNESDAY
Wednesday.
Definition: reldatefmt.h:118
UDAT_RELATIVE_SECONDS
Seconds.
Definition: reldatefmt.h:41
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
UDAT_RELATIVE_MONTHS
Months.
Definition: reldatefmt.h:71
UDAT_RELATIVE_UNIT_COUNT
One more than the highest normal UDateRelativeUnit value.
Definition: reldatefmt.h:84
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:220
UDAT_ABSOLUTE_MONTH
Month.
Definition: reldatefmt.h:154
UDateRelativeUnit
UDateRelativeUnit
Represents the unit for formatting a relative date.
Definition: reldatefmt.h:35
UDAT_DIRECTION_LAST
Last.
Definition: reldatefmt.h:202
UDAT_DIRECTION_NEXT
Next.
Definition: reldatefmt.h:214
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192