ICU4C 79
Loading...
Searching...
No Matches
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
37
38#if !UCONFIG_NO_FORMATTING
39
40#include "unicode/datefmt.h"
42#include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */
43#include "unicode/brkiter.h"
44
45U_NAMESPACE_BEGIN
46
47class DateFormatSymbols;
48class DateFormat;
49class MessageFormat;
50class FieldPositionHandler;
51class TimeZoneFormat;
52class SharedNumberFormat;
53class SimpleDateFormatMutableNFs;
54class DateIntervalFormat;
55class PluralRules;
56
57namespace number {
58class LocalizedNumberFormatter;
59class SimpleNumberFormatter;
60}
61
386class U_I18N_API_CLASS SimpleDateFormat: public DateFormat {
387public:
398
411 UErrorCode& status);
412
435 const UnicodeString& override,
436 UErrorCode& status);
437
450 U_I18N_API SimpleDateFormat(const UnicodeString& pattern, const Locale& locale, UErrorCode& status);
451
474 const UnicodeString& override,
475 const Locale& locale,
476 UErrorCode& status);
477
488 DateFormatSymbols* formatDataToAdopt,
489 UErrorCode& status);
490
501 const DateFormatSymbols& formatData,
502 UErrorCode& status);
503
509
515
521
528 U_I18N_API virtual SimpleDateFormat* clone() const override;
529
537 U_I18N_API virtual bool operator==(const Format& other) const override;
538
539 using DateFormat::format;
540
558 UnicodeString& appendTo,
559 FieldPosition& pos) const override;
560
580 UnicodeString& appendTo,
581 FieldPositionIterator* posIter,
582 UErrorCode& status) const override;
583
584 using DateFormat::parse;
585
612 U_I18N_API virtual void parse(const UnicodeString& text,
613 Calendar& cal,
614 ParsePosition& pos) const override;
615
633
650
658
682 UErrorCode& status) const;
683
692 U_I18N_API virtual void applyPattern(const UnicodeString& pattern);
693
704 U_I18N_API virtual void applyLocalizedPattern(const UnicodeString& pattern, UErrorCode& status);
705
715
722 U_I18N_API virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
723
729 U_I18N_API virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
730
743
755 U_I18N_API virtual UClassID getDynamicClassID() const override;
756
766 U_I18N_API virtual void adoptCalendar(Calendar* calendarToAdopt) override;
767
768 /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
776 U_I18N_API virtual void adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt);
777
783 U_I18N_API virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat);
784
791
802 U_I18N_API virtual void setContext(UDisplayContext value, UErrorCode& status) override;
803
811 U_I18N_API void adoptNumberFormat(NumberFormat* formatToAdopt) override;
812
829 NumberFormat* formatToAdopt,
830 UErrorCode& status);
831
837 U_I18N_API const NumberFormat* getNumberFormatForField(char16_t field) const;
838
839#ifndef U_HIDE_INTERNAL_API
851
864
874#endif /* U_HIDE_INTERNAL_API */
875
876private:
877 friend class DateFormat;
878 friend class DateIntervalFormat;
879
880 void initializeDefaultCentury();
881
882 void initializeBooleanAttributes();
883
884 SimpleDateFormat() = delete; // default constructor not implemented
885
894 SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
895
904 SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
905
909 UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
910
927 void subFormat(UnicodeString &appendTo,
928 char16_t ch,
929 int32_t count,
930 UDisplayContext capitalizationContext,
931 int32_t fieldNum,
932 char16_t fieldToOutput,
933 FieldPositionHandler& handler,
934 Calendar& cal,
935 UErrorCode& status) const; // in case of illegal argument
936
950 void zeroPaddingNumber(const NumberFormat *currentNumberFormat,
951 UnicodeString &appendTo,
952 int32_t value,
953 int32_t minDigits,
954 int32_t maxDigits) const;
955
960 static UBool isNumeric(char16_t formatChar, int32_t count);
961
965 static UBool isAtNumericField(const UnicodeString &pattern, int32_t patternOffset);
966
970 static UBool isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset);
971
979 Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
980
990 void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
991
998 void initialize(const Locale& locale, UErrorCode& status);
999
1013 int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1014 const UnicodeString* stringArray, int32_t stringArrayCount,
1015 const UnicodeString* monthPattern, Calendar& cal) const;
1016
1029 int32_t matchAlphaMonthStrings(const UnicodeString& text, int32_t start,
1030 const UnicodeString* wideStringArray, const UnicodeString* shortStringArray,
1031 int32_t stringArrayCount, Calendar& cal) const;
1032
1045 int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1046 const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
1047
1051 int32_t matchDayPeriodStrings(const UnicodeString& text, int32_t start,
1052 const UnicodeString* stringArray, int32_t stringArrayCount,
1053 int32_t &dayPeriod) const;
1054
1070 static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
1071 const UnicodeString &text, int32_t &textOffset,
1072 UBool whitespaceLenient, UBool partialMatchLenient, UBool oldLeniency);
1073
1094 int32_t subParse(const UnicodeString& text, int32_t& start, char16_t ch, int32_t count,
1095 UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
1096 int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType,
1097 int32_t *dayPeriod=nullptr) const;
1098
1099 void parseInt(const UnicodeString& text,
1100 Formattable& number,
1101 ParsePosition& pos,
1102 UBool allowNegative,
1103 const NumberFormat *fmt) const;
1104
1105 void parseInt(const UnicodeString& text,
1106 Formattable& number,
1107 int32_t maxDigits,
1108 ParsePosition& pos,
1109 UBool allowNegative,
1110 const NumberFormat *fmt) const;
1111
1112 int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
1113 int32_t patLoc, UBool isNegative) const;
1114
1123 int32_t countDigits(const UnicodeString& text, int32_t start, int32_t end) const;
1124
1137 static void translatePattern(const UnicodeString& originalPattern,
1138 UnicodeString& translatedPattern,
1139 const UnicodeString& from,
1140 const UnicodeString& to,
1141 UErrorCode& status);
1142
1150 void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
1151
1161 int32_t compareSimpleAffix(const UnicodeString& affix,
1162 const UnicodeString& input,
1163 int32_t pos) const;
1164
1169 int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
1170
1175 int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
1176
1180 void initSimpleNumberFormatter(UErrorCode &status);
1181
1185 void initNumberFormatters(const Locale &locale,UErrorCode &status);
1186
1190 void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
1191
1195 static const UCalendarDateFields fgPatternIndexToCalendarField[];
1196
1200 static const UDateFormatField fgPatternIndexToDateFormatField[];
1201
1205 TimeZoneFormat *tzFormat(UErrorCode &status) const;
1206
1207 const NumberFormat* getNumberFormatByIndex(UDateFormatField index) const;
1208
1215 static const int32_t fgCalendarFieldToLevel[];
1216
1220 static int32_t getLevelFromChar(char16_t ch);
1221
1225 static UBool isSyntaxChar(char16_t ch);
1226
1230 UnicodeString fPattern;
1231
1235 UnicodeString fDateOverride;
1236
1240 UnicodeString fTimeOverride;
1241
1242
1246 Locale fLocale;
1247
1252 DateFormatSymbols* fSymbols = nullptr; // Owned
1253
1257 TimeZoneFormat* fTimeZoneFormat = nullptr;
1258
1267 UDate fDefaultCenturyStart;
1268
1269 UBool fHasMinute;
1270 UBool fHasSecond;
1271 UBool fHasHanYearChar; // pattern contains the Han year character \u5E74
1272 PluralRules* fOrdinalPluralRules = nullptr; // Owned; created in parsePattern()
1273
1277 void parsePattern();
1278
1282 /*transient*/ int32_t fDefaultCenturyStartYear;
1283
1284 struct NSOverride : public UMemory {
1285 const SharedNumberFormat *snf;
1286 int32_t hash;
1287 NSOverride *next;
1288 void free();
1289 NSOverride() : snf(nullptr), hash(0), next(nullptr) {
1290 }
1291 ~NSOverride();
1292 };
1293
1298 const SharedNumberFormat **fSharedNumberFormatters = nullptr;
1299
1307 const number::SimpleNumberFormatter* fSimpleNumberFormatter = nullptr;
1308
1309 UBool fHaveDefaultCentury;
1310
1311 const BreakIterator* fCapitalizationBrkIter = nullptr;
1312};
1313
1314inline UDate
1316{
1317 return fDefaultCenturyStart;
1318}
1319
1320U_NAMESPACE_END
1321
1322#endif /* #if !UCONFIG_NO_FORMATTING */
1323
1324#endif /* U_SHOW_CPLUSPLUS_API */
1325
1326#endif // _SMPDTFMT
1327//eof
C++ API: Break Iterator.
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition calendar.h:189
DateFormatSymbols is a public class for encapsulating localizable date-time formatting data – includi...
Definition dtfmtsym.h:84
virtual U_I18N_API UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const override
Format an object to produce a string.
virtual U_I18N_API UDate parse(const UnicodeString &text, UErrorCode &status) const
Parse a date/time string.
EStyle
Constants for various style patterns.
Definition datefmt.h:155
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition fpositer.h:58
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
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
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition plurrule.h:212
U_I18N_API SimpleDateFormat(const UnicodeString &pattern, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and the default locale.
static U_I18N_API UBool isFieldUnitIgnored(const UnicodeString &pattern, UCalendarDateFields field)
This is for ICU internal use only.
virtual U_I18N_API void adoptCalendar(Calendar *calendarToAdopt) override
Set the calendar to be used by this date format.
U_I18N_API SimpleDateFormat(const UnicodeString &pattern, const DateFormatSymbols &formatData, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale-specific symbol data.
virtual U_I18N_API void setDateFormatSymbols(const DateFormatSymbols &newFormatSymbols)
Set the date/time formatting data.
U_I18N_API const Locale & getSmpFmtLocale() const
This is for ICU internal use only.
U_I18N_API UDate get2DigitYearStart(UErrorCode &status) const
Get the start UDate used to interpret two-digit year strings.
Definition smpdtfmt.h:1315
virtual U_I18N_API bool operator==(const Format &other) const override
Return true if the given Format objects are semantically equal.
virtual U_I18N_API void setContext(UDisplayContext value, UErrorCode &status) override
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
virtual U_I18N_API SimpleDateFormat * clone() const override
Clone this Format object polymorphically.
U_I18N_API const NumberFormat * getNumberFormatForField(char16_t field) const
Get the numbering system to be used for a particular field.
virtual U_I18N_API void setTimeZoneFormat(const TimeZoneFormat &newTimeZoneFormat)
Sets the TimeZoneFormat to be used by this date/time formatter.
virtual U_I18N_API void set2DigitYearStart(UDate d, UErrorCode &status)
Set the start UDate used to interpret two-digit year strings.
U_I18N_API 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...
U_I18N_API SimpleDateFormat & operator=(const SimpleDateFormat &)
Assignment operator.
virtual U_I18N_API void applyPattern(const UnicodeString &pattern)
Apply the given unlocalized pattern string to this date format.
U_I18N_API SimpleDateFormat(UErrorCode &status)
Construct a SimpleDateFormat using the default pattern for the default locale.
U_I18N_API UBool isFieldUnitIgnored(UCalendarDateFields field) const
This is for ICU internal use only.
U_I18N_API SimpleDateFormat(const UnicodeString &pattern, const Locale &locale, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale.
U_I18N_API SimpleDateFormat(const UnicodeString &pattern, const UnicodeString &override, const Locale &locale, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern, numbering system override, and locale.
virtual U_I18N_API 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.
U_I18N_API void adoptNumberFormat(NumberFormat *formatToAdopt) override
Overrides base class method and This method clears per field NumberFormat instances previously set by...
U_I18N_API SimpleDateFormat(const UnicodeString &pattern, const UnicodeString &override, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern, numbering system override, and the default loca...
virtual U_I18N_API UnicodeString & toPattern(UnicodeString &result) const
Return a pattern string describing this date format.
virtual U_I18N_API UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
virtual U_I18N_API void adoptTimeZoneFormat(TimeZoneFormat *timeZoneFormatToAdopt)
Sets the TimeZoneFormat to be used by this date/time formatter.
virtual U_I18N_API void parse(const UnicodeString &text, Calendar &cal, ParsePosition &pos) const override
Parse a date/time string beginning at the given parse position.
virtual U_I18N_API const TimeZoneFormat * getTimeZoneFormat() const
Gets the time zone format object associated with this date/time formatter.
virtual U_I18N_API void adoptDateFormatSymbols(DateFormatSymbols *newFormatSymbols)
Set the date/time formatting symbols.
virtual U_I18N_API 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.
virtual U_I18N_API UnicodeString & toLocalizedPattern(UnicodeString &result, UErrorCode &status) const
Return a localized pattern string describing this date format.
virtual U_I18N_API const DateFormatSymbols * getDateFormatSymbols() const
Gets the date/time formatting symbols (this is an object carrying the various strings and other symbo...
U_I18N_API SimpleDateFormat(const UnicodeString &pattern, DateFormatSymbols *formatDataToAdopt, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale-specific symbol data.
virtual U_I18N_API ~SimpleDateFormat()
Destructor.
static U_I18N_API UClassID getStaticClassID()
Return the class ID for this class.
virtual U_I18N_API void applyLocalizedPattern(const UnicodeString &pattern, UErrorCode &status)
Apply the given localized pattern string to this date format.
U_I18N_API SimpleDateFormat(const SimpleDateFormat &)
Copy constructor.
TimeZoneFormat supports time zone display name formatting and parsing.
Definition tzfmt.h:274
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: Abstract class for converting dates.
C++ API: TimeZoneFormat.
UTimeZoneFormatTimeType
Constants for time types used by TimeZoneFormat APIs for receiving time type (standard time,...
Definition tzfmt.h:206
UCalendarDateFields
Possible fields in a UCalendar.
Definition ucal.h:202
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat.
Definition udat.h:515
C API: Display context types (enum values).
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
#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
double UDate
Date and Time data type.
Definition utypes.h:218