| 1 |
// © 2016 and later: Unicode, Inc. and others. |
| 2 |
// License & terms of use: http://www.unicode.org/copyright.html |
| 3 |
/* |
| 4 |
******************************************************************************** |
| 5 |
* Copyright (C) 2005-2015, International Business Machines |
| 6 |
* Corporation and others. All Rights Reserved. |
| 7 |
******************************************************************************** |
| 8 |
* |
| 9 |
* File WINDTFMT.H |
| 10 |
* |
| 11 |
******************************************************************************** |
| 12 |
*/ |
| 13 |
|
| 14 |
#ifndef __WINDTFMT |
| 15 |
#define __WINDTFMT |
| 16 |
|
| 17 |
#include "unicode/utypes.h" |
| 18 |
|
| 19 |
#if U_PLATFORM_USES_ONLY_WIN32_API |
| 20 |
|
| 21 |
#if !UCONFIG_NO_FORMATTING |
| 22 |
|
| 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" |
| 28 |
|
| 29 |
/** |
| 30 |
* \file |
| 31 |
* \brief C++ API: Format dates using Windows API. |
| 32 |
*/ |
| 33 |
|
| 34 |
U_CDECL_BEGIN |
| 35 |
// Forward declarations for Windows types... |
| 36 |
typedef struct _SYSTEMTIME SYSTEMTIME; |
| 37 |
typedef struct _TIME_ZONE_INFORMATION TIME_ZONE_INFORMATION; |
| 38 |
U_CDECL_END |
| 39 |
|
| 40 |
U_NAMESPACE_BEGIN |
| 41 |
|
| 42 |
class Win32DateFormat : public DateFormat |
| 43 |
{ |
| 44 |
public: |
| 45 |
Win32DateFormat(DateFormat::EStyle timeStyle, DateFormat::EStyle dateStyle, const Locale &locale, UErrorCode &status); |
| 46 |
|
| 47 |
Win32DateFormat(const Win32DateFormat &other); |
| 48 |
|
| 49 |
virtual ~Win32DateFormat(); |
| 50 |
|
| 51 |
virtual Win32DateFormat *clone() const; |
| 52 |
|
| 53 |
Win32DateFormat &operator=(const Win32DateFormat &other); |
| 54 |
|
| 55 |
UnicodeString &format(Calendar &cal, UnicodeString &appendTo, FieldPosition &pos) const; |
| 56 |
|
| 57 |
using DateFormat::format; |
| 58 |
|
| 59 |
void parse(const UnicodeString& text, Calendar& cal, ParsePosition& pos) const; |
| 60 |
|
| 61 |
/** |
| 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. |
| 65 |
* |
| 66 |
* @param calendarToAdopt Calendar object to be adopted. |
| 67 |
*/ |
| 68 |
virtual void adoptCalendar(Calendar* calendarToAdopt); |
| 69 |
|
| 70 |
/** |
| 71 |
* Set the calendar to be used by this date format. Initially, the default |
| 72 |
* calendar for the specified or default locale is used. |
| 73 |
* |
| 74 |
* @param newCalendar Calendar object to be set. |
| 75 |
*/ |
| 76 |
virtual void setCalendar(const Calendar& newCalendar); |
| 77 |
|
| 78 |
/** |
| 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. |
| 81 |
* |
| 82 |
* @param zoneToAdopt the TimeZone to be adopted. |
| 83 |
*/ |
| 84 |
virtual void adoptTimeZone(TimeZone* zoneToAdopt); |
| 85 |
|
| 86 |
/** |
| 87 |
* Sets the time zone for the calendar of this DateFormat object. |
| 88 |
* @param zone the new time zone. |
| 89 |
*/ |
| 90 |
virtual void setTimeZone(const TimeZone& zone); |
| 91 |
|
| 92 |
/** |
| 93 |
* Return the class ID for this class. This is useful only for comparing to |
| 94 |
* a return value from getDynamicClassID(). For example: |
| 95 |
* <pre> |
| 96 |
* . Base* polymorphic_pointer = createPolymorphicObject(); |
| 97 |
* . if (polymorphic_pointer->getDynamicClassID() == |
| 98 |
* . derived::getStaticClassID()) ... |
| 99 |
* </pre> |
| 100 |
* @return The class ID for all objects of this class. |
| 101 |
*/ |
| 102 |
U_I18N_API static UClassID U_EXPORT2 getStaticClassID(); |
| 103 |
|
| 104 |
/** |
| 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. |
| 109 |
* |
| 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. |
| 113 |
*/ |
| 114 |
virtual UClassID getDynamicClassID() const; |
| 115 |
|
| 116 |
private: |
| 117 |
void formatDate(const SYSTEMTIME *st, UnicodeString &appendTo) const; |
| 118 |
void formatTime(const SYSTEMTIME *st, UnicodeString &appendTo) const; |
| 119 |
|
| 120 |
UnicodeString setTimeZoneInfo(TIME_ZONE_INFORMATION *tzi, const TimeZone &zone) const; |
| 121 |
UnicodeString* getTimeDateFormat(const Calendar *cal, const Locale *locale, UErrorCode &status) const; |
| 122 |
|
| 123 |
UnicodeString *fDateTimeMsg; |
| 124 |
DateFormat::EStyle fTimeStyle; |
| 125 |
DateFormat::EStyle fDateStyle; |
| 126 |
Locale fLocale; |
| 127 |
UnicodeString fZoneID; |
| 128 |
TIME_ZONE_INFORMATION *fTZI; |
| 129 |
|
| 130 |
UnicodeString* fWindowsLocaleName; // Stores the equivalent Windows locale name. |
| 131 |
}; |
| 132 |
|
| 133 |
U_NAMESPACE_END |
| 134 |
|
| 135 |
#endif /* #if !UCONFIG_NO_FORMATTING */ |
| 136 |
|
| 137 |
#endif // U_PLATFORM_USES_ONLY_WIN32_API |
| 138 |
|
| 139 |
#endif // __WINDTFMT |