- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- Search for |

- File List
- Globals

# smpdtfmt.h

Go to the documentation of this file.

    00001 /*
    00002 * Copyright (C) 1997-2006, International Business Machines Corporation and others. All Rights Reserved.
    00003 *******************************************************************************
    00004 *
    00005 * File SMPDTFMT.H
    00006 *
    00007 * Modification History:
    00008 *
    00009 *   Date        Name        Description
    00010 *   02/19/97    aliu        Converted from java.
    00011 *   07/09/97    helena      Make ParsePosition into a class.
    00012 *   07/21/98    stephen     Added GMT_PLUS, GMT_MINUS
    00013 *                            Changed setTwoDigitStartDate to set2DigitYearStart
    00014 *                            Changed getTwoDigitStartDate to get2DigitYearStart
    00015 *                            Removed subParseLong
    00016 *                            Removed getZoneIndex (added in DateFormatSymbols)
    00017 *   06/14/99    stephen     Removed fgTimeZoneDataSuffix
    00018 *   10/14/99    aliu        Updated class doc to describe 2-digit year parsing
    00019 *                           {j28 4182066}.
    00020 *******************************************************************************
    00021 */
    00022
    00023 #ifndef SMPDTFMT_H
    00024 #define SMPDTFMT_H
    00025
    00026 #include "unicode/utypes.h"
    00027
    00033 #if !UCONFIG_NO_FORMATTING
    00034
    00035 #include "unicode/datefmt.h"
    00036
    00037 U_NAMESPACE_BEGIN
    00038
    00039 class DateFormatSymbols;
    00040 class DateFormat;
    00041
    00206 class U_I18N_API SimpleDateFormat: public DateFormat {
    00207 public:
    00217     SimpleDateFormat(UErrorCode& status);
    00218
    00230     SimpleDateFormat(const UnicodeString& pattern,
    00231                      UErrorCode& status);
    00232
    00245     SimpleDateFormat(const UnicodeString& pattern,
    00246                      const Locale& locale,
    00247                      UErrorCode& status);
    00248
    00258     SimpleDateFormat(const UnicodeString& pattern,
    00259                      DateFormatSymbols* formatDataToAdopt,
    00260                      UErrorCode& status);
    00261
    00271     SimpleDateFormat(const UnicodeString& pattern,
    00272                      const DateFormatSymbols& formatData,
    00273                      UErrorCode& status);
    00274
    00279     SimpleDateFormat(const SimpleDateFormat&);
    00280
    00285     SimpleDateFormat& operator=(const SimpleDateFormat&);
    00286
    00291     virtual ~SimpleDateFormat();
    00292
    00299     virtual Format* clone(void) const;
    00300
    00308     virtual UBool operator==(const Format& other) const;
    00309
    00326     virtual UnicodeString& format(  Calendar& cal,
    00327                                     UnicodeString& appendTo,
    00328                                     FieldPosition& pos) const;
    00329
    00349     virtual UnicodeString& format(  const Formattable& obj,
    00350                                     UnicodeString& appendTo,
    00351                                     FieldPosition& pos,
    00352                                     UErrorCode& status) const;
    00353
    00364     UnicodeString& format(UDate date,
    00365                           UnicodeString& appendTo,
    00366                           FieldPosition& fieldPosition) const;
    00367
    00377     UnicodeString& format(const Formattable& obj,
    00378                           UnicodeString& appendTo,
    00379                           UErrorCode& status) const;
    00380
    00389     UnicodeString& format(UDate date, UnicodeString& appendTo) const;
    00390
    00410     virtual void parse( const UnicodeString& text,
    00411                         Calendar& cal,
    00412                         ParsePosition& pos) const;
    00413
    00433     UDate parse( const UnicodeString& text,
    00434                  ParsePosition& pos) const;
    00435
    00436
    00452     virtual UDate parse( const UnicodeString& text,
    00453                         UErrorCode& status) const;
    00454
    00471     virtual void set2DigitYearStart(UDate d, UErrorCode& status);
    00472
    00488     UDate get2DigitYearStart(UErrorCode& status) const;
    00489
    00496     virtual UnicodeString& toPattern(UnicodeString& result) const;
    00497
    00514     virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
    00515                                               UErrorCode& status) const;
    00516
    00525     virtual void applyPattern(const UnicodeString& pattern);
    00526
    00537     virtual void applyLocalizedPattern(const UnicodeString& pattern,
    00538                                        UErrorCode& status);
    00539
    00548     virtual const DateFormatSymbols* getDateFormatSymbols(void) const;
    00549
    00556     virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
    00557
    00563     virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
    00564
    00576     static UClassID U_EXPORT2 getStaticClassID(void);
    00577
    00589     virtual UClassID getDynamicClassID(void) const;
    00590
    00600     virtual void adoptCalendar(Calendar* calendarToAdopt);
    00601
    00602 private:
    00603     friend class DateFormat;
    00604
    00605     void initializeDefaultCentury(void);
    00606
    00607     SimpleDateFormat(); // default constructor not implemented
    00608
    00617     SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
    00618
    00627     SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
    00628
    00645     void subFormat(             UnicodeString &appendTo,
    00646                                 UChar ch,
    00647                                 int32_t count,
    00648                                 FieldPosition& pos,
    00649                                 Calendar& cal,
    00650                                 UErrorCode& status) const; // in case of illegal argument
    00651
    00657     void zoneIDCanonicalize( UnicodeString & ) const;
    00658
    00671     void zeroPaddingNumber(          UnicodeString &appendTo,
    00672                                      int32_t value,
    00673                                      int32_t minDigits,
    00674                                      int32_t maxDigits) const;
    00675
    00680     static UBool isNumeric(UChar formatChar, int32_t count);
    00681
    00689     Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
    00690
    00697     void initializeSymbols(const Locale& locale, Calendar* calendar, UErrorCode& status);
    00698
    00708     void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
    00709
    00716     void initialize(const Locale& locale, UErrorCode& status);
    00717
    00730     int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
    00731                         const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
    00732
    00745     int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
    00746                                const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
    00747
    00762     int32_t subParse(const UnicodeString& text, int32_t& start, UChar ch, int32_t count,
    00763                      UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], Calendar& cal) const;
    00764
    00765     void parseInt(const UnicodeString& text,
    00766                   Formattable& number,
    00767                   ParsePosition& pos,
    00768                   UBool allowNegative) const;
    00769
    00782     static void translatePattern(const UnicodeString& originalPattern,
    00783                                 UnicodeString& translatedPattern,
    00784                                 const UnicodeString& from,
    00785                                 const UnicodeString& to,
    00786                                 UErrorCode& status);
    00787
    00795     void         parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
    00796
    00809     int32_t      subParseZoneString(const UnicodeString& text, int32_t start, Calendar& cal, UErrorCode& status) const;
    00810
    00814     inline void appendGMT(UnicodeString &appendTo, Calendar& cal, UErrorCode& status) const;
    00815
    00819     static const UCalendarDateFields fgPatternIndexToCalendarField[];
    00820
    00824     static const UDateFormatField fgPatternIndexToDateFormatField[];
    00825
    00829     UnicodeString       fPattern;
    00830
    00834     Locale              fLocale;
    00835
    00840     DateFormatSymbols*  fSymbols;   // Owned
    00841
    00850     UDate                fDefaultCenturyStart;
    00851
    00855     /*transient*/ int32_t   fDefaultCenturyStartYear;
    00856
    00857     /*transient*/ TimeZone* parsedTimeZone; // here to avoid api change
    00858
    00859     UBool fHaveDefaultCentury;
    00860 };
    00861
    00862 inline UDate
    00863 SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
    00864 {
    00865     return fDefaultCenturyStart;
    00866 }
    00867
    00868 inline UnicodeString&
    00869 SimpleDateFormat::format(const Formattable& obj,
    00870                          UnicodeString& appendTo,
    00871                          UErrorCode& status) const {
    00872     // Don't use Format:: - use immediate base class only,
    00873     // in case immediate base modifies behavior later.
    00874     return DateFormat::format(obj, appendTo, status);
    00875 }
    00876
    00877 inline UnicodeString&
    00878 SimpleDateFormat::format(UDate date,
    00879                          UnicodeString& appendTo,
    00880                          FieldPosition& fieldPosition) const {
    00881     // Don't use Format:: - use immediate base class only,
    00882     // in case immediate base modifies behavior later.
    00883     return DateFormat::format(date, appendTo, fieldPosition);
    00884 }
    00885
    00886 inline UnicodeString&
    00887 SimpleDateFormat::format(UDate date, UnicodeString& appendTo) const {
    00888     return DateFormat::format(date, appendTo);
    00889 }
    00890
    00891 U_NAMESPACE_END
    00892
    00893 #endif /* #if !UCONFIG_NO_FORMATTING */
    00894
    00895 #endif // _SMPDTFMT
    00896 //eof