ICU 64.2  64.2
dtitvfmt.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 * Copyright (C) 2008-2016, International Business Machines Corporation and
5 * others. All Rights Reserved.
6 *******************************************************************************
7 *
8 * File DTITVFMT.H
9 *
10 *******************************************************************************
11 */
12 
13 #ifndef __DTITVFMT_H__
14 #define __DTITVFMT_H__
15 
16 
17 #include "unicode/utypes.h"
18 
24 #if !UCONFIG_NO_FORMATTING
25 
26 #include "unicode/ucal.h"
27 #include "unicode/smpdtfmt.h"
28 #include "unicode/dtintrv.h"
29 #include "unicode/dtitvinf.h"
30 #include "unicode/dtptngen.h"
31 #include "unicode/formattedvalue.h"
32 
34 
35 
36 class FormattedDateIntervalData;
37 class DateIntervalFormat;
38 
39 #ifndef U_HIDE_DRAFT_API
40 
58  public:
63  FormattedDateInterval() : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
64 
70 
76 
79 
81  FormattedDateInterval& operator=(const FormattedDateInterval&) = delete;
82 
88 
91 
94 
96  Appendable &appendTo(Appendable& appendable, UErrorCode& status) const U_OVERRIDE;
97 
100 
101  private:
102  FormattedDateIntervalData *fData;
103  UErrorCode fErrorCode;
104  explicit FormattedDateInterval(FormattedDateIntervalData *results)
105  : fData(results), fErrorCode(U_ZERO_ERROR) {}
106  explicit FormattedDateInterval(UErrorCode errorCode)
107  : fData(nullptr), fErrorCode(errorCode) {}
108  friend class DateIntervalFormat;
109 };
110 #endif /* U_HIDE_DRAFT_API */
111 
112 
299 public:
300 
314  static DateIntervalFormat* U_EXPORT2 createInstance(
315  const UnicodeString& skeleton,
316  UErrorCode& status);
317 
352  static DateIntervalFormat* U_EXPORT2 createInstance(
353  const UnicodeString& skeleton,
354  const Locale& locale,
355  UErrorCode& status);
356 
372  static DateIntervalFormat* U_EXPORT2 createInstance(
373  const UnicodeString& skeleton,
374  const DateIntervalInfo& dtitvinf,
375  UErrorCode& status);
376 
417  static DateIntervalFormat* U_EXPORT2 createInstance(
418  const UnicodeString& skeleton,
419  const Locale& locale,
420  const DateIntervalInfo& dtitvinf,
421  UErrorCode& status);
422 
427  virtual ~DateIntervalFormat();
428 
435  virtual Format* clone(void) const;
436 
444  virtual UBool operator==(const Format& other) const;
445 
453  UBool operator!=(const Format& other) const;
454 
455 
456  using Format::format;
457 
477  virtual UnicodeString& format(const Formattable& obj,
478  UnicodeString& appendTo,
479  FieldPosition& fieldPosition,
480  UErrorCode& status) const ;
481 
482 
483 
499  UnicodeString& format(const DateInterval* dtInterval,
500  UnicodeString& appendTo,
501  FieldPosition& fieldPosition,
502  UErrorCode& status) const ;
503 
504 #ifndef U_HIDE_DRAFT_API
505 
515  FormattedDateInterval formatToValue(
516  const DateInterval& dtInterval,
517  UErrorCode& status) const;
518 #endif /* U_HIDE_DRAFT_API */
519 
543  UnicodeString& format(Calendar& fromCalendar,
544  Calendar& toCalendar,
545  UnicodeString& appendTo,
546  FieldPosition& fieldPosition,
547  UErrorCode& status) const ;
548 
549 #ifndef U_HIDE_DRAFT_API
550 
566  FormattedDateInterval formatToValue(
567  Calendar& fromCalendar,
568  Calendar& toCalendar,
569  UErrorCode& status) const;
570 #endif /* U_HIDE_DRAFT_API */
571 
598  virtual void parseObject(const UnicodeString& source,
599  Formattable& result,
600  ParsePosition& parse_pos) const;
601 
602 
609  const DateIntervalInfo* getDateIntervalInfo(void) const;
610 
611 
618  void setDateIntervalInfo(const DateIntervalInfo& newIntervalPatterns,
619  UErrorCode& status);
620 
621 
633  const DateFormat* getDateFormat(void) const;
634 
640  virtual const TimeZone& getTimeZone(void) const;
641 
648  virtual void adoptTimeZone(TimeZone* zoneToAdopt);
649 
655  virtual void setTimeZone(const TimeZone& zone);
656 
668  static UClassID U_EXPORT2 getStaticClassID(void);
669 
681  virtual UClassID getDynamicClassID(void) const;
682 
683 protected:
684 
690 
696 
697 private:
698 
699  /*
700  * This is for ICU internal use only. Please do not use.
701  * Save the interval pattern information.
702  * Interval pattern consists of 2 single date patterns and the separator.
703  * For example, interval pattern "MMM d - MMM d, yyyy" consists
704  * a single date pattern "MMM d", another single date pattern "MMM d, yyyy",
705  * and a separator "-".
706  * The pattern is divided into 2 parts. For above example,
707  * the first part is "MMM d - ", and the second part is "MMM d, yyyy".
708  * Also, the first date appears in an interval pattern could be
709  * the earlier date or the later date.
710  * And such information is saved in the interval pattern as well.
711  */
712  struct PatternInfo {
713  UnicodeString firstPart;
714  UnicodeString secondPart;
728  UBool laterDateFirst;
729  };
730 
731 
737 
756  DateIntervalFormat(const Locale& locale, DateIntervalInfo* dtItvInfo,
757  const UnicodeString* skeleton, UErrorCode& status);
758 
759 
772  static DateIntervalFormat* U_EXPORT2 create(const Locale& locale,
773  DateIntervalInfo* dtitvinf,
774  const UnicodeString* skeleton,
775  UErrorCode& status);
776 
782  void fallbackFormatRange(
783  Calendar& fromCalendar,
784  Calendar& toCalendar,
785  UnicodeString& appendTo,
786  int8_t& firstIndex,
787  FieldPositionHandler& fphandler,
788  UErrorCode& status) const;
789 
812  UnicodeString& fallbackFormat(Calendar& fromCalendar,
813  Calendar& toCalendar,
814  UBool fromToOnSameDay,
815  UnicodeString& appendTo,
816  int8_t& firstIndex,
817  FieldPositionHandler& fphandler,
818  UErrorCode& status) const;
819 
820 
821 
856  void initializePattern(UErrorCode& status);
857 
858 
859 
867  void setFallbackPattern(UCalendarDateFields field,
868  const UnicodeString& skeleton,
869  UErrorCode& status);
870 
871 
872 
897  static void U_EXPORT2 getDateTimeSkeleton(const UnicodeString& skeleton,
898  UnicodeString& date,
899  UnicodeString& normalizedDate,
900  UnicodeString& time,
901  UnicodeString& normalizedTime);
902 
903 
904 
928  UBool setSeparateDateTimePtn(const UnicodeString& dateSkeleton,
929  const UnicodeString& timeSkeleton);
930 
931 
932 
933 
957  UBool setIntervalPattern(UCalendarDateFields field,
958  const UnicodeString* skeleton,
959  const UnicodeString* bestSkeleton,
960  int8_t differenceInfo,
961  UnicodeString* extendedSkeleton = NULL,
962  UnicodeString* extendedBestSkeleton = NULL);
963 
992  static void U_EXPORT2 adjustFieldWidth(
993  const UnicodeString& inputSkeleton,
994  const UnicodeString& bestMatchSkeleton,
995  const UnicodeString& bestMatchIntervalPattern,
996  int8_t differenceInfo,
997  UnicodeString& adjustedIntervalPattern);
998 
1010  void concatSingleDate2TimeInterval(UnicodeString& format,
1011  const UnicodeString& datePattern,
1012  UCalendarDateFields field,
1013  UErrorCode& status);
1014 
1021  static UBool U_EXPORT2 fieldExistsInSkeleton(UCalendarDateFields field,
1022  const UnicodeString& skeleton);
1023 
1024 
1030  static int32_t U_EXPORT2 splitPatternInto2Part(const UnicodeString& intervalPattern);
1031 
1032 
1038  void setIntervalPattern(UCalendarDateFields field,
1039  const UnicodeString& intervalPattern);
1040 
1041 
1048  void setIntervalPattern(UCalendarDateFields field,
1049  const UnicodeString& intervalPattern,
1050  UBool laterDateFirst);
1051 
1052 
1062  void setPatternInfo(UCalendarDateFields field,
1063  const UnicodeString* firstPart,
1064  const UnicodeString* secondPart,
1065  UBool laterDateFirst);
1066 
1092  UnicodeString& formatImpl(Calendar& fromCalendar,
1093  Calendar& toCalendar,
1094  UnicodeString& appendTo,
1095  int8_t& firstIndex,
1096  FieldPositionHandler& fphandler,
1097  UErrorCode& status) const ;
1098 
1100  UnicodeString& formatIntervalImpl(const DateInterval& dtInterval,
1101  UnicodeString& appendTo,
1102  int8_t& firstIndex,
1103  FieldPositionHandler& fphandler,
1104  UErrorCode& status) const;
1105 
1106 
1107  // from calendar field to pattern letter
1108  static const char16_t fgCalendarFieldToPatternLetter[];
1109 
1110 
1114  DateIntervalInfo* fInfo;
1115 
1119  SimpleDateFormat* fDateFormat;
1120 
1126  Calendar* fFromCalendar;
1127  Calendar* fToCalendar;
1128 
1129  Locale fLocale;
1130 
1134  UnicodeString fSkeleton;
1135  PatternInfo fIntervalPatterns[DateIntervalInfo::kIPI_MAX_INDEX];
1136 
1140  UnicodeString* fDatePattern;
1141  UnicodeString* fTimePattern;
1142  UnicodeString* fDateTimeFormat;
1143 };
1144 
1145 inline UBool
1147  return !operator==(other);
1148 }
1149 
1151 
1152 #endif /* #if !UCONFIG_NO_FORMATTING */
1153 
1154 #endif // _DTITVFMT_H__
1155 //eof
C++ API: Abstract operations for localized strings.
Base class for all formats.
Definition: format.h:96
virtual UBool nextPosition(ConstrainedFieldPosition &cfpos, UErrorCode &status) const =0
Iterates over field positions in the FormattedValue.
#define U_OVERRIDE
Defined to the C++11 "override" keyword if available.
Definition: umachine.h:129
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:199
DateIntervalFormat is a class for formatting and parsing date intervals in a language-independent man...
Definition: dtitvfmt.h:298
virtual UnicodeString toString(UErrorCode &status) const =0
Returns the formatted string as a self-contained UnicodeString.
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:121
C API: Calendar.
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
C++ API: Date/Time Pattern Generator.
DateIntervalInfo is a public class for encapsulating localizable date time interval patterns...
Definition: dtitvinf.h:152
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:185
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:93
virtual Format * clone() const =0
Clone this object polymorphically.
No error, no warning.
Definition: utypes.h:435
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:131
An abstract formatted value: a string with associated field attributes.
This class represents a date interval.
Definition: dtintrv.h:34
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
C++ API: Format and parse dates in a language-independent manner.
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
Definition: utypes.h:188
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
Represents a span of a string containing a given field.
#define U_NOEXCEPT
"noexcept" if supported, otherwise empty.
Definition: platform.h:503
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
C++ API: Date Interval data type.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition: smpdtfmt.h:724
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:108
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:49
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:154
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
An immutable class containing the result of a date interval formatting operation. ...
Definition: dtitvfmt.h:57
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
Basic definitions for ICU, for both C and C++ APIs.
C++ API: Date/Time interval patterns for formatting date/time interval.
Format & operator=(const Format &)
virtual Appendable & appendTo(Appendable &appendable, UErrorCode &status) const =0
Appends the formatted string to an Appendable.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
FormattedDateInterval()
Default constructor; makes an empty FormattedDateInterval.
Definition: dtitvfmt.h:63
UMemory is the common ICU base class.
Definition: uobject.h:112
Requested operation can not be completed with ICU in its current state.
Definition: utypes.h:464
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
Base class for objects to which Unicode characters and strings can be appended.
Definition: appendable.h:51
virtual UnicodeString toTempString(UErrorCode &status) const =0
Returns the formatted string as a read-only alias to memory owned by the FormattedValue.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192