ICU 57.1  57.1
smpdtfmt.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 1997-2016, International Business Machines Corporation and
3 * others. All Rights Reserved.
4 *******************************************************************************
5 *
6 * File SMPDTFMT.H
7 *
8 * Modification History:
9 *
10 * Date Name Description
11 * 02/19/97 aliu Converted from java.
12 * 07/09/97 helena Make ParsePosition into a class.
13 * 07/21/98 stephen Added GMT_PLUS, GMT_MINUS
14 * Changed setTwoDigitStartDate to set2DigitYearStart
15 * Changed getTwoDigitStartDate to get2DigitYearStart
16 * Removed subParseLong
17 * Removed getZoneIndex (added in DateFormatSymbols)
18 * 06/14/99 stephen Removed fgTimeZoneDataSuffix
19 * 10/14/99 aliu Updated class doc to describe 2-digit year parsing
20 * {j28 4182066}.
21 *******************************************************************************
22 */
23 
24 #ifndef SMPDTFMT_H
25 #define SMPDTFMT_H
26 
27 #include "unicode/utypes.h"
28 
34 #if !UCONFIG_NO_FORMATTING
35 
36 #include "unicode/datefmt.h"
38 #include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */
39 #include "unicode/brkiter.h"
40 
42 
43 class DateFormatSymbols;
44 class DateFormat;
45 class MessageFormat;
46 class FieldPositionHandler;
47 class TimeZoneFormat;
48 class SharedNumberFormat;
49 class SimpleDateFormatMutableNFs;
50 
718 public:
729 
742  UErrorCode& status);
743 
766  const UnicodeString& override,
767  UErrorCode& status);
768 
782  const Locale& locale,
783  UErrorCode& status);
784 
807  const UnicodeString& override,
808  const Locale& locale,
809  UErrorCode& status);
810 
821  DateFormatSymbols* formatDataToAdopt,
822  UErrorCode& status);
823 
834  const DateFormatSymbols& formatData,
835  UErrorCode& status);
836 
842 
848 
853  virtual ~SimpleDateFormat();
854 
861  virtual Format* clone(void) const;
862 
870  virtual UBool operator==(const Format& other) const;
871 
872 
873  using DateFormat::format;
874 
891  virtual UnicodeString& format( Calendar& cal,
892  UnicodeString& appendTo,
893  FieldPosition& pos) const;
894 
913  virtual UnicodeString& format( Calendar& cal,
914  UnicodeString& appendTo,
915  FieldPositionIterator* posIter,
916  UErrorCode& status) const;
917 
918  using DateFormat::parse;
919 
946  virtual void parse( const UnicodeString& text,
947  Calendar& cal,
948  ParsePosition& pos) const;
949 
950 
967  virtual void set2DigitYearStart(UDate d, UErrorCode& status);
968 
984  UDate get2DigitYearStart(UErrorCode& status) const;
985 
992  virtual UnicodeString& toPattern(UnicodeString& result) const;
993 
1011  UErrorCode& status) const;
1012 
1021  virtual void applyPattern(const UnicodeString& pattern);
1022 
1033  virtual void applyLocalizedPattern(const UnicodeString& pattern,
1034  UErrorCode& status);
1035 
1044  virtual const DateFormatSymbols* getDateFormatSymbols(void) const;
1045 
1052  virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
1053 
1059  virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
1060 
1072  static UClassID U_EXPORT2 getStaticClassID(void);
1073 
1085  virtual UClassID getDynamicClassID(void) const;
1086 
1096  virtual void adoptCalendar(Calendar* calendarToAdopt);
1097 
1098  /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
1106  virtual void adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt);
1107 
1113  virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat);
1114 
1120  virtual const TimeZoneFormat* getTimeZoneFormat(void) const;
1121 
1132  virtual void setContext(UDisplayContext value, UErrorCode& status);
1133 
1141  void adoptNumberFormat(NumberFormat *formatToAdopt);
1142 
1158  void adoptNumberFormat(const UnicodeString& fields, NumberFormat *formatToAdopt, UErrorCode &status);
1159 
1166 
1167 #ifndef U_HIDE_INTERNAL_API
1179 
1180 
1192  static UBool isFieldUnitIgnored(const UnicodeString& pattern,
1193  UCalendarDateFields field);
1194 
1203  const Locale& getSmpFmtLocale(void) const;
1204 #endif /* U_HIDE_INTERNAL_API */
1205 
1206 private:
1207  friend class DateFormat;
1208 
1209  void initializeDefaultCentury(void);
1210 
1211  void initializeBooleanAttributes(void);
1212 
1213  SimpleDateFormat(); // default constructor not implemented
1214 
1223  SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1224 
1233  SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
1234 
1238  UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
1239 
1256  void subFormat(UnicodeString &appendTo,
1257  UChar ch,
1258  int32_t count,
1259  UDisplayContext capitalizationContext,
1260  int32_t fieldNum,
1261  FieldPositionHandler& handler,
1262  Calendar& cal,
1263  SimpleDateFormatMutableNFs &mutableNFs,
1264  UErrorCode& status) const; // in case of illegal argument
1265 
1279  void zeroPaddingNumber(NumberFormat *currentNumberFormat,
1280  UnicodeString &appendTo,
1281  int32_t value,
1282  int32_t minDigits,
1283  int32_t maxDigits) const;
1284 
1289  static UBool isNumeric(UChar formatChar, int32_t count);
1290 
1294  static UBool isAtNumericField(const UnicodeString &pattern, int32_t patternOffset);
1295 
1299  static UBool isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset);
1300 
1308  Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
1309 
1319  void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1320 
1327  void initialize(const Locale& locale, UErrorCode& status);
1328 
1342  int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1343  const UnicodeString* stringArray, int32_t stringArrayCount,
1344  const UnicodeString* monthPattern, Calendar& cal) const;
1345 
1358  int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1359  const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
1360 
1364  int32_t matchDayPeriodStrings(const UnicodeString& text, int32_t start,
1365  const UnicodeString* stringArray, int32_t stringArrayCount,
1366  int32_t &dayPeriod) const;
1367 
1383  static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
1384  const UnicodeString &text, int32_t &textOffset,
1385  UBool whitespaceLenient, UBool partialMatchLenient, UBool oldLeniency);
1386 
1407  int32_t subParse(const UnicodeString& text, int32_t& start, UChar ch, int32_t count,
1408  UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
1409  int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType, SimpleDateFormatMutableNFs &mutableNFs,
1410  int32_t *dayPeriod=NULL) const;
1411 
1412  void parseInt(const UnicodeString& text,
1413  Formattable& number,
1414  ParsePosition& pos,
1415  UBool allowNegative,
1416  NumberFormat *fmt) const;
1417 
1418  void parseInt(const UnicodeString& text,
1419  Formattable& number,
1420  int32_t maxDigits,
1421  ParsePosition& pos,
1422  UBool allowNegative,
1423  NumberFormat *fmt) const;
1424 
1425  int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
1426  int32_t patLoc, UBool isNegative) const;
1427 
1440  static void translatePattern(const UnicodeString& originalPattern,
1441  UnicodeString& translatedPattern,
1442  const UnicodeString& from,
1443  const UnicodeString& to,
1444  UErrorCode& status);
1445 
1453  void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
1454 
1464  int32_t compareSimpleAffix(const UnicodeString& affix,
1465  const UnicodeString& input,
1466  int32_t pos) const;
1467 
1472  int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
1473 
1478  int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
1479 
1483  void initNumberFormatters(const Locale &locale,UErrorCode &status);
1484 
1488  void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
1489 
1493  static const UCalendarDateFields fgPatternIndexToCalendarField[];
1494 
1498  static const UDateFormatField fgPatternIndexToDateFormatField[];
1499 
1503  TimeZoneFormat *tzFormat() const;
1504 
1505  const NumberFormat* getNumberFormatByIndex(UDateFormatField index) const;
1506 
1513  static const int32_t fgCalendarFieldToLevel[];
1514 
1518  static int32_t getLevelFromChar(UChar ch);
1519 
1523  static UBool isSyntaxChar(UChar ch);
1524 
1528  UnicodeString fPattern;
1529 
1533  UnicodeString fDateOverride;
1534 
1538  UnicodeString fTimeOverride;
1539 
1540 
1544  Locale fLocale;
1545 
1550  DateFormatSymbols* fSymbols; // Owned
1551 
1555  TimeZoneFormat* fTimeZoneFormat;
1556 
1565  UDate fDefaultCenturyStart;
1566 
1567  UBool fHasMinute;
1568  UBool fHasSecond;
1569 
1573  void parsePattern();
1574 
1578  /*transient*/ int32_t fDefaultCenturyStartYear;
1579 
1580  struct NSOverride : public UMemory {
1581  const SharedNumberFormat *snf;
1582  int32_t hash;
1583  NSOverride *next;
1584  void free();
1585  NSOverride() : snf(NULL), hash(0), next(NULL) {
1586  }
1587  ~NSOverride();
1588  };
1589 
1594  const SharedNumberFormat **fSharedNumberFormatters;
1595 
1596  UBool fHaveDefaultCentury;
1597 
1598  BreakIterator* fCapitalizationBrkIter;
1599 };
1600 
1601 inline UDate
1603 {
1604  return fDefaultCenturyStart;
1605 }
1606 
1608 
1609 #endif /* #if !UCONFIG_NO_FORMATTING */
1610 
1611 #endif // _SMPDTFMT
1612 //eof
C++ API: Break Iterator.
The BreakIterator class implements methods for finding the location of boundaries in text.
Definition: brkiter.h:100
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:200
DateFormatSymbols is a public class for encapsulating localizable date-time formatting data – includi...
Definition: dtfmtsym.h:79
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:147
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
virtual UDate parse(const UnicodeString &text, UErrorCode &status) const
Parse a date/time string.
EStyle
Constants for various style patterns.
Definition: datefmt.h:158
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:53
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
Base class for all formats.
Definition: format.h:94
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:66
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185
Abstract base class for all number formats.
Definition: numfmt.h:167
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition: smpdtfmt.h:717
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 & toLocalizedPattern(UnicodeString &result, UErrorCode &status) const
Return a localized pattern string describing this date format.
static UClassID getStaticClassID(void)
Return the class ID for this class.
void adoptNumberFormat(NumberFormat *formatToAdopt)
Overrides base class method and This method clears per field NumberFormat instances previously set by...
virtual const TimeZoneFormat * getTimeZoneFormat(void) const
Gets the time zone format object associated with this date/time formatter.
virtual UnicodeString & format(Calendar &cal, UnicodeString &appendTo, FieldPosition &pos) const
Format a date or time, which is the standard millis since 24:00 GMT, Jan 1, 1970.
static UBool isFieldUnitIgnored(const UnicodeString &pattern, UCalendarDateFields field)
This is for ICU internal use only.
virtual void setContext(UDisplayContext value, UErrorCode &status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
virtual Format * clone(void) const
Clone this Format object polymorphically.
const NumberFormat * getNumberFormatForField(UChar field) const
Get the numbering system to be used for a particular field.
virtual const DateFormatSymbols * getDateFormatSymbols(void) const
Gets the date/time formatting symbols (this is an object carrying the various strings and other symbo...
const Locale & getSmpFmtLocale(void) const
This is for ICU internal use only.
virtual void setTimeZoneFormat(const TimeZoneFormat &newTimeZoneFormat)
Sets the TimeZoneFormat to be used by this date/time formatter.
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 void adoptCalendar(Calendar *calendarToAdopt)
Set the calendar to be used by this date format.
SimpleDateFormat(const UnicodeString &pattern, const DateFormatSymbols &formatData, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale-specific symbol data.
SimpleDateFormat(const UnicodeString &pattern, DateFormatSymbols *formatDataToAdopt, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale-specific symbol data.
SimpleDateFormat & operator=(const SimpleDateFormat &)
Assignment operator.
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
virtual void setDateFormatSymbols(const DateFormatSymbols &newFormatSymbols)
Set the date/time formatting data.
SimpleDateFormat(UErrorCode &status)
Construct a SimpleDateFormat using the default pattern for the default locale.
virtual void applyLocalizedPattern(const UnicodeString &pattern, UErrorCode &status)
Apply the given localized pattern string to this date format.
virtual void set2DigitYearStart(UDate d, UErrorCode &status)
Set the start UDate used to interpret two-digit year strings.
virtual UnicodeString & toPattern(UnicodeString &result) const
Return a pattern string describing this date format.
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 Locale &locale, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale.
UDate get2DigitYearStart(UErrorCode &status) const
Get the start UDate used to interpret two-digit year strings.
Definition: smpdtfmt.h:1602
virtual UnicodeString & format(Calendar &cal, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Format a date or time, which is the standard millis since 24:00 GMT, Jan 1, 1970.
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
virtual void applyPattern(const UnicodeString &pattern)
Apply the given unlocalized pattern string to this date format.
virtual void adoptDateFormatSymbols(DateFormatSymbols *newFormatSymbols)
Set the date/time formatting symbols.
virtual void parse(const UnicodeString &text, Calendar &cal, ParsePosition &pos) const
Parse a date/time string beginning at the given parse position.
UBool isFieldUnitIgnored(UCalendarDateFields field) const
This is for ICU internal use only.
virtual ~SimpleDateFormat()
Destructor.
SimpleDateFormat(const SimpleDateFormat &)
Copy constructor.
SimpleDateFormat(const UnicodeString &pattern, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and the default locale.
virtual void adoptTimeZoneFormat(TimeZoneFormat *timeZoneFormatToAdopt)
Sets the TimeZoneFormat to be used by this date/time formatter.
TimeZoneFormat supports time zone display name formatting and parsing.
Definition: tzfmt.h:270
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:129
UMemory is the common ICU base class.
Definition: uobject.h:110
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:294
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:202
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:183
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat.
Definition: udat.h:488
C API: Display context types (enum values)
UDisplayContext
Display context settings.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition: umachine.h:312
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
Basic definitions for ICU, for both C and C++ APIs.
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition: utypes.h:186
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:476
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:358
double UDate
Date and Time data type.
Definition: utypes.h:201
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129