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

- Search for |

- File List
- Globals

# datefmt.h

Go to the documentation of this file.

    00001 /*
    00002  ********************************************************************************
    00003  *   Copyright (C) 1997-2007, 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
    00137 class U_I18N_API DateFormat : public Format {
    00138 public:
    00139
    00147     enum EStyle
    00148     {
    00149         kNone   = -1,
    00150
    00151         kFull   = 0,
    00152         kLong   = 1,
    00153         kMedium = 2,
    00154         kShort  = 3,
    00155
    00156         kDateOffset   = kShort + 1,
    00157      // kFull   + kDateOffset = 4
    00158      // kLong   + kDateOffset = 5
    00159      // kMedium + kDateOffset = 6
    00160      // kShort  + kDateOffset = 7
    00161
    00162         kDateTime             = 8,
    00163
    00164
    00165         // relative dates
    00166         kRelative = (1 << 7),
    00167
    00168         kFullRelative = (kFull | kRelative),
    00169
    00170         kLongRelative = kLong | kRelative,
    00171
    00172         kMediumRelative = kMedium | kRelative,
    00173
    00174         kShortRelative = kShort | kRelative,
    00175
    00176
    00177         kDefault      = kMedium,
    00178
    00179
    00180
    00185         FULL        = kFull,
    00186         LONG        = kLong,
    00187         MEDIUM        = kMedium,
    00188         SHORT        = kShort,
    00189         DEFAULT        = kDefault,
    00190         DATE_OFFSET    = kDateOffset,
    00191         NONE        = kNone,
    00192         DATE_TIME    = kDateTime
    00193     };
    00194
    00199     virtual ~DateFormat();
    00200
    00205     virtual UBool operator==(const Format&) const;
    00206
    00221     virtual UnicodeString& format(const Formattable& obj,
    00222                                   UnicodeString& appendTo,
    00223                                   FieldPosition& pos,
    00224                                   UErrorCode& status) const;
    00225
    00255     virtual UnicodeString& format(  Calendar& cal,
    00256                                     UnicodeString& appendTo,
    00257                                     FieldPosition& fieldPosition) const = 0;
    00258
    00286     UnicodeString& format(  UDate date,
    00287                             UnicodeString& appendTo,
    00288                             FieldPosition& fieldPosition) const;
    00289
    00301     UnicodeString& format(UDate date, UnicodeString& appendTo) const;
    00302
    00313     UnicodeString& format(const Formattable& obj,
    00314                           UnicodeString& appendTo,
    00315                           UErrorCode& status) const;
    00316
    00327     virtual UDate parse( const UnicodeString& text,
    00328                         UErrorCode& status) const;
    00329
    00351     virtual void parse( const UnicodeString& text,
    00352                         Calendar& cal,
    00353                         ParsePosition& pos) const = 0;
    00354
    00374     UDate parse( const UnicodeString& text,
    00375                  ParsePosition& pos) const;
    00376
    00403     virtual void parseObject(const UnicodeString& source,
    00404                              Formattable& result,
    00405                              ParsePosition& parse_pos) const;
    00406
    00414     static DateFormat* U_EXPORT2 createInstance(void);
    00415
    00426     static DateFormat* U_EXPORT2 createTimeInstance(EStyle style = kDefault,
    00427                                           const Locale& aLocale = Locale::getDefault());
    00428
    00439     static DateFormat* U_EXPORT2 createDateInstance(EStyle style = kDefault,
    00440                                           const Locale& aLocale = Locale::getDefault());
    00441
    00454     static DateFormat* U_EXPORT2 createDateTimeInstance(EStyle dateStyle = kDefault,
    00455                                               EStyle timeStyle = kDefault,
    00456                                               const Locale& aLocale = Locale::getDefault());
    00457
    00465     static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
    00466
    00471     virtual UBool isLenient(void) const;
    00472
    00483     virtual void setLenient(UBool lenient);
    00484
    00490     virtual const Calendar* getCalendar(void) const;
    00491
    00501     virtual void adoptCalendar(Calendar* calendarToAdopt);
    00502
    00510     virtual void setCalendar(const Calendar& newCalendar);
    00511
    00512
    00519     virtual const NumberFormat* getNumberFormat(void) const;
    00520
    00527     virtual void adoptNumberFormat(NumberFormat* formatToAdopt);
    00528
    00534     virtual void setNumberFormat(const NumberFormat& newNumberFormat);
    00535
    00541     virtual const TimeZone& getTimeZone(void) const;
    00542
    00549     virtual void adoptTimeZone(TimeZone* zoneToAdopt);
    00550
    00556     virtual void setTimeZone(const TimeZone& zone);
    00557
    00558 protected:
    00565     DateFormat();
    00566
    00571     DateFormat(const DateFormat&);
    00572
    00577     DateFormat& operator=(const DateFormat&);
    00578
    00585     Calendar* fCalendar;
    00586
    00593     NumberFormat* fNumberFormat;
    00594
    00595 private:
    00604     static DateFormat* U_EXPORT2 create(EStyle timeStyle, EStyle dateStyle, const Locale&);
    00605
    00606 public:
    00612     enum EField
    00613     {
    00614         // Obsolete; use UDateFormatField instead
    00615         kEraField = UDAT_ERA_FIELD,
    00616         kYearField = UDAT_YEAR_FIELD,
    00617         kMonthField = UDAT_MONTH_FIELD,
    00618         kDateField = UDAT_DATE_FIELD,
    00619         kHourOfDay1Field = UDAT_HOUR_OF_DAY1_FIELD,
    00620         kHourOfDay0Field = UDAT_HOUR_OF_DAY0_FIELD,
    00621         kMinuteField = UDAT_MINUTE_FIELD,
    00622         kSecondField = UDAT_SECOND_FIELD,
    00623         kMillisecondField = UDAT_FRACTIONAL_SECOND_FIELD,
    00624         kDayOfWeekField = UDAT_DAY_OF_WEEK_FIELD,
    00625         kDayOfYearField = UDAT_DAY_OF_YEAR_FIELD,
    00626         kDayOfWeekInMonthField = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
    00627         kWeekOfYearField = UDAT_WEEK_OF_YEAR_FIELD,
    00628         kWeekOfMonthField = UDAT_WEEK_OF_MONTH_FIELD,
    00629         kAmPmField = UDAT_AM_PM_FIELD,
    00630         kHour1Field = UDAT_HOUR1_FIELD,
    00631         kHour0Field = UDAT_HOUR0_FIELD,
    00632         kTimezoneField = UDAT_TIMEZONE_FIELD,
    00633         kYearWOYField = UDAT_YEAR_WOY_FIELD,
    00634         kDOWLocalField = UDAT_DOW_LOCAL_FIELD,
    00635         kExtendedYearField = UDAT_EXTENDED_YEAR_FIELD,
    00636         kJulianDayField = UDAT_JULIAN_DAY_FIELD,
    00637         kMillisecondsInDayField = UDAT_MILLISECONDS_IN_DAY_FIELD,
    00638
    00639         // Obsolete; use UDateFormatField instead
    00640         ERA_FIELD = UDAT_ERA_FIELD,
    00641         YEAR_FIELD = UDAT_YEAR_FIELD,
    00642         MONTH_FIELD = UDAT_MONTH_FIELD,
    00643         DATE_FIELD = UDAT_DATE_FIELD,
    00644         HOUR_OF_DAY1_FIELD = UDAT_HOUR_OF_DAY1_FIELD,
    00645         HOUR_OF_DAY0_FIELD = UDAT_HOUR_OF_DAY0_FIELD,
    00646         MINUTE_FIELD = UDAT_MINUTE_FIELD,
    00647         SECOND_FIELD = UDAT_SECOND_FIELD,
    00648         MILLISECOND_FIELD = UDAT_FRACTIONAL_SECOND_FIELD,
    00649         DAY_OF_WEEK_FIELD = UDAT_DAY_OF_WEEK_FIELD,
    00650         DAY_OF_YEAR_FIELD = UDAT_DAY_OF_YEAR_FIELD,
    00651         DAY_OF_WEEK_IN_MONTH_FIELD = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
    00652         WEEK_OF_YEAR_FIELD = UDAT_WEEK_OF_YEAR_FIELD,
    00653         WEEK_OF_MONTH_FIELD = UDAT_WEEK_OF_MONTH_FIELD,
    00654         AM_PM_FIELD = UDAT_AM_PM_FIELD,
    00655         HOUR1_FIELD = UDAT_HOUR1_FIELD,
    00656         HOUR0_FIELD = UDAT_HOUR0_FIELD,
    00657         TIMEZONE_FIELD = UDAT_TIMEZONE_FIELD
    00658     };
    00659 };
    00660
    00661 inline UnicodeString&
    00662 DateFormat::format(const Formattable& obj,
    00663                    UnicodeString& appendTo,
    00664                    UErrorCode& status) const {
    00665     return Format::format(obj, appendTo, status);
    00666 }
    00667 U_NAMESPACE_END
    00668
    00669 #endif /* #if !UCONFIG_NO_FORMATTING */
    00670
    00671 #endif // _DATEFMT
    00672 //eof