ICU 69.1 69.1

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
19 #if U_SHOW_CPLUSPLUS_API
20
26 #if !UCONFIG_NO_FORMATTING
27
28 #include "unicode/ucal.h"
29 #include "unicode/smpdtfmt.h"
30 #include "unicode/dtintrv.h"
31 #include "unicode/dtitvinf.h"
32 #include "unicode/dtptngen.h"
33 #include "unicode/formattedvalue.h"
34 #include "unicode/udisplaycontext.h"
35
36 U_NAMESPACE_BEGIN
37
38
39 class FormattedDateIntervalData;
40 class DateIntervalFormat;
41
59 class U_I18N_API FormattedDateInterval : public UMemory, public FormattedValue {
60 public:
65 FormattedDateInterval() : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
66
71 FormattedDateInterval(FormattedDateInterval&& src) U_NOEXCEPT;
72
77 virtual ~FormattedDateInterval() U_OVERRIDE;
78
80 FormattedDateInterval(const FormattedDateInterval&) = delete;
81
83 FormattedDateInterval& operator=(const FormattedDateInterval&) = delete;
84
89 FormattedDateInterval& operator=(FormattedDateInterval&& src) U_NOEXCEPT;
90
92 UnicodeString toString(UErrorCode& status) const U_OVERRIDE;
93
95 UnicodeString toTempString(UErrorCode& status) const U_OVERRIDE;
96
98 Appendable &appendTo(Appendable& appendable, UErrorCode& status) const U_OVERRIDE;
99
101 UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const U_OVERRIDE;
102
103 private:
104 FormattedDateIntervalData *fData;
105 UErrorCode fErrorCode;
106 explicit FormattedDateInterval(FormattedDateIntervalData *results)
107 : fData(results), fErrorCode(U_ZERO_ERROR) {}
108 explicit FormattedDateInterval(UErrorCode errorCode)
109 : fData(nullptr), fErrorCode(errorCode) {}
110 friend class DateIntervalFormat;
111 };
112
113
300 class U_I18N_API DateIntervalFormat : public Format {
301 public:
302
316 static DateIntervalFormat* U_EXPORT2 createInstance(
317 const UnicodeString& skeleton,
318 UErrorCode& status);
319
354 static DateIntervalFormat* U_EXPORT2 createInstance(
355 const UnicodeString& skeleton,
356 const Locale& locale,
357 UErrorCode& status);
358
374 static DateIntervalFormat* U_EXPORT2 createInstance(
375 const UnicodeString& skeleton,
376 const DateIntervalInfo& dtitvinf,
377 UErrorCode& status);
378
419 static DateIntervalFormat* U_EXPORT2 createInstance(
420 const UnicodeString& skeleton,
421 const Locale& locale,
422 const DateIntervalInfo& dtitvinf,
423 UErrorCode& status);
424
429 virtual ~DateIntervalFormat();
430
437 virtual DateIntervalFormat* clone() const;
438
446 virtual UBool operator==(const Format& other) const;
447
455 UBool operator!=(const Format& other) const;
456
457
458 using Format::format;
459
479 virtual UnicodeString& format(const Formattable& obj,
480 UnicodeString& appendTo,
481 FieldPosition& fieldPosition,
482 UErrorCode& status) const ;
483
484
485
501 UnicodeString& format(const DateInterval* dtInterval,
502 UnicodeString& appendTo,
503 FieldPosition& fieldPosition,
504 UErrorCode& status) const ;
505
516 FormattedDateInterval formatToValue(
517 const DateInterval& dtInterval,
518 UErrorCode& status) const;
519
543 UnicodeString& format(Calendar& fromCalendar,
544 Calendar& toCalendar,
545 UnicodeString& appendTo,
546 FieldPosition& fieldPosition,
547 UErrorCode& status) const ;
548
565 FormattedDateInterval formatToValue(
566 Calendar& fromCalendar,
567 Calendar& toCalendar,
568 UErrorCode& status) const;
569
596 virtual void parseObject(const UnicodeString& source,
597 Formattable& result,
598 ParsePosition& parse_pos) const;
599
600
607 const DateIntervalInfo* getDateIntervalInfo(void) const;
608
609
616 void setDateIntervalInfo(const DateIntervalInfo& newIntervalPatterns,
617 UErrorCode& status);
618
619
631 const DateFormat* getDateFormat(void) const;
632
638 virtual const TimeZone& getTimeZone(void) const;
639
646 virtual void adoptTimeZone(TimeZone* zoneToAdopt);
647
653 virtual void setTimeZone(const TimeZone& zone);
654
655 #ifndef U_FORCE_HIDE_DRAFT_API
656
668 virtual void setContext(UDisplayContext value, UErrorCode& status);
669
680 virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const;
681 #endif // U_FORCE_HIDE_DRAFT_API
682
694 static UClassID U_EXPORT2 getStaticClassID(void);
695
707 virtual UClassID getDynamicClassID(void) const;
708
709 protected:
710
715 DateIntervalFormat(const DateIntervalFormat&);
716
721 DateIntervalFormat& operator=(const DateIntervalFormat&);
722
723 private:
724
725 /*
726 * This is for ICU internal use only. Please do not use.
727 * Save the interval pattern information.
728 * Interval pattern consists of 2 single date patterns and the separator.
729 * For example, interval pattern "MMM d - MMM d, yyyy" consists
730 * a single date pattern "MMM d", another single date pattern "MMM d, yyyy",
731 * and a separator "-".
732 * The pattern is divided into 2 parts. For above example,
733 * the first part is "MMM d - ", and the second part is "MMM d, yyyy".
734 * Also, the first date appears in an interval pattern could be
735 * the earlier date or the later date.
736 * And such information is saved in the interval pattern as well.
737 */
738 struct PatternInfo {
739 UnicodeString firstPart;
740 UnicodeString secondPart;
754 UBool laterDateFirst;
755 };
756
757
762 DateIntervalFormat();
763
782 DateIntervalFormat(const Locale& locale, DateIntervalInfo* dtItvInfo,
783 const UnicodeString* skeleton, UErrorCode& status);
784
785
798 static DateIntervalFormat* U_EXPORT2 create(const Locale& locale,
799 DateIntervalInfo* dtitvinf,
800 const UnicodeString* skeleton,
801 UErrorCode& status);
802
808 void fallbackFormatRange(
809 Calendar& fromCalendar,
810 Calendar& toCalendar,
811 UnicodeString& appendTo,
812 int8_t& firstIndex,
813 FieldPositionHandler& fphandler,
814 UErrorCode& status) const;
815
838 UnicodeString& fallbackFormat(Calendar& fromCalendar,
839 Calendar& toCalendar,
840 UBool fromToOnSameDay,
841 UnicodeString& appendTo,
842 int8_t& firstIndex,
843 FieldPositionHandler& fphandler,
844 UErrorCode& status) const;
845
846
847
882 void initializePattern(UErrorCode& status);
883
884
885
893 void setFallbackPattern(UCalendarDateFields field,
894 const UnicodeString& skeleton,
895 UErrorCode& status);
896
897
898
908 UnicodeString normalizeHourMetacharacters(const UnicodeString& skeleton) const;
909
910
911
936 static void U_EXPORT2 getDateTimeSkeleton(const UnicodeString& skeleton,
937 UnicodeString& date,
938 UnicodeString& normalizedDate,
939 UnicodeString& time,
940 UnicodeString& normalizedTime);
941
942
943
967 UBool setSeparateDateTimePtn(const UnicodeString& dateSkeleton,
968 const UnicodeString& timeSkeleton);
969
970
971
972
996 UBool setIntervalPattern(UCalendarDateFields field,
997 const UnicodeString* skeleton,
998 const UnicodeString* bestSkeleton,
999 int8_t differenceInfo,
1000 UnicodeString* extendedSkeleton = NULL,
1001 UnicodeString* extendedBestSkeleton = NULL);
1002
1032 static void U_EXPORT2 adjustFieldWidth(
1033 const UnicodeString& inputSkeleton,
1034 const UnicodeString& bestMatchSkeleton,
1035 const UnicodeString& bestMatchIntervalPattern,
1036 int8_t differenceInfo,
1037 UBool suppressDayPeriodField,
1038 UnicodeString& adjustedIntervalPattern);
1039
1047 static void U_EXPORT2 findReplaceInPattern(UnicodeString& targetString,
1048 const UnicodeString& strToReplace,
1049 const UnicodeString& strToReplaceWith);
1050
1062 void concatSingleDate2TimeInterval(UnicodeString& format,
1063 const UnicodeString& datePattern,
1064 UCalendarDateFields field,
1065 UErrorCode& status);
1066
1073 static UBool U_EXPORT2 fieldExistsInSkeleton(UCalendarDateFields field,
1074 const UnicodeString& skeleton);
1075
1076
1082 static int32_t U_EXPORT2 splitPatternInto2Part(const UnicodeString& intervalPattern);
1083
1084
1090 void setIntervalPattern(UCalendarDateFields field,
1091 const UnicodeString& intervalPattern);
1092
1093
1100 void setIntervalPattern(UCalendarDateFields field,
1101 const UnicodeString& intervalPattern,
1102 UBool laterDateFirst);
1103
1104
1114 void setPatternInfo(UCalendarDateFields field,
1115 const UnicodeString* firstPart,
1116 const UnicodeString* secondPart,
1117 UBool laterDateFirst);
1118
1144 UnicodeString& formatImpl(Calendar& fromCalendar,
1145 Calendar& toCalendar,
1146 UnicodeString& appendTo,
1147 int8_t& firstIndex,
1148 FieldPositionHandler& fphandler,
1149 UErrorCode& status) const ;
1150
1152 UnicodeString& formatIntervalImpl(const DateInterval& dtInterval,
1153 UnicodeString& appendTo,
1154 int8_t& firstIndex,
1155 FieldPositionHandler& fphandler,
1156 UErrorCode& status) const;
1157
1158
1159 // from calendar field to pattern letter
1160 static const char16_t fgCalendarFieldToPatternLetter[];
1161
1162
1166 DateIntervalInfo* fInfo;
1167
1171 SimpleDateFormat* fDateFormat;
1172
1178 Calendar* fFromCalendar;
1179 Calendar* fToCalendar;
1180
1181 Locale fLocale;
1182
1186 UnicodeString fSkeleton;
1187 PatternInfo fIntervalPatterns[DateIntervalInfo::kIPI_MAX_INDEX];
1188
1192 UnicodeString* fDatePattern;
1193 UnicodeString* fTimePattern;
1194 UnicodeString* fDateTimeFormat;
1195
1199 UDisplayContext fCapitalizationContext;
1200 };
1201
1202 inline UBool
1203 DateIntervalFormat::operator!=(const Format& other) const {
1204 return !operator==(other);
1205 }
1206
1207 U_NAMESPACE_END
1208
1209 #endif /* #if !UCONFIG_NO_FORMATTING */
1210
1211 #endif /* U_SHOW_CPLUSPLUS_API */
1212
1213 #endif // _DTITVFMT_H__
1214 //eof
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:110
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::DateFormat
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:156
U_I18N_API
#define U_I18N_API
Definition: utypes.h:301
icu::Calendar
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:189
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
icu::Format::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
U_NOEXCEPT
#define U_NOEXCEPT
Definition: platform.h:529
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:64
icu::FormattedValue
An abstract formatted value: a string with associated field attributes.
Definition: formattedvalue.h:241
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
U_OVERRIDE
#define U_OVERRIDE
Definition: umachine.h:130
icu::Format::operator!=
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:123
icu::DateIntervalInfo
DateIntervalInfo is a public class for encapsulating localizable date time interval patterns.
Definition: dtitvinf.h:154
icu::Format::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
icu::SimpleDateFormat
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition: smpdtfmt.h:726
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:133
icu::DateInterval
This class represents a date interval.
Definition: dtintrv.h:36
UDisplayContextType
UDisplayContextType
Display context types, for getting values of a particular setting.
Definition: udisplaycontext.h:27
NULL
#define NULL
Definition: utypes.h:188
icu::FormattedDateInterval
An immutable class containing the result of a date interval formatting operation.
Definition: dtitvfmt.h:59
icu::Format
Base class for all formats.
Definition: format.h:98
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
dtptngen.h
C++ API: Date/Time Pattern Generator.
icu::Format::operator=
Format & operator=(const Format &)
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
ucal.h
C API: Calendar.
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:115
icu::operator!=
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:335
icu::FormattedDateInterval::FormattedDateInterval
FormattedDateInterval()
Default constructor; makes an empty FormattedDateInterval.
Definition: dtitvfmt.h:65
U_ZERO_ERROR
@ U_ZERO_ERROR
No error, no warning.
Definition: utypes.h:449
formattedvalue.h
C++ API: Abstract operations for localized strings.
icu::Appendable
Base class for objects to which Unicode characters and strings can be appended.
Definition: appendable.h:54
UDisplayContext
UDisplayContext
Display context settings.
Definition: udisplaycontext.h:64
UCalendarDateFields
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:202
udisplaycontext.h
C API: Display context types (enum values)
dtintrv.h
C++ API: Date Interval data type.
smpdtfmt.h
C++ API: Format and parse dates in a language-independent manner.
U_INVALID_STATE_ERROR
@ U_INVALID_STATE_ERROR
Requested operation can not be completed with ICU in its current state.
Definition: utypes.h:478
icu::Format::operator==
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:52
dtitvinf.h
C++ API: Date/Time interval patterns for formatting date/time interval.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::DateIntervalFormat
DateIntervalFormat is a class for formatting and parsing date intervals in a language-independent man...
Definition: dtitvfmt.h:300
icu::ConstrainedFieldPosition
Represents a span of a string containing a given field.
Definition: formattedvalue.h:41