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