windtfmt.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #ifndef __WINDTFMT
  14. #define __WINDTFMT
  15. #include "unicode/utypes.h"
  16. #if U_PLATFORM_USES_ONLY_WIN32_API
  17. #if !UCONFIG_NO_FORMATTING
  18. #include "unicode/format.h"
  19. #include "unicode/datefmt.h"
  20. #include "unicode/calendar.h"
  21. #include "unicode/ustring.h"
  22. #include "unicode/locid.h"
  23. /**
  24. * \file
  25. * \brief C++ API: Format dates using Windows API.
  26. */
  27. U_CDECL_BEGIN
  28. // Forward declarations for Windows types...
  29. typedef struct _SYSTEMTIME SYSTEMTIME;
  30. typedef struct _TIME_ZONE_INFORMATION TIME_ZONE_INFORMATION;
  31. U_CDECL_END
  32. U_NAMESPACE_BEGIN
  33. class Win32DateFormat : public DateFormat
  34. {
  35. public:
  36. Win32DateFormat(DateFormat::EStyle timeStyle, DateFormat::EStyle dateStyle, const Locale &locale, UErrorCode &status);
  37. Win32DateFormat(const Win32DateFormat &other);
  38. virtual ~Win32DateFormat();
  39. virtual Win32DateFormat *clone() const;
  40. Win32DateFormat &operator=(const Win32DateFormat &other);
  41. UnicodeString &format(Calendar &cal, UnicodeString &appendTo, FieldPosition &pos) const;
  42. using DateFormat::format;
  43. void parse(const UnicodeString& text, Calendar& cal, ParsePosition& pos) const;
  44. /**
  45. * Set the calendar to be used by this date format. Initially, the default
  46. * calendar for the specified or default locale is used. The caller should
  47. * not delete the Calendar object after it is adopted by this call.
  48. *
  49. * @param calendarToAdopt Calendar object to be adopted.
  50. */
  51. virtual void adoptCalendar(Calendar* calendarToAdopt);
  52. /**
  53. * Set the calendar to be used by this date format. Initially, the default
  54. * calendar for the specified or default locale is used.
  55. *
  56. * @param newCalendar Calendar object to be set.
  57. */
  58. virtual void setCalendar(const Calendar& newCalendar);
  59. /**
  60. * Sets the time zone for the calendar of this DateFormat object. The caller
  61. * no longer owns the TimeZone object and should not delete it after this call.
  62. *
  63. * @param zoneToAdopt the TimeZone to be adopted.
  64. */
  65. virtual void adoptTimeZone(TimeZone* zoneToAdopt);
  66. /**
  67. * Sets the time zone for the calendar of this DateFormat object.
  68. * @param zone the new time zone.
  69. */
  70. virtual void setTimeZone(const TimeZone& zone);
  71. /**
  72. * Return the class ID for this class. This is useful only for comparing to
  73. * a return value from getDynamicClassID(). For example:
  74. * <pre>
  75. * . Base* polymorphic_pointer = createPolymorphicObject();
  76. * . if (polymorphic_pointer->getDynamicClassID() ==
  77. * . derived::getStaticClassID()) ...
  78. * </pre>
  79. * @return The class ID for all objects of this class.
  80. */
  81. U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
  82. /**
  83. * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
  84. * method is to implement a simple version of RTTI, since not all C++
  85. * compilers support genuine RTTI. Polymorphic operator==() and clone()
  86. * methods call this method.
  87. *
  88. * @return The class ID for this object. All objects of a
  89. * given class have the same class ID. Objects of
  90. * other classes have different class IDs.
  91. */
  92. virtual UClassID getDynamicClassID(void) const;
  93. private:
  94. void formatDate(const SYSTEMTIME *st, UnicodeString &appendTo) const;
  95. void formatTime(const SYSTEMTIME *st, UnicodeString &appendTo) const;
  96. UnicodeString setTimeZoneInfo(TIME_ZONE_INFORMATION *tzi, const TimeZone &zone) const;
  97. UnicodeString* getTimeDateFormat(const Calendar *cal, const Locale *locale, UErrorCode &status) const;
  98. UnicodeString *fDateTimeMsg;
  99. DateFormat::EStyle fTimeStyle;
  100. DateFormat::EStyle fDateStyle;
  101. Locale fLocale;
  102. UnicodeString fZoneID;
  103. TIME_ZONE_INFORMATION *fTZI;
  104. UnicodeString* fWindowsLocaleName; // Stores the equivalent Windows locale name.
  105. };
  106. U_NAMESPACE_END
  107. #endif /* #if !UCONFIG_NO_FORMATTING */
  108. #endif // U_PLATFORM_USES_ONLY_WIN32_API
  109. #endif // __WINDTFMT