ICU 77.1: i18n/unicode/smpdtfmt.h Source File

ICU 77.1 77.1

smpdtfmt.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) 1997-2016, International Business Machines Corporation and
5 * others. All Rights Reserved.
6 *******************************************************************************
7 *
8 * File SMPDTFMT.H
9 *
10 * Modification History:
11 *
12 * Date Name Description
13 * 02/19/97 aliu Converted from java.
14 * 07/09/97 helena Make ParsePosition into a class.
15 * 07/21/98 stephen Added GMT_PLUS, GMT_MINUS
16 * Changed setTwoDigitStartDate to set2DigitYearStart
17 * Changed getTwoDigitStartDate to get2DigitYearStart
18 * Removed subParseLong
19 * Removed getZoneIndex (added in DateFormatSymbols)
20 * 06/14/99 stephen Removed fgTimeZoneDataSuffix
21 * 10/14/99 aliu Updated class doc to describe 2-digit year parsing
22 * {j28 4182066}.
23 *******************************************************************************
24 */
25
26 #ifndef SMPDTFMT_H
27 #define SMPDTFMT_H
28
29 #include "unicode/utypes.h"
30
31 #if U_SHOW_CPLUSPLUS_API
32
38 #if !UCONFIG_NO_FORMATTING
39
40 #include "unicode/datefmt.h"
41 #include "unicode/udisplaycontext.h"
42 #include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */
43 #include "unicode/brkiter.h"
44
45 U_NAMESPACE_BEGIN
46
47 class DateFormatSymbols;
48 class DateFormat;
49 class MessageFormat;
50 class FieldPositionHandler;
51 class TimeZoneFormat;
52 class SharedNumberFormat;
53 class SimpleDateFormatMutableNFs;
54 class DateIntervalFormat;
55
56 namespace number {
57 class LocalizedNumberFormatter;
58 class SimpleNumberFormatter;
59 }
60
385 class U_I18N_API SimpleDateFormat: public DateFormat {
386 public:
396 SimpleDateFormat(UErrorCode& status);
397
409 SimpleDateFormat(const UnicodeString& pattern,
410 UErrorCode& status);
411
433 SimpleDateFormat(const UnicodeString& pattern,
434 const UnicodeString& override,
435 UErrorCode& status);
436
449 SimpleDateFormat(const UnicodeString& pattern,
450 const Locale& locale,
451 UErrorCode& status);
452
474 SimpleDateFormat(const UnicodeString& pattern,
475 const UnicodeString& override,
476 const Locale& locale,
477 UErrorCode& status);
478
488 SimpleDateFormat(const UnicodeString& pattern,
489 DateFormatSymbols* formatDataToAdopt,
490 UErrorCode& status);
491
501 SimpleDateFormat(const UnicodeString& pattern,
502 const DateFormatSymbols& formatData,
503 UErrorCode& status);
504
509 SimpleDateFormat(const SimpleDateFormat&);
510
515 SimpleDateFormat& operator=(const SimpleDateFormat&);
516
521 virtual ~SimpleDateFormat();
522
529 virtual SimpleDateFormat* clone() const override;
530
538 virtual bool operator==(const Format& other) const override;
539
540
541 using DateFormat::format;
542
559 virtual UnicodeString& format( Calendar& cal,
560 UnicodeString& appendTo,
561 FieldPosition& pos) const override;
562
581 virtual UnicodeString& format( Calendar& cal,
582 UnicodeString& appendTo,
583 FieldPositionIterator* posIter,
584 UErrorCode& status) const override;
585
586 using DateFormat::parse;
587
614 virtual void parse( const UnicodeString& text,
615 Calendar& cal,
616 ParsePosition& pos) const override;
617
618
635 virtual void set2DigitYearStart(UDate d, UErrorCode& status);
636
652 UDate get2DigitYearStart(UErrorCode& status) const;
653
660 virtual UnicodeString& toPattern(UnicodeString& result) const;
661
684 virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
685 UErrorCode& status) const;
686
695 virtual void applyPattern(const UnicodeString& pattern);
696
707 virtual void applyLocalizedPattern(const UnicodeString& pattern,
708 UErrorCode& status);
709
718 virtual const DateFormatSymbols* getDateFormatSymbols() const;
719
726 virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
727
733 virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
734
746 static UClassID U_EXPORT2 getStaticClassID();
747
759 virtual UClassID getDynamicClassID() const override;
760
770 virtual void adoptCalendar(Calendar* calendarToAdopt) override;
771
772 /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
780 virtual void adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt);
781
787 virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat);
788
794 virtual const TimeZoneFormat* getTimeZoneFormat() const;
795
806 virtual void setContext(UDisplayContext value, UErrorCode& status) override;
807
815 void adoptNumberFormat(NumberFormat *formatToAdopt) override;
816
832 void adoptNumberFormat(const UnicodeString& fields, NumberFormat *formatToAdopt, UErrorCode &status);
833
839 const NumberFormat * getNumberFormatForField(char16_t field) const;
840
841 #ifndef U_HIDE_INTERNAL_API
852 UBool isFieldUnitIgnored(UCalendarDateFields field) const;
853
854
866 static UBool isFieldUnitIgnored(const UnicodeString& pattern,
867 UCalendarDateFields field);
868
877 const Locale& getSmpFmtLocale() const;
878 #endif /* U_HIDE_INTERNAL_API */
879
880 private:
881 friend class DateFormat;
882 friend class DateIntervalFormat;
883
884 void initializeDefaultCentury();
885
886 void initializeBooleanAttributes();
887
888 SimpleDateFormat() = delete; // default constructor not implemented
889
898 SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
899
908 SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
909
913 UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
914
931 void subFormat(UnicodeString &appendTo,
932 char16_t ch,
933 int32_t count,
934 UDisplayContext capitalizationContext,
935 int32_t fieldNum,
936 char16_t fieldToOutput,
937 FieldPositionHandler& handler,
938 Calendar& cal,
939 UErrorCode& status) const; // in case of illegal argument
940
954 void zeroPaddingNumber(const NumberFormat *currentNumberFormat,
955 UnicodeString &appendTo,
956 int32_t value,
957 int32_t minDigits,
958 int32_t maxDigits) const;
959
964 static UBool isNumeric(char16_t formatChar, int32_t count);
965
969 static UBool isAtNumericField(const UnicodeString &pattern, int32_t patternOffset);
970
974 static UBool isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset);
975
983 Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
984
994 void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
995
1002 void initialize(const Locale& locale, UErrorCode& status);
1003
1017 int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1018 const UnicodeString* stringArray, int32_t stringArrayCount,
1019 const UnicodeString* monthPattern, Calendar& cal) const;
1020
1033 int32_t matchAlphaMonthStrings(const UnicodeString& text, int32_t start,
1034 const UnicodeString* wideStringArray, const UnicodeString* shortStringArray,
1035 int32_t stringArrayCount, Calendar& cal) const;
1036
1049 int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1050 const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
1051
1055 int32_t matchDayPeriodStrings(const UnicodeString& text, int32_t start,
1056 const UnicodeString* stringArray, int32_t stringArrayCount,
1057 int32_t &dayPeriod) const;
1058
1074 static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
1075 const UnicodeString &text, int32_t &textOffset,
1076 UBool whitespaceLenient, UBool partialMatchLenient, UBool oldLeniency);
1077
1098 int32_t subParse(const UnicodeString& text, int32_t& start, char16_t ch, int32_t count,
1099 UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
1100 int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType,
1101 int32_t *dayPeriod=nullptr) const;
1102
1103 void parseInt(const UnicodeString& text,
1104 Formattable& number,
1105 ParsePosition& pos,
1106 UBool allowNegative,
1107 const NumberFormat *fmt) const;
1108
1109 void parseInt(const UnicodeString& text,
1110 Formattable& number,
1111 int32_t maxDigits,
1112 ParsePosition& pos,
1113 UBool allowNegative,
1114 const NumberFormat *fmt) const;
1115
1116 int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
1117 int32_t patLoc, UBool isNegative) const;
1118
1127 int32_t countDigits(const UnicodeString& text, int32_t start, int32_t end) const;
1128
1141 static void translatePattern(const UnicodeString& originalPattern,
1142 UnicodeString& translatedPattern,
1143 const UnicodeString& from,
1144 const UnicodeString& to,
1145 UErrorCode& status);
1146
1154 void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
1155
1165 int32_t compareSimpleAffix(const UnicodeString& affix,
1166 const UnicodeString& input,
1167 int32_t pos) const;
1168
1173 int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
1174
1179 int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
1180
1184 void initSimpleNumberFormatter(UErrorCode &status);
1185
1189 void initNumberFormatters(const Locale &locale,UErrorCode &status);
1190
1194 void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
1195
1199 static const UCalendarDateFields fgPatternIndexToCalendarField[];
1200
1204 static const UDateFormatField fgPatternIndexToDateFormatField[];
1205
1209 TimeZoneFormat *tzFormat(UErrorCode &status) const;
1210
1211 const NumberFormat* getNumberFormatByIndex(UDateFormatField index) const;
1212
1219 static const int32_t fgCalendarFieldToLevel[];
1220
1224 static int32_t getLevelFromChar(char16_t ch);
1225
1229 static UBool isSyntaxChar(char16_t ch);
1230
1234 UnicodeString fPattern;
1235
1239 UnicodeString fDateOverride;
1240
1244 UnicodeString fTimeOverride;
1245
1246
1250 Locale fLocale;
1251
1256 DateFormatSymbols* fSymbols = nullptr; // Owned
1257
1261 TimeZoneFormat* fTimeZoneFormat = nullptr;
1262
1271 UDate fDefaultCenturyStart;
1272
1273 UBool fHasMinute;
1274 UBool fHasSecond;
1275 UBool fHasHanYearChar; // pattern contains the Han year character \u5E74
1276
1280 void parsePattern();
1281
1285 /*transient*/ int32_t fDefaultCenturyStartYear;
1286
1287 struct NSOverride : public UMemory {
1288 const SharedNumberFormat *snf;
1289 int32_t hash;
1290 NSOverride *next;
1291 void free();
1292 NSOverride() : snf(nullptr), hash(0), next(nullptr) {
1293 }
1294 ~NSOverride();
1295 };
1296
1301 const SharedNumberFormat **fSharedNumberFormatters = nullptr;
1302
1310 const number::SimpleNumberFormatter* fSimpleNumberFormatter = nullptr;
1311
1312 UBool fHaveDefaultCentury;
1313
1314 const BreakIterator* fCapitalizationBrkIter = nullptr;
1315 };
1316
1317 inline UDate
1318 SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
1319 {
1320 return fDefaultCenturyStart;
1321 }
1322
1323 U_NAMESPACE_END
1324
1325 #endif /* #if !UCONFIG_NO_FORMATTING */
1326
1327 #endif /* U_SHOW_CPLUSPLUS_API */
1328
1329 #endif // _SMPDTFMT
1330 //eof
brkiter.h
C++ API: Break Iterator.
icu::Calendar
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:190
icu::DateFormatSymbols
DateFormatSymbols is a public class for encapsulating localizable date-time formatting data – includi...
Definition: dtfmtsym.h:85
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::DateFormat::parse
virtual UDate parse(const UnicodeString &text, UErrorCode &status) const
Parse a date/time string.
icu::DateFormat::EStyle
EStyle
Constants for various style patterns.
Definition: datefmt.h:167
icu::DateFormat::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
icu::DateIntervalFormat
DateIntervalFormat is a class for formatting and parsing date intervals in a language-independent man...
Definition: dtitvfmt.h:300
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:58
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:110
icu::Format
Base class for all formats.
Definition: format.h:99
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:63
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::MessageFormat
Definition: msgfmt.h:345
icu::NumberFormat
Definition: numfmt.h:175
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::SimpleDateFormat
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition: smpdtfmt.h:385
icu::SimpleDateFormat::format
virtual UnicodeString & format(Calendar &cal, UnicodeString &appendTo, FieldPosition &pos) const override
Format a date or time, which is the standard millis since 24:00 GMT, Jan 1, 1970.
icu::SimpleDateFormat::operator==
virtual bool operator==(const Format &other) const override
Return true if the given Format objects are semantically equal.
icu::SimpleDateFormat::parse
virtual void parse(const UnicodeString &text, Calendar &cal, ParsePosition &pos) const override
Parse a date/time string beginning at the given parse position.
icu::SimpleDateFormat::getTimeZoneFormat
virtual const TimeZoneFormat * getTimeZoneFormat() const
Gets the time zone format object associated with this date/time formatter.
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(const UnicodeString &pattern, const UnicodeString &override, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern, numbering system override, and the default loca...
icu::SimpleDateFormat::applyPattern
virtual void applyPattern(const UnicodeString &pattern)
Apply the given unlocalized pattern string to this date format.
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(const SimpleDateFormat &)
Copy constructor.
icu::SimpleDateFormat::adoptDateFormatSymbols
virtual void adoptDateFormatSymbols(DateFormatSymbols *newFormatSymbols)
Set the date/time formatting symbols.
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(const UnicodeString &pattern, DateFormatSymbols *formatDataToAdopt, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale-specific symbol data.
icu::SimpleDateFormat::setDateFormatSymbols
virtual void setDateFormatSymbols(const DateFormatSymbols &newFormatSymbols)
Set the date/time formatting data.
icu::SimpleDateFormat::toPattern
virtual UnicodeString & toPattern(UnicodeString &result) const
Return a pattern string describing this date format.
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(const UnicodeString &pattern, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and the default locale.
icu::SimpleDateFormat::getDynamicClassID
virtual UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
icu::SimpleDateFormat::toLocalizedPattern
virtual UnicodeString & toLocalizedPattern(UnicodeString &result, UErrorCode &status) const
Return a localized pattern string describing this date format.
icu::SimpleDateFormat::getNumberFormatForField
const NumberFormat * getNumberFormatForField(char16_t field) const
Get the numbering system to be used for a particular field.
icu::SimpleDateFormat::setContext
virtual void setContext(UDisplayContext value, UErrorCode &status) override
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
icu::SimpleDateFormat::adoptNumberFormat
void adoptNumberFormat(NumberFormat *formatToAdopt) override
Overrides base class method and This method clears per field NumberFormat instances previously set by...
icu::SimpleDateFormat::isFieldUnitIgnored
UBool isFieldUnitIgnored(UCalendarDateFields field) const
This is for ICU internal use only.
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(const UnicodeString &pattern, const DateFormatSymbols &formatData, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale-specific symbol data.
icu::SimpleDateFormat::setTimeZoneFormat
virtual void setTimeZoneFormat(const TimeZoneFormat &newTimeZoneFormat)
Sets the TimeZoneFormat to be used by this date/time formatter.
icu::SimpleDateFormat::operator=
SimpleDateFormat & operator=(const SimpleDateFormat &)
Assignment operator.
icu::SimpleDateFormat::adoptCalendar
virtual void adoptCalendar(Calendar *calendarToAdopt) override
Set the calendar to be used by this date format.
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(UErrorCode &status)
Construct a SimpleDateFormat using the default pattern for the default locale.
icu::SimpleDateFormat::getStaticClassID
static UClassID getStaticClassID()
Return the class ID for this class.
icu::SimpleDateFormat::format
virtual UnicodeString & format(Calendar &cal, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const override
Format a date or time, which is the standard millis since 24:00 GMT, Jan 1, 1970.
icu::SimpleDateFormat::set2DigitYearStart
virtual void set2DigitYearStart(UDate d, UErrorCode &status)
Set the start UDate used to interpret two-digit year strings.
icu::SimpleDateFormat::~SimpleDateFormat
virtual ~SimpleDateFormat()
Destructor.
icu::SimpleDateFormat::adoptNumberFormat
void adoptNumberFormat(const UnicodeString &fields, NumberFormat *formatToAdopt, UErrorCode &status)
Allow the user to set the NumberFormat for several fields It can be a single field like: "y"(year) or...
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(const UnicodeString &pattern, const UnicodeString &override, const Locale &locale, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern, numbering system override, and locale.
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(const UnicodeString &pattern, const Locale &locale, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale.
icu::SimpleDateFormat::isFieldUnitIgnored
static UBool isFieldUnitIgnored(const UnicodeString &pattern, UCalendarDateFields field)
This is for ICU internal use only.
icu::SimpleDateFormat::adoptTimeZoneFormat
virtual void adoptTimeZoneFormat(TimeZoneFormat *timeZoneFormatToAdopt)
Sets the TimeZoneFormat to be used by this date/time formatter.
icu::SimpleDateFormat::getSmpFmtLocale
const Locale & getSmpFmtLocale() const
This is for ICU internal use only.
icu::SimpleDateFormat::applyLocalizedPattern
virtual void applyLocalizedPattern(const UnicodeString &pattern, UErrorCode &status)
Apply the given localized pattern string to this date format.
icu::SimpleDateFormat::getDateFormatSymbols
virtual const DateFormatSymbols * getDateFormatSymbols() const
Gets the date/time formatting symbols (this is an object carrying the various strings and other symbo...
icu::SimpleDateFormat::clone
virtual SimpleDateFormat * clone() const override
Clone this Format object polymorphically.
icu::TimeZoneFormat
TimeZoneFormat supports time zone display name formatting and parsing.
Definition: tzfmt.h:274
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:133
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:115
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
datefmt.h
C++ API: Abstract class for converting dates.
tzfmt.h
C++ API: TimeZoneFormat.
UTimeZoneFormatTimeType
UTimeZoneFormatTimeType
Constants for time types used by TimeZoneFormat APIs for receiving time type (standard time,...
Definition: tzfmt.h:206
UCalendarDateFields
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:202
UDateFormatField
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat.
Definition: udat.h:515
udisplaycontext.h
C API: Display context types (enum values)
UDisplayContext
UDisplayContext
Display context settings.
Definition: udisplaycontext.h:64
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:430
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:316
UDate
double UDate
Date and Time data type.
Definition: utypes.h:218