ICU 77.1
77.1
i18n
unicode
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
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
32
#if !UCONFIG_NO_FORMATTING
33
39
typedef
enum
UDateRelativeUnit
{
40
45
UDAT_RELATIVE_SECONDS
,
46
51
UDAT_RELATIVE_MINUTES
,
52
57
UDAT_RELATIVE_HOURS
,
58
63
UDAT_RELATIVE_DAYS
,
64
69
UDAT_RELATIVE_WEEKS
,
70
75
UDAT_RELATIVE_MONTHS
,
76
81
UDAT_RELATIVE_YEARS
,
82
83
#ifndef U_HIDE_DEPRECATED_API
88
UDAT_RELATIVE_UNIT_COUNT
89
#endif
// U_HIDE_DEPRECATED_API
90
}
UDateRelativeUnit
;
91
96
typedef
enum
UDateAbsoluteUnit
{
97
98
// Days of week have to remain together and in order from Sunday to
99
// Saturday.
104
UDAT_ABSOLUTE_SUNDAY
,
105
110
UDAT_ABSOLUTE_MONDAY
,
111
116
UDAT_ABSOLUTE_TUESDAY
,
117
122
UDAT_ABSOLUTE_WEDNESDAY
,
123
128
UDAT_ABSOLUTE_THURSDAY
,
129
134
UDAT_ABSOLUTE_FRIDAY
,
135
140
UDAT_ABSOLUTE_SATURDAY
,
141
146
UDAT_ABSOLUTE_DAY
,
147
152
UDAT_ABSOLUTE_WEEK
,
153
158
UDAT_ABSOLUTE_MONTH
,
159
164
UDAT_ABSOLUTE_YEAR
,
165
170
UDAT_ABSOLUTE_NOW
,
171
176
UDAT_ABSOLUTE_QUARTER
,
177
182
UDAT_ABSOLUTE_HOUR
,
183
188
UDAT_ABSOLUTE_MINUTE
,
189
190
#ifndef U_HIDE_DEPRECATED_API
195
UDAT_ABSOLUTE_UNIT_COUNT
=
UDAT_ABSOLUTE_NOW
+ 4
196
#endif
// U_HIDE_DEPRECATED_API
197
}
UDateAbsoluteUnit
;
198
204
typedef
enum
UDateDirection
{
205
210
UDAT_DIRECTION_LAST_2
,
211
216
UDAT_DIRECTION_LAST
,
217
222
UDAT_DIRECTION_THIS
,
223
228
UDAT_DIRECTION_NEXT
,
229
234
UDAT_DIRECTION_NEXT_2
,
235
240
UDAT_DIRECTION_PLAIN
,
241
242
#ifndef U_HIDE_DEPRECATED_API
247
UDAT_DIRECTION_COUNT
248
#endif
// U_HIDE_DEPRECATED_API
249
}
UDateDirection
;
250
251
U_NAMESPACE_BEGIN
252
253
class
BreakIterator;
254
class
RelativeDateTimeCacheData;
255
class
SharedNumberFormat;
256
class
SharedPluralRules;
257
class
SharedBreakIterator;
258
class
NumberFormat;
259
class
UnicodeString;
260
class
FormattedRelativeDateTime;
261
class
FormattedRelativeDateTimeData;
262
272
class
U_I18N_API
FormattedRelativeDateTime
:
public
UMemory
,
public
FormattedValue
{
273
public
:
278
FormattedRelativeDateTime
() : fData(nullptr), fErrorCode(
U_INVALID_STATE_ERROR
) {}
279
284
FormattedRelativeDateTime
(
FormattedRelativeDateTime
&& src) noexcept;
285
290
virtual
~FormattedRelativeDateTime
()
override
;
291
293
FormattedRelativeDateTime
(
const
FormattedRelativeDateTime
&) =
delete
;
294
296
FormattedRelativeDateTime
&
operator=
(
const
FormattedRelativeDateTime
&) =
delete
;
297
302
FormattedRelativeDateTime
&
operator=
(
FormattedRelativeDateTime
&& src) noexcept;
303
305
UnicodeString
toString
(
UErrorCode
& status)
const override
;
306
308
UnicodeString
toTempString
(
UErrorCode
& status)
const override
;
309
311
Appendable
&
appendTo
(
Appendable
& appendable,
UErrorCode
& status)
const override
;
312
314
UBool
nextPosition
(
ConstrainedFieldPosition
& cfpos,
UErrorCode
& status)
const override
;
315
316
private
:
317
FormattedRelativeDateTimeData *fData;
318
UErrorCode
fErrorCode;
319
explicit
FormattedRelativeDateTime
(FormattedRelativeDateTimeData *results)
320
: fData(results), fErrorCode(
U_ZERO_ERROR
) {}
321
explicit
FormattedRelativeDateTime
(
UErrorCode
errorCode)
322
: fData(nullptr), fErrorCode(errorCode) {}
323
friend
class
RelativeDateTimeFormatter;
324
};
325
396
class
U_I18N_API
RelativeDateTimeFormatter
:
public
UObject
{
397
public
:
398
403
RelativeDateTimeFormatter
(
UErrorCode
& status);
404
409
RelativeDateTimeFormatter
(
const
Locale
& locale,
UErrorCode
& status);
410
421
RelativeDateTimeFormatter
(
422
const
Locale
& locale,
NumberFormat
*nfToAdopt,
UErrorCode
& status);
423
439
RelativeDateTimeFormatter
(
440
const
Locale
& locale,
441
NumberFormat
*nfToAdopt,
442
UDateRelativeDateTimeFormatterStyle
style,
443
UDisplayContext
capitalizationContext,
444
UErrorCode
& status);
445
450
RelativeDateTimeFormatter
(
const
RelativeDateTimeFormatter
& other);
451
456
RelativeDateTimeFormatter
&
operator=
(
457
const
RelativeDateTimeFormatter
& other);
458
463
virtual
~RelativeDateTimeFormatter
();
464
484
UnicodeString
&
format
(
485
double
quantity,
486
UDateDirection
direction,
487
UDateRelativeUnit
unit,
488
UnicodeString
& appendTo,
489
UErrorCode
& status)
const
;
490
508
FormattedRelativeDateTime
formatToValue
(
509
double
quantity,
510
UDateDirection
direction,
511
UDateRelativeUnit
unit,
512
UErrorCode
& status)
const
;
513
530
UnicodeString
&
format
(
531
UDateDirection
direction,
532
UDateAbsoluteUnit
unit,
533
UnicodeString
& appendTo,
534
UErrorCode
& status)
const
;
535
551
FormattedRelativeDateTime
formatToValue
(
552
UDateDirection
direction,
553
UDateAbsoluteUnit
unit,
554
UErrorCode
& status)
const
;
555
576
UnicodeString
&
formatNumeric
(
577
double
offset,