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"
16 * \brief C++ API: Rule for specifying date and time in an year
19 #if !UCONFIG_NO_FORMATTING
21 #include "unicode/uobject.h"
23 #if U_SHOW_CPLUSPLUS_API
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
32 class U_I18N_API DateTimeRule
: public UObject
{
36 * Date rule type constants.
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. */
51 * Time rule type constants.
55 WALL_TIME
= 0, /**< The local wall clock time */
56 STANDARD_TIME
, /**< The local standard time */
57 UTC_TIME
/**< The UTC time */
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>.
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>.
72 DateTimeRule(int32_t month
, int32_t dayOfMonth
,
73 int32_t millisInDay
, TimeRuleType timeType
);
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>.
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>.
90 DateTimeRule(int32_t month
, int32_t weekInMonth
, int32_t dayOfWeek
,
91 int32_t millisInDay
, TimeRuleType timeType
);
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>.
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>.
108 DateTimeRule(int32_t month
, int32_t dayOfMonth
, int32_t dayOfWeek
, UBool after
,
109 int32_t millisInDay
, TimeRuleType timeType
);
113 * @param source The DateTimeRule object to be copied.
116 DateTimeRule(const DateTimeRule
& source
);
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.
130 DateTimeRule
* clone(void) const;
133 * Assignment operator.
134 * @param right The object to be copied.
137 DateTimeRule
& operator=(const DateTimeRule
& right
);
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.
146 UBool
operator==(const DateTimeRule
& that
) const;
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.
155 UBool
operator!=(const DateTimeRule
& that
) const;
158 * Gets the date rule type, such as <code>DOM</code>
159 * @return The date rule type.
162 DateRuleType
getDateRuleType(void) const;
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>.
170 TimeRuleType
getTimeRuleType(void) const;
173 * Gets the rule month.
174 * @return The rule month.
177 int32_t getRuleMonth(void) const;
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
185 int32_t getRuleDayOfMonth(void) const;
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.
193 int32_t getRuleDayOfWeek(void) const;
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.
202 int32_t getRuleWeekInMonth(void) const;
205 * Gets the rule time in the rule day.
206 * @return The time in the rule day in milliseconds.
209 int32_t getRuleMillisInDay(void) const;
215 int32_t fWeekInMonth
;
216 int32_t fMillisInDay
;
217 DateRuleType fDateRuleType
;
218 TimeRuleType fTimeRuleType
;
222 * Return the class ID for this class. This is useful only for comparing to
223 * a return value from getDynamicClassID(). For example:
225 * . Base* polymorphic_pointer = createPolymorphicObject();
226 * . if (polymorphic_pointer->getDynamicClassID() ==
227 * . erived::getStaticClassID()) ...
229 * @return The class ID for all objects of this class.
232 static UClassID U_EXPORT2
getStaticClassID(void);
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.
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.
245 virtual UClassID
getDynamicClassID(void) const;
249 #endif // U_SHOW_CPLUSPLUS_API
251 #endif /* #if !UCONFIG_NO_FORMATTING */