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