Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | ******************************************************************************* |
michael@0 | 3 | * Copyright (C) 2007-2008, International Business Machines Corporation and * |
michael@0 | 4 | * others. All Rights Reserved. * |
michael@0 | 5 | ******************************************************************************* |
michael@0 | 6 | */ |
michael@0 | 7 | #ifndef DTRULE_H |
michael@0 | 8 | #define DTRULE_H |
michael@0 | 9 | |
michael@0 | 10 | #include "unicode/utypes.h" |
michael@0 | 11 | |
michael@0 | 12 | /** |
michael@0 | 13 | * \file |
michael@0 | 14 | * \brief C++ API: Rule for specifying date and time in an year |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | #if !UCONFIG_NO_FORMATTING |
michael@0 | 18 | |
michael@0 | 19 | #include "unicode/uobject.h" |
michael@0 | 20 | |
michael@0 | 21 | U_NAMESPACE_BEGIN |
michael@0 | 22 | /** |
michael@0 | 23 | * <code>DateTimeRule</code> is a class representing a time in a year by |
michael@0 | 24 | * a rule specified by month, day of month, day of week and |
michael@0 | 25 | * time in the day. |
michael@0 | 26 | * |
michael@0 | 27 | * @stable ICU 3.8 |
michael@0 | 28 | */ |
michael@0 | 29 | class U_I18N_API DateTimeRule : public UObject { |
michael@0 | 30 | public: |
michael@0 | 31 | |
michael@0 | 32 | /** |
michael@0 | 33 | * Date rule type constants. |
michael@0 | 34 | * @stable ICU 3.8 |
michael@0 | 35 | */ |
michael@0 | 36 | enum DateRuleType { |
michael@0 | 37 | DOM = 0, /**< The exact day of month, |
michael@0 | 38 | for example, March 11. */ |
michael@0 | 39 | DOW, /**< The Nth occurence of the day of week, |
michael@0 | 40 | for example, 2nd Sunday in March. */ |
michael@0 | 41 | DOW_GEQ_DOM, /**< The first occurence of the day of week on or after the day of monnth, |
michael@0 | 42 | for example, first Sunday on or after March 8. */ |
michael@0 | 43 | DOW_LEQ_DOM /**< The last occurence of the day of week on or before the day of month, |
michael@0 | 44 | for example, first Sunday on or before March 14. */ |
michael@0 | 45 | }; |
michael@0 | 46 | |
michael@0 | 47 | /** |
michael@0 | 48 | * Time rule type constants. |
michael@0 | 49 | * @stable ICU 3.8 |
michael@0 | 50 | */ |
michael@0 | 51 | enum TimeRuleType { |
michael@0 | 52 | WALL_TIME = 0, /**< The local wall clock time */ |
michael@0 | 53 | STANDARD_TIME, /**< The local standard time */ |
michael@0 | 54 | UTC_TIME /**< The UTC time */ |
michael@0 | 55 | }; |
michael@0 | 56 | |
michael@0 | 57 | /** |
michael@0 | 58 | * Constructs a <code>DateTimeRule</code> by the day of month and |
michael@0 | 59 | * the time rule. The date rule type for an instance created by |
michael@0 | 60 | * this constructor is <code>DOM</code>. |
michael@0 | 61 | * |
michael@0 | 62 | * @param month The rule month, for example, <code>Calendar::JANUARY</code> |
michael@0 | 63 | * @param dayOfMonth The day of month, 1-based. |
michael@0 | 64 | * @param millisInDay The milliseconds in the rule date. |
michael@0 | 65 | * @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code> |
michael@0 | 66 | * or <code>UTC_TIME</code>. |
michael@0 | 67 | * @stable ICU 3.8 |
michael@0 | 68 | */ |
michael@0 | 69 | DateTimeRule(int32_t month, int32_t dayOfMonth, |
michael@0 | 70 | int32_t millisInDay, TimeRuleType timeType); |
michael@0 | 71 | |
michael@0 | 72 | /** |
michael@0 | 73 | * Constructs a <code>DateTimeRule</code> by the day of week and its oridinal |
michael@0 | 74 | * number and the time rule. The date rule type for an instance created |
michael@0 | 75 | * by this constructor is <code>DOW</code>. |
michael@0 | 76 | * |
michael@0 | 77 | * @param month The rule month, for example, <code>Calendar::JANUARY</code>. |
michael@0 | 78 | * @param weekInMonth The ordinal number of the day of week. Negative number |
michael@0 | 79 | * may be used for specifying a rule date counted from the |
michael@0 | 80 | * end of the rule month. |
michael@0 | 81 | * @param dayOfWeek The day of week, for example, <code>Calendar::SUNDAY</code>. |
michael@0 | 82 | * @param millisInDay The milliseconds in the rule date. |
michael@0 | 83 | * @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code> |
michael@0 | 84 | * or <code>UTC_TIME</code>. |
michael@0 | 85 | * @stable ICU 3.8 |
michael@0 | 86 | */ |
michael@0 | 87 | DateTimeRule(int32_t month, int32_t weekInMonth, int32_t dayOfWeek, |
michael@0 | 88 | int32_t millisInDay, TimeRuleType timeType); |
michael@0 | 89 | |
michael@0 | 90 | /** |
michael@0 | 91 | * Constructs a <code>DateTimeRule</code> by the first/last day of week |
michael@0 | 92 | * on or after/before the day of month and the time rule. The date rule |
michael@0 | 93 | * type for an instance created by this constructor is either |
michael@0 | 94 | * <code>DOM_GEQ_DOM</code> or <code>DOM_LEQ_DOM</code>. |
michael@0 | 95 | * |
michael@0 | 96 | * @param month The rule month, for example, <code>Calendar::JANUARY</code> |
michael@0 | 97 | * @param dayOfMonth The day of month, 1-based. |
michael@0 | 98 | * @param dayOfWeek The day of week, for example, <code>Calendar::SUNDAY</code>. |
michael@0 | 99 | * @param after true if the rule date is on or after the day of month. |
michael@0 | 100 | * @param millisInDay The milliseconds in the rule date. |
michael@0 | 101 | * @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code> |
michael@0 | 102 | * or <code>UTC_TIME</code>. |
michael@0 | 103 | * @stable ICU 3.8 |
michael@0 | 104 | */ |
michael@0 | 105 | DateTimeRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, UBool after, |
michael@0 | 106 | int32_t millisInDay, TimeRuleType timeType); |
michael@0 | 107 | |
michael@0 | 108 | /** |
michael@0 | 109 | * Copy constructor. |
michael@0 | 110 | * @param source The DateTimeRule object to be copied. |
michael@0 | 111 | * @stable ICU 3.8 |
michael@0 | 112 | */ |
michael@0 | 113 | DateTimeRule(const DateTimeRule& source); |
michael@0 | 114 | |
michael@0 | 115 | /** |
michael@0 | 116 | * Destructor. |
michael@0 | 117 | * @stable ICU 3.8 |
michael@0 | 118 | */ |
michael@0 | 119 | ~DateTimeRule(); |
michael@0 | 120 | |
michael@0 | 121 | /** |
michael@0 | 122 | * Clone this DateTimeRule object polymorphically. The caller owns the result and |
michael@0 | 123 | * should delete it when done. |
michael@0 | 124 | * @return A copy of the object. |
michael@0 | 125 | * @stable ICU 3.8 |
michael@0 | 126 | */ |
michael@0 | 127 | DateTimeRule* clone(void) const; |
michael@0 | 128 | |
michael@0 | 129 | /** |
michael@0 | 130 | * Assignment operator. |
michael@0 | 131 | * @param right The object to be copied. |
michael@0 | 132 | * @stable ICU 3.8 |
michael@0 | 133 | */ |
michael@0 | 134 | DateTimeRule& operator=(const DateTimeRule& right); |
michael@0 | 135 | |
michael@0 | 136 | /** |
michael@0 | 137 | * Return true if the given DateTimeRule objects are semantically equal. Objects |
michael@0 | 138 | * of different subclasses are considered unequal. |
michael@0 | 139 | * @param that The object to be compared with. |
michael@0 | 140 | * @return true if the given DateTimeRule objects are semantically equal. |
michael@0 | 141 | * @stable ICU 3.8 |
michael@0 | 142 | */ |
michael@0 | 143 | UBool operator==(const DateTimeRule& that) const; |
michael@0 | 144 | |
michael@0 | 145 | /** |
michael@0 | 146 | * Return true if the given DateTimeRule objects are semantically unequal. Objects |
michael@0 | 147 | * of different subclasses are considered unequal. |
michael@0 | 148 | * @param that The object to be compared with. |
michael@0 | 149 | * @return true if the given DateTimeRule objects are semantically unequal. |
michael@0 | 150 | * @stable ICU 3.8 |
michael@0 | 151 | */ |
michael@0 | 152 | UBool operator!=(const DateTimeRule& that) const; |
michael@0 | 153 | |
michael@0 | 154 | /** |
michael@0 | 155 | * Gets the date rule type, such as <code>DOM</code> |
michael@0 | 156 | * @return The date rule type. |
michael@0 | 157 | * @stable ICU 3.8 |
michael@0 | 158 | */ |
michael@0 | 159 | DateRuleType getDateRuleType(void) const; |
michael@0 | 160 | |
michael@0 | 161 | /** |
michael@0 | 162 | * Gets the time rule type |
michael@0 | 163 | * @return The time rule type, either <code>WALL_TIME</code> or <code>STANDARD_TIME</code> |
michael@0 | 164 | * or <code>UTC_TIME</code>. |
michael@0 | 165 | * @stable ICU 3.8 |
michael@0 | 166 | */ |
michael@0 | 167 | TimeRuleType getTimeRuleType(void) const; |
michael@0 | 168 | |
michael@0 | 169 | /** |
michael@0 | 170 | * Gets the rule month. |
michael@0 | 171 | * @return The rule month. |
michael@0 | 172 | * @stable ICU 3.8 |
michael@0 | 173 | */ |
michael@0 | 174 | int32_t getRuleMonth(void) const; |
michael@0 | 175 | |
michael@0 | 176 | /** |
michael@0 | 177 | * Gets the rule day of month. When the date rule type |
michael@0 | 178 | * is <code>DOW</code>, the value is always 0. |
michael@0 | 179 | * @return The rule day of month |
michael@0 | 180 | * @stable ICU 3.8 |
michael@0 | 181 | */ |
michael@0 | 182 | int32_t getRuleDayOfMonth(void) const; |
michael@0 | 183 | |
michael@0 | 184 | /** |
michael@0 | 185 | * Gets the rule day of week. When the date rule type |
michael@0 | 186 | * is <code>DOM</code>, the value is always 0. |
michael@0 | 187 | * @return The rule day of week. |
michael@0 | 188 | * @stable ICU 3.8 |
michael@0 | 189 | */ |
michael@0 | 190 | int32_t getRuleDayOfWeek(void) const; |
michael@0 | 191 | |
michael@0 | 192 | /** |
michael@0 | 193 | * Gets the ordinal number of the occurence of the day of week |
michael@0 | 194 | * in the month. When the date rule type is not <code>DOW</code>, |
michael@0 | 195 | * the value is always 0. |
michael@0 | 196 | * @return The rule day of week ordinal number in the month. |
michael@0 | 197 | * @stable ICU 3.8 |
michael@0 | 198 | */ |
michael@0 | 199 | int32_t getRuleWeekInMonth(void) const; |
michael@0 | 200 | |
michael@0 | 201 | /** |
michael@0 | 202 | * Gets the rule time in the rule day. |
michael@0 | 203 | * @return The time in the rule day in milliseconds. |
michael@0 | 204 | * @stable ICU 3.8 |
michael@0 | 205 | */ |
michael@0 | 206 | int32_t getRuleMillisInDay(void) const; |
michael@0 | 207 | |
michael@0 | 208 | private: |
michael@0 | 209 | int32_t fMonth; |
michael@0 | 210 | int32_t fDayOfMonth; |
michael@0 | 211 | int32_t fDayOfWeek; |
michael@0 | 212 | int32_t fWeekInMonth; |
michael@0 | 213 | int32_t fMillisInDay; |
michael@0 | 214 | DateRuleType fDateRuleType; |
michael@0 | 215 | TimeRuleType fTimeRuleType; |
michael@0 | 216 | |
michael@0 | 217 | public: |
michael@0 | 218 | /** |
michael@0 | 219 | * Return the class ID for this class. This is useful only for comparing to |
michael@0 | 220 | * a return value from getDynamicClassID(). For example: |
michael@0 | 221 | * <pre> |
michael@0 | 222 | * . Base* polymorphic_pointer = createPolymorphicObject(); |
michael@0 | 223 | * . if (polymorphic_pointer->getDynamicClassID() == |
michael@0 | 224 | * . erived::getStaticClassID()) ... |
michael@0 | 225 | * </pre> |
michael@0 | 226 | * @return The class ID for all objects of this class. |
michael@0 | 227 | * @stable ICU 3.8 |
michael@0 | 228 | */ |
michael@0 | 229 | static UClassID U_EXPORT2 getStaticClassID(void); |
michael@0 | 230 | |
michael@0 | 231 | /** |
michael@0 | 232 | * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This |
michael@0 | 233 | * method is to implement a simple version of RTTI, since not all C++ |
michael@0 | 234 | * compilers support genuine RTTI. Polymorphic operator==() and clone() |
michael@0 | 235 | * methods call this method. |
michael@0 | 236 | * |
michael@0 | 237 | * @return The class ID for this object. All objects of a |
michael@0 | 238 | * given class have the same class ID. Objects of |
michael@0 | 239 | * other classes have different class IDs. |
michael@0 | 240 | * @stable ICU 3.8 |
michael@0 | 241 | */ |
michael@0 | 242 | virtual UClassID getDynamicClassID(void) const; |
michael@0 | 243 | }; |
michael@0 | 244 | |
michael@0 | 245 | U_NAMESPACE_END |
michael@0 | 246 | |
michael@0 | 247 | #endif /* #if !UCONFIG_NO_FORMATTING */ |
michael@0 | 248 | |
michael@0 | 249 | #endif // DTRULE_H |
michael@0 | 250 | //eof |