1 // © 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"
14 #if U_SHOW_CPLUSPLUS_API
18 * \brief C++ API: Rule for specifying date and time in an year
21 #if !UCONFIG_NO_FORMATTING
23 #include "unicode/uobject.h"
27 * <code>DateTimeRule</code> is a class representing a time in a year by
28 * a rule specified by month, day of month, day of week and
33 class U_I18N_API DateTimeRule
: public UObject
{
37 * Date rule type constants.
41 DOM
= 0, /**< The exact day of month,
42 for example, March 11. */
43 DOW
, /**< The Nth occurence of the day of week,
44 for example, 2nd Sunday in March. */
45 DOW_GEQ_DOM
, /**< The first occurence of the day of week on or after the day of monnth,
46 for example, first Sunday on or after March 8. */
47 DOW_LEQ_DOM
/**< The last occurence of the day of week on or before the day of month,
48 for example, first Sunday on or before March 14. */
52 * Time rule type constants.
56 WALL_TIME
= 0, /**< The local wall clock time */
57 STANDARD_TIME
, /**< The local standard time */
58 UTC_TIME
/**< The UTC time */
62 * Constructs a <code>DateTimeRule</code> by the day of month and
63 * the time rule. The date rule type for an instance created by
64 * this constructor is <code>DOM</code>.
66 * @param month The rule month, for example, <code>Calendar::JANUARY</code>
67 * @param dayOfMonth The day of month, 1-based.
68 * @param millisInDay The milliseconds in the rule date.
69 * @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code>
70 * or <code>UTC_TIME</code>.
73 DateTimeRule(int32_t month
, int32_t dayOfMonth
,
74 int32_t millisInDay
, TimeRuleType timeType
);
77 * Constructs a <code>DateTimeRule</code> by the day of week and its oridinal
78 * number and the time rule. The date rule type for an instance created
79 * by this constructor is <code>DOW</code>.
81 * @param month The rule month, for example, <code>Calendar::JANUARY</code>.
82 * @param weekInMonth The ordinal number of the day of week. Negative number
83 * may be used for specifying a rule date counted from the
84 * end of the rule month.
85 * @param dayOfWeek The day of week, for example, <code>Calendar::SUNDAY</code>.
86 * @param millisInDay The milliseconds in the rule date.
87 * @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code>
88 * or <code>UTC_TIME</code>.
91 DateTimeRule(int32_t month
, int32_t weekInMonth
, int32_t dayOfWeek
,
92 int32_t millisInDay
, TimeRuleType timeType
);
95 * Constructs a <code>DateTimeRule</code> by the first/last day of week
96 * on or after/before the day of month and the time rule. The date rule
97 * type for an instance created by this constructor is either
98 * <code>DOM_GEQ_DOM</code> or <code>DOM_LEQ_DOM</code>.
100 * @param month The rule month, for example, <code>Calendar::JANUARY</code>
101 * @param dayOfMonth The day of month, 1-based.
102 * @param dayOfWeek The day of week, for example, <code>Calendar::SUNDAY</code>.
103 * @param after true if the rule date is on or after the day of month.
104 * @param millisInDay The milliseconds in the rule date.
105 * @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code>
106 * or <code>UTC_TIME</code>.
109 DateTimeRule(int32_t month
, int32_t dayOfMonth
, int32_t dayOfWeek
, UBool after
,
110 int32_t millisInDay
, TimeRuleType timeType
);
114 * @param source The DateTimeRule object to be copied.
117 DateTimeRule(const DateTimeRule
& source
);
126 * Clone this DateTimeRule object polymorphically. The caller owns the result and
127 * should delete it when done.
128 * @return A copy of the object.
131 DateTimeRule
* clone() const;
134 * Assignment operator.
135 * @param right The object to be copied.
138 DateTimeRule
& operator=(const DateTimeRule
& right
);
141 * Return true if the given DateTimeRule objects are semantically equal. Objects
142 * of different subclasses are considered unequal.
143 * @param that The object to be compared with.
144 * @return true if the given DateTimeRule objects are semantically equal.
147 UBool
operator==(const DateTimeRule
& that
) const;
150 * Return true if the given DateTimeRule objects are semantically unequal. Objects
151 * of different subclasses are considered unequal.
152 * @param that The object to be compared with.
153 * @return true if the given DateTimeRule objects are semantically unequal.
156 UBool
operator!=(const DateTimeRule
& that
) const;
159 * Gets the date rule type, such as <code>DOM</code>
160 * @return The date rule type.
163 DateRuleType
getDateRuleType(void) const;
166 * Gets the time rule type
167 * @return The time rule type, either <code>WALL_TIME</code> or <code>STANDARD_TIME</code>
168 * or <code>UTC_TIME</code>.
171 TimeRuleType
getTimeRuleType(void) const;
174 * Gets the rule month.
175 * @return The rule month.
178 int32_t getRuleMonth(void) const;
181 * Gets the rule day of month. When the date rule type
182 * is <code>DOW</code>, the value is always 0.
183 * @return The rule day of month
186 int32_t getRuleDayOfMonth(void) const;
189 * Gets the rule day of week. When the date rule type
190 * is <code>DOM</code>, the value is always 0.
191 * @return The rule day of week.
194 int32_t getRuleDayOfWeek(void) const;
197 * Gets the ordinal number of the occurence of the day of week
198 * in the month. When the date rule type is not <code>DOW</code>,
199 * the value is always 0.
200 * @return The rule day of week ordinal number in the month.
203 int32_t getRuleWeekInMonth(void) const;
206 * Gets the rule time in the rule day.
207 * @return The time in the rule day in milliseconds.
210 int32_t getRuleMillisInDay(void) const;
216 int32_t fWeekInMonth
;
217 int32_t fMillisInDay
;
218 DateRuleType fDateRuleType
;
219 TimeRuleType fTimeRuleType
;
223 * Return the class ID for this class. This is useful only for comparing to
224 * a return value from getDynamicClassID(). For example:
226 * . Base* polymorphic_pointer = createPolymorphicObject();
227 * . if (polymorphic_pointer->getDynamicClassID() ==
228 * . erived::getStaticClassID()) ...
230 * @return The class ID for all objects of this class.
233 static UClassID U_EXPORT2
getStaticClassID(void);
236 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
237 * method is to implement a simple version of RTTI, since not all C++
238 * compilers support genuine RTTI. Polymorphic operator==() and clone()
239 * methods call this method.
241 * @return The class ID for this object. All objects of a
242 * given class have the same class ID. Objects of
243 * other classes have different class IDs.
246 virtual UClassID
getDynamicClassID(void) const;
251 #endif /* #if !UCONFIG_NO_FORMATTING */
253 #endif /* U_SHOW_CPLUSPLUS_API */