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 #if U_SHOW_CPLUSPLUS_API 15 16 /** 17 * \file 18 * \brief C++ API: Rule for specifying date and time in an year 19 */ 20 21 #if !UCONFIG_NO_FORMATTING 22 23 #include "unicode/uobject.h" 24 25 U_NAMESPACE_BEGIN 26 /** 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 29 * time in the day. 30 * 31 * @stable ICU 3.8 32 */ 33 class U_I18N_API DateTimeRule : public UObject { 34 public: 35 36 /** 37 * Date rule type constants. 38 * @stable ICU 3.8 39 */ 40 enum DateRuleType { 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. */ 49 }; 50 51 /** 52 * Time rule type constants. 53 * @stable ICU 3.8 54 */ 55 enum TimeRuleType { 56 WALL_TIME = 0, /**< The local wall clock time */ 57 STANDARD_TIME, /**< The local standard time */ 58 UTC_TIME /**< The UTC time */ 59 }; 60 61 /** 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>. 65 * 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>. 71 * @stable ICU 3.8 72 */ 73 DateTimeRule(int32_t month, int32_t dayOfMonth, 74 int32_t millisInDay, TimeRuleType timeType); 75 76 /** 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>. 80 * 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>. 89 * @stable ICU 3.8 90 */ 91 DateTimeRule(int32_t month, int32_t weekInMonth, int32_t dayOfWeek, 92 int32_t millisInDay, TimeRuleType timeType); 93 94 /** 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>. 99 * 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>. 107 * @stable ICU 3.8 108 */ 109 DateTimeRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, UBool after, 110 int32_t millisInDay, TimeRuleType timeType); 111 112 /** 113 * Copy constructor. 114 * @param source The DateTimeRule object to be copied. 115 * @stable ICU 3.8 116 */ 117 DateTimeRule(const DateTimeRule& source); 118 119 /** 120 * Destructor. 121 * @stable ICU 3.8 122 */ 123 ~DateTimeRule(); 124 125 /** 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. 129 * @stable ICU 3.8 130 */ 131 DateTimeRule* clone() const; 132 133 /** 134 * Assignment operator. 135 * @param right The object to be copied. 136 * @stable ICU 3.8 137 */ 138 DateTimeRule& operator=(const DateTimeRule& right); 139 140 /** 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. 145 * @stable ICU 3.8 146 */ 147 UBool operator==(const DateTimeRule& that) const; 148 149 /** 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. 154 * @stable ICU 3.8 155 */ 156 UBool operator!=(const DateTimeRule& that) const; 157 158 /** 159 * Gets the date rule type, such as <code>DOM</code> 160 * @return The date rule type. 161 * @stable ICU 3.8 162 */ 163 DateRuleType getDateRuleType(void) const; 164 165 /** 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>. 169 * @stable ICU 3.8 170 */ 171 TimeRuleType getTimeRuleType(void) const; 172 173 /** 174 * Gets the rule month. 175 * @return The rule month. 176 * @stable ICU 3.8 177 */ 178 int32_t getRuleMonth(void) const; 179 180 /** 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 184 * @stable ICU 3.8 185 */ 186 int32_t getRuleDayOfMonth(void) const; 187 188 /** 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. 192 * @stable ICU 3.8 193 */ 194 int32_t getRuleDayOfWeek(void) const; 195 196 /** 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. 201 * @stable ICU 3.8 202 */ 203 int32_t getRuleWeekInMonth(void) const; 204 205 /** 206 * Gets the rule time in the rule day. 207 * @return The time in the rule day in milliseconds. 208 * @stable ICU 3.8 209 */ 210 int32_t getRuleMillisInDay(void) const; 211 212 private: 213 int32_t fMonth; 214 int32_t fDayOfMonth; 215 int32_t fDayOfWeek; 216 int32_t fWeekInMonth; 217 int32_t fMillisInDay; 218 DateRuleType fDateRuleType; 219 TimeRuleType fTimeRuleType; 220 221 public: 222 /** 223 * Return the class ID for this class. This is useful only for comparing to 224 * a return value from getDynamicClassID(). For example: 225 * <pre> 226 * . Base* polymorphic_pointer = createPolymorphicObject(); 227 * . if (polymorphic_pointer->getDynamicClassID() == 228 * . erived::getStaticClassID()) ... 229 * </pre> 230 * @return The class ID for all objects of this class. 231 * @stable ICU 3.8 232 */ 233 static UClassID U_EXPORT2 getStaticClassID(void); 234 235 /** 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. 240 * 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. 244 * @stable ICU 3.8 245 */ 246 virtual UClassID getDynamicClassID(void) const; 247 }; 248 249 U_NAMESPACE_END 250 251 #endif /* #if !UCONFIG_NO_FORMATTING */ 252 253 #endif /* U_SHOW_CPLUSPLUS_API */ 254 255 #endif // DTRULE_H 256 //eof 257