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