2 ********************************************************************************
3 * Copyright (C) 2005-2007, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ********************************************************************************
9 ********************************************************************************
15 #include "unicode/utypes.h"
19 #if !UCONFIG_NO_FORMATTING
21 #include "unicode/format.h"
22 #include "unicode/datefmt.h"
23 #include "unicode/calendar.h"
24 #include "unicode/ustring.h"
25 #include "unicode/locid.h"
29 * \brief C++ API: Format dates using Windows API.
33 // Forward declarations for Windows types...
34 typedef struct _SYSTEMTIME SYSTEMTIME
;
35 typedef struct _TIME_ZONE_INFORMATION TIME_ZONE_INFORMATION
;
40 class Win32DateFormat
: public DateFormat
43 Win32DateFormat(DateFormat::EStyle timeStyle
, DateFormat::EStyle dateStyle
, const Locale
&locale
, UErrorCode
&status
);
45 Win32DateFormat(const Win32DateFormat
&other
);
47 virtual ~Win32DateFormat();
49 virtual Format
*clone(void) const;
51 Win32DateFormat
&operator=(const Win32DateFormat
&other
);
53 UnicodeString
&format(Calendar
&cal
, UnicodeString
&appendTo
, FieldPosition
&pos
) const;
55 UnicodeString
& format(UDate date
, UnicodeString
& appendTo
) const;
57 void parse(const UnicodeString
& text
, Calendar
& cal
, ParsePosition
& pos
) const;
60 * Set the calendar to be used by this date format. Initially, the default
61 * calendar for the specified or default locale is used. The caller should
62 * not delete the Calendar object after it is adopted by this call.
64 * @param calendarToAdopt Calendar object to be adopted.
67 virtual void adoptCalendar(Calendar
* calendarToAdopt
);
70 * Set the calendar to be used by this date format. Initially, the default
71 * calendar for the specified or default locale is used.
73 * @param newCalendar Calendar object to be set.
77 virtual void setCalendar(const Calendar
& newCalendar
);
80 * Sets the time zone for the calendar of this DateFormat object. The caller
81 * no longer owns the TimeZone object and should not delete it after this call.
83 * @param zoneToAdopt the TimeZone to be adopted.
87 virtual void adoptTimeZone(TimeZone
* zoneToAdopt
);
90 * Sets the time zone for the calendar of this DateFormat object.
91 * @param zone the new time zone.
95 virtual void setTimeZone(const TimeZone
& zone
);
98 * Return the class ID for this class. This is useful only for comparing to
99 * a return value from getDynamicClassID(). For example:
101 * . Base* polymorphic_pointer = createPolymorphicObject();
102 * . if (polymorphic_pointer->getDynamicClassID() ==
103 * . erived::getStaticClassID()) ...
105 * @return The class ID for all objects of this class.
108 U_I18N_API
static UClassID U_EXPORT2
getStaticClassID(void);
111 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
112 * method is to implement a simple version of RTTI, since not all C++
113 * compilers support genuine RTTI. Polymorphic operator==() and clone()
114 * methods call this method.
116 * @return The class ID for this object. All objects of a
117 * given class have the same class ID. Objects of
118 * other classes have different class IDs.
121 virtual UClassID
getDynamicClassID(void) const;
124 void formatDate(const SYSTEMTIME
*st
, UnicodeString
&appendTo
) const;
125 void formatTime(const SYSTEMTIME
*st
, UnicodeString
&appendTo
) const;
127 UnicodeString
setTimeZoneInfo(TIME_ZONE_INFORMATION
*tzi
, const TimeZone
&zone
) const;
129 UnicodeString
*fDateTimeMsg
;
130 DateFormat::EStyle fTimeStyle
;
131 DateFormat::EStyle fDateStyle
;
132 const Locale
*fLocale
;
134 UnicodeString fZoneID
;
135 TIME_ZONE_INFORMATION
*fTZI
;
138 inline UnicodeString
&Win32DateFormat::format(UDate date
, UnicodeString
& appendTo
) const {
139 return DateFormat::format(date
, appendTo
);
144 #endif /* #if !UCONFIG_NO_FORMATTING */
146 #endif // #ifdef U_WINDOWS