ICU 76.1 76.1
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
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:
66
72
77 virtual ~FormattedDateInterval() override;
78
81
84
90
93
96
99
102
103 private:
105 UErrorCode fErrorCode;
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 const UnicodeString& skeleton,
319
350 const UnicodeString& skeleton,
351 const Locale& locale,
353
370 const UnicodeString& skeleton,
373
410 const UnicodeString& skeleton,
411 const Locale& locale,
414
420
427 virtual DateIntervalFormat* clone() const override;
428
436 virtual bool operator==(const Format& other) const override;
437
445 bool operator!=(const Format& other) const;
446
447
448 using Format::format;
449
470 UnicodeString& appendTo,
472 UErrorCode& status) const override;
473
474
475
492 UnicodeString& appendTo,
494 UErrorCode& status) const ;
495
508 UErrorCode& status) const;
509
535 UnicodeString& appendTo,
537 UErrorCode& status) const ;
538
558 UErrorCode& status) const;
559
586 virtual void parseObject(const UnicodeString& source,
588 ParsePosition& parse_pos) const override;
589
590
598
607
608
620 const DateFormat* getDateFormat() const;
621
627 virtual const TimeZone& getTimeZone() const;
628
636
642 virtual void setTimeZone(const TimeZone& zone);
643
657
669
682
694 virtual UClassID getDynamicClassID() const override;
695
696protected:
697
703
709
710private:
711
712 /*
713 * This is for ICU internal use only. Please do not use.
714 * Save the interval pattern information.
715 * Interval pattern consists of 2 single date patterns and the separator.
716 * For example, interval pattern "MMM d - MMM d, yyyy" consists
717 * a single date pattern "MMM d", another single date pattern "MMM d, yyyy",
718 * and a separator "-".
719 * The pattern is divided into 2 parts. For above example,
720 * the first part is "MMM d - ", and the second part is "MMM d, yyyy".
721 * Also, the first date appears in an interval pattern could be
722 * the earlier date or the later date.
723 * And such information is saved in the interval pattern as well.
724 */
725 struct PatternInfo {
726 UnicodeString firstPart;
727 UnicodeString secondPart;
741 UBool laterDateFirst;
742 };
743
744
750
771
772
785 static DateIntervalFormat* U_EXPORT2 create(const Locale& locale,
787 const UnicodeString* skeleton,
789
795 void fallbackFormatRange(
798 UnicodeString& appendTo,
801 UErrorCode& status) const;
802
825 UnicodeString& fallbackFormat(Calendar& fromCalendar,
828 UnicodeString& appendTo,
831 UErrorCode& status) const;
832
833
834
869 void initializePattern(UErrorCode& status);
870
871
872
880 void setFallbackPattern(UCalendarDateFields field,
881 const UnicodeString& skeleton,
883
884
885
895 UnicodeString normalizeHourMetacharacters(const UnicodeString& skeleton) const;
896
897
898
923 static void U_EXPORT2 getDateTimeSkeleton(const UnicodeString& skeleton,
928
929
930
954 UBool setSeparateDateTimePtn(const UnicodeString& dateSkeleton,
956
957
958
959
983 UBool setIntervalPattern(UCalendarDateFields field,
984 const UnicodeString* skeleton,
989
1019 static void U_EXPORT2 adjustFieldWidth(
1026
1034 static void U_EXPORT2 findReplaceInPattern(UnicodeString& targetString,
1037
1049 void concatSingleDate2TimeInterval(UnicodeString& format,
1051 UCalendarDateFields field,
1053
1060 static UBool U_EXPORT2 fieldExistsInSkeleton(UCalendarDateFields field,
1061 const UnicodeString& skeleton);
1062
1063
1069 static int32_t U_EXPORT2 splitPatternInto2Part(const UnicodeString& intervalPattern);
1070
1071
1077 void setIntervalPattern(UCalendarDateFields field,
1079
1080
1087 void setIntervalPattern(UCalendarDateFields field,
1089 UBool laterDateFirst);
1090
1091
1101 void setPatternInfo(UCalendarDateFields field,
1102 const UnicodeString* firstPart,
1103 const UnicodeString* secondPart,
1104 UBool laterDateFirst);
1105
1131 UnicodeString& formatImpl(Calendar& fromCalendar,
1133 UnicodeString& appendTo,
1136 UErrorCode& status) const ;
1137
1139 UnicodeString& formatIntervalImpl(const DateInterval& dtInterval,
1140 UnicodeString& appendTo,
1143 UErrorCode& status) const;
1144
1145
1146 // from calendar field to pattern letter
1147 static const char16_t fgCalendarFieldToPatternLetter[];
1148
1149
1153 DateIntervalInfo* fInfo;
1154
1158 SimpleDateFormat* fDateFormat;
1159
1165 Calendar* fFromCalendar;
1166 Calendar* fToCalendar;
1167
1168 Locale fLocale;
1169
1173 UnicodeString fSkeleton;
1174 PatternInfo fIntervalPatterns[DateIntervalInfo::kIPI_MAX_INDEX];
1175
1179 UnicodeString* fDatePattern;
1180 UnicodeString* fTimePattern;
1181 UnicodeString* fDateTimeFormat;
1182
1186 UDisplayContext fCapitalizationContext;
1187};
1188
1189inline bool
1190DateIntervalFormat::operator!=(const Format& other) const {
1191 return !operator==(other);
1192}
1193
1195
1196#endif /* #if !UCONFIG_NO_FORMATTING */
1197
1198#endif /* U_SHOW_CPLUSPLUS_API */
1199
1200#endif // _DTITVFMT_H__
1201//eof
Base class for objects to which Unicode characters and strings can be appended.
Definition appendable.h:54
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:156
DateIntervalFormat is a class for formatting and parsing date intervals in a language-independent man...
Definition dtitvfmt.h:300
virtual void setTimeZone(const TimeZone &zone)
Sets the time zone for the calendar used by this DateIntervalFormat object.
UnicodeString & format(Calendar &fromCalendar, Calendar &toCalendar, UnicodeString &appendTo, FieldPosition &fieldPosition, UErrorCode &status) const
Format 2 Calendars to produce a string.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &fieldPosition, UErrorCode &status) const override
Format an object to produce a string.
const DateIntervalInfo * getDateIntervalInfo() const
Gets the date time interval patterns.
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const override
Date interval parsing is not supported.
virtual ~DateIntervalFormat()
Destructor.
const DateFormat * getDateFormat() const
Gets the date formatter.
virtual void setContext(UDisplayContext value, UErrorCode &status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
virtual DateIntervalFormat * clone() const override
Clone this Format object polymorphically.
static DateIntervalFormat * createInstance(const UnicodeString &skeleton, const DateIntervalInfo &dtitvinf, UErrorCode &status)
Construct a DateIntervalFormat from skeleton DateIntervalInfo, and default locale.
virtual void adoptTimeZone(TimeZone *zoneToAdopt)
Sets the time zone for the calendar used by this DateIntervalFormat object.
static DateIntervalFormat * createInstance(const UnicodeString &skeleton, UErrorCode &status)
Construct a DateIntervalFormat from skeleton and the default locale.
virtual const TimeZone & getTimeZone() const
Returns a reference to the TimeZone used by this DateIntervalFormat's calendar.
static DateIntervalFormat * createInstance(const UnicodeString &skeleton, const Locale &locale, const DateIntervalInfo &dtitvinf, UErrorCode &status)
Construct a DateIntervalFormat from skeleton a DateIntervalInfo, and the given locale.
virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode &status) const
Get the formatter's UDisplayContext value for the specified UDisplayContextType, such as UDISPCTX_TYP...
virtual bool operator==(const Format &other) const override
Return true if the given Format objects are semantically equal.
virtual UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
FormattedDateInterval formatToValue(Calendar &fromCalendar, Calendar &toCalendar, UErrorCode &status) const
Format 2 Calendars to produce a FormattedDateInterval.
DateIntervalFormat(const DateIntervalFormat &)
Copy constructor.
DateIntervalFormat & operator=(const DateIntervalFormat &)
Assignment operator.
static DateIntervalFormat * createInstance(const UnicodeString &skeleton, const Locale &locale, UErrorCode &status)
Construct a DateIntervalFormat from skeleton and a given locale.
FormattedDateInterval formatToValue(const DateInterval &dtInterval, UErrorCode &status) const
Format a DateInterval to produce a FormattedDateInterval.
UnicodeString & format(const DateInterval *dtInterval, UnicodeString &appendTo, FieldPosition &fieldPosition, UErrorCode &status) const
Format a DateInterval to produce a string.
static UClassID getStaticClassID()
Return the class ID for this class.
void setDateIntervalInfo(const DateIntervalInfo &newIntervalPatterns, UErrorCode &status)
Set the date time interval patterns.
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
Base class for all formats.
Definition format.h:98
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.
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:195
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:385
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:296
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.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
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:247
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:430
@ U_INVALID_STATE_ERROR
Requested operation can not be completed with ICU in its current state.
Definition utypes.h:494
@ U_ZERO_ERROR
No error, no warning.
Definition utypes.h:465
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:316