1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru******************************************************************************** 359d709d503bab6e2b61931737e662dd293b40578ccornelius* Copyright (C) 2005-2013, International Business Machines 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Corporation and others. All Rights Reserved. 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru******************************************************************************** 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* File WINDTFMT.H 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru******************************************************************************** 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef __WINDTFMT 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define __WINDTFMT 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1783a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius#if U_PLATFORM_HAS_WIN32_API 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_FORMATTING 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/format.h" 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/datefmt.h" 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/calendar.h" 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ustring.h" 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/locid.h" 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * \file 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * \brief C++ API: Format dates using Windows API. 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CDECL_BEGIN 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// Forward declarations for Windows types... 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef struct _SYSTEMTIME SYSTEMTIME; 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef struct _TIME_ZONE_INFORMATION TIME_ZONE_INFORMATION; 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CDECL_END 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass Win32DateFormat : public DateFormat 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic: 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Win32DateFormat(DateFormat::EStyle timeStyle, DateFormat::EStyle dateStyle, const Locale &locale, UErrorCode &status); 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Win32DateFormat(const Win32DateFormat &other); 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual ~Win32DateFormat(); 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual Format *clone(void) const; 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Win32DateFormat &operator=(const Win32DateFormat &other); 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString &format(Calendar &cal, UnicodeString &appendTo, FieldPosition &pos) const; 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString& format(UDate date, UnicodeString& appendTo) const; 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru void parse(const UnicodeString& text, Calendar& cal, ParsePosition& pos) const; 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Set the calendar to be used by this date format. Initially, the default 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * calendar for the specified or default locale is used. The caller should 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * not delete the Calendar object after it is adopted by this call. 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param calendarToAdopt Calendar object to be adopted. 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void adoptCalendar(Calendar* calendarToAdopt); 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Set the calendar to be used by this date format. Initially, the default 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * calendar for the specified or default locale is used. 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param newCalendar Calendar object to be set. 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void setCalendar(const Calendar& newCalendar); 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Sets the time zone for the calendar of this DateFormat object. The caller 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * no longer owns the TimeZone object and should not delete it after this call. 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param zoneToAdopt the TimeZone to be adopted. 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void adoptTimeZone(TimeZone* zoneToAdopt); 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Sets the time zone for the calendar of this DateFormat object. 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param zone the new time zone. 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void setTimeZone(const TimeZone& zone); 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Return the class ID for this class. This is useful only for comparing to 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * a return value from getDynamicClassID(). For example: 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <pre> 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * . Base* polymorphic_pointer = createPolymorphicObject(); 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * . if (polymorphic_pointer->getDynamicClassID() == 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * . erived::getStaticClassID()) ... 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * </pre> 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return The class ID for all objects of this class. 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void); 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * method is to implement a simple version of RTTI, since not all C++ 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * compilers support genuine RTTI. Polymorphic operator==() and clone() 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * methods call this method. 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return The class ID for this object. All objects of a 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * given class have the same class ID. Objects of 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * other classes have different class IDs. 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UClassID getDynamicClassID(void) const; 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprivate: 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru void formatDate(const SYSTEMTIME *st, UnicodeString &appendTo) const; 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru void formatTime(const SYSTEMTIME *st, UnicodeString &appendTo) const; 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString setTimeZoneInfo(TIME_ZONE_INFORMATION *tzi, const TimeZone &zone) const; 11985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UnicodeString* getTimeDateFormat(const Calendar *cal, const Locale *locale, UErrorCode &status) const; 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString *fDateTimeMsg; 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru DateFormat::EStyle fTimeStyle; 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru DateFormat::EStyle fDateStyle; 12459d709d503bab6e2b61931737e662dd293b40578ccornelius Locale fLocale; 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t fLCID; 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString fZoneID; 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TIME_ZONE_INFORMATION *fTZI; 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline UnicodeString &Win32DateFormat::format(UDate date, UnicodeString& appendTo) const { 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return DateFormat::format(date, appendTo); 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_FORMATTING */ 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 13883a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius#endif // U_PLATFORM_HAS_WIN32_API 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif // __WINDTFMT 141