1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2007-2008, International Business Machines Corporation and *
6 * others. All Rights Reserved. *
7 *******************************************************************************
12 #include "unicode/utypes.h"
16 * \brief C++ API: Rule for specifying date and time in an year
19 #if !UCONFIG_NO_FORMATTING
21 #include "unicode/uobject.h"
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
31 class U_I18N_API DateTimeRule : public UObject {
35 * Date rule type constants.
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. */
50 * Time rule type constants.
54 WALL_TIME = 0, /**< The local wall clock time */
55 STANDARD_TIME, /**< The local standard time */
56 UTC_TIME /**< The UTC time */
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>.
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>.
71 DateTimeRule(int32_t month, int32_t dayOfMonth,
72 int32_t millisInDay, TimeRuleType timeType);
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>.
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>.
89 DateTimeRule(int32_t month, int32_t weekInMonth, int32_t dayOfWeek,
90 int32_t millisInDay, TimeRuleType timeType);
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>.
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>.
107 DateTimeRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, UBool after,
108 int32_t millisInDay, TimeRuleType timeType);
112 * @param source The DateTimeRule object to be copied.
115 DateTimeRule(const DateTimeRule& source);
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.
129 DateTimeRule* clone(void) const;
132 * Assignment operator.
133 * @param right The object to be copied.
136 DateTimeRule& operator=(const DateTimeRule& right);
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.
145 UBool operator==(const DateTimeRule& that) const;
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.
154 UBool operator!=(const DateTimeRule& that) const;
157 * Gets the date rule type, such as <code>DOM</code>
158 * @return The date rule type.
161 DateRuleType getDateRuleType(void) const;
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>.
169 TimeRuleType getTimeRuleType(void) const;
172 * Gets the rule month.
173 * @return The rule month.
176 int32_t getRuleMonth(void) const;
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
184 int32_t getRuleDayOfMonth(void) const;
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.
192 int32_t getRuleDayOfWeek(void) const;
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.
201 int32_t getRuleWeekInMonth(void) const;
204 * Gets the rule time in the rule day.
205 * @return The time in the rule day in milliseconds.
208 int32_t getRuleMillisInDay(void) const;
214 int32_t fWeekInMonth;
215 int32_t fMillisInDay;
216 DateRuleType fDateRuleType;
217 TimeRuleType fTimeRuleType;
221 * Return the class ID for this class. This is useful only for comparing to
222 * a return value from getDynamicClassID(). For example:
224 * . Base* polymorphic_pointer = createPolymorphicObject();
225 * . if (polymorphic_pointer->getDynamicClassID() ==
226 * . erived::getStaticClassID()) ...
228 * @return The class ID for all objects of this class.
231 static UClassID U_EXPORT2 getStaticClassID(void);
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.
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.
244 virtual UClassID getDynamicClassID(void) const;
249 #endif /* #if !UCONFIG_NO_FORMATTING */