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