1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ********************************************************************************
5 * Copyright (C) 2005-2015, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ********************************************************************************
11 ********************************************************************************
17 #include "unicode/utypes.h"
19 #if U_PLATFORM_HAS_WIN32_API
21 #if !UCONFIG_NO_FORMATTING
23 #include "unicode/format.h"
24 #include "unicode/datefmt.h"
25 #include "unicode/calendar.h"
26 #include "unicode/ustring.h"
27 #include "unicode/locid.h"
31 * \brief C++ API: Format dates using Windows API.
35 // Forward declarations for Windows types...
36 typedef struct _SYSTEMTIME SYSTEMTIME;
37 typedef struct _TIME_ZONE_INFORMATION TIME_ZONE_INFORMATION;
42 class Win32DateFormat : public DateFormat
45 Win32DateFormat(DateFormat::EStyle timeStyle, DateFormat::EStyle dateStyle, const Locale &locale, UErrorCode &status);
47 Win32DateFormat(const Win32DateFormat &other);
49 virtual ~Win32DateFormat();
51 virtual Format *clone(void) const;
53 Win32DateFormat &operator=(const Win32DateFormat &other);
55 UnicodeString &format(Calendar &cal, UnicodeString &appendTo, FieldPosition &pos) const;
57 using DateFormat::format;
59 void parse(const UnicodeString& text, Calendar& cal, ParsePosition& pos) const;
62 * Set the calendar to be used by this date format. Initially, the default
63 * calendar for the specified or default locale is used. The caller should
64 * not delete the Calendar object after it is adopted by this call.
66 * @param calendarToAdopt Calendar object to be adopted.
68 virtual void adoptCalendar(Calendar* calendarToAdopt);
71 * Set the calendar to be used by this date format. Initially, the default
72 * calendar for the specified or default locale is used.
74 * @param newCalendar Calendar object to be set.
76 virtual void setCalendar(const Calendar& newCalendar);
79 * Sets the time zone for the calendar of this DateFormat object. The caller
80 * no longer owns the TimeZone object and should not delete it after this call.
82 * @param zoneToAdopt the TimeZone to be adopted.
84 virtual void adoptTimeZone(TimeZone* zoneToAdopt);
87 * Sets the time zone for the calendar of this DateFormat object.
88 * @param zone the new time zone.
90 virtual void setTimeZone(const TimeZone& zone);
93 * Return the class ID for this class. This is useful only for comparing to
94 * a return value from getDynamicClassID(). For example:
96 * . Base* polymorphic_pointer = createPolymorphicObject();
97 * . if (polymorphic_pointer->getDynamicClassID() ==
98 * . erived::getStaticClassID()) ...
100 * @return The class ID for all objects of this class.
102 U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
105 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
106 * method is to implement a simple version of RTTI, since not all C++
107 * compilers support genuine RTTI. Polymorphic operator==() and clone()
108 * methods call this method.
110 * @return The class ID for this object. All objects of a
111 * given class have the same class ID. Objects of
112 * other classes have different class IDs.
114 virtual UClassID getDynamicClassID(void) const;
117 void formatDate(const SYSTEMTIME *st, UnicodeString &appendTo) const;
118 void formatTime(const SYSTEMTIME *st, UnicodeString &appendTo) const;
120 UnicodeString setTimeZoneInfo(TIME_ZONE_INFORMATION *tzi, const TimeZone &zone) const;
121 UnicodeString* getTimeDateFormat(const Calendar *cal, const Locale *locale, UErrorCode &status) const;
123 UnicodeString *fDateTimeMsg;
124 DateFormat::EStyle fTimeStyle;
125 DateFormat::EStyle fDateStyle;
128 UnicodeString fZoneID;
129 TIME_ZONE_INFORMATION *fTZI;
134 #endif /* #if !UCONFIG_NO_FORMATTING */
136 #endif // U_PLATFORM_HAS_WIN32_API