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

- Search for |

- File List
- Globals

# datefmt.h

Go to the documentation of this file.

    00001 /*
    00002  ********************************************************************************
    00003  *   Copyright (C) 1997-2009, 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
    00228     virtual UnicodeString& format(const Formattable& obj,
    00229                                   UnicodeString& appendTo,
    00230                                   FieldPosition& pos,
    00231                                   UErrorCode& status) const;
    00232
    00266     virtual UnicodeString& format(  Calendar& cal,
    00267                                     UnicodeString& appendTo,
    00268                                     FieldPosition& fieldPosition) const = 0;
    00269
    00297     UnicodeString& format(  UDate date,
    00298                             UnicodeString& appendTo,
    00299                             FieldPosition& fieldPosition) const;
    00300
    00312     UnicodeString& format(UDate date, UnicodeString& appendTo) const;
    00313
    00324     UnicodeString& format(const Formattable& obj,
    00325                           UnicodeString& appendTo,
    00326                           UErrorCode& status) const;
    00327
    00338     virtual UDate parse( const UnicodeString& text,
    00339                         UErrorCode& status) const;
    00340
    00367     virtual void parse( const UnicodeString& text,
    00368                         Calendar& cal,
    00369                         ParsePosition& pos) const = 0;
    00370
    00390     UDate parse( const UnicodeString& text,
    00391                  ParsePosition& pos) const;
    00392
    00419     virtual void parseObject(const UnicodeString& source,
    00420                              Formattable& result,
    00421                              ParsePosition& parse_pos) const;
    00422
    00430     static DateFormat* U_EXPORT2 createInstance(void);
    00431
    00443     static DateFormat* U_EXPORT2 createTimeInstance(EStyle style = kDefault,
    00444                                           const Locale& aLocale = Locale::getDefault());
    00445
    00456     static DateFormat* U_EXPORT2 createDateInstance(EStyle style = kDefault,
    00457                                           const Locale& aLocale = Locale::getDefault());
    00458
    00472     static DateFormat* U_EXPORT2 createDateTimeInstance(EStyle dateStyle = kDefault,
    00473                                               EStyle timeStyle = kDefault,
    00474                                               const Locale& aLocale = Locale::getDefault());
    00475
    00483     static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
    00484
    00489     virtual UBool isLenient(void) const;
    00490
    00501     virtual void setLenient(UBool lenient);
    00502
    00508     virtual const Calendar* getCalendar(void) const;
    00509
    00519     virtual void adoptCalendar(Calendar* calendarToAdopt);
    00520
    00528     virtual void setCalendar(const Calendar& newCalendar);
    00529
    00530
    00537     virtual const NumberFormat* getNumberFormat(void) const;
    00538
    00545     virtual void adoptNumberFormat(NumberFormat* formatToAdopt);
    00546
    00552     virtual void setNumberFormat(const NumberFormat& newNumberFormat);
    00553
    00559     virtual const TimeZone& getTimeZone(void) const;
    00560
    00567     virtual void adoptTimeZone(TimeZone* zoneToAdopt);
    00568
    00574     virtual void setTimeZone(const TimeZone& zone);
    00575
    00576 protected:
    00583     DateFormat();
    00584
    00589     DateFormat(const DateFormat&);
    00590
    00595     DateFormat& operator=(const DateFormat&);
    00596
    00603     Calendar* fCalendar;
    00604
    00611     NumberFormat* fNumberFormat;
    00612
    00613 private:
    00622     static DateFormat* U_EXPORT2 create(EStyle timeStyle, EStyle dateStyle, const Locale&);
    00623
    00624 public:
    00630     enum EField
    00631     {
    00632         // Obsolete; use UDateFormatField instead
    00633         kEraField = UDAT_ERA_FIELD,
    00634         kYearField = UDAT_YEAR_FIELD,
    00635         kMonthField = UDAT_MONTH_FIELD,
    00636         kDateField = UDAT_DATE_FIELD,
    00637         kHourOfDay1Field = UDAT_HOUR_OF_DAY1_FIELD,
    00638         kHourOfDay0Field = UDAT_HOUR_OF_DAY0_FIELD,
    00639         kMinuteField = UDAT_MINUTE_FIELD,
    00640         kSecondField = UDAT_SECOND_FIELD,
    00641         kMillisecondField = UDAT_FRACTIONAL_SECOND_FIELD,
    00642         kDayOfWeekField = UDAT_DAY_OF_WEEK_FIELD,
    00643         kDayOfYearField = UDAT_DAY_OF_YEAR_FIELD,
    00644         kDayOfWeekInMonthField = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
    00645         kWeekOfYearField = UDAT_WEEK_OF_YEAR_FIELD,
    00646         kWeekOfMonthField = UDAT_WEEK_OF_MONTH_FIELD,
    00647         kAmPmField = UDAT_AM_PM_FIELD,
    00648         kHour1Field = UDAT_HOUR1_FIELD,
    00649         kHour0Field = UDAT_HOUR0_FIELD,
    00650         kTimezoneField = UDAT_TIMEZONE_FIELD,
    00651         kYearWOYField = UDAT_YEAR_WOY_FIELD,
    00652         kDOWLocalField = UDAT_DOW_LOCAL_FIELD,
    00653         kExtendedYearField = UDAT_EXTENDED_YEAR_FIELD,
    00654         kJulianDayField = UDAT_JULIAN_DAY_FIELD,
    00655         kMillisecondsInDayField = UDAT_MILLISECONDS_IN_DAY_FIELD,
    00656
    00657         // Obsolete; use UDateFormatField instead
    00658         ERA_FIELD = UDAT_ERA_FIELD,
    00659         YEAR_FIELD = UDAT_YEAR_FIELD,
    00660         MONTH_FIELD = UDAT_MONTH_FIELD,
    00661         DATE_FIELD = UDAT_DATE_FIELD,
    00662         HOUR_OF_DAY1_FIELD = UDAT_HOUR_OF_DAY1_FIELD,
    00663         HOUR_OF_DAY0_FIELD = UDAT_HOUR_OF_DAY0_FIELD,
    00664         MINUTE_FIELD = UDAT_MINUTE_FIELD,
    00665         SECOND_FIELD = UDAT_SECOND_FIELD,
    00666         MILLISECOND_FIELD = UDAT_FRACTIONAL_SECOND_FIELD,
    00667         DAY_OF_WEEK_FIELD = UDAT_DAY_OF_WEEK_FIELD,
    00668         DAY_OF_YEAR_FIELD = UDAT_DAY_OF_YEAR_FIELD,
    00669         DAY_OF_WEEK_IN_MONTH_FIELD = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
    00670         WEEK_OF_YEAR_FIELD = UDAT_WEEK_OF_YEAR_FIELD,
    00671         WEEK_OF_MONTH_FIELD = UDAT_WEEK_OF_MONTH_FIELD,
    00672         AM_PM_FIELD = UDAT_AM_PM_FIELD,
    00673         HOUR1_FIELD = UDAT_HOUR1_FIELD,
    00674         HOUR0_FIELD = UDAT_HOUR0_FIELD,
    00675         TIMEZONE_FIELD = UDAT_TIMEZONE_FIELD
    00676     };
    00677 };
    00678
    00679 inline UnicodeString&
    00680 DateFormat::format(const Formattable& obj,
    00681                    UnicodeString& appendTo,
    00682                    UErrorCode& status) const {
    00683     return Format::format(obj, appendTo, status);
    00684 }
    00685 U_NAMESPACE_END
    00686
    00687 #endif /* #if !UCONFIG_NO_FORMATTING */
    00688
    00689 #endif // _DATEFMT
    00690 //eof