ICU 75.1 75.1
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
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;
55
56namespace number {
57class LocalizedNumberFormatter;
58class SimpleNumberFormatter;
59}
60
386public:
397
411
434 const UnicodeString& override,
436
450 const Locale& locale,
452
475 const UnicodeString& override,
476 const Locale& locale,
478
491
504
510
516
522
529 virtual SimpleDateFormat* clone() const override;
530
538 virtual bool operator==(const Format& other) const override;
539
540
541 using DateFormat::format;
542
560 UnicodeString& appendTo,
561 FieldPosition& pos) const override;
562
582 UnicodeString& appendTo,
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
636
652 UDate get2DigitYearStart(UErrorCode& status) const;
653
661
685 UErrorCode& status) const;
686
695 virtual void applyPattern(const UnicodeString& pattern);
696
707 virtual void applyLocalizedPattern(const UnicodeString& pattern,
709
719
727
734
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 */
781
788
794 virtual const TimeZoneFormat* getTimeZoneFormat() const;
795
806 virtual void setContext(UDisplayContext value, UErrorCode& status) override;
807
816
833
839 const NumberFormat * getNumberFormatForField(char16_t field) const;
840
841#ifndef U_HIDE_INTERNAL_API
853
854
867 UCalendarDateFields field);
868
877 const Locale& getSmpFmtLocale() const;
878#endif /* U_HIDE_INTERNAL_API */
879
880private:
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
899
908 SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
909
914
931 void subFormat(UnicodeString &appendTo,
932 char16_t ch,
933 int32_t count,
936 char16_t fieldToOutput,
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,
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,
1019 const UnicodeString* monthPattern, Calendar& cal) const;
1020
1033 int32_t matchAlphaMonthStrings(const UnicodeString& text, int32_t start,
1036
1049 int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1051
1055 int32_t matchDayPeriodStrings(const UnicodeString& text, int32_t start,
1057 int32_t &dayPeriod) const;
1058
1074 static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
1075 const UnicodeString &text, int32_t &textOffset,
1077
1098 int32_t subParse(const UnicodeString& text, int32_t& start, char16_t ch, int32_t count,
1101 int32_t *dayPeriod=nullptr) const;
1102
1103 void parseInt(const UnicodeString& text,
1104 Formattable& number,
1105 ParsePosition& pos,
1107 const NumberFormat *fmt) const;
1108
1109 void parseInt(const UnicodeString& text,
1110 Formattable& number,
1112 ParsePosition& pos,
1114 const NumberFormat *fmt) const;
1115
1116 int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
1118
1127 int32_t countDigits(const UnicodeString& text, int32_t start, int32_t end) const;
1128
1141 static void translatePattern(const UnicodeString& originalPattern,
1143 const UnicodeString& from,
1144 const UnicodeString& to,
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
1317inline UDate
1318SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
1319{
1320 return fDefaultCenturyStart;
1321}
1322
1324
1325#endif /* #if !UCONFIG_NO_FORMATTING */
1326
1327#endif /* U_SHOW_CPLUSPLUS_API */
1328
1329#endif // _SMPDTFMT
1330//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
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition datefmt.h:156
EStyle
Constants for various style patterns.
Definition datefmt.h:167
DateIntervalFormat is a class for formatting and parsing date intervals in a language-independent man...
Definition dtitvfmt.h:300
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
"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
virtual bool operator==(const Format &other) const override
Return true if the given Format objects are semantically equal.
virtual void parse(const UnicodeString &text, Calendar &cal, ParsePosition &pos) const override
Parse a date/time string beginning at the given parse position.
virtual UnicodeString & toLocalizedPattern(UnicodeString &result, UErrorCode &status) const
Return a localized pattern string describing this date format.
SimpleDateFormat(const UnicodeString &pattern, const UnicodeString &override, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern, numbering system override, and the default loca...
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.
virtual void applyPattern(const UnicodeString &pattern)
Apply the given unlocalized pattern string to this date format.
SimpleDateFormat(const SimpleDateFormat &)
Copy constructor.
virtual void adoptDateFormatSymbols(DateFormatSymbols *newFormatSymbols)
Set the date/time formatting symbols.
SimpleDateFormat(const UnicodeString &pattern, DateFormatSymbols *formatDataToAdopt, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale-specific symbol data.
virtual void setDateFormatSymbols(const DateFormatSymbols &newFormatSymbols)
Set the date/time formatting data.
const Locale & getSmpFmtLocale() const
This is for ICU internal use only.
SimpleDateFormat(const UnicodeString &pattern, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and the default locale.
virtual UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
virtual void setContext(UDisplayContext value, UErrorCode &status) override
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
virtual const DateFormatSymbols * getDateFormatSymbols() const
Gets the date/time formatting symbols (this is an object carrying the various strings and other symbo...
void adoptNumberFormat(NumberFormat *formatToAdopt) override
Overrides base class method and This method clears per field NumberFormat instances previously set by...
UBool isFieldUnitIgnored(UCalendarDateFields field) const
This is for ICU internal use only.
virtual SimpleDateFormat * clone() const override
Clone this Format object polymorphically.
SimpleDateFormat(const UnicodeString &pattern, const DateFormatSymbols &formatData, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale-specific symbol data.
virtual const TimeZoneFormat * getTimeZoneFormat() const
Gets the time zone format object associated with this date/time formatter.
virtual void setTimeZoneFormat(const TimeZoneFormat &newTimeZoneFormat)
Sets the TimeZoneFormat to be used by this date/time formatter.
virtual void adoptCalendar(Calendar *calendarToAdopt) override
Set the calendar to be used by this date format.
SimpleDateFormat(UErrorCode &status)
Construct a SimpleDateFormat using the default pattern for the default locale.
static UClassID getStaticClassID()
Return the class ID for this class.
const NumberFormat * getNumberFormatForField(char16_t field) const
Get the numbering system to be used for a particular field.
SimpleDateFormat & operator=(const SimpleDateFormat &)
Assignment operator.
virtual void set2DigitYearStart(UDate d, UErrorCode &status)
Set the start UDate used to interpret two-digit year strings.
virtual ~SimpleDateFormat()
Destructor.
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...
SimpleDateFormat(const UnicodeString &pattern, const UnicodeString &override, const Locale &locale, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern, numbering system override, and locale.
SimpleDateFormat(const UnicodeString &pattern, const Locale &locale, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale.
static UBool isFieldUnitIgnored(const UnicodeString &pattern, UCalendarDateFields field)
This is for ICU internal use only.
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.
virtual void adoptTimeZoneFormat(TimeZoneFormat *timeZoneFormatToAdopt)
Sets the TimeZoneFormat to be used by this date/time formatter.
virtual UnicodeString & toPattern(UnicodeString &result) const
Return a pattern string describing this date format.
virtual void applyLocalizedPattern(const UnicodeString &pattern, UErrorCode &status)
Apply the given localized pattern string to this date format.
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:296
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: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:415
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:301
double UDate
Date and Time data type.
Definition utypes.h:203