ICU4C 79
Loading...
Searching...
No Matches
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
25
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"
35
36U_NAMESPACE_BEGIN
37
38
39class FormattedDateIntervalData;
40class DateIntervalFormat;
41
60 public:
65 FormattedDateInterval() : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
66
72
77 virtual ~FormattedDateInterval() override;
78
81
84
90
92 UnicodeString toString(UErrorCode& status) const override;
93
95 UnicodeString toTempString(UErrorCode& status) const override;
96
98 Appendable &appendTo(Appendable& appendable, UErrorCode& status) const override;
99
101 UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const 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
301public:
302
317 UErrorCode& status);
318
347
349 const Locale& locale,
350 UErrorCode& status);
351
368 const DateIntervalInfo& dtitvinf,
369 UErrorCode& status);
370
407 const Locale& locale,
408 const DateIntervalInfo& dtitvinf,
409 UErrorCode& status);
410
416
423 U_I18N_API virtual DateIntervalFormat* clone() const override;
424
432 U_I18N_API virtual bool operator==(const Format& other) const override;
433
441 U_I18N_API bool operator!=(const Format& other) const;
442
443 using Format::format;
444
465 UnicodeString& appendTo,
466 FieldPosition& fieldPosition,
467 UErrorCode& status) const override;
468
485 UnicodeString& appendTo,
486 FieldPosition& fieldPosition,
487 UErrorCode& status) const;
488
500 UErrorCode& status) const;
501
526 Calendar& toCalendar,
527 UnicodeString& appendTo,
528 FieldPosition& fieldPosition,
529 UErrorCode& status) const;
530
548 Calendar& toCalendar,
549 UErrorCode& status) const;
550
574 U_I18N_API virtual void parseObject(const UnicodeString& source,
575 Formattable& result,
576 ParsePosition& parse_pos) const override;
577
585
592 U_I18N_API void setDateIntervalInfo(const DateIntervalInfo& newIntervalPatterns, UErrorCode& status);
593
606
612 U_I18N_API virtual const TimeZone& getTimeZone() const;
613
620 U_I18N_API virtual void adoptTimeZone(TimeZone* zoneToAdopt);
621
627 U_I18N_API virtual void setTimeZone(const TimeZone& zone);
628
641 U_I18N_API virtual void setContext(UDisplayContext value, UErrorCode& status);
642
654
667
679 U_I18N_API virtual UClassID getDynamicClassID() const override;
680
681protected:
682
688
694
695private:
696
697 /*
698 * This is for ICU internal use only. Please do not use.
699 * Save the interval pattern information.
700 * Interval pattern consists of 2 single date patterns and the separator.
701 * For example, interval pattern "MMM d - MMM d, yyyy" consists
702 * a single date pattern "MMM d", another single date pattern "MMM d, yyyy",
703 * and a separator "-".
704 * The pattern is divided into 2 parts. For above example,
705 * the first part is "MMM d - ", and the second part is "MMM d, yyyy".
706 * Also, the first date appears in an interval pattern could be
707 * the earlier date or the later date.
708 * And such information is saved in the interval pattern as well.
709 */
710 struct PatternInfo {
711 UnicodeString firstPart;
712 UnicodeString secondPart;
726 UBool laterDateFirst;
727 };
728
729
734
753 DateIntervalFormat(const Locale& locale, DateIntervalInfo* dtItvInfo,
754 const UnicodeString* skeleton, UErrorCode& status);
755
756
769 U_I18N_API static DateIntervalFormat* create(const Locale& locale,
770 DateIntervalInfo* dtitvinf,
771 const UnicodeString* skeleton,
772 UErrorCode& status);
773
777
779 void fallbackFormatRange(
780 Calendar& fromCalendar,
781 Calendar& toCalendar,
782 UnicodeString& appendTo,
783 int8_t& firstIndex,
784 FieldPositionHandler& fphandler,
785 UErrorCode& status) const;
786
808 UnicodeString& fallbackFormat(Calendar& fromCalendar,
809 Calendar& toCalendar,
810 UBool fromToOnSameDay,
811 UnicodeString& appendTo,
812 int8_t& firstIndex,
813 FieldPositionHandler& fphandler,
814 UErrorCode& status) const;
815
816
817
852 void initializePattern(UErrorCode& status);
853
854
855
863 void setFallbackPattern(UCalendarDateFields field,
864 const UnicodeString& skeleton,
865 UErrorCode& status);
866
867
868
878 UnicodeString normalizeHourMetacharacters(const UnicodeString& skeleton) const;
879
880
881
906 U_I18N_API static void getDateTimeSkeleton(const UnicodeString& skeleton,
907 UnicodeString& date,
908 UnicodeString& normalizedDate,
909 UnicodeString& time,
910 UnicodeString& normalizedTime);
911
935 UBool setSeparateDateTimePtn(const UnicodeString& dateSkeleton,
936 const UnicodeString& timeSkeleton);
937
938
939
940
964 UBool setIntervalPattern(UCalendarDateFields field,
965 const UnicodeString* skeleton,
966 const UnicodeString* bestSkeleton,
967 int8_t differenceInfo,
968 UnicodeString* extendedSkeleton = nullptr,
969 UnicodeString* extendedBestSkeleton = nullptr);
970
1000 U_I18N_API static void adjustFieldWidth(const UnicodeString& inputSkeleton,
1001 const UnicodeString& bestMatchSkeleton,
1002 const UnicodeString& bestMatchIntervalPattern,
1003 int8_t differenceInfo,
1004 UBool suppressDayPeriodField,
1005 UnicodeString& adjustedIntervalPattern);
1006
1014 U_I18N_API static void findReplaceInPattern(UnicodeString& targetString,
1015 const UnicodeString& strToReplace,
1016 const UnicodeString& strToReplaceWith);
1017
1029 void concatSingleDate2TimeInterval(UnicodeString& format,
1030 const UnicodeString& datePattern,
1031 UCalendarDateFields field,
1032 UErrorCode& status);
1033
1040 U_I18N_API static UBool fieldExistsInSkeleton(UCalendarDateFields field,
1041 const UnicodeString& skeleton);
1042
1048 U_I18N_API static int32_t splitPatternInto2Part(const UnicodeString& intervalPattern);
1049
1055 void setIntervalPattern(UCalendarDateFields field,
1056 const UnicodeString& intervalPattern);
1057
1058
1065 void setIntervalPattern(UCalendarDateFields field,
1066 const UnicodeString& intervalPattern,
1067 UBool laterDateFirst);
1068
1069
1079 void setPatternInfo(UCalendarDateFields field,
1080 const UnicodeString* firstPart,
1081 const UnicodeString* secondPart,
1082 UBool laterDateFirst);
1083
1108 UnicodeString& formatImpl(Calendar& fromCalendar,
1109 Calendar& toCalendar,
1110 UnicodeString& appendTo,
1111 int8_t& firstIndex,
1112 FieldPositionHandler& fphandler,
1113 UErrorCode& status) const ;
1114
1116 UnicodeString& formatIntervalImpl(const DateInterval& dtInterval,
1117 UnicodeString& appendTo,
1118 int8_t& firstIndex,
1119 FieldPositionHandler& fphandler,
1120 UErrorCode& status) const;
1121
1122
1123 // from calendar field to pattern letter
1124 static const char16_t fgCalendarFieldToPatternLetter[];
1125
1126
1130 DateIntervalInfo* fInfo;
1131
1135 SimpleDateFormat* fDateFormat;
1136
1142 Calendar* fFromCalendar;
1143 Calendar* fToCalendar;
1144
1145 Locale fLocale;
1146
1150 UnicodeString fSkeleton;
1151 PatternInfo fIntervalPatterns[DateIntervalInfo::kIPI_MAX_INDEX];
1152
1156 UnicodeString* fDatePattern;
1157 UnicodeString* fTimePattern;
1158 UnicodeString* fDateTimeFormat;
1159
1163 UDisplayContext fCapitalizationContext;
1164};
1165
1166inline bool
1168 return !operator==(other);
1169}
1170
1171U_NAMESPACE_END
1172
1173#endif /* #if !UCONFIG_NO_FORMATTING */
1174
1175#endif /* U_SHOW_CPLUSPLUS_API */
1176
1177#endif // _DTITVFMT_H__
1178//eof
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition calendar.h:189
Represents a span of a string containing a given field.
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition datefmt.h:144
DateIntervalFormat is a class for formatting and parsing date intervals in a language-independent man...
Definition dtitvfmt.h:300
U_I18N_API bool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition dtitvfmt.h:1167
U_I18N_API void setDateIntervalInfo(const DateIntervalInfo &newIntervalPatterns, UErrorCode &status)
Set the date time interval patterns.
static U_I18N_API DateIntervalFormat * createInstance(const UnicodeString &skeleton, UErrorCode &status)
Construct a DateIntervalFormat from skeleton and the default locale.
virtual U_I18N_API DateIntervalFormat * clone() const override
Clone this Format object polymorphically.
static U_I18N_API DateIntervalFormat * createInstance(const UnicodeString &skeleton, const Locale &locale, const DateIntervalInfo &dtitvinf, UErrorCode &status)
Construct a DateIntervalFormat from skeleton a DateIntervalInfo, and the given locale.
static U_I18N_API UClassID getStaticClassID()
Return the class ID for this class.
U_I18N_API const DateIntervalInfo * getDateIntervalInfo() const
Gets the date time interval patterns.
U_I18N_API FormattedDateInterval formatToValue(Calendar &fromCalendar, Calendar &toCalendar, UErrorCode &status) const
Format 2 Calendars to produce a FormattedDateInterval.
virtual U_I18N_API bool operator==(const Format &other) const override
Return true if the given Format objects are semantically equal.
U_I18N_API UnicodeString & format(Calendar &fromCalendar, Calendar &toCalendar, UnicodeString &appendTo, FieldPosition &fieldPosition, UErrorCode &status) const
Format 2 Calendars to produce a string.
virtual U_I18N_API void setContext(UDisplayContext value, UErrorCode &status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
virtual U_I18N_API void setTimeZone(const TimeZone &zone)
Sets the time zone for the calendar used by this DateIntervalFormat object.
static U_I18N_API DateIntervalFormat * createInstance(const UnicodeString &skeleton, const Locale &locale, UErrorCode &status)
Construct a DateIntervalFormat from skeleton and a given locale.
virtual U_I18N_API UDisplayContext getContext(UDisplayContextType type, UErrorCode &status) const
Get the formatter's UDisplayContext value for the specified UDisplayContextType, such as UDISPCTX_TYP...
U_I18N_API UnicodeString & format(const DateInterval *dtInterval, UnicodeString &appendTo, FieldPosition &fieldPosition, UErrorCode &status) const
Format a DateInterval to produce a string.
U_I18N_API const DateFormat * getDateFormat() const
Gets the date formatter.
virtual U_I18N_API const TimeZone & getTimeZone() const
Returns a reference to the TimeZone used by this DateIntervalFormat's calendar.
virtual U_I18N_API void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const override
Date interval parsing is not supported.
DateIntervalFormat(const DateIntervalFormat &)
Copy constructor.
U_I18N_API FormattedDateInterval formatToValue(const DateInterval &dtInterval, UErrorCode &status) const
Format a DateInterval to produce a FormattedDateInterval.
virtual U_I18N_API void adoptTimeZone(TimeZone *zoneToAdopt)
Sets the time zone for the calendar used by this DateIntervalFormat object.
DateIntervalFormat & operator=(const DateIntervalFormat &)
Assignment operator.
virtual U_I18N_API UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &fieldPosition, UErrorCode &status) const override
Format an object to produce a string.
virtual U_I18N_API UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
virtual U_I18N_API ~DateIntervalFormat()
Destructor.
static U_I18N_API DateIntervalFormat * createInstance(const UnicodeString &skeleton, const DateIntervalInfo &dtitvinf, UErrorCode &status)
Construct a DateIntervalFormat from skeleton DateIntervalInfo, and default locale.
DateIntervalInfo is a public class for encapsulating localizable date time interval patterns.
Definition dtitvinf.h:154
This class represents a date interval.
Definition dtintrv.h:36
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:110
U_I18N_API bool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition format.h:123
U_I18N_API Format()
Default constructor for subclass use only.
U_I18N_API UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:63
An immutable class containing the result of a date interval formatting operation.
Definition dtitvfmt.h:59
FormattedDateInterval & operator=(FormattedDateInterval &&src) noexcept
Move assignment: Leaves the source FormattedDateInterval in an undefined state.
FormattedDateInterval(const FormattedDateInterval &)=delete
Copying not supported; use move constructor instead.
UBool nextPosition(ConstrainedFieldPosition &cfpos, UErrorCode &status) const override
Iterates over field positions in the FormattedValue.
virtual ~FormattedDateInterval() override
Destruct an instance of FormattedDateInterval.
FormattedDateInterval()
Default constructor; makes an empty FormattedDateInterval.
Definition dtitvfmt.h:65
UnicodeString toString(UErrorCode &status) const override
Returns the formatted string as a self-contained UnicodeString.
UnicodeString toTempString(UErrorCode &status) const override
Returns the formatted string as a read-only alias to memory owned by the FormattedValue.
Appendable & appendTo(Appendable &appendable, UErrorCode &status) const override
Appends the formatted string to an Appendable.
FormattedDateInterval & operator=(const FormattedDateInterval &)=delete
Copying not supported; use move assignment instead.
FormattedDateInterval(FormattedDateInterval &&src) noexcept
Move constructor: Leaves the source FormattedDateInterval in an undefined state.
An abstract formatted value: a string with associated field attributes.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:198
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:52
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition smpdtfmt.h:386
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition timezone.h:133
UMemory is the common ICU base class.
Definition uobject.h:115
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
C++ API: Date Interval data type.
C++ API: Date/Time interval patterns for formatting date/time interval.
C++ API: Date/Time Pattern Generator.
C++ API: Abstract operations for localized strings.
C++ API: Format and parse dates in a language-independent manner.
C API: Calendar.
UCalendarDateFields
Possible fields in a UCalendar.
Definition ucal.h:202
C API: Display context types (enum values).
UDisplayContextType
Display context types, for getting values of a particular setting.
UDisplayContext
Display context settings.
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509
@ U_INVALID_STATE_ERROR
Requested operation can not be completed with ICU in its current state.
Definition utypes.h:573
@ U_ZERO_ERROR
No error, no warning.
Definition utypes.h:544
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside,...
Definition utypes.h:457
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:316