1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 /******************************************************************** 4 * COPYRIGHT: 5 * Copyright (c) 1997-2009, International Business Machines Corporation and 6 * others. All Rights Reserved. 7 ********************************************************************/ 8 9 10 #ifndef _CALTZTST 11 #define _CALTZTST 12 13 #include "unicode/utypes.h" 14 15 #if !UCONFIG_NO_FORMATTING 16 17 #include "unicode/unistr.h" 18 #include "unicode/calendar.h" 19 #include "unicode/datefmt.h" 20 #include "intltest.h" 21 22 /** 23 * This class doesn't perform any tests, but provides utility methods to its subclasses. 24 **/ 25 class CalendarTimeZoneTest : public IntlTest 26 { 27 public: 28 static void cleanup(); 29 protected: 30 // Return true if the given status indicates failure. Also has the side effect 31 // of calling errln(). Msg should be of the form "Class::Method" in general. 32 UBool failure(UErrorCode status, const char* msg, UBool possibleDataError=FALSE); 33 34 // Utility method for formatting dates for printing; useful for Java->C++ conversion. 35 // Tries to mimic the Java Date.toString() format. 36 UnicodeString dateToString(UDate d); 37 UnicodeString& dateToString(UDate d, UnicodeString& str); 38 UnicodeString& dateToString(UDate d, UnicodeString& str, const TimeZone& z); 39 40 // Utility methods to create a date. This is useful for converting Java constructs 41 // which create a Date object. Returns a Date in the current local time. 42 UDate date(int32_t y, int32_t m, int32_t d, int32_t hr=0, int32_t min=0, int32_t sec=0); 43 44 // Utility methods to create a date. Returns a Date in UTC. This will differ 45 // from local dates returned by date() by the current default zone offset. 46 // Date utcDate(int y, int m, int d, int hr=0, int min=0, int sec=0); 47 48 // Utility method to get the fields of a date; similar to Date.getYear() etc. 49 void dateToFields(UDate date, int32_t& y, int32_t& m, int32_t& d, int32_t& hr, int32_t& min, int32_t& sec); 50 51 protected: 52 static DateFormat* fgDateFormat; 53 static Calendar* fgCalendar; 54 55 // the 'get()' functions are not static because they can call errln(). 56 // they are effectively static otherwise. 57 DateFormat* getDateFormat(void); 58 static void releaseDateFormat(DateFormat *f); 59 60 Calendar* getCalendar(void); 61 static void releaseCalendar(Calendar *c); 62 }; 63 64 #endif /* #if !UCONFIG_NO_FORMATTING */ 65 66 #endif //_CALTZTST 67 //eof 68