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

- File List
- Globals

# datefmt.h

Go to the documentation of this file.

    00001 /*
    00002  ********************************************************************************
    00003  *   Copyright (C) 1997-2010, International Business Machines
    00004  *   Corporation and others.  All Rights Reserved.
    00005  ********************************************************************************
    00006  *
    00007  * File DATEFMT.H
    00008  *
    00009  * Modification History:
    00010  *
    00011  *   Date        Name        Description
    00012  *   02/19/97    aliu        Converted from java.
    00013  *   04/01/97    aliu        Added support for centuries.
    00014  *   07/23/98    stephen     JDK 1.2 sync
    00015  *   11/15/99    weiv        Added support for week of year/day of week formatting
    00016  ********************************************************************************
    00017  */
    00018
    00019 #ifndef DATEFMT_H
    00020 #define DATEFMT_H
    00021
    00022 #include "unicode/utypes.h"
    00023
    00024 #if !UCONFIG_NO_FORMATTING
    00025
    00026 #include "unicode/udat.h"
    00027 #include "unicode/calendar.h"
    00028 #include "unicode/numfmt.h"
    00029 #include "unicode/format.h"
    00030 #include "unicode/locid.h"
    00031
    00037 U_NAMESPACE_BEGIN
    00038
    00039 class TimeZone;
    00040 class DateTimePatternGenerator;
    00041
    00138 class U_I18N_API DateFormat : public Format {
    00139 public:
    00140
    00148     enum EStyle
    00149     {
    00150         kNone   = -1,
    00151
    00152         kFull   = 0,
    00153         kLong   = 1,
    00154         kMedium = 2,
    00155         kShort  = 3,
    00156
    00157         kDateOffset   = kShort + 1,
    00158      // kFull   + kDateOffset = 4
    00159      // kLong   + kDateOffset = 5
    00160      // kMedium + kDateOffset = 6
    00161      // kShort  + kDateOffset = 7
    00162
    00163         kDateTime             = 8,
    00164      // Default DateTime
    00165
    00166         kDateTimeOffset = kDateTime + 1,
    00167      // kFull   + kDateTimeOffset = 9
    00168      // kLong   + kDateTimeOffset = 10
    00169      // kMedium + kDateTimeOffset = 11
    00170      // kShort  + kDateTimeOffset = 12
    00171
    00172         // relative dates
    00173         kRelative = (1 << 7),
    00174
    00175         kFullRelative = (kFull | kRelative),
    00176
    00177         kLongRelative = kLong | kRelative,
    00178
    00179         kMediumRelative = kMedium | kRelative,
    00180
    00181         kShortRelative = kShort | kRelative,
    00182
    00183
    00184         kDefault      = kMedium,
    00185
    00186
    00187
    00192         FULL        = kFull,
    00193         LONG        = kLong,
    00194         MEDIUM        = kMedium,
    00195         SHORT        = kShort,
    00196         DEFAULT        = kDefault,
    00197         DATE_OFFSET    = kDateOffset,
    00198         NONE        = kNone,
    00199         DATE_TIME    = kDateTime
    00200     };
    00201
    00206     virtual ~DateFormat();
    00207
    00212     virtual UBool operator==(const Format&) const;
    00213
    00214
    00215     using Format::format;
    00216
    00231     virtual UnicodeString& format(const Formattable& obj,
    00232                                   UnicodeString& appendTo,
    00233                                   FieldPosition& pos,
    00234                                   UErrorCode& status) const;
    00235
    00251     virtual UnicodeString& format(const Formattable& obj,
    00252                                   UnicodeString& appendTo,
    00253                                   FieldPositionIterator* posIter,
    00254                                   UErrorCode& status) const;
    00288     virtual UnicodeString& format(  Calendar& cal,
    00289                                     UnicodeString& appendTo,
    00290                                     FieldPosition& fieldPosition) const = 0;
    00291
    00310     virtual UnicodeString& format(Calendar& cal,
    00311                                   UnicodeString& appendTo,
    00312                                   FieldPositionIterator* posIter,
    00313                                   UErrorCode& status) const;
    00341     UnicodeString& format(  UDate date,
    00342                             UnicodeString& appendTo,
    00343                             FieldPosition& fieldPosition) const;
    00344
    00358     UnicodeString& format(UDate date,
    00359                           UnicodeString& appendTo,
    00360                           FieldPositionIterator* posIter,
    00361                           UErrorCode& status) const;
    00373     UnicodeString& format(UDate date, UnicodeString& appendTo) const;
    00374
    00385     UnicodeString& format(const Formattable& obj,
    00386                           UnicodeString& appendTo,
    00387                           UErrorCode& status) const;
    00388
    00399     virtual UDate parse( const UnicodeString& text,
    00400                         UErrorCode& status) const;
    00401
    00428     virtual void parse( const UnicodeString& text,
    00429                         Calendar& cal,
    00430                         ParsePosition& pos) const = 0;
    00431
    00451     UDate parse( const UnicodeString& text,
    00452                  ParsePosition& pos) const;
    00453
    00480     virtual void parseObject(const UnicodeString& source,
    00481                              Formattable& result,
    00482                              ParsePosition& parse_pos) const;
    00483
    00491     static DateFormat* U_EXPORT2 createInstance(void);
    00492
    00504     static DateFormat* U_EXPORT2 createTimeInstance(EStyle style = kDefault,
    00505                                           const Locale& aLocale = Locale::getDefault());
    00506
    00517     static DateFormat* U_EXPORT2 createDateInstance(EStyle style = kDefault,
    00518                                           const Locale& aLocale = Locale::getDefault());
    00519
    00533     static DateFormat* U_EXPORT2 createDateTimeInstance(EStyle dateStyle = kDefault,
    00534                                               EStyle timeStyle = kDefault,
    00535                                               const Locale& aLocale = Locale::getDefault());
    00536
    00544     static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
    00545
    00550     virtual UBool isLenient(void) const;
    00551
    00562     virtual void setLenient(UBool lenient);
    00563
    00569     virtual const Calendar* getCalendar(void) const;
    00570
    00580     virtual void adoptCalendar(Calendar* calendarToAdopt);
    00581
    00589     virtual void setCalendar(const Calendar& newCalendar);
    00590
    00591
    00598     virtual const NumberFormat* getNumberFormat(void) const;
    00599
    00606     virtual void adoptNumberFormat(NumberFormat* formatToAdopt);
    00607
    00613     virtual void setNumberFormat(const NumberFormat& newNumberFormat);
    00614
    00620     virtual const TimeZone& getTimeZone(void) const;
    00621
    00628     virtual void adoptTimeZone(TimeZone* zoneToAdopt);
    00629
    00635     virtual void setTimeZone(const TimeZone& zone);
    00636
    00637 protected:
    00644     DateFormat();
    00645
    00650     DateFormat(const DateFormat&);
    00651
    00656     DateFormat& operator=(const DateFormat&);
    00657
    00664     Calendar* fCalendar;
    00665
    00672     NumberFormat* fNumberFormat;
    00673
    00674 private:
    00683     static DateFormat* U_EXPORT2 create(EStyle timeStyle, EStyle dateStyle, const Locale&);
    00684
    00685 public:
    00691     enum EField
    00692     {
    00693         // Obsolete; use UDateFormatField instead
    00694         kEraField = UDAT_ERA_FIELD,
    00695         kYearField = UDAT_YEAR_FIELD,
    00696         kMonthField = UDAT_MONTH_FIELD,
    00697         kDateField = UDAT_DATE_FIELD,
    00698         kHourOfDay1Field = UDAT_HOUR_OF_DAY1_FIELD,
    00699         kHourOfDay0Field = UDAT_HOUR_OF_DAY0_FIELD,
    00700         kMinuteField = UDAT_MINUTE_FIELD,
    00701         kSecondField = UDAT_SECOND_FIELD,
    00702         kMillisecondField = UDAT_FRACTIONAL_SECOND_FIELD,
    00703         kDayOfWeekField = UDAT_DAY_OF_WEEK_FIELD,
    00704         kDayOfYearField = UDAT_DAY_OF_YEAR_FIELD,
    00705         kDayOfWeekInMonthField = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
    00706         kWeekOfYearField = UDAT_WEEK_OF_YEAR_FIELD,
    00707         kWeekOfMonthField = UDAT_WEEK_OF_MONTH_FIELD,
    00708         kAmPmField = UDAT_AM_PM_FIELD,
    00709         kHour1Field = UDAT_HOUR1_FIELD,
    00710         kHour0Field = UDAT_HOUR0_FIELD,
    00711         kTimezoneField = UDAT_TIMEZONE_FIELD,
    00712         kYearWOYField = UDAT_YEAR_WOY_FIELD,
    00713         kDOWLocalField = UDAT_DOW_LOCAL_FIELD,
    00714         kExtendedYearField = UDAT_EXTENDED_YEAR_FIELD,
    00715         kJulianDayField = UDAT_JULIAN_DAY_FIELD,
    00716         kMillisecondsInDayField = UDAT_MILLISECONDS_IN_DAY_FIELD,
    00717
    00718         // Obsolete; use UDateFormatField instead
    00719         ERA_FIELD = UDAT_ERA_FIELD,
    00720         YEAR_FIELD = UDAT_YEAR_FIELD,
    00721         MONTH_FIELD = UDAT_MONTH_FIELD,
    00722         DATE_FIELD = UDAT_DATE_FIELD,
    00723         HOUR_OF_DAY1_FIELD = UDAT_HOUR_OF_DAY1_FIELD,
    00724         HOUR_OF_DAY0_FIELD = UDAT_HOUR_OF_DAY0_FIELD,
    00725         MINUTE_FIELD = UDAT_MINUTE_FIELD,
    00726         SECOND_FIELD = UDAT_SECOND_FIELD,
    00727         MILLISECOND_FIELD = UDAT_FRACTIONAL_SECOND_FIELD,
    00728         DAY_OF_WEEK_FIELD = UDAT_DAY_OF_WEEK_FIELD,
    00729         DAY_OF_YEAR_FIELD = UDAT_DAY_OF_YEAR_FIELD,
    00730         DAY_OF_WEEK_IN_MONTH_FIELD = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
    00731         WEEK_OF_YEAR_FIELD = UDAT_WEEK_OF_YEAR_FIELD,
    00732         WEEK_OF_MONTH_FIELD = UDAT_WEEK_OF_MONTH_FIELD,
    00733         AM_PM_FIELD = UDAT_AM_PM_FIELD,
    00734         HOUR1_FIELD = UDAT_HOUR1_FIELD,
    00735         HOUR0_FIELD = UDAT_HOUR0_FIELD,
    00736         TIMEZONE_FIELD = UDAT_TIMEZONE_FIELD
    00737     };
    00738 };
    00739
    00740 inline UnicodeString&
    00741 DateFormat::format(const Formattable& obj,
    00742                    UnicodeString& appendTo,
    00743                    UErrorCode& status) const {
    00744     return Format::format(obj, appendTo, status);
    00745 }
    00746 U_NAMESPACE_END
    00747
    00748 #endif /* #if !UCONFIG_NO_FORMATTING */
    00749
    00750 #endif // _DATEFMT
    00751 //eof

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines