2 *******************************************************************************
3 * Copyright (C) 2007-2008, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
10 #include "unicode/utypes.h"
14 * \brief C++ API: Rule for specifying date and time in an year
17 #if !UCONFIG_NO_FORMATTING
19 #include "unicode/uobject.h"
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
29 class U_I18N_API DateTimeRule
: public UObject
{
33 * Date rule type constants.
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. */
48 * Time rule type constants.
52 WALL_TIME
= 0, /**< The local wall clock time */
53 STANDARD_TIME
, /**< The local standard time */
54 UTC_TIME
/**< The UTC time */
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>.
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>STANDARD_TIME</code>
66 * or <code>UTC_TIME</code>.
69 DateTimeRule(int32_t month
, int32_t dayOfMonth
,
70 int32_t millisInDay
, TimeRuleType timeType
);
73 * Constructs a <code>DateTimeRule</code> by the day of week and its oridinal
74 * number and the time rule. The date rule type for an instance created
75 * by this constructor is <code>DOW</code>.
77 * @param month The rule month, for example, <code>Calendar::JANUARY</code>.
78 * @param weekInMonth The ordinal number of the day of week. Negative number
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>STANDARD_TIME</code>
84 * or <code>UTC_TIME</code>.
87 DateTimeRule(int32_t month
, int32_t weekInMonth
, int32_t dayOfWeek
,
88 int32_t millisInDay
, TimeRuleType timeType
);
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>.
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 month.
100 * @param millisInDay The milliseconds in the rule date.
101 * @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code>
102 * or <code>UTC_TIME</code>.
105 DateTimeRule(int32_t month
, int32_t dayOfMonth
, int32_t dayOfWeek
, UBool after
,
106 int32_t millisInDay
, TimeRuleType timeType
);
110 * @param source The DateTimeRule object to be copied.
113 DateTimeRule(const DateTimeRule
& source
);
122 * Clone this DateTimeRule object polymorphically. The caller owns the result and
123 * should delete it when done.
124 * @return A copy of the object.
127 DateTimeRule
* clone(void) const;
130 * Assignment operator.
131 * @param right The object to be copied.
134 DateTimeRule
& operator=(const DateTimeRule
& right
);
137 * Return true if the given DateTimeRule objects are semantically equal. Objects
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.
143 UBool
operator==(const DateTimeRule
& that
) const;
146 * Return true if the given DateTimeRule objects are semantically unequal. Objects
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.
152 UBool
operator!=(const DateTimeRule
& that
) const;
155 * Gets the date rule type, such as <code>DOM</code>
156 * @return The date rule type.
159 DateRuleType
getDateRuleType(void) const;
162 * Gets the time rule type
163 * @return The time rule type, either <code>WALL_TIME</code> or <code>STANDARD_TIME</code>
164 * or <code>UTC_TIME</code>.
167 TimeRuleType
getTimeRuleType(void) const;
170 * Gets the rule month.
171 * @return The rule month.
174 int32_t getRuleMonth(void) const;
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
182 int32_t getRuleDayOfMonth(void) const;
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.
190 int32_t getRuleDayOfWeek(void) const;
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.
199 int32_t getRuleWeekInMonth(void) const;
202 * Gets the rule time in the rule day.
203 * @return The time in the rule day in milliseconds.
206 int32_t getRuleMillisInDay(void) const;
212 int32_t fWeekInMonth
;
213 int32_t fMillisInDay
;
214 DateRuleType fDateRuleType
;
215 TimeRuleType fTimeRuleType
;
219 * Return the class ID for this class. This is useful only for comparing to
220 * a return value from getDynamicClassID(). For example:
222 * . Base* polymorphic_pointer = createPolymorphicObject();
223 * . if (polymorphic_pointer->getDynamicClassID() ==
224 * . erived::getStaticClassID()) ...
226 * @return The class ID for all objects of this class.
229 static UClassID U_EXPORT2
getStaticClassID(void);
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.
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.
242 virtual UClassID
getDynamicClassID(void) const;
247 #endif /* #if !UCONFIG_NO_FORMATTING */