ICU 58.2 58.2

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

- File List
- Globals

reldatefmt.h
Go to the documentation of this file.
1 // Copyright (C) 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_DEPRECATED_API
169
173 UDAT_ABSOLUTE_UNIT_COUNT
174 #endif // U_HIDE_DEPRECATED_API
175 } UDateAbsoluteUnit;
176
182 typedef enum UDateDirection {
183
188 UDAT_DIRECTION_LAST_2,
189
194 UDAT_DIRECTION_LAST,
195
200 UDAT_DIRECTION_THIS,
201
206 UDAT_DIRECTION_NEXT,
207
212 UDAT_DIRECTION_NEXT_2,
213
218 UDAT_DIRECTION_PLAIN,
219
220 #ifndef U_HIDE_DEPRECATED_API
221
225 UDAT_DIRECTION_COUNT
226 #endif // U_HIDE_DEPRECATED_API
227 } UDateDirection;
228
229 #if !UCONFIG_NO_BREAK_ITERATION
230
231 U_NAMESPACE_BEGIN
232
233 class RelativeDateTimeCacheData;
234 class SharedNumberFormat;
235 class SharedPluralRules;
236 class SharedBreakIterator;
237 class NumberFormat;
238 class UnicodeString;
239
308 class U_I18N_API RelativeDateTimeFormatter : public UObject {
309 public:
310
315 RelativeDateTimeFormatter(UErrorCode& status);
316
321 RelativeDateTimeFormatter(const Locale& locale, UErrorCode& status);
322
333 RelativeDateTimeFormatter(
334 const Locale& locale, NumberFormat *nfToAdopt, UErrorCode& status);
335
351 RelativeDateTimeFormatter(
352 const Locale& locale,
353 NumberFormat *nfToAdopt,
354 UDateRelativeDateTimeFormatterStyle style,
355 UDisplayContext capitalizationContext,
356 UErrorCode& status);
357
362 RelativeDateTimeFormatter(const RelativeDateTimeFormatter& other);
363
368 RelativeDateTimeFormatter& operator=(
369 const RelativeDateTimeFormatter& other);
370
375 virtual ~RelativeDateTimeFormatter();
376
392 UnicodeString& format(
393 double quantity,
394 UDateDirection direction,
395 UDateRelativeUnit unit,
396 UnicodeString& appendTo,
397 UErrorCode& status) const;
398
411 UnicodeString& format(
412 UDateDirection direction,
413 UDateAbsoluteUnit unit,
414 UnicodeString& appendTo,
415 UErrorCode& status) const;
416
417 #ifndef U_HIDE_DRAFT_API
418
435 UnicodeString& formatNumeric(
436 double offset,
437 URelativeDateTimeUnit unit,
438 UnicodeString& appendTo,
439 UErrorCode& status) const;
440
458 UnicodeString& format(
459 double offset,
460 URelativeDateTimeUnit unit,
461 UnicodeString& appendTo,
462 UErrorCode& status) const;
463 #endif /* U_HIDE_DRAFT_API */
464
477 UnicodeString& combineDateAndTime(
478 const UnicodeString& relativeDateString,
479 const UnicodeString& timeString,
480 UnicodeString& appendTo,
481 UErrorCode& status) const;
482
488 const NumberFormat& getNumberFormat() const;
489
495 UDisplayContext getCapitalizationContext() const;
496
502 UDateRelativeDateTimeFormatterStyle getFormatStyle() const;
503
504 private:
505 const RelativeDateTimeCacheData* fCache;
506 const SharedNumberFormat *fNumberFormat;
507 const SharedPluralRules *fPluralRules;
508 UDateRelativeDateTimeFormatterStyle fStyle;
509 UDisplayContext fContext;
510 const SharedBreakIterator *fOptBreakIterator;
511 Locale fLocale;
512 void init(
513 NumberFormat *nfToAdopt,
514 BreakIterator *brkIter,
515 UErrorCode &status);
516 void adjustForContext(UnicodeString &) const;
517 };
518
519 U_NAMESPACE_END
520
521 #endif /* !UCONFIG_NO_BREAK_ITERATION */
522 #endif /* !UCONFIG_NO_FORMATTING */
523 #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:173
URelativeDateTimeUnit
URelativeDateTimeUnit
Represents the unit for formatting a relative date.
Definition: ureldatefmt.h:78
UDAT_ABSOLUTE_THURSDAY
Thursday.
Definition: reldatefmt.h:124
UDAT_DIRECTION_NEXT_2
Two after.
Definition: reldatefmt.h:212
icu::NumberFormat
Abstract base class for all number formats.
Definition: numfmt.h:169
UDisplayContext
UDisplayContext
Display context settings.
Definition: udisplaycontext.h:66
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:188
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:360
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
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:182
UDAT_DIRECTION_PLAIN
Plain, which means the absence of a qualifier.
Definition: reldatefmt.h:218
icu::RelativeDateTimeFormatter
Formats simple relative dates.
Definition: reldatefmt.h:308
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:132
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
UDAT_ABSOLUTE_WEEK
Week.
Definition: reldatefmt.h:148
UDAT_DIRECTION_COUNT
One more than the highest normal UDateDirection value.
Definition: reldatefmt.h:225
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:200
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:295
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:223
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:194
UDAT_DIRECTION_NEXT
Next.
Definition: reldatefmt.h:206
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:187