michael@0: /* michael@0: ******************************************************************************** michael@0: * Copyright (C) 2005-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ******************************************************************************** michael@0: * michael@0: * File WINDTFMT.H michael@0: * michael@0: ******************************************************************************** michael@0: */ michael@0: michael@0: #ifndef __WINDTFMT michael@0: #define __WINDTFMT michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if U_PLATFORM_HAS_WIN32_API michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/format.h" michael@0: #include "unicode/datefmt.h" michael@0: #include "unicode/calendar.h" michael@0: #include "unicode/ustring.h" michael@0: #include "unicode/locid.h" michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: Format dates using Windows API. michael@0: */ michael@0: michael@0: U_CDECL_BEGIN michael@0: // Forward declarations for Windows types... michael@0: typedef struct _SYSTEMTIME SYSTEMTIME; michael@0: typedef struct _TIME_ZONE_INFORMATION TIME_ZONE_INFORMATION; michael@0: U_CDECL_END michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class Win32DateFormat : public DateFormat michael@0: { michael@0: public: michael@0: Win32DateFormat(DateFormat::EStyle timeStyle, DateFormat::EStyle dateStyle, const Locale &locale, UErrorCode &status); michael@0: michael@0: Win32DateFormat(const Win32DateFormat &other); michael@0: michael@0: virtual ~Win32DateFormat(); michael@0: michael@0: virtual Format *clone(void) const; michael@0: michael@0: Win32DateFormat &operator=(const Win32DateFormat &other); michael@0: michael@0: UnicodeString &format(Calendar &cal, UnicodeString &appendTo, FieldPosition &pos) const; michael@0: michael@0: UnicodeString& format(UDate date, UnicodeString& appendTo) const; michael@0: michael@0: void parse(const UnicodeString& text, Calendar& cal, ParsePosition& pos) const; michael@0: michael@0: /** michael@0: * Set the calendar to be used by this date format. Initially, the default michael@0: * calendar for the specified or default locale is used. The caller should michael@0: * not delete the Calendar object after it is adopted by this call. michael@0: * michael@0: * @param calendarToAdopt Calendar object to be adopted. michael@0: */ michael@0: virtual void adoptCalendar(Calendar* calendarToAdopt); michael@0: michael@0: /** michael@0: * Set the calendar to be used by this date format. Initially, the default michael@0: * calendar for the specified or default locale is used. michael@0: * michael@0: * @param newCalendar Calendar object to be set. michael@0: */ michael@0: virtual void setCalendar(const Calendar& newCalendar); michael@0: michael@0: /** michael@0: * Sets the time zone for the calendar of this DateFormat object. The caller michael@0: * no longer owns the TimeZone object and should not delete it after this call. michael@0: * michael@0: * @param zoneToAdopt the TimeZone to be adopted. michael@0: */ michael@0: virtual void adoptTimeZone(TimeZone* zoneToAdopt); michael@0: michael@0: /** michael@0: * Sets the time zone for the calendar of this DateFormat object. michael@0: * @param zone the new time zone. michael@0: */ michael@0: virtual void setTimeZone(const TimeZone& zone); michael@0: michael@0: /** michael@0: * Return the class ID for this class. This is useful only for comparing to michael@0: * a return value from getDynamicClassID(). For example: michael@0: *
michael@0: * . Base* polymorphic_pointer = createPolymorphicObject(); michael@0: * . if (polymorphic_pointer->getDynamicClassID() == michael@0: * . erived::getStaticClassID()) ... michael@0: *michael@0: * @return The class ID for all objects of this class. michael@0: */ michael@0: U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void); michael@0: michael@0: /** michael@0: * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This michael@0: * method is to implement a simple version of RTTI, since not all C++ michael@0: * compilers support genuine RTTI. Polymorphic operator==() and clone() michael@0: * methods call this method. michael@0: * michael@0: * @return The class ID for this object. All objects of a michael@0: * given class have the same class ID. Objects of michael@0: * other classes have different class IDs. michael@0: */ michael@0: virtual UClassID getDynamicClassID(void) const; michael@0: michael@0: private: michael@0: void formatDate(const SYSTEMTIME *st, UnicodeString &appendTo) const; michael@0: void formatTime(const SYSTEMTIME *st, UnicodeString &appendTo) const; michael@0: michael@0: UnicodeString setTimeZoneInfo(TIME_ZONE_INFORMATION *tzi, const TimeZone &zone) const; michael@0: UnicodeString* getTimeDateFormat(const Calendar *cal, const Locale *locale, UErrorCode &status) const; michael@0: michael@0: UnicodeString *fDateTimeMsg; michael@0: DateFormat::EStyle fTimeStyle; michael@0: DateFormat::EStyle fDateStyle; michael@0: Locale fLocale; michael@0: int32_t fLCID; michael@0: UnicodeString fZoneID; michael@0: TIME_ZONE_INFORMATION *fTZI; michael@0: }; michael@0: michael@0: inline UnicodeString &Win32DateFormat::format(UDate date, UnicodeString& appendTo) const { michael@0: return DateFormat::format(date, appendTo); michael@0: } michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: michael@0: #endif // U_PLATFORM_HAS_WIN32_API michael@0: michael@0: #endif // __WINDTFMT