ICU 65.1 65.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
35 U_NAMESPACE_BEGIN
36
37
38 class FormattedDateIntervalData;
39 class DateIntervalFormat;
40
41 #ifndef U_HIDE_DRAFT_API
42
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 #endif /* U_HIDE_DRAFT_API */
113
114
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
506 #ifndef U_HIDE_DRAFT_API
507
517 FormattedDateInterval formatToValue(
518 const DateInterval& dtInterval,
519 UErrorCode& status) const;
520 #endif /* U_HIDE_DRAFT_API */
521
545 UnicodeString& format(Calendar& fromCalendar,
546 Calendar& toCalendar,
547 UnicodeString& appendTo,
548 FieldPosition& fieldPosition,
549 UErrorCode& status) const ;
550
551 #ifndef U_HIDE_DRAFT_API
552
568 FormattedDateInterval formatToValue(
569 Calendar& fromCalendar,
570 Calendar& toCalendar,
571 UErrorCode& status) const;
572 #endif /* U_HIDE_DRAFT_API */
573
600 virtual void parseObject(const UnicodeString& source,
601 Formattable& result,
602 ParsePosition& parse_pos) const;
603
604
611 const DateIntervalInfo* getDateIntervalInfo(void) const;
612
613
620 void setDateIntervalInfo(const DateIntervalInfo& newIntervalPatterns,
621 UErrorCode& status);
622
623
635 const DateFormat* getDateFormat(void) const;
636
642 virtual const TimeZone& getTimeZone(void) const;
643
650 virtual void adoptTimeZone(TimeZone* zoneToAdopt);
651
657 virtual void setTimeZone(const TimeZone& zone);
658
670 static UClassID U_EXPORT2 getStaticClassID(void);
671
683 virtual UClassID getDynamicClassID(void) const;
684
685 protected:
686
691 DateIntervalFormat(const DateIntervalFormat&);
692
697 DateIntervalFormat& operator=(const DateIntervalFormat&);
698
699 private:
700
701 /*
702 * This is for ICU internal use only. Please do not use.
703 * Save the interval pattern information.
704 * Interval pattern consists of 2 single date patterns and the separator.
705 * For example, interval pattern "MMM d - MMM d, yyyy" consists
706 * a single date pattern "MMM d", another single date pattern "MMM d, yyyy",
707 * and a separator "-".
708 * The pattern is divided into 2 parts. For above example,
709 * the first part is "MMM d - ", and the second part is "MMM d, yyyy".
710 * Also, the first date appears in an interval pattern could be
711 * the earlier date or the later date.
712 * And such information is saved in the interval pattern as well.
713 */
714 struct PatternInfo {
715 UnicodeString firstPart;
716 UnicodeString secondPart;
730 UBool laterDateFirst;
731 };
732
733
738 DateIntervalFormat();
739
758 DateIntervalFormat(const Locale& locale, DateIntervalInfo* dtItvInfo,
759 const UnicodeString* skeleton, UErrorCode& status);
760
761
774 static DateIntervalFormat* U_EXPORT2 create(const Locale& locale,
775 DateIntervalInfo* dtitvinf,
776 const UnicodeString* skeleton,
777 UErrorCode& status);
778
784 void fallbackFormatRange(
785 Calendar& fromCalendar,
786 Calendar& toCalendar,
787 UnicodeString& appendTo,
788 int8_t& firstIndex,
789 FieldPositionHandler& fphandler,
790 UErrorCode& status) const;
791
814 UnicodeString& fallbackFormat(Calendar& fromCalendar,
815 Calendar& toCalendar,
816 UBool fromToOnSameDay,
817 UnicodeString& appendTo,
818 int8_t& firstIndex,
819 FieldPositionHandler& fphandler,
820 UErrorCode& status) const;
821
822
823
858 void initializePattern(UErrorCode& status);
859
860
861
869 void setFallbackPattern(UCalendarDateFields field,
870 const UnicodeString& skeleton,
871 UErrorCode& status);
872
873
874
899 static void U_EXPORT2 getDateTimeSkeleton(const UnicodeString& skeleton,
900 UnicodeString& date,
901 UnicodeString& normalizedDate,
902 UnicodeString& time,
903 UnicodeString& normalizedTime);
904
905
906
930 UBool setSeparateDateTimePtn(const UnicodeString& dateSkeleton,
931 const UnicodeString& timeSkeleton);
932
933
934
935
959 UBool setIntervalPattern(UCalendarDateFields field,
960 const UnicodeString* skeleton,
961 const UnicodeString* bestSkeleton,
962 int8_t differenceInfo,
963 UnicodeString* extendedSkeleton = NULL,
964 UnicodeString* extendedBestSkeleton = NULL);
965
994 static void U_EXPORT2 adjustFieldWidth(
995 const UnicodeString& inputSkeleton,
996 const UnicodeString& bestMatchSkeleton,
997 const UnicodeString& bestMatchIntervalPattern,
998 int8_t differenceInfo,
999 UnicodeString& adjustedIntervalPattern);
1000
1012 void concatSingleDate2TimeInterval(UnicodeString& format,
1013 const UnicodeString& datePattern,
1014 UCalendarDateFields field,
1015 UErrorCode& status);
1016
1023 static UBool U_EXPORT2 fieldExistsInSkeleton(UCalendarDateFields field,
1024 const UnicodeString& skeleton);
1025
1026
1032 static int32_t U_EXPORT2 splitPatternInto2Part(const UnicodeString& intervalPattern);
1033
1034
1040 void setIntervalPattern(UCalendarDateFields field,
1041 const UnicodeString& intervalPattern);
1042
1043
1050 void setIntervalPattern(UCalendarDateFields field,
1051 const UnicodeString& intervalPattern,
1052 UBool laterDateFirst);
1053
1054
1064 void setPatternInfo(UCalendarDateFields field,
1065 const UnicodeString* firstPart,
1066 const UnicodeString* secondPart,
1067 UBool laterDateFirst);
1068
1094 UnicodeString& formatImpl(Calendar& fromCalendar,
1095 Calendar& toCalendar,
1096 UnicodeString& appendTo,
1097 int8_t& firstIndex,
1098 FieldPositionHandler& fphandler,
1099 UErrorCode& status) const ;
1100
1102 UnicodeString& formatIntervalImpl(const DateInterval& dtInterval,
1103 UnicodeString& appendTo,
1104 int8_t& firstIndex,
1105 FieldPositionHandler& fphandler,
1106 UErrorCode& status) const;
1107
1108
1109 // from calendar field to pattern letter
1110 static const char16_t fgCalendarFieldToPatternLetter[];
1111
1112
1116 DateIntervalInfo* fInfo;
1117
1121 SimpleDateFormat* fDateFormat;
1122
1128 Calendar* fFromCalendar;
1129 Calendar* fToCalendar;
1130
1131 Locale fLocale;
1132
1136 UnicodeString fSkeleton;
1137 PatternInfo fIntervalPatterns[DateIntervalInfo::kIPI_MAX_INDEX];
1138
1142 UnicodeString* fDatePattern;
1143 UnicodeString* fTimePattern;
1144 UnicodeString* fDateTimeFormat;
1145 };
1146
1147 inline UBool
1148 DateIntervalFormat::operator!=(const Format& other) const {
1149 return !operator==(other);
1150 }
1151
1152 U_NAMESPACE_END
1153
1154 #endif /* #if !UCONFIG_NO_FORMATTING */
1155
1156 #endif /* U_SHOW_CPLUSPLUS_API */
1157
1158 #endif // _DTITVFMT_H__
1159 //eof
formattedvalue.h
C++ API: Abstract operations for localized strings.
icu::Format
Base class for all formats.
Definition: format.h:98
icu::FormattedValue::nextPosition
virtual UBool nextPosition(ConstrainedFieldPosition &cfpos, UErrorCode &status) const =0
Iterates over field positions in the FormattedValue.
U_OVERRIDE
#define U_OVERRIDE
Defined to the C++11 "override" keyword if available.
Definition: umachine.h:129
UCalendarDateFields
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:199
icu::DateIntervalFormat
DateIntervalFormat is a class for formatting and parsing date intervals in a language-independent man...
Definition: dtitvfmt.h:300
icu::FormattedValue::toString
virtual UnicodeString toString(UErrorCode &status) const =0
Returns the formatted string as a self-contained UnicodeString.
icu::Format::operator!=
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:123
ucal.h
C API: Calendar.
icu::Format::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
dtptngen.h
C++ API: Date/Time Pattern Generator.
icu::DateIntervalInfo
DateIntervalInfo is a public class for encapsulating localizable date time interval patterns...
Definition: dtitvinf.h:154
icu::Calendar
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:187
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:96
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
U_ZERO_ERROR
No error, no warning.
Definition: utypes.h:449
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:133
icu::FormattedValue
An abstract formatted value: a string with associated field attributes.
Definition: formattedvalue.h:254
icu::DateInterval
This class represents a date interval.
Definition: dtintrv.h:36
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
smpdtfmt.h
C++ API: Format and parse dates in a language-independent manner.
icu::operator!=
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:251
NULL
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
Definition: utypes.h:188
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
icu::ConstrainedFieldPosition
Represents a span of a string containing a given field.
Definition: formattedvalue.h:46
U_NOEXCEPT
#define U_NOEXCEPT
"noexcept" if supported, otherwise empty.
Definition: platform.h:529
dtintrv.h
C++ API: Date Interval data type.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
icu::SimpleDateFormat
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition: smpdtfmt.h:726
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:110
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:52
icu::DateFormat
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:156
icu::Format::operator==
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
icu::FormattedDateInterval
An immutable class containing the result of a date interval formatting operation. ...
Definition: dtitvfmt.h:59
icu::Format::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
dtitvinf.h
C++ API: Date/Time interval patterns for formatting date/time interval.
icu::Format::operator=
Format & operator=(const Format &)
icu::FormattedValue::appendTo
virtual Appendable & appendTo(Appendable &appendable, UErrorCode &status) const =0
Appends the formatted string to an Appendable.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:294
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:64
icu::FormattedDateInterval::FormattedDateInterval
FormattedDateInterval()
Default constructor; makes an empty FormattedDateInterval.
Definition: dtitvfmt.h:65
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:115
U_INVALID_STATE_ERROR
Requested operation can not be completed with ICU in its current state.
Definition: utypes.h:478
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261
icu::Appendable
Base class for objects to which Unicode characters and strings can be appended.
Definition: appendable.h:54
icu::FormattedValue::toTempString
virtual UnicodeString toTempString(UErrorCode &status) const =0
Returns the formatted string as a read-only alias to memory owned by the FormattedValue.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195