OLD | NEW |
| (Empty) |
1 /* | |
2 ******************************************************************************* | |
3 * Copyright (C) 2007-2008, International Business Machines Corporation and
* | |
4 * others. All Rights Reserved. * | |
5 ******************************************************************************* | |
6 */ | |
7 #ifndef DTRULE_H | |
8 #define DTRULE_H | |
9 | |
10 #include "unicode/utypes.h" | |
11 | |
12 /** | |
13 * \file | |
14 * \brief C++ API: Rule for specifying date and time in an year | |
15 */ | |
16 | |
17 #if !UCONFIG_NO_FORMATTING | |
18 | |
19 #include "unicode/uobject.h" | |
20 | |
21 U_NAMESPACE_BEGIN | |
22 /** | |
23 * <code>DateTimeRule</code> is a class representing a time in a year by | |
24 * a rule specified by month, day of month, day of week and | |
25 * time in the day. | |
26 * | |
27 * @stable ICU 3.8 | |
28 */ | |
29 class U_I18N_API DateTimeRule : public UObject { | |
30 public: | |
31 | |
32 /** | |
33 * Date rule type constants. | |
34 * @stable ICU 3.8 | |
35 */ | |
36 enum DateRuleType { | |
37 DOM = 0, /**< The exact day of month, | |
38 for example, March 11. */ | |
39 DOW, /**< The Nth occurence of the day of week, | |
40 for example, 2nd Sunday in March. */ | |
41 DOW_GEQ_DOM, /**< The first occurence of the day of week on or after
the day of monnth, | |
42 for example, first Sunday on or after March 8. */ | |
43 DOW_LEQ_DOM /**< The last occurence of the day of week on or before
the day of month, | |
44 for example, first Sunday on or before March 14. */ | |
45 }; | |
46 | |
47 /** | |
48 * Time rule type constants. | |
49 * @stable ICU 3.8 | |
50 */ | |
51 enum TimeRuleType { | |
52 WALL_TIME = 0, /**< The local wall clock time */ | |
53 STANDARD_TIME, /**< The local standard time */ | |
54 UTC_TIME /**< The UTC time */ | |
55 }; | |
56 | |
57 /** | |
58 * Constructs a <code>DateTimeRule</code> by the day of month and | |
59 * the time rule. The date rule type for an instance created by | |
60 * this constructor is <code>DOM</code>. | |
61 * | |
62 * @param month The rule month, for example, <code>Calendar::JANUARY
</code> | |
63 * @param dayOfMonth The day of month, 1-based. | |
64 * @param millisInDay The milliseconds in the rule date. | |
65 * @param timeType The time type, <code>WALL_TIME</code> or <code>STAND
ARD_TIME</code> | |
66 * or <code>UTC_TIME</code>. | |
67 * @stable ICU 3.8 | |
68 */ | |
69 DateTimeRule(int32_t month, int32_t dayOfMonth, | |
70 int32_t millisInDay, TimeRuleType timeType); | |
71 | |
72 /** | |
73 * Constructs a <code>DateTimeRule</code> by the day of week and its oridina
l | |
74 * number and the time rule. The date rule type for an instance created | |
75 * by this constructor is <code>DOW</code>. | |
76 * | |
77 * @param month The rule month, for example, <code>Calendar::JANUARY
</code>. | |
78 * @param weekInMonth The ordinal number of the day of week. Negative num
ber | |
79 * may be used for specifying a rule date counted from
the | |
80 * end of the rule month. | |
81 * @param dayOfWeek The day of week, for example, <code>Calendar::SUNDAY
</code>. | |
82 * @param millisInDay The milliseconds in the rule date. | |
83 * @param timeType The time type, <code>WALL_TIME</code> or <code>STAND
ARD_TIME</code> | |
84 * or <code>UTC_TIME</code>. | |
85 * @stable ICU 3.8 | |
86 */ | |
87 DateTimeRule(int32_t month, int32_t weekInMonth, int32_t dayOfWeek, | |
88 int32_t millisInDay, TimeRuleType timeType); | |
89 | |
90 /** | |
91 * Constructs a <code>DateTimeRule</code> by the first/last day of week | |
92 * on or after/before the day of month and the time rule. The date rule | |
93 * type for an instance created by this constructor is either | |
94 * <code>DOM_GEQ_DOM</code> or <code>DOM_LEQ_DOM</code>. | |
95 * | |
96 * @param month The rule month, for example, <code>Calendar::JANUARY
</code> | |
97 * @param dayOfMonth The day of month, 1-based. | |
98 * @param dayOfWeek The day of week, for example, <code>Calendar::SUNDAY
</code>. | |
99 * @param after true if the rule date is on or after the day of mont
h. | |
100 * @param millisInDay The milliseconds in the rule date. | |
101 * @param timeType The time type, <code>WALL_TIME</code> or <code>STAND
ARD_TIME</code> | |
102 * or <code>UTC_TIME</code>. | |
103 * @stable ICU 3.8 | |
104 */ | |
105 DateTimeRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, UBool aft
er, | |
106 int32_t millisInDay, TimeRuleType timeType); | |
107 | |
108 /** | |
109 * Copy constructor. | |
110 * @param source The DateTimeRule object to be copied. | |
111 * @stable ICU 3.8 | |
112 */ | |
113 DateTimeRule(const DateTimeRule& source); | |
114 | |
115 /** | |
116 * Destructor. | |
117 * @stable ICU 3.8 | |
118 */ | |
119 ~DateTimeRule(); | |
120 | |
121 /** | |
122 * Clone this DateTimeRule object polymorphically. The caller owns the resul
t and | |
123 * should delete it when done. | |
124 * @return A copy of the object. | |
125 * @stable ICU 3.8 | |
126 */ | |
127 DateTimeRule* clone(void) const; | |
128 | |
129 /** | |
130 * Assignment operator. | |
131 * @param right The object to be copied. | |
132 * @stable ICU 3.8 | |
133 */ | |
134 DateTimeRule& operator=(const DateTimeRule& right); | |
135 | |
136 /** | |
137 * Return true if the given DateTimeRule objects are semantically equal. Obj
ects | |
138 * of different subclasses are considered unequal. | |
139 * @param that The object to be compared with. | |
140 * @return true if the given DateTimeRule objects are semantically equal. | |
141 * @stable ICU 3.8 | |
142 */ | |
143 UBool operator==(const DateTimeRule& that) const; | |
144 | |
145 /** | |
146 * Return true if the given DateTimeRule objects are semantically unequal. O
bjects | |
147 * of different subclasses are considered unequal. | |
148 * @param that The object to be compared with. | |
149 * @return true if the given DateTimeRule objects are semantically unequal. | |
150 * @stable ICU 3.8 | |
151 */ | |
152 UBool operator!=(const DateTimeRule& that) const; | |
153 | |
154 /** | |
155 * Gets the date rule type, such as <code>DOM</code> | |
156 * @return The date rule type. | |
157 * @stable ICU 3.8 | |
158 */ | |
159 DateRuleType getDateRuleType(void) const; | |
160 | |
161 /** | |
162 * Gets the time rule type | |
163 * @return The time rule type, either <code>WALL_TIME</code> or <code>STANDA
RD_TIME</code> | |
164 * or <code>UTC_TIME</code>. | |
165 * @stable ICU 3.8 | |
166 */ | |
167 TimeRuleType getTimeRuleType(void) const; | |
168 | |
169 /** | |
170 * Gets the rule month. | |
171 * @return The rule month. | |
172 * @stable ICU 3.8 | |
173 */ | |
174 int32_t getRuleMonth(void) const; | |
175 | |
176 /** | |
177 * Gets the rule day of month. When the date rule type | |
178 * is <code>DOW</code>, the value is always 0. | |
179 * @return The rule day of month | |
180 * @stable ICU 3.8 | |
181 */ | |
182 int32_t getRuleDayOfMonth(void) const; | |
183 | |
184 /** | |
185 * Gets the rule day of week. When the date rule type | |
186 * is <code>DOM</code>, the value is always 0. | |
187 * @return The rule day of week. | |
188 * @stable ICU 3.8 | |
189 */ | |
190 int32_t getRuleDayOfWeek(void) const; | |
191 | |
192 /** | |
193 * Gets the ordinal number of the occurence of the day of week | |
194 * in the month. When the date rule type is not <code>DOW</code>, | |
195 * the value is always 0. | |
196 * @return The rule day of week ordinal number in the month. | |
197 * @stable ICU 3.8 | |
198 */ | |
199 int32_t getRuleWeekInMonth(void) const; | |
200 | |
201 /** | |
202 * Gets the rule time in the rule day. | |
203 * @return The time in the rule day in milliseconds. | |
204 * @stable ICU 3.8 | |
205 */ | |
206 int32_t getRuleMillisInDay(void) const; | |
207 | |
208 private: | |
209 int32_t fMonth; | |
210 int32_t fDayOfMonth; | |
211 int32_t fDayOfWeek; | |
212 int32_t fWeekInMonth; | |
213 int32_t fMillisInDay; | |
214 DateRuleType fDateRuleType; | |
215 TimeRuleType fTimeRuleType; | |
216 | |
217 public: | |
218 /** | |
219 * Return the class ID for this class. This is useful only for comparing to | |
220 * a return value from getDynamicClassID(). For example: | |
221 * <pre> | |
222 * . Base* polymorphic_pointer = createPolymorphicObject(); | |
223 * . if (polymorphic_pointer->getDynamicClassID() == | |
224 * . erived::getStaticClassID()) ... | |
225 * </pre> | |
226 * @return The class ID for all objects of this class. | |
227 * @stable ICU 3.8 | |
228 */ | |
229 static UClassID U_EXPORT2 getStaticClassID(void); | |
230 | |
231 /** | |
232 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This | |
233 * method is to implement a simple version of RTTI, since not all C++ | |
234 * compilers support genuine RTTI. Polymorphic operator==() and clone() | |
235 * methods call this method. | |
236 * | |
237 * @return The class ID for this object. All objects of a | |
238 * given class have the same class ID. Objects of | |
239 * other classes have different class IDs. | |
240 * @stable ICU 3.8 | |
241 */ | |
242 virtual UClassID getDynamicClassID(void) const; | |
243 }; | |
244 | |
245 U_NAMESPACE_END | |
246 | |
247 #endif /* #if !UCONFIG_NO_FORMATTING */ | |
248 | |
249 #endif // DTRULE_H | |
250 //eof | |
OLD | NEW |