ICU 77.1  77.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 
19 #if U_SHOW_CPLUSPLUS_API
20 
21 #include "unicode/uobject.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 
46 
52 
58 
64 
70 
76 
82 
83 #ifndef U_HIDE_DEPRECATED_API
89 #endif // U_HIDE_DEPRECATED_API
91 
96 typedef enum UDateAbsoluteUnit {
97 
98  // Days of week have to remain together and in order from Sunday to
99  // Saturday.
105 
111 
117 
123 
129 
135 
141 
147 
153 
159 
165 
171 
177 
183 
189 
190 #ifndef U_HIDE_DEPRECATED_API
196 #endif // U_HIDE_DEPRECATED_API
198 
204 typedef enum UDateDirection {
205 
211 
217 
223 
229 
235 
241 
242 #ifndef U_HIDE_DEPRECATED_API
248 #endif // U_HIDE_DEPRECATED_API
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 
273  public:
278  FormattedRelativeDateTime() : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
279 
285 
290  virtual ~FormattedRelativeDateTime() override;
291 
294 
297 
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 
397 public:
398 
404 
409  RelativeDateTimeFormatter(const Locale& locale, UErrorCode& status);
410 
422  const Locale& locale, NumberFormat *nfToAdopt, UErrorCode& status);
423 
440  const Locale& locale,
441  NumberFormat *nfToAdopt,
443  UDisplayContext capitalizationContext,
444  UErrorCode& status);
445 
451 
457  const RelativeDateTimeFormatter& other);
458 
464 
485  double quantity,
486  UDateDirection direction,
487  UDateRelativeUnit unit,
488  UnicodeString& appendTo,
489  UErrorCode& status) const;
490 
509  double quantity,
510  UDateDirection direction,
511  UDateRelativeUnit unit,
512  UErrorCode& status) const;
513 
531  UDateDirection direction,
532  UDateAbsoluteUnit unit,
533  UnicodeString& appendTo,
534  UErrorCode& status) const;
535 
552  UDateDirection direction,
553  UDateAbsoluteUnit unit,
554  UErrorCode& status) const;
555 
577  double offset,